mirror of
https://github.com/SimpleMobileTools/Simple-App-Launcher.git
synced 2025-03-04 03:17:41 +01:00
update the launchers and actionbar after every dialog action
This commit is contained in:
parent
0f2315f39d
commit
54f7b7dfa5
@ -97,11 +97,11 @@ class MainActivity : SimpleActivity(), AddAppDialog.AddLaunchersInterface, Recyc
|
|||||||
launchers = launchers.filter { !invalidIds.contains(it.id.toString()) } as ArrayList<AppLauncher>
|
launchers = launchers.filter { !invalidIds.contains(it.id.toString()) } as ArrayList<AppLauncher>
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun selectedLaunchers(launchers: ArrayList<AppLauncher>) {
|
override fun addLaunchers(launchers: ArrayList<AppLauncher>) {
|
||||||
for ((id, name, pkgName) in launchers) {
|
for ((id, name, pkgName) in launchers) {
|
||||||
dbHelper.addLauncher(name, pkgName)
|
dbHelper.addLauncher(name, pkgName)
|
||||||
}
|
}
|
||||||
setupLaunchers()
|
refreshLaunchers()
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun launchersDeleted(indexes: List<Int>, deletedLaunchers: List<AppLauncher>) {
|
override fun launchersDeleted(indexes: List<Int>, deletedLaunchers: List<AppLauncher>) {
|
||||||
@ -116,6 +116,15 @@ class MainActivity : SimpleActivity(), AddAppDialog.AddLaunchersInterface, Recyc
|
|||||||
}
|
}
|
||||||
|
|
||||||
override fun launcherRenamed() {
|
override fun launcherRenamed() {
|
||||||
|
refreshLaunchers()
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun updateLaunchers() {
|
||||||
|
refreshLaunchers()
|
||||||
|
}
|
||||||
|
|
||||||
|
fun refreshLaunchers() {
|
||||||
|
(launchers_holder.adapter as RecyclerAdapter).finishActionMode()
|
||||||
setupLaunchers()
|
setupLaunchers()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -34,6 +34,7 @@ class RecyclerAdapter(val act: Activity, val launchers: List<AppLauncher>, val i
|
|||||||
when (item?.itemId) {
|
when (item?.itemId) {
|
||||||
R.id.cab_edit -> {
|
R.id.cab_edit -> {
|
||||||
showEditDialog()
|
showEditDialog()
|
||||||
|
return true
|
||||||
}
|
}
|
||||||
R.id.cab_delete -> {
|
R.id.cab_delete -> {
|
||||||
deleteSelectedItems()
|
deleteSelectedItems()
|
||||||
@ -89,7 +90,7 @@ class RecyclerAdapter(val act: Activity, val launchers: List<AppLauncher>, val i
|
|||||||
if (isValidName(newName)) {
|
if (isValidName(newName)) {
|
||||||
if (DbHelper(act).updateLauncherName(selectedLauncher.id, newName) > 0) {
|
if (DbHelper(act).updateLauncherName(selectedLauncher.id, newName) > 0) {
|
||||||
(act as EditLaunchersInterface).launcherRenamed()
|
(act as EditLaunchersInterface).launcherRenamed()
|
||||||
actMode?.finish()
|
finishActionMode()
|
||||||
alertDialog.dismiss()
|
alertDialog.dismiss()
|
||||||
} else {
|
} else {
|
||||||
Toast.makeText(act, act.resources.getString(R.string.unknown_error), Toast.LENGTH_SHORT).show()
|
Toast.makeText(act, act.resources.getString(R.string.unknown_error), Toast.LENGTH_SHORT).show()
|
||||||
@ -100,6 +101,10 @@ class RecyclerAdapter(val act: Activity, val launchers: List<AppLauncher>, val i
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fun finishActionMode() {
|
||||||
|
actMode?.finish()
|
||||||
|
}
|
||||||
|
|
||||||
private fun isValidName(newName: String): Boolean {
|
private fun isValidName(newName: String): Boolean {
|
||||||
val pattern = Pattern.compile("[0-9a-zA-Z-_. ]+")
|
val pattern = Pattern.compile("[0-9a-zA-Z-_. ]+")
|
||||||
return pattern.matcher(newName).matches()
|
return pattern.matcher(newName).matches()
|
||||||
@ -114,7 +119,7 @@ class RecyclerAdapter(val act: Activity, val launchers: List<AppLauncher>, val i
|
|||||||
deleteIds.add(launchers[i].id.toString())
|
deleteIds.add(launchers[i].id.toString())
|
||||||
}
|
}
|
||||||
DbHelper(act).deleteLaunchers(deleteIds)
|
DbHelper(act).deleteLaunchers(deleteIds)
|
||||||
actMode?.finish()
|
finishActionMode()
|
||||||
(act as EditLaunchersInterface).launchersDeleted(positions, deletedLaunchers)
|
(act as EditLaunchersInterface).launchersDeleted(positions, deletedLaunchers)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -33,14 +33,18 @@ class AddAppDialog() : DialogFragment() {
|
|||||||
|
|
||||||
builder.setPositiveButton(android.R.string.ok, { dialogInterface, i ->
|
builder.setPositiveButton(android.R.string.ok, { dialogInterface, i ->
|
||||||
val selectedApps = launchers.filter { it.isChecked } as ArrayList<AppLauncher>
|
val selectedApps = launchers.filter { it.isChecked } as ArrayList<AppLauncher>
|
||||||
callback?.selectedLaunchers(selectedApps)
|
callback?.addLaunchers(selectedApps)
|
||||||
})
|
})
|
||||||
|
|
||||||
builder.setNegativeButton(android.R.string.cancel, null)
|
builder.setNegativeButton(android.R.string.cancel, { dialogInterface, i ->
|
||||||
|
callback?.updateLaunchers()
|
||||||
|
})
|
||||||
return builder.create()
|
return builder.create()
|
||||||
}
|
}
|
||||||
|
|
||||||
interface AddLaunchersInterface {
|
interface AddLaunchersInterface {
|
||||||
fun selectedLaunchers(launchers: ArrayList<AppLauncher>)
|
fun addLaunchers(launchers: ArrayList<AppLauncher>)
|
||||||
|
|
||||||
|
fun updateLaunchers()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user