Commit 16ec499c authored by Vladislav Bogdashkin's avatar Vladislav Bogdashkin 🎣

calculate files size

parent 48c17059
......@@ -5,6 +5,8 @@ import com.biganto.visual.roompark.data.repository.api.IRoomParkApi
import com.biganto.visual.roompark.data.repository.db.IDb
import com.biganto.visual.roompark.data.repository.file.FileModule
import com.biganto.visual.roompark.domain.contract.FilesContract
import com.biganto.visual.roompark.util.extensions.folderSize
import java.io.File
import javax.inject.Inject
import kotlin.reflect.full.primaryConstructor
......@@ -21,10 +23,23 @@ class FilesContractModule @Inject constructor(
): FilesContract {
inline fun <reified T:FileModule.FileDirectory> getDirectory(): T? =
private inline fun <reified T:FileModule.FileDirectory> getDirectory(): T? =
T::class.primaryConstructor?.call()
fun getPlansSize() = getDirectorySize<>()
private inline fun <reified T:FileModule.FileDirectory> getFile(): File {
val d = getDirectory<T>()?:error("Unresolved class type")
return FileModule.getDirectory(context,d)
}
override fun getPlansSize() = getFile<FileModule.FileDirectory.PlanTypeDir>().folderSize
override fun getToursSize() = getFile<FileModule.FileDirectory.ToursDir>().folderSize
override fun getFeedSize() = getFile<FileModule.FileDirectory.FeedsDir>().folderSize
override fun getAlbumSize() = getFile<FileModule.FileDirectory.Albums>().folderSize
override fun allCacheSize() = FileModule.assetsFile(context).folderSize
}
......@@ -71,6 +71,9 @@ class FileModule @Inject constructor(val context: Application) {
File(context.filesDir.absolutePath.plus(dirType.dir))
fun assetsDirectory(context: Context): String = context.filesDir.absolutePath
fun assetsFile(context: Context): File = context.filesDir.absoluteFile
}
......
......@@ -6,4 +6,9 @@ package com.biganto.visual.roompark.domain.contract
interface FilesContract{
fun allCacheSize(): Long
fun getAlbumSize(): Long
fun getFeedSize(): Long
fun getToursSize(): Long
fun getPlansSize(): Long
}
\ No newline at end of file
......@@ -5,6 +5,7 @@ import android.graphics.Canvas
import android.graphics.RectF
import android.view.View
import timber.log.Timber
import java.io.File
import java.text.DecimalFormat
import java.text.SimpleDateFormat
import java.util.*
......@@ -97,4 +98,10 @@ fun Bitmap.scaleCenterCrop(viewHolder:View): Bitmap {
canvas.drawBitmap(this, null, targetRect, null)
return dest
}
\ No newline at end of file
}
val File.folderSize get() =
this.walkTopDown()
.asSequence()
.map {it.length()}
.sum()
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment