Also Clear download cache when clearing media

This commit is contained in:
Valere 2020-06-25 13:44:29 +02:00 committed by Benoit Marty
parent 4254db5cc0
commit 04b6b3674d
3 changed files with 20 additions and 1 deletions

View File

@ -71,4 +71,8 @@ interface FileService {
fun getTemporarySharableURI(mxcUrl: String, mimeType: String?): Uri?
fun fileState(mxcUrl: String, mimeType: String?) : FileState
fun clearCache()
fun getCacheSize() : Int
}

View File

@ -238,4 +238,17 @@ internal class DefaultFileService @Inject constructor(
file
}
}
override fun getCacheSize(): Int {
return downloadFolder.walkTopDown()
.onEnter {
Timber.v("Get size of ${it.absolutePath}")
true
}
.sumBy { it.length().toInt() }
}
override fun clearCache() {
downloadFolder.deleteRecursively()
}
}

View File

@ -237,7 +237,7 @@ class VectorSettingsGeneralFragment : VectorSettingsBaseFragment() {
// clear medias cache
findPreference<VectorPreference>(VectorPreferences.SETTINGS_CLEAR_MEDIA_CACHE_PREFERENCE_KEY)!!.let {
val size = getSizeOfFiles(File(requireContext().cacheDir, DiskCache.Factory.DEFAULT_DISK_CACHE_DIR))
val size = getSizeOfFiles(File(requireContext().cacheDir, DiskCache.Factory.DEFAULT_DISK_CACHE_DIR)) + session.getCacheSize()
it.summary = TextUtils.formatFileSize(requireContext(), size.toLong())
@ -247,6 +247,7 @@ class VectorSettingsGeneralFragment : VectorSettingsBaseFragment() {
displayLoadingView()
Glide.get(requireContext()).clearMemory()
session.clearCache()
var newSize = 0
@ -255,6 +256,7 @@ class VectorSettingsGeneralFragment : VectorSettingsBaseFragment() {
Glide.get(requireContext()).clearDiskCache()
newSize = getSizeOfFiles(File(requireContext().cacheDir, DiskCache.Factory.DEFAULT_DISK_CACHE_DIR))
newSize += session.getCacheSize()
}
it.summary = TextUtils.formatFileSize(requireContext(), newSize.toLong())