Ensure SDCard files get scanned on StorageFragment

This commit is contained in:
Ensar Sarajčić 2023-09-07 11:21:00 +02:00
parent b58e509633
commit 4cca280de7

View file

@ -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<MyViewPagerFragment.StorageInnerBinding>(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<String>()
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 {