From 223fcffee9154e04ac9407fde174e9c10f4a5a70 Mon Sep 17 00:00:00 2001 From: tibbi Date: Mon, 15 Aug 2016 23:44:20 +0200 Subject: [PATCH] add ID to launchers --- .../applauncher/activities/MainActivity.kt | 8 ++++---- .../applauncher/adapters/RecyclerAdapter.kt | 5 +++++ .../simplemobiletools/applauncher/databases/DbHelper.kt | 5 +++-- .../simplemobiletools/applauncher/models/AppLauncher.kt | 2 +- 4 files changed, 13 insertions(+), 7 deletions(-) diff --git a/app/src/main/kotlin/com/simplemobiletools/applauncher/activities/MainActivity.kt b/app/src/main/kotlin/com/simplemobiletools/applauncher/activities/MainActivity.kt index e87afd6..0994cfe 100644 --- a/app/src/main/kotlin/com/simplemobiletools/applauncher/activities/MainActivity.kt +++ b/app/src/main/kotlin/com/simplemobiletools/applauncher/activities/MainActivity.kt @@ -67,7 +67,7 @@ class MainActivity : SimpleActivity(), AddAppDialog.AddLaunchersInterface { } private fun getNotDisplayedLaunchers(): ArrayList { - val apps = ArrayList() + val allApps = ArrayList() val intent = Intent(Intent.ACTION_MAIN, null) intent.addCategory(Intent.CATEGORY_LAUNCHER) val list = packageManager.queryIntentActivities(intent, PackageManager.PERMISSION_GRANTED) @@ -75,17 +75,17 @@ class MainActivity : SimpleActivity(), AddAppDialog.AddLaunchersInterface { val componentInfo = info.activityInfo.applicationInfo val label = componentInfo.loadLabel(packageManager).toString() 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 filtered = unique.filter { !launchers.contains(it) } return filtered as ArrayList } override fun selectedLaunchers(launchers: ArrayList) { - for ((name, pkgName) in launchers) { + for ((id, name, pkgName) in launchers) { dbHelper.addLauncher(name, pkgName) } setupLaunchers() diff --git a/app/src/main/kotlin/com/simplemobiletools/applauncher/adapters/RecyclerAdapter.kt b/app/src/main/kotlin/com/simplemobiletools/applauncher/adapters/RecyclerAdapter.kt index 613615b..f2c6db6 100644 --- a/app/src/main/kotlin/com/simplemobiletools/applauncher/adapters/RecyclerAdapter.kt +++ b/app/src/main/kotlin/com/simplemobiletools/applauncher/adapters/RecyclerAdapter.kt @@ -25,6 +25,11 @@ class RecyclerAdapter(val act: Activity, val launchers: List, val i val deleteMode = object : ModalMultiSelectorCallback(multiSelector) { override fun onActionItemClicked(mode: ActionMode?, item: MenuItem?): Boolean { + when (item?.itemId) { + R.id.cab_delete -> { + return true + } + } return false } diff --git a/app/src/main/kotlin/com/simplemobiletools/applauncher/databases/DbHelper.kt b/app/src/main/kotlin/com/simplemobiletools/applauncher/databases/DbHelper.kt index 7a2540b..0d52050 100644 --- a/app/src/main/kotlin/com/simplemobiletools/applauncher/databases/DbHelper.kt +++ b/app/src/main/kotlin/com/simplemobiletools/applauncher/databases/DbHelper.kt @@ -46,13 +46,14 @@ class DbHelper(context: Context) : SQLiteOpenHelper(context, "launchers.db", nul fun getLaunchers(): ArrayList { val launchers = ArrayList() - 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 { while (cursor.moveToNext()) { + val id = cursor.getInt(cursor.getColumnIndex(DbHelper.ID)) val name = cursor.getString(cursor.getColumnIndex(DbHelper.NAME)) val pkgName = cursor.getString(cursor.getColumnIndex(DbHelper.PKG_NAME)) val icon = cursor.getInt(cursor.getColumnIndex(DbHelper.ICON_ID)) - launchers.add(AppLauncher(name, pkgName, icon)) + launchers.add(AppLauncher(id, name, pkgName, icon)) } } finally { cursor.close() diff --git a/app/src/main/kotlin/com/simplemobiletools/applauncher/models/AppLauncher.kt b/app/src/main/kotlin/com/simplemobiletools/applauncher/models/AppLauncher.kt index 4dc0c7d..08cb12f 100644 --- a/app/src/main/kotlin/com/simplemobiletools/applauncher/models/AppLauncher.kt +++ b/app/src/main/kotlin/com/simplemobiletools/applauncher/models/AppLauncher.kt @@ -1,6 +1,6 @@ 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 { return pkgName.equals((other as AppLauncher).pkgName) }