mirror of
https://github.com/SimpleMobileTools/Simple-App-Launcher.git
synced 2025-02-01 09:56:47 +01:00
implement launcher renaming
This commit is contained in:
parent
8a4f190f52
commit
0f2315f39d
@ -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
|
||||
|
@ -85,9 +85,15 @@ class RecyclerAdapter(val act: Activity, val launchers: List<AppLauncher>, 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)) {
|
||||
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<AppLauncher>, val i
|
||||
|
||||
interface EditLaunchersInterface {
|
||||
fun launchersDeleted(indexes: List<Int>, deletedLaunchers: List<AppLauncher>)
|
||||
|
||||
fun launcherRenamed()
|
||||
}
|
||||
}
|
||||
|
@ -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<AppLauncher> {
|
||||
val launchers = ArrayList<AppLauncher>()
|
||||
val cursor = readableDatabase.query(TABLE, arrayOf(ID, NAME, PKG_NAME, ICON_ID), null, null, null, null, NAME)
|
||||
|
@ -6,6 +6,7 @@
|
||||
<string name="ok">OK</string>
|
||||
<string name="cancel">Cancel</string>
|
||||
<string name="invalid_characters">New launcher name contains invalid characters</string>
|
||||
<string name="unknown_error">An unknown error occurred</string>
|
||||
|
||||
<!-- About -->
|
||||
<string name="about">About</string>
|
||||
|
Loading…
x
Reference in New Issue
Block a user