Toast for error in profile

This commit is contained in:
Milos Kozak 2021-10-21 09:45:34 +02:00
parent aee569e9a9
commit 30af551cbd
3 changed files with 57 additions and 14 deletions

View file

@ -221,7 +221,7 @@ class LocalProfileFragment : DaggerFragment() {
} }
binding.save.setOnClickListener { binding.save.setOnClickListener {
if (!localProfilePlugin.isValidEditState()) { if (!localProfilePlugin.isValidEditState(activity)) {
return@setOnClickListener //Should not happen as saveButton should not be visible if not valid return@setOnClickListener //Should not happen as saveButton should not be visible if not valid
} }
uel.log(Action.STORE_PROFILE, Sources.LocalProfile, ValueWithUnit.SimpleString(localProfilePlugin.currentProfile()?.name uel.log(Action.STORE_PROFILE, Sources.LocalProfile, ValueWithUnit.SimpleString(localProfilePlugin.currentProfile()?.name
@ -261,7 +261,7 @@ class LocalProfileFragment : DaggerFragment() {
private fun updateGUI() { private fun updateGUI() {
if (_binding == null) return if (_binding == null) return
val isValid = localProfilePlugin.isValidEditState() val isValid = localProfilePlugin.isValidEditState(activity)
val isEdited = localProfilePlugin.isEdited val isEdited = localProfilePlugin.isEdited
if (isValid) { if (isValid) {
this.view?.setBackgroundColor(resourceHelper.gc(R.color.ok_background)) this.view?.setBackgroundColor(resourceHelper.gc(R.color.ok_background))

View file

@ -24,6 +24,7 @@ import info.nightscout.androidaps.utils.DateUtil
import info.nightscout.androidaps.utils.DecimalFormatter import info.nightscout.androidaps.utils.DecimalFormatter
import info.nightscout.androidaps.utils.HardLimits import info.nightscout.androidaps.utils.HardLimits
import info.nightscout.androidaps.utils.JsonHelper import info.nightscout.androidaps.utils.JsonHelper
import info.nightscout.androidaps.utils.ToastUtils
import info.nightscout.androidaps.utils.alertDialogs.OKDialog import info.nightscout.androidaps.utils.alertDialogs.OKDialog
import info.nightscout.androidaps.utils.resources.ResourceHelper import info.nightscout.androidaps.utils.resources.ResourceHelper
import info.nightscout.androidaps.utils.sharedPreferences.SP import info.nightscout.androidaps.utils.sharedPreferences.SP
@ -104,25 +105,62 @@ class LocalProfilePlugin @Inject constructor(
fun currentProfile(): SingleProfile? = if (numOfProfiles > 0 && currentProfileIndex < numOfProfiles) profiles[currentProfileIndex] else null fun currentProfile(): SingleProfile? = if (numOfProfiles > 0 && currentProfileIndex < numOfProfiles) profiles[currentProfileIndex] else null
@Synchronized @Synchronized
fun isValidEditState(): Boolean { fun isValidEditState(activity: FragmentActivity?): Boolean {
val pumpDescription = activePlugin.activePump.pumpDescription val pumpDescription = activePlugin.activePump.pumpDescription
with(profiles[currentProfileIndex]) { with(profiles[currentProfileIndex]) {
if (dia < hardLimits.minDia() || dia > hardLimits.maxDia()) return false if (dia < hardLimits.minDia() || dia > hardLimits.maxDia()) {
if (name.isNullOrEmpty()) return false ToastUtils.errorToast(activity,resourceHelper.gs(R.string.value_out_of_hard_limits, resourceHelper.gs(info.nightscout.androidaps.core.R.string.profile_dia), dia))
if (blockFromJsonArray(ic, dateUtil)?.any { it.amount < hardLimits.minIC() || it.amount > hardLimits.maxIC() } != false) return false return false
if (blockFromJsonArray(basal, dateUtil)?.any { it.amount < pumpDescription.basalMinimumRate || it.amount > 10.0 } != false) return false }
if (name.isNullOrEmpty()){
ToastUtils.errorToast(activity,resourceHelper.gs(R.string.missing_profile_name))
return false
}
if (blockFromJsonArray(ic, dateUtil)?.any { it.amount < hardLimits.minIC() || it.amount > hardLimits.maxIC() } != false) {
ToastUtils.errorToast(activity,resourceHelper.gs(R.string.error_in_ic_values))
return false
}
val low = blockFromJsonArray(targetLow, dateUtil) val low = blockFromJsonArray(targetLow, dateUtil)
val high = blockFromJsonArray(targetHigh, dateUtil) val high = blockFromJsonArray(targetHigh, dateUtil)
if (profileFunction.getUnits() == GlucoseUnit.MGDL) { if (profileFunction.getUnits() == GlucoseUnit.MGDL) {
if (low?.any { it.amount < HardLimits.VERY_HARD_LIMIT_TARGET_BG[0].toDouble() || it.amount > HardLimits.VERY_HARD_LIMIT_TARGET_BG[1].toDouble() } != false) return false if (blockFromJsonArray(isf, dateUtil)?.any { it.amount < HardLimits.MIN_ISF || it.amount > HardLimits.MAX_ISF } != false) {
if (high?.any { it.amount < HardLimits.VERY_HARD_LIMIT_TARGET_BG[0].toDouble() || it.amount > HardLimits.VERY_HARD_LIMIT_TARGET_BG[1].toDouble() } != false) return false ToastUtils.errorToast(activity,resourceHelper.gs(R.string.error_in_isf_values))
if (blockFromJsonArray(isf, dateUtil)?.any { it.amount < HardLimits.MIN_ISF || it.amount > HardLimits.MAX_ISF } != false) return false return false
}
if (blockFromJsonArray(basal, dateUtil)?.any { it.amount < pumpDescription.basalMinimumRate || it.amount > 10.0 } != false) {
ToastUtils.errorToast(activity,resourceHelper.gs(R.string.error_in_basal_values))
return false
}
if (low?.any { it.amount < HardLimits.VERY_HARD_LIMIT_TARGET_BG[0].toDouble() || it.amount > HardLimits.VERY_HARD_LIMIT_TARGET_BG[1].toDouble() } != false) {
ToastUtils.errorToast(activity,resourceHelper.gs(R.string.error_in_target_values))
return false
}
if (high?.any { it.amount < HardLimits.VERY_HARD_LIMIT_TARGET_BG[0].toDouble() || it.amount > HardLimits.VERY_HARD_LIMIT_TARGET_BG[1].toDouble() } != false) {
ToastUtils.errorToast(activity,resourceHelper.gs(R.string.error_in_target_values))
return false
}
} else { } else {
if (low?.any { it.amount < Profile.fromMgdlToUnits(HardLimits.VERY_HARD_LIMIT_TARGET_BG[0].toDouble(), GlucoseUnit.MMOL) || it.amount > Profile.fromMgdlToUnits(HardLimits.VERY_HARD_LIMIT_TARGET_BG[1].toDouble(), GlucoseUnit.MMOL) } != false) return false if (blockFromJsonArray(isf, dateUtil)?.any { it.amount < Profile.fromMgdlToUnits(HardLimits.MIN_ISF, GlucoseUnit.MMOL) || it.amount > Profile.fromMgdlToUnits(HardLimits.MAX_ISF, GlucoseUnit.MMOL) } != false) {
if (high?.any { it.amount < Profile.fromMgdlToUnits(HardLimits.VERY_HARD_LIMIT_TARGET_BG[0].toDouble(), GlucoseUnit.MMOL) || it.amount > Profile.fromMgdlToUnits(HardLimits.VERY_HARD_LIMIT_TARGET_BG[1].toDouble(), GlucoseUnit.MMOL) } != false) return false ToastUtils.errorToast(activity,resourceHelper.gs(R.string.error_in_isf_values))
if (blockFromJsonArray(isf, dateUtil)?.any { it.amount < Profile.fromMgdlToUnits(HardLimits.MIN_ISF, GlucoseUnit.MMOL) || it.amount > Profile.fromMgdlToUnits(HardLimits.MAX_ISF, GlucoseUnit.MMOL) } != false) return false return false
}
if (blockFromJsonArray(basal, dateUtil)?.any { it.amount < pumpDescription.basalMinimumRate || it.amount > 10.0 } != false) {
ToastUtils.errorToast(activity,resourceHelper.gs(R.string.error_in_basal_values))
return false
}
if (low?.any { it.amount < Profile.fromMgdlToUnits(HardLimits.VERY_HARD_LIMIT_TARGET_BG[0].toDouble(), GlucoseUnit.MMOL) || it.amount > Profile.fromMgdlToUnits(HardLimits.VERY_HARD_LIMIT_TARGET_BG[1].toDouble(), GlucoseUnit.MMOL) } != false) {
ToastUtils.errorToast(activity,resourceHelper.gs(R.string.error_in_target_values))
return false
}
if (high?.any { it.amount < Profile.fromMgdlToUnits(HardLimits.VERY_HARD_LIMIT_TARGET_BG[0].toDouble(), GlucoseUnit.MMOL) || it.amount > Profile.fromMgdlToUnits(HardLimits.VERY_HARD_LIMIT_TARGET_BG[1].toDouble(), GlucoseUnit.MMOL) } != false) {
ToastUtils.errorToast(activity,resourceHelper.gs(R.string.error_in_target_values))
return false
}
}
for (i in low.indices) if (low[i].amount > high[i].amount) {
ToastUtils.errorToast(activity,resourceHelper.gs(R.string.error_in_target_values))
return false
} }
for (i in low.indices) if (low[i].amount > high[i].amount) return false
} }
return true return true
} }

View file

@ -1112,5 +1112,10 @@
<string name="sms_timeout_while_wating">Timeout while waiting for finish of previous pump communication</string> <string name="sms_timeout_while_wating">Timeout while waiting for finish of previous pump communication</string>
<string name="smscommunicator_another_bolus_in_queue">There is another bolus in queue. Try again later.</string> <string name="smscommunicator_another_bolus_in_queue">There is another bolus in queue. Try again later.</string>
<string name="calculation_in_progress">Calculation in progress</string> <string name="calculation_in_progress">Calculation in progress</string>
<string name="missing_profile_name">Missing profile name</string>
<string name="error_in_ic_values">Error in IC vaules</string>
<string name="error_in_basal_values">Error in basal values</string>
<string name="error_in_target_values">Error in target values</string>
<string name="error_in_isf_values">Error in ISF values</string>
</resources> </resources>