sort medium groups appropriately

This commit is contained in:
tibbi 2018-06-21 23:41:34 +02:00
parent e3fde0a6eb
commit 2a23632333
1 changed files with 10 additions and 2 deletions

View File

@ -19,10 +19,11 @@ import com.simplemobiletools.gallery.R
import com.simplemobiletools.gallery.dialogs.DeleteWithRememberDialog
import com.simplemobiletools.gallery.extensions.*
import com.simplemobiletools.gallery.helpers.GROUP_BY_NONE
import com.simplemobiletools.gallery.helpers.GROUP_DESCENDING
import com.simplemobiletools.gallery.helpers.VIEW_TYPE_LIST
import com.simplemobiletools.gallery.models.Medium
import kotlinx.android.synthetic.main.photo_video_item_grid.view.*
import java.util.HashMap
import java.util.*
import kotlin.collections.ArrayList
class MediaAdapter(activity: BaseSimpleActivity, var media: MutableList<Medium>, val listener: MediaOperationsListener?, val isAGetIntent: Boolean,
@ -39,7 +40,7 @@ class MediaAdapter(activity: BaseSimpleActivity, var media: MutableList<Medium>,
private var delayHandler = Handler(Looper.getMainLooper())
private var currentMediaHash = media.hashCode()
private val hasOTGConnected = activity.hasOTGConnected()
private var mediumGroups = HashMap<String, ArrayList<Medium>>()
private var mediumGroups = LinkedHashMap<String, ArrayList<Medium>>()
private var scrollHorizontally = config.scrollHorizontally
private var animateGifs = config.animateGifs
@ -344,6 +345,13 @@ class MediaAdapter(activity: BaseSimpleActivity, var media: MutableList<Medium>,
}
mediumGroups[key]!!.add(it)
}
val sortDescending = grouping and GROUP_DESCENDING != 0
val sorted = mediumGroups.toSortedMap(if (sortDescending) compareByDescending { it } else compareBy { it })
mediumGroups.clear()
sorted.forEach { key, value ->
mediumGroups[key] = value
}
}
private fun setupView(view: View, medium: Medium) {