diff --git a/app/src/main/java/eu/kanade/tachiyomi/util/view/ImageViewExtensions.kt b/app/src/main/java/eu/kanade/tachiyomi/util/view/ImageViewExtensions.kt index 4ee2c6f6e9..ac44d27171 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/util/view/ImageViewExtensions.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/util/view/ImageViewExtensions.kt @@ -21,11 +21,11 @@ fun ImageView.setVectorCompat(@DrawableRes drawable: Int, @AttrRes tint: Int? = setImageDrawable(vector) } -fun ImageView.setAnimVectorCompat(@DrawableRes drawable: Int, tint: Int? = null) { +fun ImageView.setAnimVectorCompat(@DrawableRes drawable: Int, @AttrRes tint: Int? = null) { val vector = AnimatedVectorDrawableCompat.create(context, drawable) if (tint != null) { vector?.mutate() - vector?.setTint(tint) + vector?.setTint(context.getResourceColor(tint)) } setImageDrawable(vector) vector?.start() diff --git a/app/src/main/java/eu/kanade/tachiyomi/widget/materialdialogs/QuadStateCheckBox.kt b/app/src/main/java/eu/kanade/tachiyomi/widget/materialdialogs/QuadStateCheckBox.kt index b01d224374..3455fb5421 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/widget/materialdialogs/QuadStateCheckBox.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/widget/materialdialogs/QuadStateCheckBox.kt @@ -4,23 +4,36 @@ import android.content.Context import android.util.AttributeSet import androidx.appcompat.widget.AppCompatImageView import eu.kanade.tachiyomi.R +import eu.kanade.tachiyomi.util.view.setAnimVectorCompat import eu.kanade.tachiyomi.util.view.setVectorCompat class QuadStateCheckBox @JvmOverloads constructor(context: Context, attrs: AttributeSet? = null) : AppCompatImageView(context, attrs) { var state: State = State.UNCHECKED - set(value) { - field = value - updateDrawable() - } - private fun updateDrawable() { + fun animateDrawableToState(state: State) { + when (state) { + State.UNCHECKED -> setAnimVectorCompat( + when (this.state) { + State.INVERSED -> R.drawable.anim_check_box_x_to_blank_24dp + else -> R.drawable.anim_checkbox_checked_to_blank_24dp + }, + R.attr.colorControlNormal + ) + State.INDETERMINATE -> setVectorCompat(R.drawable.ic_indeterminate_check_box_24dp, R.attr.colorAccent) + State.CHECKED -> setAnimVectorCompat(R.drawable.anim_check_box_blank_to_checked_24dp, R.attr.colorAccent) + State.INVERSED -> setAnimVectorCompat(R.drawable.anim_check_box_checked_to_x_24dp, R.attr.colorAccentText) + } + this.state = state + } + + fun updateDrawable() { when (state) { State.UNCHECKED -> setVectorCompat(R.drawable.ic_check_box_outline_blank_24dp, R.attr.colorControlNormal) State.INDETERMINATE -> setVectorCompat(R.drawable.ic_indeterminate_check_box_24dp, R.attr.colorAccent) State.CHECKED -> setVectorCompat(R.drawable.ic_check_box_24dp, R.attr.colorAccent) - State.INVERSED -> setVectorCompat(R.drawable.ic_check_box_x_24dp, R.attr.colorAccent) + State.INVERSED -> setVectorCompat(R.drawable.ic_check_box_x_24dp, R.attr.colorAccentText) } } diff --git a/app/src/main/java/eu/kanade/tachiyomi/widget/materialdialogs/QuadStateMultiChoiceDialogAdapter.kt b/app/src/main/java/eu/kanade/tachiyomi/widget/materialdialogs/QuadStateMultiChoiceDialogAdapter.kt index f156c23e8f..de415fe97d 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/widget/materialdialogs/QuadStateMultiChoiceDialogAdapter.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/widget/materialdialogs/QuadStateMultiChoiceDialogAdapter.kt @@ -95,6 +95,7 @@ internal class QuadStateMultiChoiceDialogAdapter( holder.isEnabled = !disabledIndices.contains(position) holder.controlView.state = states[currentSelection[position]] + holder.controlView.updateDrawable() holder.titleView.text = items[position] holder.itemView.background = dialog.getItemSelector() @@ -110,15 +111,15 @@ internal class QuadStateMultiChoiceDialogAdapter( ) { when (payloads.firstOrNull()) { CheckPayload -> { - holder.controlView.state = QuadStateCheckBox.State.CHECKED + holder.controlView.animateDrawableToState(QuadStateCheckBox.State.CHECKED) return } InverseCheckPayload -> { - holder.controlView.state = QuadStateCheckBox.State.INVERSED + holder.controlView.animateDrawableToState(QuadStateCheckBox.State.INVERSED) return } UncheckPayload -> { - holder.controlView.state = QuadStateCheckBox.State.UNCHECKED + holder.controlView.animateDrawableToState(QuadStateCheckBox.State.UNCHECKED) return } } diff --git a/app/src/main/res/drawable/anim_check_box_blank_to_checked_24dp.xml b/app/src/main/res/drawable/anim_check_box_blank_to_checked_24dp.xml new file mode 100644 index 0000000000..c930ea2b20 --- /dev/null +++ b/app/src/main/res/drawable/anim_check_box_blank_to_checked_24dp.xml @@ -0,0 +1,80 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/app/src/main/res/drawable/anim_check_box_checked_to_x_24dp.xml b/app/src/main/res/drawable/anim_check_box_checked_to_x_24dp.xml new file mode 100644 index 0000000000..f1da805abb --- /dev/null +++ b/app/src/main/res/drawable/anim_check_box_checked_to_x_24dp.xml @@ -0,0 +1,80 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/app/src/main/res/drawable/anim_check_box_x_to_blank_24dp.xml b/app/src/main/res/drawable/anim_check_box_x_to_blank_24dp.xml new file mode 100644 index 0000000000..acf22aa178 --- /dev/null +++ b/app/src/main/res/drawable/anim_check_box_x_to_blank_24dp.xml @@ -0,0 +1,80 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/app/src/main/res/drawable/anim_checkbox_checked_to_blank_24dp.xml b/app/src/main/res/drawable/anim_checkbox_checked_to_blank_24dp.xml new file mode 100644 index 0000000000..6c996364e9 --- /dev/null +++ b/app/src/main/res/drawable/anim_checkbox_checked_to_blank_24dp.xml @@ -0,0 +1,80 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + +