From 07a2902367aa1a52d5acf1fdbc72fe1ea2ffcd0f Mon Sep 17 00:00:00 2001 From: denizk0461 Date: Thu, 20 Apr 2023 14:30:48 +0200 Subject: [PATCH] Highlighted course is now highlighted with the primary colour, 50% translucent --- .../studip/adapter/StudIPEventItemAdapter.kt | 26 +++++++++++++------ .../res/color/card_background_default.xml | 4 +++ .../res/color/card_background_highlight.xml | 4 +++ .../main/res/color/item_chip_background.xml | 2 +- app/src/main/res/layout/item_event.xml | 2 +- app/src/main/res/values-night/themes.xml | 7 ++--- app/src/main/res/values/attrs.xml | 1 + app/src/main/res/values/colors.xml | 2 ++ app/src/main/res/values/themes.xml | 3 ++- 9 files changed, 37 insertions(+), 14 deletions(-) create mode 100644 app/src/main/res/color/card_background_default.xml create mode 100644 app/src/main/res/color/card_background_highlight.xml diff --git a/app/src/main/java/com/denizk0461/studip/adapter/StudIPEventItemAdapter.kt b/app/src/main/java/com/denizk0461/studip/adapter/StudIPEventItemAdapter.kt index 0e08a75..692aabe 100644 --- a/app/src/main/java/com/denizk0461/studip/adapter/StudIPEventItemAdapter.kt +++ b/app/src/main/java/com/denizk0461/studip/adapter/StudIPEventItemAdapter.kt @@ -1,5 +1,6 @@ package com.denizk0461.studip.adapter +import android.content.res.ColorStateList import android.util.TypedValue import android.view.LayoutInflater import android.view.ViewGroup @@ -39,20 +40,29 @@ class StudIPEventItemAdapter( holder.binding.textRoom.text = currentItem.room holder.binding.textTimeslot.text = currentItem.timeslot() - val colorPrimary = TypedValue() - val colorTextHint = TypedValue() + val colorPrimaryTranslucent = TypedValue() + val colorCardBackground = TypedValue() + val colorTextHintLighter = TypedValue() val theme = holder.binding.root.context.theme - theme.resolveAttribute(R.attr.colorPrimary, colorPrimary, true) - theme.resolveAttribute(R.attr.colorTextHintLighter, colorTextHint, true) + + theme.resolveAttribute(R.attr.colorPrimaryTranslucent, colorPrimaryTranslucent, true) + theme.resolveAttribute(R.attr.colorCardBackground, colorCardBackground, true) + theme.resolveAttribute(R.attr.colorTextHintLighter, colorTextHintLighter, true) if (!isAnyCourseHighlighted && currentItem.isCurrentCourse(currentCalendar)) { // highlight isAnyCourseHighlighted = true - holder.binding.cardBackground.strokeColor = colorPrimary.data - holder.binding.cardBackground.strokeWidth = 6 // TODO replace this with proper float -> dp conversion + holder.binding.cardBackground.apply { + backgroundTintList = ColorStateList.valueOf(colorPrimaryTranslucent.data)//R.attr.colorPrimaryTranslucent) + strokeColor = context.getColor(android.R.color.transparent) + }//colorPrimary.data +// holder.binding.cardBackground.strokeWidth = 6 // TODO replace this with proper float -> dp conversion // R.color.list_card_selected) } else { // un-highlight - holder.binding.cardBackground.strokeColor = colorTextHint.data - holder.binding.cardBackground.strokeWidth = 3 // this should (?) be 1dp + holder.binding.cardBackground.apply { + backgroundTintList = ColorStateList.valueOf(colorCardBackground.data)//context.getColor(R.attr.colorCardBackground)) + strokeColor = colorTextHintLighter.data + } +// holder.binding.cardBackground.strokeWidth = 3 // this should (?) be 1dp } holder.binding.cardBackground.setOnClickListener { diff --git a/app/src/main/res/color/card_background_default.xml b/app/src/main/res/color/card_background_default.xml new file mode 100644 index 0000000..5ae061b --- /dev/null +++ b/app/src/main/res/color/card_background_default.xml @@ -0,0 +1,4 @@ + + + + \ No newline at end of file diff --git a/app/src/main/res/color/card_background_highlight.xml b/app/src/main/res/color/card_background_highlight.xml new file mode 100644 index 0000000..00ab9ab --- /dev/null +++ b/app/src/main/res/color/card_background_highlight.xml @@ -0,0 +1,4 @@ + + + + \ No newline at end of file diff --git a/app/src/main/res/color/item_chip_background.xml b/app/src/main/res/color/item_chip_background.xml index 6626625..ebcec5d 100644 --- a/app/src/main/res/color/item_chip_background.xml +++ b/app/src/main/res/color/item_chip_background.xml @@ -1,5 +1,5 @@ - + \ No newline at end of file diff --git a/app/src/main/res/layout/item_event.xml b/app/src/main/res/layout/item_event.xml index 57dc01c..dc9963f 100644 --- a/app/src/main/res/layout/item_event.xml +++ b/app/src/main/res/layout/item_event.xml @@ -11,7 +11,7 @@ android:layout_width="match_parent" android:layout_height="wrap_content" style="@style/Widget.Material3.CardView.Outlined" - android:backgroundTint="?attr/colorCardBackground"> + android:backgroundTint="@color/card_background_default"> @color/primaryNight + @color/primaryNightTranslucent @color/primaryNight @color/colorTextNight @@ -21,9 +22,9 @@ @color/highlightNight - + + +