mirror of
https://github.com/SimpleMobileTools/Simple-App-Launcher.git
synced 2025-02-01 18:06:47 +01:00
implementing sorting by title
This commit is contained in:
parent
ea5199b26e
commit
4765b23831
@ -117,8 +117,14 @@ class MainActivity : SimpleActivity(), RefreshRecyclerViewListener {
|
||||
displayedLaunchers = dbHelper.getLaunchers()
|
||||
checkInvalidApps()
|
||||
initZoomListener()
|
||||
setupAdapter(displayedLaunchers)
|
||||
}
|
||||
|
||||
LaunchersAdapter(this, displayedLaunchers, this, launchers_grid, launchers_fastscroller) {
|
||||
private fun setupAdapter(launchers: ArrayList<AppLauncher>) {
|
||||
AppLauncher.sorting = config.sorting
|
||||
launchers.sort()
|
||||
|
||||
LaunchersAdapter(this, launchers, this, launchers_grid, launchers_fastscroller) {
|
||||
val launchIntent = packageManager.getLaunchIntentForPackage((it as AppLauncher).packageName)
|
||||
if (launchIntent != null) {
|
||||
try {
|
||||
@ -142,17 +148,18 @@ class MainActivity : SimpleActivity(), RefreshRecyclerViewListener {
|
||||
}
|
||||
|
||||
launchers_fastscroller.setViews(launchers_grid) {
|
||||
launchers_fastscroller.updateBubbleText(displayedLaunchers.getOrNull(it)?.getBubbleText() ?: "")
|
||||
val item = (launchers_grid.adapter as LaunchersAdapter).launchers.getOrNull(it)
|
||||
launchers_fastscroller.updateBubbleText(item?.getBubbleText() ?: "")
|
||||
}
|
||||
|
||||
ensureBackgroundThread {
|
||||
notDisplayedLaunchers = getNotDisplayedLaunchers(displayedLaunchers)
|
||||
notDisplayedLaunchers = getNotDisplayedLaunchers(launchers)
|
||||
}
|
||||
}
|
||||
|
||||
private fun showSortingDialog() {
|
||||
ChangeSortingDialog(this) {
|
||||
|
||||
setupAdapter(displayedLaunchers)
|
||||
}
|
||||
}
|
||||
|
||||
@ -214,6 +221,7 @@ class MainActivity : SimpleActivity(), RefreshRecyclerViewListener {
|
||||
invalidIds.add(id.toString())
|
||||
}
|
||||
}
|
||||
|
||||
dbHelper.deleteLaunchers(invalidIds)
|
||||
displayedLaunchers = displayedLaunchers.filter { !invalidIds.contains(it.id.toString()) } as ArrayList<AppLauncher>
|
||||
}
|
||||
|
@ -1,9 +1,28 @@
|
||||
package com.simplemobiletools.applauncher.models
|
||||
|
||||
import android.graphics.drawable.Drawable
|
||||
import com.simplemobiletools.commons.helpers.SORT_BY_TITLE
|
||||
import com.simplemobiletools.commons.helpers.SORT_DESCENDING
|
||||
|
||||
data class AppLauncher(val id: Int, var title: String, val packageName: String, val drawable: Drawable? = null) : Comparable<AppLauncher> {
|
||||
companion object {
|
||||
var sorting = 0
|
||||
}
|
||||
|
||||
data class AppLauncher(val id: Int, var title: String, val packageName: String, val drawable: Drawable? = null) {
|
||||
override fun equals(other: Any?) = packageName.equals((other as AppLauncher).packageName, true)
|
||||
|
||||
fun getBubbleText() = title
|
||||
|
||||
override fun compareTo(other: AppLauncher): Int {
|
||||
var result = when {
|
||||
sorting and SORT_BY_TITLE != 0 -> title.compareTo(other.title)
|
||||
else -> 1
|
||||
}
|
||||
|
||||
if (sorting and SORT_DESCENDING != 0) {
|
||||
result *= -1
|
||||
}
|
||||
|
||||
return result
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user