chore: convert to material alert dialogs
This commit is contained in:
parent
36999ebd87
commit
b81bc4b5a7
5 changed files with 24 additions and 22 deletions
|
@ -16,6 +16,7 @@ import androidx.annotation.DrawableRes
|
||||||
import androidx.annotation.StringRes
|
import androidx.annotation.StringRes
|
||||||
import androidx.annotation.StyleRes
|
import androidx.annotation.StyleRes
|
||||||
import androidx.appcompat.view.ContextThemeWrapper
|
import androidx.appcompat.view.ContextThemeWrapper
|
||||||
|
import com.google.android.material.dialog.MaterialAlertDialogBuilder
|
||||||
import info.nightscout.androidaps.R
|
import info.nightscout.androidaps.R
|
||||||
import info.nightscout.androidaps.extensions.runOnUiThread
|
import info.nightscout.androidaps.extensions.runOnUiThread
|
||||||
import info.nightscout.androidaps.plugins.general.maintenance.formats.Prefs
|
import info.nightscout.androidaps.plugins.general.maintenance.formats.Prefs
|
||||||
|
@ -49,7 +50,6 @@ object PrefImportSummaryDialog {
|
||||||
var idx = 0
|
var idx = 0
|
||||||
val details = LinkedList<String>()
|
val details = LinkedList<String>()
|
||||||
|
|
||||||
|
|
||||||
for ((metaKey, metaEntry) in prefs.metadata) {
|
for ((metaKey, metaEntry) in prefs.metadata) {
|
||||||
val rowLayout = LayoutInflater.from(themedCtx).inflate(R.layout.import_summary_item, null)
|
val rowLayout = LayoutInflater.from(themedCtx).inflate(R.layout.import_summary_item, null)
|
||||||
val label = (rowLayout.findViewById<View>(R.id.summary_text) as TextView)
|
val label = (rowLayout.findViewById<View>(R.id.summary_text) as TextView)
|
||||||
|
@ -92,7 +92,7 @@ object PrefImportSummaryDialog {
|
||||||
webView.setBackgroundColor(Color.TRANSPARENT)
|
webView.setBackgroundColor(Color.TRANSPARENT)
|
||||||
webView.setLayerType(WebView.LAYER_TYPE_SOFTWARE, null)
|
webView.setLayerType(WebView.LAYER_TYPE_SOFTWARE, null)
|
||||||
|
|
||||||
AlertDialogHelper.Builder(context, R.style.DialogTheme)
|
MaterialAlertDialogBuilder(context, R.style.DialogTheme)
|
||||||
.setCustomTitle(
|
.setCustomTitle(
|
||||||
AlertDialogHelper.buildCustomTitle(
|
AlertDialogHelper.buildCustomTitle(
|
||||||
context,
|
context,
|
||||||
|
@ -109,11 +109,10 @@ object PrefImportSummaryDialog {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
val builder = AlertDialogHelper.Builder(context, theme)
|
val builder = MaterialAlertDialogBuilder(context, theme)
|
||||||
.setMessage(context.getString(messageRes))
|
.setMessage(context.getString(messageRes))
|
||||||
.setCustomTitle(AlertDialogHelper.buildCustomTitle(context, context.getString(R.string.nav_import), headerIcon, theme))
|
.setCustomTitle(AlertDialogHelper.buildCustomTitle(context, context.getString(R.string.nav_import), headerIcon, theme))
|
||||||
.setView(innerLayout)
|
.setView(innerLayout)
|
||||||
|
|
||||||
.setNegativeButton(android.R.string.cancel) { dialog: DialogInterface, _: Int ->
|
.setNegativeButton(android.R.string.cancel) { dialog: DialogInterface, _: Int ->
|
||||||
dialog.dismiss()
|
dialog.dismiss()
|
||||||
SystemClock.sleep(100)
|
SystemClock.sleep(100)
|
||||||
|
|
|
@ -8,6 +8,7 @@ import android.view.LayoutInflater
|
||||||
import android.view.View
|
import android.view.View
|
||||||
import android.widget.TextView
|
import android.widget.TextView
|
||||||
import androidx.annotation.DrawableRes
|
import androidx.annotation.DrawableRes
|
||||||
|
import com.google.android.material.dialog.MaterialAlertDialogBuilder
|
||||||
import info.nightscout.androidaps.R
|
import info.nightscout.androidaps.R
|
||||||
import info.nightscout.androidaps.extensions.runOnUiThread
|
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)
|
val secondMessageLayout = LayoutInflater.from(context).inflate(R.layout.dialog_alert_two_messages, null)
|
||||||
(secondMessageLayout.findViewById<View>(R.id.password_prompt_title) as TextView).text = secondMessage
|
(secondMessageLayout.findViewById<View>(R.id.password_prompt_title) as TextView).text = secondMessage
|
||||||
|
|
||||||
AlertDialogHelper.Builder(context, R.style.DialogTheme)
|
MaterialAlertDialogBuilder(context, R.style.DialogTheme)
|
||||||
.setMessage(message)
|
.setMessage(message)
|
||||||
.setCustomTitle(
|
.setCustomTitle(
|
||||||
AlertDialogHelper.buildCustomTitle(
|
AlertDialogHelper.buildCustomTitle(
|
||||||
|
@ -32,7 +33,6 @@ object TwoMessagesAlertDialog {
|
||||||
dialog.dismiss()
|
dialog.dismiss()
|
||||||
SystemClock.sleep(100)
|
SystemClock.sleep(100)
|
||||||
if (ok != null) runOnUiThread { ok() }
|
if (ok != null) runOnUiThread { ok() }
|
||||||
|
|
||||||
}
|
}
|
||||||
.setNegativeButton(android.R.string.cancel) { dialog: DialogInterface, _: Int ->
|
.setNegativeButton(android.R.string.cancel) { dialog: DialogInterface, _: Int ->
|
||||||
dialog.dismiss()
|
dialog.dismiss()
|
||||||
|
|
|
@ -6,6 +6,7 @@ import android.content.DialogInterface
|
||||||
import android.os.SystemClock
|
import android.os.SystemClock
|
||||||
import android.text.Spanned
|
import android.text.Spanned
|
||||||
import androidx.fragment.app.FragmentActivity
|
import androidx.fragment.app.FragmentActivity
|
||||||
|
import com.google.android.material.dialog.MaterialAlertDialogBuilder
|
||||||
import info.nightscout.androidaps.core.R
|
import info.nightscout.androidaps.core.R
|
||||||
import info.nightscout.androidaps.extensions.runOnUiThread
|
import info.nightscout.androidaps.extensions.runOnUiThread
|
||||||
|
|
||||||
|
@ -17,7 +18,7 @@ object OKDialog {
|
||||||
var notEmptyTitle = title
|
var notEmptyTitle = title
|
||||||
if (notEmptyTitle.isEmpty()) notEmptyTitle = context.getString(R.string.message)
|
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))
|
.setCustomTitle(AlertDialogHelper.buildCustomTitle(context, notEmptyTitle))
|
||||||
.setMessage(message)
|
.setMessage(message)
|
||||||
.setPositiveButton(context.getString(R.string.ok)) { dialog: DialogInterface, _: Int ->
|
.setPositiveButton(context.getString(R.string.ok)) { dialog: DialogInterface, _: Int ->
|
||||||
|
@ -39,7 +40,7 @@ object OKDialog {
|
||||||
var notEmptyTitle = title
|
var notEmptyTitle = title
|
||||||
if (notEmptyTitle.isEmpty()) notEmptyTitle = activity.getString(R.string.message)
|
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))
|
.setCustomTitle(AlertDialogHelper.buildCustomTitle(activity, notEmptyTitle))
|
||||||
.setMessage(message)
|
.setMessage(message)
|
||||||
.setPositiveButton(activity.getString(R.string.ok)) { dialog: DialogInterface, _: Int ->
|
.setPositiveButton(activity.getString(R.string.ok)) { dialog: DialogInterface, _: Int ->
|
||||||
|
@ -66,7 +67,7 @@ object OKDialog {
|
||||||
@SuppressLint("InflateParams")
|
@SuppressLint("InflateParams")
|
||||||
fun showConfirmation(activity: FragmentActivity, title: String, message: Spanned, ok: Runnable?, cancel: Runnable? = null) {
|
fun showConfirmation(activity: FragmentActivity, title: String, message: Spanned, ok: Runnable?, cancel: Runnable? = null) {
|
||||||
var okClicked = false
|
var okClicked = false
|
||||||
AlertDialogHelper.Builder(activity, R.style.DialogTheme)
|
MaterialAlertDialogBuilder(activity, R.style.DialogTheme)
|
||||||
.setMessage(message)
|
.setMessage(message)
|
||||||
.setCustomTitle(AlertDialogHelper.buildCustomTitle(activity, title))
|
.setCustomTitle(AlertDialogHelper.buildCustomTitle(activity, title))
|
||||||
.setPositiveButton(android.R.string.ok) { dialog: DialogInterface, _: Int ->
|
.setPositiveButton(android.R.string.ok) { dialog: DialogInterface, _: Int ->
|
||||||
|
@ -94,7 +95,7 @@ object OKDialog {
|
||||||
@SuppressLint("InflateParams")
|
@SuppressLint("InflateParams")
|
||||||
fun showConfirmation(activity: FragmentActivity, title: String, message: String, ok: Runnable?, cancel: Runnable? = null) {
|
fun showConfirmation(activity: FragmentActivity, title: String, message: String, ok: Runnable?, cancel: Runnable? = null) {
|
||||||
var okClicked = false
|
var okClicked = false
|
||||||
AlertDialogHelper.Builder(activity, R.style.DialogTheme)
|
MaterialAlertDialogBuilder(activity, R.style.DialogTheme)
|
||||||
.setMessage(message)
|
.setMessage(message)
|
||||||
.setCustomTitle(AlertDialogHelper.buildCustomTitle(activity, title))
|
.setCustomTitle(AlertDialogHelper.buildCustomTitle(activity, title))
|
||||||
.setPositiveButton(android.R.string.ok) { dialog: DialogInterface, _: Int ->
|
.setPositiveButton(android.R.string.ok) { dialog: DialogInterface, _: Int ->
|
||||||
|
@ -126,7 +127,7 @@ object OKDialog {
|
||||||
@SuppressLint("InflateParams")
|
@SuppressLint("InflateParams")
|
||||||
fun showConfirmation(context: Context, title: String, message: Spanned, ok: Runnable?, cancel: Runnable? = null) {
|
fun showConfirmation(context: Context, title: String, message: Spanned, ok: Runnable?, cancel: Runnable? = null) {
|
||||||
var okClicked = false
|
var okClicked = false
|
||||||
AlertDialogHelper.Builder(context, R.style.DialogTheme)
|
MaterialAlertDialogBuilder(context, R.style.DialogTheme)
|
||||||
.setMessage(message)
|
.setMessage(message)
|
||||||
.setCustomTitle(AlertDialogHelper.buildCustomTitle(context, title))
|
.setCustomTitle(AlertDialogHelper.buildCustomTitle(context, title))
|
||||||
.setPositiveButton(android.R.string.ok) { dialog: DialogInterface, _: Int ->
|
.setPositiveButton(android.R.string.ok) { dialog: DialogInterface, _: Int ->
|
||||||
|
@ -158,7 +159,7 @@ object OKDialog {
|
||||||
@SuppressLint("InflateParams")
|
@SuppressLint("InflateParams")
|
||||||
fun showConfirmation(context: Context, title: String, message: String, ok: Runnable?, cancel: Runnable? = null) {
|
fun showConfirmation(context: Context, title: String, message: String, ok: Runnable?, cancel: Runnable? = null) {
|
||||||
var okClicked = false
|
var okClicked = false
|
||||||
AlertDialogHelper.Builder(context, R.style.DialogTheme)
|
MaterialAlertDialogBuilder(context, R.style.DialogTheme)
|
||||||
.setMessage(message)
|
.setMessage(message)
|
||||||
.setCustomTitle(AlertDialogHelper.buildCustomTitle(context, title))
|
.setCustomTitle(AlertDialogHelper.buildCustomTitle(context, title))
|
||||||
.setPositiveButton(android.R.string.ok) { dialog: DialogInterface, _: Int ->
|
.setPositiveButton(android.R.string.ok) { dialog: DialogInterface, _: Int ->
|
||||||
|
@ -186,7 +187,7 @@ object OKDialog {
|
||||||
@SuppressLint("InflateParams")
|
@SuppressLint("InflateParams")
|
||||||
fun showConfirmation(context: Context, title: String, message: String, ok: DialogInterface.OnClickListener?, cancel: DialogInterface.OnClickListener? = null) {
|
fun showConfirmation(context: Context, title: String, message: String, ok: DialogInterface.OnClickListener?, cancel: DialogInterface.OnClickListener? = null) {
|
||||||
var okClicked = false
|
var okClicked = false
|
||||||
AlertDialogHelper.Builder(context, R.style.DialogTheme)
|
MaterialAlertDialogBuilder(context, R.style.DialogTheme)
|
||||||
.setMessage(message)
|
.setMessage(message)
|
||||||
.setCustomTitle(AlertDialogHelper.buildCustomTitle(context, title))
|
.setCustomTitle(AlertDialogHelper.buildCustomTitle(context, title))
|
||||||
.setPositiveButton(android.R.string.ok) { dialog: DialogInterface, which: Int ->
|
.setPositiveButton(android.R.string.ok) { dialog: DialogInterface, which: Int ->
|
||||||
|
@ -214,7 +215,7 @@ object OKDialog {
|
||||||
@SuppressLint("InflateParams")
|
@SuppressLint("InflateParams")
|
||||||
fun showYesNoCancel(context: Context, title: String, message: String, yes: Runnable?, no: Runnable? = null) {
|
fun showYesNoCancel(context: Context, title: String, message: String, yes: Runnable?, no: Runnable? = null) {
|
||||||
var okClicked = false
|
var okClicked = false
|
||||||
AlertDialogHelper.Builder(context, R.style.DialogTheme)
|
MaterialAlertDialogBuilder(context, R.style.DialogTheme)
|
||||||
.setMessage(message)
|
.setMessage(message)
|
||||||
.setCustomTitle(AlertDialogHelper.buildCustomTitle(context, title))
|
.setCustomTitle(AlertDialogHelper.buildCustomTitle(context, title))
|
||||||
.setPositiveButton(R.string.yes) { dialog: DialogInterface, _: Int ->
|
.setPositiveButton(R.string.yes) { dialog: DialogInterface, _: Int ->
|
||||||
|
|
|
@ -5,6 +5,7 @@ import android.content.Context
|
||||||
import android.content.DialogInterface
|
import android.content.DialogInterface
|
||||||
import android.os.SystemClock
|
import android.os.SystemClock
|
||||||
import androidx.annotation.StringRes
|
import androidx.annotation.StringRes
|
||||||
|
import com.google.android.material.dialog.MaterialAlertDialogBuilder
|
||||||
import info.nightscout.androidaps.core.R
|
import info.nightscout.androidaps.core.R
|
||||||
import info.nightscout.androidaps.extensions.runOnUiThread
|
import info.nightscout.androidaps.extensions.runOnUiThread
|
||||||
|
|
||||||
|
@ -15,7 +16,7 @@ object WarningDialog {
|
||||||
@SuppressLint("InflateParams")
|
@SuppressLint("InflateParams")
|
||||||
fun showWarning(context: Context, title: String, message: String, @StringRes positiveButton: Int = -1, ok: (() -> Unit)? = null, cancel: (() -> Unit)? = null) {
|
fun showWarning(context: Context, title: String, message: String, @StringRes positiveButton: Int = -1, ok: (() -> Unit)? = null, cancel: (() -> Unit)? = null) {
|
||||||
var okClicked = false
|
var okClicked = false
|
||||||
val builder = AlertDialogHelper.Builder(context, R.style.AppThemeWarningDialog)
|
val builder = MaterialAlertDialogBuilder(context, R.style.AppThemeWarningDialog)
|
||||||
.setMessage(message)
|
.setMessage(message)
|
||||||
.setCustomTitle(AlertDialogHelper.buildCustomTitle(context, title, R.drawable.ic_header_warning, R.style.AppThemeWarningDialog))
|
.setCustomTitle(AlertDialogHelper.buildCustomTitle(context, title, R.drawable.ic_header_warning, R.style.AppThemeWarningDialog))
|
||||||
.setNegativeButton(R.string.dismiss) { dialog: DialogInterface, _: Int ->
|
.setNegativeButton(R.string.dismiss) { dialog: DialogInterface, _: Int ->
|
||||||
|
|
|
@ -11,6 +11,7 @@ import android.view.inputmethod.InputMethodManager
|
||||||
import android.widget.EditText
|
import android.widget.EditText
|
||||||
import android.widget.TextView
|
import android.widget.TextView
|
||||||
import androidx.annotation.StringRes
|
import androidx.annotation.StringRes
|
||||||
|
import com.google.android.material.dialog.MaterialAlertDialogBuilder
|
||||||
import info.nightscout.androidaps.core.R
|
import info.nightscout.androidaps.core.R
|
||||||
import info.nightscout.androidaps.interfaces.ActivePlugin
|
import info.nightscout.androidaps.interfaces.ActivePlugin
|
||||||
import info.nightscout.androidaps.plugins.general.maintenance.PrefFileListProvider
|
import info.nightscout.androidaps.plugins.general.maintenance.PrefFileListProvider
|
||||||
|
@ -44,7 +45,7 @@ class PasswordCheck @Inject constructor(
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
val promptsView = LayoutInflater.from(context).inflate(R.layout.passwordprompt, 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)
|
alertDialogBuilder.setView(promptsView)
|
||||||
|
|
||||||
val userInput = promptsView.findViewById<View>(R.id.password_prompt_pass) as EditText
|
val userInput = promptsView.findViewById<View>(R.id.password_prompt_pass) as EditText
|
||||||
|
@ -101,7 +102,7 @@ class PasswordCheck @Inject constructor(
|
||||||
@SuppressLint("InflateParams")
|
@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) {
|
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 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)
|
alertDialogBuilder.setView(promptsView)
|
||||||
|
|
||||||
val userInput = promptsView.findViewById<View>(R.id.password_prompt_pass) as EditText
|
val userInput = promptsView.findViewById<View>(R.id.password_prompt_pass) as EditText
|
||||||
|
@ -165,7 +166,7 @@ class PasswordCheck @Inject constructor(
|
||||||
@StringRes passwordWarning: Int?, ok: ((String) -> Unit)?, cancel: (() -> Unit)? = null) {
|
@StringRes passwordWarning: Int?, ok: ((String) -> Unit)?, cancel: (() -> Unit)? = null) {
|
||||||
|
|
||||||
val promptsView = LayoutInflater.from(context).inflate(R.layout.passwordprompt, 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)
|
alertDialogBuilder.setView(promptsView)
|
||||||
passwordExplanation?.let { alertDialogBuilder.setMessage(it) }
|
passwordExplanation?.let { alertDialogBuilder.setMessage(it) }
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue