check for input data

This commit is contained in:
Milos Kozak 2020-07-09 18:48:28 +02:00
parent 4b967d237c
commit f39df8e8eb
3 changed files with 28 additions and 24 deletions

View file

@ -48,18 +48,21 @@ class ProfileHelperActivity : NoSplashAppCompatActivity() {
return@setOnClickListener return@setOnClickListener
} }
profileFunction.getProfile()?.let { runningProfile -> profileFunction.getProfile()?.let { runningProfile ->
val profile = defaultProfile.profile(age, tdd, weight, profileFunction.getUnits()) defaultProfile.profile(age, tdd, weight, profileFunction.getUnits())?.let { profile ->
ProfileViewerDialog().also { pvd -> ProfileViewerDialog().also { pvd ->
pvd.arguments = Bundle().also { pvd.arguments = Bundle().also {
it.putLong("time", DateUtil.now()) it.putLong("time", DateUtil.now())
it.putInt("mode", ProfileViewerDialog.Mode.PROFILE_COMPARE.ordinal) it.putInt("mode", ProfileViewerDialog.Mode.PROFILE_COMPARE.ordinal)
it.putString("customProfile", runningProfile.data.toString()) it.putString("customProfile", runningProfile.data.toString())
it.putString("customProfile2", profile.data.toString()) it.putString("customProfile2", profile.data.toString())
it.putString("customProfileUnits", profile.units) it.putString("customProfileUnits", profile.units)
it.putString("customProfileName", "Age: $age TDD: $tdd Weight: $weight") it.putString("customProfileName", "Age: $age TDD: $tdd Weight: $weight")
} }
}.show(supportFragmentManager, "ProfileViewDialog") }.show(supportFragmentManager, "ProfileViewDialog")
return@setOnClickListener
}
} }
ToastUtils.showToastInUiThread(this, R.string.invalidinput)
} }
} }

View file

@ -63,17 +63,18 @@ class SurveyActivity : NoSplashAppCompatActivity() {
return@setOnClickListener return@setOnClickListener
} }
profileFunction.getProfile()?.let { runningProfile -> profileFunction.getProfile()?.let { runningProfile ->
val profile = defaultProfile.profile(age, tdd, weight, profileFunction.getUnits()) defaultProfile.profile(age, tdd, weight, profileFunction.getUnits())?.let { profile ->
ProfileViewerDialog().also { pvd -> ProfileViewerDialog().also { pvd ->
pvd.arguments = Bundle().also { pvd.arguments = Bundle().also {
it.putLong("time", DateUtil.now()) it.putLong("time", DateUtil.now())
it.putInt("mode", ProfileViewerDialog.Mode.PROFILE_COMPARE.ordinal) it.putInt("mode", ProfileViewerDialog.Mode.PROFILE_COMPARE.ordinal)
it.putString("customProfile", runningProfile.data.toString()) it.putString("customProfile", runningProfile.data.toString())
it.putString("customProfile2", profile.data.toString()) it.putString("customProfile2", profile.data.toString())
it.putString("customProfileUnits", profile.units) it.putString("customProfileUnits", profile.units)
it.putString("customProfileName", "Age: $age TDD: $tdd Weight: $weight") it.putString("customProfileName", "Age: $age TDD: $tdd Weight: $weight")
} }
}.show(supportFragmentManager, "ProfileViewDialog") }.show(supportFragmentManager, "ProfileViewDialog")
}
} }
} }

View file

@ -17,7 +17,7 @@ class DefaultProfile @Inject constructor(val injector: HasAndroidInjector) {
var twelveToSeventeen: TreeMap<Double, Array<Double>> = TreeMap() var twelveToSeventeen: TreeMap<Double, Array<Double>> = TreeMap()
var eighteenToTwentyfor: TreeMap<Double, Array<Double>> = TreeMap() var eighteenToTwentyfor: TreeMap<Double, Array<Double>> = 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() val profile = JSONObject()
if (age >= 1 && age < 6) { if (age >= 1 && age < 6) {
val _tdd = if (tdd == 0.0) 0.6 * weight else tdd 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) 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))) profile.put("sens", singleValueArray(isf, arrayOf(0.2, 0.0, 0.2, 0.2, 0.0, 0.2, 0.2)))
} else if (age >= 18) { } else if (age >= 18) {
return null
} }
profile.put("dia", 5.0) profile.put("dia", 5.0)
profile.put("carbs_hr", 20) // not used profile.put("carbs_hr", 20) // not used