Use the base Groupie library in ChannelItem.
This commit is contained in:
parent
e0de66b1be
commit
01396923f1
3 changed files with 20 additions and 16 deletions
|
@ -19,9 +19,9 @@ import androidx.lifecycle.ViewModelProvider
|
||||||
import androidx.recyclerview.widget.GridLayoutManager
|
import androidx.recyclerview.widget.GridLayoutManager
|
||||||
import androidx.recyclerview.widget.RecyclerView
|
import androidx.recyclerview.widget.RecyclerView
|
||||||
import com.xwray.groupie.GroupAdapter
|
import com.xwray.groupie.GroupAdapter
|
||||||
|
import com.xwray.groupie.GroupieViewHolder
|
||||||
import com.xwray.groupie.OnItemClickListener
|
import com.xwray.groupie.OnItemClickListener
|
||||||
import com.xwray.groupie.Section
|
import com.xwray.groupie.Section
|
||||||
import com.xwray.groupie.kotlinandroidextensions.GroupieViewHolder
|
|
||||||
import icepick.Icepick
|
import icepick.Icepick
|
||||||
import icepick.State
|
import icepick.State
|
||||||
import org.schabi.newpipe.R
|
import org.schabi.newpipe.R
|
||||||
|
|
|
@ -12,8 +12,8 @@ import androidx.recyclerview.widget.ItemTouchHelper.SimpleCallback
|
||||||
import androidx.recyclerview.widget.LinearLayoutManager
|
import androidx.recyclerview.widget.LinearLayoutManager
|
||||||
import androidx.recyclerview.widget.RecyclerView
|
import androidx.recyclerview.widget.RecyclerView
|
||||||
import com.xwray.groupie.GroupAdapter
|
import com.xwray.groupie.GroupAdapter
|
||||||
|
import com.xwray.groupie.GroupieViewHolder
|
||||||
import com.xwray.groupie.TouchCallback
|
import com.xwray.groupie.TouchCallback
|
||||||
import com.xwray.groupie.kotlinandroidextensions.GroupieViewHolder
|
|
||||||
import icepick.Icepick
|
import icepick.Icepick
|
||||||
import icepick.State
|
import icepick.State
|
||||||
import org.schabi.newpipe.R
|
import org.schabi.newpipe.R
|
||||||
|
|
|
@ -1,13 +1,11 @@
|
||||||
package org.schabi.newpipe.local.subscription.item
|
package org.schabi.newpipe.local.subscription.item
|
||||||
|
|
||||||
import android.content.Context
|
import android.content.Context
|
||||||
|
import android.widget.ImageView
|
||||||
|
import android.widget.TextView
|
||||||
import com.nostra13.universalimageloader.core.ImageLoader
|
import com.nostra13.universalimageloader.core.ImageLoader
|
||||||
import com.xwray.groupie.kotlinandroidextensions.GroupieViewHolder
|
import com.xwray.groupie.GroupieViewHolder
|
||||||
import com.xwray.groupie.kotlinandroidextensions.Item
|
import com.xwray.groupie.Item
|
||||||
import kotlinx.android.synthetic.main.list_channel_item.itemAdditionalDetails
|
|
||||||
import kotlinx.android.synthetic.main.list_channel_item.itemChannelDescriptionView
|
|
||||||
import kotlinx.android.synthetic.main.list_channel_item.itemThumbnailView
|
|
||||||
import kotlinx.android.synthetic.main.list_channel_item.itemTitleView
|
|
||||||
import org.schabi.newpipe.R
|
import org.schabi.newpipe.R
|
||||||
import org.schabi.newpipe.extractor.channel.ChannelInfoItem
|
import org.schabi.newpipe.extractor.channel.ChannelInfoItem
|
||||||
import org.schabi.newpipe.util.ImageDisplayConstants
|
import org.schabi.newpipe.util.ImageDisplayConstants
|
||||||
|
@ -19,8 +17,7 @@ class ChannelItem(
|
||||||
private val subscriptionId: Long = -1L,
|
private val subscriptionId: Long = -1L,
|
||||||
var itemVersion: ItemVersion = ItemVersion.NORMAL,
|
var itemVersion: ItemVersion = ItemVersion.NORMAL,
|
||||||
var gesturesListener: OnClickGesture<ChannelInfoItem>? = null
|
var gesturesListener: OnClickGesture<ChannelInfoItem>? = null
|
||||||
) : Item() {
|
) : Item<GroupieViewHolder>() {
|
||||||
|
|
||||||
override fun getId(): Long = if (subscriptionId == -1L) super.getId() else subscriptionId
|
override fun getId(): Long = if (subscriptionId == -1L) super.getId() else subscriptionId
|
||||||
|
|
||||||
enum class ItemVersion { NORMAL, MINI, GRID }
|
enum class ItemVersion { NORMAL, MINI, GRID }
|
||||||
|
@ -32,18 +29,25 @@ class ChannelItem(
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun bind(viewHolder: GroupieViewHolder, position: Int) {
|
override fun bind(viewHolder: GroupieViewHolder, position: Int) {
|
||||||
viewHolder.itemTitleView.text = infoItem.name
|
val itemTitleView = viewHolder.root.findViewById<TextView>(R.id.itemTitleView)
|
||||||
viewHolder.itemAdditionalDetails.text = getDetailLine(viewHolder.root.context)
|
val itemAdditionalDetails = viewHolder.root.findViewById<TextView>(R.id.itemAdditionalDetails)
|
||||||
if (itemVersion == ItemVersion.NORMAL) viewHolder.itemChannelDescriptionView.text = infoItem.description
|
val itemChannelDescriptionView = viewHolder.root.findViewById<TextView>(R.id.itemChannelDescriptionView)
|
||||||
|
val itemThumbnailView = viewHolder.root.findViewById<ImageView>(R.id.itemThumbnailView)
|
||||||
|
|
||||||
|
itemTitleView.text = infoItem.name
|
||||||
|
itemAdditionalDetails.text = getDetailLine(viewHolder.root.context)
|
||||||
|
if (itemVersion == ItemVersion.NORMAL) {
|
||||||
|
itemChannelDescriptionView.text = infoItem.description
|
||||||
|
}
|
||||||
|
|
||||||
ImageLoader.getInstance().displayImage(
|
ImageLoader.getInstance().displayImage(
|
||||||
infoItem.thumbnailUrl, viewHolder.itemThumbnailView,
|
infoItem.thumbnailUrl, itemThumbnailView,
|
||||||
ImageDisplayConstants.DISPLAY_THUMBNAIL_OPTIONS
|
ImageDisplayConstants.DISPLAY_THUMBNAIL_OPTIONS
|
||||||
)
|
)
|
||||||
|
|
||||||
gesturesListener?.run {
|
gesturesListener?.run {
|
||||||
viewHolder.containerView.setOnClickListener { selected(infoItem) }
|
viewHolder.root.setOnClickListener { selected(infoItem) }
|
||||||
viewHolder.containerView.setOnLongClickListener { held(infoItem); true }
|
viewHolder.root.setOnLongClickListener { held(infoItem); true }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue