From 2ac1cc1a2823e6b2b966613942e6437c69256807 Mon Sep 17 00:00:00 2001 From: tibbi Date: Tue, 5 Jul 2022 23:21:07 +0200 Subject: [PATCH] updating Commons with the new dialogs --- app/build.gradle | 2 +- .../applauncher/dialogs/AddLaunchersDialog.kt | 6 +-- .../dialogs/ChangeSortingDialog.kt | 6 +-- .../applauncher/dialogs/EditDialog.kt | 41 ++++++++----------- 4 files changed, 25 insertions(+), 30 deletions(-) diff --git a/app/build.gradle b/app/build.gradle index 8f5df7b..e035db6 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -63,7 +63,7 @@ android { } dependencies { - implementation 'com.github.SimpleMobileTools:Simple-Commons:4b8a3568df' + implementation 'com.github.SimpleMobileTools:Simple-Commons:c070dff787' implementation 'androidx.multidex:multidex:2.0.1' implementation 'androidx.swiperefreshlayout:swiperefreshlayout:1.1.0' } diff --git a/app/src/main/kotlin/com/simplemobiletools/applauncher/dialogs/AddLaunchersDialog.kt b/app/src/main/kotlin/com/simplemobiletools/applauncher/dialogs/AddLaunchersDialog.kt index 8dccafa..fa73d58 100644 --- a/app/src/main/kotlin/com/simplemobiletools/applauncher/dialogs/AddLaunchersDialog.kt +++ b/app/src/main/kotlin/com/simplemobiletools/applauncher/dialogs/AddLaunchersDialog.kt @@ -2,12 +2,12 @@ package com.simplemobiletools.applauncher.dialogs import android.app.Activity import android.view.ViewGroup -import androidx.appcompat.app.AlertDialog import com.simplemobiletools.applauncher.R import com.simplemobiletools.applauncher.adapters.AddLaunchersAdapter import com.simplemobiletools.applauncher.extensions.dbHelper import com.simplemobiletools.applauncher.models.AppLauncher import com.simplemobiletools.commons.extensions.areSystemAnimationsEnabled +import com.simplemobiletools.commons.extensions.getAlertDialogBuilder import com.simplemobiletools.commons.extensions.setupDialogStuff import kotlinx.android.synthetic.main.dialog_add_launchers.view.* @@ -21,10 +21,10 @@ class AddLaunchersDialog( private var adapter: AddLaunchersAdapter? = null init { - AlertDialog.Builder(activity) + activity.getAlertDialogBuilder() .setPositiveButton(R.string.ok) { dialogInterface, i -> confirmSelection() } .setNegativeButton(R.string.cancel, null) - .create().apply { + .apply { activity.setupDialogStuff(view, this) { adapter = AddLaunchersAdapter(activity, allLaunchers, shownLaunchers) view.add_launchers_holder.adapter = adapter diff --git a/app/src/main/kotlin/com/simplemobiletools/applauncher/dialogs/ChangeSortingDialog.kt b/app/src/main/kotlin/com/simplemobiletools/applauncher/dialogs/ChangeSortingDialog.kt index 2e0306d..8c90d86 100644 --- a/app/src/main/kotlin/com/simplemobiletools/applauncher/dialogs/ChangeSortingDialog.kt +++ b/app/src/main/kotlin/com/simplemobiletools/applauncher/dialogs/ChangeSortingDialog.kt @@ -1,10 +1,10 @@ package com.simplemobiletools.applauncher.dialogs -import androidx.appcompat.app.AlertDialog import com.simplemobiletools.applauncher.R import com.simplemobiletools.applauncher.extensions.config import com.simplemobiletools.commons.activities.BaseSimpleActivity import com.simplemobiletools.commons.extensions.beGoneIf +import com.simplemobiletools.commons.extensions.getAlertDialogBuilder import com.simplemobiletools.commons.extensions.setupDialogStuff import com.simplemobiletools.commons.helpers.SORT_BY_CUSTOM import com.simplemobiletools.commons.helpers.SORT_BY_TITLE @@ -17,10 +17,10 @@ class ChangeSortingDialog(val activity: BaseSimpleActivity, private val callback private var view = activity.layoutInflater.inflate(R.layout.dialog_change_sorting, null) init { - AlertDialog.Builder(activity) + activity.getAlertDialogBuilder() .setPositiveButton(R.string.ok) { dialog, which -> dialogConfirmed() } .setNegativeButton(R.string.cancel, null) - .create().apply { + .apply { activity.setupDialogStuff(view, this, R.string.sort_by) } diff --git a/app/src/main/kotlin/com/simplemobiletools/applauncher/dialogs/EditDialog.kt b/app/src/main/kotlin/com/simplemobiletools/applauncher/dialogs/EditDialog.kt index 3baf808..918e252 100644 --- a/app/src/main/kotlin/com/simplemobiletools/applauncher/dialogs/EditDialog.kt +++ b/app/src/main/kotlin/com/simplemobiletools/applauncher/dialogs/EditDialog.kt @@ -2,43 +2,38 @@ package com.simplemobiletools.applauncher.dialogs import android.app.Activity import android.view.ViewGroup -import androidx.appcompat.app.AlertDialog import com.simplemobiletools.applauncher.R import com.simplemobiletools.applauncher.extensions.dbHelper import com.simplemobiletools.applauncher.models.AppLauncher -import com.simplemobiletools.commons.extensions.setupDialogStuff -import com.simplemobiletools.commons.extensions.showKeyboard -import com.simplemobiletools.commons.extensions.toast -import com.simplemobiletools.commons.extensions.value +import com.simplemobiletools.commons.extensions.* import kotlinx.android.synthetic.main.dialog_edit_launcher.view.* class EditDialog(val activity: Activity, val appLauncher: AppLauncher, val callback: () -> Unit) { - var dialog: AlertDialog - var view = (activity.layoutInflater.inflate(R.layout.dialog_edit_launcher, null) as ViewGroup) + private var view = (activity.layoutInflater.inflate(R.layout.dialog_edit_launcher, null) as ViewGroup) init { view.edit_launcher_edittext.setText(appLauncher.title) - dialog = AlertDialog.Builder(activity) - .setPositiveButton(R.string.ok, null) - .setNegativeButton(R.string.cancel, null) - .create().apply { - activity.setupDialogStuff(view, this, R.string.rename) { - showKeyboard(view.edit_launcher_edittext) - getButton(android.app.AlertDialog.BUTTON_POSITIVE).setOnClickListener { - val newName = view.edit_launcher_edittext.value - if (!newName.isEmpty()) { - if (activity.dbHelper.updateLauncherName(appLauncher.id, newName)) { - callback() - dismiss() - } else { - activity.toast(R.string.unknown_error_occurred) - } + activity.getAlertDialogBuilder() + .setPositiveButton(R.string.ok, null) + .setNegativeButton(R.string.cancel, null) + .apply { + activity.setupDialogStuff(view, this, R.string.rename) { alertDialog -> + alertDialog.showKeyboard(view.edit_launcher_edittext) + alertDialog.getButton(android.app.AlertDialog.BUTTON_POSITIVE).setOnClickListener { + val newName = view.edit_launcher_edittext.value + if (!newName.isEmpty()) { + if (activity.dbHelper.updateLauncherName(appLauncher.id, newName)) { + callback() + alertDialog.dismiss() } else { - activity.toast(R.string.enter_launcher_name) + activity.toast(R.string.unknown_error_occurred) } + } else { + activity.toast(R.string.enter_launcher_name) } } } + } } }