1
0
mirror of https://github.com/TeamNewPipe/NewPipe synced 2024-12-23 08:30:44 +00:00

Use BindableItem in PickerSubscriptionItem.

This commit is contained in:
Isira Seneviratne 2020-11-28 14:08:24 +05:30
parent e2dd058430
commit 77675b361f

View File

@ -1,14 +1,14 @@
package org.schabi.newpipe.local.subscription.item
import android.view.View
import androidx.core.view.isGone
import androidx.core.view.isVisible
import com.nostra13.universalimageloader.core.ImageLoader
import com.xwray.groupie.kotlinandroidextensions.GroupieViewHolder
import com.xwray.groupie.kotlinandroidextensions.Item
import kotlinx.android.synthetic.main.picker_subscription_item.*
import kotlinx.android.synthetic.main.picker_subscription_item.view.*
import com.xwray.groupie.viewbinding.BindableItem
import com.xwray.groupie.viewbinding.GroupieViewHolder
import org.schabi.newpipe.R
import org.schabi.newpipe.database.subscription.SubscriptionEntity
import org.schabi.newpipe.databinding.PickerSubscriptionItemBinding
import org.schabi.newpipe.ktx.AnimationType
import org.schabi.newpipe.ktx.animate
import org.schabi.newpipe.util.ImageDisplayConstants
@ -16,31 +16,36 @@ import org.schabi.newpipe.util.ImageDisplayConstants
data class PickerSubscriptionItem(
val subscriptionEntity: SubscriptionEntity,
var isSelected: Boolean = false
) : Item() {
) : BindableItem<PickerSubscriptionItemBinding>() {
override fun getId(): Long = subscriptionEntity.uid
override fun getLayout(): Int = R.layout.picker_subscription_item
override fun getSpanSize(spanCount: Int, position: Int): Int = 1
override fun bind(viewHolder: GroupieViewHolder, position: Int) {
override fun bind(viewBinding: PickerSubscriptionItemBinding, position: Int) {
ImageLoader.getInstance().displayImage(
subscriptionEntity.avatarUrl,
viewHolder.thumbnail_view, ImageDisplayConstants.DISPLAY_AVATAR_OPTIONS
viewBinding.thumbnailView, ImageDisplayConstants.DISPLAY_AVATAR_OPTIONS
)
viewHolder.title_view.text = subscriptionEntity.name
viewHolder.selected_highlight.isVisible = isSelected
viewBinding.titleView.text = subscriptionEntity.name
viewBinding.selectedHighlight.isVisible = isSelected
}
override fun unbind(viewHolder: GroupieViewHolder) {
override fun unbind(viewHolder: GroupieViewHolder<PickerSubscriptionItemBinding>) {
super.unbind(viewHolder)
viewHolder.selected_highlight.animate().setListener(null).cancel()
viewHolder.selected_highlight.visibility = View.GONE
viewHolder.selected_highlight.alpha = 1F
viewHolder.binding.selectedHighlight.apply {
animate().setListener(null).cancel()
isGone = true
alpha = 1F
}
}
override fun initializeViewBinding(view: View) = PickerSubscriptionItemBinding.bind(view)
fun updateSelected(containerView: View, isSelected: Boolean) {
this.isSelected = isSelected
containerView.selected_highlight.animate(isSelected, 150, AnimationType.LIGHT_SCALE_AND_ALPHA)
PickerSubscriptionItemBinding.bind(containerView).selectedHighlight
.animate(isSelected, 150, AnimationType.LIGHT_SCALE_AND_ALPHA)
}
}