From d11b7b17b957d49e52403a8b5049b9f9dbf7baba Mon Sep 17 00:00:00 2001 From: Isira Seneviratne Date: Sat, 15 Jun 2024 05:47:52 +0530 Subject: [PATCH] refactor: Use parcelable extensions with channel tabs --- .../com/github/libretube/api/obj/ChannelTab.kt | 5 ++++- .../ui/fragments/ChannelContentFragment.kt | 17 +++++++---------- .../libretube/ui/fragments/ChannelFragment.kt | 4 ++-- 3 files changed, 13 insertions(+), 13 deletions(-) diff --git a/app/src/main/java/com/github/libretube/api/obj/ChannelTab.kt b/app/src/main/java/com/github/libretube/api/obj/ChannelTab.kt index 14e0f86cf..238ae3b42 100644 --- a/app/src/main/java/com/github/libretube/api/obj/ChannelTab.kt +++ b/app/src/main/java/com/github/libretube/api/obj/ChannelTab.kt @@ -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 diff --git a/app/src/main/java/com/github/libretube/ui/fragments/ChannelContentFragment.kt b/app/src/main/java/com/github/libretube/ui/fragments/ChannelContentFragment.kt index 00725c309..7e5d53a2d 100644 --- a/app/src/main/java/com/github/libretube/ui/fragments/ChannelContentFragment.kt +++ b/app/src/main/java/com/github/libretube/ui/fragments/ChannelContentFragment.kt @@ -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(arguments?.getString(IntentData.tabData) ?: "") - }.getOrNull() - channelId = arguments?.getString(IntentData.channelId) - nextPage = arguments?.getString(IntentData.nextPage) + val arguments = requireArguments() + val tabData = arguments.parcelable(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>(videoDataString!!) - }.getOrElse { mutableListOf() } channelAdapter = VideosAdapter( - videos.toMutableList(), + arguments.parcelableArrayList(IntentData.videoList)!!, forceMode = VideosAdapter.Companion.LayoutMode.CHANNEL_ROW ) binding.channelRecView.adapter = channelAdapter diff --git a/app/src/main/java/com/github/libretube/ui/fragments/ChannelFragment.kt b/app/src/main/java/com/github/libretube/ui/fragments/ChannelFragment.kt index e25937fcd..a23b43704 100644 --- a/app/src/main/java/com/github/libretube/ui/fragments/ChannelFragment.kt +++ b/app/src/main/java/com/github/libretube/ui/fragments/ChannelFragment.kt @@ -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 )