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