From aa160841922ee40be52fed867eaa8ad2c5176723 Mon Sep 17 00:00:00 2001 From: tibbi Date: Mon, 18 Sep 2017 20:25:03 +0200 Subject: [PATCH] use layoutPosition at directory and media adapters --- .../gallery/adapters/DirectoryAdapter.kt | 20 +++++++++---------- .../gallery/adapters/MediaAdapter.kt | 20 +++++++++---------- 2 files changed, 20 insertions(+), 20 deletions(-) diff --git a/app/src/main/kotlin/com/simplemobiletools/gallery/adapters/DirectoryAdapter.kt b/app/src/main/kotlin/com/simplemobiletools/gallery/adapters/DirectoryAdapter.kt index 02aae82b2..c7e3dcbbf 100644 --- a/app/src/main/kotlin/com/simplemobiletools/gallery/adapters/DirectoryAdapter.kt +++ b/app/src/main/kotlin/com/simplemobiletools/gallery/adapters/DirectoryAdapter.kt @@ -336,7 +336,7 @@ class DirectoryAdapter(val activity: SimpleActivity, var dirs: MutableList (Unit)) : SwappingHolder(view, MultiSelector()) { - fun bindView(directory: Directory, isPinned: Boolean, scrollVertically: Boolean, position: Int): View { + fun bindView(directory: Directory, isPinned: Boolean, scrollVertically: Boolean): View { itemView.apply { dir_name.text = directory.name photo_cnt.text = directory.mediaCnt.toString() @@ -403,29 +403,29 @@ class DirectoryAdapter(val activity: SimpleActivity, var dirs: MutableList, } override fun onBindViewHolder(holder: ViewHolder, position: Int) { - itemViews.put(position, holder.bindView(media[position], displayFilenames, scrollVertically, position)) + itemViews.put(position, holder.bindView(media[position], displayFilenames, scrollVertically)) toggleItemSelection(selectedPositions.contains(position), position) holder.itemView.tag = holder } @@ -315,36 +315,36 @@ class MediaAdapter(val activity: SimpleActivity, var media: MutableList, class ViewHolder(val view: View, val adapterListener: MyAdapterListener, val activity: SimpleActivity, val multiSelectorCallback: ModalMultiSelectorCallback, val multiSelector: MultiSelector, val listener: MediaOperationsListener?, val isPickIntent: Boolean, val itemClick: (Medium) -> (Unit)) : SwappingHolder(view, MultiSelector()) { - fun bindView(medium: Medium, displayFilenames: Boolean, scrollVertically: Boolean, position: Int): View { + fun bindView(medium: Medium, displayFilenames: Boolean, scrollVertically: Boolean): View { itemView.apply { play_outline.visibility = if (medium.video) View.VISIBLE else View.GONE photo_name.beVisibleIf(displayFilenames) photo_name.text = medium.name activity.loadImage(medium.path, medium_thumbnail, scrollVertically) - setOnClickListener { viewClicked(medium, position) } - setOnLongClickListener { if (isPickIntent) viewClicked(medium, position) else viewLongClicked(position); true } + setOnClickListener { viewClicked(medium) } + setOnLongClickListener { if (isPickIntent) viewClicked(medium) else viewLongClicked(); true } } return itemView } - private fun viewClicked(medium: Medium, position: Int) { + private fun viewClicked(medium: Medium) { if (multiSelector.isSelectable) { - val isSelected = adapterListener.getSelectedPositions().contains(position) - adapterListener.toggleItemSelectionAdapter(!isSelected, position) + val isSelected = adapterListener.getSelectedPositions().contains(layoutPosition) + adapterListener.toggleItemSelectionAdapter(!isSelected, layoutPosition) } else { itemClick(medium) } } - private fun viewLongClicked(position: Int) { + private fun viewLongClicked() { if (listener != null) { if (!multiSelector.isSelectable) { activity.startSupportActionMode(multiSelectorCallback) - adapterListener.toggleItemSelectionAdapter(true, position) + adapterListener.toggleItemSelectionAdapter(true, layoutPosition) } - listener.itemLongClicked(position) + listener.itemLongClicked(layoutPosition) } }