diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/source/filter/SortItem.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/source/filter/SortItem.kt index fbbeb3b6ad..3b53f4ed8a 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/ui/source/filter/SortItem.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/ui/source/filter/SortItem.kt @@ -1,17 +1,14 @@ package eu.kanade.tachiyomi.ui.source.filter import android.view.View -import android.widget.CheckedTextView -import androidx.core.content.ContextCompat import androidx.recyclerview.widget.RecyclerView -import androidx.vectordrawable.graphics.drawable.VectorDrawableCompat import eu.davidea.flexibleadapter.FlexibleAdapter import eu.davidea.flexibleadapter.items.AbstractSectionableItem import eu.davidea.flexibleadapter.items.IFlexible import eu.davidea.viewholders.FlexibleViewHolder import eu.kanade.tachiyomi.R import eu.kanade.tachiyomi.source.model.Filter -import eu.kanade.tachiyomi.util.system.getResourceColor +import eu.kanade.tachiyomi.widget.SortTextView class SortItem(val name: String, val group: SortGroup) : AbstractSectionableItem(group) { @@ -30,29 +27,17 @@ class SortItem(val name: String, val group: SortGroup) : AbstractSectionableItem override fun bindViewHolder(adapter: FlexibleAdapter>, holder: Holder, position: Int, payloads: MutableList?) { val view = holder.text view.text = name + val filter = group.filter - val i = filter.values.indexOf(name) - - fun getIcon() = when (filter.state) { - Filter.Sort.Selection(i, false) -> - VectorDrawableCompat.create(view.resources, R.drawable.ic_arrow_downward_32dp, null) - ?.apply { setTint(view.context.getResourceColor(R.attr.colorAccent)) } - Filter.Sort.Selection(i, true) -> - VectorDrawableCompat.create(view.resources, R.drawable.ic_arrow_upward_32dp, null) - ?.apply { setTint(view.context.getResourceColor(R.attr.colorAccent)) } - else -> ContextCompat.getDrawable(view.context, R.drawable.empty_drawable_32dp) + view.state = when (filter.state) { + Filter.Sort.Selection(i, false) -> SortTextView.State.DESCENDING + Filter.Sort.Selection(i, true) -> SortTextView.State.ASCENDING + else -> SortTextView.State.NONE } - view.setCompoundDrawablesWithIntrinsicBounds(getIcon(), null, null, null) - holder.itemView.setOnClickListener { - val pre = filter.state?.index ?: i - if (pre != i) { - filter.state = Filter.Sort.Selection(i, false) - } else { - filter.state = Filter.Sort.Selection(i, filter.state?.ascending == false) - } - + view.setOnSortChangeListener { _, state -> + filter.state = Filter.Sort.Selection(i, state == SortTextView.State.ASCENDING) group.subItems.forEach { adapter.notifyItemChanged(adapter.getGlobalPositionOf(it)) } } } @@ -72,6 +57,6 @@ class SortItem(val name: String, val group: SortGroup) : AbstractSectionableItem class Holder(view: View, adapter: FlexibleAdapter>) : FlexibleViewHolder(view, adapter) { - val text: CheckedTextView = itemView.findViewById(R.id.nav_view_item) + val text: SortTextView = itemView.findViewById(R.id.nav_view_item) } } diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/source/filter/TriStateItem.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/source/filter/TriStateItem.kt index e44b9bd547..a53185608c 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/ui/source/filter/TriStateItem.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/ui/source/filter/TriStateItem.kt @@ -1,23 +1,19 @@ package eu.kanade.tachiyomi.ui.source.filter import android.view.View -import android.widget.CheckedTextView import androidx.recyclerview.widget.RecyclerView -import androidx.vectordrawable.graphics.drawable.VectorDrawableCompat -import com.google.android.material.R import eu.davidea.flexibleadapter.FlexibleAdapter import eu.davidea.flexibleadapter.items.AbstractFlexibleItem import eu.davidea.flexibleadapter.items.IFlexible import eu.davidea.viewholders.FlexibleViewHolder import eu.kanade.tachiyomi.source.model.Filter -import eu.kanade.tachiyomi.util.system.dpToPx -import eu.kanade.tachiyomi.util.system.getResourceColor +import eu.kanade.tachiyomi.widget.TriStateCheckBox import eu.kanade.tachiyomi.R as TR open class TriStateItem(val filter: Filter.TriState) : AbstractFlexibleItem() { override fun getLayoutRes(): Int { - return TR.layout.navigation_view_checkedtext + return TR.layout.navigation_view_tristatebox } override fun getItemViewType(): Int { @@ -31,30 +27,19 @@ open class TriStateItem(val filter: Filter.TriState) : AbstractFlexibleItem>, holder: Holder, position: Int, payloads: MutableList?) { val view = holder.text view.text = filter.name - - fun getIcon() = VectorDrawableCompat.create( - view.resources, - when (filter.state) { - Filter.TriState.STATE_IGNORE -> TR.drawable.ic_check_box_outline_blank_24dp - Filter.TriState.STATE_INCLUDE -> TR.drawable.ic_check_box_24dp - Filter.TriState.STATE_EXCLUDE -> TR.drawable.ic_check_box_x_24dp - else -> throw Exception("Unknown state") - }, - null - )?.apply { - val color = if (filter.state == Filter.TriState.STATE_INCLUDE) { - R.attr.colorAccent - } else { - android.R.attr.textColorSecondary - } - - setTint(view.context.getResourceColor(color)) + view.state = when (filter.state) { + Filter.TriState.STATE_IGNORE -> TriStateCheckBox.State.UNCHECKED + Filter.TriState.STATE_INCLUDE -> TriStateCheckBox.State.CHECKED + Filter.TriState.STATE_EXCLUDE -> TriStateCheckBox.State.INVERSED + else -> throw Exception("Unknown state") } - view.setCompoundDrawablesWithIntrinsicBounds(getIcon(), null, null, null) - holder.itemView.setOnClickListener { - filter.state = (filter.state + 1) % 3 - view.setCompoundDrawablesWithIntrinsicBounds(getIcon(), null, null, null) + view.setOnCheckedChangeListener { _, state -> + filter.state = when (state) { + TriStateCheckBox.State.UNCHECKED -> Filter.TriState.STATE_IGNORE + TriStateCheckBox.State.CHECKED -> Filter.TriState.STATE_INCLUDE + TriStateCheckBox.State.INVERSED -> Filter.TriState.STATE_EXCLUDE + } } } @@ -70,12 +55,6 @@ open class TriStateItem(val filter: Filter.TriState) : AbstractFlexibleItem>) : FlexibleViewHolder(view, adapter) { - val text: CheckedTextView = itemView.findViewById(TR.id.nav_view_item) - - init { - // Align with native checkbox - text.setPadding(4.dpToPx, 0, 0, 0) - text.compoundDrawablePadding = 20.dpToPx - } + val text: TriStateCheckBox = itemView.findViewById(TR.id.nav_view_item) } } diff --git a/app/src/main/java/eu/kanade/tachiyomi/widget/SimpleNavigationView.kt b/app/src/main/java/eu/kanade/tachiyomi/widget/SimpleNavigationView.kt index 797cf75b8f..116796996b 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/widget/SimpleNavigationView.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/widget/SimpleNavigationView.kt @@ -6,7 +6,6 @@ import android.util.AttributeSet import android.view.View import android.view.ViewGroup import android.widget.CheckBox -import android.widget.CheckedTextView import android.widget.EditText import android.widget.RadioButton import android.widget.TextView @@ -147,7 +146,7 @@ open class SimpleNavigationView @JvmOverloads constructor( class MultiStateHolder(parent: ViewGroup, listener: View.OnClickListener?) : ClickableHolder(parent.inflate(TR.layout.navigation_view_checkedtext), listener) { - val text: CheckedTextView = itemView.findViewById(TR.id.nav_view_item) + val text: TriStateCheckBox = itemView.findViewById(TR.id.nav_view_item) } class SpinnerHolder(parent: ViewGroup, listener: OnClickListener? = null) : diff --git a/app/src/main/java/eu/kanade/tachiyomi/widget/SortTextView.kt b/app/src/main/java/eu/kanade/tachiyomi/widget/SortTextView.kt index e23c153505..0fbb84f5ae 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/widget/SortTextView.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/widget/SortTextView.kt @@ -4,6 +4,7 @@ import android.content.Context import android.util.AttributeSet import android.view.LayoutInflater import android.widget.FrameLayout +import androidx.core.view.updateLayoutParams import eu.kanade.tachiyomi.R import eu.kanade.tachiyomi.databinding.SortTextViewBinding import eu.kanade.tachiyomi.util.view.setVectorCompat @@ -45,6 +46,18 @@ class SortTextView constructor(context: Context, attrs: AttributeSet?) : val maxLines = a.getInt(R.styleable.SortTextView_android_maxLines, Int.MAX_VALUE) binding.textView.maxLines = maxLines + val resourceId = a.getResourceId(R.styleable.SortTextView_android_textAppearance, 0) + if (resourceId != 0) { + binding.textView.setTextAppearance(resourceId) + } + + val drawablePadding = a.getDimensionPixelSize(R.styleable.SortTextView_android_drawablePadding, 0) + if (drawablePadding != 0) { + binding.textView.updateLayoutParams { + marginStart = drawablePadding + } + } + a.recycle() setOnClickListener { diff --git a/app/src/main/java/eu/kanade/tachiyomi/widget/TriStateCheckBox.kt b/app/src/main/java/eu/kanade/tachiyomi/widget/TriStateCheckBox.kt index e916dc3b33..9471ffd09e 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/widget/TriStateCheckBox.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/widget/TriStateCheckBox.kt @@ -10,6 +10,7 @@ import eu.kanade.tachiyomi.databinding.TriStateCheckBoxBinding import eu.kanade.tachiyomi.util.system.getResourceColor import eu.kanade.tachiyomi.util.view.setAnimVectorCompat import eu.kanade.tachiyomi.util.view.setVectorCompat +import eu.kanade.tachiyomi.util.view.updateLayoutParams class TriStateCheckBox constructor(context: Context, attrs: AttributeSet?) : FrameLayout(context, attrs) { @@ -57,6 +58,18 @@ class TriStateCheckBox constructor(context: Context, attrs: AttributeSet?) : val maxLines = a.getInt(R.styleable.TriStateCheckBox_android_maxLines, Int.MAX_VALUE) binding.textView.maxLines = maxLines + val resourceId = a.getResourceId(R.styleable.TriStateCheckBox_android_textAppearance, 0) + if (resourceId != 0) { + binding.textView.setTextAppearance(resourceId) + } + + val drawablePadding = a.getDimensionPixelSize(R.styleable.TriStateCheckBox_android_drawablePadding, 0) + if (drawablePadding != 0) { + binding.textView.updateLayoutParams { + marginStart = drawablePadding + } + } + a.recycle() setOnClickListener { diff --git a/app/src/main/res/layout/navigation_view_checkbox.xml b/app/src/main/res/layout/navigation_view_checkbox.xml index 82ef90d095..06f33dab0d 100644 --- a/app/src/main/res/layout/navigation_view_checkbox.xml +++ b/app/src/main/res/layout/navigation_view_checkbox.xml @@ -8,7 +8,7 @@ android:background="?attr/selectableItemBackground" android:focusable="true"> - + android:clickable="false" /> diff --git a/app/src/main/res/layout/navigation_view_checkedtext.xml b/app/src/main/res/layout/navigation_view_checkedtext.xml index 69813970e0..3ac9995027 100644 --- a/app/src/main/res/layout/navigation_view_checkedtext.xml +++ b/app/src/main/res/layout/navigation_view_checkedtext.xml @@ -1,21 +1,19 @@ - - + android:maxLines="1" /> diff --git a/app/src/main/res/layout/navigation_view_tristatebox.xml b/app/src/main/res/layout/navigation_view_tristatebox.xml new file mode 100644 index 0000000000..67b2f7bab5 --- /dev/null +++ b/app/src/main/res/layout/navigation_view_tristatebox.xml @@ -0,0 +1,21 @@ + + + + + + diff --git a/app/src/main/res/values/attrs.xml b/app/src/main/res/values/attrs.xml index efb212ad94..7714649ecf 100644 --- a/app/src/main/res/values/attrs.xml +++ b/app/src/main/res/values/attrs.xml @@ -31,12 +31,16 @@ + + + +