mirror of
https://github.com/SimpleMobileTools/Simple-File-Manager.git
synced 2025-06-05 22:09:15 +02:00
read files from Andoid/data and Android/obb
This commit is contained in:
@ -3,7 +3,6 @@ package com.simplemobiletools.filemanager.pro.fragments
|
|||||||
import android.content.Context
|
import android.content.Context
|
||||||
import android.os.Parcelable
|
import android.os.Parcelable
|
||||||
import android.util.AttributeSet
|
import android.util.AttributeSet
|
||||||
import android.util.Log
|
|
||||||
import androidx.recyclerview.widget.GridLayoutManager
|
import androidx.recyclerview.widget.GridLayoutManager
|
||||||
import com.simplemobiletools.commons.activities.BaseSimpleActivity
|
import com.simplemobiletools.commons.activities.BaseSimpleActivity
|
||||||
import com.simplemobiletools.commons.dialogs.StoragePickerDialog
|
import com.simplemobiletools.commons.dialogs.StoragePickerDialog
|
||||||
@ -120,8 +119,10 @@ class ItemsFragment(context: Context, attributeSet: AttributeSet) : MyViewPagerF
|
|||||||
breadcrumbs.updateFontSize(context!!.getTextSize())
|
breadcrumbs.updateFontSize(context!!.getTextSize())
|
||||||
}
|
}
|
||||||
|
|
||||||
ItemsAdapter(activity as SimpleActivity, storedItems, this, items_list, isPickMultipleIntent, items_fastscroller,
|
ItemsAdapter(
|
||||||
items_swipe_refresh) {
|
activity as SimpleActivity, storedItems, this, items_list, isPickMultipleIntent, items_fastscroller,
|
||||||
|
items_swipe_refresh
|
||||||
|
) {
|
||||||
if ((it as? ListItem)?.isSectionTitle == true) {
|
if ((it as? ListItem)?.isSectionTitle == true) {
|
||||||
openDirectory(it.mPath)
|
openDirectory(it.mPath)
|
||||||
searchClosed()
|
searchClosed()
|
||||||
@ -158,47 +159,18 @@ class ItemsFragment(context: Context, attributeSet: AttributeSet) : MyViewPagerF
|
|||||||
|
|
||||||
private fun getItems(path: String, callback: (originalPath: String, items: ArrayList<ListItem>) -> Unit) {
|
private fun getItems(path: String, callback: (originalPath: String, items: ArrayList<ListItem>) -> Unit) {
|
||||||
skipItemUpdating = false
|
skipItemUpdating = false
|
||||||
Log.d(TAG, "getItems: $path")
|
ensureBackgroundThread {
|
||||||
|
if (activity?.isDestroyed == false && activity?.isFinishing == false) {
|
||||||
if (isRPlus() && context.isAndroidDataRoot(path)) {
|
val config = context!!.config
|
||||||
activity?.handleSAFDialog(path) { granted ->
|
if (context!!.isPathOnOTG(path) && config.OTGTreeUri.isNotEmpty()) {
|
||||||
Log.d(TAG, "getItems: $granted")
|
val getProperFileSize = context!!.config.getFolderSorting(currentPath) and SORT_BY_SIZE != 0
|
||||||
if (!granted) {
|
context!!.getOTGItems(path, config.shouldShowHidden, getProperFileSize) {
|
||||||
return@handleSAFDialog
|
callback(path, getListItemsFromFileDirItems(it))
|
||||||
}
|
|
||||||
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
|
|
||||||
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)) {
|
|
||||||
getRegularItemsOf(path, callback)
|
|
||||||
} else {
|
|
||||||
RootHelpers(activity!!).getFiles(path, callback)
|
|
||||||
}
|
}
|
||||||
|
} else if (!config.enableRootAccess || !context!!.isPathOnRoot(path)) {
|
||||||
|
getRegularItemsOf(path, callback)
|
||||||
|
} else {
|
||||||
|
RootHelpers(activity!!).getFiles(path, callback)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -206,33 +178,47 @@ class ItemsFragment(context: Context, attributeSet: AttributeSet) : MyViewPagerF
|
|||||||
|
|
||||||
private fun getRegularItemsOf(path: String, callback: (originalPath: String, items: ArrayList<ListItem>) -> Unit) {
|
private fun getRegularItemsOf(path: String, callback: (originalPath: String, items: ArrayList<ListItem>) -> Unit) {
|
||||||
val items = ArrayList<ListItem>()
|
val items = ArrayList<ListItem>()
|
||||||
val files = File(path).listFiles()?.filterNotNull()
|
|
||||||
if (context == null || files == null) {
|
if (context == null) {
|
||||||
callback(path, items)
|
callback(path, items)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
val isSortingBySize = context!!.config.getFolderSorting(currentPath) and SORT_BY_SIZE != 0
|
val isSortingBySize = context!!.config.getFolderSorting(currentPath) and SORT_BY_SIZE != 0
|
||||||
val getProperChildCount = context!!.config.getFolderViewType(currentPath) == VIEW_TYPE_LIST
|
val getProperChildCount = context!!.config.getFolderViewType(currentPath) == VIEW_TYPE_LIST
|
||||||
val lastModifieds = context!!.getFolderLastModifieds(path)
|
|
||||||
|
|
||||||
for (file in files) {
|
if (isRPlus() && context.isSAFOnlyRoot(path)) {
|
||||||
val fileDirItem = getFileDirItemFromFile(file, isSortingBySize, lastModifieds, false)
|
activity?.handlePrimarySAFDialog(path) {
|
||||||
if (fileDirItem != null) {
|
context.getStorageItemsWithTreeUri(path, context.config.shouldShowHidden, getProperChildCount) {
|
||||||
items.add(fileDirItem)
|
callback(path, getListItemsFromFileDirItems(it))
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
} else {
|
||||||
|
val files = File(path).listFiles()?.filterNotNull()
|
||||||
|
if (files == null) {
|
||||||
|
callback(path, items)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
val lastModifieds = context!!.getFolderLastModifieds(path)
|
||||||
|
|
||||||
// send out the initial item list asap, get proper child count asynchronously as it can be slow
|
for (file in files) {
|
||||||
callback(path, items)
|
val fileDirItem = getFileDirItemFromFile(file, isSortingBySize, lastModifieds, false)
|
||||||
|
if (fileDirItem != null) {
|
||||||
|
items.add(fileDirItem)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if (getProperChildCount) {
|
// send out the initial item list asap, get proper child count asynchronously as it can be slow
|
||||||
items.filter { it.mIsDirectory }.forEach {
|
callback(path, items)
|
||||||
if (context != null) {
|
|
||||||
val childrenCount = it.getDirectChildrenCount(context!!, showHidden)
|
if (getProperChildCount) {
|
||||||
if (childrenCount != 0) {
|
items.filter { it.mIsDirectory }.forEach {
|
||||||
activity?.runOnUiThread {
|
if (context != null) {
|
||||||
getRecyclerAdapter()?.updateChildCount(it.mPath, childrenCount)
|
val childrenCount = it.getDirectChildrenCount(context!!, showHidden)
|
||||||
|
if (childrenCount != 0) {
|
||||||
|
activity?.runOnUiThread {
|
||||||
|
getRecyclerAdapter()?.updateChildCount(it.mPath, childrenCount)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -557,8 +543,4 @@ class ItemsFragment(context: Context, attributeSet: AttributeSet) : MyViewPagerF
|
|||||||
override fun selectedPaths(paths: ArrayList<String>) {
|
override fun selectedPaths(paths: ArrayList<String>) {
|
||||||
(activity as MainActivity).pickedPaths(paths)
|
(activity as MainActivity).pickedPaths(paths)
|
||||||
}
|
}
|
||||||
|
|
||||||
companion object {
|
|
||||||
private const val TAG = "ItemsFragment"
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user