Ensure SDCard files get scanned on StorageFragment
This commit is contained in:
parent
b58e509633
commit
4cca280de7
|
@ -6,6 +6,7 @@ import android.app.usage.StorageStatsManager
|
||||||
import android.content.ContentResolver
|
import android.content.ContentResolver
|
||||||
import android.content.Context
|
import android.content.Context
|
||||||
import android.content.Intent
|
import android.content.Intent
|
||||||
|
import android.media.MediaScannerConnection
|
||||||
import android.os.Handler
|
import android.os.Handler
|
||||||
import android.os.Looper
|
import android.os.Looper
|
||||||
import android.os.storage.StorageManager
|
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.helpers.*
|
||||||
import com.simplemobiletools.filemanager.pro.interfaces.ItemOperationsListener
|
import com.simplemobiletools.filemanager.pro.interfaces.ItemOperationsListener
|
||||||
import com.simplemobiletools.filemanager.pro.models.ListItem
|
import com.simplemobiletools.filemanager.pro.models.ListItem
|
||||||
|
import java.io.File
|
||||||
import java.util.*
|
import java.util.*
|
||||||
|
|
||||||
class StorageFragment(context: Context, attributeSet: AttributeSet) : MyViewPagerFragment<MyViewPagerFragment.StorageInnerBinding>(context, attributeSet),
|
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)
|
volumeName = storageVolume.uuid!!.lowercase(Locale.US)
|
||||||
totalStorageSpace = file.totalSpace
|
totalStorageSpace = file.totalSpace
|
||||||
freeStorageSpace = file.freeSpace
|
freeStorageSpace = file.freeSpace
|
||||||
|
post {
|
||||||
|
ensureBackgroundThread {
|
||||||
|
scanVolume(volumeName, file)
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
post {
|
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) {
|
override fun searchQueryChanged(text: String) {
|
||||||
lastSearchedText = text
|
lastSearchedText = text
|
||||||
binding.apply {
|
binding.apply {
|
||||||
|
|
Loading…
Reference in New Issue