From c8e8d3b5ce6d879490af2561f4e317c57b8db414 Mon Sep 17 00:00:00 2001 From: Isira Seneviratne Date: Tue, 20 Jun 2023 05:18:56 +0530 Subject: [PATCH] Make the Comment class parcelable. --- .../main/java/com/github/libretube/api/obj/Comment.kt | 5 ++++- .../github/libretube/ui/adapters/CommentsAdapter.kt | 7 +------ .../libretube/ui/fragments/CommentsRepliesFragment.kt | 10 ++++------ 3 files changed, 9 insertions(+), 13 deletions(-) diff --git a/app/src/main/java/com/github/libretube/api/obj/Comment.kt b/app/src/main/java/com/github/libretube/api/obj/Comment.kt index 4e40a17b1..8bfd29f3c 100644 --- a/app/src/main/java/com/github/libretube/api/obj/Comment.kt +++ b/app/src/main/java/com/github/libretube/api/obj/Comment.kt @@ -1,8 +1,11 @@ package com.github.libretube.api.obj +import android.os.Parcelable +import kotlinx.parcelize.Parcelize import kotlinx.serialization.Serializable @Serializable +@Parcelize data class Comment( val author: String, val commentId: String, @@ -16,4 +19,4 @@ data class Comment( val thumbnail: String, val verified: Boolean, val replyCount: Long, -) +) : Parcelable diff --git a/app/src/main/java/com/github/libretube/ui/adapters/CommentsAdapter.kt b/app/src/main/java/com/github/libretube/ui/adapters/CommentsAdapter.kt index 3689fe7b4..8311f71e9 100644 --- a/app/src/main/java/com/github/libretube/ui/adapters/CommentsAdapter.kt +++ b/app/src/main/java/com/github/libretube/ui/adapters/CommentsAdapter.kt @@ -17,7 +17,6 @@ import androidx.fragment.app.commit import androidx.fragment.app.replace import androidx.recyclerview.widget.RecyclerView import com.github.libretube.R -import com.github.libretube.api.JsonHelper import com.github.libretube.api.obj.Comment import com.github.libretube.constants.IntentData import com.github.libretube.databinding.CommentsRowBinding @@ -31,7 +30,6 @@ import com.github.libretube.ui.viewholders.CommentsViewHolder import com.github.libretube.util.HtmlParser import com.github.libretube.util.LinkHandler import com.github.libretube.util.TextUtils -import kotlinx.serialization.encodeToString class CommentsAdapter( private val fragment: Fragment?, @@ -61,10 +59,7 @@ class CommentsAdapter( } private fun navigateToReplies(comment: Comment) { - val args = bundleOf( - IntentData.videoId to videoId, - IntentData.comment to JsonHelper.json.encodeToString(comment), - ) + val args = bundleOf(IntentData.videoId to videoId, IntentData.comment to comment) fragment!!.parentFragmentManager.commit { replace(R.id.commentFragContainer, args = args) addToBackStack(null) diff --git a/app/src/main/java/com/github/libretube/ui/fragments/CommentsRepliesFragment.kt b/app/src/main/java/com/github/libretube/ui/fragments/CommentsRepliesFragment.kt index 4e359b34b..8f7503362 100644 --- a/app/src/main/java/com/github/libretube/ui/fragments/CommentsRepliesFragment.kt +++ b/app/src/main/java/com/github/libretube/ui/fragments/CommentsRepliesFragment.kt @@ -10,13 +10,13 @@ import androidx.fragment.app.Fragment import androidx.fragment.app.activityViewModels import androidx.lifecycle.lifecycleScope import androidx.recyclerview.widget.LinearLayoutManager -import com.github.libretube.api.JsonHelper import com.github.libretube.api.RetrofitInstance import com.github.libretube.api.obj.Comment import com.github.libretube.api.obj.CommentsPage import com.github.libretube.constants.IntentData import com.github.libretube.databinding.FragmentCommentsBinding import com.github.libretube.extensions.TAG +import com.github.libretube.extensions.parcelable import com.github.libretube.ui.adapters.CommentsAdapter import com.github.libretube.ui.extensions.filterNonEmptyComments import com.github.libretube.ui.models.CommentsViewModel @@ -45,11 +45,9 @@ class CommentsRepliesFragment : Fragment() { override fun onViewCreated(view: View, savedInstanceState: Bundle?) { super.onViewCreated(view, savedInstanceState) - val videoId = arguments?.getString(IntentData.videoId) ?: "" - val comment = JsonHelper.json.decodeFromString( - Comment.serializer(), - arguments?.getString(IntentData.comment)!!, - ) + val arguments = requireArguments() + val videoId = arguments.getString(IntentData.videoId, "") + val comment = arguments.parcelable(IntentData.comment)!! repliesAdapter = CommentsAdapter( null,