Merge pull request #5396 from tgloureiro/develop

Fix Media cache size with negative values in the General Settings screen
This commit is contained in:
Benoit Marty 2022-03-01 18:29:37 +01:00 committed by GitHub
commit d4caad1665
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 8 additions and 7 deletions

1
changelog.d/5394.bugfix Normal file
View File

@ -0,0 +1 @@
Fix incorrect media cache size in settings

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()
}