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

View file

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

View file

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

View file

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