diff --git a/app/src/main/kotlin/com/simplemobiletools/filemanager/adapters/ItemsAdapter.kt b/app/src/main/kotlin/com/simplemobiletools/filemanager/adapters/ItemsAdapter.kt index 050b3fd9..c6418609 100644 --- a/app/src/main/kotlin/com/simplemobiletools/filemanager/adapters/ItemsAdapter.kt +++ b/app/src/main/kotlin/com/simplemobiletools/filemanager/adapters/ItemsAdapter.kt @@ -247,6 +247,45 @@ class ItemsAdapter(val activity: SimpleActivity, var mItems: MutableList -1 && min < to) { + (min..to - 1).filter { it != from } + .forEach { toggleItemSelection(false, it) } + } + if (max > -1) { + for (i in from + 1..max) + toggleItemSelection(false, i) + } + } else { + for (i in from..to) + toggleItemSelection(true, i) + + if (max > -1 && max > to) { + (to + 1..max).filter { it != from } + .forEach { toggleItemSelection(false, it) } + } + + if (min > -1) { + for (i in min..from - 1) + toggleItemSelection(false, i) + } + } + } + class ViewHolder(val view: View, val adapterListener: MyAdapterListener, val activity: SimpleActivity, val multiSelectorCallback: ModalMultiSelectorCallback, val multiSelector: MultiSelector, val listener: ItemOperationsListener?, val itemClick: (FileDirItem) -> (Unit)) : SwappingHolder(view, MultiSelector()) { fun bindView(fileDirItem: FileDirItem, fileDrawable: Drawable, folderDrawable: Drawable, textColor: Int): View { diff --git a/app/src/main/kotlin/com/simplemobiletools/filemanager/fragments/ItemsFragment.kt b/app/src/main/kotlin/com/simplemobiletools/filemanager/fragments/ItemsFragment.kt index a8c5e6bc..732e6c65 100644 --- a/app/src/main/kotlin/com/simplemobiletools/filemanager/fragments/ItemsFragment.kt +++ b/app/src/main/kotlin/com/simplemobiletools/filemanager/fragments/ItemsFragment.kt @@ -13,6 +13,7 @@ import android.view.ViewGroup import android.webkit.MimeTypeMap import com.simplemobiletools.commons.extensions.* import com.simplemobiletools.commons.models.FileDirItem +import com.simplemobiletools.commons.views.MyScalableRecyclerView import com.simplemobiletools.commons.views.RecyclerViewDivider import com.simplemobiletools.filemanager.PATH import com.simplemobiletools.filemanager.R @@ -86,17 +87,17 @@ class ItemsFragment : Fragment(), ItemsAdapter.ItemOperationsListener { mItems = newItems - val adapter = ItemsAdapter(activity as SimpleActivity, mItems, this@ItemsFragment) { - itemClicked(it) - } - val currAdapter = items_list.adapter if (currAdapter == null) { items_list.apply { - this.adapter = adapter + this.adapter = ItemsAdapter(activity as SimpleActivity, mItems, this@ItemsFragment) { + itemClicked(it) + } addItemDecoration(RecyclerViewDivider(context)) } + items_list.isDragSelectionEnabled = true items_fastscroller.setViews(items_list, items_swipe_refresh) + setupRecyclerViewListener() } else { val state = (items_list.layoutManager as LinearLayoutManager).onSaveInstanceState() (currAdapter as ItemsAdapter).updateItems(mItems) @@ -109,7 +110,29 @@ class ItemsFragment : Fragment(), ItemsAdapter.ItemOperationsListener { } } - fun getRecyclerLayoutManager() = (fragmentView.items_list.layoutManager as LinearLayoutManager) + private fun getRecyclerLayoutManager() = (fragmentView.items_list.layoutManager as LinearLayoutManager) + + private fun setupRecyclerViewListener() { + fragmentView.items_list.listener = object : MyScalableRecyclerView.MyScalableRecyclerViewListener { + override fun zoomIn() { + + } + + override fun zoomOut() { + + } + + override fun selectItem(position: Int) { + getRecyclerAdapter().selectItem(position) + } + + override fun selectRange(initialSelection: Int, lastDraggedIndex: Int, minReached: Int, maxReached: Int) { + getRecyclerAdapter().selectRange(initialSelection, lastDraggedIndex, minReached, maxReached) + } + } + } + + private fun getRecyclerAdapter() = (items_list.adapter as ItemsAdapter) fun getScrollState() = getRecyclerLayoutManager().onSaveInstanceState() @@ -217,7 +240,7 @@ class ItemsFragment : Fragment(), ItemsAdapter.ItemOperationsListener { } override fun itemLongClicked(position: Int) { - + items_list.setDragSelectActive(position) } interface ItemInteractionListener {