mirror of
https://github.com/SchildiChat/SchildiChat-android.git
synced 2024-12-18 07:11:58 +03:00
Ensure storage is computed in background, to not block display of general settings.
This commit is contained in:
parent
48641769d9
commit
fa47c4b87e
2 changed files with 25 additions and 27 deletions
|
@ -17,6 +17,7 @@
|
|||
package im.vector.app.core.utils
|
||||
|
||||
import android.content.Context
|
||||
import androidx.annotation.WorkerThread
|
||||
import timber.log.Timber
|
||||
import java.io.File
|
||||
import java.util.Locale
|
||||
|
@ -125,6 +126,7 @@ fun getFileExtension(fileUri: String): String? {
|
|||
* Size
|
||||
* ========================================================================================== */
|
||||
|
||||
@WorkerThread
|
||||
fun getSizeOfFiles(root: File): Long {
|
||||
return root.walkTopDown()
|
||||
.onEnter {
|
||||
|
|
|
@ -250,37 +250,28 @@ class VectorSettingsGeneralFragment :
|
|||
|
||||
// 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)) + session.fileService().getCacheSize()
|
||||
|
||||
it.summary = TextUtils.formatFileSize(requireContext(), size.toLong())
|
||||
|
||||
lifecycleScope.launch(Dispatchers.Main) {
|
||||
it.summary = getString(R.string.loading)
|
||||
val size = getCacheSize()
|
||||
it.summary = TextUtils.formatFileSize(requireContext(), size)
|
||||
it.onPreferenceClickListener = Preference.OnPreferenceClickListener {
|
||||
lifecycleScope.launch(Dispatchers.Main) {
|
||||
// On UI Thread
|
||||
displayLoadingView()
|
||||
|
||||
Glide.get(requireContext()).clearMemory()
|
||||
session.fileService().clearCache()
|
||||
|
||||
var newSize: Long
|
||||
|
||||
withContext(Dispatchers.IO) {
|
||||
val newSize = withContext(Dispatchers.IO) {
|
||||
// On BG thread
|
||||
Glide.get(requireContext()).clearDiskCache()
|
||||
|
||||
newSize = getSizeOfFiles(File(requireContext().cacheDir, DiskCache.Factory.DEFAULT_DISK_CACHE_DIR))
|
||||
newSize += session.fileService().getCacheSize()
|
||||
getCacheSize()
|
||||
}
|
||||
|
||||
it.summary = TextUtils.formatFileSize(requireContext(), newSize)
|
||||
|
||||
hideLoadingView()
|
||||
}
|
||||
|
||||
false
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
// Sign out
|
||||
findPreference<VectorPreference>("SETTINGS_SIGN_OUT_KEY")!!
|
||||
.onPreferenceClickListener = Preference.OnPreferenceClickListener {
|
||||
|
@ -292,6 +283,11 @@ class VectorSettingsGeneralFragment :
|
|||
}
|
||||
}
|
||||
|
||||
private suspend fun getCacheSize(): Long = withContext(Dispatchers.IO) {
|
||||
getSizeOfFiles(File(requireContext().cacheDir, DiskCache.Factory.DEFAULT_DISK_CACHE_DIR)) +
|
||||
session.fileService().getCacheSize()
|
||||
}
|
||||
|
||||
override fun onResume() {
|
||||
super.onResume()
|
||||
// Refresh identity server summary
|
||||
|
|
Loading…
Reference in a new issue