mirror of
https://github.com/element-hq/element-android
synced 2024-11-28 13:38:49 +03:00
Also Clear download cache when clearing media
This commit is contained in:
parent
4254db5cc0
commit
04b6b3674d
3 changed files with 20 additions and 1 deletions
|
@ -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
|
||||
}
|
||||
|
|
|
@ -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()
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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())
|
||||
|
|
Loading…
Reference in a new issue