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

114 lines
4 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
class DefaultValueHelper @Inject constructor(
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))
2019-12-20 13:58:51 +01:00
value = Profile.toCurrentUnits(value)
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))
2019-12-20 13:58:51 +01:00
value = Profile.toCurrentUnits(value)
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))
2019-12-20 13:58:51 +01:00
value = Profile.toCurrentUnits(value)
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
highLineSetting = Profile.toCurrentUnits(highLineSetting)
return highLineSetting
}
fun determineLowLine(): Double {
var lowLineSetting = sp.getDouble(R.string.key_low_mark, bgTargetLow)
if (lowLineSetting < 1) lowLineSetting = Constants.LOWMARK
lowLineSetting = Profile.toCurrentUnits(lowLineSetting)
return lowLineSetting
}
2019-12-20 13:58:51 +01:00
}