2019-04-28 22:43:54 +02:00
|
|
|
package org.schabi.newpipe.local.subscription.item
|
|
|
|
|
|
|
|
import android.view.View
|
2020-11-28 09:38:24 +01:00
|
|
|
import androidx.core.view.isGone
|
2020-10-17 12:24:35 +02:00
|
|
|
import androidx.core.view.isVisible
|
2020-11-28 09:38:24 +01:00
|
|
|
import com.xwray.groupie.viewbinding.BindableItem
|
|
|
|
import com.xwray.groupie.viewbinding.GroupieViewHolder
|
2019-04-28 22:43:54 +02:00
|
|
|
import org.schabi.newpipe.R
|
|
|
|
import org.schabi.newpipe.database.subscription.SubscriptionEntity
|
2020-11-28 09:38:24 +01:00
|
|
|
import org.schabi.newpipe.databinding.PickerSubscriptionItemBinding
|
2021-01-16 04:32:01 +01:00
|
|
|
import org.schabi.newpipe.ktx.AnimationType
|
|
|
|
import org.schabi.newpipe.ktx.animate
|
2023-05-02 11:08:32 +02:00
|
|
|
import org.schabi.newpipe.util.image.PicassoHelper
|
2019-04-28 22:43:54 +02:00
|
|
|
|
2020-04-05 21:25:44 +02:00
|
|
|
data class PickerSubscriptionItem(
|
|
|
|
val subscriptionEntity: SubscriptionEntity,
|
|
|
|
var isSelected: Boolean = false
|
2020-11-28 09:38:24 +01:00
|
|
|
) : BindableItem<PickerSubscriptionItemBinding>() {
|
2020-04-05 21:25:44 +02:00
|
|
|
override fun getId(): Long = subscriptionEntity.uid
|
2019-04-28 22:43:54 +02:00
|
|
|
override fun getLayout(): Int = R.layout.picker_subscription_item
|
2020-04-05 21:25:44 +02:00
|
|
|
override fun getSpanSize(spanCount: Int, position: Int): Int = 1
|
2019-04-28 22:43:54 +02:00
|
|
|
|
2020-11-28 09:38:24 +01:00
|
|
|
override fun bind(viewBinding: PickerSubscriptionItemBinding, position: Int) {
|
2021-03-27 14:37:44 +01:00
|
|
|
PicassoHelper.loadAvatar(subscriptionEntity.avatarUrl).into(viewBinding.thumbnailView)
|
2020-11-28 09:38:24 +01:00
|
|
|
viewBinding.titleView.text = subscriptionEntity.name
|
|
|
|
viewBinding.selectedHighlight.isVisible = isSelected
|
2019-04-28 22:43:54 +02:00
|
|
|
}
|
|
|
|
|
2020-11-28 09:38:24 +01:00
|
|
|
override fun unbind(viewHolder: GroupieViewHolder<PickerSubscriptionItemBinding>) {
|
2019-04-28 22:43:54 +02:00
|
|
|
super.unbind(viewHolder)
|
|
|
|
|
2020-11-28 09:38:24 +01:00
|
|
|
viewHolder.binding.selectedHighlight.apply {
|
|
|
|
animate().setListener(null).cancel()
|
|
|
|
isGone = true
|
|
|
|
alpha = 1F
|
|
|
|
}
|
2019-04-28 22:43:54 +02:00
|
|
|
}
|
|
|
|
|
2020-11-28 09:38:24 +01:00
|
|
|
override fun initializeViewBinding(view: View) = PickerSubscriptionItemBinding.bind(view)
|
|
|
|
|
2020-04-05 21:25:44 +02:00
|
|
|
fun updateSelected(containerView: View, isSelected: Boolean) {
|
|
|
|
this.isSelected = isSelected
|
2020-11-28 09:38:24 +01:00
|
|
|
PickerSubscriptionItemBinding.bind(containerView).selectedHighlight
|
2021-01-17 05:21:11 +01:00
|
|
|
.animate(isSelected, 150, AnimationType.LIGHT_SCALE_AND_ALPHA)
|
2019-04-28 22:43:54 +02:00
|
|
|
}
|
2020-05-01 20:13:01 +02:00
|
|
|
}
|