Use graphical Toast

This commit is contained in:
Milos Kozak 2022-09-15 16:17:58 +02:00
parent 4f1cc50d76
commit 511dd08ae7
32 changed files with 90 additions and 77 deletions

View file

@ -175,29 +175,29 @@ class ProfileHelperActivity : NoSplashAppCompatActivity() {
for (i in 0..1) { for (i in 0..1) {
if (typeSelected[i] == ProfileType.MOTOL_DEFAULT) { if (typeSelected[i] == ProfileType.MOTOL_DEFAULT) {
if (ageUsed[i] < 1 || ageUsed[i] > 18) { if (ageUsed[i] < 1 || ageUsed[i] > 18) {
ToastUtils.showToastInUiThread(this, R.string.invalidage) ToastUtils.warnToast(this, R.string.invalidage)
return@setOnClickListener return@setOnClickListener
} }
if ((weightUsed[i] < 5 || weightUsed[i] > 150) && tddUsed[i] == 0.0) { 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 return@setOnClickListener
} }
if ((tddUsed[i] < 5 || tddUsed[i] > 150) && weightUsed[i] == 0.0) { 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 return@setOnClickListener
} }
} }
if (typeSelected[i] == ProfileType.DPV_DEFAULT) { if (typeSelected[i] == ProfileType.DPV_DEFAULT) {
if (ageUsed[i] < 1 || ageUsed[i] > 18) { if (ageUsed[i] < 1 || ageUsed[i] > 18) {
ToastUtils.showToastInUiThread(this, R.string.invalidage) ToastUtils.warnToast(this, R.string.invalidage)
return@setOnClickListener return@setOnClickListener
} }
if (tddUsed[i] < 5 || tddUsed[i] > 150) { if (tddUsed[i] < 5 || tddUsed[i] > 150) {
ToastUtils.showToastInUiThread(this, R.string.invalidweight) ToastUtils.warnToast(this, R.string.invalidweight)
return@setOnClickListener return@setOnClickListener
} }
if ((pctUsed[i] < 32 || pctUsed[i] > 37)) { if ((pctUsed[i] < 32 || pctUsed[i] > 37)) {
ToastUtils.showToastInUiThread(this, R.string.invalidpct) ToastUtils.warnToast(this, R.string.invalidpct)
return@setOnClickListener return@setOnClickListener
} }
} }
@ -226,7 +226,7 @@ class ProfileHelperActivity : NoSplashAppCompatActivity() {
return@setOnClickListener return@setOnClickListener
} }
} }
ToastUtils.showToastInUiThread(this, R.string.invalidinput) ToastUtils.warnToast(this, R.string.invalidinput)
} }
binding.ageLabel.labelFor = binding.age.editTextId binding.ageLabel.labelFor = binding.age.editTextId
binding.tddLabel.labelFor = binding.tdd.editTextId binding.tddLabel.labelFor = binding.tdd.editTextId

View file

