diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/general/actions/ActionsFragment.kt b/app/src/main/java/info/nightscout/androidaps/plugins/general/actions/ActionsFragment.kt index 6c4432c0a8..9e80d9d331 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/general/actions/ActionsFragment.kt +++ b/app/src/main/java/info/nightscout/androidaps/plugins/general/actions/ActionsFragment.kt @@ -240,7 +240,7 @@ class ActionsFragment : DaggerFragment() { actions_temptarget?.visibility = Config.APS.toVisibility() actions_tddstats?.visibility = pump.pumpDescription.supportsTDDs.toVisibility() - statusLightHandler.updateAge(careportal_sensorage, careportal_insulinage, careportal_canulaage, careportal_pbage) + statusLightHandler.updateStatusLights(careportal_canulaage, careportal_insulinage, null, careportal_sensorage, careportal_pbage, null) checkPumpCustomActions() } diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/general/careportal/CareportalFragment.kt b/app/src/main/java/info/nightscout/androidaps/plugins/general/careportal/CareportalFragment.kt index 876a067ac4..12f1bdbeb8 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/general/careportal/CareportalFragment.kt +++ b/app/src/main/java/info/nightscout/androidaps/plugins/general/careportal/CareportalFragment.kt @@ -133,6 +133,6 @@ class CareportalFragment : DaggerFragment(), View.OnClickListener { } private fun updateGUI() { - statusLightHandler.updateAge(careportal_sensorage, careportal_insulinage, careportal_canulaage, careportal_pbage) + statusLightHandler.updateStatusLights(careportal_canulaage, careportal_insulinage, null, careportal_sensorage, careportal_pbage, null) } } \ No newline at end of file diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/general/nsclient/NSClientPlugin.java b/app/src/main/java/info/nightscout/androidaps/plugins/general/nsclient/NSClientPlugin.java index 8c6480ea86..61975db049 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/general/nsclient/NSClientPlugin.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/general/nsclient/NSClientPlugin.java @@ -192,7 +192,6 @@ public class NSClientPlugin extends PluginBase { scrnAdvancedSettings.removePreference(preferenceFragment.findPreference(resourceHelper.gs(R.string.key_statuslights_bat_warning))); scrnAdvancedSettings.removePreference(preferenceFragment.findPreference(resourceHelper.gs(R.string.key_statuslights_bat_critical))); scrnAdvancedSettings.removePreference(preferenceFragment.findPreference(resourceHelper.gs(R.string.key_show_statuslights))); - scrnAdvancedSettings.removePreference(preferenceFragment.findPreference(resourceHelper.gs(R.string.key_show_statuslights_extended))); } } } diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/general/overview/OverviewFragment.kt b/app/src/main/java/info/nightscout/androidaps/plugins/general/overview/OverviewFragment.kt index d56d8d9afe..e67d31e773 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/general/overview/OverviewFragment.kt +++ b/app/src/main/java/info/nightscout/androidaps/plugins/general/overview/OverviewFragment.kt @@ -68,8 +68,13 @@ import info.nightscout.androidaps.utils.wizard.QuickWizard import io.reactivex.android.schedulers.AndroidSchedulers import io.reactivex.disposables.CompositeDisposable import io.reactivex.schedulers.Schedulers -import kotlinx.android.synthetic.main.careportal_stats_fragment.* import kotlinx.android.synthetic.main.overview_fragment.* +import kotlinx.android.synthetic.main.overview_fragment.careportal_canulaage +import kotlinx.android.synthetic.main.overview_fragment.careportal_insulinage +import kotlinx.android.synthetic.main.overview_fragment.careportal_reservoirlevel +import kotlinx.android.synthetic.main.overview_fragment.careportal_sensorage +import kotlinx.android.synthetic.main.overview_fragment.careportal_pbage +import kotlinx.android.synthetic.main.overview_fragment.careportal_batterylevel import kotlinx.android.synthetic.main.overview_fragment.overview_activeprofile import kotlinx.android.synthetic.main.overview_fragment.overview_apsmode import kotlinx.android.synthetic.main.overview_fragment.overview_arrow @@ -714,15 +719,9 @@ class OverviewFragment : DaggerFragment(), View.OnClickListener, OnLongClickList } } - // NSClient mode - statusLightHandler.updateAge(careportal_sensorage, careportal_insulinage, careportal_canulaage, careportal_pbage) - // Mode modes - if (sp.getBoolean(R.string.key_show_statuslights, false)) { - if (sp.getBoolean(R.string.key_show_statuslights_extended, false)) - statusLightHandler.extendedStatusLight(overview_canulaage, overview_insulinage, overview_reservoirlevel, overview_sensorage, overview_batterylevel) - else - statusLightHandler.statusLight(overview_canulaage, overview_insulinage, overview_reservoirlevel, overview_sensorage, overview_batterylevel) - } + // Status lights + overview_statuslights?.visibility = (sp.getBoolean(R.string.key_show_statuslights, false) || Config.NSCLIENT).toVisibility() + statusLightHandler.updateStatusLights(careportal_canulaage, careportal_insulinage, careportal_reservoirlevel, careportal_sensorage, careportal_pbage, careportal_batterylevel) // cob var cobText: String = resourceHelper.gs(R.string.value_unavailable_short) @@ -755,7 +754,7 @@ class OverviewFragment : DaggerFragment(), View.OnClickListener, OnLongClickList // ****** GRAPH ******* GlobalScope.launch(Dispatchers.Main) { - overview_bggraph?: return@launch + overview_bggraph ?: return@launch val graphData = GraphData(injector, overview_bggraph, iobCobCalculatorPlugin) val secondaryGraphsData: ArrayList = ArrayList() diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/general/overview/StatusLightHandler.kt b/app/src/main/java/info/nightscout/androidaps/plugins/general/overview/StatusLightHandler.kt index 79b1c80ba1..ca779f0031 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/general/overview/StatusLightHandler.kt +++ b/app/src/main/java/info/nightscout/androidaps/plugins/general/overview/StatusLightHandler.kt @@ -1,9 +1,7 @@ package info.nightscout.androidaps.plugins.general.overview -import android.graphics.Color -import android.view.View import android.widget.TextView -import androidx.arch.core.util.Function +import info.nightscout.androidaps.Config import info.nightscout.androidaps.MainApp import info.nightscout.androidaps.R import info.nightscout.androidaps.db.CareportalEvent @@ -11,7 +9,7 @@ import info.nightscout.androidaps.interfaces.ActivePluginProvider import info.nightscout.androidaps.plugins.general.nsclient.data.NSSettingsStatus import info.nightscout.androidaps.plugins.pump.common.defs.PumpType import info.nightscout.androidaps.utils.DecimalFormatter -import info.nightscout.androidaps.utils.SetWarnColor +import info.nightscout.androidaps.utils.WarnColors import info.nightscout.androidaps.utils.resources.ResourceHelper import info.nightscout.androidaps.utils.sharedPreferences.SP import javax.inject.Inject @@ -22,151 +20,42 @@ class StatusLightHandler @Inject constructor( private val nsSettingsStatus: NSSettingsStatus, private val resourceHelper: ResourceHelper, private val sp: SP, - private val activePlugin: ActivePluginProvider + private val activePlugin: ActivePluginProvider, + private val warnColors: WarnColors ) { - /** - * applies the statusLight subview on the overview fragment - */ - fun statusLight(cageView: TextView?, iAgeView: TextView?, reservoirView: TextView?, - sageView: TextView?, batteryView: TextView?) { - val pump = activePlugin.activePump - applyStatusLight("cage", CareportalEvent.SITECHANGE, cageView, "CAN", 48, 72) - applyStatusLight("iage", CareportalEvent.INSULINCHANGE, iAgeView, "INS", 72, 96) - val reservoirLevel = if (pump.isInitialized) pump.reservoirLevel else (-1).toDouble() - applyStatusLightLevel(R.string.key_statuslights_res_critical, 10.0, - R.string.key_statuslights_res_warning, 80.0, reservoirView, "RES", reservoirLevel) - applyStatusLight("sage", CareportalEvent.SENSORCHANGE, sageView, "SEN", 164, 166) - if (pump.model() != PumpType.AccuChekCombo) { - val batteryLevel = if (pump.isInitialized) pump.batteryLevel.toDouble() else -1.0 - applyStatusLightLevel(R.string.key_statuslights_bat_critical, 5.0, - R.string.key_statuslights_bat_warning, 22.0, - batteryView, "BAT", batteryLevel) - } else { - applyStatusLight("bage", CareportalEvent.PUMPBATTERYCHANGE, batteryView, "BAT", 224, 336) - } - } - - private fun applyStatusLight(nsSettingPlugin: String?, eventName: String?, view: TextView?, text: String?, - defaultWarnThreshold: Int, defaultUrgentThreshold: Int) { - if (view != null) { - val urgent = nsSettingsStatus.getExtendedWarnValue(nsSettingPlugin!!, "urgent", defaultUrgentThreshold.toDouble()) - val warn = nsSettingsStatus.getExtendedWarnValue(nsSettingPlugin, "warn", defaultWarnThreshold.toDouble()) - val event = MainApp.getDbHelper().getLastCareportalEvent(eventName) - val age = event?.hoursFromStart ?: Double.MAX_VALUE - applyStatusLight(view, text, age, warn, urgent, Double.MAX_VALUE, true) - } - } - - private fun applyStatusLightLevel(criticalSetting: Int, criticalDefaultValue: Double, - warnSetting: Int, warnDefaultValue: Double, - view: TextView?, text: String?, level: Double) { - if (view != null) { - val resUrgent = sp.getDouble(criticalSetting, criticalDefaultValue) - val resWarn = sp.getDouble(warnSetting, warnDefaultValue) - applyStatusLight(view, text, level, resWarn, resUrgent, -1.0, false) - } - } - - private fun applyStatusLight(view: TextView, text: String?, value: Double, warnThreshold: Double, - urgentThreshold: Double, invalid: Double, checkAscending: Boolean) { - val check = - if (checkAscending) Function { threshold: Double -> value >= threshold } - else Function { threshold: Double -> value <= threshold } - if (value != invalid) { - view.text = text - when { - check.apply(urgentThreshold) -> view.setTextColor(resourceHelper.gc(R.color.ribbonCritical)) - check.apply(warnThreshold) -> view.setTextColor(resourceHelper.gc(R.color.ribbonWarning)) - else -> view.setTextColor(resourceHelper.gc(R.color.ribbonDefault)) - } - view.visibility = View.VISIBLE - } else { - view.visibility = View.GONE - } - } - /** * applies the extended statusLight subview on the overview fragment */ - fun extendedStatusLight(cageView: TextView?, iAgeView: TextView?, - reservoirView: TextView?, sageView: TextView?, - batteryView: TextView?) { + fun updateStatusLights(careportal_canulaage: TextView?, careportal_insulinage: TextView?, careportal_reservoirlevel: TextView?, careportal_sensorage: TextView?, careportal_pbage: TextView?, careportal_batterylevel: TextView?) { val pump = activePlugin.activePump - handleAge("cage", CareportalEvent.SITECHANGE, cageView, "CAN ", - 48, 72) - handleAge("iage", CareportalEvent.INSULINCHANGE, iAgeView, "INS ", - 72, 96) - handleLevel(R.string.key_statuslights_res_critical, 10.0, - R.string.key_statuslights_res_warning, 80.0, - reservoirView, "RES ", pump.reservoirLevel) - handleAge("sage", CareportalEvent.SENSORCHANGE, sageView, "SEN ", - 164, 166) - if (pump.model() != PumpType.AccuChekCombo) { - handleLevel(R.string.key_statuslights_bat_critical, 26.0, - R.string.key_statuslights_bat_warning, 51.0, - batteryView, "BAT ", pump.batteryLevel.toDouble()) - } else { - handleAge("bage", CareportalEvent.PUMPBATTERYCHANGE, batteryView, "BAT ", - 224, 336) - } + handleAge(careportal_canulaage, "cage", CareportalEvent.SITECHANGE, 48.0, 72.0) + handleAge(careportal_insulinage, "iage", CareportalEvent.INSULINCHANGE, 72.0, 96.0) + handleAge(careportal_sensorage, "sage", CareportalEvent.SENSORCHANGE, 164.0, 166.0) + handleAge(careportal_pbage, "bage", CareportalEvent.PUMPBATTERYCHANGE, 224.0, 336.0) + if (!Config.NSCLIENT) + handleLevel(careportal_reservoirlevel, R.string.key_statuslights_res_critical, 10.0, R.string.key_statuslights_res_warning, 80.0, pump.reservoirLevel) + if (!Config.NSCLIENT && pump.model() != PumpType.AccuChekCombo) + handleLevel(careportal_batterylevel, R.string.key_statuslights_bat_critical, 26.0, R.string.key_statuslights_bat_warning, 51.0, pump.batteryLevel.toDouble()) } - private fun handleAge(nsSettingPlugin: String, eventName: String, view: TextView?, text: String, - defaultWarnThreshold: Int, defaultUrgentThreshold: Int) { - val urgent = nsSettingsStatus.getExtendedWarnValue(nsSettingPlugin, "urgent", defaultUrgentThreshold.toDouble()) - val warn = nsSettingsStatus.getExtendedWarnValue(nsSettingPlugin, "warn", defaultWarnThreshold.toDouble()) - handleAge(view, text, eventName, warn, urgent) - } - - private fun handleLevel(criticalSetting: Int, criticalDefaultValue: Double, - warnSetting: Int, warnDefaultValue: Double, - view: TextView?, text: String, level: Double) { - if (view != null) { - val resUrgent = sp.getDouble(criticalSetting, criticalDefaultValue) - val resWarn = sp.getDouble(warnSetting, warnDefaultValue) - @Suppress("SetTextI18n") - view.text = text + DecimalFormatter.to0Decimal(level) - SetWarnColor.setColorInverse(view, level, resWarn, resUrgent) - } - } - - private fun handleAge(age: TextView?, eventType: String, warnThreshold: Double, urgentThreshold: Double) = - handleAge(age, "", eventType, warnThreshold, urgentThreshold) - - fun handleAge(age: TextView?, prefix: String, eventType: String, warnThreshold: Double, urgentThreshold: Double) { - val notavailable = if (resourceHelper.shortTextMode()) "-" else resourceHelper.gs(R.string.notavailable) - val careportalEvent = MainApp.getDbHelper().getLastCareportalEvent(eventType) + private fun handleAge(view: TextView?, nsSettingPlugin: String, eventName: String, defaultWarnThreshold: Double, defaultUrgentThreshold: Double) { + val urgent = nsSettingsStatus.getExtendedWarnValue(nsSettingPlugin, "urgent", defaultUrgentThreshold) + val warn = nsSettingsStatus.getExtendedWarnValue(nsSettingPlugin, "warn", defaultWarnThreshold) + val careportalEvent = MainApp.getDbHelper().getLastCareportalEvent(eventName) if (careportalEvent != null) { - age?.setTextColor(determineTextColor(careportalEvent, warnThreshold, urgentThreshold)) - age?.text = prefix + careportalEvent.age(resourceHelper.shortTextMode()) + warnColors.setColorByAge(view, careportalEvent, warn, urgent) + view?.text = careportalEvent.age(resourceHelper.shortTextMode()) } else { - age?.text = notavailable + view?.text = if (resourceHelper.shortTextMode()) "-" else resourceHelper.gs(R.string.notavailable) } } - fun updateAge(sage: TextView?, iage: TextView?, cage: TextView?, pbage: TextView?) { - val iageUrgent = nsSettingsStatus.getExtendedWarnValue("iage", "urgent", 96.0) - val iageWarn = nsSettingsStatus.getExtendedWarnValue("iage", "warn", 72.0) - handleAge(iage, CareportalEvent.INSULINCHANGE, iageWarn, iageUrgent) - val cageUrgent = nsSettingsStatus.getExtendedWarnValue("cage", "urgent", 72.0) - val cageWarn = nsSettingsStatus.getExtendedWarnValue("cage", "warn", 48.0) - handleAge(cage, CareportalEvent.SITECHANGE, cageWarn, cageUrgent) - val sageUrgent = nsSettingsStatus.getExtendedWarnValue("sage", "urgent", 166.0) - val sageWarn = nsSettingsStatus.getExtendedWarnValue("sage", "warn", 164.0) - handleAge(sage, CareportalEvent.SENSORCHANGE, sageWarn, sageUrgent) - val pbageUrgent = nsSettingsStatus.getExtendedWarnValue("bage", "urgent", 360.0) - val pbageWarn = nsSettingsStatus.getExtendedWarnValue("bage", "warn", 240.0) - handleAge(pbage, CareportalEvent.PUMPBATTERYCHANGE, pbageWarn, pbageUrgent) - } - - fun determineTextColor(careportalEvent: CareportalEvent, warnThreshold: Double, urgentThreshold: Double): Int { - return if (careportalEvent.isOlderThan(urgentThreshold)) { - resourceHelper.gc(R.color.low) - } else if (careportalEvent.isOlderThan(warnThreshold)) { - resourceHelper.gc(R.color.high) - } else { - Color.WHITE - } + private fun handleLevel(view: TextView?, criticalSetting: Int, criticalDefaultValue: Double, warnSetting: Int, warnDefaultValue: Double, level: Double) { + val resUrgent = sp.getDouble(criticalSetting, criticalDefaultValue) + val resWarn = sp.getDouble(warnSetting, warnDefaultValue) + @Suppress("SetTextI18n") + view?.text = DecimalFormatter.to0Decimal(level) + warnColors.setColorInverse(view, level, resWarn, resUrgent) } } \ No newline at end of file diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaR/DanaRFragment.kt b/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaR/DanaRFragment.kt index 2e7104c9e1..60420d6d70 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaR/DanaRFragment.kt +++ b/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaR/DanaRFragment.kt @@ -27,8 +27,8 @@ import info.nightscout.androidaps.plugins.pump.danaRKorean.DanaRKoreanPlugin import info.nightscout.androidaps.queue.events.EventQueueChanged import info.nightscout.androidaps.utils.DateUtil import info.nightscout.androidaps.utils.FabricPrivacy -import info.nightscout.androidaps.utils.SetWarnColor import info.nightscout.androidaps.utils.T +import info.nightscout.androidaps.utils.WarnColors import info.nightscout.androidaps.utils.extensions.plusAssign import info.nightscout.androidaps.utils.resources.ResourceHelper import io.reactivex.android.schedulers.AndroidSchedulers @@ -45,6 +45,7 @@ class DanaRFragment : DaggerFragment() { @Inject lateinit var danaRKoreanPlugin: DanaRKoreanPlugin @Inject lateinit var danaRPump: DanaRPump @Inject lateinit var resourceHelper: ResourceHelper + @Inject lateinit var warnColors: WarnColors private var disposable: CompositeDisposable = CompositeDisposable() @@ -157,7 +158,7 @@ class DanaRFragment : DaggerFragment() { val agoMsec = System.currentTimeMillis() - pump.lastConnection val agoMin = (agoMsec.toDouble() / 60.0 / 1000.0).toInt() danar_lastconnection.text = DateUtil.timeString(pump.lastConnection) + " (" + resourceHelper.gs(R.string.minago, agoMin) + ")" - SetWarnColor.setColor(danar_lastconnection, agoMin.toDouble(), 16.0, 31.0) + warnColors.setColor(danar_lastconnection, agoMin.toDouble(), 16.0, 31.0) } if (pump.lastBolusTime != 0L) { val agoMsec = System.currentTimeMillis() - pump.lastBolusTime @@ -170,7 +171,7 @@ class DanaRFragment : DaggerFragment() { } danar_dailyunits.text = resourceHelper.gs(R.string.reservoirvalue, pump.dailyTotalUnits, pump.maxDailyTotalUnits) - SetWarnColor.setColor(danar_dailyunits, pump.dailyTotalUnits, pump.maxDailyTotalUnits * 0.75, pump.maxDailyTotalUnits * 0.9) + warnColors.setColor(danar_dailyunits, pump.dailyTotalUnits, pump.maxDailyTotalUnits * 0.75, pump.maxDailyTotalUnits * 0.9) danar_basabasalrate.text = "( " + (pump.activeProfile + 1) + " ) " + resourceHelper.gs(R.string.pump_basebasalrate, plugin.baseBasalRate) // DanaRPlugin, DanaRKoreanPlugin if (activePlugin.activePump.isFakingTempsByExtendedBoluses == true) { @@ -184,9 +185,9 @@ class DanaRFragment : DaggerFragment() { danar_extendedbolus.text = activePlugin.activeTreatments.getExtendedBolusFromHistory(System.currentTimeMillis())?.toString() ?: "" danar_reservoir.text = resourceHelper.gs(R.string.reservoirvalue, pump.reservoirRemainingUnits, 300) - SetWarnColor.setColorInverse(danar_reservoir, pump.reservoirRemainingUnits, 50.0, 20.0) + warnColors.setColorInverse(danar_reservoir, pump.reservoirRemainingUnits, 50.0, 20.0) danar_battery.text = "{fa-battery-" + pump.batteryRemaining / 25 + "}" - SetWarnColor.setColorInverse(danar_battery, pump.batteryRemaining.toDouble(), 51.0, 26.0) + warnColors.setColorInverse(danar_battery, pump.batteryRemaining.toDouble(), 51.0, 26.0) danar_iob.text = resourceHelper.gs(R.string.formatinsulinunits, pump.iob) if (pump.model != 0 || pump.protocol != 0 || pump.productCode != 0) { danar_firmware.text = resourceHelper.gs(R.string.danar_model, pump.model, pump.protocol, pump.productCode) diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/pump/medtronic/MedtronicFragment.kt b/app/src/main/java/info/nightscout/androidaps/plugins/pump/medtronic/MedtronicFragment.kt index 62999798ba..7237dab948 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/pump/medtronic/MedtronicFragment.kt +++ b/app/src/main/java/info/nightscout/androidaps/plugins/pump/medtronic/MedtronicFragment.kt @@ -38,8 +38,8 @@ import info.nightscout.androidaps.queue.events.EventQueueChanged import info.nightscout.androidaps.utils.DateUtil import info.nightscout.androidaps.utils.FabricPrivacy import info.nightscout.androidaps.utils.alertDialogs.OKDialog -import info.nightscout.androidaps.utils.SetWarnColor import info.nightscout.androidaps.utils.T +import info.nightscout.androidaps.utils.WarnColors import info.nightscout.androidaps.utils.extensions.plusAssign import info.nightscout.androidaps.utils.resources.ResourceHelper import io.reactivex.android.schedulers.AndroidSchedulers @@ -56,6 +56,7 @@ class MedtronicFragment : DaggerFragment() { @Inject lateinit var commandQueue: CommandQueueProvider @Inject lateinit var activePlugin: ActivePluginProvider @Inject lateinit var medtronicPumpPlugin: MedtronicPumpPlugin + @Inject lateinit var warnColors: WarnColors private var disposable: CompositeDisposable = CompositeDisposable() @@ -325,11 +326,11 @@ class MedtronicFragment : DaggerFragment() { } else { medtronic_pumpstate_battery.text = "{fa-battery-" + pumpStatus.batteryRemaining / 25 + "} " + pumpStatus.batteryRemaining + "%" + String.format(" (%.2f V)", pumpStatus.batteryVoltage) } - SetWarnColor.setColorInverse(medtronic_pumpstate_battery, pumpStatus.batteryRemaining.toDouble(), 25.0, 10.0) + warnColors.setColorInverse(medtronic_pumpstate_battery, pumpStatus.batteryRemaining.toDouble(), 25.0, 10.0) // reservoir medtronic_reservoir.text = resourceHelper.gs(R.string.reservoirvalue, pumpStatus.reservoirRemainingUnits, pumpStatus.reservoirFullUnits) - SetWarnColor.setColorInverse(medtronic_reservoir, pumpStatus.reservoirRemainingUnits, 50.0, 20.0) + warnColors.setColorInverse(medtronic_reservoir, pumpStatus.reservoirRemainingUnits, 50.0, 20.0) medtronic_errors.text = pumpStatus.errorInfo } diff --git a/app/src/main/java/info/nightscout/androidaps/utils/SetWarnColor.java b/app/src/main/java/info/nightscout/androidaps/utils/SetWarnColor.java deleted file mode 100644 index e22197d83f..0000000000 --- a/app/src/main/java/info/nightscout/androidaps/utils/SetWarnColor.java +++ /dev/null @@ -1,25 +0,0 @@ -package info.nightscout.androidaps.utils; - -import android.graphics.Color; -import android.widget.TextView; - -/** - * Created by mike on 08.07.2016. - */ -public class SetWarnColor { - static final int normalColor = Color.WHITE; - static final int warnColor = Color.YELLOW; - static final int urgentColor = Color.RED; - - public static void setColor(TextView view, double value, double warnLevel, double urgentLevel) { - if (value >= urgentLevel) view.setTextColor(urgentColor); - else if (value >= warnLevel) view.setTextColor(warnColor); - else view.setTextColor(normalColor); - } - - public static void setColorInverse(TextView view, double value, double warnLevel, double urgentLevel) { - if (value <= urgentLevel) view.setTextColor(urgentColor); - else if (value <= warnLevel) view.setTextColor(warnColor); - else view.setTextColor(normalColor); - } -} diff --git a/app/src/main/java/info/nightscout/androidaps/utils/SetWarnColor.kt b/app/src/main/java/info/nightscout/androidaps/utils/SetWarnColor.kt new file mode 100644 index 0000000000..fd375ad1cc --- /dev/null +++ b/app/src/main/java/info/nightscout/androidaps/utils/SetWarnColor.kt @@ -0,0 +1,38 @@ +package info.nightscout.androidaps.utils + +import android.graphics.Color +import android.widget.TextView +import info.nightscout.androidaps.R +import info.nightscout.androidaps.db.CareportalEvent +import info.nightscout.androidaps.utils.resources.ResourceHelper +import javax.inject.Inject +import javax.inject.Singleton + +@Singleton +class WarnColors @Inject constructor(val resourceHelper: ResourceHelper) { + + private val normalColor = Color.WHITE + private val warnColor = Color.YELLOW + private val urgentColor = Color.RED + + fun setColor(view: TextView?, value: Double, warnLevel: Double, urgentLevel: Double) = + view?.setTextColor(when { + value >= urgentLevel -> urgentColor + value >= warnLevel -> warnColor + else -> normalColor + }) + + fun setColorInverse(view: TextView?, value: Double, warnLevel: Double, urgentLevel: Double) = + view?.setTextColor(when { + value <= urgentLevel -> urgentColor + value <= warnLevel -> warnColor + else -> normalColor + }) + + fun setColorByAge(view: TextView?, careportalEvent: CareportalEvent, warnThreshold: Double, urgentThreshold: Double) = + view?.setTextColor(when { + careportalEvent.isOlderThan(urgentThreshold) -> resourceHelper.gc(R.color.low) + careportalEvent.isOlderThan(warnThreshold) -> resourceHelper.gc(R.color.high) + else -> Color.WHITE + }) +} \ No newline at end of file diff --git a/app/src/main/java/info/nightscout/androidaps/utils/resources/ResourceHelperImplementation.kt b/app/src/main/java/info/nightscout/androidaps/utils/resources/ResourceHelperImplementation.kt index f398534039..0773b8a859 100644 --- a/app/src/main/java/info/nightscout/androidaps/utils/resources/ResourceHelperImplementation.kt +++ b/app/src/main/java/info/nightscout/androidaps/utils/resources/ResourceHelperImplementation.kt @@ -42,21 +42,19 @@ class ResourceHelperImplementation @Inject constructor(private val context: Cont override fun openRawResourceFd(id: Int): AssetFileDescriptor = context.resources.openRawResourceFd(id) - override fun getIcon(): Int { - return when { + override fun getIcon(): Int = + when { Config.NSCLIENT -> R.mipmap.ic_yellowowl Config.PUMPCONTROL -> R.mipmap.ic_pumpcontrol else -> R.mipmap.ic_launcher } - } - override fun getNotificationIcon(): Int { - return when { + override fun getNotificationIcon(): Int = + when { Config.NSCLIENT -> R.drawable.ic_notif_nsclient Config.PUMPCONTROL -> R.drawable.ic_notif_pumpcontrol else -> R.drawable.ic_notif_aaps } - } override fun decodeResource(id: Int): Bitmap = BitmapFactory.decodeResource(context.resources, id) @@ -69,5 +67,5 @@ class ResourceHelperImplementation @Inject constructor(private val context: Cont return (dp * scale + 0.5f).toInt() } - override fun shortTextMode() : Boolean = !gb(R.bool.isTablet) && Config.NSCLIENT + override fun shortTextMode() : Boolean = !gb(R.bool.isTablet) } \ No newline at end of file diff --git a/app/src/main/res/layout/overview_fragment.xml b/app/src/main/res/layout/overview_fragment.xml index 64e32cf747..78b83dd30f 100644 --- a/app/src/main/res/layout/overview_fragment.xml +++ b/app/src/main/res/layout/overview_fragment.xml @@ -363,58 +363,113 @@ + + + + + + + + + + + + + + - - - - diff --git a/app/src/main/res/layout/overview_fragment_landscape.xml b/app/src/main/res/layout/overview_fragment_landscape.xml index cea0f76d21..a2a4eb2b4d 100644 --- a/app/src/main/res/layout/overview_fragment_landscape.xml +++ b/app/src/main/res/layout/overview_fragment_landscape.xml @@ -363,58 +363,113 @@ + + + + + + + + + + + + + + - - - - diff --git a/app/src/main/res/layout/overview_fragment_nsclient.xml b/app/src/main/res/layout/overview_fragment_nsclient.xml index 026d697838..3491184c6f 100644 --- a/app/src/main/res/layout/overview_fragment_nsclient.xml +++ b/app/src/main/res/layout/overview_fragment_nsclient.xml @@ -117,7 +117,7 @@ android:layout_width="wrap_content" android:layout_height="wrap_content" android:orientation="horizontal" - app:layout_constraintBottom_toTopOf="@+id/overview_statuslights_nscl" + app:layout_constraintBottom_toTopOf="@+id/overview_statuslights" app:layout_constraintEnd_toEndOf="parent" app:layout_constraintStart_toStartOf="parent" app:layout_constraintTop_toBottomOf="@+id/overview_pumpstatuslayout"> @@ -362,23 +362,22 @@ - + + + + + app:layout_constraintTop_toBottomOf="@+id/overview_statuslights" /> Enable superbolus in wizard Enable superbolus functionality in wizard. Do not enable until you learn what it really does. IT MAY CAUSE INSULIN OVERDOSE IF USED BLINDLY! key_show_statuslights - key_show_statuslights_extended Show status lights on home screen - Show extended status lights on home screen - Enable extended status lights for cage, iage, sage, reservoir and battery level on home screen. key_statuslights_res_warning Threshold warning reservoir level [U] key_statuslights_res_critical diff --git a/app/src/main/res/xml/pref_overview.xml b/app/src/main/res/xml/pref_overview.xml index 1e4825f113..720f8019cc 100644 --- a/app/src/main/res/xml/pref_overview.xml +++ b/app/src/main/res/xml/pref_overview.xml @@ -301,13 +301,6 @@ android:key="@string/key_show_statuslights" android:title="@string/show_statuslights" /> - -