Adding Animation when expanding/collapsing sections in source filter sheet

This commit is contained in:
Jays2Kings 2021-04-15 01:04:19 -04:00
parent 41f3d1ea2a
commit 6c581dd0fc
7 changed files with 77 additions and 10 deletions

View File

@ -11,7 +11,7 @@ import eu.davidea.flexibleadapter.items.ISectionable
import eu.davidea.viewholders.ExpandableViewHolder import eu.davidea.viewholders.ExpandableViewHolder
import eu.kanade.tachiyomi.R import eu.kanade.tachiyomi.R
import eu.kanade.tachiyomi.source.model.Filter import eu.kanade.tachiyomi.source.model.Filter
import eu.kanade.tachiyomi.util.view.setVectorCompat import eu.kanade.tachiyomi.util.view.setAnimVectorCompat
class GroupItem(val filter: Filter.Group<*>) : AbstractExpandableHeaderItem<GroupItem.Holder, ISectionable<*, *>>() { class GroupItem(val filter: Filter.Group<*>) : AbstractExpandableHeaderItem<GroupItem.Holder, ISectionable<*, *>>() {
@ -34,11 +34,11 @@ class GroupItem(val filter: Filter.Group<*>) : AbstractExpandableHeaderItem<Grou
override fun bindViewHolder(adapter: FlexibleAdapter<IFlexible<RecyclerView.ViewHolder>>, holder: Holder, position: Int, payloads: MutableList<Any?>?) { override fun bindViewHolder(adapter: FlexibleAdapter<IFlexible<RecyclerView.ViewHolder>>, holder: Holder, position: Int, payloads: MutableList<Any?>?) {
holder.title.text = filter.name holder.title.text = filter.name
holder.icon.setVectorCompat( holder.icon.setAnimVectorCompat(
if (isExpanded) { if (isExpanded) {
R.drawable.ic_expand_less_24dp R.drawable.expand_more_to_less
} else { } else {
R.drawable.ic_expand_more_24dp R.drawable.expand_less_to_more
} }
) )

View File

@ -8,7 +8,7 @@ import eu.davidea.flexibleadapter.items.IFlexible
import eu.davidea.flexibleadapter.items.ISectionable import eu.davidea.flexibleadapter.items.ISectionable
import eu.kanade.tachiyomi.R import eu.kanade.tachiyomi.R
import eu.kanade.tachiyomi.source.model.Filter import eu.kanade.tachiyomi.source.model.Filter
import eu.kanade.tachiyomi.util.view.setVectorCompat import eu.kanade.tachiyomi.util.view.setAnimVectorCompat
class SortGroup(val filter: Filter.Sort) : AbstractExpandableHeaderItem<SortGroup.Holder, ISectionable<*, *>>() { class SortGroup(val filter: Filter.Sort) : AbstractExpandableHeaderItem<SortGroup.Holder, ISectionable<*, *>>() {
@ -31,11 +31,11 @@ class SortGroup(val filter: Filter.Sort) : AbstractExpandableHeaderItem<SortGrou
override fun bindViewHolder(adapter: FlexibleAdapter<IFlexible<RecyclerView.ViewHolder>>, holder: Holder, position: Int, payloads: MutableList<Any?>?) { override fun bindViewHolder(adapter: FlexibleAdapter<IFlexible<RecyclerView.ViewHolder>>, holder: Holder, position: Int, payloads: MutableList<Any?>?) {
holder.title.text = filter.name holder.title.text = filter.name
holder.icon.setVectorCompat( holder.icon.setAnimVectorCompat(
if (isExpanded) { if (isExpanded) {
R.drawable.ic_expand_less_24dp R.drawable.expand_more_to_less
} else { } else {
R.drawable.ic_expand_more_24dp R.drawable.expand_less_to_more
} }
) )

View File

@ -2,6 +2,7 @@ package eu.kanade.tachiyomi.util.view
import android.widget.ImageView import android.widget.ImageView
import androidx.annotation.DrawableRes import androidx.annotation.DrawableRes
import androidx.vectordrawable.graphics.drawable.AnimatedVectorDrawableCompat
import androidx.vectordrawable.graphics.drawable.VectorDrawableCompat import androidx.vectordrawable.graphics.drawable.VectorDrawableCompat
/** /**
@ -17,3 +18,13 @@ fun ImageView.setVectorCompat(@DrawableRes drawable: Int, tint: Int? = null) {
} }
setImageDrawable(vector) setImageDrawable(vector)
} }
fun ImageView.setAnimVectorCompat(@DrawableRes drawable: Int, tint: Int? = null) {
val vector = AnimatedVectorDrawableCompat.create(context, drawable)
if (tint != null) {
vector?.mutate()
vector?.setTint(tint)
}
setImageDrawable(vector)
vector?.start()
}

View File

@ -0,0 +1,28 @@
<animated-vector
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:aapt="http://schemas.android.com/aapt">
<aapt:attr name="android:drawable">
<vector
android:name="vector"
android:width="24dp"
android:height="24dp"
android:viewportWidth="24"
android:viewportHeight="24">
<path
android:name="path"
android:pathData="M 18 14 L 12 8 L 6 14 L 7.41 15.41 L 12 10.83 L 16.59 15.41 L 18 14"
android:fillColor="#000000"/>
</vector>
</aapt:attr>
<target android:name="path">
<aapt:attr name="android:animation">
<objectAnimator
android:propertyName="pathData"
android:duration="250"
android:valueFrom="M 18 14 L 12 8 L 6 14 L 7.41 15.41 L 12 10.83 L 16.59 15.41 L 18 14"
android:valueTo="M 16.59 8.59 L 12 13.17 L 7.41 8.59 L 6 10 L 12 16 L 18 10 L 16.59 8.59"
android:valueType="pathType"
android:interpolator="@android:interpolator/fast_out_slow_in"/>
</aapt:attr>
</target>
</animated-vector>

View File

@ -0,0 +1,28 @@
<animated-vector
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:aapt="http://schemas.android.com/aapt">
<aapt:attr name="android:drawable">
<vector
android:name="vector"
android:width="24dp"
android:height="24dp"
android:viewportWidth="24"
android:viewportHeight="24">
<path
android:name="path"
android:pathData="M 16.59 8.59 L 12 13.17 L 7.41 8.59 L 6 10 L 12 16 L 18 10 L 16.59 8.59"
android:fillColor="#000000"/>
</vector>
</aapt:attr>
<target android:name="path">
<aapt:attr name="android:animation">
<objectAnimator
android:propertyName="pathData"
android:duration="250"
android:valueFrom="M 16.59 8.59 L 12 13.17 L 7.41 8.59 L 6 10 L 12 16 L 18 10 L 16.59 8.59"
android:valueTo="M 18 14 L 12 8 L 6 14 L 7.41 15.41 L 12 10.83 L 16.59 15.41 L 18 14"
android:valueType="pathType"
android:interpolator="@android:interpolator/fast_out_slow_in"/>
</aapt:attr>
</target>
</animated-vector>

View File

@ -5,7 +5,7 @@
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="?attr/listPreferredItemHeightSmall" android:layout_height="?attr/listPreferredItemHeightSmall"
android:gravity="center_vertical" android:gravity="center_vertical"
android:background="?android:attr/colorBackground" android:background="@drawable/rect_ripple"
android:orientation="horizontal" android:orientation="horizontal"
android:paddingStart="?attr/listPreferredItemPaddingStart" android:paddingStart="?attr/listPreferredItemPaddingStart"
android:paddingEnd="?attr/listPreferredItemPaddingEnd"> android:paddingEnd="?attr/listPreferredItemPaddingEnd">

View File

@ -10,7 +10,7 @@
<eu.kanade.tachiyomi.widget.MaterialSpinnerView <eu.kanade.tachiyomi.widget.MaterialSpinnerView
android:id="@+id/nav_view_item" android:id="@+id/nav_view_item"
android:layout_marginEnd="8dp" android:layout_marginEnd="6dp"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="match_parent" android:layout_height="match_parent"
tools:entries="@array/viewers_selector" tools:entries="@array/viewers_selector"