diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/base/MaterialMenuSheet.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/base/MaterialMenuSheet.kt index 7a392c381a..3b3ed2839e 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/ui/base/MaterialMenuSheet.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/ui/base/MaterialMenuSheet.kt @@ -87,8 +87,7 @@ open class MaterialMenuSheet( if (item.id == selectedId) { currentIndex = index - setIconColor(activity.getResourceColor(R.attr.colorAccent)) - setTextColor(activity.getResourceColor(R.attr.colorAccent)) + isSelected = true } setOnClickListener { @@ -142,10 +141,7 @@ open class MaterialMenuSheet( private fun clearEndDrawables() { (0 until binding.menuLayout.childCount).forEach { - val itemView = (binding.menuLayout.getChildAt(it) as MenuSheetItemView) - itemView.setTextColor(primaryColor) - itemView.setIconColor(primaryColor) - itemView.setEndIcon(0) + (binding.menuLayout.getChildAt(it) as? MenuSheetItemView)?.isSelected = false } } @@ -153,10 +149,7 @@ open class MaterialMenuSheet( if (clearAll) { clearEndDrawables() } - val layout = binding.menuLayout.findViewById(id) ?: return - layout.setTextColor(layout.context.getResourceColor(R.attr.colorAccent)) - layout.setIconColor(layout.context.getResourceColor(R.attr.colorAccent)) - layout.setEndIcon(drawableRes) + binding.menuLayout.findViewById(id)?.selectWithEndIcon(drawableRes) } data class MenuSheetItem( diff --git a/app/src/main/java/eu/kanade/tachiyomi/widget/MenuSheetItemView.kt b/app/src/main/java/eu/kanade/tachiyomi/widget/MenuSheetItemView.kt index 1dfd0b6a58..6de84c68cd 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/widget/MenuSheetItemView.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/widget/MenuSheetItemView.kt @@ -13,6 +13,7 @@ import androidx.core.view.isGone import androidx.core.widget.TextViewCompat import eu.kanade.tachiyomi.R import eu.kanade.tachiyomi.databinding.MenuSheetItemBinding +import eu.kanade.tachiyomi.util.system.getResourceColor class MenuSheetItemView @JvmOverloads constructor(context: Context, attrs: AttributeSet?) : LinearLayout(context, attrs) { @@ -70,6 +71,23 @@ class MenuSheetItemView @JvmOverloads constructor(context: Context, attrs: Attri text = context.getString(res) } + fun selectWithEndIcon(@DrawableRes endDrawableRes: Int) { + isSelected = true + setEndIcon(endDrawableRes) + } + + override fun setSelected(selected: Boolean) { + super.setSelected(selected) + if (isSelected) { + setIconColor(context.getResourceColor(R.attr.colorAccent)) + setTextColor(context.getResourceColor(R.attr.colorAccent)) + } else { + setTextColor(context.getResourceColor(android.R.attr.textColorPrimary)) + setIconColor(context.getResourceColor(android.R.attr.textColorPrimary)) + setEndIcon(0) + } + } + fun setTextColor(@ColorInt color: Int) { binding?.itemTextView?.setTextColor(color) }