From 052821d27fbde5cf3d3d692064398e9f78504259 Mon Sep 17 00:00:00 2001 From: tibbi Date: Wed, 27 Mar 2019 11:39:24 +0100 Subject: [PATCH] allow showing sections in the file lists too --- .../filemanager/pro/adapters/ItemsAdapter.kt | 116 +++++++++++------- .../{list_item.xml => item_list_file_dir.xml} | 10 +- app/src/main/res/layout/item_list_section.xml | 13 ++ 3 files changed, 87 insertions(+), 52 deletions(-) rename app/src/main/res/layout/{list_item.xml => item_list_file_dir.xml} (85%) create mode 100644 app/src/main/res/layout/item_list_section.xml diff --git a/app/src/main/kotlin/com/simplemobiletools/filemanager/pro/adapters/ItemsAdapter.kt b/app/src/main/kotlin/com/simplemobiletools/filemanager/pro/adapters/ItemsAdapter.kt index ca60c678..2058368f 100644 --- a/app/src/main/kotlin/com/simplemobiletools/filemanager/pro/adapters/ItemsAdapter.kt +++ b/app/src/main/kotlin/com/simplemobiletools/filemanager/pro/adapters/ItemsAdapter.kt @@ -29,7 +29,8 @@ 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 kotlinx.android.synthetic.main.item_list_file_dir.view.* +import kotlinx.android.synthetic.main.item_list_section.view.* import java.io.Closeable import java.io.File import java.io.FileInputStream @@ -38,13 +39,15 @@ import java.util.zip.ZipEntry import java.util.zip.ZipFile import java.util.zip.ZipOutputStream -class ItemsAdapter(activity: SimpleActivity, var fileDirItems: MutableList, val listener: ItemOperationsListener?, recyclerView: MyRecyclerView, +class ItemsAdapter(activity: SimpleActivity, var listItems: MutableList, val listener: ItemOperationsListener?, recyclerView: MyRecyclerView, val isPickMultipleIntent: Boolean, fastScroller: FastScroller, itemClick: (Any) -> Unit) : MyRecyclerViewAdapter(activity, recyclerView, fastScroller, itemClick) { + private val TYPE_FILE_DIR = 1 + private val TYPE_SECTION = 2 private lateinit var folderDrawable: Drawable private lateinit var fileDrawable: Drawable - private var currentItemsHash = fileDirItems.hashCode() + private var currentItemsHash = listItems.hashCode() private var textToHighlight = "" var adjustedPrimaryColor = activity.getAdjustedPrimaryColor() @@ -93,27 +96,38 @@ class ItemsAdapter(activity: SimpleActivity, var fileDirItems: MutableList setupView(itemView, fileDirItem) } bindViewHolder(holder) } - override fun getItemCount() = fileDirItems.size + override fun getItemCount() = listItems.size - private fun getItemWithKey(key: Int): FileDirItem? = fileDirItems.firstOrNull { it.path.hashCode() == key } + private fun getItemWithKey(key: Int): FileDirItem? = listItems.firstOrNull { it.path.hashCode() == key } fun initDrawables() { folderDrawable = activity.resources.getColoredDrawableWithColor(R.drawable.ic_folder, textColor) @@ -512,10 +526,10 @@ class ItemsAdapter(activity: SimpleActivity, var fileDirItems: MutableList + private fun getSelectedFileDirItems() = listItems.filter { selectedKeys.contains(it.path.hashCode()) } as ArrayList fun updateItems(newItems: ArrayList, highlightText: String = "") { if (newItems.hashCode() != currentItemsHash) { currentItemsHash = newItems.hashCode() textToHighlight = highlightText - fileDirItems = newItems.clone() as ArrayList + listItems = newItems.clone() as ArrayList notifyDataSetChanged() finishActMode() } else if (textToHighlight != highlightText) { @@ -548,47 +562,55 @@ class ItemsAdapter(activity: SimpleActivity, var fileDirItems: MutableList + android:paddingEnd="@dimen/activity_margin"> @@ -40,8 +40,8 @@ android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_below="@+id/item_name" - android:layout_toRightOf="@+id/item_icon" - android:paddingLeft="@dimen/small_margin" + android:layout_toEndOf="@+id/item_icon" + android:paddingStart="@dimen/small_margin" android:textSize="@dimen/smaller_text_size" tools:text="1 KB"/> diff --git a/app/src/main/res/layout/item_list_section.xml b/app/src/main/res/layout/item_list_section.xml new file mode 100644 index 00000000..eea44a61 --- /dev/null +++ b/app/src/main/res/layout/item_list_section.xml @@ -0,0 +1,13 @@ + +