properly handle grid updating if a thumbnail gets deleted

This commit is contained in:
tibbi 2021-01-20 23:12:39 +01:00
parent 58a9150db0
commit 7f2db07892
4 changed files with 24 additions and 0 deletions

View file

@ -46,6 +46,7 @@ import kotlinx.android.synthetic.main.activity_media.*
import java.io.File import java.io.File
import java.io.IOException import java.io.IOException
import java.util.* import java.util.*
import kotlin.collections.ArrayList
class MediaActivity : SimpleActivity(), MediaOperationsListener { class MediaActivity : SimpleActivity(), MediaOperationsListener {
private val LAST_MEDIA_CHECK_PERIOD = 3000L private val LAST_MEDIA_CHECK_PERIOD = 3000L
@ -989,6 +990,22 @@ class MediaActivity : SimpleActivity(), MediaOperationsListener {
finish() finish()
} }
override fun updateMediaGridDecoration(media: ArrayList<ThumbnailItem>) {
var currentGridPosition = 0
media.forEach {
if (it is Medium) {
it.gridPosition = currentGridPosition++
} else if (it is ThumbnailSection) {
currentGridPosition = 0
}
}
if (media_grid.itemDecorationCount > 0) {
val currentGridDecoration = media_grid.getItemDecorationAt(0) as GridSpacingItemDecoration
currentGridDecoration.items = media
}
}
private fun setAsDefaultFolder() { private fun setAsDefaultFolder() {
config.defaultFolder = mPath config.defaultFolder = mPath
invalidateOptionsMenu() invalidateOptionsMenu()

View file

@ -379,4 +379,7 @@ class SearchActivity : SimpleActivity(), MediaOperationsListener {
override fun selectedPaths(paths: ArrayList<String>) { override fun selectedPaths(paths: ArrayList<String>) {
} }
override fun updateMediaGridDecoration(media: ArrayList<ThumbnailItem>) {
}
} }

View file

@ -439,6 +439,7 @@ class MediaAdapter(activity: BaseSimpleActivity, var media: ArrayList<ThumbnailI
media.removeAll(removeMedia) media.removeAll(removeMedia)
listener?.tryDeleteFiles(fileDirItems) listener?.tryDeleteFiles(fileDirItems)
listener?.updateMediaGridDecoration(media)
removeSelectedItems(positions) removeSelectedItems(positions)
currentMediaHash = media.hashCode() currentMediaHash = media.hashCode()
} }

View file

@ -1,6 +1,7 @@
package com.simplemobiletools.gallery.pro.interfaces package com.simplemobiletools.gallery.pro.interfaces
import com.simplemobiletools.commons.models.FileDirItem import com.simplemobiletools.commons.models.FileDirItem
import com.simplemobiletools.gallery.pro.models.ThumbnailItem
interface MediaOperationsListener { interface MediaOperationsListener {
fun refreshItems() fun refreshItems()
@ -8,4 +9,6 @@ interface MediaOperationsListener {
fun tryDeleteFiles(fileDirItems: ArrayList<FileDirItem>) fun tryDeleteFiles(fileDirItems: ArrayList<FileDirItem>)
fun selectedPaths(paths: ArrayList<String>) fun selectedPaths(paths: ArrayList<String>)
fun updateMediaGridDecoration(media: ArrayList<ThumbnailItem>)
} }