split file fetching between regular and root folders
This commit is contained in:
parent
2ae28ca91b
commit
57aa9054f2
|
@ -40,12 +40,12 @@ class ItemsFragment : Fragment(), ItemsAdapter.ItemOperationsListener {
|
||||||
|
|
||||||
override fun onCreateView(inflater: LayoutInflater?, container: ViewGroup?, savedInstanceState: Bundle?): View {
|
override fun onCreateView(inflater: LayoutInflater?, container: ViewGroup?, savedInstanceState: Bundle?): View {
|
||||||
fragmentView = inflater!!.inflate(R.layout.items_fragment, container, false)!!
|
fragmentView = inflater!!.inflate(R.layout.items_fragment, container, false)!!
|
||||||
|
storeConfigVariables()
|
||||||
return fragmentView
|
return fragmentView
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun onViewCreated(view: View?, savedInstanceState: Bundle?) {
|
override fun onViewCreated(view: View?, savedInstanceState: Bundle?) {
|
||||||
super.onViewCreated(view, savedInstanceState)
|
super.onViewCreated(view, savedInstanceState)
|
||||||
mShowHidden = context.config.shouldShowHidden
|
|
||||||
fillItems()
|
fillItems()
|
||||||
|
|
||||||
items_swipe_refresh.setOnRefreshListener({ fillItems() })
|
items_swipe_refresh.setOnRefreshListener({ fillItems() })
|
||||||
|
@ -69,6 +69,11 @@ class ItemsFragment : Fragment(), ItemsAdapter.ItemOperationsListener {
|
||||||
|
|
||||||
override fun onPause() {
|
override fun onPause() {
|
||||||
super.onPause()
|
super.onPause()
|
||||||
|
storeConfigVariables()
|
||||||
|
}
|
||||||
|
|
||||||
|
private fun storeConfigVariables() {
|
||||||
|
mShowHidden = context.config.shouldShowHidden
|
||||||
mStoredTextColor = context.config.textColor
|
mStoredTextColor = context.config.textColor
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -153,26 +158,39 @@ class ItemsFragment : Fragment(), ItemsAdapter.ItemOperationsListener {
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun getItems(path: String, callback: (items: ArrayList<FileDirItem>) -> Unit) {
|
private fun getItems(path: String, callback: (items: ArrayList<FileDirItem>) -> Unit) {
|
||||||
|
val config = context.config
|
||||||
Thread({
|
Thread({
|
||||||
val items = ArrayList<FileDirItem>()
|
if (!config.enableRootAccess || path.startsWith(config.internalStoragePath) || (context.hasExternalSDCard() && path.startsWith(config.sdCardPath))) {
|
||||||
val files = File(path).listFiles()
|
getRegularItemsOf(path, callback)
|
||||||
if (files != null) {
|
} else {
|
||||||
for (file in files) {
|
getRootItemsOf(path, callback)
|
||||||
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)
|
|
||||||
}).start()
|
}).start()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private fun getRegularItemsOf(path: String, callback: (items: ArrayList<FileDirItem>) -> Unit) {
|
||||||
|
val items = ArrayList<FileDirItem>()
|
||||||
|
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<FileDirItem>) -> Unit) {
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
private fun getChildren(file: File): Int {
|
private fun getChildren(file: File): Int {
|
||||||
val fileList: Array<out String>? = file.list() ?: return 0
|
val fileList: Array<out String>? = file.list() ?: return 0
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue