hopefully fixed ocean-16 (Made actors clickable)

This commit is contained in:
LagradOst 2022-04-28 01:25:01 +02:00
parent d60b685f7e
commit 7e9fa1ec41
4 changed files with 55 additions and 21 deletions

View file

@ -14,9 +14,13 @@ import com.lagradost.cloudstream3.R
import com.lagradost.cloudstream3.utils.UIHelper.setImage
import kotlinx.android.synthetic.main.cast_item.view.*
class ActorAdaptor(
private val actors: MutableList<ActorData>,
) : RecyclerView.Adapter<RecyclerView.ViewHolder>() {
class ActorAdaptor() : RecyclerView.Adapter<RecyclerView.ViewHolder>() {
data class ActorMetaData(
var isInverted: Boolean,
val actor: ActorData,
)
private val actors: MutableList<ActorMetaData> = mutableListOf()
override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): RecyclerView.ViewHolder {
return CardViewHolder(
@ -27,7 +31,10 @@ class ActorAdaptor(
override fun onBindViewHolder(holder: RecyclerView.ViewHolder, position: Int) {
when (holder) {
is CardViewHolder -> {
holder.bind(actors[position])
holder.bind(actors[position].actor, actors[position].isInverted, position) {
actors[position].isInverted = !actors[position].isInverted
this.notifyItemChanged(position)
}
}
}
}
@ -36,7 +43,7 @@ class ActorAdaptor(
return actors.size
}
fun updateList(newList: List<ActorData>) {
private fun updateActorList(newList: List<ActorMetaData>) {
val diffResult = DiffUtil.calculateDiff(
ActorDiffCallback(this.actors, newList)
)
@ -47,6 +54,18 @@ class ActorAdaptor(
diffResult.dispatchUpdatesTo(this)
}
fun updateList(newList: List<ActorData>) {
if (actors.size >= newList.size) {
updateActorList(newList.mapIndexed { i, data -> actors[i].copy(actor = data) })
} else {
updateActorList(newList.mapIndexed { i, data ->
if (i < actors.size)
actors[i].copy(actor = data)
else ActorMetaData(isInverted = false, actor = data)
})
}
}
private class CardViewHolder
constructor(
itemView: View,
@ -59,10 +78,21 @@ class ActorAdaptor(
private val voiceActorImageHolder: View = itemView.voice_actor_image_holder
private val voiceActorName: TextView = itemView.voice_actor_name
fun bind(card: ActorData) {
actorImage.setImage(card.actor.image)
actorName.text = card.actor.name
card.role?.let {
fun bind(actor: ActorData, isInverted: Boolean, position: Int, callback: (Int) -> Unit) {
val (mainImg, vaImage) = if (!isInverted || actor.voiceActor?.image.isNullOrBlank()) {
Pair(actor.actor.image, actor.voiceActor?.image)
} else {
Pair(actor.voiceActor?.image, actor.actor.image)
}
itemView.setOnClickListener {
callback(position)
}
actorImage.setImage(mainImg)
actorName.text = actor.actor.name
actor.role?.let {
actorExtra.context?.getString(
when (it) {
ActorRole.Main -> {
@ -79,31 +109,31 @@ class ActorAdaptor(
actorExtra.isVisible = true
actorExtra.text = text
}
} ?: card.roleString?.let {
} ?: actor.roleString?.let {
actorExtra.isVisible = true
actorExtra.text = it
} ?: run {
actorExtra.isVisible = false
}
if (card.voiceActor == null) {
if (actor.voiceActor == null) {
voiceActorImageHolder.isVisible = false
voiceActorName.isVisible = false
} else {
voiceActorName.text = card.voiceActor.name
voiceActorImageHolder.isVisible = voiceActorImage.setImage(card.voiceActor.image)
voiceActorName.text = actor.voiceActor.name
voiceActorImageHolder.isVisible = voiceActorImage.setImage(vaImage)
}
}
}
}
class ActorDiffCallback(
private val oldList: List<ActorData>,
private val newList: List<ActorData>
private val oldList: List<ActorAdaptor.ActorMetaData>,
private val newList: List<ActorAdaptor.ActorMetaData>
) :
DiffUtil.Callback() {
override fun areItemsTheSame(oldItemPosition: Int, newItemPosition: Int) =
oldList[oldItemPosition].actor.name == newList[newItemPosition].actor.name
oldList[oldItemPosition].actor.actor.name == newList[newItemPosition].actor.actor.name
override fun getOldListSize() = oldList.size

View file

@ -673,7 +673,7 @@ class ResultFragment : Fragment(), PanelsChildGestureRegionObserver.GestureRegio
result_cast_items?.let {
PanelsChildGestureRegionObserver.Provider.get().register(it)
}
result_cast_items?.adapter = ActorAdaptor(mutableListOf())
result_cast_items?.adapter = ActorAdaptor()
fixGrid()
result_recommendations?.spanCount = 3
result_overlapping_panels?.setStartPanelLockState(OverlappingPanelsLayout.LockState.CLOSE)

View file

@ -6,15 +6,16 @@
android:nextFocusLeft="@id/episode_poster"
android:nextFocusRight="@id/result_episode_download"
android:id="@+id/episode_holder"
app:cardElevation="0dp"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
app:cardCornerRadius="@dimen/rounded_image_radius"
app:cardBackgroundColor="?attr/primaryBlackBackground"
app:cardBackgroundColor="@color/transparent"
android:foreground="@drawable/outline_drawable"
android:layout_marginEnd="10dp">
android:layout_margin="5dp">
<LinearLayout
android:padding="5dp"
android:layout_width="100dp"
android:orientation="vertical"
android:layout_height="wrap_content">

View file

@ -392,7 +392,7 @@
android:nextFocusRight="@id/result_search"
android:nextFocusUp="@id/result_description"
android:nextFocusDown="@id/result_play_movie"
android:nextFocusDown="@id/result_cast_items"
android:paddingTop="0dp"
app:cornerRadius="4dp"
app:icon="@drawable/ic_baseline_bookmark_24"
@ -411,6 +411,9 @@
tools:text="Cast: Joe Ligma" />
<androidx.recyclerview.widget.RecyclerView
android:nextFocusUp="@id/result_bookmark_button"
android:nextFocusDown="@id/result_play_movie"
android:id="@+id/result_cast_items"
android:layout_width="match_parent"
android:descendantFocusability="afterDescendants"