replace FileDirItem with ListItem in a few more places

This commit is contained in:
tibbi 2019-03-27 11:00:39 +01:00
parent c23a9c1fb1
commit c22aedc416
5 changed files with 30 additions and 41 deletions

1
.gitignore vendored
View File

@ -2,7 +2,6 @@
*.aab *.aab
.gradle .gradle
/local.properties /local.properties
/gradle.properties
/.idea/ /.idea/
.DS_Store .DS_Store
/build /build

View File

@ -51,7 +51,7 @@ android {
} }
dependencies { dependencies {
implementation 'com.simplemobiletools:commons:5.10.20' implementation 'com.simplemobiletools:commons:5.10.22'
implementation 'com.github.Stericson:RootTools:df729dcb13' implementation 'com.github.Stericson:RootTools:df729dcb13'
implementation 'com.alexvasilkov:gesture-views:2.5.2' implementation 'com.alexvasilkov:gesture-views:2.5.2'
} }

View File

@ -42,7 +42,7 @@ class ItemsFragment : Fragment(), ItemOperationsListener, Breadcrumbs.Breadcrumb
private var isSearchOpen = false private var isSearchOpen = false
private var scrollStates = HashMap<String, Parcelable>() private var scrollStates = HashMap<String, Parcelable>()
private var storedItems = ArrayList<FileDirItem>() private var storedItems = ArrayList<ListItem>()
private var storedTextColor = 0 private var storedTextColor = 0
lateinit var mView: View lateinit var mView: View
@ -123,20 +123,20 @@ class ItemsFragment : Fragment(), ItemOperationsListener, Breadcrumbs.Breadcrumb
scrollStates[currentPath] = getScrollState()!! scrollStates[currentPath] = getScrollState()!!
currentPath = realPath currentPath = realPath
showHidden = context!!.config.shouldShowHidden showHidden = context!!.config.shouldShowHidden
getItems(currentPath) { originalPath, fileDirItems -> getItems(currentPath) { originalPath, listItems ->
if (currentPath != originalPath || !isAdded) { if (currentPath != originalPath || !isAdded) {
return@getItems return@getItems
} }
FileDirItem.sorting = context!!.config.getFolderSorting(currentPath) FileDirItem.sorting = context!!.config.getFolderSorting(currentPath)
fileDirItems.sort() listItems.sort()
activity?.runOnUiThread { 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 skipItemUpdating = false
mView.apply { mView.apply {
activity?.runOnUiThread { activity?.runOnUiThread {
@ -147,7 +147,7 @@ class ItemsFragment : Fragment(), ItemOperationsListener, Breadcrumbs.Breadcrumb
mView.breadcrumbs.setBreadcrumb(currentPath) mView.breadcrumbs.setBreadcrumb(currentPath)
storedItems = items 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) itemClicked(it as FileDirItem)
}.apply { }.apply {
addVerticalDividers(true) addVerticalDividers(true)
@ -170,7 +170,7 @@ class ItemsFragment : Fragment(), ItemOperationsListener, Breadcrumbs.Breadcrumb
private fun getRecyclerLayoutManager() = (mView.items_list.layoutManager as MyLinearLayoutManager) 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 skipItemUpdating = false
Thread { Thread {
if (activity?.isDestroyed == false) { if (activity?.isDestroyed == false) {
@ -183,8 +183,8 @@ class ItemsFragment : Fragment(), ItemOperationsListener, Breadcrumbs.Breadcrumb
}.start() }.start()
} }
private fun getRegularItemsOf(path: String, callback: (originalPath: String, items: ArrayList<FileDirItem>) -> Unit) { private fun getRegularItemsOf(path: String, callback: (originalPath: String, items: ArrayList<ListItem>) -> Unit) {
val items = ArrayList<FileDirItem>() val items = ArrayList<ListItem>()
val files = File(path).listFiles()?.filterNotNull() val files = File(path).listFiles()?.filterNotNull()
if (context == null) { if (context == null) {
callback(path, items) callback(path, items)
@ -204,7 +204,7 @@ class ItemsFragment : Fragment(), ItemOperationsListener, Breadcrumbs.Breadcrumb
callback(path, items) 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 curPath = file.absolutePath
val curName = file.name val curName = file.name
if (!showHidden && curName.startsWith(".")) { if (!showHidden && curName.startsWith(".")) {
@ -223,16 +223,7 @@ class ItemsFragment : Fragment(), ItemOperationsListener, Breadcrumbs.Breadcrumb
file.length() file.length()
} }
return FileDirItem(curPath, curName, isDirectory, children, size) return ListItem(curPath, curName, isDirectory, children, size, false)
}
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
} }
private fun itemClicked(item: FileDirItem) { private fun itemClicked(item: FileDirItem) {
@ -266,7 +257,7 @@ class ItemsFragment : Fragment(), ItemOperationsListener, Breadcrumbs.Breadcrumb
mView.apply { mView.apply {
if (items_list.isGone()) { if (items_list.isGone()) {
items_list.beVisible() items_list.beVisible()
getRecyclerAdapter()?.updateItems(getListItemsFromFileDirItems(storedItems)) getRecyclerAdapter()?.updateItems(storedItems)
} }
items_placeholder.beGone() items_placeholder.beGone()
items_placeholder_2.beGone() items_placeholder_2.beGone()
@ -280,14 +271,14 @@ class ItemsFragment : Fragment(), ItemOperationsListener, Breadcrumbs.Breadcrumb
} }
} }
else -> { else -> {
val fileDirItems = ArrayList<FileDirItem>() val listItems = ArrayList<ListItem>()
fileDirItems.addAll(searchFiles(searchText, currentPath)) listItems.addAll(searchFiles(searchText, currentPath, 0))
activity?.runOnUiThread { activity?.runOnUiThread {
getRecyclerAdapter()?.updateItems(getListItemsFromFileDirItems(fileDirItems), text) getRecyclerAdapter()?.updateItems(listItems, text)
mView.apply { mView.apply {
items_list.beVisibleIf(fileDirItems.isNotEmpty()) items_list.beVisibleIf(listItems.isNotEmpty())
items_placeholder.beVisibleIf(fileDirItems.isEmpty()) items_placeholder.beVisibleIf(listItems.isEmpty())
items_placeholder_2.beGone() items_placeholder_2.beGone()
} }
} }
@ -296,15 +287,15 @@ class ItemsFragment : Fragment(), ItemOperationsListener, Breadcrumbs.Breadcrumb
}.start() }.start()
} }
private fun searchFiles(text: String, path: String): ArrayList<FileDirItem> { private fun searchFiles(text: String, path: String, nestingLevel: Int): ArrayList<ListItem> {
val files = ArrayList<FileDirItem>() val files = ArrayList<ListItem>()
val isSortingBySize = context!!.config.getFolderSorting(path) and SORT_BY_SIZE != 0 val isSortingBySize = context!!.config.getFolderSorting(path) and SORT_BY_SIZE != 0
File(path).listFiles()?.forEach { File(path).listFiles()?.forEach {
if (it.isDirectory) { if (it.isDirectory) {
files.addAll(searchFiles(text, it.absolutePath)) files.addAll(searchFiles(text, it.absolutePath, nestingLevel + 1))
} else { } else {
if (it.name.startsWith(text, true)) { if (it.name.startsWith(text, true)) {
val fileDirItem = getFileDirItemFromFile(it, isSortingBySize) val fileDirItem = getFileDirItemFromFile(it, isSortingBySize, nestingLevel)
if (fileDirItem != null) { if (fileDirItem != null) {
files.add(fileDirItem) files.add(fileDirItem)
} }
@ -321,7 +312,7 @@ class ItemsFragment : Fragment(), ItemOperationsListener, Breadcrumbs.Breadcrumb
fun searchClosed() { fun searchClosed() {
isSearchOpen = false isSearchOpen = false
if (!skipItemUpdating) { if (!skipItemUpdating) {
getRecyclerAdapter()?.updateItems(getListItemsFromFileDirItems(storedItems)) getRecyclerAdapter()?.updateItems(storedItems)
} }
skipItemUpdating = false skipItemUpdating = false
} }

View File

@ -8,6 +8,7 @@ import com.simplemobiletools.commons.helpers.SORT_BY_SIZE
import com.simplemobiletools.commons.models.FileDirItem import com.simplemobiletools.commons.models.FileDirItem
import com.simplemobiletools.filemanager.pro.R import com.simplemobiletools.filemanager.pro.R
import com.simplemobiletools.filemanager.pro.extensions.config import com.simplemobiletools.filemanager.pro.extensions.config
import com.simplemobiletools.filemanager.pro.models.ListItem
import com.stericson.RootShell.execution.Command import com.stericson.RootShell.execution.Command
import com.stericson.RootTools.RootTools import com.stericson.RootTools.RootTools
import java.io.File 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) { getFullLines(path) {
val fullLines = it val fullLines = it
val files = ArrayList<FileDirItem>() val files = ArrayList<ListItem>()
val hiddenArgument = if (activity.config.shouldShowHidden) "-A " else "" val hiddenArgument = if (activity.config.shouldShowHidden) "-A " else ""
val cmd = "ls $hiddenArgument$path" val cmd = "ls $hiddenArgument$path"
@ -43,7 +44,7 @@ class RootHelpers(val activity: Activity) {
val file = File(path, line) val file = File(path, line)
val fullLine = fullLines.firstOrNull { it.endsWith(" $line") } val fullLine = fullLines.firstOrNull { it.endsWith(" $line") }
val isDirectory = fullLine?.startsWith('d') ?: file.isDirectory 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) files.add(fileDirItem)
super.commandOutput(id, line) super.commandOutput(id, line)
} }
@ -83,7 +84,7 @@ class RootHelpers(val activity: Activity) {
runCommand(command) 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 "" val hiddenArgument = if (activity.config.shouldShowHidden) "-A " else ""
var cmd = "" var cmd = ""
files.filter { it.isDirectory }.forEach { files.filter { it.isDirectory }.forEach {
@ -118,7 +119,7 @@ class RootHelpers(val activity: Activity) {
runCommand(command) 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 = "" var cmd = ""
files.filter { !it.isDirectory }.forEach { files.filter { !it.isDirectory }.forEach {
cmd += "stat -t ${it.path};" cmd += "stat -t ${it.path};"

View File

@ -3,6 +3,4 @@ package com.simplemobiletools.filemanager.pro.models
import com.simplemobiletools.commons.models.FileDirItem 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) 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)
}