From 57aa9054f244428b541fda079720adece8301224 Mon Sep 17 00:00:00 2001 From: tibbi Date: Sun, 3 Sep 2017 19:57:01 +0200 Subject: [PATCH] split file fetching between regular and root folders --- .../filemanager/fragments/ItemsFragment.kt | 50 +++++++++++++------ 1 file changed, 34 insertions(+), 16 deletions(-) diff --git a/app/src/main/kotlin/com/simplemobiletools/filemanager/fragments/ItemsFragment.kt b/app/src/main/kotlin/com/simplemobiletools/filemanager/fragments/ItemsFragment.kt index 2a14308a..14223405 100644 --- a/app/src/main/kotlin/com/simplemobiletools/filemanager/fragments/ItemsFragment.kt +++ b/app/src/main/kotlin/com/simplemobiletools/filemanager/fragments/ItemsFragment.kt @@ -40,12 +40,12 @@ class ItemsFragment : Fragment(), ItemsAdapter.ItemOperationsListener { override fun onCreateView(inflater: LayoutInflater?, container: ViewGroup?, savedInstanceState: Bundle?): View { fragmentView = inflater!!.inflate(R.layout.items_fragment, container, false)!! + storeConfigVariables() return fragmentView } override fun onViewCreated(view: View?, savedInstanceState: Bundle?) { super.onViewCreated(view, savedInstanceState) - mShowHidden = context.config.shouldShowHidden fillItems() items_swipe_refresh.setOnRefreshListener({ fillItems() }) @@ -69,6 +69,11 @@ class ItemsFragment : Fragment(), ItemsAdapter.ItemOperationsListener { override fun onPause() { super.onPause() + storeConfigVariables() + } + + private fun storeConfigVariables() { + mShowHidden = context.config.shouldShowHidden mStoredTextColor = context.config.textColor } @@ -153,26 +158,39 @@ class ItemsFragment : Fragment(), ItemsAdapter.ItemOperationsListener { } private fun getItems(path: String, callback: (items: ArrayList) -> Unit) { + val config = context.config Thread({ - val items = ArrayList() - val files = File(path).listFiles() - if (files != null) { - for (file in files) { - val curPath = file.absolutePath - val curName = curPath.getFilenameFromPath() - if (!mShowHidden && curName.startsWith(".")) - continue - - val children = getChildren(file) - val size = file.length() - - items.add(FileDirItem(curPath, curName, file.isDirectory, children, size)) - } + if (!config.enableRootAccess || path.startsWith(config.internalStoragePath) || (context.hasExternalSDCard() && path.startsWith(config.sdCardPath))) { + getRegularItemsOf(path, callback) + } else { + getRootItemsOf(path, callback) } - callback(items) }).start() } + private fun getRegularItemsOf(path: String, callback: (items: ArrayList) -> Unit) { + val items = ArrayList() + val files = File(path).listFiles() + if (files != null) { + for (file in files) { + val curPath = file.absolutePath + val curName = curPath.getFilenameFromPath() + if (!mShowHidden && curName.startsWith(".")) + continue + + val children = getChildren(file) + val size = file.length() + + items.add(FileDirItem(curPath, curName, file.isDirectory, children, size)) + } + } + callback(items) + } + + private fun getRootItemsOf(path: String, callback: (items: ArrayList) -> Unit) { + + } + private fun getChildren(file: File): Int { val fileList: Array? = file.list() ?: return 0