Update: Make List Animation Optional (Closes #53)

This commit is contained in:
LooKeR
2021-10-20 20:13:55 +05:30
parent 84bf96e42e
commit c458e39be7
8 changed files with 41 additions and 7 deletions

View File

@ -14,6 +14,7 @@ import androidx.recyclerview.widget.RecyclerView
import coil.transform.RoundedCornersTransformation
import com.google.android.material.imageview.ShapeableImageView
import com.looker.droidify.R
import com.looker.droidify.content.Preferences
import com.looker.droidify.database.Database
import com.looker.droidify.entity.ProductItem
import com.looker.droidify.entity.Repository
@ -131,7 +132,9 @@ class ProductsAdapter(private val onClick: (ProductItem) -> Unit) :
override fun onViewDetachedFromWindow(holder: RecyclerView.ViewHolder) {
super.onViewDetachedFromWindow(holder)
holder.itemView.clearAnimation()
if (Preferences[Preferences.Key.ListAnimation]) {
holder.itemView.clearAnimation()
}
}
override fun onBindViewHolder(holder: RecyclerView.ViewHolder, position: Int) {
@ -197,12 +200,17 @@ class ProductsAdapter(private val onClick: (ProductItem) -> Unit) :
holder.text.text = emptyText
}
}::class
if (Preferences[Preferences.Key.ListAnimation]) {
setAnimation(holder.itemView, holder.adapterPosition)
}
}
private fun setAnimation(itemView: View, position: Int) {
val animation = AnimationUtils.loadAnimation(
holder.itemView.context,
itemView.context,
if (position > lastPosition) R.anim.slide_up else R.anim.slide_down
)
holder.itemView.startAnimation(animation)
lastPosition = holder.adapterPosition
itemView.startAnimation(animation)
lastPosition = position
}
}
}

View File

@ -114,6 +114,10 @@ class SettingsFragment : ScreenFragment() {
is Preferences.Theme.Amoled -> getString(R.string.amoled)
}
}
addSwitch(
Preferences.Key.ListAnimation, getString(R.string.list_animation),
getString(R.string.list_animation_description)
)
}
preferences.addCategory(getString(R.string.install_types)) {
addSwitch(