mirror of
https://github.com/Aviortheking/Neo-Store.git
synced 2025-04-23 19:32:16 +00:00
Add: List Scroll Animation
This commit is contained in:
parent
d6bdd11d56
commit
2a7e289dda
@ -93,7 +93,7 @@ data class Product(
|
|||||||
}
|
}
|
||||||
|
|
||||||
fun serialize(generator: JsonGenerator) {
|
fun serialize(generator: JsonGenerator) {
|
||||||
generator.writeNumberField("repositoryId",repositoryId)
|
generator.writeNumberField("repositoryId", repositoryId)
|
||||||
generator.writeNumberField("serialVersion", 1)
|
generator.writeNumberField("serialVersion", 1)
|
||||||
generator.writeStringField("packageName", packageName)
|
generator.writeStringField("packageName", packageName)
|
||||||
generator.writeStringField("name", name)
|
generator.writeStringField("name", name)
|
||||||
|
@ -6,6 +6,7 @@ import android.graphics.drawable.GradientDrawable
|
|||||||
import android.view.Gravity
|
import android.view.Gravity
|
||||||
import android.view.View
|
import android.view.View
|
||||||
import android.view.ViewGroup
|
import android.view.ViewGroup
|
||||||
|
import android.view.animation.AnimationUtils
|
||||||
import android.widget.FrameLayout
|
import android.widget.FrameLayout
|
||||||
import android.widget.ImageView
|
import android.widget.ImageView
|
||||||
import android.widget.ProgressBar
|
import android.widget.ProgressBar
|
||||||
@ -23,6 +24,8 @@ import com.looker.droidify.widget.CursorRecyclerAdapter
|
|||||||
|
|
||||||
class ProductsAdapter(private val onClick: (ProductItem) -> Unit) :
|
class ProductsAdapter(private val onClick: (ProductItem) -> Unit) :
|
||||||
CursorRecyclerAdapter<ProductsAdapter.ViewType, RecyclerView.ViewHolder>() {
|
CursorRecyclerAdapter<ProductsAdapter.ViewType, RecyclerView.ViewHolder>() {
|
||||||
|
private var lastPosition = 0
|
||||||
|
|
||||||
enum class ViewType { PRODUCT, LOADING, EMPTY }
|
enum class ViewType { PRODUCT, LOADING, EMPTY }
|
||||||
|
|
||||||
private class ProductViewHolder(itemView: View) : RecyclerView.ViewHolder(itemView) {
|
private class ProductViewHolder(itemView: View) : RecyclerView.ViewHolder(itemView) {
|
||||||
@ -125,6 +128,11 @@ class ProductsAdapter(private val onClick: (ProductItem) -> Unit) :
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
override fun onViewDetachedFromWindow(holder: RecyclerView.ViewHolder) {
|
||||||
|
super.onViewDetachedFromWindow(holder)
|
||||||
|
holder.itemView.clearAnimation()
|
||||||
|
}
|
||||||
|
|
||||||
override fun onBindViewHolder(holder: RecyclerView.ViewHolder, position: Int) {
|
override fun onBindViewHolder(holder: RecyclerView.ViewHolder, position: Int) {
|
||||||
when (getItemEnumViewType(position)) {
|
when (getItemEnumViewType(position)) {
|
||||||
ViewType.PRODUCT -> {
|
ViewType.PRODUCT -> {
|
||||||
@ -187,5 +195,12 @@ class ProductsAdapter(private val onClick: (ProductItem) -> Unit) :
|
|||||||
holder.text.text = emptyText
|
holder.text.text = emptyText
|
||||||
}
|
}
|
||||||
}::class
|
}::class
|
||||||
|
|
||||||
|
val animation = AnimationUtils.loadAnimation(
|
||||||
|
holder.itemView.context,
|
||||||
|
if (position > lastPosition) R.anim.slide_up else R.anim.slide_down
|
||||||
|
)
|
||||||
|
holder.itemView.startAnimation(animation)
|
||||||
|
lastPosition = holder.adapterPosition
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
10
src/main/res/anim/slide_down.xml
Normal file
10
src/main/res/anim/slide_down.xml
Normal file
@ -0,0 +1,10 @@
|
|||||||
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
|
<set xmlns:android="http://schemas.android.com/apk/res/android"
|
||||||
|
android:shareInterpolator="@android:anim/decelerate_interpolator">
|
||||||
|
<translate
|
||||||
|
android:duration="400"
|
||||||
|
android:fromXDelta="0%"
|
||||||
|
android:fromYDelta="-100%"
|
||||||
|
android:toXDelta="0%"
|
||||||
|
android:toYDelta="0%" />
|
||||||
|
</set>
|
10
src/main/res/anim/slide_up.xml
Normal file
10
src/main/res/anim/slide_up.xml
Normal file
@ -0,0 +1,10 @@
|
|||||||
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
|
<set xmlns:android="http://schemas.android.com/apk/res/android"
|
||||||
|
android:shareInterpolator="@android:anim/decelerate_interpolator">
|
||||||
|
<translate
|
||||||
|
android:duration="400"
|
||||||
|
android:fromXDelta="0%"
|
||||||
|
android:fromYDelta="100%"
|
||||||
|
android:toXDelta="0%"
|
||||||
|
android:toYDelta="0%" />
|
||||||
|
</set>
|
Loading…
x
Reference in New Issue
Block a user