From b81bc4b5a7f11feabb52766c7ef9e2b9d3bd1d47 Mon Sep 17 00:00:00 2001 From: Andries Smit Date: Thu, 14 Apr 2022 13:49:08 +0200 Subject: [PATCH] chore: convert to material alert dialogs --- .../alertDialogs/PrefImportSummaryDialog.kt | 9 ++++----- .../alertDialogs/TwoMessagesAlertDialog.kt | 6 +++--- .../androidaps/utils/alertDialogs/OKDialog.kt | 19 ++++++++++--------- .../utils/alertDialogs/WarningDialog.kt | 5 +++-- .../utils/protection/PasswordCheck.kt | 7 ++++--- 5 files changed, 24 insertions(+), 22 deletions(-) diff --git a/app/src/main/java/info/nightscout/androidaps/utils/alertDialogs/PrefImportSummaryDialog.kt b/app/src/main/java/info/nightscout/androidaps/utils/alertDialogs/PrefImportSummaryDialog.kt index 46756397d5..60edb6b6ad 100644 --- a/app/src/main/java/info/nightscout/androidaps/utils/alertDialogs/PrefImportSummaryDialog.kt +++ b/app/src/main/java/info/nightscout/androidaps/utils/alertDialogs/PrefImportSummaryDialog.kt @@ -16,6 +16,7 @@ import androidx.annotation.DrawableRes import androidx.annotation.StringRes import androidx.annotation.StyleRes import androidx.appcompat.view.ContextThemeWrapper +import com.google.android.material.dialog.MaterialAlertDialogBuilder import info.nightscout.androidaps.R import info.nightscout.androidaps.extensions.runOnUiThread import info.nightscout.androidaps.plugins.general.maintenance.formats.Prefs @@ -49,7 +50,6 @@ object PrefImportSummaryDialog { var idx = 0 val details = LinkedList() - for ((metaKey, metaEntry) in prefs.metadata) { val rowLayout = LayoutInflater.from(themedCtx).inflate(R.layout.import_summary_item, null) val label = (rowLayout.findViewById(R.id.summary_text) as TextView) @@ -92,7 +92,7 @@ object PrefImportSummaryDialog { webView.setBackgroundColor(Color.TRANSPARENT) webView.setLayerType(WebView.LAYER_TYPE_SOFTWARE, null) - AlertDialogHelper.Builder(context, R.style.DialogTheme) + MaterialAlertDialogBuilder(context, R.style.DialogTheme) .setCustomTitle( AlertDialogHelper.buildCustomTitle( context, @@ -109,11 +109,10 @@ object PrefImportSummaryDialog { } } - val builder = AlertDialogHelper.Builder(context, theme) + val builder = MaterialAlertDialogBuilder(context, theme) .setMessage(context.getString(messageRes)) .setCustomTitle(AlertDialogHelper.buildCustomTitle(context, context.getString(R.string.nav_import), headerIcon, theme)) .setView(innerLayout) - .setNegativeButton(android.R.string.cancel) { dialog: DialogInterface, _: Int -> dialog.dismiss() SystemClock.sleep(100) @@ -137,4 +136,4 @@ object PrefImportSummaryDialog { dialog.setCanceledOnTouchOutside(false) } -} \ No newline at end of file +} diff --git a/app/src/main/java/info/nightscout/androidaps/utils/alertDialogs/TwoMessagesAlertDialog.kt b/app/src/main/java/info/nightscout/androidaps/utils/alertDialogs/TwoMessagesAlertDialog.kt index 0bfd1f72f9..d4f2787538 100644 --- a/app/src/main/java/info/nightscout/androidaps/utils/alertDialogs/TwoMessagesAlertDialog.kt +++ b/app/src/main/java/info/nightscout/androidaps/utils/alertDialogs/TwoMessagesAlertDialog.kt @@ -8,6 +8,7 @@ import android.view.LayoutInflater import android.view.View import android.widget.TextView import androidx.annotation.DrawableRes +import com.google.android.material.dialog.MaterialAlertDialogBuilder import info.nightscout.androidaps.R import info.nightscout.androidaps.extensions.runOnUiThread @@ -19,7 +20,7 @@ object TwoMessagesAlertDialog { val secondMessageLayout = LayoutInflater.from(context).inflate(R.layout.dialog_alert_two_messages, null) (secondMessageLayout.findViewById(R.id.password_prompt_title) as TextView).text = secondMessage - AlertDialogHelper.Builder(context, R.style.DialogTheme) + MaterialAlertDialogBuilder(context, R.style.DialogTheme) .setMessage(message) .setCustomTitle( AlertDialogHelper.buildCustomTitle( @@ -32,7 +33,6 @@ object TwoMessagesAlertDialog { dialog.dismiss() SystemClock.sleep(100) if (ok != null) runOnUiThread { ok() } - } .setNegativeButton(android.R.string.cancel) { dialog: DialogInterface, _: Int -> dialog.dismiss() @@ -43,4 +43,4 @@ object TwoMessagesAlertDialog { .setCanceledOnTouchOutside(false) } -} \ No newline at end of file +} diff --git a/core/src/main/java/info/nightscout/androidaps/utils/alertDialogs/OKDialog.kt b/core/src/main/java/info/nightscout/androidaps/utils/alertDialogs/OKDialog.kt index 0de43096e0..53b25b4a67 100644 --- a/core/src/main/java/info/nightscout/androidaps/utils/alertDialogs/OKDialog.kt +++ b/core/src/main/java/info/nightscout/androidaps/utils/alertDialogs/OKDialog.kt @@ -6,6 +6,7 @@ import android.content.DialogInterface import android.os.SystemClock import android.text.Spanned import androidx.fragment.app.FragmentActivity +import com.google.android.material.dialog.MaterialAlertDialogBuilder import info.nightscout.androidaps.core.R import info.nightscout.androidaps.extensions.runOnUiThread @@ -17,7 +18,7 @@ object OKDialog { var notEmptyTitle = title if (notEmptyTitle.isEmpty()) notEmptyTitle = context.getString(R.string.message) - AlertDialogHelper.Builder(context, R.style.DialogTheme) + MaterialAlertDialogBuilder(context, R.style.DialogTheme) .setCustomTitle(AlertDialogHelper.buildCustomTitle(context, notEmptyTitle)) .setMessage(message) .setPositiveButton(context.getString(R.string.ok)) { dialog: DialogInterface, _: Int -> @@ -39,7 +40,7 @@ object OKDialog { var notEmptyTitle = title if (notEmptyTitle.isEmpty()) notEmptyTitle = activity.getString(R.string.message) - AlertDialogHelper.Builder(activity, R.style.DialogTheme) + MaterialAlertDialogBuilder(activity, R.style.DialogTheme) .setCustomTitle(AlertDialogHelper.buildCustomTitle(activity, notEmptyTitle)) .setMessage(message) .setPositiveButton(activity.getString(R.string.ok)) { dialog: DialogInterface, _: Int -> @@ -66,7 +67,7 @@ object OKDialog { @SuppressLint("InflateParams") fun showConfirmation(activity: FragmentActivity, title: String, message: Spanned, ok: Runnable?, cancel: Runnable? = null) { var okClicked = false - AlertDialogHelper.Builder(activity, R.style.DialogTheme) + MaterialAlertDialogBuilder(activity, R.style.DialogTheme) .setMessage(message) .setCustomTitle(AlertDialogHelper.buildCustomTitle(activity, title)) .setPositiveButton(android.R.string.ok) { dialog: DialogInterface, _: Int -> @@ -94,7 +95,7 @@ object OKDialog { @SuppressLint("InflateParams") fun showConfirmation(activity: FragmentActivity, title: String, message: String, ok: Runnable?, cancel: Runnable? = null) { var okClicked = false - AlertDialogHelper.Builder(activity, R.style.DialogTheme) + MaterialAlertDialogBuilder(activity, R.style.DialogTheme) .setMessage(message) .setCustomTitle(AlertDialogHelper.buildCustomTitle(activity, title)) .setPositiveButton(android.R.string.ok) { dialog: DialogInterface, _: Int -> @@ -126,7 +127,7 @@ object OKDialog { @SuppressLint("InflateParams") fun showConfirmation(context: Context, title: String, message: Spanned, ok: Runnable?, cancel: Runnable? = null) { var okClicked = false - AlertDialogHelper.Builder(context, R.style.DialogTheme) + MaterialAlertDialogBuilder(context, R.style.DialogTheme) .setMessage(message) .setCustomTitle(AlertDialogHelper.buildCustomTitle(context, title)) .setPositiveButton(android.R.string.ok) { dialog: DialogInterface, _: Int -> @@ -158,7 +159,7 @@ object OKDialog { @SuppressLint("InflateParams") fun showConfirmation(context: Context, title: String, message: String, ok: Runnable?, cancel: Runnable? = null) { var okClicked = false - AlertDialogHelper.Builder(context, R.style.DialogTheme) + MaterialAlertDialogBuilder(context, R.style.DialogTheme) .setMessage(message) .setCustomTitle(AlertDialogHelper.buildCustomTitle(context, title)) .setPositiveButton(android.R.string.ok) { dialog: DialogInterface, _: Int -> @@ -186,7 +187,7 @@ object OKDialog { @SuppressLint("InflateParams") fun showConfirmation(context: Context, title: String, message: String, ok: DialogInterface.OnClickListener?, cancel: DialogInterface.OnClickListener? = null) { var okClicked = false - AlertDialogHelper.Builder(context, R.style.DialogTheme) + MaterialAlertDialogBuilder(context, R.style.DialogTheme) .setMessage(message) .setCustomTitle(AlertDialogHelper.buildCustomTitle(context, title)) .setPositiveButton(android.R.string.ok) { dialog: DialogInterface, which: Int -> @@ -214,7 +215,7 @@ object OKDialog { @SuppressLint("InflateParams") fun showYesNoCancel(context: Context, title: String, message: String, yes: Runnable?, no: Runnable? = null) { var okClicked = false - AlertDialogHelper.Builder(context, R.style.DialogTheme) + MaterialAlertDialogBuilder(context, R.style.DialogTheme) .setMessage(message) .setCustomTitle(AlertDialogHelper.buildCustomTitle(context, title)) .setPositiveButton(R.string.yes) { dialog: DialogInterface, _: Int -> @@ -242,4 +243,4 @@ object OKDialog { .setCanceledOnTouchOutside(false) } -} \ No newline at end of file +} diff --git a/core/src/main/java/info/nightscout/androidaps/utils/alertDialogs/WarningDialog.kt b/core/src/main/java/info/nightscout/androidaps/utils/alertDialogs/WarningDialog.kt index 38f3314667..1c72451ee3 100644 --- a/core/src/main/java/info/nightscout/androidaps/utils/alertDialogs/WarningDialog.kt +++ b/core/src/main/java/info/nightscout/androidaps/utils/alertDialogs/WarningDialog.kt @@ -5,6 +5,7 @@ import android.content.Context import android.content.DialogInterface import android.os.SystemClock import androidx.annotation.StringRes +import com.google.android.material.dialog.MaterialAlertDialogBuilder import info.nightscout.androidaps.core.R import info.nightscout.androidaps.extensions.runOnUiThread @@ -15,7 +16,7 @@ object WarningDialog { @SuppressLint("InflateParams") fun showWarning(context: Context, title: String, message: String, @StringRes positiveButton: Int = -1, ok: (() -> Unit)? = null, cancel: (() -> Unit)? = null) { var okClicked = false - val builder = AlertDialogHelper.Builder(context, R.style.AppThemeWarningDialog) + val builder = MaterialAlertDialogBuilder(context, R.style.AppThemeWarningDialog) .setMessage(message) .setCustomTitle(AlertDialogHelper.buildCustomTitle(context, title, R.drawable.ic_header_warning, R.style.AppThemeWarningDialog)) .setNegativeButton(R.string.dismiss) { dialog: DialogInterface, _: Int -> @@ -52,4 +53,4 @@ object WarningDialog { dialog.setCanceledOnTouchOutside(true) } -} \ No newline at end of file +} diff --git a/core/src/main/java/info/nightscout/androidaps/utils/protection/PasswordCheck.kt b/core/src/main/java/info/nightscout/androidaps/utils/protection/PasswordCheck.kt index a395cdc111..9d03d04cbc 100644 --- a/core/src/main/java/info/nightscout/androidaps/utils/protection/PasswordCheck.kt +++ b/core/src/main/java/info/nightscout/androidaps/utils/protection/PasswordCheck.kt @@ -11,6 +11,7 @@ import android.view.inputmethod.InputMethodManager import android.widget.EditText import android.widget.TextView import androidx.annotation.StringRes +import com.google.android.material.dialog.MaterialAlertDialogBuilder import info.nightscout.androidaps.core.R import info.nightscout.androidaps.interfaces.ActivePlugin import info.nightscout.androidaps.plugins.general.maintenance.PrefFileListProvider @@ -44,7 +45,7 @@ class PasswordCheck @Inject constructor( return } val promptsView = LayoutInflater.from(context).inflate(R.layout.passwordprompt, null) - val alertDialogBuilder = AlertDialogHelper.Builder(context, R.style.DialogTheme) + val alertDialogBuilder = MaterialAlertDialogBuilder(context, R.style.DialogTheme) alertDialogBuilder.setView(promptsView) val userInput = promptsView.findViewById(R.id.password_prompt_pass) as EditText @@ -101,7 +102,7 @@ class PasswordCheck @Inject constructor( @SuppressLint("InflateParams") fun setPassword(context: Context, @StringRes labelId: Int, @StringRes preference: Int, ok: ((String) -> Unit)? = null, cancel: (() -> Unit)? = null, clear: (() -> Unit)? = null, pinInput: Boolean = false) { val promptsView = LayoutInflater.from(context).inflate(R.layout.passwordprompt, null) - val alertDialogBuilder = AlertDialogHelper.Builder(context, R.style.DialogTheme) + val alertDialogBuilder = MaterialAlertDialogBuilder(context, R.style.DialogTheme) alertDialogBuilder.setView(promptsView) val userInput = promptsView.findViewById(R.id.password_prompt_pass) as EditText @@ -165,7 +166,7 @@ class PasswordCheck @Inject constructor( @StringRes passwordWarning: Int?, ok: ((String) -> Unit)?, cancel: (() -> Unit)? = null) { val promptsView = LayoutInflater.from(context).inflate(R.layout.passwordprompt, null) - val alertDialogBuilder = AlertDialogHelper.Builder(context, R.style.DialogTheme) + val alertDialogBuilder = MaterialAlertDialogBuilder(context, R.style.DialogTheme) alertDialogBuilder.setView(promptsView) passwordExplanation?.let { alertDialogBuilder.setMessage(it) }