use layoutPosition at directory and media adapters
This commit is contained in:
parent
7597efcba2
commit
aa16084192
2 changed files with 20 additions and 20 deletions
|
@ -336,7 +336,7 @@ class DirectoryAdapter(val activity: SimpleActivity, var dirs: MutableList<Direc
|
|||
|
||||
override fun onBindViewHolder(holder: ViewHolder, position: Int) {
|
||||
val dir = dirs[position]
|
||||
itemViews.put(position, holder.bindView(dir, pinnedFolders.contains(dir.path), scrollVertically, position))
|
||||
itemViews.put(position, holder.bindView(dir, pinnedFolders.contains(dir.path), scrollVertically))
|
||||
toggleItemSelection(selectedPositions.contains(position), position)
|
||||
holder.itemView.tag = holder
|
||||
}
|
||||
|
@ -395,7 +395,7 @@ class DirectoryAdapter(val activity: SimpleActivity, var dirs: MutableList<Direc
|
|||
class ViewHolder(val view: View, val adapterListener: MyAdapterListener, val activity: SimpleActivity, val multiSelectorCallback: ModalMultiSelectorCallback,
|
||||
val multiSelector: MultiSelector, val listener: DirOperationsListener?, val isPickIntent: Boolean, val itemClick: (Directory) -> (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<Direc
|
|||
dir_pin.beVisibleIf(isPinned)
|
||||
dir_sd_card.beVisibleIf(activity.isPathOnSD(directory.path))
|
||||
|
||||
setOnClickListener { viewClicked(directory, position) }
|
||||
setOnLongClickListener { if (isPickIntent) viewClicked(directory, position) else viewLongClicked(position); true }
|
||||
setOnClickListener { viewClicked(directory) }
|
||||
setOnLongClickListener { if (isPickIntent) viewClicked(directory) else viewLongClicked(); true }
|
||||
}
|
||||
return itemView
|
||||
}
|
||||
|
||||
private fun viewClicked(directory: Directory, position: Int) {
|
||||
private fun viewClicked(directory: Directory) {
|
||||
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(directory)
|
||||
}
|
||||
}
|
||||
|
||||
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)
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -251,7 +251,7 @@ class MediaAdapter(val activity: SimpleActivity, var media: MutableList<Medium>,
|
|||
}
|
||||
|
||||
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<Medium>,
|
|||
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)
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue