show the dialog about removing launcher just once

This commit is contained in:
tibbi
2018-04-04 21:06:48 +02:00
parent dcc56deaa4
commit 4d1d8447b4
3 changed files with 17 additions and 1 deletions

View File

@ -6,6 +6,7 @@ import android.view.ViewGroup
import com.simplemobiletools.applauncher.R import com.simplemobiletools.applauncher.R
import com.simplemobiletools.applauncher.activities.SimpleActivity import com.simplemobiletools.applauncher.activities.SimpleActivity
import com.simplemobiletools.applauncher.dialogs.EditDialog import com.simplemobiletools.applauncher.dialogs.EditDialog
import com.simplemobiletools.applauncher.extensions.config
import com.simplemobiletools.applauncher.extensions.dbHelper import com.simplemobiletools.applauncher.extensions.dbHelper
import com.simplemobiletools.applauncher.models.AppLauncher import com.simplemobiletools.applauncher.models.AppLauncher
import com.simplemobiletools.commons.adapters.MyRecyclerViewAdapter import com.simplemobiletools.commons.adapters.MyRecyclerViewAdapter
@ -55,7 +56,7 @@ class LaunchersAdapter(activity: SimpleActivity, val launchers: MutableList<AppL
override fun actionItemPressed(id: Int) { override fun actionItemPressed(id: Int) {
when (id) { when (id) {
R.id.cab_edit -> showEditDialog() R.id.cab_edit -> showEditDialog()
R.id.cab_remove -> askConfirmRemove() R.id.cab_remove -> tryRemoveLauncher()
} }
} }
@ -68,8 +69,17 @@ class LaunchersAdapter(activity: SimpleActivity, val launchers: MutableList<AppL
} }
} }
private fun tryRemoveLauncher() {
if (activity.config.wasRemoveInfoShown) {
removeItems()
} else {
askConfirmRemove()
}
}
private fun askConfirmRemove() { private fun askConfirmRemove() {
ConfirmationDialog(activity, "", R.string.remove_explanation, R.string.ok, R.string.cancel) { ConfirmationDialog(activity, "", R.string.remove_explanation, R.string.ok, R.string.cancel) {
activity.config.wasRemoveInfoShown = true
removeItems() removeItems()
} }
} }

View File

@ -7,4 +7,8 @@ class Config(context: Context) : BaseConfig(context) {
companion object { companion object {
fun newInstance(context: Context) = Config(context) fun newInstance(context: Context) = Config(context)
} }
var wasRemoveInfoShown: Boolean
get() = prefs.getBoolean(WAS_REMOVE_INFO_SHOWN, false)
set(wasRemoveInfoShown) = prefs.edit().putBoolean(WAS_REMOVE_INFO_SHOWN, wasRemoveInfoShown).apply()
} }

View File

@ -1,5 +1,7 @@
package com.simplemobiletools.applauncher.helpers package com.simplemobiletools.applauncher.helpers
const val WAS_REMOVE_INFO_SHOWN = "was_remove_info_shown"
val predefinedPackageNames = arrayListOf( val predefinedPackageNames = arrayListOf(
"com.simplemobiletools.calculator", "com.simplemobiletools.calculator",
"com.simplemobiletools.calendar", "com.simplemobiletools.calendar",