prevent NPE

This commit is contained in:
Milos Kozak 2020-11-26 12:22:38 +01:00
parent 8ff9985b6e
commit 561ba72bf0
10 changed files with 10 additions and 10 deletions

View file

@ -58,7 +58,7 @@ class CalibrationDialog : DialogFragmentWithDate() {
val units = profileFunction.getUnits()
val unitLabel = if (units == Constants.MMOL) resourceHelper.gs(R.string.mmol) else resourceHelper.gs(R.string.mgdl)
val actions: LinkedList<String?> = LinkedList()
val bg = overview_calibration_bg.value
val bg = overview_calibration_bg?.value ?: return false
actions.add(resourceHelper.gs(R.string.treatments_wizard_bg_label) + ": " + Profile.toCurrentUnitsString(profileFunction, bg) + " " + unitLabel)
if (bg > 0) {
activity?.let { activity ->

View file

@ -150,7 +150,7 @@ class CarbsDialog : DialogFragmentWithDate() {
}
override fun submit(): Boolean {
val carbs = overview_carbs_carbs.value.toInt()
val carbs = overview_carbs_carbs?.value?.toInt() ?: return false
val carbsAfterConstraints = constraintChecker.applyCarbsConstraints(Constraint(carbs)).value()
val units = profileFunction.getUnits()
val activityTTDuration = defaultValueHelper.determineActivityTTDuration()

View file

@ -62,7 +62,7 @@ class ExtendedBolusDialog : DialogFragmentWithDate() {
}
override fun submit(): Boolean {
val insulin = SafeParse.stringToDouble(actions_extendedbolus_insulin.text)
val insulin = SafeParse.stringToDouble(actions_extendedbolus_insulin?.text ?: return false)
val durationInMinutes = actions_extendedbolus_duration.value.toInt()
val actions: LinkedList<String> = LinkedList()
val insulinAfterConstraint = constraintChecker.applyExtendedBolusConstraints(Constraint(insulin)).value()

View file

@ -85,7 +85,7 @@ class FillDialog : DialogFragmentWithDate() {
}
override fun submit(): Boolean {
val insulin = SafeParse.stringToDouble(fill_insulinamount.text)
val insulin = SafeParse.stringToDouble(fill_insulinamount?.text ?: return false)
val actions: LinkedList<String?> = LinkedList()
val insulinAfterConstraints = constraintChecker.applyBolusConstraints(Constraint(insulin)).value()

View file

@ -129,7 +129,7 @@ class InsulinDialog : DialogFragmentWithDate() {
override fun submit(): Boolean {
val pumpDescription = activePlugin.activePump.pumpDescription
val insulin = SafeParse.stringToDouble(overview_insulin_amount.text)
val insulin = SafeParse.stringToDouble(overview_insulin_amount?.text ?: return false)
val insulinAfterConstraints = constraintChecker.applyBolusConstraints(Constraint(insulin)).value()
val actions: LinkedList<String?> = LinkedList()
val units = profileFunction.getUnits()

View file

@ -91,7 +91,7 @@ class ProfileSwitchDialog : DialogFragmentWithDate() {
?: return false
val actions: LinkedList<String> = LinkedList()
val duration = overview_profileswitch_duration.value.toInt()
val duration = overview_profileswitch_duration?.value?.toInt() ?: return false
if (duration > 0)
actions.add(resourceHelper.gs(R.string.duration) + ": " + resourceHelper.gs(R.string.format_mins, duration))
val profile = overview_profileswitch_profile.selectedItem.toString()

View file

@ -84,7 +84,7 @@ class TempBasalDialog : DialogFragmentWithDate() {
override fun submit(): Boolean {
var percent = 0
var absolute = 0.0
val durationInMinutes = actions_tempbasal_duration.value.toInt()
val durationInMinutes = actions_tempbasal_duration?.value?.toInt() ?: return false
val profile = profileFunction.getProfile() ?: return false
val actions: LinkedList<String> = LinkedList()
if (isPercentPump) {

View file

@ -116,7 +116,7 @@ class TempTargetDialog : DialogFragmentWithDate() {
override fun submit(): Boolean {
val actions: LinkedList<String> = LinkedList()
val reason = overview_temptarget_reason.selectedItem.toString()
val reason = overview_temptarget_reason?.selectedItem?.toString() ?: return false
val unitResId = if (profileFunction.getUnits() == Constants.MGDL) R.string.mgdl else R.string.mmol
val target = overview_temptarget_temptarget.value
val duration = overview_temptarget_duration.value.toInt()

View file

@ -94,7 +94,7 @@ class TreatmentDialog : DialogFragmentWithDate() {
override fun submit(): Boolean {
val pumpDescription = activePlugin.activePump.pumpDescription
val insulin = SafeParse.stringToDouble(overview_treatment_insulin.text)
val insulin = SafeParse.stringToDouble(overview_treatment_insulin?.text ?: return false)
val carbs = SafeParse.stringToInt(overview_treatment_carbs.text)
val recordOnlyChecked = overview_treatment_record_only.isChecked
val actions: LinkedList<String?> = LinkedList()

View file

@ -113,7 +113,7 @@ class EditEventDialog : DialogFragmentWithDate() {
override fun submit(): Boolean {
// check for title
val title = automation_inputEventTitle.text.toString()
val title = automation_inputEventTitle?.text?.toString() ?: return false
if (title.isEmpty()) {
ToastUtils.showToastInUiThread(context, R.string.automation_missing_task_name)
return false