diff --git a/app/src/main/kotlin/com/simplemobiletools/filemanager/pro/activities/MainActivity.kt b/app/src/main/kotlin/com/simplemobiletools/filemanager/pro/activities/MainActivity.kt index 6f7c7b82..12e356e4 100644 --- a/app/src/main/kotlin/com/simplemobiletools/filemanager/pro/activities/MainActivity.kt +++ b/app/src/main/kotlin/com/simplemobiletools/filemanager/pro/activities/MainActivity.kt @@ -98,7 +98,7 @@ class MainActivity : SimpleActivity() { } getAllFragments().forEach { - it?.setupColors(config.textColor, config.primaryColor) + it?.onResume(config.textColor, config.primaryColor) } if (storedFontSize != config.fontSize) { diff --git a/app/src/main/kotlin/com/simplemobiletools/filemanager/pro/adapters/ViewPagerAdapter.kt b/app/src/main/kotlin/com/simplemobiletools/filemanager/pro/adapters/ViewPagerAdapter.kt index 36ced7d7..95fa3e75 100644 --- a/app/src/main/kotlin/com/simplemobiletools/filemanager/pro/adapters/ViewPagerAdapter.kt +++ b/app/src/main/kotlin/com/simplemobiletools/filemanager/pro/adapters/ViewPagerAdapter.kt @@ -20,7 +20,7 @@ class ViewPagerAdapter(val activity: SimpleActivity) : PagerAdapter() { (view as MyViewPagerFragment).apply { setupFragment(activity) - setupColors(activity.config.textColor, activity.config.primaryColor) + onResume(activity.config.textColor, activity.config.primaryColor) } return view diff --git a/app/src/main/kotlin/com/simplemobiletools/filemanager/pro/fragments/ItemsFragment.kt b/app/src/main/kotlin/com/simplemobiletools/filemanager/pro/fragments/ItemsFragment.kt index 8fd14aac..4b0cf9fb 100644 --- a/app/src/main/kotlin/com/simplemobiletools/filemanager/pro/fragments/ItemsFragment.kt +++ b/app/src/main/kotlin/com/simplemobiletools/filemanager/pro/fragments/ItemsFragment.kt @@ -47,7 +47,7 @@ class ItemsFragment(context: Context, attributeSet: AttributeSet) : MyViewPagerF } } - override fun setupColors(textColor: Int, primaryColor: Int) { + override fun onResume(textColor: Int, primaryColor: Int) { context!!.updateTextColors(this) items_fastscroller.updatePrimaryColor() storedItems = ArrayList() diff --git a/app/src/main/kotlin/com/simplemobiletools/filemanager/pro/fragments/MyViewPagerFragment.kt b/app/src/main/kotlin/com/simplemobiletools/filemanager/pro/fragments/MyViewPagerFragment.kt index f254ca38..28d501a7 100644 --- a/app/src/main/kotlin/com/simplemobiletools/filemanager/pro/fragments/MyViewPagerFragment.kt +++ b/app/src/main/kotlin/com/simplemobiletools/filemanager/pro/fragments/MyViewPagerFragment.kt @@ -36,7 +36,7 @@ abstract class MyViewPagerFragment(context: Context, attributeSet: AttributeSet) abstract fun setupFragment(activity: SimpleActivity) - abstract fun setupColors(textColor: Int, primaryColor: Int) + abstract fun onResume(textColor: Int, primaryColor: Int) abstract fun refreshFragment() } diff --git a/app/src/main/kotlin/com/simplemobiletools/filemanager/pro/fragments/RecentsFragment.kt b/app/src/main/kotlin/com/simplemobiletools/filemanager/pro/fragments/RecentsFragment.kt index 66098d98..297b6975 100644 --- a/app/src/main/kotlin/com/simplemobiletools/filemanager/pro/fragments/RecentsFragment.kt +++ b/app/src/main/kotlin/com/simplemobiletools/filemanager/pro/fragments/RecentsFragment.kt @@ -64,7 +64,7 @@ class RecentsFragment(context: Context, attributeSet: AttributeSet) : MyViewPage } } - override fun setupColors(textColor: Int, primaryColor: Int) { + override fun onResume(textColor: Int, primaryColor: Int) { recents_placeholder.setTextColor(textColor) getRecyclerAdapter()?.apply { diff --git a/app/src/main/kotlin/com/simplemobiletools/filemanager/pro/fragments/StorageFragment.kt b/app/src/main/kotlin/com/simplemobiletools/filemanager/pro/fragments/StorageFragment.kt index 669850d3..1a2cceb3 100644 --- a/app/src/main/kotlin/com/simplemobiletools/filemanager/pro/fragments/StorageFragment.kt +++ b/app/src/main/kotlin/com/simplemobiletools/filemanager/pro/fragments/StorageFragment.kt @@ -25,38 +25,7 @@ class StorageFragment(context: Context, attributeSet: AttributeSet) : MyViewPage override fun setupFragment(activity: SimpleActivity) { total_space.text = String.format(context.getString(R.string.total_storage), "…") - - ensureBackgroundThread { - getMainStorageStats(activity) - - val filesSize = getSizesByMimeType() - val imagesSize = filesSize[IMAGES]!! - val videosSize = filesSize[VIDEOS]!! - val audioSize = filesSize[AUDIO]!! - val documentsSize = filesSize[DOCUMENTS]!! - val archivesSize = filesSize[ARCHIVES]!! - val othersSize = filesSize[OTHERS]!! - - activity.runOnUiThread { - images_size.text = imagesSize.formatSize() - images_progressbar.progress = (imagesSize / SIZE_DIVIDER).toInt() - - videos_size.text = videosSize.formatSize() - videos_progressbar.progress = (videosSize / SIZE_DIVIDER).toInt() - - audio_size.text = audioSize.formatSize() - audio_progressbar.progress = (audioSize / SIZE_DIVIDER).toInt() - - documents_size.text = documentsSize.formatSize() - documents_progressbar.progress = (documentsSize / SIZE_DIVIDER).toInt() - - archives_size.text = archivesSize.formatSize() - archives_progressbar.progress = (archivesSize / SIZE_DIVIDER).toInt() - - others_size.text = othersSize.formatSize() - others_progressbar.progress = (othersSize / SIZE_DIVIDER).toInt() - } - } + getSizes() free_space_holder.setOnClickListener { try { @@ -77,7 +46,8 @@ class StorageFragment(context: Context, attributeSet: AttributeSet) : MyViewPage override fun refreshFragment() {} - override fun setupColors(textColor: Int, primaryColor: Int) { + override fun onResume(textColor: Int, primaryColor: Int) { + getSizes() context.updateTextColors(storage_fragment) main_storage_usage_progressbar.setIndicatorColor(primaryColor) @@ -115,6 +85,40 @@ class StorageFragment(context: Context, attributeSet: AttributeSet) : MyViewPage } } + private fun getSizes() { + ensureBackgroundThread { + getMainStorageStats(context) + + val filesSize = getSizesByMimeType() + val imagesSize = filesSize[IMAGES]!! + val videosSize = filesSize[VIDEOS]!! + val audioSize = filesSize[AUDIO]!! + val documentsSize = filesSize[DOCUMENTS]!! + val archivesSize = filesSize[ARCHIVES]!! + val othersSize = filesSize[OTHERS]!! + + post { + images_size.text = imagesSize.formatSize() + images_progressbar.progress = (imagesSize / SIZE_DIVIDER).toInt() + + videos_size.text = videosSize.formatSize() + videos_progressbar.progress = (videosSize / SIZE_DIVIDER).toInt() + + audio_size.text = audioSize.formatSize() + audio_progressbar.progress = (audioSize / SIZE_DIVIDER).toInt() + + documents_size.text = documentsSize.formatSize() + documents_progressbar.progress = (documentsSize / SIZE_DIVIDER).toInt() + + archives_size.text = archivesSize.formatSize() + archives_progressbar.progress = (archivesSize / SIZE_DIVIDER).toInt() + + others_size.text = othersSize.formatSize() + others_progressbar.progress = (othersSize / SIZE_DIVIDER).toInt() + } + } + } + private fun getSizesByMimeType(): HashMap { val uri = MediaStore.Files.getContentUri("external") val projection = arrayOf( @@ -177,20 +181,20 @@ class StorageFragment(context: Context, attributeSet: AttributeSet) : MyViewPage } @SuppressLint("NewApi") - private fun getMainStorageStats(activity: SimpleActivity) { - val externalDirs = activity.getExternalFilesDirs(null) - val storageManager = activity.getSystemService(AppCompatActivity.STORAGE_SERVICE) as StorageManager + private fun getMainStorageStats(context: Context) { + val externalDirs = context.getExternalFilesDirs(null) + val storageManager = context.getSystemService(AppCompatActivity.STORAGE_SERVICE) as StorageManager externalDirs.forEach { file -> val storageVolume = storageManager.getStorageVolume(file) ?: return if (storageVolume.isPrimary) { // internal storage - val storageStatsManager = activity.getSystemService(AppCompatActivity.STORAGE_STATS_SERVICE) as StorageStatsManager + val storageStatsManager = context.getSystemService(AppCompatActivity.STORAGE_STATS_SERVICE) as StorageStatsManager val uuid = StorageManager.UUID_DEFAULT val totalSpace = storageStatsManager.getTotalBytes(uuid) val freeSpace = storageStatsManager.getFreeBytes(uuid) - activity.runOnUiThread { + post { arrayOf( main_storage_usage_progressbar, images_progressbar, videos_progressbar, audio_progressbar, documents_progressbar, archives_progressbar, others_progressbar