mirror of
https://github.com/libre-tube/LibreTube.git
synced 2025-04-28 16:00:31 +05:30
Use Kotlinx Serialization with comments.
This commit is contained in:
parent
165e0677d4
commit
ef103284af
@ -1,19 +1,19 @@
|
||||
package com.github.libretube.api.obj
|
||||
|
||||
import com.fasterxml.jackson.annotation.JsonIgnoreProperties
|
||||
import kotlinx.serialization.Serializable
|
||||
|
||||
@JsonIgnoreProperties(ignoreUnknown = true)
|
||||
@Serializable
|
||||
data class Comment(
|
||||
val author: String? = null,
|
||||
val commentId: String? = null,
|
||||
val commentText: String? = null,
|
||||
val commentedTime: String? = null,
|
||||
val commentorUrl: String? = null,
|
||||
val author: String,
|
||||
val commentId: String,
|
||||
val commentText: String,
|
||||
val commentedTime: String,
|
||||
val commentorUrl: String,
|
||||
val repliesPage: String? = null,
|
||||
val hearted: Boolean? = null,
|
||||
val likeCount: Long? = null,
|
||||
val pinned: Boolean? = null,
|
||||
val thumbnail: String? = null,
|
||||
val verified: Boolean? = null,
|
||||
val replyCount: Long? = null
|
||||
val hearted: Boolean,
|
||||
val likeCount: Long,
|
||||
val pinned: Boolean,
|
||||
val thumbnail: String,
|
||||
val verified: Boolean,
|
||||
val replyCount: Long
|
||||
)
|
||||
|
@ -1,10 +1,10 @@
|
||||
package com.github.libretube.api.obj
|
||||
|
||||
import com.fasterxml.jackson.annotation.JsonIgnoreProperties
|
||||
import kotlinx.serialization.Serializable
|
||||
|
||||
@JsonIgnoreProperties(ignoreUnknown = true)
|
||||
@Serializable
|
||||
data class CommentsPage(
|
||||
var comments: MutableList<Comment> = arrayListOf(),
|
||||
val disabled: Boolean? = null,
|
||||
var comments: List<Comment> = emptyList(),
|
||||
val disabled: Boolean = false,
|
||||
val nextpage: String? = null
|
||||
)
|
||||
|
@ -66,22 +66,21 @@ class CommentsAdapter(
|
||||
commentorImage.scaleY = REPLIES_ADAPTER_SCALE
|
||||
}
|
||||
|
||||
commentInfos.text =
|
||||
comment.author.toString() + TextUtils.SEPARATOR + comment.commentedTime.toString()
|
||||
commentInfos.text = comment.author + TextUtils.SEPARATOR + comment.commentedTime
|
||||
commentText.text = HtmlCompat.fromHtml(
|
||||
comment.commentText.toString(),
|
||||
comment.commentText,
|
||||
HtmlCompat.FROM_HTML_MODE_LEGACY
|
||||
)
|
||||
|
||||
ImageHelper.loadImage(comment.thumbnail, commentorImage)
|
||||
likesTextView.text = comment.likeCount.formatShort()
|
||||
|
||||
if (comment.verified == true) verifiedImageView.visibility = View.VISIBLE
|
||||
if (comment.pinned == true) pinnedImageView.visibility = View.VISIBLE
|
||||
if (comment.hearted == true) heartedImageView.visibility = View.VISIBLE
|
||||
if (comment.verified) verifiedImageView.visibility = View.VISIBLE
|
||||
if (comment.pinned) pinnedImageView.visibility = View.VISIBLE
|
||||
if (comment.hearted) heartedImageView.visibility = View.VISIBLE
|
||||
if (comment.repliesPage != null) repliesAvailable.visibility = View.VISIBLE
|
||||
if ((comment.replyCount ?: -1L) > 0L) {
|
||||
repliesCount.text = comment.replyCount?.formatShort()
|
||||
if (comment.replyCount > 0L) {
|
||||
repliesCount.text = comment.replyCount.formatShort()
|
||||
}
|
||||
|
||||
commentorImage.setOnClickListener {
|
||||
@ -99,7 +98,7 @@ class CommentsAdapter(
|
||||
}
|
||||
|
||||
root.setOnLongClickListener {
|
||||
ClipboardHelper(root.context).save(comment.commentText.toString())
|
||||
ClipboardHelper(root.context).save(comment.commentText)
|
||||
Toast.makeText(root.context, R.string.copied, Toast.LENGTH_SHORT).show()
|
||||
true
|
||||
}
|
||||
|
@ -48,7 +48,7 @@ class CommentsViewModel : ViewModel() {
|
||||
return@launch
|
||||
}
|
||||
val updatedPage = commentsPage.value?.apply {
|
||||
comments = comments.plus(response.comments).toMutableList()
|
||||
comments += response.comments
|
||||
}
|
||||
nextPage = response.nextpage
|
||||
commentsPage.postValue(updatedPage)
|
||||
|
Loading…
x
Reference in New Issue
Block a user