mirror of
https://github.com/SimpleMobileTools/Simple-File-Manager.git
synced 2025-02-16 11:50:47 +01:00
replace FileDirItem with ListItem in a few more places
This commit is contained in:
parent
c23a9c1fb1
commit
c22aedc416
1
.gitignore
vendored
1
.gitignore
vendored
@ -2,7 +2,6 @@
|
||||
*.aab
|
||||
.gradle
|
||||
/local.properties
|
||||
/gradle.properties
|
||||
/.idea/
|
||||
.DS_Store
|
||||
/build
|
||||
|
@ -51,7 +51,7 @@ android {
|
||||
}
|
||||
|
||||
dependencies {
|
||||
implementation 'com.simplemobiletools:commons:5.10.20'
|
||||
implementation 'com.simplemobiletools:commons:5.10.22'
|
||||
implementation 'com.github.Stericson:RootTools:df729dcb13'
|
||||
implementation 'com.alexvasilkov:gesture-views:2.5.2'
|
||||
}
|
||||
|
@ -42,7 +42,7 @@ class ItemsFragment : Fragment(), ItemOperationsListener, Breadcrumbs.Breadcrumb
|
||||
private var isSearchOpen = false
|
||||
private var scrollStates = HashMap<String, Parcelable>()
|
||||
|
||||
private var storedItems = ArrayList<FileDirItem>()
|
||||
private var storedItems = ArrayList<ListItem>()
|
||||
private var storedTextColor = 0
|
||||
|
||||
lateinit var mView: View
|
||||
@ -123,20 +123,20 @@ class ItemsFragment : Fragment(), ItemOperationsListener, Breadcrumbs.Breadcrumb
|
||||
scrollStates[currentPath] = getScrollState()!!
|
||||
currentPath = realPath
|
||||
showHidden = context!!.config.shouldShowHidden
|
||||
getItems(currentPath) { originalPath, fileDirItems ->
|
||||
getItems(currentPath) { originalPath, listItems ->
|
||||
if (currentPath != originalPath || !isAdded) {
|
||||
return@getItems
|
||||
}
|
||||
|
||||
FileDirItem.sorting = context!!.config.getFolderSorting(currentPath)
|
||||
fileDirItems.sort()
|
||||
listItems.sort()
|
||||
activity?.runOnUiThread {
|
||||
addItems(fileDirItems, forceRefresh)
|
||||
addItems(listItems, forceRefresh)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private fun addItems(items: ArrayList<FileDirItem>, forceRefresh: Boolean = false) {
|
||||
private fun addItems(items: ArrayList<ListItem>, forceRefresh: Boolean = false) {
|
||||
skipItemUpdating = false
|
||||
mView.apply {
|
||||
activity?.runOnUiThread {
|
||||
@ -147,7 +147,7 @@ class ItemsFragment : Fragment(), ItemOperationsListener, Breadcrumbs.Breadcrumb
|
||||
|
||||
mView.breadcrumbs.setBreadcrumb(currentPath)
|
||||
storedItems = items
|
||||
ItemsAdapter(activity as SimpleActivity, getListItemsFromFileDirItems(storedItems), this@ItemsFragment, items_list, isPickMultipleIntent, items_fastscroller) {
|
||||
ItemsAdapter(activity as SimpleActivity, storedItems, this@ItemsFragment, items_list, isPickMultipleIntent, items_fastscroller) {
|
||||
itemClicked(it as FileDirItem)
|
||||
}.apply {
|
||||
addVerticalDividers(true)
|
||||
@ -170,7 +170,7 @@ class ItemsFragment : Fragment(), ItemOperationsListener, Breadcrumbs.Breadcrumb
|
||||
|
||||
private fun getRecyclerLayoutManager() = (mView.items_list.layoutManager as MyLinearLayoutManager)
|
||||
|
||||
private fun getItems(path: String, callback: (originalPath: String, items: ArrayList<FileDirItem>) -> Unit) {
|
||||
private fun getItems(path: String, callback: (originalPath: String, items: ArrayList<ListItem>) -> Unit) {
|
||||
skipItemUpdating = false
|
||||
Thread {
|
||||
if (activity?.isDestroyed == false) {
|
||||
@ -183,8 +183,8 @@ class ItemsFragment : Fragment(), ItemOperationsListener, Breadcrumbs.Breadcrumb
|
||||
}.start()
|
||||
}
|
||||
|
||||
private fun getRegularItemsOf(path: String, callback: (originalPath: String, items: ArrayList<FileDirItem>) -> Unit) {
|
||||
val items = ArrayList<FileDirItem>()
|
||||
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) {
|
||||
callback(path, items)
|
||||
@ -204,7 +204,7 @@ class ItemsFragment : Fragment(), ItemOperationsListener, Breadcrumbs.Breadcrumb
|
||||
callback(path, items)
|
||||
}
|
||||
|
||||
private fun getFileDirItemFromFile(file: File, isSortingBySize: Boolean): FileDirItem? {
|
||||
private fun getFileDirItemFromFile(file: File, isSortingBySize: Boolean, nestingLevel: Int = 0): ListItem? {
|
||||
val curPath = file.absolutePath
|
||||
val curName = file.name
|
||||
if (!showHidden && curName.startsWith(".")) {
|
||||
@ -223,16 +223,7 @@ class ItemsFragment : Fragment(), ItemOperationsListener, Breadcrumbs.Breadcrumb
|
||||
file.length()
|
||||
}
|
||||
|
||||
return FileDirItem(curPath, curName, isDirectory, children, size)
|
||||
}
|
||||
|
||||
private fun getListItemsFromFileDirItems(fileDirItems: ArrayList<FileDirItem>): ArrayList<ListItem> {
|
||||
val listItems = ArrayList<ListItem>()
|
||||
fileDirItems.forEach {
|
||||
val listItem = ListItem(it.path, it.name, it.isDirectory, it.children, it.size, false)
|
||||
listItems.add(listItem)
|
||||
}
|
||||
return listItems
|
||||
return ListItem(curPath, curName, isDirectory, children, size, false)
|
||||
}
|
||||
|
||||
private fun itemClicked(item: FileDirItem) {
|
||||
@ -266,7 +257,7 @@ class ItemsFragment : Fragment(), ItemOperationsListener, Breadcrumbs.Breadcrumb
|
||||
mView.apply {
|
||||
if (items_list.isGone()) {
|
||||
items_list.beVisible()
|
||||
getRecyclerAdapter()?.updateItems(getListItemsFromFileDirItems(storedItems))
|
||||
getRecyclerAdapter()?.updateItems(storedItems)
|
||||
}
|
||||
items_placeholder.beGone()
|
||||
items_placeholder_2.beGone()
|
||||
@ -280,14 +271,14 @@ class ItemsFragment : Fragment(), ItemOperationsListener, Breadcrumbs.Breadcrumb
|
||||
}
|
||||
}
|
||||
else -> {
|
||||
val fileDirItems = ArrayList<FileDirItem>()
|
||||
fileDirItems.addAll(searchFiles(searchText, currentPath))
|
||||
val listItems = ArrayList<ListItem>()
|
||||
listItems.addAll(searchFiles(searchText, currentPath, 0))
|
||||
|
||||
activity?.runOnUiThread {
|
||||
getRecyclerAdapter()?.updateItems(getListItemsFromFileDirItems(fileDirItems), text)
|
||||
getRecyclerAdapter()?.updateItems(listItems, text)
|
||||
mView.apply {
|
||||
items_list.beVisibleIf(fileDirItems.isNotEmpty())
|
||||
items_placeholder.beVisibleIf(fileDirItems.isEmpty())
|
||||
items_list.beVisibleIf(listItems.isNotEmpty())
|
||||
items_placeholder.beVisibleIf(listItems.isEmpty())
|
||||
items_placeholder_2.beGone()
|
||||
}
|
||||
}
|
||||
@ -296,15 +287,15 @@ class ItemsFragment : Fragment(), ItemOperationsListener, Breadcrumbs.Breadcrumb
|
||||
}.start()
|
||||
}
|
||||
|
||||
private fun searchFiles(text: String, path: String): ArrayList<FileDirItem> {
|
||||
val files = ArrayList<FileDirItem>()
|
||||
private fun searchFiles(text: String, path: String, nestingLevel: Int): ArrayList<ListItem> {
|
||||
val files = ArrayList<ListItem>()
|
||||
val isSortingBySize = context!!.config.getFolderSorting(path) and SORT_BY_SIZE != 0
|
||||
File(path).listFiles()?.forEach {
|
||||
if (it.isDirectory) {
|
||||
files.addAll(searchFiles(text, it.absolutePath))
|
||||
files.addAll(searchFiles(text, it.absolutePath, nestingLevel + 1))
|
||||
} else {
|
||||
if (it.name.startsWith(text, true)) {
|
||||
val fileDirItem = getFileDirItemFromFile(it, isSortingBySize)
|
||||
val fileDirItem = getFileDirItemFromFile(it, isSortingBySize, nestingLevel)
|
||||
if (fileDirItem != null) {
|
||||
files.add(fileDirItem)
|
||||
}
|
||||
@ -321,7 +312,7 @@ class ItemsFragment : Fragment(), ItemOperationsListener, Breadcrumbs.Breadcrumb
|
||||
fun searchClosed() {
|
||||
isSearchOpen = false
|
||||
if (!skipItemUpdating) {
|
||||
getRecyclerAdapter()?.updateItems(getListItemsFromFileDirItems(storedItems))
|
||||
getRecyclerAdapter()?.updateItems(storedItems)
|
||||
}
|
||||
skipItemUpdating = false
|
||||
}
|
||||
|
@ -8,6 +8,7 @@ import com.simplemobiletools.commons.helpers.SORT_BY_SIZE
|
||||
import com.simplemobiletools.commons.models.FileDirItem
|
||||
import com.simplemobiletools.filemanager.pro.R
|
||||
import com.simplemobiletools.filemanager.pro.extensions.config
|
||||
import com.simplemobiletools.filemanager.pro.models.ListItem
|
||||
import com.stericson.RootShell.execution.Command
|
||||
import com.stericson.RootTools.RootTools
|
||||
import java.io.File
|
||||
@ -30,11 +31,11 @@ class RootHelpers(val activity: Activity) {
|
||||
}
|
||||
}
|
||||
|
||||
fun getFiles(path: String, callback: (originalPath: String, fileDirItems: ArrayList<FileDirItem>) -> Unit) {
|
||||
fun getFiles(path: String, callback: (originalPath: String, listItems: ArrayList<ListItem>) -> Unit) {
|
||||
getFullLines(path) {
|
||||
val fullLines = it
|
||||
|
||||
val files = ArrayList<FileDirItem>()
|
||||
val files = ArrayList<ListItem>()
|
||||
val hiddenArgument = if (activity.config.shouldShowHidden) "-A " else ""
|
||||
val cmd = "ls $hiddenArgument$path"
|
||||
|
||||
@ -43,7 +44,7 @@ class RootHelpers(val activity: Activity) {
|
||||
val file = File(path, line)
|
||||
val fullLine = fullLines.firstOrNull { it.endsWith(" $line") }
|
||||
val isDirectory = fullLine?.startsWith('d') ?: file.isDirectory
|
||||
val fileDirItem = FileDirItem(file.absolutePath, line, isDirectory, 0, 0)
|
||||
val fileDirItem = ListItem(file.absolutePath, line, isDirectory, 0, 0, false)
|
||||
files.add(fileDirItem)
|
||||
super.commandOutput(id, line)
|
||||
}
|
||||
@ -83,7 +84,7 @@ class RootHelpers(val activity: Activity) {
|
||||
runCommand(command)
|
||||
}
|
||||
|
||||
private fun getChildrenCount(files: ArrayList<FileDirItem>, path: String, callback: (originalPath: String, fileDirItems: ArrayList<FileDirItem>) -> Unit) {
|
||||
private fun getChildrenCount(files: ArrayList<ListItem>, path: String, callback: (originalPath: String, listItems: ArrayList<ListItem>) -> Unit) {
|
||||
val hiddenArgument = if (activity.config.shouldShowHidden) "-A " else ""
|
||||
var cmd = ""
|
||||
files.filter { it.isDirectory }.forEach {
|
||||
@ -118,7 +119,7 @@ class RootHelpers(val activity: Activity) {
|
||||
runCommand(command)
|
||||
}
|
||||
|
||||
private fun getFileSizes(files: ArrayList<FileDirItem>, path: String, callback: (originalPath: String, fileDirItems: ArrayList<FileDirItem>) -> Unit) {
|
||||
private fun getFileSizes(files: ArrayList<ListItem>, path: String, callback: (originalPath: String, listItems: ArrayList<ListItem>) -> Unit) {
|
||||
var cmd = ""
|
||||
files.filter { !it.isDirectory }.forEach {
|
||||
cmd += "stat -t ${it.path};"
|
||||
|
@ -3,6 +3,4 @@ package com.simplemobiletools.filemanager.pro.models
|
||||
import com.simplemobiletools.commons.models.FileDirItem
|
||||
|
||||
data class ListItem(val mPath: String, val mName: String = "", var mIsDirectory: Boolean = false, var mChildren: Int = 0, var mSize: Long = 0L, var isSectionTitle: Boolean)
|
||||
: FileDirItem(mPath, mName, mIsDirectory, mChildren, mSize) {
|
||||
|
||||
}
|
||||
: FileDirItem(mPath, mName, mIsDirectory, mChildren, mSize)
|
||||
|
Loading…
x
Reference in New Issue
Block a user