From 5bee00a0bfe0b6cdc71b147d2ed1a6b146559ec9 Mon Sep 17 00:00:00 2001 From: Andries Smit Date: Sat, 5 Mar 2022 20:49:00 +0100 Subject: [PATCH 1/2] fix: notifications color contract --- app/src/main/res/layout/overview_notification_item.xml | 4 +++- app/src/main/res/values/colors.xml | 2 +- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/app/src/main/res/layout/overview_notification_item.xml b/app/src/main/res/layout/overview_notification_item.xml index 490092fce0..0a4e809e92 100644 --- a/app/src/main/res/layout/overview_notification_item.xml +++ b/app/src/main/res/layout/overview_notification_item.xml @@ -7,7 +7,7 @@ android:layout_height="wrap_content" android:layout_gravity="center" android:layout_margin="1dp" - card_view:cardBackgroundColor="@color/cardColorBackground" + card_view:cardBackgroundColor="@color/notificationUrgent" card_view:cardCornerRadius="6dp"> diff --git a/app/src/main/res/values/colors.xml b/app/src/main/res/values/colors.xml index 334e809e1e..e9c677487b 100644 --- a/app/src/main/res/values/colors.xml +++ b/app/src/main/res/values/colors.xml @@ -43,7 +43,7 @@ #ff0400 #ff5e55 #ff827c - #009705 + #24DF2B #c8666666 #7200FF00 From 59bb5937f2155ae0fc3d1e71846298f1b5e72325 Mon Sep 17 00:00:00 2001 From: Andries Smit Date: Mon, 7 Mar 2022 14:56:17 +0100 Subject: [PATCH 2/2] chore: move colors to themed arguments --- .../overview/notifications/NotificationStore.kt | 10 +++++----- .../main/res/layout/overview_notification_item.xml | 2 +- app/src/main/res/values/colors.xml | 5 ----- .../androidaps/utils/resources/ResourceHelper.kt | 14 ++++++++++++-- .../utils/resources/ResourceHelperExtensions.kt | 13 +++++++++++++ .../resources/ResourceHelperImplementation.kt | 9 ++++++++- core/src/main/res/values/attrs.xml | 8 ++++++++ core/src/main/res/values/colors.xml | 8 +++++++- core/src/main/res/values/styles.xml | 6 ++++++ 9 files changed, 60 insertions(+), 15 deletions(-) create mode 100644 core/src/main/java/info/nightscout/androidaps/utils/resources/ResourceHelperExtensions.kt diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/general/overview/notifications/NotificationStore.kt b/app/src/main/java/info/nightscout/androidaps/plugins/general/overview/notifications/NotificationStore.kt index 5e66ac8260..087ec2f2ee 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/general/overview/notifications/NotificationStore.kt +++ b/app/src/main/java/info/nightscout/androidaps/plugins/general/overview/notifications/NotificationStore.kt @@ -164,11 +164,11 @@ class NotificationStore @Inject constructor( @Suppress("SetTextI18n") holder.binding.text.text = dateUtil.timeString(notification.date) + " " + notification.text when (notification.level) { - Notification.URGENT -> holder.binding.cv.setBackgroundColor(rh.gc(R.color.notificationUrgent)) - Notification.NORMAL -> holder.binding.cv.setBackgroundColor(rh.gc(R.color.notificationNormal)) - Notification.LOW -> holder.binding.cv.setBackgroundColor(rh.gc(R.color.notificationLow)) - Notification.INFO -> holder.binding.cv.setBackgroundColor(rh.gc(R.color.notificationInfo)) - Notification.ANNOUNCEMENT -> holder.binding.cv.setBackgroundColor(rh.gc(R.color.notificationAnnouncement)) + Notification.URGENT -> holder.binding.cv.setBackgroundColor(rh.gac(R.attr.notificationUrgent)) + Notification.NORMAL -> holder.binding.cv.setBackgroundColor(rh.gac(R.attr.notificationNormal)) + Notification.LOW -> holder.binding.cv.setBackgroundColor(rh.gac(R.attr.notificationLow)) + Notification.INFO -> holder.binding.cv.setBackgroundColor(rh.gac(R.attr.notificationInfo)) + Notification.ANNOUNCEMENT -> holder.binding.cv.setBackgroundColor(rh.gac(R.attr.notificationAnnouncement)) } } diff --git a/app/src/main/res/layout/overview_notification_item.xml b/app/src/main/res/layout/overview_notification_item.xml index 0a4e809e92..23d103abeb 100644 --- a/app/src/main/res/layout/overview_notification_item.xml +++ b/app/src/main/res/layout/overview_notification_item.xml @@ -22,7 +22,7 @@ android:layout_height="wrap_content" android:layout_marginStart="5dp" android:layout_weight="1" - android:textColor="@color/black" + android:textColor="?attr/colorOnError" android:maxLines="4" android:textStyle="bold" android:text="Notification text. Notification text. Notification text. Notification text. Notification text. Notification text. " diff --git a/app/src/main/res/values/colors.xml b/app/src/main/res/values/colors.xml index e9c677487b..96670d632b 100644 --- a/app/src/main/res/values/colors.xml +++ b/app/src/main/res/values/colors.xml @@ -40,11 +40,6 @@ #de7550 #25912e - #ff0400 - #ff5e55 - #ff827c - #24DF2B - #c8666666 #7200FF00 #72FF0000 diff --git a/core/src/main/java/info/nightscout/androidaps/utils/resources/ResourceHelper.kt b/core/src/main/java/info/nightscout/androidaps/utils/resources/ResourceHelper.kt index 8f6379d657..bdfdb76a92 100644 --- a/core/src/main/java/info/nightscout/androidaps/utils/resources/ResourceHelper.kt +++ b/core/src/main/java/info/nightscout/androidaps/utils/resources/ResourceHelper.kt @@ -1,5 +1,6 @@ package info.nightscout.androidaps.utils.resources +import android.content.Context import android.content.res.AssetFileDescriptor import android.graphics.Bitmap import android.graphics.drawable.Drawable @@ -11,7 +12,7 @@ interface ResourceHelper { fun gs(@StringRes id: Int, vararg args: Any?): String fun gq(@PluralsRes id: Int, quantity: Int, vararg args: Any?): String fun gsNotLocalised(@StringRes id: Int, vararg args: Any?): String - fun gc(@ColorRes id: Int): Int + @ColorInt fun gc(@ColorRes id: Int): Int fun gd(@DrawableRes id: Int): Drawable? fun gb(@BoolRes id :Int) : Boolean fun gcs(@ColorRes id: Int): String @@ -23,4 +24,13 @@ interface ResourceHelper { fun dpToPx(dp: Int): Int fun dpToPx(dp: Float): Int fun shortTextMode(): Boolean -} \ No newline at end of file + + /** + * Get Attribute Color based on theme style + */ + @ColorInt fun gac(@AttrRes attributeId: Int): Int + /** + * Get Attribute Color based on theme style for specified context + */ + @ColorInt fun gac(context: Context, @AttrRes attributeId: Int): Int +} diff --git a/core/src/main/java/info/nightscout/androidaps/utils/resources/ResourceHelperExtensions.kt b/core/src/main/java/info/nightscout/androidaps/utils/resources/ResourceHelperExtensions.kt new file mode 100644 index 0000000000..db31c42970 --- /dev/null +++ b/core/src/main/java/info/nightscout/androidaps/utils/resources/ResourceHelperExtensions.kt @@ -0,0 +1,13 @@ +package info.nightscout.androidaps.utils.resources + +import android.content.Context +import android.util.TypedValue +import androidx.annotation.AttrRes +import androidx.annotation.ColorInt + +@ColorInt +fun Context.getThemeColor(@AttrRes attribute: Int) = + TypedValue().let { + theme.resolveAttribute(attribute, it, true) + it.data + } diff --git a/core/src/main/java/info/nightscout/androidaps/utils/resources/ResourceHelperImplementation.kt b/core/src/main/java/info/nightscout/androidaps/utils/resources/ResourceHelperImplementation.kt index 86673862f4..0c6cd537b9 100644 --- a/core/src/main/java/info/nightscout/androidaps/utils/resources/ResourceHelperImplementation.kt +++ b/core/src/main/java/info/nightscout/androidaps/utils/resources/ResourceHelperImplementation.kt @@ -9,6 +9,7 @@ import android.graphics.BitmapFactory import android.graphics.drawable.Drawable import android.util.DisplayMetrics import androidx.annotation.* +import androidx.appcompat.view.ContextThemeWrapper import androidx.core.content.ContextCompat import info.nightscout.androidaps.core.R import info.nightscout.androidaps.utils.FabricPrivacy @@ -83,4 +84,10 @@ class ResourceHelperImplementation @Inject constructor(private val context: Cont } override fun shortTextMode(): Boolean = !gb(R.bool.isTablet) -} \ No newline at end of file + + override fun gac(context: Context, attributeId: Int): Int = + context.getThemeColor(attributeId) + + override fun gac(attributeId: Int): Int = + ContextThemeWrapper(this.context, R.style.AppTheme).getThemeColor(attributeId) +} diff --git a/core/src/main/res/values/attrs.xml b/core/src/main/res/values/attrs.xml index 85a25abfed..918e9b7114 100644 --- a/core/src/main/res/values/attrs.xml +++ b/core/src/main/res/values/attrs.xml @@ -7,4 +7,12 @@ + + + + + + + + \ No newline at end of file diff --git a/core/src/main/res/values/colors.xml b/core/src/main/res/values/colors.xml index a6a7245cba..69de6e1abb 100644 --- a/core/src/main/res/values/colors.xml +++ b/core/src/main/res/values/colors.xml @@ -92,8 +92,14 @@ #1ea3e5 #1e88e5 - + #FF8C00 + #ff0400 + #ff5e55 + #ff827c + + + #009705 #666666 diff --git a/core/src/main/res/values/styles.xml b/core/src/main/res/values/styles.xml index 31076be1d6..b22248a881 100644 --- a/core/src/main/res/values/styles.xml +++ b/core/src/main/res/values/styles.xml @@ -22,6 +22,12 @@ @color/white @color/white @color/white + + @color/notificationUrgent + @color/notificationNormal + @color/notificationLow + @color/notificationInfo + @color/notificationAnnouncement