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

View File

@ -93,16 +93,18 @@ class LaunchersAdapter(activity: SimpleActivity, val launchers: ArrayList<AppLau
override fun onActionModeCreated() {}
override fun onActionModeDestroyed() {
if (isChangingOrder) {
notifyDataSetChanged()
launchers.forEachIndexed { index, appLauncher ->
appLauncher.order = index + 1
}
launchers.forEach {
activity.dbHelper.updateLauncherOrder(it.id, it.order)
}
}
isChangingOrder = false
notifyDataSetChanged()
launchers.forEachIndexed { index, appLauncher ->
appLauncher.order = index + 1
}
launchers.forEach {
activity.dbHelper.updateLauncherOrder(it.id, it.order)
}
}
private fun changeOrder() {

View File

@ -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) {