create a new ListItem model for showing in the recycler views
This commit is contained in:
parent
1c9715715f
commit
c23a9c1fb1
|
@ -27,6 +27,7 @@ import com.simplemobiletools.filemanager.pro.dialogs.CompressAsDialog
|
|||
import com.simplemobiletools.filemanager.pro.extensions.*
|
||||
import com.simplemobiletools.filemanager.pro.helpers.*
|
||||
import com.simplemobiletools.filemanager.pro.interfaces.ItemOperationsListener
|
||||
import com.simplemobiletools.filemanager.pro.models.ListItem
|
||||
import com.stericson.RootTools.RootTools
|
||||
import kotlinx.android.synthetic.main.list_item.view.*
|
||||
import java.io.Closeable
|
||||
|
@ -37,7 +38,7 @@ import java.util.zip.ZipEntry
|
|||
import java.util.zip.ZipFile
|
||||
import java.util.zip.ZipOutputStream
|
||||
|
||||
class ItemsAdapter(activity: SimpleActivity, var fileDirItems: MutableList<FileDirItem>, val listener: ItemOperationsListener?, recyclerView: MyRecyclerView,
|
||||
class ItemsAdapter(activity: SimpleActivity, var fileDirItems: MutableList<ListItem>, val listener: ItemOperationsListener?, recyclerView: MyRecyclerView,
|
||||
val isPickMultipleIntent: Boolean, fastScroller: FastScroller, itemClick: (Any) -> Unit) :
|
||||
MyRecyclerViewAdapter(activity, recyclerView, fastScroller, itemClick) {
|
||||
|
||||
|
@ -94,7 +95,7 @@ class ItemsAdapter(activity: SimpleActivity, var fileDirItems: MutableList<FileD
|
|||
|
||||
override fun getSelectableItemCount() = fileDirItems.size
|
||||
|
||||
override fun getIsItemSelectable(position: Int) = true
|
||||
override fun getIsItemSelectable(position: Int) = !fileDirItems[position].isSectionTitle
|
||||
|
||||
override fun getItemSelectionKey(position: Int) = fileDirItems.getOrNull(position)?.path?.hashCode()
|
||||
|
||||
|
@ -531,11 +532,11 @@ class ItemsAdapter(activity: SimpleActivity, var fileDirItems: MutableList<FileD
|
|||
|
||||
private fun getSelectedFileDirItems() = fileDirItems.filter { selectedKeys.contains(it.path.hashCode()) } as ArrayList<FileDirItem>
|
||||
|
||||
fun updateItems(newItems: ArrayList<FileDirItem>, highlightText: String = "") {
|
||||
fun updateItems(newItems: ArrayList<ListItem>, highlightText: String = "") {
|
||||
if (newItems.hashCode() != currentItemsHash) {
|
||||
currentItemsHash = newItems.hashCode()
|
||||
textToHighlight = highlightText
|
||||
fileDirItems = newItems.clone() as ArrayList<FileDirItem>
|
||||
fileDirItems = newItems.clone() as ArrayList<ListItem>
|
||||
notifyDataSetChanged()
|
||||
finishActMode()
|
||||
} else if (textToHighlight != highlightText) {
|
||||
|
@ -552,7 +553,7 @@ class ItemsAdapter(activity: SimpleActivity, var fileDirItems: MutableList<FileD
|
|||
}
|
||||
}
|
||||
|
||||
private fun setupView(view: View, fileDirItem: FileDirItem) {
|
||||
private fun setupView(view: View, fileDirItem: ListItem) {
|
||||
val isSelected = selectedKeys.contains(fileDirItem.path.hashCode())
|
||||
view.apply {
|
||||
item_frame.isSelected = isSelected
|
||||
|
|
|
@ -24,6 +24,7 @@ import com.simplemobiletools.filemanager.pro.extensions.tryOpenPathIntent
|
|||
import com.simplemobiletools.filemanager.pro.helpers.PATH
|
||||
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.HashMap
|
||||
|
@ -146,7 +147,7 @@ class ItemsFragment : Fragment(), ItemOperationsListener, Breadcrumbs.Breadcrumb
|
|||
|
||||
mView.breadcrumbs.setBreadcrumb(currentPath)
|
||||
storedItems = items
|
||||
ItemsAdapter(activity as SimpleActivity, storedItems, this@ItemsFragment, items_list, isPickMultipleIntent, items_fastscroller) {
|
||||
ItemsAdapter(activity as SimpleActivity, getListItemsFromFileDirItems(storedItems), this@ItemsFragment, items_list, isPickMultipleIntent, items_fastscroller) {
|
||||
itemClicked(it as FileDirItem)
|
||||
}.apply {
|
||||
addVerticalDividers(true)
|
||||
|
@ -225,6 +226,15 @@ class ItemsFragment : Fragment(), ItemOperationsListener, Breadcrumbs.Breadcrumb
|
|||
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
|
||||
}
|
||||
|
||||
private fun itemClicked(item: FileDirItem) {
|
||||
if (item.isDirectory) {
|
||||
(activity as? MainActivity)?.apply {
|
||||
|
@ -256,7 +266,7 @@ class ItemsFragment : Fragment(), ItemOperationsListener, Breadcrumbs.Breadcrumb
|
|||
mView.apply {
|
||||
if (items_list.isGone()) {
|
||||
items_list.beVisible()
|
||||
getRecyclerAdapter()?.updateItems(storedItems)
|
||||
getRecyclerAdapter()?.updateItems(getListItemsFromFileDirItems(storedItems))
|
||||
}
|
||||
items_placeholder.beGone()
|
||||
items_placeholder_2.beGone()
|
||||
|
@ -274,7 +284,7 @@ class ItemsFragment : Fragment(), ItemOperationsListener, Breadcrumbs.Breadcrumb
|
|||
fileDirItems.addAll(searchFiles(searchText, currentPath))
|
||||
|
||||
activity?.runOnUiThread {
|
||||
getRecyclerAdapter()?.updateItems(fileDirItems, text)
|
||||
getRecyclerAdapter()?.updateItems(getListItemsFromFileDirItems(fileDirItems), text)
|
||||
mView.apply {
|
||||
items_list.beVisibleIf(fileDirItems.isNotEmpty())
|
||||
items_placeholder.beVisibleIf(fileDirItems.isEmpty())
|
||||
|
@ -311,7 +321,7 @@ class ItemsFragment : Fragment(), ItemOperationsListener, Breadcrumbs.Breadcrumb
|
|||
fun searchClosed() {
|
||||
isSearchOpen = false
|
||||
if (!skipItemUpdating) {
|
||||
getRecyclerAdapter()?.updateItems(storedItems)
|
||||
getRecyclerAdapter()?.updateItems(getListItemsFromFileDirItems(storedItems))
|
||||
}
|
||||
skipItemUpdating = false
|
||||
}
|
||||
|
|
|
@ -0,0 +1,8 @@
|
|||
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) {
|
||||
|
||||
}
|
Loading…
Reference in New Issue