AndroidAPS/app/src/main/java/info/nightscout/androidaps/utils/DefaultValueHelper.kt

114 lines
4.1 KiB
Kotlin
Raw Normal View History

2019-12-20 13:58:51 +01:00
package info.nightscout.androidaps.utils
import info.nightscout.androidaps.Constants
import info.nightscout.androidaps.R
import info.nightscout.androidaps.data.Profile
2020-01-01 23:23:16 +01:00
import info.nightscout.androidaps.plugins.configBuilder.ProfileFunction
import info.nightscout.androidaps.utils.sharedPreferences.SP
import javax.inject.Inject
import javax.inject.Singleton
@Singleton
2020-01-11 15:19:46 +01:00
open class DefaultValueHelper @Inject constructor(
2020-01-01 23:23:16 +01:00
private val sp: SP,
private val profileFunction: ProfileFunction
) {
2019-12-20 13:58:51 +01:00
/**
* returns the corresponding EatingSoon TempTarget based on the given units (MMOL / MGDL)
*
* @param units
* @return
*/
2020-01-01 23:23:16 +01:00
private fun getDefaultEatingSoonTT(units: String): Double {
2019-12-20 13:58:51 +01:00
return if (Constants.MMOL == units) Constants.defaultEatingSoonTTmmol else Constants.defaultEatingSoonTTmgdl
}
/**
* returns the corresponding Activity TempTarget based on the given units (MMOL / MGDL)
*
* @param units
* @return
*/
2020-01-01 23:23:16 +01:00
private fun getDefaultActivityTT(units: String): Double {
2019-12-20 13:58:51 +01:00
return if (Constants.MMOL == units) Constants.defaultActivityTTmmol else Constants.defaultActivityTTmgdl
}
/**
* returns the corresponding Hypo TempTarget based on the given units (MMOL / MGDL)
*
* @param units
* @return
*/
2020-01-01 23:23:16 +01:00
private fun getDefaultHypoTT(units: String): Double {
2019-12-20 13:58:51 +01:00
return if (Constants.MMOL == units) Constants.defaultHypoTTmmol else Constants.defaultHypoTTmgdl
}
/**
* returns the configured EatingSoon TempTarget, if this is set to 0, the Default-Value is returned.
*
* @return
*/
fun determineEatingSoonTT(): Double {
2020-01-01 23:23:16 +01:00
val units = profileFunction.getUnits()
var value = sp.getDouble(R.string.key_eatingsoon_target, getDefaultEatingSoonTT(units))
2020-03-10 18:58:27 +01:00
value = Profile.toCurrentUnits(profileFunction, value)
2019-12-20 13:58:51 +01:00
return if (value > 0) value else getDefaultEatingSoonTT(units)
}
fun determineEatingSoonTTDuration(): Int {
2020-01-01 23:23:16 +01:00
val value = sp.getInt(R.string.key_eatingsoon_duration, Constants.defaultEatingSoonTTDuration)
2019-12-20 13:58:51 +01:00
return if (value > 0) value else Constants.defaultEatingSoonTTDuration
}
/**
* returns the configured Activity TempTarget, if this is set to 0, the Default-Value is returned.
*
* @return
*/
fun determineActivityTT(): Double {
2020-01-01 23:23:16 +01:00
val units = profileFunction.getUnits()
var value = sp.getDouble(R.string.key_activity_target, getDefaultActivityTT(units))
2020-03-10 18:58:27 +01:00
value = Profile.toCurrentUnits(profileFunction, value)
2019-12-20 13:58:51 +01:00
return if (value > 0) value else getDefaultActivityTT(units)
}
fun determineActivityTTDuration(): Int {
2020-01-01 23:23:16 +01:00
val value = sp.getInt(R.string.key_activity_duration, Constants.defaultActivityTTDuration)
2019-12-20 13:58:51 +01:00
return if (value > 0) value else Constants.defaultActivityTTDuration
}
/**
* returns the configured Hypo TempTarget, if this is set to 0, the Default-Value is returned.
*
* @return
*/
fun determineHypoTT(): Double {
2020-01-01 23:23:16 +01:00
val units = profileFunction.getUnits()
var value = sp.getDouble(R.string.key_hypo_target, getDefaultHypoTT(units))
2020-03-10 18:58:27 +01:00
value = Profile.toCurrentUnits(profileFunction, value)
2019-12-20 13:58:51 +01:00
return if (value > 0) value else getDefaultHypoTT(units)
}
fun determineHypoTTDuration(): Int {
2020-01-01 23:23:16 +01:00
val value = sp.getInt(R.string.key_hypo_duration, Constants.defaultHypoTTDuration)
2019-12-20 13:58:51 +01:00
return if (value > 0) value else Constants.defaultHypoTTDuration
}
2020-01-01 23:23:16 +01:00
var bgTargetLow = 80.0
var bgTargetHigh = 180.0
fun determineHighLine(): Double {
var highLineSetting = sp.getDouble(R.string.key_high_mark, bgTargetHigh)
if (highLineSetting < 1) highLineSetting = Constants.HIGHMARK
2020-03-10 18:58:27 +01:00
highLineSetting = Profile.toCurrentUnits(profileFunction, highLineSetting)
2020-01-01 23:23:16 +01:00
return highLineSetting
}
fun determineLowLine(): Double {
var lowLineSetting = sp.getDouble(R.string.key_low_mark, bgTargetLow)
if (lowLineSetting < 1) lowLineSetting = Constants.LOWMARK
2020-03-10 18:58:27 +01:00
lowLineSetting = Profile.toCurrentUnits(profileFunction, lowLineSetting)
2020-01-01 23:23:16 +01:00
return lowLineSetting
}
2019-12-20 13:58:51 +01:00
}