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 068defa..3b4aef1 100644 --- a/app/src/main/kotlin/com/simplemobiletools/applauncher/activities/MainActivity.kt +++ b/app/src/main/kotlin/com/simplemobiletools/applauncher/activities/MainActivity.kt @@ -115,6 +115,10 @@ class MainActivity : SimpleActivity(), AddAppDialog.AddLaunchersInterface, Recyc remainingLaunchers.sortBy { it.name } } + override fun launcherRenamed() { + setupLaunchers() + } + override fun onDestroy() { super.onDestroy() preferences.isFirstRun = false 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 d0c8abd..15a715f 100644 --- a/app/src/main/kotlin/com/simplemobiletools/applauncher/adapters/RecyclerAdapter.kt +++ b/app/src/main/kotlin/com/simplemobiletools/applauncher/adapters/RecyclerAdapter.kt @@ -85,9 +85,15 @@ class RecyclerAdapter(val act: Activity, val launchers: List, val i val alertDialog = builder.create() alertDialog.show() alertDialog.getButton(AlertDialog.BUTTON_POSITIVE).setOnClickListener { - val newName = editView.edit_launcher_edittext.text.toString() + val newName = editView.edit_launcher_edittext.text.toString().trim() if (isValidName(newName)) { - alertDialog.dismiss() + if (DbHelper(act).updateLauncherName(selectedLauncher.id, newName) > 0) { + (act as EditLaunchersInterface).launcherRenamed() + actMode?.finish() + alertDialog.dismiss() + } else { + Toast.makeText(act, act.resources.getString(R.string.unknown_error), Toast.LENGTH_SHORT).show() + } } else { Toast.makeText(act, act.resources.getString(R.string.invalid_characters), Toast.LENGTH_SHORT).show() } @@ -167,5 +173,7 @@ class RecyclerAdapter(val act: Activity, val launchers: List, val i interface EditLaunchersInterface { fun launchersDeleted(indexes: List, deletedLaunchers: List) + + fun launcherRenamed() } } 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 15b9e0e..d0bcdda 100644 --- a/app/src/main/kotlin/com/simplemobiletools/applauncher/databases/DbHelper.kt +++ b/app/src/main/kotlin/com/simplemobiletools/applauncher/databases/DbHelper.kt @@ -52,6 +52,14 @@ class DbHelper(context: Context) : SQLiteOpenHelper(context, "launchers.db", nul writableDatabase.delete(TABLE, "$ID IN ($args)", null) } + fun updateLauncherName(id: Int, newName: String): Int { + val values = ContentValues() + values.put(NAME, newName) + val selection = ID + " = ?" + val selectionArgs = Array(1) { id.toString() } + return writableDatabase.update(TABLE, values, selection, selectionArgs) + } + fun getLaunchers(): ArrayList { val launchers = ArrayList() val cursor = readableDatabase.query(TABLE, arrayOf(ID, NAME, PKG_NAME, ICON_ID), null, null, null, null, NAME) diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index c985589..e57ce1b 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -6,6 +6,7 @@ OK Cancel New launcher name contains invalid characters + An unknown error occurred About