automatically remove launchers of uninstalled apps

This commit is contained in:
tibbi 2016-08-16 23:20:10 +02:00
parent 1d78da67a3
commit cbb077de35

View File

@ -54,6 +54,7 @@ class MainActivity : SimpleActivity(), AddAppDialog.AddLaunchersInterface, Recyc
private fun setupLaunchers() {
launchers = dbHelper.getLaunchers()
checkInvalidApps()
launchers_holder.adapter = RecyclerAdapter(this, launchers) {
val launchIntent = packageManager.getLaunchIntentForPackage(it.pkgName)
if (launchIntent != null) {
@ -84,6 +85,18 @@ class MainActivity : SimpleActivity(), AddAppDialog.AddLaunchersInterface, Recyc
return filtered as ArrayList<AppLauncher>
}
private fun checkInvalidApps() {
val invalidIds = ArrayList<String>()
for ((id, name, pkgName) in launchers) {
val launchIntent = packageManager.getLaunchIntentForPackage(pkgName)
if (launchIntent == null && !pkgName.startsWith("com.simplemobiletools")) {
invalidIds.add(id.toString())
}
}
dbHelper.deleteLaunchers(invalidIds)
launchers = launchers.filter { !invalidIds.contains(it.id.toString()) } as ArrayList<AppLauncher>
}
override fun selectedLaunchers(launchers: ArrayList<AppLauncher>) {
for ((id, name, pkgName) in launchers) {
dbHelper.addLauncher(name, pkgName)