mirror of
				https://github.com/recloudstream/cloudstream.git
				synced 2024-08-15 01:53:11 +00:00 
			
		
		
		
	hopefully fixed ocean-16 (Made actors clickable)
This commit is contained in:
		
							parent
							
								
									d60b685f7e
								
							
						
					
					
						commit
						7e9fa1ec41
					
				
					 4 changed files with 55 additions and 21 deletions
				
			
		| 
						 | 
				
			
			@ -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
 | 
			
		||||
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -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)
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -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">
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -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"
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue