mirror of
https://github.com/tachiyomiorg/tachiyomi.git
synced 2024-12-23 14:31:50 +01:00
More helper methods in MenuSheetItemView
This commit is contained in:
parent
19ce2d2427
commit
3cf8b52025
@ -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<MenuSheetItemView>(id) ?: return
|
||||
layout.setTextColor(layout.context.getResourceColor(R.attr.colorAccent))
|
||||
layout.setIconColor(layout.context.getResourceColor(R.attr.colorAccent))
|
||||
layout.setEndIcon(drawableRes)
|
||||
binding.menuLayout.findViewById<MenuSheetItemView>(id)?.selectWithEndIcon(drawableRes)
|
||||
}
|
||||
|
||||
data class MenuSheetItem(
|
||||
|
@ -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)
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user