refactor: Use parcelable extensions with channel tabs

This commit is contained in:
Isira Seneviratne 2024-06-15 05:47:52 +05:30
parent 282e7bd5c9
commit d11b7b17b9
3 changed files with 13 additions and 13 deletions

View File

@ -1,9 +1,12 @@
package com.github.libretube.api.obj
import android.os.Parcelable
import kotlinx.parcelize.Parcelize
import kotlinx.serialization.Serializable
@Serializable
@Parcelize
data class ChannelTab(
val name: String,
val data: String
)
) : Parcelable

View File

@ -19,6 +19,8 @@ import com.github.libretube.constants.IntentData
import com.github.libretube.databinding.FragmentChannelContentBinding
import com.github.libretube.extensions.TAG
import com.github.libretube.extensions.ceilHalf
import com.github.libretube.extensions.parcelable
import com.github.libretube.extensions.parcelableArrayList
import com.github.libretube.ui.adapters.SearchChannelAdapter
import com.github.libretube.ui.adapters.VideosAdapter
import com.github.libretube.ui.base.DynamicLayoutManagerFragment
@ -121,12 +123,11 @@ class ChannelContentFragment : DynamicLayoutManagerFragment() {
override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
super.onViewCreated(view, savedInstanceState)
val tabData = kotlin.runCatching {
Json.decodeFromString<ChannelTab>(arguments?.getString(IntentData.tabData) ?: "")
}.getOrNull()
channelId = arguments?.getString(IntentData.channelId)
nextPage = arguments?.getString(IntentData.nextPage)
val arguments = requireArguments()
val tabData = arguments.parcelable<ChannelTab>(IntentData.tabData)
channelId = arguments.getString(IntentData.channelId)
nextPage = arguments.getString(IntentData.nextPage)
binding.channelRecView.addOnScrollListener(object : RecyclerView.OnScrollListener() {
override fun onScrollStateChanged(recyclerView: RecyclerView, newState: Int) {
@ -151,12 +152,8 @@ class ChannelContentFragment : DynamicLayoutManagerFragment() {
})
if (tabData?.data.isNullOrEmpty()) {
val videoDataString = arguments?.getString(IntentData.videoList)
val videos = runCatching {
Json.decodeFromString<List<StreamItem>>(videoDataString!!)
}.getOrElse { mutableListOf() }
channelAdapter = VideosAdapter(
videos.toMutableList(),
arguments.parcelableArrayList<StreamItem>(IntentData.videoList)!!,
forceMode = VideosAdapter.Companion.LayoutMode.CHANNEL_ROW
)
binding.channelRecView.adapter = channelAdapter

View File

@ -260,8 +260,8 @@ class ChannelContentAdapter(
override fun createFragment(position: Int) = ChannelContentFragment().apply {
arguments = bundleOf(
IntentData.tabData to Json.encodeToString(list[position]),
IntentData.videoList to Json.encodeToString(videos),
IntentData.tabData to list[position],
IntentData.videoList to videos.toMutableList(),
IntentData.channelId to channelId,
IntentData.nextPage to nextPage
)