From 6350b72e231faac8f7087904a1d0b4ac1d596755 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Rafa=C5=82=20Borcz?= Date: Fri, 6 Sep 2019 18:23:51 +0200 Subject: [PATCH] Fix account icon color in widgets (#488) --- .../LuckyNumberWidgetConfigureItem.kt | 22 ++++++++++++------- .../TimetableWidgetConfigureItem.kt | 22 ++++++++++++------- .../ic_account_circular_border.xml | 8 ------- .../drawable/ic_account_circular_border.xml | 8 ------- 4 files changed, 28 insertions(+), 32 deletions(-) delete mode 100644 app/src/main/res/drawable-night/ic_account_circular_border.xml delete mode 100644 app/src/main/res/drawable/ic_account_circular_border.xml diff --git a/app/src/main/java/io/github/wulkanowy/ui/modules/luckynumberwidget/LuckyNumberWidgetConfigureItem.kt b/app/src/main/java/io/github/wulkanowy/ui/modules/luckynumberwidget/LuckyNumberWidgetConfigureItem.kt index bba0974b6..e260b7fcb 100644 --- a/app/src/main/java/io/github/wulkanowy/ui/modules/luckynumberwidget/LuckyNumberWidgetConfigureItem.kt +++ b/app/src/main/java/io/github/wulkanowy/ui/modules/luckynumberwidget/LuckyNumberWidgetConfigureItem.kt @@ -2,6 +2,7 @@ package io.github.wulkanowy.ui.modules.luckynumberwidget import android.annotation.SuppressLint import android.view.View +import androidx.core.graphics.ColorUtils import eu.davidea.flexibleadapter.FlexibleAdapter import eu.davidea.flexibleadapter.items.AbstractFlexibleItem import eu.davidea.flexibleadapter.items.IFlexible @@ -9,6 +10,7 @@ import eu.davidea.viewholders.FlexibleViewHolder import io.github.wulkanowy.R import io.github.wulkanowy.data.db.entities.Student import io.github.wulkanowy.ui.modules.timetablewidget.TimetableWidgetConfigureItem +import io.github.wulkanowy.utils.getThemeAttrColor import kotlinx.android.extensions.LayoutContainer import kotlinx.android.synthetic.main.item_account.* @@ -17,16 +19,19 @@ class LuckyNumberWidgetConfigureItem(var student: Student, val isCurrent: Boolea override fun getLayoutRes() = R.layout.item_account - override fun createViewHolder(view: View, adapter: FlexibleAdapter>): ViewHolder { - return ViewHolder(view, adapter) - } + override fun createViewHolder(view: View, adapter: FlexibleAdapter>) = ViewHolder(view, adapter) @SuppressLint("SetTextI18n") override fun bindViewHolder(adapter: FlexibleAdapter>, holder: ViewHolder, position: Int, payloads: MutableList) { - holder.apply { + val context = holder.contentView.context + + val colorImage = if (isCurrent) context.getThemeAttrColor(R.attr.colorPrimary) + else ColorUtils.setAlphaComponent(context.getThemeAttrColor(R.attr.colorOnSurface), 153) + + with(holder) { accountItemName.text = "${student.studentName} ${student.className}" accountItemSchool.text = student.schoolName - accountItemImage.setBackgroundResource(if (isCurrent) R.drawable.ic_account_circular_border else 0) + accountItemImage.setColorFilter(colorImage) } } @@ -47,8 +52,9 @@ class LuckyNumberWidgetConfigureItem(var student: Student, val isCurrent: Boolea return result } - class ViewHolder(view: View, adapter: FlexibleAdapter<*>) : FlexibleViewHolder(view, adapter), LayoutContainer { - override val containerView: View - get() = contentView + class ViewHolder(view: View, adapter: FlexibleAdapter<*>) : FlexibleViewHolder(view, adapter), + LayoutContainer { + + override val containerView: View? get() = contentView } } diff --git a/app/src/main/java/io/github/wulkanowy/ui/modules/timetablewidget/TimetableWidgetConfigureItem.kt b/app/src/main/java/io/github/wulkanowy/ui/modules/timetablewidget/TimetableWidgetConfigureItem.kt index f6ec1519f..a3338c684 100644 --- a/app/src/main/java/io/github/wulkanowy/ui/modules/timetablewidget/TimetableWidgetConfigureItem.kt +++ b/app/src/main/java/io/github/wulkanowy/ui/modules/timetablewidget/TimetableWidgetConfigureItem.kt @@ -2,12 +2,14 @@ package io.github.wulkanowy.ui.modules.timetablewidget import android.annotation.SuppressLint import android.view.View +import androidx.core.graphics.ColorUtils import eu.davidea.flexibleadapter.FlexibleAdapter import eu.davidea.flexibleadapter.items.AbstractFlexibleItem import eu.davidea.flexibleadapter.items.IFlexible import eu.davidea.viewholders.FlexibleViewHolder import io.github.wulkanowy.R import io.github.wulkanowy.data.db.entities.Student +import io.github.wulkanowy.utils.getThemeAttrColor import kotlinx.android.extensions.LayoutContainer import kotlinx.android.synthetic.main.item_account.* @@ -16,16 +18,19 @@ class TimetableWidgetConfigureItem(val student: Student, private val isCurrent: override fun getLayoutRes() = R.layout.item_account - override fun createViewHolder(view: View, adapter: FlexibleAdapter>): ViewHolder { - return ViewHolder(view, adapter) - } + override fun createViewHolder(view: View, adapter: FlexibleAdapter>) = ViewHolder(view, adapter) @SuppressLint("SetTextI18n") override fun bindViewHolder(adapter: FlexibleAdapter>, holder: ViewHolder, position: Int, payloads: MutableList) { - holder.apply { + val context = holder.contentView.context + + val colorImage = if (isCurrent) context.getThemeAttrColor(R.attr.colorPrimary) + else ColorUtils.setAlphaComponent(context.getThemeAttrColor(R.attr.colorOnSurface), 153) + + with(holder) { accountItemName.text = "${student.studentName} ${student.className}" accountItemSchool.text = student.schoolName - accountItemImage.setBackgroundResource(if (isCurrent) R.drawable.ic_account_circular_border else 0) + accountItemImage.setColorFilter(colorImage) } } @@ -46,8 +51,9 @@ class TimetableWidgetConfigureItem(val student: Student, private val isCurrent: return result } - class ViewHolder(view: View, adapter: FlexibleAdapter<*>) : FlexibleViewHolder(view, adapter), LayoutContainer { - override val containerView: View - get() = contentView + class ViewHolder(view: View, adapter: FlexibleAdapter<*>) : FlexibleViewHolder(view, adapter), + LayoutContainer { + + override val containerView: View? get() = contentView } } diff --git a/app/src/main/res/drawable-night/ic_account_circular_border.xml b/app/src/main/res/drawable-night/ic_account_circular_border.xml deleted file mode 100644 index a6a9e2536..000000000 --- a/app/src/main/res/drawable-night/ic_account_circular_border.xml +++ /dev/null @@ -1,8 +0,0 @@ - - - - - diff --git a/app/src/main/res/drawable/ic_account_circular_border.xml b/app/src/main/res/drawable/ic_account_circular_border.xml deleted file mode 100644 index 8ba66975a..000000000 --- a/app/src/main/res/drawable/ic_account_circular_border.xml +++ /dev/null @@ -1,8 +0,0 @@ - - - - -