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 5edf93f4..fc4997f4 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 @@ -6,6 +6,7 @@ import android.app.usage.StorageStatsManager import android.content.ContentResolver import android.content.Context import android.content.Intent +import android.media.MediaScannerConnection import android.os.Handler import android.os.Looper import android.os.storage.StorageManager @@ -32,6 +33,7 @@ import com.simplemobiletools.filemanager.pro.extensions.getAllVolumeNames import com.simplemobiletools.filemanager.pro.helpers.* import com.simplemobiletools.filemanager.pro.interfaces.ItemOperationsListener import com.simplemobiletools.filemanager.pro.models.ListItem +import java.io.File import java.util.* class StorageFragment(context: Context, attributeSet: AttributeSet) : MyViewPagerFragment(context, attributeSet), @@ -292,6 +294,11 @@ class StorageFragment(context: Context, attributeSet: AttributeSet) : MyViewPage volumeName = storageVolume.uuid!!.lowercase(Locale.US) totalStorageSpace = file.totalSpace freeStorageSpace = file.freeSpace + post { + ensureBackgroundThread { + scanVolume(volumeName, file) + } + } } post { @@ -314,6 +321,22 @@ class StorageFragment(context: Context, attributeSet: AttributeSet) : MyViewPage } } + private fun scanVolume(volumeName: String, root: File) { + val paths = mutableListOf() + if (context.isPathOnSD(root.path)) { + File(context.config.sdCardPath).walkBottomUp().forEach { + paths.add(it.path) + } + } + var callbackCount = 0 + MediaScannerConnection.scanFile(context, paths.toTypedArray(), null) { _, _ -> + callbackCount++ + if (callbackCount == paths.size) { + getSizes(volumeName) + } + } + } + override fun searchQueryChanged(text: String) { lastSearchedText = text binding.apply {