properly handle custom sorting

This commit is contained in:
tibbi 2020-11-08 10:03:03 +01:00
parent 4da1259e58
commit da7acb2c9f
2 changed files with 22 additions and 10 deletions
app/src/main/kotlin/com/simplemobiletools/applauncher

@ -93,9 +93,8 @@ class LaunchersAdapter(activity: SimpleActivity, val launchers: ArrayList<AppLau
override fun onActionModeCreated() {}
override fun onActionModeDestroyed() {
isChangingOrder = false
if (isChangingOrder) {
notifyDataSetChanged()
launchers.forEachIndexed { index, appLauncher ->
appLauncher.order = index + 1
}
@ -105,6 +104,9 @@ class LaunchersAdapter(activity: SimpleActivity, val launchers: ArrayList<AppLau
}
}
isChangingOrder = false
}
private fun changeOrder() {
isChangingOrder = true
notifyDataSetChanged()

@ -16,7 +16,17 @@ data class AppLauncher(val id: Int, var title: String, val packageName: String,
override fun compareTo(other: AppLauncher): Int {
var result = when {
sorting and SORT_BY_TITLE != 0 -> title.toLowerCase().compareTo(other.title.toLowerCase())
else -> order.compareTo(other.order)
else -> {
if (order > 0 && other.order == 0) {
-1
} else if (order == 0 && other.order > 0) {
1
} else if (order > 0 && other.order > 0) {
order.compareTo(other.order)
} else {
title.toLowerCase().compareTo(other.title.toLowerCase())
}
}
}
if (sorting and SORT_DESCENDING != 0) {