From 0d4e2c2e550faf8680d2b7d0733a7c3af051c24c Mon Sep 17 00:00:00 2001 From: osodebailar Date: Fri, 22 Apr 2022 19:24:28 +0200 Subject: [PATCH] adjust ribbon style --- .../general/overview/OverviewFragment.kt | 61 ++++++++++++------- .../nightscout/androidaps/skins/SkinLowRes.kt | 3 + app/src/main/res/drawable/ic_crosstarget.xml | 12 ++++ .../main/res/drawable/ic_ribbon_profile.xml | 9 +++ app/src/main/res/layout/overview_fragment.xml | 12 ++-- .../src/main/res/drawable/ic_home_profile.xml | 2 +- core/src/main/res/values-night/styles.xml | 5 +- core/src/main/res/values/attrs.xml | 3 + core/src/main/res/values/styles.xml | 5 +- 9 files changed, 82 insertions(+), 30 deletions(-) create mode 100644 app/src/main/res/drawable/ic_crosstarget.xml create mode 100644 app/src/main/res/drawable/ic_ribbon_profile.xml 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 7be5135fa4..865ee4496e 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 @@ -807,31 +807,28 @@ class OverviewFragment : DaggerFragment(), View.OnClickListener, OnLongClickList profileFunction.getProfile()?.let { if (it is ProfileSealed.EPS) { if (it.value.originalPercentage != 100 || it.value.originalTimeshift != 0L || it.value.originalDuration != 0L) - rh.gac(context, R.attr.ribbonWarningColor) - else rh.gac(context, R.attr.ribbonDefaultColor) + R.attr.ribbonWarningColor + else R.attr.ribbonDefaultColor } else if (it is ProfileSealed.PS) { - rh.gac(context, R.attr.ribbonDefaultColor) + R.attr.ribbonDefaultColor } else { - rh.gac(context, R.attr.ribbonDefaultColor) + R.attr.ribbonDefaultColor } - } ?: rh.gac(context, R.attr.ribbonCriticalColor) + } ?: R.attr.ribbonCriticalColor val profileTextColor = profileFunction.getProfile()?.let { if (it is ProfileSealed.EPS) { if (it.value.originalPercentage != 100 || it.value.originalTimeshift != 0L || it.value.originalDuration != 0L) - rh.gac(context, R.attr.ribbonTextWarningColor) - else rh.gac(context, R.attr.ribbonTextDefaultColor) + R.attr.ribbonTextWarningColor + else R.attr.ribbonTextDefaultColor } else if (it is ProfileSealed.PS) { - rh.gac(context, R.attr.ribbonTextDefaultColor) + R.attr.ribbonTextDefaultColor } else { - rh.gac(context, R.attr.ribbonTextDefaultColor) + R.attr.ribbonTextDefaultColor } - } ?: rh.gac(context, R.attr.ribbonTextDefaultColor) - - binding.activeProfile.text = profileFunction.getProfileNameWithRemainingTime() - binding.activeProfile.setBackgroundColor(profileBackgroundColor) - binding.activeProfile.setTextColor(profileTextColor) + } ?: R.attr.ribbonTextDefaultColor + setRibbon(binding.activeProfile, profileTextColor, profileBackgroundColor, profileFunction.getProfileNameWithRemainingTime()) } private fun updateTemporaryBasal() { @@ -919,9 +916,12 @@ class OverviewFragment : DaggerFragment(), View.OnClickListener, OnLongClickList val units = profileFunction.getUnits() val tempTarget = overviewData.temporaryTarget if (tempTarget != null) { - binding.tempTarget.setTextColor(rh.gac(context, R.attr.ribbonTextWarningColor)) - binding.tempTarget.setBackgroundColor(rh.gac(context, R.attr.ribbonWarningColor)) - binding.tempTarget.text = Profile.toTargetRangeString(tempTarget.lowTarget, tempTarget.highTarget, GlucoseUnit.MGDL, units) + " " + dateUtil.untilString(tempTarget.end, rh) + setRibbon( + binding.tempTarget, + R.attr.ribbonTextWarningColor, + R.attr.ribbonWarningColor, + Profile.toTargetRangeString(tempTarget.lowTarget, tempTarget.highTarget, GlucoseUnit.MGDL, units) + " " + dateUtil.untilString(tempTarget.end, rh) + ) } else { // If the target is not the same as set in the profile then oref has overridden it profileFunction.getProfile()?.let { profile -> @@ -929,18 +929,33 @@ class OverviewFragment : DaggerFragment(), View.OnClickListener, OnLongClickList if (targetUsed != 0.0 && abs(profile.getTargetMgdl() - targetUsed) > 0.01) { aapsLogger.debug("Adjusted target. Profile: ${profile.getTargetMgdl()} APS: $targetUsed") - binding.tempTarget.text = Profile.toTargetRangeString(targetUsed, targetUsed, GlucoseUnit.MGDL, units) - binding.tempTarget.setTextColor(rh.gac(context, R.attr.ribbonTextWarningColor)) - binding.tempTarget.setBackgroundColor(rh.gac(context, R.attr.tempTargetBackgroundColor)) + setRibbon( + binding.tempTarget, + R.attr.ribbonTextWarningColor, + R.attr.tempTargetBackgroundColor, + Profile.toTargetRangeString(targetUsed, targetUsed, GlucoseUnit.MGDL, units) + ) } else { - binding.tempTarget.setTextColor(rh.gac(context, R.attr.ribbonTextDefaultColor)) - binding.tempTarget.setBackgroundColor(rh.gac(context, R.attr.ribbonDefaultColor)) - binding.tempTarget.text = Profile.toTargetRangeString(profile.getTargetLowMgdl(), profile.getTargetHighMgdl(), GlucoseUnit.MGDL, units) + setRibbon( + binding.tempTarget, + R.attr.ribbonTextDefaultColor, + R.attr.ribbonDefaultColor, + Profile.toTargetRangeString(profile.getTargetLowMgdl(), profile.getTargetHighMgdl(), GlucoseUnit.MGDL, units) + ) } } } } + private fun setRibbon(view: TextView, attrResText: Int, attrResBack: Int, text: String) { + with(view) { + setText(text) + setBackgroundColor(rh.gac(context, attrResBack)) + setTextColor(rh.gac(context, attrResText)) + compoundDrawables[0]?.setTint(rh.gac(context, attrResText)) + } + } + private fun updateGraph() { _binding ?: return val pump = activePlugin.activePump diff --git a/app/src/main/java/info/nightscout/androidaps/skins/SkinLowRes.kt b/app/src/main/java/info/nightscout/androidaps/skins/SkinLowRes.kt index 03206a0d46..440ac96733 100644 --- a/app/src/main/java/info/nightscout/androidaps/skins/SkinLowRes.kt +++ b/app/src/main/java/info/nightscout/androidaps/skins/SkinLowRes.kt @@ -70,6 +70,9 @@ class SkinLowRes @Inject constructor(private val config: Config) : SkinInterface setMargins(0,0,0,0) } graphCard.layoutParams = paramGraph + + activeProfile.setCompoundDrawablesWithIntrinsicBounds(0, 0, 0, 0) + tempTarget.setCompoundDrawablesWithIntrinsicBounds(0, 0, 0, 0) } } diff --git a/app/src/main/res/drawable/ic_crosstarget.xml b/app/src/main/res/drawable/ic_crosstarget.xml new file mode 100644 index 0000000000..7642b99942 --- /dev/null +++ b/app/src/main/res/drawable/ic_crosstarget.xml @@ -0,0 +1,12 @@ + + + + \ No newline at end of file diff --git a/app/src/main/res/drawable/ic_ribbon_profile.xml b/app/src/main/res/drawable/ic_ribbon_profile.xml new file mode 100644 index 0000000000..0d37823a08 --- /dev/null +++ b/app/src/main/res/drawable/ic_ribbon_profile.xml @@ -0,0 +1,9 @@ + + + diff --git a/app/src/main/res/layout/overview_fragment.xml b/app/src/main/res/layout/overview_fragment.xml index f2b69855b7..779d159c22 100644 --- a/app/src/main/res/layout/overview_fragment.xml +++ b/app/src/main/res/layout/overview_fragment.xml @@ -38,11 +38,13 @@ android:layout_marginEnd="5dp" android:layout_weight="1" android:gravity="center_vertical|center_horizontal" - android:paddingTop="6dp" - android:paddingBottom="6dp" + android:paddingTop="4dp" + android:paddingBottom="4dp" android:hint="active profile" android:text="Profile" android:textAppearance="?android:attr/textAppearanceSmall" + android:foreground="?attr/selectableItemBackgroundBorderless" + app:drawableStartCompat="@drawable/ic_ribbon_profile" tools:ignore="HardcodedText" /> diff --git a/core/src/main/res/drawable/ic_home_profile.xml b/core/src/main/res/drawable/ic_home_profile.xml index 31c93c3483..6caef133fe 100644 --- a/core/src/main/res/drawable/ic_home_profile.xml +++ b/core/src/main/res/drawable/ic_home_profile.xml @@ -5,5 +5,5 @@ android:viewportHeight="24"> + android:fillColor="?attr/profileColor"/> diff --git a/core/src/main/res/values-night/styles.xml b/core/src/main/res/values-night/styles.xml index 87e5b2cdd8..7e98c75fcd 100644 --- a/core/src/main/res/values-night/styles.xml +++ b/core/src/main/res/values-night/styles.xml @@ -86,7 +86,7 @@ @color/activity_title_background - @color/ribbonDefault + @color/buttonBackground @color/ribbonWarning @color/ribbonCritical @color/ribbonTextDefault @@ -243,6 +243,9 @@ @style/DatePicker @color/defaultText + + @color/white + @color/white