Fix overflow on media cache size

This commit is contained in:
Tiago Loureiro 2022-03-01 13:12:46 -03:00
parent b8fad693f3
commit ad8809196f
4 changed files with 7 additions and 7 deletions

View File

@ -117,5 +117,5 @@ interface FileService {
/**
* Get size of cached files
*/
fun getCacheSize(): Int
fun getCacheSize(): Long
}

View File

@ -323,13 +323,13 @@ internal class DefaultFileService @Inject constructor(
return FileProvider.getUriForFile(context, authority, targetFile)
}
override fun getCacheSize(): Int {
override fun getCacheSize(): Long {
return downloadFolder.walkTopDown()
.onEnter {
Timber.v("Get size of ${it.absolutePath}")
true
}
.sumOf { it.length().toInt() }
.sumOf { it.length() }
}
override fun clearCache() {

View File

@ -125,11 +125,11 @@ fun getFileExtension(fileUri: String): String? {
* Size
* ========================================================================================== */
fun getSizeOfFiles(root: File): Int {
fun getSizeOfFiles(root: File): Long {
return root.walkTopDown()
.onEnter {
Timber.v("Get size of ${it.absolutePath}")
true
}
.sumOf { it.length().toInt() }
.sumOf { it.length() }
}

View File

@ -251,7 +251,7 @@ class VectorSettingsGeneralFragment @Inject constructor(
Glide.get(requireContext()).clearMemory()
session.fileService().clearCache()
var newSize: Int
var newSize: Long
withContext(Dispatchers.IO) {
// On BG thread
@ -261,7 +261,7 @@ class VectorSettingsGeneralFragment @Inject constructor(
newSize += session.fileService().getCacheSize()
}
it.summary = TextUtils.formatFileSize(requireContext(), newSize.toLong())
it.summary = TextUtils.formatFileSize(requireContext(), newSize)
hideLoadingView()
}