refresh media thumbnails if only the grouping changes

This commit is contained in:
tibbi 2018-06-21 23:48:50 +02:00
parent 2a23632333
commit f47190b9e1
1 changed files with 8 additions and 5 deletions

View File

@ -39,6 +39,7 @@ class MediaAdapter(activity: BaseSimpleActivity, var media: MutableList<Medium>,
private var loadImageInstantly = false private var loadImageInstantly = false
private var delayHandler = Handler(Looper.getMainLooper()) private var delayHandler = Handler(Looper.getMainLooper())
private var currentMediaHash = media.hashCode() private var currentMediaHash = media.hashCode()
private var currentGrouping = GROUP_BY_NONE
private val hasOTGConnected = activity.hasOTGConnected() private val hasOTGConnected = activity.hasOTGConnected()
private var mediumGroups = LinkedHashMap<String, ArrayList<Medium>>() private var mediumGroups = LinkedHashMap<String, ArrayList<Medium>>()
@ -291,7 +292,7 @@ class MediaAdapter(activity: BaseSimpleActivity, var media: MutableList<Medium>,
} }
fun updateMedia(newMedia: ArrayList<Medium>) { fun updateMedia(newMedia: ArrayList<Medium>) {
if (newMedia.hashCode() != currentMediaHash) { if (newMedia.hashCode() != currentMediaHash || currentGrouping != getCurrentFolderGrouping()) {
currentMediaHash = newMedia.hashCode() currentMediaHash = newMedia.hashCode()
Handler().postDelayed({ Handler().postDelayed({
media = newMedia media = newMedia
@ -333,20 +334,20 @@ class MediaAdapter(activity: BaseSimpleActivity, var media: MutableList<Medium>,
} }
private fun groupMedia() { private fun groupMedia() {
val grouping = activity.config.getFolderGrouping(path) currentGrouping = getCurrentFolderGrouping()
if (grouping and GROUP_BY_NONE != 0) { if (currentGrouping and GROUP_BY_NONE != 0) {
return return
} }
media.forEach { media.forEach {
val key = it.getGroupingKey(grouping) val key = it.getGroupingKey(currentGrouping)
if (!mediumGroups.containsKey(key)) { if (!mediumGroups.containsKey(key)) {
mediumGroups[key] = ArrayList() mediumGroups[key] = ArrayList()
} }
mediumGroups[key]!!.add(it) mediumGroups[key]!!.add(it)
} }
val sortDescending = grouping and GROUP_DESCENDING != 0 val sortDescending = currentGrouping and GROUP_DESCENDING != 0
val sorted = mediumGroups.toSortedMap(if (sortDescending) compareByDescending { it } else compareBy { it }) val sorted = mediumGroups.toSortedMap(if (sortDescending) compareByDescending { it } else compareBy { it })
mediumGroups.clear() mediumGroups.clear()
sorted.forEach { key, value -> sorted.forEach { key, value ->
@ -354,6 +355,8 @@ class MediaAdapter(activity: BaseSimpleActivity, var media: MutableList<Medium>,
} }
} }
private fun getCurrentFolderGrouping() = activity.config.getFolderGrouping(path)
private fun setupView(view: View, medium: Medium) { private fun setupView(view: View, medium: Medium) {
view.apply { view.apply {
play_outline.beVisibleIf(medium.isVideo()) play_outline.beVisibleIf(medium.isVideo())