add ID to launchers

This commit is contained in:
tibbi 2016-08-15 23:44:20 +02:00
parent bad094482a
commit 223fcffee9
4 changed files with 13 additions and 7 deletions
app/src/main/kotlin/com/simplemobiletools/applauncher

@ -67,7 +67,7 @@ class MainActivity : SimpleActivity(), AddAppDialog.AddLaunchersInterface {
} }
private fun getNotDisplayedLaunchers(): ArrayList<AppLauncher> { private fun getNotDisplayedLaunchers(): ArrayList<AppLauncher> {
val apps = ArrayList<AppLauncher>() val allApps = ArrayList<AppLauncher>()
val intent = Intent(Intent.ACTION_MAIN, null) val intent = Intent(Intent.ACTION_MAIN, null)
intent.addCategory(Intent.CATEGORY_LAUNCHER) intent.addCategory(Intent.CATEGORY_LAUNCHER)
val list = packageManager.queryIntentActivities(intent, PackageManager.PERMISSION_GRANTED) val list = packageManager.queryIntentActivities(intent, PackageManager.PERMISSION_GRANTED)
@ -75,17 +75,17 @@ class MainActivity : SimpleActivity(), AddAppDialog.AddLaunchersInterface {
val componentInfo = info.activityInfo.applicationInfo val componentInfo = info.activityInfo.applicationInfo
val label = componentInfo.loadLabel(packageManager).toString() val label = componentInfo.loadLabel(packageManager).toString()
val pkgName = componentInfo.packageName val pkgName = componentInfo.packageName
apps.add(AppLauncher(label, pkgName, 0)) allApps.add(AppLauncher(0, label, pkgName, 0))
} }
val sorted = apps.sortedWith(compareBy { it.name.toLowerCase() }) val sorted = allApps.sortedWith(compareBy { it.name.toLowerCase() })
val unique = sorted.distinctBy { it.pkgName } val unique = sorted.distinctBy { it.pkgName }
val filtered = unique.filter { !launchers.contains(it) } val filtered = unique.filter { !launchers.contains(it) }
return filtered as ArrayList<AppLauncher> return filtered as ArrayList<AppLauncher>
} }
override fun selectedLaunchers(launchers: ArrayList<AppLauncher>) { override fun selectedLaunchers(launchers: ArrayList<AppLauncher>) {
for ((name, pkgName) in launchers) { for ((id, name, pkgName) in launchers) {
dbHelper.addLauncher(name, pkgName) dbHelper.addLauncher(name, pkgName)
} }
setupLaunchers() setupLaunchers()

@ -25,6 +25,11 @@ class RecyclerAdapter(val act: Activity, val launchers: List<AppLauncher>, val i
val deleteMode = object : ModalMultiSelectorCallback(multiSelector) { val deleteMode = object : ModalMultiSelectorCallback(multiSelector) {
override fun onActionItemClicked(mode: ActionMode?, item: MenuItem?): Boolean { override fun onActionItemClicked(mode: ActionMode?, item: MenuItem?): Boolean {
when (item?.itemId) {
R.id.cab_delete -> {
return true
}
}
return false return false
} }

@ -46,13 +46,14 @@ class DbHelper(context: Context) : SQLiteOpenHelper(context, "launchers.db", nul
fun getLaunchers(): ArrayList<AppLauncher> { fun getLaunchers(): ArrayList<AppLauncher> {
val launchers = ArrayList<AppLauncher>() val launchers = ArrayList<AppLauncher>()
val cursor = readableDatabase.query(TABLE, arrayOf(NAME, PKG_NAME, ICON_ID), null, null, null, null, NAME) val cursor = readableDatabase.query(TABLE, arrayOf(ID, NAME, PKG_NAME, ICON_ID), null, null, null, null, NAME)
try { try {
while (cursor.moveToNext()) { while (cursor.moveToNext()) {
val id = cursor.getInt(cursor.getColumnIndex(DbHelper.ID))
val name = cursor.getString(cursor.getColumnIndex(DbHelper.NAME)) val name = cursor.getString(cursor.getColumnIndex(DbHelper.NAME))
val pkgName = cursor.getString(cursor.getColumnIndex(DbHelper.PKG_NAME)) val pkgName = cursor.getString(cursor.getColumnIndex(DbHelper.PKG_NAME))
val icon = cursor.getInt(cursor.getColumnIndex(DbHelper.ICON_ID)) val icon = cursor.getInt(cursor.getColumnIndex(DbHelper.ICON_ID))
launchers.add(AppLauncher(name, pkgName, icon)) launchers.add(AppLauncher(id, name, pkgName, icon))
} }
} finally { } finally {
cursor.close() cursor.close()

@ -1,6 +1,6 @@
package com.simplemobiletools.applauncher.models package com.simplemobiletools.applauncher.models
data class AppLauncher(val name: String, val pkgName: String, val iconId: Int, var isChecked: Boolean = false) { data class AppLauncher(val id: Int, val name: String, val pkgName: String, val iconId: Int, var isChecked: Boolean = false) {
override fun equals(other: Any?): Boolean { override fun equals(other: Any?): Boolean {
return pkgName.equals((other as AppLauncher).pkgName) return pkgName.equals((other as AppLauncher).pkgName)
} }