@ -52,15 +52,15 @@ class SurveyActivity : NoSplashAppCompatActivity() {
val weight = SafeParse.stringToDouble(binding.weight.text.toString()) val weight = SafeParse.stringToDouble(binding.weight.text.toString())
val tdd = SafeParse.stringToDouble(binding.tdd.text.toString()) val tdd = SafeParse.stringToDouble(binding.tdd.text.toString())
if (age < 1 || age > 120) { if (age < 1 || age > 120) {
ToastUtils.showToastInUiThread(this, R.string.invalidage) ToastUtils.warnToast(this, R.string.invalidage)
return@setOnClickListener return@setOnClickListener
} }
if ((weight < 5 || weight > 150) && tdd == 0.0) { if ((weight < 5 || weight > 150) && tdd == 0.0) {
ToastUtils.showToastInUiThread(this, R.string.invalidweight) ToastUtils.warnToast(this, R.string.invalidweight)
return@setOnClickListener return@setOnClickListener
} }
if ((tdd < 5 || tdd > 150) && weight == 0.0) { if ((tdd < 5 || tdd > 150) && weight == 0.0) {
ToastUtils.showToastInUiThread(this, R.string.invalidweight) ToastUtils.warnToast(this, R.string.invalidweight)
return@setOnClickListener return@setOnClickListener
} }
profileFunction.getProfile()?.let { runningProfile -> profileFunction.getProfile()?.let { runningProfile ->
@ -84,11 +84,11 @@ class SurveyActivity : NoSplashAppCompatActivity() {
r.age = SafeParse.stringToInt(binding.age.text.toString()) r.age = SafeParse.stringToInt(binding.age.text.toString())
r.weight = SafeParse.stringToInt(binding.weight.text.toString()) r.weight = SafeParse.stringToInt(binding.weight.text.toString())
if (r.age < 1 || r.age > 120) { if (r.age < 1 || r.age > 120) {
ToastUtils.showToastInUiThread(this, R.string.invalidage) ToastUtils.warnToast(this, R.string.invalidage)
return@setOnClickListener return@setOnClickListener
} }
if (r.weight < 5 || r.weight > 150) { if (r.weight < 5 || r.weight > 150) {
ToastUtils.showToastInUiThread(this, R.string.invalidweight) ToastUtils.warnToast(this, R.string.invalidweight)
return@setOnClickListener return@setOnClickListener
} }
@ -110,7 +110,7 @@ class SurveyActivity : NoSplashAppCompatActivity() {
database.child("survey").child(r.id).setValue(r) database.child("survey").child(r.id).setValue(r)
} else { } else {
aapsLogger.error("signInAnonymously:failure", task.exception!!) aapsLogger.error("signInAnonymously:failure", task.exception!!)
ToastUtils.showToastInUiThread(this, "Authentication failed.") ToastUtils.warnToast(this, "Authentication failed.")
//updateUI(null) //updateUI(null)
} }

View file

@ -315,7 +315,7 @@ class TreatmentsBolusCarbsFragment : DaggerFragment(), MenuProvider {
R.id.nav_show_invalidated -> { R.id.nav_show_invalidated -> {
showInvalidated = true showInvalidated = true
updateMenuVisibility() updateMenuVisibility()
ToastUtils.showToastInUiThread(context, rh.gs(R.string.show_invalidated_records)) ToastUtils.infoToast(context, R.string.show_invalidated_records)
swapAdapter() swapAdapter()
true true
} }
@ -323,7 +323,7 @@ class TreatmentsBolusCarbsFragment : DaggerFragment(), MenuProvider {
R.id.nav_hide_invalidated -> { R.id.nav_hide_invalidated -> {
showInvalidated = false showInvalidated = false
updateMenuVisibility() updateMenuVisibility()
ToastUtils.showToastInUiThread(context, rh.gs(R.string.hide_invalidated_records)) ToastUtils.infoToast(context, R.string.hide_invalidated_records)
swapAdapter() swapAdapter()
true true
} }

View file

@ -206,7 +206,7 @@ class TreatmentsCareportalFragment : DaggerFragment(), MenuProvider {
R.id.nav_show_invalidated -> { R.id.nav_show_invalidated -> {
showInvalidated = true showInvalidated = true
updateMenuVisibility() updateMenuVisibility()
ToastUtils.showToastInUiThread(context, rh.gs(R.string.show_invalidated_records)) ToastUtils.infoToast(context, R.string.show_invalidated_records)
swapAdapter() swapAdapter()
true true
} }
@ -214,7 +214,7 @@ class TreatmentsCareportalFragment : DaggerFragment(), MenuProvider {
R.id.nav_hide_invalidated -> { R.id.nav_hide_invalidated -> {
showInvalidated = false showInvalidated = false
updateMenuVisibility() updateMenuVisibility()
ToastUtils.showToastInUiThread(context, rh.gs(R.string.hide_invalidated_records)) ToastUtils.infoToast(context, R.string.hide_invalidated_records)
swapAdapter() swapAdapter()
true true
} }

View file

@ -194,7 +194,7 @@ class TreatmentsExtendedBolusesFragment : DaggerFragment(), MenuProvider {
R.id.nav_show_invalidated -> { R.id.nav_show_invalidated -> {
showInvalidated = true showInvalidated = true
updateMenuVisibility() updateMenuVisibility()
ToastUtils.showToastInUiThread(context, rh.gs(R.string.show_invalidated_records)) ToastUtils.infoToast(context, R.string.show_invalidated_records)
swapAdapter() swapAdapter()
true true
} }
@ -202,7 +202,7 @@ class TreatmentsExtendedBolusesFragment : DaggerFragment(), MenuProvider {
R.id.nav_hide_invalidated -> { R.id.nav_hide_invalidated -> {
showInvalidated = false showInvalidated = false
updateMenuVisibility() updateMenuVisibility()
ToastUtils.showToastInUiThread(context, rh.gs(R.string.hide_invalidated_records)) ToastUtils.infoToast(context, R.string.hide_invalidated_records)
swapAdapter() swapAdapter()
true true
} }

View file

@ -294,7 +294,7 @@ class TreatmentsProfileSwitchFragment : DaggerFragment(), MenuProvider {
R.id.nav_show_invalidated -> { R.id.nav_show_invalidated -> {
showInvalidated = true showInvalidated = true
updateMenuVisibility() updateMenuVisibility()
ToastUtils.showToastInUiThread(context, rh.gs(R.string.show_invalidated_records)) ToastUtils.infoToast(context, R.string.show_invalidated_records)
swapAdapter() swapAdapter()
true true
} }
@ -302,7 +302,7 @@ class TreatmentsProfileSwitchFragment : DaggerFragment(), MenuProvider {
R.id.nav_hide_invalidated -> { R.id.nav_hide_invalidated -> {
showInvalidated = false showInvalidated = false
updateMenuVisibility() updateMenuVisibility()
ToastUtils.showToastInUiThread(context, rh.gs(R.string.hide_invalidated_records)) ToastUtils.infoToast(context, R.string.hide_invalidated_records)
swapAdapter() swapAdapter()
true true
} }

View file

@ -225,7 +225,7 @@ class TreatmentsTempTargetFragment : DaggerFragment(), MenuProvider {
R.id.nav_show_invalidated -> { R.id.nav_show_invalidated -> {
showInvalidated = true showInvalidated = true
updateMenuVisibility() updateMenuVisibility()
ToastUtils.showToastInUiThread(context, rh.gs(R.string.show_invalidated_records)) ToastUtils.infoToast(context, R.string.show_invalidated_records)
swapAdapter() swapAdapter()
true true
} }
@ -233,7 +233,7 @@ class TreatmentsTempTargetFragment : DaggerFragment(), MenuProvider {
R.id.nav_hide_invalidated -> { R.id.nav_hide_invalidated -> {
showInvalidated = false showInvalidated = false
updateMenuVisibility() updateMenuVisibility()
ToastUtils.showToastInUiThread(context, rh.gs(R.string.show_invalidated_records)) ToastUtils.infoToast(context, R.string.show_invalidated_records)
swapAdapter() swapAdapter()
true true
} }

View file

@ -236,7 +236,7 @@ class TreatmentsTemporaryBasalsFragment : DaggerFragment(), MenuProvider {
R.id.nav_show_invalidated -> { R.id.nav_show_invalidated -> {
showInvalidated = true showInvalidated = true
updateMenuVisibility() updateMenuVisibility()
ToastUtils.showToastInUiThread(context, rh.gs(R.string.show_invalidated_records)) ToastUtils.infoToast(context, R.string.show_invalidated_records)
swapAdapter() swapAdapter()
true true
} }
@ -244,7 +244,7 @@ class TreatmentsTemporaryBasalsFragment : DaggerFragment(), MenuProvider {
R.id.nav_hide_invalidated -> { R.id.nav_hide_invalidated -> {
showInvalidated = false showInvalidated = false
updateMenuVisibility() updateMenuVisibility()
ToastUtils.showToastInUiThread(context, rh.gs(R.string.hide_invalidated_records)) ToastUtils.infoToast(context, R.string.hide_invalidated_records)
swapAdapter() swapAdapter()
true true
} }

View file

@ -162,7 +162,7 @@ class TreatmentsUserEntryFragment : DaggerFragment(), MenuProvider {
R.id.nav_show_loop -> { R.id.nav_show_loop -> {
showLoop = true showLoop = true
updateMenuVisibility() updateMenuVisibility()
ToastUtils.showToastInUiThread(context, rh.gs(R.string.show_loop_records)) ToastUtils.infoToast(context, R.string.show_loop_records)
swapAdapter() swapAdapter()
true true
} }
@ -170,7 +170,7 @@ class TreatmentsUserEntryFragment : DaggerFragment(), MenuProvider {
R.id.nav_hide_loop -> { R.id.nav_hide_loop -> {
showLoop = false showLoop = false
updateMenuVisibility() updateMenuVisibility()
ToastUtils.showToastInUiThread(context, rh.gs(R.string.show_hide_records)) ToastUtils.infoToast(context, R.string.show_hide_records)
swapAdapter() swapAdapter()
true true
} }

View file

@ -78,15 +78,15 @@ class CarbsDialog : DialogFragmentWithDate() {
val time = binding.time.value.toInt() val time = binding.time.value.toInt()
if (time > 12 * 60 || time < -7 * 24 * 60) { if (time > 12 * 60 || time < -7 * 24 * 60) {
binding.time.value = 0.0 binding.time.value = 0.0
ToastUtils.showToastInUiThread(ctx, rh.gs(R.string.constraintapllied)) ToastUtils.warnToast(ctx, R.string.constraintapllied)
} }
if (binding.duration.value > 10) { if (binding.duration.value > 10) {
binding.duration.value = 0.0 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) { if (binding.carbs.value.toInt() > maxCarbs) {
binding.carbs.value = 0.0 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 = { val cancelFail = {
queryingProtection = false queryingProtection = false
aapsLogger.debug(LTag.APS, "Dialog canceled on resume protection: ${this.javaClass.name}") 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() dismiss()
} }
protectionCheck.queryProtection(activity, BOLUS, { queryingProtection = false }, cancelFail, cancelFail) protectionCheck.queryProtection(activity, BOLUS, { queryingProtection = false }, cancelFail, cancelFail)

View file

@ -120,7 +120,7 @@ class ExtendedBolusDialog : DialogFragmentWithDate() {
val cancelFail = { val cancelFail = {
queryingProtection = false queryingProtection = false
aapsLogger.debug(LTag.APS, "Dialog canceled on resume protection: ${this.javaClass.name}") 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() dismiss()
} }
protectionCheck.queryProtection(activity, BOLUS, { queryingProtection = false }, cancelFail, cancelFail) protectionCheck.queryProtection(activity, BOLUS, { queryingProtection = false }, cancelFail, cancelFail)

View file

@ -208,7 +208,7 @@ class FillDialog : DialogFragmentWithDate() {
val cancelFail = { val cancelFail = {
queryingProtection = false queryingProtection = false
aapsLogger.debug(LTag.APS, "Dialog canceled on resume protection: ${this.javaClass.name}") 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() dismiss()
} }
protectionCheck.queryProtection(activity, BOLUS, { queryingProtection = false }, cancelFail, cancelFail) protectionCheck.queryProtection(activity, BOLUS, { queryingProtection = false }, cancelFail, cancelFail)

View file

@ -83,11 +83,11 @@ class InsulinDialog : DialogFragmentWithDate() {
val maxInsulin = constraintChecker.getMaxBolusAllowed().value() val maxInsulin = constraintChecker.getMaxBolusAllowed().value()
if (abs(binding.time.value.toInt()) > 12 * 60) { if (abs(binding.time.value.toInt()) > 12 * 60) {
binding.time.value = 0.0 binding.time.value = 0.0
ToastUtils.showToastInUiThread(context, rh.gs(R.string.constraintapllied)) ToastUtils.warnToast(context, R.string.constraintapllied)
} }
if (binding.amount.value > maxInsulin) { if (binding.amount.value > maxInsulin) {
binding.amount.value = 0.0 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 = { val cancelFail = {
queryingProtection = false queryingProtection = false
aapsLogger.debug(LTag.APS, "Dialog canceled on resume protection: ${this.javaClass.name}") 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() dismiss()
} }
protectionCheck.queryProtection(activity, BOLUS, { queryingProtection = false }, cancelFail, cancelFail) protectionCheck.queryProtection(activity, BOLUS, { queryingProtection = false }, cancelFail, cancelFail)

View file

@ -304,7 +304,7 @@ class LoopDialog : DaggerDialogFragment() {
commandQueue.cancelTempBasal(true, object : Callback() { commandQueue.cancelTempBasal(true, object : Callback() {
override fun run() { override fun run() {
if (!result.success) { 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 = { val cancelFail = {
queryingProtection = false queryingProtection = false
aapsLogger.debug(LTag.APS, "Dialog canceled on resume protection: ${this.javaClass.name}") 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() dismiss()
} }
protectionCheck.queryProtection(activity, BOLUS, { queryingProtection = false }, cancelFail, cancelFail) protectionCheck.queryProtection(activity, BOLUS, { queryingProtection = false }, cancelFail, cancelFail)

View file

@ -258,7 +258,7 @@ class ProfileSwitchDialog : DialogFragmentWithDate() {
val cancelFail = { val cancelFail = {
queryingProtection = false queryingProtection = false
aapsLogger.debug(LTag.APS, "Dialog canceled on resume protection: ${this.javaClass.name}") 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() dismiss()
} }
protectionCheck.queryProtection(activity, BOLUS, { queryingProtection = false }, cancelFail, cancelFail) protectionCheck.queryProtection(activity, BOLUS, { queryingProtection = false }, cancelFail, cancelFail)

View file

@ -153,7 +153,7 @@ class TempBasalDialog : DialogFragmentWithDate() {
val cancelFail = { val cancelFail = {
queryingProtection = false queryingProtection = false
aapsLogger.debug(LTag.APS, "Dialog canceled on resume protection: ${this.javaClass.name}") 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() dismiss()
} }
protectionCheck.queryProtection(activity, BOLUS, { queryingProtection = false }, cancelFail, cancelFail) protectionCheck.queryProtection(activity, BOLUS, { queryingProtection = false }, cancelFail, cancelFail)

View file

@ -230,7 +230,7 @@ class TempTargetDialog : DialogFragmentWithDate() {
val cancelFail = { val cancelFail = {
queryingProtection = false queryingProtection = false
aapsLogger.debug(LTag.APS, "Dialog canceled on resume protection: ${this.javaClass.name}") 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() dismiss()
} }
protectionCheck.queryProtection(activity, BOLUS, { queryingProtection = false }, cancelFail, cancelFail) protectionCheck.queryProtection(activity, BOLUS, { queryingProtection = false }, cancelFail, cancelFail)

View file

@ -72,11 +72,11 @@ class TreatmentDialog : DialogFragmentWithDate() {
val maxInsulin = constraintChecker.getMaxBolusAllowed().value() val maxInsulin = constraintChecker.getMaxBolusAllowed().value()
if (SafeParse.stringToInt(binding.carbs.text) > maxCarbs) { if (SafeParse.stringToInt(binding.carbs.text) > maxCarbs) {
binding.carbs.value = 0.0 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) { if (SafeParse.stringToDouble(binding.insulin.text) > maxInsulin) {
binding.insulin.value = 0.0 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 = { val cancelFail = {
queryingProtection = false queryingProtection = false
aapsLogger.debug(LTag.APS, "Dialog canceled on resume protection: ${this.javaClass.name}") 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() dismiss()
} }
protectionCheck.queryProtection(activity, BOLUS, { queryingProtection = false }, cancelFail, cancelFail) protectionCheck.queryProtection(activity, BOLUS, { queryingProtection = false }, cancelFail, cancelFail)

View file

@ -335,7 +335,7 @@ class WizardDialog : DaggerDialogFragment() {
val tempTarget = repository.getTemporaryTargetActiveAt(dateUtil.now()).blockingGet() val tempTarget = repository.getTemporaryTargetActiveAt(dateUtil.now()).blockingGet()
if (profile == null || profileStore == null) { if (profile == null || profileStore == null) {
ToastUtils.showToastInUiThread(ctx, rh.gs(R.string.noprofile)) ToastUtils.errorToast(ctx, R.string.noprofile)
dismiss() dismiss()
return return
} }
@ -409,7 +409,7 @@ class WizardDialog : DaggerDialogFragment() {
val carbsAfterConstraint = constraintChecker.applyCarbsConstraints(Constraint(carbs)).value() val carbsAfterConstraint = constraintChecker.applyCarbsConstraints(Constraint(carbs)).value()
if (abs(carbs - carbsAfterConstraint) > 0.01) { if (abs(carbs - carbsAfterConstraint) > 0.01) {
binding.carbsInput.value = 0.0 binding.carbsInput.value = 0.0
ToastUtils.showToastInUiThread(ctx, rh.gs(R.string.carbsconstraintapplied)) ToastUtils.warnToast(ctx, R.string.carbsconstraintapplied)
return return
} }
@ -511,7 +511,7 @@ class WizardDialog : DaggerDialogFragment() {
val cancelFail = { val cancelFail = {
queryingProtection = false queryingProtection = false
aapsLogger.debug(LTag.APS, "Dialog canceled on resume protection: ${this.javaClass.name}") 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() dismiss()
} }
protectionCheck.queryProtection(activity, BOLUS, { queryingProtection = false }, cancelFail, cancelFail) protectionCheck.queryProtection(activity, BOLUS, { queryingProtection = false }, cancelFail, cancelFail)

View file

@ -109,7 +109,7 @@ class ObjectivesExamDialog : DaggerDialogFragment() {
task.answered = result task.answered = result
if (!result) { if (!result) {
task.disabledTo = dateUtil.now() + T.hours(1).msecs() 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 } else task.disabledTo = 0
updateGui() updateGui()
rxBus.send(EventObjectivesUpdateGui()) rxBus.send(EventObjectivesUpdateGui())

View file

@ -379,7 +379,7 @@ class OverviewFragment : DaggerFragment(), View.OnClickListener, OnLongClickList
dexcomMediator.findDexcomPackageName()?.let { dexcomMediator.findDexcomPackageName()?.let {
openCgmApp(it) 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) .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) { } catch (e: ActivityNotFoundException) {
ToastUtils.showToastInUiThread(activity, rh.gs(R.string.g5appnotdetected)) ToastUtils.infoToast(activity, rh.gs(R.string.g5appnotdetected))
} }
} }
} }

View file

@ -56,7 +56,7 @@ class GraphData(
addSeries(overviewData.bgReadingGraphSeries) addSeries(overviewData.bgReadingGraphSeries)
if (addPredictions) addSeries(overviewData.predictionsGraphSeries) if (addPredictions) addSeries(overviewData.predictionsGraphSeries)
overviewData.bgReadingGraphSeries.setOnDataPointTapListener { _, dataPoint -> 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) maxY = maxOf(maxY, overviewData.maxTreatmentsValue)
addSeries(overviewData.treatmentsSeries) addSeries(overviewData.treatmentsSeries)
overviewData.treatmentsSeries.setOnDataPointTapListener { _, dataPoint -> 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) { fun addEps(context: Context?, scale: Double) {
addSeries(overviewData.epsSeries) addSeries(overviewData.epsSeries)
overviewData.epsSeries.setOnDataPointTapListener { _, dataPoint -> 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 overviewData.epsScale.multiplier = maxY * scale / overviewData.maxEpsValue
} }

View file

@ -43,11 +43,11 @@ class XDripBroadcast @Inject constructor(
context.sendBroadcast(intent) context.sendBroadcast(intent)
val q = context.packageManager.queryBroadcastReceivers(intent, 0) val q = context.packageManager.queryBroadcastReceivers(intent, 0)
return if (q.size < 1) { 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)) aapsLogger.debug(rh.gs(R.string.xdripnotinstalled))
false false
} else { } else {
ToastUtils.showToastInUiThread(context, rh.gs(R.string.calibrationsent)) ToastUtils.errorToast(context, R.string.calibrationsent)
aapsLogger.debug(rh.gs(R.string.calibrationsent)) aapsLogger.debug(rh.gs(R.string.calibrationsent))
true true
} }

View file

@ -128,7 +128,7 @@ class EditEventDialog : DialogFragmentWithDate() {
// check for title // check for title
val title = binding.inputEventTitle.text?.toString() ?: return false val title = binding.inputEventTitle.text?.toString() ?: return false
if (title.isEmpty()) { 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 return false
} }
event.title = title event.title = title
@ -137,12 +137,12 @@ class EditEventDialog : DialogFragmentWithDate() {
// check for at least one trigger // check for at least one trigger
val con = event.trigger val con = event.trigger
if (con.size() == 0 && !event.userAction) { 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 return false
} }
// check for at least one action // check for at least one action
if (event.actions.isEmpty()) { 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 return false
} }
// store // store

View file

@ -10,6 +10,7 @@ import android.widget.ImageView
import android.widget.TextView import android.widget.TextView
import android.widget.Toast import android.widget.Toast
import androidx.annotation.DrawableRes import androidx.annotation.DrawableRes
import androidx.annotation.StringRes
import androidx.appcompat.view.ContextThemeWrapper import androidx.appcompat.view.ContextThemeWrapper
import info.nightscout.androidaps.core.R import info.nightscout.androidaps.core.R
import info.nightscout.androidaps.plugins.bus.RxBus import info.nightscout.androidaps.plugins.bus.RxBus
@ -27,10 +28,18 @@ object ToastUtils {
graphicalToast(ctx, string, R.drawable.ic_toast_warn, true) 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?) { fun infoToast(ctx: Context?, string: String?) {
graphicalToast(ctx, string, R.drawable.ic_toast_info, true) 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?) { fun okToast(ctx: Context?, string: String?) {
graphicalToast(ctx, string, R.drawable.ic_toast_check, true) graphicalToast(ctx, string, R.drawable.ic_toast_check, true)
} }
@ -39,6 +48,10 @@ object ToastUtils {
graphicalToast(ctx, string, R.drawable.ic_toast_error, true) 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) { fun graphicalToast(ctx: Context?, string: String?, @DrawableRes iconId: Int) {
graphicalToast(ctx, string, iconId, true) graphicalToast(ctx, string, iconId, true)
} }

View file

@ -23,7 +23,7 @@ object BiometricCheck {
ERROR_VENDOR, ERROR_VENDOR,
ERROR_LOCKOUT_PERMANENT, ERROR_LOCKOUT_PERMANENT,
ERROR_USER_CANCELED -> { ERROR_USER_CANCELED -> {
ToastUtils.showToastInUiThread(activity.baseContext, errString.toString()) ToastUtils.errorToast(activity.baseContext, errString.toString())
// fallback to master password // fallback to master password
runOnUiThread { runOnUiThread {
passwordCheck.queryPassword(activity, R.string.master_password, R.string.key_master_password, { ok?.run() }, { cancel?.run() }, { fail?.run() }) 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() cancel?.run()
ERROR_NO_DEVICE_CREDENTIAL -> { ERROR_NO_DEVICE_CREDENTIAL -> {
ToastUtils.showToastInUiThread(activity.baseContext, errString.toString()) ToastUtils.errorToast(activity.baseContext, errString.toString())
// no pin set // no pin set
// fallback to master password // fallback to master password
runOnUiThread { runOnUiThread {

View file

@ -148,7 +148,7 @@ class PasswordCheck @Inject constructor(
.setNegativeButton(context.getString(R.string.cancel) .setNegativeButton(context.getString(R.string.cancel)
) { dialog, _ -> ) { dialog, _ ->
val msg = if (pinInput) R.string.pin_not_changed else R.string.password_not_changed 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() cancel?.invoke()
dialog.cancel() dialog.cancel()
} }

View file

@ -173,13 +173,13 @@ open class NumberPicker(context: Context, attrs: AttributeSet? = null) : LinearL
currentValue = SafeParse.stringToDouble(binding.editText.text.toString()) currentValue = SafeParse.stringToDouble(binding.editText.text.toString())
if (currentValue > maxValue) { if (currentValue > maxValue) {
currentValue = maxValue currentValue = maxValue
ToastUtils.showToastInUiThread(context, context.getString(R.string.youareonallowedlimit)) ToastUtils.warnToast(context, R.string.youareonallowedlimit)
updateEditText() updateEditText()
okButton?.visibility = VISIBLE okButton?.visibility = VISIBLE
} }
if (currentValue < minValue) { if (currentValue < minValue) {
currentValue = minValue currentValue = minValue
ToastUtils.showToastInUiThread(context, context.getString(R.string.youareonallowedlimit)) ToastUtils.warnToast(context, R.string.youareonallowedlimit)
updateEditText() updateEditText()
okButton?.visibility = VISIBLE okButton?.visibility = VISIBLE
} }
@ -216,11 +216,11 @@ open class NumberPicker(context: Context, attrs: AttributeSet? = null) : LinearL
get() { get() {
if (currentValue > maxValue) { if (currentValue > maxValue) {
currentValue = maxValue currentValue = maxValue
ToastUtils.showToastInUiThread(context, context.getString(R.string.youareonallowedlimit)) ToastUtils.warnToast(context, R.string.youareonallowedlimit)
} }
if (currentValue < minValue) { if (currentValue < minValue) {
currentValue = minValue currentValue = minValue
ToastUtils.showToastInUiThread(context, context.getString(R.string.youareonallowedlimit)) ToastUtils.warnToast(context, R.string.youareonallowedlimit)
} }
return currentValue return currentValue
} }
@ -229,11 +229,11 @@ open class NumberPicker(context: Context, attrs: AttributeSet? = null) : LinearL
currentValue = value currentValue = value
if (currentValue > maxValue) { if (currentValue > maxValue) {
currentValue = maxValue currentValue = maxValue
ToastUtils.showToastInUiThread(context, context.getString(R.string.youareonallowedlimit)) ToastUtils.warnToast(context, R.string.youareonallowedlimit)
} }
if (currentValue < minValue) { if (currentValue < minValue) {
currentValue = minValue currentValue = minValue
ToastUtils.showToastInUiThread(context, context.getString(R.string.youareonallowedlimit)) ToastUtils.warnToast(context, R.string.youareonallowedlimit)
} }
callValueChangedListener() callValueChangedListener()
updateEditText() updateEditText()
@ -248,7 +248,7 @@ open class NumberPicker(context: Context, attrs: AttributeSet? = null) : LinearL
if (currentValue > maxValue) { if (currentValue > maxValue) {
currentValue = maxValue currentValue = maxValue
callValueChangedListener() callValueChangedListener()
ToastUtils.showToastInUiThread(context, context.getString(R.string.youareonallowedlimit)) ToastUtils.warnToast(context, R.string.youareonallowedlimit)
stopUpdating() stopUpdating()
} }
updateEditText() updateEditText()
@ -259,7 +259,7 @@ open class NumberPicker(context: Context, attrs: AttributeSet? = null) : LinearL
if (currentValue < minValue) { if (currentValue < minValue) {
currentValue = minValue currentValue = minValue
callValueChangedListener() callValueChangedListener()
ToastUtils.showToastInUiThread(context, context.getString(R.string.youareonallowedlimit)) ToastUtils.warnToast(context, R.string.youareonallowedlimit)
stopUpdating() stopUpdating()
} }
updateEditText() updateEditText()

View file

@ -215,13 +215,13 @@ public abstract class AbstractDanaRExecutionService extends DaggerService {
} }
} }
} else { } else {
ToastUtils.INSTANCE.showToastInUiThread(context.getApplicationContext(), rh.gs(R.string.nobtadapter)); ToastUtils.INSTANCE.errorToast(context.getApplicationContext(), R.string.nobtadapter);
} }
if (mBTDevice == null) { if (mBTDevice == null) {
ToastUtils.INSTANCE.showToastInUiThread(context.getApplicationContext(), rh.gs(R.string.devicenotfound)); ToastUtils.INSTANCE.errorToast(context.getApplicationContext(), R.string.devicenotfound);
} }
} else { } else {
ToastUtils.INSTANCE.errorToast(context, context.getString(R.string.needconnectpermission)); ToastUtils.INSTANCE.errorToast(context, R.string.needconnectpermission);
} }
} }

View file

@ -146,7 +146,7 @@ class DanaRSPlugin @Inject constructor(
aapsLogger.debug(LTag.PUMP, "RS connect from: $reason") aapsLogger.debug(LTag.PUMP, "RS connect from: $reason")
if (danaRSService != null && mDeviceAddress != "" && mDeviceName != "") { if (danaRSService != null && mDeviceAddress != "" && mDeviceName != "") {
val success = danaRSService?.connect(reason, mDeviceAddress) ?: false 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)
} }
} }

View file

@ -158,7 +158,7 @@ class BLEComm @Inject internal constructor(
// assume pairing keys are invalid // assume pairing keys are invalid
val lastClearRequest = sp.getLong(R.string.key_rs_last_clear_key_request, 0) val lastClearRequest = sp.getLong(R.string.key_rs_last_clear_key_request, 0)
if (lastClearRequest != 0L && dateUtil.isOlderThan(lastClearRequest, 5)) { if (lastClearRequest != 0L && dateUtil.isOlderThan(lastClearRequest, 5)) {
ToastUtils.showToastInUiThread(context, R.string.invalidpairing) ToastUtils.errorToast(context, R.string.invalidpairing)
danaRSPlugin.changePump() danaRSPlugin.changePump()
removeBond() removeBond()
} else if (lastClearRequest == 0L) { } 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_randompairingkey) + danaRSPlugin.mDeviceName)
sp.remove(rh.gs(R.string.key_danars_v3_pairingkey) + 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) 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() danaRSPlugin.changePump()
} else if (lastClearRequest == 0L) { } else if (lastClearRequest == 0L) {
aapsLogger.error("Clearing pairing keys postponed") aapsLogger.error("Clearing pairing keys postponed")

View file

@ -131,7 +131,7 @@ class DiaconnG8Plugin @Inject constructor(
aapsLogger.debug(LTag.PUMP, "Diaconn G8 connect from: $reason") aapsLogger.debug(LTag.PUMP, "Diaconn G8 connect from: $reason")
if(diaconnG8Service != null && mDeviceAddress != "" && mDeviceName != "") { if(diaconnG8Service != null && mDeviceAddress != "" && mDeviceName != "") {
val success = diaconnG8Service?.connect(reason, mDeviceAddress) ?: false 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)
} }
} }