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 786b30f959..b113d180be 100644 --- a/app/src/main/java/info/nightscout/androidaps/activities/ProfileHelperActivity.kt +++ b/app/src/main/java/info/nightscout/androidaps/activities/ProfileHelperActivity.kt @@ -48,18 +48,21 @@ class ProfileHelperActivity : NoSplashAppCompatActivity() { return@setOnClickListener } profileFunction.getProfile()?.let { runningProfile -> - val profile = defaultProfile.profile(age, tdd, weight, profileFunction.getUnits()) - ProfileViewerDialog().also { pvd -> - pvd.arguments = Bundle().also { - it.putLong("time", DateUtil.now()) - it.putInt("mode", ProfileViewerDialog.Mode.PROFILE_COMPARE.ordinal) - it.putString("customProfile", runningProfile.data.toString()) - it.putString("customProfile2", profile.data.toString()) - it.putString("customProfileUnits", profile.units) - it.putString("customProfileName", "Age: $age TDD: $tdd Weight: $weight") - } - }.show(supportFragmentManager, "ProfileViewDialog") + defaultProfile.profile(age, tdd, weight, profileFunction.getUnits())?.let { profile -> + ProfileViewerDialog().also { pvd -> + pvd.arguments = Bundle().also { + it.putLong("time", DateUtil.now()) + it.putInt("mode", ProfileViewerDialog.Mode.PROFILE_COMPARE.ordinal) + it.putString("customProfile", runningProfile.data.toString()) + it.putString("customProfile2", profile.data.toString()) + it.putString("customProfileUnits", profile.units) + it.putString("customProfileName", "Age: $age TDD: $tdd Weight: $weight") + } + }.show(supportFragmentManager, "ProfileViewDialog") + return@setOnClickListener + } } + ToastUtils.showToastInUiThread(this, R.string.invalidinput) } } 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 2ca326d4a3..1d03ddb344 100644 --- a/app/src/main/java/info/nightscout/androidaps/activities/SurveyActivity.kt +++ b/app/src/main/java/info/nightscout/androidaps/activities/SurveyActivity.kt @@ -63,17 +63,18 @@ class SurveyActivity : NoSplashAppCompatActivity() { return@setOnClickListener } profileFunction.getProfile()?.let { runningProfile -> - val profile = defaultProfile.profile(age, tdd, weight, profileFunction.getUnits()) - ProfileViewerDialog().also { pvd -> - pvd.arguments = Bundle().also { - it.putLong("time", DateUtil.now()) - it.putInt("mode", ProfileViewerDialog.Mode.PROFILE_COMPARE.ordinal) - it.putString("customProfile", runningProfile.data.toString()) - it.putString("customProfile2", profile.data.toString()) - it.putString("customProfileUnits", profile.units) - it.putString("customProfileName", "Age: $age TDD: $tdd Weight: $weight") - } - }.show(supportFragmentManager, "ProfileViewDialog") + defaultProfile.profile(age, tdd, weight, profileFunction.getUnits())?.let { profile -> + ProfileViewerDialog().also { pvd -> + pvd.arguments = Bundle().also { + it.putLong("time", DateUtil.now()) + it.putInt("mode", ProfileViewerDialog.Mode.PROFILE_COMPARE.ordinal) + it.putString("customProfile", runningProfile.data.toString()) + it.putString("customProfile2", profile.data.toString()) + it.putString("customProfileUnits", profile.units) + it.putString("customProfileName", "Age: $age TDD: $tdd Weight: $weight") + } + }.show(supportFragmentManager, "ProfileViewDialog") + } } } diff --git a/core/src/main/java/info/nightscout/androidaps/data/defaultProfile/DefaultProfile.kt b/core/src/main/java/info/nightscout/androidaps/data/defaultProfile/DefaultProfile.kt index ecab21784c..00dd367f99 100644 --- a/core/src/main/java/info/nightscout/androidaps/data/defaultProfile/DefaultProfile.kt +++ b/core/src/main/java/info/nightscout/androidaps/data/defaultProfile/DefaultProfile.kt @@ -17,7 +17,7 @@ class DefaultProfile @Inject constructor(val injector: HasAndroidInjector) { var twelveToSeventeen: TreeMap> = TreeMap() var eighteenToTwentyfor: TreeMap> = TreeMap() - fun profile(age: Double, tdd: Double, weight: Double, units: String): Profile { + fun profile(age: Double, tdd: Double, weight: Double, units: String): Profile? { val profile = JSONObject() if (age >= 1 && age < 6) { val _tdd = if (tdd == 0.0) 0.6 * weight else tdd @@ -41,7 +41,7 @@ class DefaultProfile @Inject constructor(val injector: HasAndroidInjector) { val isf = Round.roundTo(100.0 / _tdd, 0.1) profile.put("sens", singleValueArray(isf, arrayOf(0.2, 0.0, 0.2, 0.2, 0.0, 0.2, 0.2))) } else if (age >= 18) { - + return null } profile.put("dia", 5.0) profile.put("carbs_hr", 20) // not used