mirror of
https://github.com/libre-tube/LibreTube.git
synced 2024-12-14 22:30:30 +05:30
refactor: Use parcelable extensions with channel tabs
This commit is contained in:
parent
282e7bd5c9
commit
d11b7b17b9
@ -1,9 +1,12 @@
|
|||||||
package com.github.libretube.api.obj
|
package com.github.libretube.api.obj
|
||||||
|
|
||||||
|
import android.os.Parcelable
|
||||||
|
import kotlinx.parcelize.Parcelize
|
||||||
import kotlinx.serialization.Serializable
|
import kotlinx.serialization.Serializable
|
||||||
|
|
||||||
@Serializable
|
@Serializable
|
||||||
|
@Parcelize
|
||||||
data class ChannelTab(
|
data class ChannelTab(
|
||||||
val name: String,
|
val name: String,
|
||||||
val data: String
|
val data: String
|
||||||
)
|
) : Parcelable
|
||||||
|
@ -19,6 +19,8 @@ import com.github.libretube.constants.IntentData
|
|||||||
import com.github.libretube.databinding.FragmentChannelContentBinding
|
import com.github.libretube.databinding.FragmentChannelContentBinding
|
||||||
import com.github.libretube.extensions.TAG
|
import com.github.libretube.extensions.TAG
|
||||||
import com.github.libretube.extensions.ceilHalf
|
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.SearchChannelAdapter
|
||||||
import com.github.libretube.ui.adapters.VideosAdapter
|
import com.github.libretube.ui.adapters.VideosAdapter
|
||||||
import com.github.libretube.ui.base.DynamicLayoutManagerFragment
|
import com.github.libretube.ui.base.DynamicLayoutManagerFragment
|
||||||
@ -121,12 +123,11 @@ class ChannelContentFragment : DynamicLayoutManagerFragment() {
|
|||||||
|
|
||||||
override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
|
override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
|
||||||
super.onViewCreated(view, savedInstanceState)
|
super.onViewCreated(view, savedInstanceState)
|
||||||
val tabData = kotlin.runCatching {
|
|
||||||
Json.decodeFromString<ChannelTab>(arguments?.getString(IntentData.tabData) ?: "")
|
|
||||||
}.getOrNull()
|
|
||||||
|
|
||||||
channelId = arguments?.getString(IntentData.channelId)
|
val arguments = requireArguments()
|
||||||
nextPage = arguments?.getString(IntentData.nextPage)
|
val tabData = arguments.parcelable<ChannelTab>(IntentData.tabData)
|
||||||
|
channelId = arguments.getString(IntentData.channelId)
|
||||||
|
nextPage = arguments.getString(IntentData.nextPage)
|
||||||
|
|
||||||
binding.channelRecView.addOnScrollListener(object : RecyclerView.OnScrollListener() {
|
binding.channelRecView.addOnScrollListener(object : RecyclerView.OnScrollListener() {
|
||||||
override fun onScrollStateChanged(recyclerView: RecyclerView, newState: Int) {
|
override fun onScrollStateChanged(recyclerView: RecyclerView, newState: Int) {
|
||||||
@ -151,12 +152,8 @@ class ChannelContentFragment : DynamicLayoutManagerFragment() {
|
|||||||
})
|
})
|
||||||
|
|
||||||
if (tabData?.data.isNullOrEmpty()) {
|
if (tabData?.data.isNullOrEmpty()) {
|
||||||
val videoDataString = arguments?.getString(IntentData.videoList)
|
|
||||||
val videos = runCatching {
|
|
||||||
Json.decodeFromString<List<StreamItem>>(videoDataString!!)
|
|
||||||
}.getOrElse { mutableListOf() }
|
|
||||||
channelAdapter = VideosAdapter(
|
channelAdapter = VideosAdapter(
|
||||||
videos.toMutableList(),
|
arguments.parcelableArrayList<StreamItem>(IntentData.videoList)!!,
|
||||||
forceMode = VideosAdapter.Companion.LayoutMode.CHANNEL_ROW
|
forceMode = VideosAdapter.Companion.LayoutMode.CHANNEL_ROW
|
||||||
)
|
)
|
||||||
binding.channelRecView.adapter = channelAdapter
|
binding.channelRecView.adapter = channelAdapter
|
||||||
|
@ -260,8 +260,8 @@ class ChannelContentAdapter(
|
|||||||
|
|
||||||
override fun createFragment(position: Int) = ChannelContentFragment().apply {
|
override fun createFragment(position: Int) = ChannelContentFragment().apply {
|
||||||
arguments = bundleOf(
|
arguments = bundleOf(
|
||||||
IntentData.tabData to Json.encodeToString(list[position]),
|
IntentData.tabData to list[position],
|
||||||
IntentData.videoList to Json.encodeToString(videos),
|
IntentData.videoList to videos.toMutableList(),
|
||||||
IntentData.channelId to channelId,
|
IntentData.channelId to channelId,
|
||||||
IntentData.nextPage to nextPage
|
IntentData.nextPage to nextPage
|
||||||
)
|
)
|
||||||
|
Loading…
Reference in New Issue
Block a user