Skip to content

Commit 5b1d6ea

Browse files
committed
refresh Storage fragment data on resume
1 parent 149a8e6 commit 5b1d6ea

File tree

6 files changed

+47
-43
lines changed

6 files changed

+47
-43
lines changed

app/src/main/kotlin/com/simplemobiletools/filemanager/pro/activities/MainActivity.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,7 @@ class MainActivity : SimpleActivity() {
9898
}
9999

100100
getAllFragments().forEach {
101-
it?.setupColors(config.textColor, config.primaryColor)
101+
it?.onResume(config.textColor, config.primaryColor)
102102
}
103103

104104
if (storedFontSize != config.fontSize) {

app/src/main/kotlin/com/simplemobiletools/filemanager/pro/adapters/ViewPagerAdapter.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ class ViewPagerAdapter(val activity: SimpleActivity) : PagerAdapter() {
2020

2121
(view as MyViewPagerFragment).apply {
2222
setupFragment(activity)
23-
setupColors(activity.config.textColor, activity.config.primaryColor)
23+
onResume(activity.config.textColor, activity.config.primaryColor)
2424
}
2525

2626
return view

app/src/main/kotlin/com/simplemobiletools/filemanager/pro/fragments/ItemsFragment.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ class ItemsFragment(context: Context, attributeSet: AttributeSet) : MyViewPagerF
4747
}
4848
}
4949

50-
override fun setupColors(textColor: Int, primaryColor: Int) {
50+
override fun onResume(textColor: Int, primaryColor: Int) {
5151
context!!.updateTextColors(this)
5252
items_fastscroller.updatePrimaryColor()
5353
storedItems = ArrayList()

app/src/main/kotlin/com/simplemobiletools/filemanager/pro/fragments/MyViewPagerFragment.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ abstract class MyViewPagerFragment(context: Context, attributeSet: AttributeSet)
3636

3737
abstract fun setupFragment(activity: SimpleActivity)
3838

39-
abstract fun setupColors(textColor: Int, primaryColor: Int)
39+
abstract fun onResume(textColor: Int, primaryColor: Int)
4040

4141
abstract fun refreshFragment()
4242
}

app/src/main/kotlin/com/simplemobiletools/filemanager/pro/fragments/RecentsFragment.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ class RecentsFragment(context: Context, attributeSet: AttributeSet) : MyViewPage
6464
}
6565
}
6666

