mirror of
https://github.com/SimpleMobileTools/Simple-App-Launcher.git
synced 2025-03-05 20:07:49 +01:00
save launcher order at reordering
This commit is contained in:
parent
6a014936a9
commit
4da1259e58
@ -17,6 +17,7 @@ import com.simplemobiletools.commons.dialogs.ConfirmationDialog
|
||||
import com.simplemobiletools.commons.extensions.applyColorFilter
|
||||
import com.simplemobiletools.commons.extensions.beInvisibleIf
|
||||
import com.simplemobiletools.commons.extensions.beVisibleIf
|
||||
import com.simplemobiletools.commons.helpers.SORT_BY_CUSTOM
|
||||
import com.simplemobiletools.commons.interfaces.ItemMoveCallback
|
||||
import com.simplemobiletools.commons.interfaces.ItemTouchHelperContract
|
||||
import com.simplemobiletools.commons.interfaces.RefreshRecyclerViewListener
|
||||
@ -94,6 +95,14 @@ class LaunchersAdapter(activity: SimpleActivity, val launchers: ArrayList<AppLau
|
||||
override fun onActionModeDestroyed() {
|
||||
isChangingOrder = false
|
||||
notifyDataSetChanged()
|
||||
|
||||
launchers.forEachIndexed { index, appLauncher ->
|
||||
appLauncher.order = index + 1
|
||||
}
|
||||
|
||||
launchers.forEach {
|
||||
activity.dbHelper.updateLauncherOrder(it.id, it.order)
|
||||
}
|
||||
}
|
||||
|
||||
private fun changeOrder() {
|
||||
@ -180,7 +189,9 @@ class LaunchersAdapter(activity: SimpleActivity, val launchers: ArrayList<AppLau
|
||||
Collections.swap(launchers, i, i - 1)
|
||||
}
|
||||
}
|
||||
|
||||
notifyItemMoved(fromPosition, toPosition)
|
||||
activity.config.sorting = SORT_BY_CUSTOM
|
||||
}
|
||||
|
||||
override fun onRowClear(myViewHolder: ViewHolder?) {
|
||||
|
@ -138,6 +138,16 @@ class DBHelper private constructor(val context: Context) : SQLiteOpenHelper(cont
|
||||
return mDb.update(MAIN_TABLE_NAME, values, selection, selectionArgs) == 1
|
||||
}
|
||||
|
||||
fun updateLauncherOrder(id: Int, order: Int) {
|
||||
val values = ContentValues().apply {
|
||||
put(COL_APP_ORDER, order)
|
||||
}
|
||||
|
||||
val selection = "$COL_ID = ?"
|
||||
val selectionArgs = Array(1) { id.toString() }
|
||||
mDb.update(MAIN_TABLE_NAME, values, selection, selectionArgs)
|
||||
}
|
||||
|
||||
fun getLaunchers(): ArrayList<AppLauncher> {
|
||||
val resources = context.resources
|
||||
val packageManager = context.packageManager
|
||||
|
@ -4,7 +4,7 @@ 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 order: Int, val drawable: Drawable? = null) : Comparable<AppLauncher> {
|
||||
data class AppLauncher(val id: Int, var title: String, val packageName: String, var order: Int, val drawable: Drawable? = null) : Comparable<AppLauncher> {
|
||||
companion object {
|
||||
var sorting = 0
|
||||
}
|
||||
@ -16,7 +16,7 @@ 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 -> 1
|
||||
else -> order.compareTo(other.order)
|
||||
}
|
||||
|
||||
if (sorting and SORT_DESCENDING != 0) {
|
||||
|
Loading…
x
Reference in New Issue
Block a user