From 4e0f41dcb249e1fbcecde7c1d511f818bd911244 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Rafa=C5=82=20Borcz?= Date: Wed, 4 Sep 2019 21:19:05 +0200 Subject: [PATCH] Change marking current student in accounts dialog (#486) --- .../ui/modules/account/AccountItem.kt | 23 ++++++++++++------- app/src/main/res/layout/item_account.xml | 5 ++-- app/src/main/res/values-night/styles.xml | 1 + 3 files changed, 18 insertions(+), 11 deletions(-) diff --git a/app/src/main/java/io/github/wulkanowy/ui/modules/account/AccountItem.kt b/app/src/main/java/io/github/wulkanowy/ui/modules/account/AccountItem.kt index 972d10a26..d3a3ee6a3 100644 --- a/app/src/main/java/io/github/wulkanowy/ui/modules/account/AccountItem.kt +++ b/app/src/main/java/io/github/wulkanowy/ui/modules/account/AccountItem.kt @@ -1,13 +1,16 @@ package io.github.wulkanowy.ui.modules.account import android.annotation.SuppressLint +import android.graphics.PorterDuff 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.* @@ -15,16 +18,19 @@ class AccountItem(val student: Student) : AbstractFlexibleItem>): 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 (student.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 (student.isCurrent) R.drawable.ic_account_circular_border else 0) + accountItemImage.setColorFilter(colorImage, PorterDuff.Mode.SRC_IN) } } @@ -45,8 +51,9 @@ class AccountItem(val student: Student) : AbstractFlexibleItem) : 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/layout/item_account.xml b/app/src/main/res/layout/item_account.xml index 2abae138a..309be8121 100644 --- a/app/src/main/res/layout/item_account.xml +++ b/app/src/main/res/layout/item_account.xml @@ -17,10 +17,9 @@ android:layout_width="40dp" android:layout_height="40dp" android:layout_centerVertical="true" - android:background="@drawable/ic_account_circular_border" app:srcCompat="@drawable/ic_all_account" - app:tint="#7E7E7E" - tools:ignore="ContentDescription" /> + tools:ignore="ContentDescription" + tools:tint="@color/colorPrimary" /> ?colorSurface ?android:textColorPrimary @android:color/black + false