read files from Andoid/data and Android/obb

This commit is contained in:
darthpaul 2021-10-23 23:03:34 +01:00
parent 3a52528a54
commit 471d77e19f

View File

@ -3,7 +3,6 @@ package com.simplemobiletools.filemanager.pro.fragments
import android.content.Context
import android.os.Parcelable
import android.util.AttributeSet
import android.util.Log
import androidx.recyclerview.widget.GridLayoutManager
import com.simplemobiletools.commons.activities.BaseSimpleActivity
import com.simplemobiletools.commons.dialogs.StoragePickerDialog
@ -120,8 +119,10 @@ class ItemsFragment(context: Context, attributeSet: AttributeSet) : MyViewPagerF
breadcrumbs.updateFontSize(context!!.getTextSize())
}
ItemsAdapter(activity as SimpleActivity, storedItems, this, items_list, isPickMultipleIntent, items_fastscroller,
items_swipe_refresh) {
ItemsAdapter(
activity as SimpleActivity, storedItems, this, items_list, isPickMultipleIntent, items_fastscroller,
items_swipe_refresh
) {
if ((it as? ListItem)?.isSectionTitle == true) {
openDirectory(it.mPath)
searchClosed()
@ -158,34 +159,6 @@ class ItemsFragment(context: Context, attributeSet: AttributeSet) : MyViewPagerF
private fun getItems(path: String, callback: (originalPath: String, items: ArrayList<ListItem>) -> Unit) {
skipItemUpdating = false
Log.d(TAG, "getItems: $path")
if (isRPlus() && context.isAndroidDataRoot(path)) {
activity?.handleSAFDialog(path) { granted ->
Log.d(TAG, "getItems: $granted")
if (!granted) {
return@handleSAFDialog
}
ensureBackgroundThread {
if (activity?.isDestroyed == false && activity?.isFinishing == false) {
val config = context!!.config
if (context!!.isPathOnOTG(path) && config.OTGTreeUri.isNotEmpty()) {
val getProperFileSize = context!!.config.getFolderSorting(currentPath) and SORT_BY_SIZE != 0
context!!.getOTGItems(path, config.shouldShowHidden, getProperFileSize) {
callback(path, getListItemsFromFileDirItems(it))
}
}else if (!config.enableRootAccess || !context!!.isPathOnRoot(path)) {
val getProperFileSize = context!!.config.getFolderSorting(currentPath) and SORT_BY_SIZE != 0
context!!.getStorageItems(path, config.shouldShowHidden, getProperFileSize){
callback(path, getListItemsFromFileDirItems(it))
}
} else {
RootHelpers(activity!!).getFiles(path, callback)
}
}
}
}
} else {
ensureBackgroundThread {
if (activity?.isDestroyed == false && activity?.isFinishing == false) {
val config = context!!.config
@ -202,18 +175,30 @@ class ItemsFragment(context: Context, attributeSet: AttributeSet) : MyViewPagerF
}
}
}
}
private fun getRegularItemsOf(path: String, callback: (originalPath: String, items: ArrayList<ListItem>) -> Unit) {
val items = ArrayList<ListItem>()
val files = File(path).listFiles()?.filterNotNull()
if (context == null || files == null) {
if (context == null) {
callback(path, items)
return
}
val isSortingBySize = context!!.config.getFolderSorting(currentPath) and SORT_BY_SIZE != 0
val getProperChildCount = context!!.config.getFolderViewType(currentPath) == VIEW_TYPE_LIST
if (isRPlus() && context.isSAFOnlyRoot(path)) {
activity?.handlePrimarySAFDialog(path) {
context.getStorageItemsWithTreeUri(path, context.config.shouldShowHidden, getProperChildCount) {
callback(path, getListItemsFromFileDirItems(it))
}
}
} else {
val files = File(path).listFiles()?.filterNotNull()
if (files == null) {
callback(path, items)
return
}
val lastModifieds = context!!.getFolderLastModifieds(path)
for (file in files) {
@ -239,6 +224,7 @@ class ItemsFragment(context: Context, attributeSet: AttributeSet) : MyViewPagerF
}
}
}
}
private fun getFileDirItemFromFile(file: File, isSortingBySize: Boolean, lastModifieds: HashMap<String, Long>, getProperChildCount: Boolean): ListItem? {
val curPath = file.absolutePath
@ -557,8 +543,4 @@ class ItemsFragment(context: Context, attributeSet: AttributeSet) : MyViewPagerF
override fun selectedPaths(paths: ArrayList<String>) {
(activity as MainActivity).pickedPaths(paths)
}
companion object {
private const val TAG = "ItemsFragment"
}
}