mirror of
https://github.com/FossifyOrg/Gallery.git
synced 2024-11-26 14:37:59 +01:00
properly update the items after delete
This commit is contained in:
parent
311d28242f
commit
b6bbc8abd7
2 changed files with 41 additions and 16 deletions
|
@ -291,10 +291,23 @@ class DirectoryAdapter(val activity: SimpleActivity, val dirs: MutableList<Direc
|
||||||
folders.add(File(directory.path))
|
folders.add(File(directory.path))
|
||||||
removeFolders.add(directory)
|
removeFolders.add(directory)
|
||||||
notifyItemRemoved(it)
|
notifyItemRemoved(it)
|
||||||
|
itemViews.put(it, null)
|
||||||
}
|
}
|
||||||
|
|
||||||
dirs.removeAll(removeFolders)
|
dirs.removeAll(removeFolders)
|
||||||
|
selectedPositions.clear()
|
||||||
listener?.tryDeleteFolders(folders)
|
listener?.tryDeleteFolders(folders)
|
||||||
|
|
||||||
|
val newItems = SparseArray<View>()
|
||||||
|
var curIndex = 0
|
||||||
|
for (i in 0..itemViews.size() - 1) {
|
||||||
|
if (itemViews[i] != null) {
|
||||||
|
newItems.put(curIndex, itemViews[i])
|
||||||
|
curIndex++
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
itemViews = newItems
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -311,7 +324,7 @@ class DirectoryAdapter(val activity: SimpleActivity, val dirs: MutableList<Direc
|
||||||
|
|
||||||
override fun onBindViewHolder(holder: ViewHolder, position: Int) {
|
override fun onBindViewHolder(holder: ViewHolder, position: Int) {
|
||||||
val dir = dirs[position]
|
val dir = dirs[position]
|
||||||
itemViews.put(position, holder.bindView(activity, multiSelectorMode, multiSelector, dir, position, pinnedFolders.contains(dir.path), listener))
|
itemViews.put(position, holder.bindView(activity, multiSelectorMode, multiSelector, dir, pinnedFolders.contains(dir.path), listener))
|
||||||
toggleItemSelection(selectedPositions.contains(position), position)
|
toggleItemSelection(selectedPositions.contains(position), position)
|
||||||
holder.itemView.tag = holder
|
holder.itemView.tag = holder
|
||||||
}
|
}
|
||||||
|
@ -363,7 +376,7 @@ class DirectoryAdapter(val activity: SimpleActivity, val dirs: MutableList<Direc
|
||||||
}
|
}
|
||||||
|
|
||||||
class ViewHolder(val view: View, val adapter: MyAdapterListener, val itemClick: (Directory) -> (Unit)) : SwappingHolder(view, MultiSelector()) {
|
class ViewHolder(val view: View, val adapter: MyAdapterListener, val itemClick: (Directory) -> (Unit)) : SwappingHolder(view, MultiSelector()) {
|
||||||
fun bindView(activity: SimpleActivity, multiSelectorCallback: ModalMultiSelectorCallback, multiSelector: MultiSelector, directory: Directory, pos: Int,
|
fun bindView(activity: SimpleActivity, multiSelectorCallback: ModalMultiSelectorCallback, multiSelector: MultiSelector, directory: Directory,
|
||||||
isPinned: Boolean, listener: DirOperationsListener?): View {
|
isPinned: Boolean, listener: DirOperationsListener?): View {
|
||||||
itemView.apply {
|
itemView.apply {
|
||||||
dir_name.text = directory.name
|
dir_name.text = directory.name
|
||||||
|
@ -371,15 +384,15 @@ class DirectoryAdapter(val activity: SimpleActivity, val dirs: MutableList<Direc
|
||||||
dir_pin.visibility = if (isPinned) View.VISIBLE else View.GONE
|
dir_pin.visibility = if (isPinned) View.VISIBLE else View.GONE
|
||||||
activity.loadImage(directory.tmb, dir_thumbnail)
|
activity.loadImage(directory.tmb, dir_thumbnail)
|
||||||
|
|
||||||
setOnClickListener { viewClicked(multiSelector, directory, pos) }
|
setOnClickListener { viewClicked(multiSelector, directory) }
|
||||||
setOnLongClickListener {
|
setOnLongClickListener {
|
||||||
if (listener != null) {
|
if (listener != null) {
|
||||||
if (!multiSelector.isSelectable) {
|
if (!multiSelector.isSelectable) {
|
||||||
activity.startSupportActionMode(multiSelectorCallback)
|
activity.startSupportActionMode(multiSelectorCallback)
|
||||||
adapter.toggleItemSelectionAdapter(true, pos)
|
adapter.toggleItemSelectionAdapter(true, layoutPosition)
|
||||||
}
|
}
|
||||||
|
|
||||||
listener.itemLongClicked(pos)
|
listener.itemLongClicked(layoutPosition)
|
||||||
}
|
}
|
||||||
true
|
true
|
||||||
}
|
}
|
||||||
|
@ -389,10 +402,10 @@ class DirectoryAdapter(val activity: SimpleActivity, val dirs: MutableList<Direc
|
||||||
return itemView
|
return itemView
|
||||||
}
|
}
|
||||||
|
|
||||||
fun viewClicked(multiSelector: MultiSelector, directory: Directory, pos: Int) {
|
fun viewClicked(multiSelector: MultiSelector, directory: Directory) {
|
||||||
if (multiSelector.isSelectable) {
|
if (multiSelector.isSelectable) {
|
||||||
val isSelected = adapter.getSelectedPositions().contains(pos)
|
val isSelected = adapter.getSelectedPositions().contains(layoutPosition)
|
||||||
adapter.toggleItemSelectionAdapter(!isSelected, pos)
|
adapter.toggleItemSelectionAdapter(!isSelected, layoutPosition)
|
||||||
} else {
|
} else {
|
||||||
itemClick(directory)
|
itemClick(directory)
|
||||||
}
|
}
|
||||||
|
|
|
@ -228,11 +228,23 @@ class MediaAdapter(val activity: SimpleActivity, var media: MutableList<Medium>,
|
||||||
files.add(File(medium.path))
|
files.add(File(medium.path))
|
||||||
removeMedia.add(medium)
|
removeMedia.add(medium)
|
||||||
notifyItemRemoved(it)
|
notifyItemRemoved(it)
|
||||||
|
itemViews.put(it, null)
|
||||||
}
|
}
|
||||||
|
|
||||||
media.removeAll(removeMedia)
|
media.removeAll(removeMedia)
|
||||||
selectedPositions.clear()
|
selectedPositions.clear()
|
||||||
listener?.deleteFiles(files)
|
listener?.deleteFiles(files)
|
||||||
|
|
||||||
|
val newItems = SparseArray<View>()
|
||||||
|
var curIndex = 0
|
||||||
|
for (i in 0..itemViews.size() - 1) {
|
||||||
|
if (itemViews[i] != null) {
|
||||||
|
newItems.put(curIndex, itemViews[i])
|
||||||
|
curIndex++
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
itemViews = newItems
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -248,7 +260,7 @@ class MediaAdapter(val activity: SimpleActivity, var media: MutableList<Medium>,
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun onBindViewHolder(holder: ViewHolder, position: Int) {
|
override fun onBindViewHolder(holder: ViewHolder, position: Int) {
|
||||||
itemViews.put(position, holder.bindView(activity, multiSelectorMode, multiSelector, media[position], position, listener, displayFilenames))
|
itemViews.put(position, holder.bindView(activity, multiSelectorMode, multiSelector, media[position], listener, displayFilenames))
|
||||||
toggleItemSelection(selectedPositions.contains(position), position)
|
toggleItemSelection(selectedPositions.contains(position), position)
|
||||||
holder.itemView.tag = holder
|
holder.itemView.tag = holder
|
||||||
}
|
}
|
||||||
|
@ -311,22 +323,22 @@ class MediaAdapter(val activity: SimpleActivity, var media: MutableList<Medium>,
|
||||||
|
|
||||||
class ViewHolder(val view: View, val adapter: MyAdapterListener, val itemClick: (Medium) -> (Unit)) : SwappingHolder(view, MultiSelector()) {
|
class ViewHolder(val view: View, val adapter: MyAdapterListener, val itemClick: (Medium) -> (Unit)) : SwappingHolder(view, MultiSelector()) {
|
||||||
fun bindView(activity: SimpleActivity, multiSelectorCallback: ModalMultiSelectorCallback, multiSelector: MultiSelector, medium: Medium,
|
fun bindView(activity: SimpleActivity, multiSelectorCallback: ModalMultiSelectorCallback, multiSelector: MultiSelector, medium: Medium,
|
||||||
pos: Int, listener: MediaOperationsListener?, displayFilenames: Boolean): View {
|
listener: MediaOperationsListener?, displayFilenames: Boolean): View {
|
||||||
itemView.apply {
|
itemView.apply {
|
||||||
play_outline.visibility = if (medium.video) View.VISIBLE else View.GONE
|
play_outline.visibility = if (medium.video) View.VISIBLE else View.GONE
|
||||||
photo_name.beVisibleIf(displayFilenames)
|
photo_name.beVisibleIf(displayFilenames)
|
||||||
photo_name.text = medium.name
|
photo_name.text = medium.name
|
||||||
activity.loadImage(medium.path, medium_thumbnail)
|
activity.loadImage(medium.path, medium_thumbnail)
|
||||||
|
|
||||||
setOnClickListener { viewClicked(multiSelector, medium, pos) }
|
setOnClickListener { viewClicked(multiSelector, medium) }
|
||||||
setOnLongClickListener {
|
setOnLongClickListener {
|
||||||
if (listener != null) {
|
if (listener != null) {
|
||||||
if (!multiSelector.isSelectable) {
|
if (!multiSelector.isSelectable) {
|
||||||
activity.startSupportActionMode(multiSelectorCallback)
|
activity.startSupportActionMode(multiSelectorCallback)
|
||||||
adapter.toggleItemSelectionAdapter(true, pos)
|
adapter.toggleItemSelectionAdapter(true, layoutPosition)
|
||||||
}
|
}
|
||||||
|
|
||||||
listener.itemLongClicked(pos)
|
listener.itemLongClicked(layoutPosition)
|
||||||
}
|
}
|
||||||
true
|
true
|
||||||
}
|
}
|
||||||
|
@ -336,10 +348,10 @@ class MediaAdapter(val activity: SimpleActivity, var media: MutableList<Medium>,
|
||||||
return itemView
|
return itemView
|
||||||
}
|
}
|
||||||
|
|
||||||
fun viewClicked(multiSelector: MultiSelector, medium: Medium, pos: Int) {
|
fun viewClicked(multiSelector: MultiSelector, medium: Medium) {
|
||||||
if (multiSelector.isSelectable) {
|
if (multiSelector.isSelectable) {
|
||||||
val isSelected = adapter.getSelectedPositions().contains(pos)
|
val isSelected = adapter.getSelectedPositions().contains(layoutPosition)
|
||||||
adapter.toggleItemSelectionAdapter(!isSelected, pos)
|
adapter.toggleItemSelectionAdapter(!isSelected, layoutPosition)
|
||||||
} else {
|
} else {
|
||||||
itemClick(medium)
|
itemClick(medium)
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue