From 6a94feaf0ee00c86e8c6935c241792393067f216 Mon Sep 17 00:00:00 2001 From: Paul Akhamiogu Date: Wed, 25 Aug 2021 00:37:18 +0100 Subject: [PATCH] first attempt --- app/build.gradle | 3 +- .../filemanager/pro/extensions/Context.kt | 3 +- .../pro/fragments/ItemsFragment.kt | 61 +++++++++++++++---- settings.gradle | 2 + 4 files changed, 54 insertions(+), 15 deletions(-) diff --git a/app/build.gradle b/app/build.gradle index 7e6382db..3efe573d 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -58,7 +58,8 @@ android { } dependencies { - implementation 'com.github.SimpleMobileTools:Simple-Commons:16ae1d2c03' +// implementation 'com.github.SimpleMobileTools:Simple-Commons:e56c724d04' + implementation project(":commons") implementation 'com.github.Stericson:RootTools:df729dcb13' implementation 'com.github.Stericson:RootShell:1.6' implementation 'com.alexvasilkov:gesture-views:2.5.2' diff --git a/app/src/main/kotlin/com/simplemobiletools/filemanager/pro/extensions/Context.kt b/app/src/main/kotlin/com/simplemobiletools/filemanager/pro/extensions/Context.kt index 07b1f5f5..0e30de4a 100644 --- a/app/src/main/kotlin/com/simplemobiletools/filemanager/pro/extensions/Context.kt +++ b/app/src/main/kotlin/com/simplemobiletools/filemanager/pro/extensions/Context.kt @@ -3,8 +3,9 @@ package com.simplemobiletools.filemanager.pro.extensions import android.content.Context import com.simplemobiletools.commons.extensions.isPathOnOTG import com.simplemobiletools.commons.extensions.isPathOnSD +import com.simplemobiletools.commons.extensions.otgPath +import com.simplemobiletools.commons.extensions.sdCardPath import com.simplemobiletools.filemanager.pro.helpers.Config val Context.config: Config get() = Config.newInstance(applicationContext) - fun Context.isPathOnRoot(path: String) = !(path.startsWith(config.internalStoragePath) || isPathOnOTG(path) || (isPathOnSD(path))) diff --git a/app/src/main/kotlin/com/simplemobiletools/filemanager/pro/fragments/ItemsFragment.kt b/app/src/main/kotlin/com/simplemobiletools/filemanager/pro/fragments/ItemsFragment.kt index e935585a..4e6d22b3 100644 --- a/app/src/main/kotlin/com/simplemobiletools/filemanager/pro/fragments/ItemsFragment.kt +++ b/app/src/main/kotlin/com/simplemobiletools/filemanager/pro/fragments/ItemsFragment.kt @@ -3,6 +3,7 @@ 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 @@ -23,12 +24,13 @@ import com.simplemobiletools.filemanager.pro.helpers.MAX_COLUMN_COUNT import com.simplemobiletools.filemanager.pro.helpers.RootHelpers import com.simplemobiletools.filemanager.pro.interfaces.ItemOperationsListener import com.simplemobiletools.filemanager.pro.models.ListItem -import kotlinx.android.synthetic.main.items_fragment.view.* import java.io.File import java.util.* import kotlin.collections.ArrayList +import kotlinx.android.synthetic.main.items_fragment.view.* -class ItemsFragment(context: Context, attributeSet: AttributeSet) : MyViewPagerFragment(context, attributeSet), ItemOperationsListener, Breadcrumbs.BreadcrumbsListener { +class ItemsFragment(context: Context, attributeSet: AttributeSet) : MyViewPagerFragment(context, attributeSet), ItemOperationsListener, + Breadcrumbs.BreadcrumbsListener { private var showHidden = false private var skipItemUpdating = false private var isSearchOpen = false @@ -156,18 +158,47 @@ class ItemsFragment(context: Context, attributeSet: AttributeSet) : MyViewPagerF private fun getItems(path: String, callback: (originalPath: String, items: ArrayList) -> Unit) { skipItemUpdating = false - 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)) + 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 + 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) } } } @@ -526,4 +557,8 @@ class ItemsFragment(context: Context, attributeSet: AttributeSet) : MyViewPagerF override fun selectedPaths(paths: ArrayList) { (activity as MainActivity).pickedPaths(paths) } + + companion object { + private const val TAG = "ItemsFragment" + } } diff --git a/settings.gradle b/settings.gradle index e7b4def4..772c2522 100644 --- a/settings.gradle +++ b/settings.gradle @@ -1 +1,3 @@ include ':app' +include ':commons' +project(":commons").projectDir = new File("/Users/cyberman/StudioProjects/Simple-Commons/commons")