mirror of
https://github.com/libre-tube/LibreTube.git
synced 2024-12-15 06:40:30 +05:30
Merge pull request #4056 from Isira-Seneviratne/Comment_Parcelable
Make the Comment class parcelable
This commit is contained in:
commit
0627a6760f
@ -1,8 +1,11 @@
|
|||||||
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 Comment(
|
data class Comment(
|
||||||
val author: String,
|
val author: String,
|
||||||
val commentId: String,
|
val commentId: String,
|
||||||
@ -16,4 +19,4 @@ data class Comment(
|
|||||||
val thumbnail: String,
|
val thumbnail: String,
|
||||||
val verified: Boolean,
|
val verified: Boolean,
|
||||||
val replyCount: Long,
|
val replyCount: Long,
|
||||||
)
|
) : Parcelable
|
||||||
|
@ -17,7 +17,6 @@ import androidx.fragment.app.commit
|
|||||||
import androidx.fragment.app.replace
|
import androidx.fragment.app.replace
|
||||||
import androidx.recyclerview.widget.RecyclerView
|
import androidx.recyclerview.widget.RecyclerView
|
||||||
import com.github.libretube.R
|
import com.github.libretube.R
|
||||||
import com.github.libretube.api.JsonHelper
|
|
||||||
import com.github.libretube.api.obj.Comment
|
import com.github.libretube.api.obj.Comment
|
||||||
import com.github.libretube.constants.IntentData
|
import com.github.libretube.constants.IntentData
|
||||||
import com.github.libretube.databinding.CommentsRowBinding
|
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.HtmlParser
|
||||||
import com.github.libretube.util.LinkHandler
|
import com.github.libretube.util.LinkHandler
|
||||||
import com.github.libretube.util.TextUtils
|
import com.github.libretube.util.TextUtils
|
||||||
import kotlinx.serialization.encodeToString
|
|
||||||
|
|
||||||
class CommentsAdapter(
|
class CommentsAdapter(
|
||||||
private val fragment: Fragment?,
|
private val fragment: Fragment?,
|
||||||
@ -61,10 +59,7 @@ class CommentsAdapter(
|
|||||||
}
|
}
|
||||||
|
|
||||||
private fun navigateToReplies(comment: Comment) {
|
private fun navigateToReplies(comment: Comment) {
|
||||||
val args = bundleOf(
|
val args = bundleOf(IntentData.videoId to videoId, IntentData.comment to comment)
|
||||||
IntentData.videoId to videoId,
|
|
||||||
IntentData.comment to JsonHelper.json.encodeToString(comment),
|
|
||||||
)
|
|
||||||
fragment!!.parentFragmentManager.commit {
|
fragment!!.parentFragmentManager.commit {
|
||||||
replace<CommentsRepliesFragment>(R.id.commentFragContainer, args = args)
|
replace<CommentsRepliesFragment>(R.id.commentFragContainer, args = args)
|
||||||
addToBackStack(null)
|
addToBackStack(null)
|
||||||
|
@ -10,13 +10,13 @@ import androidx.fragment.app.Fragment
|
|||||||
import androidx.fragment.app.activityViewModels
|
import androidx.fragment.app.activityViewModels
|
||||||
import androidx.lifecycle.lifecycleScope
|
import androidx.lifecycle.lifecycleScope
|
||||||
import androidx.recyclerview.widget.LinearLayoutManager
|
import androidx.recyclerview.widget.LinearLayoutManager
|
||||||
import com.github.libretube.api.JsonHelper
|
|
||||||
import com.github.libretube.api.RetrofitInstance
|
import com.github.libretube.api.RetrofitInstance
|
||||||
import com.github.libretube.api.obj.Comment
|
import com.github.libretube.api.obj.Comment
|
||||||
import com.github.libretube.api.obj.CommentsPage
|
import com.github.libretube.api.obj.CommentsPage
|
||||||
import com.github.libretube.constants.IntentData
|
import com.github.libretube.constants.IntentData
|
||||||
import com.github.libretube.databinding.FragmentCommentsBinding
|
import com.github.libretube.databinding.FragmentCommentsBinding
|
||||||
import com.github.libretube.extensions.TAG
|
import com.github.libretube.extensions.TAG
|
||||||
|
import com.github.libretube.extensions.parcelable
|
||||||
import com.github.libretube.ui.adapters.CommentsAdapter
|
import com.github.libretube.ui.adapters.CommentsAdapter
|
||||||
import com.github.libretube.ui.extensions.filterNonEmptyComments
|
import com.github.libretube.ui.extensions.filterNonEmptyComments
|
||||||
import com.github.libretube.ui.models.CommentsViewModel
|
import com.github.libretube.ui.models.CommentsViewModel
|
||||||
@ -45,11 +45,9 @@ class CommentsRepliesFragment : Fragment() {
|
|||||||
|
|
||||||
override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
|
override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
|
||||||
super.onViewCreated(view, savedInstanceState)
|
super.onViewCreated(view, savedInstanceState)
|
||||||
val videoId = arguments?.getString(IntentData.videoId) ?: ""
|
val arguments = requireArguments()
|
||||||
val comment = JsonHelper.json.decodeFromString(
|
val videoId = arguments.getString(IntentData.videoId, "")
|
||||||
Comment.serializer(),
|
val comment = arguments.parcelable<Comment>(IntentData.comment)!!
|
||||||
arguments?.getString(IntentData.comment)!!,
|
|
||||||
)
|
|
||||||
|
|
||||||
repliesAdapter = CommentsAdapter(
|
repliesAdapter = CommentsAdapter(
|
||||||
null,
|
null,
|
||||||
|
Loading…
Reference in New Issue
Block a user