From 5aa93fdcf17828a780c8cd6e98af26151b5591c9 Mon Sep 17 00:00:00 2001 From: nzoba <55888232+nzoba@users.noreply.github.com> Date: Tue, 31 May 2022 17:45:21 -0400 Subject: [PATCH] fix compile issue --- .../tachiyomi/widget/MaterialSpinnerView.kt | 35 ++++++++++++++++--- 1 file changed, 31 insertions(+), 4 deletions(-) diff --git a/app/src/main/java/eu/kanade/tachiyomi/widget/MaterialSpinnerView.kt b/app/src/main/java/eu/kanade/tachiyomi/widget/MaterialSpinnerView.kt index d57aea5937..96b78f4b12 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/widget/MaterialSpinnerView.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/widget/MaterialSpinnerView.kt @@ -30,6 +30,8 @@ class MaterialSpinnerView constructor(context: Context, attrs: AttributeSet?) : private var entries = emptyList() var selectedPosition = 0 private set + var originalPosition: Int? = null + var originalIcon: Drawable? = null private var pref: Preference? = null private var prefOffset = 0 private var popup: PopupMenu? = null @@ -47,6 +49,14 @@ class MaterialSpinnerView constructor(context: Context, attrs: AttributeSet?) : 0.5f, ) + private val slightAccent by lazy { + ColorUtils.blendARGB( + context.getResourceColor(R.attr.colorSecondary), + context.getResourceColor(R.attr.colorOnBackground), + 0.9f, + ) + } + var onItemSelectedListener: ((Int) -> Unit)? = null set(value) { field = value @@ -72,10 +82,7 @@ class MaterialSpinnerView constructor(context: Context, attrs: AttributeSet?) : val str = a.getString(R.styleable.MaterialSpinnerView_title) ?: "" title = str - val entries = ( - a.getTextArray(R.styleable.MaterialSpinnerView_android_entries) - ?: emptyArray() - ).map { it.toString() } + val entries = (a.getTextArray(R.styleable.MaterialSpinnerView_android_entries) ?: emptyArray()).map { it.toString() } this.entries = entries val maxLines = a.getInt(R.styleable.MaterialSpinnerView_android_maxLines, Int.MAX_VALUE) @@ -118,6 +125,7 @@ class MaterialSpinnerView constructor(context: Context, attrs: AttributeSet?) : it.title = it.title?.tintText(blendedAccent) } } + updateOriginalPositionMenu() binding.detailView.text = entries.getOrNull(selection).orEmpty() } @@ -261,6 +269,25 @@ class MaterialSpinnerView constructor(context: Context, attrs: AttributeSet?) : return popup } + private fun updateOriginalPositionMenu() { + popup ?: return + val originalPosition = originalPosition ?: return + if (originalPosition != selectedPosition && + originalPosition >= 0 && originalPosition < (popup?.menu?.size() ?: 0) + ) { + popup?.menu?.getItem(originalPosition)?.let { menuItem -> + menuItem.icon = tintedOG() + menuItem + } + } + } + + private fun tintedOG(): Drawable? { + return originalIcon ?: ContextCompat.getDrawable(context, R.drawable.ic_browse_outline_24dp)?.mutate()?.apply { + setTint(slightAccent) + } + } + private fun tintedCheck(): Drawable? { return ContextCompat.getDrawable(context, R.drawable.ic_check_24dp)?.mutate()?.apply { setTint(blendedAccent)