From 511dd08ae778e07b08b2f2c77a52fd0a42f438d6 Mon Sep 17 00:00:00 2001 From: Milos Kozak Date: Thu, 15 Sep 2022 16:17:58 +0200 Subject: [PATCH] Use graphical Toast --- .../activities/ProfileHelperActivity.kt | 14 +++++++------- .../androidaps/activities/SurveyActivity.kt | 12 ++++++------ .../fragments/TreatmentsBolusCarbsFragment.kt | 4 ++-- .../fragments/TreatmentsCareportalFragment.kt | 4 ++-- .../TreatmentsExtendedBolusesFragment.kt | 4 ++-- .../fragments/TreatmentsProfileSwitchFragment.kt | 4 ++-- .../fragments/TreatmentsTempTargetFragment.kt | 4 ++-- .../TreatmentsTemporaryBasalsFragment.kt | 4 ++-- .../fragments/TreatmentsUserEntryFragment.kt | 4 ++-- .../nightscout/androidaps/dialogs/CarbsDialog.kt | 8 ++++---- .../androidaps/dialogs/ExtendedBolusDialog.kt | 2 +- .../nightscout/androidaps/dialogs/FillDialog.kt | 2 +- .../androidaps/dialogs/InsulinDialog.kt | 6 +++--- .../nightscout/androidaps/dialogs/LoopDialog.kt | 4 ++-- .../androidaps/dialogs/ProfileSwitchDialog.kt | 2 +- .../androidaps/dialogs/TempBasalDialog.kt | 2 +- .../androidaps/dialogs/TempTargetDialog.kt | 2 +- .../androidaps/dialogs/TreatmentDialog.kt | 6 +++--- .../androidaps/dialogs/WizardDialog.kt | 6 +++--- .../activities/ObjectivesExamDialog.kt | 2 +- .../plugins/general/overview/OverviewFragment.kt | 6 +++--- .../general/overview/graphData/GraphData.kt | 6 +++--- .../androidaps/utils/XDripBroadcast.kt | 4 ++-- .../automation/dialogs/EditEventDialog.kt | 6 +++--- .../nightscout/androidaps/utils/ToastUtils.kt | 13 +++++++++++++ .../utils/protection/BiometricCheck.kt | 4 ++-- .../androidaps/utils/protection/PasswordCheck.kt | 2 +- .../androidaps/utils/ui/NumberPicker.kt | 16 ++++++++-------- .../services/AbstractDanaRExecutionService.java | 6 +++--- .../nightscout/androidaps/danars/DanaRSPlugin.kt | 2 +- .../androidaps/danars/services/BLEComm.kt | 4 ++-- .../androidaps/diaconn/DiaconnG8Plugin.kt | 2 +- 32 files changed, 90 insertions(+), 77 deletions(-) diff --git a/app/src/main/java/info/nightscout/androidaps/activities/ProfileHelperActivity.kt b/app/src/main/java/info/nightscout/androidaps/activities/ProfileHelperActivity.kt index dcba11d059..e3c21e15ad 100644 --- a/app/src/main/java/info/nightscout/androidaps/activities/ProfileHelperActivity.kt +++ b/app/src/main/java/info/nightscout/androidaps/activities/ProfileHelperActivity.kt @@ -175,29 +175,29 @@ class ProfileHelperActivity : NoSplashAppCompatActivity() { for (i in 0..1) { if (typeSelected[i] == ProfileType.MOTOL_DEFAULT) { if (ageUsed[i] < 1 || ageUsed[i] > 18) { - ToastUtils.showToastInUiThread(this, R.string.invalidage) + ToastUtils.warnToast(this, R.string.invalidage) return@setOnClickListener } if ((weightUsed[i] < 5 || weightUsed[i] > 150) && tddUsed[i] == 0.0) { - ToastUtils.showToastInUiThread(this, R.string.invalidweight) + ToastUtils.warnToast(this, R.string.invalidweight) return@setOnClickListener } if ((tddUsed[i] < 5 || tddUsed[i] > 150) && weightUsed[i] == 0.0) { - ToastUtils.showToastInUiThread(this, R.string.invalidweight) + ToastUtils.warnToast(this, R.string.invalidweight) return@setOnClickListener } } if (typeSelected[i] == ProfileType.DPV_DEFAULT) { if (ageUsed[i] < 1 || ageUsed[i] > 18) { - ToastUtils.showToastInUiThread(this, R.string.invalidage) + ToastUtils.warnToast(this, R.string.invalidage) return@setOnClickListener } if (tddUsed[i] < 5 || tddUsed[i] > 150) { - ToastUtils.showToastInUiThread(this, R.string.invalidweight) + ToastUtils.warnToast(this, R.string.invalidweight) return@setOnClickListener } if ((pctUsed[i] < 32 || pctUsed[i] > 37)) { - ToastUtils.showToastInUiThread(this, R.string.invalidpct) + ToastUtils.warnToast(this, R.string.invalidpct) return@setOnClickListener } } @@ -226,7 +226,7 @@ class ProfileHelperActivity : NoSplashAppCompatActivity() { return@setOnClickListener } } - ToastUtils.showToastInUiThread(this, R.string.invalidinput) + ToastUtils.warnToast(this, R.string.invalidinput) } binding.ageLabel.labelFor = binding.age.editTextId binding.tddLabel.labelFor = binding.tdd.editTextId diff --git a/app/src/main/java/info/nightscout/androidaps/activities/SurveyActivity.kt b/app/src/main/java/info/nightscout/androidaps/activities/SurveyActivity.kt index c5f2d52cbf..1d108a7d17 100644 --- a/app/src/main/java/info/nightscout/androidaps/activities/SurveyActivity.kt +++ b/app/src/main/java/info/nightscout/androidaps/activities/SurveyActivity.kt @@ -52,15 +52,15 @@ class SurveyActivity : NoSplashAppCompatActivity() { val weight = SafeParse.stringToDouble(binding.weight.text.toString()) val tdd = SafeParse.stringToDouble(binding.tdd.text.toString()) if (age < 1 || age > 120) { - ToastUtils.showToastInUiThread(this, R.string.invalidage) + ToastUtils.warnToast(this, R.string.invalidage) return@setOnClickListener } if ((weight < 5 || weight > 150) && tdd == 0.0) { - ToastUtils.showToastInUiThread(this, R.string.invalidweight) + ToastUtils.warnToast(this, R.string.invalidweight) return@setOnClickListener } if ((tdd < 5 || tdd > 150) && weight == 0.0) { - ToastUtils.showToastInUiThread(this, R.string.invalidweight) + ToastUtils.warnToast(this, R.string.invalidweight) return@setOnClickListener } profileFunction.getProfile()?.let { runningProfile -> @@ -84,11 +84,11 @@ class SurveyActivity : NoSplashAppCompatActivity() { r.age = SafeParse.stringToInt(binding.age.text.toString()) r.weight = SafeParse.stringToInt(binding.weight.text.toString()) if (r.age < 1 || r.age > 120) { - ToastUtils.showToastInUiThread(this, R.string.invalidage) + ToastUtils.warnToast(this, R.string.invalidage) return@setOnClickListener } if (r.weight < 5 || r.weight > 150) { - ToastUtils.showToastInUiThread(this, R.string.invalidweight) + ToastUtils.warnToast(this, R.string.invalidweight) return@setOnClickListener } @@ -110,7 +110,7 @@ class SurveyActivity : NoSplashAppCompatActivity() { database.child("survey").child(r.id).setValue(r) } else { aapsLogger.error("signInAnonymously:failure", task.exception!!) - ToastUtils.showToastInUiThread(this, "Authentication failed.") + ToastUtils.warnToast(this, "Authentication failed.") //updateUI(null) } diff --git a/app/src/main/java/info/nightscout/androidaps/activities/fragments/TreatmentsBolusCarbsFragment.kt b/app/src/main/java/info/nightscout/androidaps/activities/fragments/TreatmentsBolusCarbsFragment.kt index be18c83e80..74cd4cabec 100644 --- a/app/src/main/java/info/nightscout/androidaps/activities/fragments/TreatmentsBolusCarbsFragment.kt +++ b/app/src/main/java/info/nightscout/androidaps/activities/fragments/TreatmentsBolusCarbsFragment.kt @@ -315,7 +315,7 @@ class TreatmentsBolusCarbsFragment : DaggerFragment(), MenuProvider { R.id.nav_show_invalidated -> { showInvalidated = true updateMenuVisibility() - ToastUtils.showToastInUiThread(context, rh.gs(R.string.show_invalidated_records)) + ToastUtils.infoToast(context, R.string.show_invalidated_records) swapAdapter() true } @@ -323,7 +323,7 @@ class TreatmentsBolusCarbsFragment : DaggerFragment(), MenuProvider { R.id.nav_hide_invalidated -> { showInvalidated = false updateMenuVisibility() - ToastUtils.showToastInUiThread(context, rh.gs(R.string.hide_invalidated_records)) + ToastUtils.infoToast(context, R.string.hide_invalidated_records) swapAdapter() true } diff --git a/app/src/main/java/info/nightscout/androidaps/activities/fragments/TreatmentsCareportalFragment.kt b/app/src/main/java/info/nightscout/androidaps/activities/fragments/TreatmentsCareportalFragment.kt index bedac02f8d..7803ee4359 100644 --- a/app/src/main/java/info/nightscout/androidaps/activities/fragments/TreatmentsCareportalFragment.kt +++ b/app/src/main/java/info/nightscout/androidaps/activities/fragments/TreatmentsCareportalFragment.kt @@ -206,7 +206,7 @@ class TreatmentsCareportalFragment : DaggerFragment(), MenuProvider { R.id.nav_show_invalidated -> { showInvalidated = true updateMenuVisibility() - ToastUtils.showToastInUiThread(context, rh.gs(R.string.show_invalidated_records)) + ToastUtils.infoToast(context, R.string.show_invalidated_records) swapAdapter() true } @@ -214,7 +214,7 @@ class TreatmentsCareportalFragment : DaggerFragment(), MenuProvider { R.id.nav_hide_invalidated -> { showInvalidated = false updateMenuVisibility() - ToastUtils.showToastInUiThread(context, rh.gs(R.string.hide_invalidated_records)) + ToastUtils.infoToast(context, R.string.hide_invalidated_records) swapAdapter() true } diff --git a/app/src/main/java/info/nightscout/androidaps/activities/fragments/TreatmentsExtendedBolusesFragment.kt b/app/src/main/java/info/nightscout/androidaps/activities/fragments/TreatmentsExtendedBolusesFragment.kt index 46c8bdc5f4..6bc126b1a4 100644 --- a/app/src/main/java/info/nightscout/androidaps/activities/fragments/TreatmentsExtendedBolusesFragment.kt +++ b/app/src/main/java/info/nightscout/androidaps/activities/fragments/TreatmentsExtendedBolusesFragment.kt @@ -194,7 +194,7 @@ class TreatmentsExtendedBolusesFragment : DaggerFragment(), MenuProvider { R.id.nav_show_invalidated -> { showInvalidated = true updateMenuVisibility() - ToastUtils.showToastInUiThread(context, rh.gs(R.string.show_invalidated_records)) + ToastUtils.infoToast(context, R.string.show_invalidated_records) swapAdapter() true } @@ -202,7 +202,7 @@ class TreatmentsExtendedBolusesFragment : DaggerFragment(), MenuProvider { R.id.nav_hide_invalidated -> { showInvalidated = false updateMenuVisibility() - ToastUtils.showToastInUiThread(context, rh.gs(R.string.hide_invalidated_records)) + ToastUtils.infoToast(context, R.string.hide_invalidated_records) swapAdapter() true } diff --git a/app/src/main/java/info/nightscout/androidaps/activities/fragments/TreatmentsProfileSwitchFragment.kt b/app/src/main/java/info/nightscout/androidaps/activities/fragments/TreatmentsProfileSwitchFragment.kt index eb4ea10937..b845bbc1de 100644 --- a/app/src/main/java/info/nightscout/androidaps/activities/fragments/TreatmentsProfileSwitchFragment.kt +++ b/app/src/main/java/info/nightscout/androidaps/activities/fragments/TreatmentsProfileSwitchFragment.kt @@ -294,7 +294,7 @@ class TreatmentsProfileSwitchFragment : DaggerFragment(), MenuProvider { R.id.nav_show_invalidated -> { showInvalidated = true updateMenuVisibility() - ToastUtils.showToastInUiThread(context, rh.gs(R.string.show_invalidated_records)) + ToastUtils.infoToast(context, R.string.show_invalidated_records) swapAdapter() true } @@ -302,7 +302,7 @@ class TreatmentsProfileSwitchFragment : DaggerFragment(), MenuProvider { R.id.nav_hide_invalidated -> { showInvalidated = false updateMenuVisibility() - ToastUtils.showToastInUiThread(context, rh.gs(R.string.hide_invalidated_records)) + ToastUtils.infoToast(context, R.string.hide_invalidated_records) swapAdapter() true } diff --git a/app/src/main/java/info/nightscout/androidaps/activities/fragments/TreatmentsTempTargetFragment.kt b/app/src/main/java/info/nightscout/androidaps/activities/fragments/TreatmentsTempTargetFragment.kt index ffe324b869..840dd7b1b4 100644 --- a/app/src/main/java/info/nightscout/androidaps/activities/fragments/TreatmentsTempTargetFragment.kt +++ b/app/src/main/java/info/nightscout/androidaps/activities/fragments/TreatmentsTempTargetFragment.kt @@ -225,7 +225,7 @@ class TreatmentsTempTargetFragment : DaggerFragment(), MenuProvider { R.id.nav_show_invalidated -> { showInvalidated = true updateMenuVisibility() - ToastUtils.showToastInUiThread(context, rh.gs(R.string.show_invalidated_records)) + ToastUtils.infoToast(context, R.string.show_invalidated_records) swapAdapter() true } @@ -233,7 +233,7 @@ class TreatmentsTempTargetFragment : DaggerFragment(), MenuProvider { R.id.nav_hide_invalidated -> { showInvalidated = false updateMenuVisibility() - ToastUtils.showToastInUiThread(context, rh.gs(R.string.show_invalidated_records)) + ToastUtils.infoToast(context, R.string.show_invalidated_records) swapAdapter() true } diff --git a/app/src/main/java/info/nightscout/androidaps/activities/fragments/TreatmentsTemporaryBasalsFragment.kt b/app/src/main/java/info/nightscout/androidaps/activities/fragments/TreatmentsTemporaryBasalsFragment.kt index 7da21e6cad..3bb55c7963 100644 --- a/app/src/main/java/info/nightscout/androidaps/activities/fragments/TreatmentsTemporaryBasalsFragment.kt +++ b/app/src/main/java/info/nightscout/androidaps/activities/fragments/TreatmentsTemporaryBasalsFragment.kt @@ -236,7 +236,7 @@ class TreatmentsTemporaryBasalsFragment : DaggerFragment(), MenuProvider { R.id.nav_show_invalidated -> { showInvalidated = true updateMenuVisibility() - ToastUtils.showToastInUiThread(context, rh.gs(R.string.show_invalidated_records)) + ToastUtils.infoToast(context, R.string.show_invalidated_records) swapAdapter() true } @@ -244,7 +244,7 @@ class TreatmentsTemporaryBasalsFragment : DaggerFragment(), MenuProvider { R.id.nav_hide_invalidated -> { showInvalidated = false updateMenuVisibility() - ToastUtils.showToastInUiThread(context, rh.gs(R.string.hide_invalidated_records)) + ToastUtils.infoToast(context, R.string.hide_invalidated_records) swapAdapter() true } diff --git a/app/src/main/java/info/nightscout/androidaps/activities/fragments/TreatmentsUserEntryFragment.kt b/app/src/main/java/info/nightscout/androidaps/activities/fragments/TreatmentsUserEntryFragment.kt index bd7bcdc406..3219eeb5bb 100644 --- a/app/src/main/java/info/nightscout/androidaps/activities/fragments/TreatmentsUserEntryFragment.kt +++ b/app/src/main/java/info/nightscout/androidaps/activities/fragments/TreatmentsUserEntryFragment.kt @@ -162,7 +162,7 @@ class TreatmentsUserEntryFragment : DaggerFragment(), MenuProvider { R.id.nav_show_loop -> { showLoop = true updateMenuVisibility() - ToastUtils.showToastInUiThread(context, rh.gs(R.string.show_loop_records)) + ToastUtils.infoToast(context, R.string.show_loop_records) swapAdapter() true } @@ -170,7 +170,7 @@ class TreatmentsUserEntryFragment : DaggerFragment(), MenuProvider { R.id.nav_hide_loop -> { showLoop = false updateMenuVisibility() - ToastUtils.showToastInUiThread(context, rh.gs(R.string.show_hide_records)) + ToastUtils.infoToast(context, R.string.show_hide_records) swapAdapter() true } diff --git a/app/src/main/java/info/nightscout/androidaps/dialogs/CarbsDialog.kt b/app/src/main/java/info/nightscout/androidaps/dialogs/CarbsDialog.kt index ff3d0c778a..db221159ce 100644 --- a/app/src/main/java/info/nightscout/androidaps/dialogs/CarbsDialog.kt +++ b/app/src/main/java/info/nightscout/androidaps/dialogs/CarbsDialog.kt @@ -78,15 +78,15 @@ class CarbsDialog : DialogFragmentWithDate() { val time = binding.time.value.toInt() if (time > 12 * 60 || time < -7 * 24 * 60) { binding.time.value = 0.0 - ToastUtils.showToastInUiThread(ctx, rh.gs(R.string.constraintapllied)) + ToastUtils.warnToast(ctx, R.string.constraintapllied) } if (binding.duration.value > 10) { binding.duration.value = 0.0 - ToastUtils.showToastInUiThread(ctx, rh.gs(R.string.constraintapllied)) + ToastUtils.warnToast(ctx, R.string.constraintapllied) } if (binding.carbs.value.toInt() > maxCarbs) { binding.carbs.value = 0.0 - ToastUtils.showToastInUiThread(ctx, rh.gs(R.string.carbsconstraintapplied)) + ToastUtils.warnToast(ctx, R.string.carbsconstraintapplied) } } @@ -392,7 +392,7 @@ class CarbsDialog : DialogFragmentWithDate() { val cancelFail = { queryingProtection = false aapsLogger.debug(LTag.APS, "Dialog canceled on resume protection: ${this.javaClass.name}") - ToastUtils.showToastInUiThread(ctx, R.string.dialog_canceled) + ToastUtils.warnToast(ctx, R.string.dialog_canceled) dismiss() } protectionCheck.queryProtection(activity, BOLUS, { queryingProtection = false }, cancelFail, cancelFail) diff --git a/app/src/main/java/info/nightscout/androidaps/dialogs/ExtendedBolusDialog.kt b/app/src/main/java/info/nightscout/androidaps/dialogs/ExtendedBolusDialog.kt index 0f6fd525a1..d068a8b1d1 100644 --- a/app/src/main/java/info/nightscout/androidaps/dialogs/ExtendedBolusDialog.kt +++ b/app/src/main/java/info/nightscout/androidaps/dialogs/ExtendedBolusDialog.kt @@ -120,7 +120,7 @@ class ExtendedBolusDialog : DialogFragmentWithDate() { val cancelFail = { queryingProtection = false aapsLogger.debug(LTag.APS, "Dialog canceled on resume protection: ${this.javaClass.name}") - ToastUtils.showToastInUiThread(ctx, R.string.dialog_canceled) + ToastUtils.warnToast(ctx, R.string.dialog_canceled) dismiss() } protectionCheck.queryProtection(activity, BOLUS, { queryingProtection = false }, cancelFail, cancelFail) diff --git a/app/src/main/java/info/nightscout/androidaps/dialogs/FillDialog.kt b/app/src/main/java/info/nightscout/androidaps/dialogs/FillDialog.kt index a11fd61cbb..3699e70352 100644 --- a/app/src/main/java/info/nightscout/androidaps/dialogs/FillDialog.kt +++ b/app/src/main/java/info/nightscout/androidaps/dialogs/FillDialog.kt @@ -208,7 +208,7 @@ class FillDialog : DialogFragmentWithDate() { val cancelFail = { queryingProtection = false aapsLogger.debug(LTag.APS, "Dialog canceled on resume protection: ${this.javaClass.name}") - ToastUtils.showToastInUiThread(ctx, R.string.dialog_canceled) + ToastUtils.warnToast(ctx, R.string.dialog_canceled) dismiss() } protectionCheck.queryProtection(activity, BOLUS, { queryingProtection = false }, cancelFail, cancelFail) diff --git a/app/src/main/java/info/nightscout/androidaps/dialogs/InsulinDialog.kt b/app/src/main/java/info/nightscout/androidaps/dialogs/InsulinDialog.kt index 7c45fe99ee..25143f9feb 100644 --- a/app/src/main/java/info/nightscout/androidaps/dialogs/InsulinDialog.kt +++ b/app/src/main/java/info/nightscout/androidaps/dialogs/InsulinDialog.kt @@ -83,11 +83,11 @@ class InsulinDialog : DialogFragmentWithDate() { val maxInsulin = constraintChecker.getMaxBolusAllowed().value() if (abs(binding.time.value.toInt()) > 12 * 60) { binding.time.value = 0.0 - ToastUtils.showToastInUiThread(context, rh.gs(R.string.constraintapllied)) + ToastUtils.warnToast(context, R.string.constraintapllied) } if (binding.amount.value > maxInsulin) { binding.amount.value = 0.0 - ToastUtils.showToastInUiThread(context, rh.gs(R.string.bolusconstraintapplied)) + ToastUtils.warnToast(context, R.string.bolusconstraintapplied) } } @@ -267,7 +267,7 @@ class InsulinDialog : DialogFragmentWithDate() { val cancelFail = { queryingProtection = false aapsLogger.debug(LTag.APS, "Dialog canceled on resume protection: ${this.javaClass.name}") - ToastUtils.showToastInUiThread(ctx, R.string.dialog_canceled) + ToastUtils.warnToast(ctx, R.string.dialog_canceled) dismiss() } protectionCheck.queryProtection(activity, BOLUS, { queryingProtection = false }, cancelFail, cancelFail) diff --git a/app/src/main/java/info/nightscout/androidaps/dialogs/LoopDialog.kt b/app/src/main/java/info/nightscout/androidaps/dialogs/LoopDialog.kt index e0b0788a25..88a400f82c 100644 --- a/app/src/main/java/info/nightscout/androidaps/dialogs/LoopDialog.kt +++ b/app/src/main/java/info/nightscout/androidaps/dialogs/LoopDialog.kt @@ -304,7 +304,7 @@ class LoopDialog : DaggerDialogFragment() { commandQueue.cancelTempBasal(true, object : Callback() { override fun run() { if (!result.success) { - ToastUtils.showToastInUiThread(ctx, rh.gs(R.string.tempbasaldeliveryerror)) + ToastUtils.errorToast(ctx, rh.gs(R.string.tempbasaldeliveryerror)) } } }) @@ -449,7 +449,7 @@ class LoopDialog : DaggerDialogFragment() { val cancelFail = { queryingProtection = false aapsLogger.debug(LTag.APS, "Dialog canceled on resume protection: ${this.javaClass.name}") - ToastUtils.showToastInUiThread(ctx, R.string.dialog_canceled) + ToastUtils.warnToast(ctx, R.string.dialog_canceled) dismiss() } protectionCheck.queryProtection(activity, BOLUS, { queryingProtection = false }, cancelFail, cancelFail) diff --git a/app/src/main/java/info/nightscout/androidaps/dialogs/ProfileSwitchDialog.kt b/app/src/main/java/info/nightscout/androidaps/dialogs/ProfileSwitchDialog.kt index db1a8d0478..a3e410e826 100644 --- a/app/src/main/java/info/nightscout/androidaps/dialogs/ProfileSwitchDialog.kt +++ b/app/src/main/java/info/nightscout/androidaps/dialogs/ProfileSwitchDialog.kt @@ -258,7 +258,7 @@ class ProfileSwitchDialog : DialogFragmentWithDate() { val cancelFail = { queryingProtection = false aapsLogger.debug(LTag.APS, "Dialog canceled on resume protection: ${this.javaClass.name}") - ToastUtils.showToastInUiThread(ctx, R.string.dialog_canceled) + ToastUtils.warnToast(ctx, R.string.dialog_canceled) dismiss() } protectionCheck.queryProtection(activity, BOLUS, { queryingProtection = false }, cancelFail, cancelFail) diff --git a/app/src/main/java/info/nightscout/androidaps/dialogs/TempBasalDialog.kt b/app/src/main/java/info/nightscout/androidaps/dialogs/TempBasalDialog.kt index 39e0ddda9b..8940d1fb94 100644 --- a/app/src/main/java/info/nightscout/androidaps/dialogs/TempBasalDialog.kt +++ b/app/src/main/java/info/nightscout/androidaps/dialogs/TempBasalDialog.kt @@ -153,7 +153,7 @@ class TempBasalDialog : DialogFragmentWithDate() { val cancelFail = { queryingProtection = false aapsLogger.debug(LTag.APS, "Dialog canceled on resume protection: ${this.javaClass.name}") - ToastUtils.showToastInUiThread(ctx, R.string.dialog_canceled) + ToastUtils.warnToast(ctx, R.string.dialog_canceled) dismiss() } protectionCheck.queryProtection(activity, BOLUS, { queryingProtection = false }, cancelFail, cancelFail) diff --git a/app/src/main/java/info/nightscout/androidaps/dialogs/TempTargetDialog.kt b/app/src/main/java/info/nightscout/androidaps/dialogs/TempTargetDialog.kt index 407af78133..60609fe12d 100644 --- a/app/src/main/java/info/nightscout/androidaps/dialogs/TempTargetDialog.kt +++ b/app/src/main/java/info/nightscout/androidaps/dialogs/TempTargetDialog.kt @@ -230,7 +230,7 @@ class TempTargetDialog : DialogFragmentWithDate() { val cancelFail = { queryingProtection = false aapsLogger.debug(LTag.APS, "Dialog canceled on resume protection: ${this.javaClass.name}") - ToastUtils.showToastInUiThread(ctx, R.string.dialog_canceled) + ToastUtils.warnToast(ctx, R.string.dialog_canceled) dismiss() } protectionCheck.queryProtection(activity, BOLUS, { queryingProtection = false }, cancelFail, cancelFail) diff --git a/app/src/main/java/info/nightscout/androidaps/dialogs/TreatmentDialog.kt b/app/src/main/java/info/nightscout/androidaps/dialogs/TreatmentDialog.kt index 3a783410dd..14f18a193d 100644 --- a/app/src/main/java/info/nightscout/androidaps/dialogs/TreatmentDialog.kt +++ b/app/src/main/java/info/nightscout/androidaps/dialogs/TreatmentDialog.kt @@ -72,11 +72,11 @@ class TreatmentDialog : DialogFragmentWithDate() { val maxInsulin = constraintChecker.getMaxBolusAllowed().value() if (SafeParse.stringToInt(binding.carbs.text) > maxCarbs) { binding.carbs.value = 0.0 - ToastUtils.showToastInUiThread(context, rh.gs(R.string.carbsconstraintapplied)) + ToastUtils.warnToast(context, R.string.carbsconstraintapplied) } if (SafeParse.stringToDouble(binding.insulin.text) > maxInsulin) { binding.insulin.value = 0.0 - ToastUtils.showToastInUiThread(context, rh.gs(R.string.bolusconstraintapplied)) + ToastUtils.warnToast(context, R.string.bolusconstraintapplied) } } @@ -212,7 +212,7 @@ class TreatmentDialog : DialogFragmentWithDate() { val cancelFail = { queryingProtection = false aapsLogger.debug(LTag.APS, "Dialog canceled on resume protection: ${this.javaClass.name}") - ToastUtils.showToastInUiThread(ctx, R.string.dialog_canceled) + ToastUtils.warnToast(ctx, R.string.dialog_canceled) dismiss() } protectionCheck.queryProtection(activity, BOLUS, { queryingProtection = false }, cancelFail, cancelFail) diff --git a/app/src/main/java/info/nightscout/androidaps/dialogs/WizardDialog.kt b/app/src/main/java/info/nightscout/androidaps/dialogs/WizardDialog.kt index 9c8fe4ba91..8d86cb5e9e 100644 --- a/app/src/main/java/info/nightscout/androidaps/dialogs/WizardDialog.kt +++ b/app/src/main/java/info/nightscout/androidaps/dialogs/WizardDialog.kt @@ -335,7 +335,7 @@ class WizardDialog : DaggerDialogFragment() { val tempTarget = repository.getTemporaryTargetActiveAt(dateUtil.now()).blockingGet() if (profile == null || profileStore == null) { - ToastUtils.showToastInUiThread(ctx, rh.gs(R.string.noprofile)) + ToastUtils.errorToast(ctx, R.string.noprofile) dismiss() return } @@ -409,7 +409,7 @@ class WizardDialog : DaggerDialogFragment() { val carbsAfterConstraint = constraintChecker.applyCarbsConstraints(Constraint(carbs)).value() if (abs(carbs - carbsAfterConstraint) > 0.01) { binding.carbsInput.value = 0.0 - ToastUtils.showToastInUiThread(ctx, rh.gs(R.string.carbsconstraintapplied)) + ToastUtils.warnToast(ctx, R.string.carbsconstraintapplied) return } @@ -511,7 +511,7 @@ class WizardDialog : DaggerDialogFragment() { val cancelFail = { queryingProtection = false aapsLogger.debug(LTag.APS, "Dialog canceled on resume protection: ${this.javaClass.name}") - ToastUtils.showToastInUiThread(ctx, R.string.dialog_canceled) + ToastUtils.warnToast(ctx, R.string.dialog_canceled) dismiss() } protectionCheck.queryProtection(activity, BOLUS, { queryingProtection = false }, cancelFail, cancelFail) diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/constraints/objectives/activities/ObjectivesExamDialog.kt b/app/src/main/java/info/nightscout/androidaps/plugins/constraints/objectives/activities/ObjectivesExamDialog.kt index e2ae0121a0..7e4ac193fa 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/constraints/objectives/activities/ObjectivesExamDialog.kt +++ b/app/src/main/java/info/nightscout/androidaps/plugins/constraints/objectives/activities/ObjectivesExamDialog.kt @@ -109,7 +109,7 @@ class ObjectivesExamDialog : DaggerDialogFragment() { task.answered = result if (!result) { task.disabledTo = dateUtil.now() + T.hours(1).msecs() - context?.let { it1 -> ToastUtils.showToastInUiThread(it1, R.string.wronganswer) } + context?.let { it1 -> ToastUtils.infoToast(it1, R.string.wronganswer) } } else task.disabledTo = 0 updateGui() rxBus.send(EventObjectivesUpdateGui()) diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/general/overview/OverviewFragment.kt b/app/src/main/java/info/nightscout/androidaps/plugins/general/overview/OverviewFragment.kt index 54a2bbcb40..26b6321c14 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/general/overview/OverviewFragment.kt +++ b/app/src/main/java/info/nightscout/androidaps/plugins/general/overview/OverviewFragment.kt @@ -379,7 +379,7 @@ class OverviewFragment : DaggerFragment(), View.OnClickListener, OnLongClickList dexcomMediator.findDexcomPackageName()?.let { openCgmApp(it) } - ?: ToastUtils.showToastInUiThread(activity, rh.gs(R.string.dexcom_app_not_installed)) + ?: ToastUtils.infoToast(activity, rh.gs(R.string.dexcom_app_not_installed)) } } @@ -395,9 +395,9 @@ class OverviewFragment : DaggerFragment(), View.OnClickListener, OnLongClickList .addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP) ) } - ?: ToastUtils.showToastInUiThread(activity, rh.gs(R.string.dexcom_app_not_installed)) + ?: ToastUtils.infoToast(activity, rh.gs(R.string.dexcom_app_not_installed)) } catch (e: ActivityNotFoundException) { - ToastUtils.showToastInUiThread(activity, rh.gs(R.string.g5appnotdetected)) + ToastUtils.infoToast(activity, rh.gs(R.string.g5appnotdetected)) } } } diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/general/overview/graphData/GraphData.kt b/app/src/main/java/info/nightscout/androidaps/plugins/general/overview/graphData/GraphData.kt index 7b34ba26c3..d3aeb014e0 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/general/overview/graphData/GraphData.kt +++ b/app/src/main/java/info/nightscout/androidaps/plugins/general/overview/graphData/GraphData.kt @@ -56,7 +56,7 @@ class GraphData( addSeries(overviewData.bgReadingGraphSeries) if (addPredictions) addSeries(overviewData.predictionsGraphSeries) overviewData.bgReadingGraphSeries.setOnDataPointTapListener { _, dataPoint -> - if (dataPoint is GlucoseValueDataPoint) ToastUtils.showToastInUiThread(context, dataPoint.label) + if (dataPoint is GlucoseValueDataPoint) ToastUtils.infoToast(context, dataPoint.label) } } @@ -93,14 +93,14 @@ class GraphData( maxY = maxOf(maxY, overviewData.maxTreatmentsValue) addSeries(overviewData.treatmentsSeries) overviewData.treatmentsSeries.setOnDataPointTapListener { _, dataPoint -> - if (dataPoint is BolusDataPoint) ToastUtils.showToastInUiThread(context, dataPoint.label) + if (dataPoint is BolusDataPoint) ToastUtils.infoToast(context, dataPoint.label) } } fun addEps(context: Context?, scale: Double) { addSeries(overviewData.epsSeries) overviewData.epsSeries.setOnDataPointTapListener { _, dataPoint -> - if (dataPoint is EffectiveProfileSwitchDataPoint) ToastUtils.showToastInUiThread(context, dataPoint.data.originalCustomizedName) + if (dataPoint is EffectiveProfileSwitchDataPoint) ToastUtils.infoToast(context, dataPoint.data.originalCustomizedName) } overviewData.epsScale.multiplier = maxY * scale / overviewData.maxEpsValue } diff --git a/app/src/main/java/info/nightscout/androidaps/utils/XDripBroadcast.kt b/app/src/main/java/info/nightscout/androidaps/utils/XDripBroadcast.kt index 0553ca7dde..4fdc5fb70c 100644 --- a/app/src/main/java/info/nightscout/androidaps/utils/XDripBroadcast.kt +++ b/app/src/main/java/info/nightscout/androidaps/utils/XDripBroadcast.kt @@ -43,11 +43,11 @@ class XDripBroadcast @Inject constructor( context.sendBroadcast(intent) val q = context.packageManager.queryBroadcastReceivers(intent, 0) return if (q.size < 1) { - ToastUtils.showToastInUiThread(context, rh.gs(R.string.xdripnotinstalled)) + ToastUtils.errorToast(context, R.string.xdripnotinstalled) aapsLogger.debug(rh.gs(R.string.xdripnotinstalled)) false } else { - ToastUtils.showToastInUiThread(context, rh.gs(R.string.calibrationsent)) + ToastUtils.errorToast(context, R.string.calibrationsent) aapsLogger.debug(rh.gs(R.string.calibrationsent)) true } diff --git a/automation/src/main/java/info/nightscout/androidaps/plugins/general/automation/dialogs/EditEventDialog.kt b/automation/src/main/java/info/nightscout/androidaps/plugins/general/automation/dialogs/EditEventDialog.kt index 783b9dace3..cdafc9c788 100644 --- a/automation/src/main/java/info/nightscout/androidaps/plugins/general/automation/dialogs/EditEventDialog.kt +++ b/automation/src/main/java/info/nightscout/androidaps/plugins/general/automation/dialogs/EditEventDialog.kt @@ -128,7 +128,7 @@ class EditEventDialog : DialogFragmentWithDate() { // check for title val title = binding.inputEventTitle.text?.toString() ?: return false if (title.isEmpty()) { - context?.let { ToastUtils.showToastInUiThread(it, R.string.automation_missing_task_name) } + context?.let { ToastUtils.errorToast(it, R.string.automation_missing_task_name) } return false } event.title = title @@ -137,12 +137,12 @@ class EditEventDialog : DialogFragmentWithDate() { // check for at least one trigger val con = event.trigger if (con.size() == 0 && !event.userAction) { - context?.let { ToastUtils.showToastInUiThread(it, R.string.automation_missing_trigger) } + context?.let { ToastUtils.errorToast(it, R.string.automation_missing_trigger) } return false } // check for at least one action if (event.actions.isEmpty()) { - context?.let { ToastUtils.showToastInUiThread(it, R.string.automation_missing_action) } + context?.let { ToastUtils.errorToast(it, R.string.automation_missing_action) } return false } // store diff --git a/core/src/main/java/info/nightscout/androidaps/utils/ToastUtils.kt b/core/src/main/java/info/nightscout/androidaps/utils/ToastUtils.kt index 5d2ef2f6ae..1a6043723d 100644 --- a/core/src/main/java/info/nightscout/androidaps/utils/ToastUtils.kt +++ b/core/src/main/java/info/nightscout/androidaps/utils/ToastUtils.kt @@ -10,6 +10,7 @@ import android.widget.ImageView import android.widget.TextView import android.widget.Toast import androidx.annotation.DrawableRes +import androidx.annotation.StringRes import androidx.appcompat.view.ContextThemeWrapper import info.nightscout.androidaps.core.R import info.nightscout.androidaps.plugins.bus.RxBus @@ -27,10 +28,18 @@ object ToastUtils { graphicalToast(ctx, string, R.drawable.ic_toast_warn, true) } + fun warnToast(ctx: Context?, @StringRes id: Int) { + graphicalToast(ctx, ctx?.getString(id), R.drawable.ic_toast_warn, true) + } + fun infoToast(ctx: Context?, string: String?) { graphicalToast(ctx, string, R.drawable.ic_toast_info, true) } + fun infoToast(ctx: Context?, @StringRes id: Int) { + graphicalToast(ctx, ctx?.getString(id), R.drawable.ic_toast_info, true) + } + fun okToast(ctx: Context?, string: String?) { graphicalToast(ctx, string, R.drawable.ic_toast_check, true) } @@ -39,6 +48,10 @@ object ToastUtils { graphicalToast(ctx, string, R.drawable.ic_toast_error, true) } + fun errorToast(ctx: Context?, @StringRes id: Int) { + graphicalToast(ctx, ctx?.getString(id), R.drawable.ic_toast_error, true) + } + fun graphicalToast(ctx: Context?, string: String?, @DrawableRes iconId: Int) { graphicalToast(ctx, string, iconId, true) } diff --git a/core/src/main/java/info/nightscout/androidaps/utils/protection/BiometricCheck.kt b/core/src/main/java/info/nightscout/androidaps/utils/protection/BiometricCheck.kt index f3b8083baa..16f32a7035 100644 --- a/core/src/main/java/info/nightscout/androidaps/utils/protection/BiometricCheck.kt +++ b/core/src/main/java/info/nightscout/androidaps/utils/protection/BiometricCheck.kt @@ -23,7 +23,7 @@ object BiometricCheck { ERROR_VENDOR, ERROR_LOCKOUT_PERMANENT, ERROR_USER_CANCELED -> { - ToastUtils.showToastInUiThread(activity.baseContext, errString.toString()) + ToastUtils.errorToast(activity.baseContext, errString.toString()) // fallback to master password runOnUiThread { passwordCheck.queryPassword(activity, R.string.master_password, R.string.key_master_password, { ok?.run() }, { cancel?.run() }, { fail?.run() }) @@ -34,7 +34,7 @@ object BiometricCheck { cancel?.run() ERROR_NO_DEVICE_CREDENTIAL -> { - ToastUtils.showToastInUiThread(activity.baseContext, errString.toString()) + ToastUtils.errorToast(activity.baseContext, errString.toString()) // no pin set // fallback to master password runOnUiThread { 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 9d03d04cbc..24b67debb7 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 @@ -148,7 +148,7 @@ class PasswordCheck @Inject constructor( .setNegativeButton(context.getString(R.string.cancel) ) { dialog, _ -> val msg = if (pinInput) R.string.pin_not_changed else R.string.password_not_changed - ToastUtils.infoToast(context, context.getString(msg)) + ToastUtils.infoToast(context, msg) cancel?.invoke() dialog.cancel() } diff --git a/core/src/main/java/info/nightscout/androidaps/utils/ui/NumberPicker.kt b/core/src/main/java/info/nightscout/androidaps/utils/ui/NumberPicker.kt index 71d0b7c392..ad0a760456 100644 --- a/core/src/main/java/info/nightscout/androidaps/utils/ui/NumberPicker.kt +++ b/core/src/main/java/info/nightscout/androidaps/utils/ui/NumberPicker.kt @@ -173,13 +173,13 @@ open class NumberPicker(context: Context, attrs: AttributeSet? = null) : LinearL currentValue = SafeParse.stringToDouble(binding.editText.text.toString()) if (currentValue > maxValue) { currentValue = maxValue - ToastUtils.showToastInUiThread(context, context.getString(R.string.youareonallowedlimit)) + ToastUtils.warnToast(context, R.string.youareonallowedlimit) updateEditText() okButton?.visibility = VISIBLE } if (currentValue < minValue) { currentValue = minValue - ToastUtils.showToastInUiThread(context, context.getString(R.string.youareonallowedlimit)) + ToastUtils.warnToast(context, R.string.youareonallowedlimit) updateEditText() okButton?.visibility = VISIBLE } @@ -216,11 +216,11 @@ open class NumberPicker(context: Context, attrs: AttributeSet? = null) : LinearL get() { if (currentValue > maxValue) { currentValue = maxValue - ToastUtils.showToastInUiThread(context, context.getString(R.string.youareonallowedlimit)) + ToastUtils.warnToast(context, R.string.youareonallowedlimit) } if (currentValue < minValue) { currentValue = minValue - ToastUtils.showToastInUiThread(context, context.getString(R.string.youareonallowedlimit)) + ToastUtils.warnToast(context, R.string.youareonallowedlimit) } return currentValue } @@ -229,11 +229,11 @@ open class NumberPicker(context: Context, attrs: AttributeSet? = null) : LinearL currentValue = value if (currentValue > maxValue) { currentValue = maxValue - ToastUtils.showToastInUiThread(context, context.getString(R.string.youareonallowedlimit)) + ToastUtils.warnToast(context, R.string.youareonallowedlimit) } if (currentValue < minValue) { currentValue = minValue - ToastUtils.showToastInUiThread(context, context.getString(R.string.youareonallowedlimit)) + ToastUtils.warnToast(context, R.string.youareonallowedlimit) } callValueChangedListener() updateEditText() @@ -248,7 +248,7 @@ open class NumberPicker(context: Context, attrs: AttributeSet? = null) : LinearL if (currentValue > maxValue) { currentValue = maxValue callValueChangedListener() - ToastUtils.showToastInUiThread(context, context.getString(R.string.youareonallowedlimit)) + ToastUtils.warnToast(context, R.string.youareonallowedlimit) stopUpdating() } updateEditText() @@ -259,7 +259,7 @@ open class NumberPicker(context: Context, attrs: AttributeSet? = null) : LinearL if (currentValue < minValue) { currentValue = minValue callValueChangedListener() - ToastUtils.showToastInUiThread(context, context.getString(R.string.youareonallowedlimit)) + ToastUtils.warnToast(context, R.string.youareonallowedlimit) stopUpdating() } updateEditText() diff --git a/danar/src/main/java/info/nightscout/androidaps/danar/services/AbstractDanaRExecutionService.java b/danar/src/main/java/info/nightscout/androidaps/danar/services/AbstractDanaRExecutionService.java index 3425dd25ad..b582e829fd 100644 --- a/danar/src/main/java/info/nightscout/androidaps/danar/services/AbstractDanaRExecutionService.java +++ b/danar/src/main/java/info/nightscout/androidaps/danar/services/AbstractDanaRExecutionService.java @@ -215,13 +215,13 @@ public abstract class AbstractDanaRExecutionService extends DaggerService { } } } else { - ToastUtils.INSTANCE.showToastInUiThread(context.getApplicationContext(), rh.gs(R.string.nobtadapter)); + ToastUtils.INSTANCE.errorToast(context.getApplicationContext(), R.string.nobtadapter); } if (mBTDevice == null) { - ToastUtils.INSTANCE.showToastInUiThread(context.getApplicationContext(), rh.gs(R.string.devicenotfound)); + ToastUtils.INSTANCE.errorToast(context.getApplicationContext(), R.string.devicenotfound); } } else { - ToastUtils.INSTANCE.errorToast(context, context.getString(R.string.needconnectpermission)); + ToastUtils.INSTANCE.errorToast(context, R.string.needconnectpermission); } } diff --git a/danars/src/main/java/info/nightscout/androidaps/danars/DanaRSPlugin.kt b/danars/src/main/java/info/nightscout/androidaps/danars/DanaRSPlugin.kt index cfc4e85911..964fe05fb8 100644 --- a/danars/src/main/java/info/nightscout/androidaps/danars/DanaRSPlugin.kt +++ b/danars/src/main/java/info/nightscout/androidaps/danars/DanaRSPlugin.kt @@ -146,7 +146,7 @@ class DanaRSPlugin @Inject constructor( aapsLogger.debug(LTag.PUMP, "RS connect from: $reason") if (danaRSService != null && mDeviceAddress != "" && mDeviceName != "") { val success = danaRSService?.connect(reason, mDeviceAddress) ?: false - if (!success) ToastUtils.showToastInUiThread(context, rh.gs(R.string.ble_not_supported_or_not_paired)) + if (!success) ToastUtils.errorToast(context, R.string.ble_not_supported_or_not_paired) } } diff --git a/danars/src/main/java/info/nightscout/androidaps/danars/services/BLEComm.kt b/danars/src/main/java/info/nightscout/androidaps/danars/services/BLEComm.kt index 959a14aa3a..d3ad649bd9 100644 --- a/danars/src/main/java/info/nightscout/androidaps/danars/services/BLEComm.kt +++ b/danars/src/main/java/info/nightscout/androidaps/danars/services/BLEComm.kt @@ -158,7 +158,7 @@ class BLEComm @Inject internal constructor( // assume pairing keys are invalid val lastClearRequest = sp.getLong(R.string.key_rs_last_clear_key_request, 0) if (lastClearRequest != 0L && dateUtil.isOlderThan(lastClearRequest, 5)) { - ToastUtils.showToastInUiThread(context, R.string.invalidpairing) + ToastUtils.errorToast(context, R.string.invalidpairing) danaRSPlugin.changePump() removeBond() } else if (lastClearRequest == 0L) { @@ -175,7 +175,7 @@ class BLEComm @Inject internal constructor( sp.remove(rh.gs(R.string.key_danars_v3_randompairingkey) + danaRSPlugin.mDeviceName) sp.remove(rh.gs(R.string.key_danars_v3_pairingkey) + danaRSPlugin.mDeviceName) sp.remove(rh.gs(R.string.key_danars_v3_randomsynckey) + danaRSPlugin.mDeviceName) - ToastUtils.showToastInUiThread(context, R.string.invalidpairing) + ToastUtils.errorToast(context, R.string.invalidpairing) danaRSPlugin.changePump() } else if (lastClearRequest == 0L) { aapsLogger.error("Clearing pairing keys postponed") diff --git a/diaconn/src/main/java/info/nightscout/androidaps/diaconn/DiaconnG8Plugin.kt b/diaconn/src/main/java/info/nightscout/androidaps/diaconn/DiaconnG8Plugin.kt index 4bd3d07f22..d6f144209b 100644 --- a/diaconn/src/main/java/info/nightscout/androidaps/diaconn/DiaconnG8Plugin.kt +++ b/diaconn/src/main/java/info/nightscout/androidaps/diaconn/DiaconnG8Plugin.kt @@ -131,7 +131,7 @@ class DiaconnG8Plugin @Inject constructor( aapsLogger.debug(LTag.PUMP, "Diaconn G8 connect from: $reason") if(diaconnG8Service != null && mDeviceAddress != "" && mDeviceName != "") { val success = diaconnG8Service?.connect(reason, mDeviceAddress) ?: false - if(!success) ToastUtils.showToastInUiThread(context, rh.gs(R.string.ble_not_supported)) + if(!success) ToastUtils.errorToast(context, R.string.ble_not_supported) } }