67-
override fun setupColors(textColor: Int, primaryColor: Int) {
67+
override fun onResume(textColor: Int, primaryColor: Int) {
6868
recents_placeholder.setTextColor(textColor)
6969

7070
getRecyclerAdapter()?.apply {

app/src/main/kotlin/com/simplemobiletools/filemanager/pro/fragments/StorageFragment.kt

Lines changed: 42 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -25,38 +25,7 @@ class StorageFragment(context: Context, attributeSet: AttributeSet) : MyViewPage
2525

2626
override fun setupFragment(activity: SimpleActivity) {
2727
total_space.text = String.format(context.getString(R.string.total_storage), "")
28-
29-
ensureBackgroundThread {
30-
getMainStorageStats(activity)
31-
32-
val filesSize = getSizesByMimeType()
33-
val imagesSize = filesSize[IMAGES]!!
34-
val videosSize = filesSize[VIDEOS]!!
35-
val audioSize = filesSize[AUDIO]!!
36-
val documentsSize = filesSize[DOCUMENTS]!!
37-
val archivesSize = filesSize[ARCHIVES]!!
38-
val othersSize = filesSize[OTHERS]!!
39-
40-
activity.runOnUiThread {
41-
images_size.text = imagesSize.formatSize()
42-
images_progressbar.progress = (imagesSize / SIZE_DIVIDER).toInt()
43-
44-
videos_size.text = videosSize.formatSize()
45-
videos_progressbar.progress = (videosSize / SIZE_DIVIDER).toInt()
46-
47-
audio_size.text = audioSize.formatSize()
48-
audio_progressbar.progress = (audioSize / SIZE_DIVIDER).toInt()
49-
50-
documents_size.text = documentsSize.formatSize()
51-
documents_progressbar.progress = (documentsSize / SIZE_DIVIDER).toInt()
52-
53-
archives_size.text = archivesSize.formatSize()
54-
archives_progressbar.progress = (archivesSize / SIZE_DIVIDER).toInt()
55-
56-
others_size.text = othersSize.formatSize()
57-
others_progressbar.progress = (othersSize / SIZE_DIVIDER).toInt()
58-
}
59-
}
28+
getSizes()
6029

6130
free_space_holder.setOnClickListener {
6231
try {
@@ -77,7 +46,8 @@ class StorageFragment(context: Context, attributeSet: AttributeSet) : MyViewPage
7746

7847
override fun refreshFragment() {}
7948

80-
override fun setupColors(textColor: Int, primaryColor: Int) {
49+
override fun onResume(textColor: Int, primaryColor: Int) {
50+
getSizes()
8151
context.updateTextColors(storage_fragment)
8252

8353
main_storage_usage_progressbar.setIndicatorColor(primaryColor)
@@ -115,6 +85,40 @@ class StorageFragment(context: Context, attributeSet: AttributeSet) : MyViewPage
11585
}
11686
}
11787

88+
private fun getSizes() {
89+
ensureBackgroundThread {
90+
getMainStorageStats(context)
91+
92+
val filesSize = getSizesByMimeType()
93+
val imagesSize = filesSize[IMAGES]!!
94+
val videosSize = filesSize[VIDEOS]!!
95+
val audioSize = filesSize[AUDIO]!!
96+
val documentsSize = filesSize[DOCUMENTS]!!
97+
val archivesSize = filesSize[ARCHIVES]!!
98+
val othersSize = filesSize[OTHERS]!!
99+
100+
post {
101+
images_size.text = imagesSize.formatSize()
102+
images_progressbar.progress = (imagesSize / SIZE_DIVIDER).toInt()
103+
104+
videos_size.text = videosSize.formatSize()
105+
videos_progressbar.progress = (videosSize / SIZE_DIVIDER).toInt()
106+
107+
audio_size.text = audioSize.formatSize()
108+
audio_progressbar.progress = (audioSize / SIZE_DIVIDER).toInt()
109+
110+
documents_size.text = documentsSize.formatSize()
111+
documents_progressbar.progress = (documentsSize / SIZE_DIVIDER).toInt()
112+
113+
archives_size.text = archivesSize.formatSize()
114+
archives_progressbar.progress = (archivesSize / SIZE_DIVIDER).toInt()
115+
116+
others_size.text = othersSize.formatSize()
117+
others_progressbar.progress = (othersSize / SIZE_DIVIDER).toInt()
118+
}
119+
}
120+
}
121+
118122
private fun getSizesByMimeType(): HashMap<String, Long> {
119123
val uri = MediaStore.Files.getContentUri("external")
120124
val projection = arrayOf(
@@ -177,20 +181,20 @@ class StorageFragment(context: Context, attributeSet: AttributeSet) : MyViewPage
177181
}
178182

179183
@SuppressLint("NewApi")
180-
private fun getMainStorageStats(activity: SimpleActivity) {
181-
val externalDirs = activity.getExternalFilesDirs(null)
182-
val storageManager = activity.getSystemService(AppCompatActivity.STORAGE_SERVICE) as StorageManager
184+
private fun getMainStorageStats(context: Context) {
185+
val externalDirs = context.getExternalFilesDirs(null)
186+
val storageManager = context.getSystemService(AppCompatActivity.STORAGE_SERVICE) as StorageManager
183187

184188
externalDirs.forEach { file ->
185189
val storageVolume = storageManager.getStorageVolume(file) ?: return
186190
if (storageVolume.isPrimary) {
187191
// internal storage
188-
val storageStatsManager = activity.getSystemService(AppCompatActivity.STORAGE_STATS_SERVICE) as StorageStatsManager
192+
val storageStatsManager = context.getSystemService(AppCompatActivity.STORAGE_STATS_SERVICE) as StorageStatsManager
189193
val uuid = StorageManager.UUID_DEFAULT
190194
val totalSpace = storageStatsManager.getTotalBytes(uuid)
191195
val freeSpace = storageStatsManager.getFreeBytes(uuid)
192196

193-
activity.runOnUiThread {
197+
post {
194198
arrayOf(
195199
main_storage_usage_progressbar, images_progressbar, videos_progressbar, audio_progressbar, documents_progressbar,
196200
archives_progressbar, others_progressbar

0 commit comments

Comments
 (0)