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
|
package com.github.libretube.api.obj
|
||||||
|
|
||||||
import com.fasterxml.jackson.annotation.JsonIgnoreProperties
|
import kotlinx.serialization.Serializable
|
||||||
|
|
||||||
@JsonIgnoreProperties(ignoreUnknown = true)
|
@Serializable
|
||||||
data class Comment(
|
data class Comment(
|
||||||
val author: String? = null,
|
val author: String,
|
||||||
val commentId: String? = null,
|
val commentId: String,
|
||||||
val commentText: String? = null,
|
val commentText: String,
|
||||||
val commentedTime: String? = null,
|
val commentedTime: String,
|
||||||
val commentorUrl: String? = null,
|
val commentorUrl: String,
|
||||||
val repliesPage: String? = null,
|
val repliesPage: String? = null,
|
||||||
val hearted: Boolean? = null,
|
val hearted: Boolean,
|
||||||
val likeCount: Long? = null,
|
val likeCount: Long,
|
||||||
val pinned: Boolean? = null,
|
val pinned: Boolean,
|
||||||
val thumbnail: String? = null,
|
val thumbnail: String,
|
||||||
val verified: Boolean? = null,
|
val verified: Boolean,
|
||||||
val replyCount: Long? = null
|
val replyCount: Long
|
||||||
)
|
)
|
||||||
|
@ -1,10 +1,10 @@
|
|||||||
package com.github.libretube.api.obj
|
package com.github.libretube.api.obj
|
||||||
|
|
||||||
import com.fasterxml.jackson.annotation.JsonIgnoreProperties
|
import kotlinx.serialization.Serializable
|
||||||
|
|
||||||
@JsonIgnoreProperties(ignoreUnknown = true)
|
@Serializable
|
||||||
data class CommentsPage(
|
data class CommentsPage(
|
||||||
var comments: MutableList<Comment> = arrayListOf(),
|
var comments: List<Comment> = emptyList(),
|
||||||
val disabled: Boolean? = null,
|
val disabled: Boolean = false,
|
||||||
val nextpage: String? = null
|
val nextpage: String? = null
|
||||||
)
|
)
|
||||||
|
@ -66,22 +66,21 @@ class CommentsAdapter(
|
|||||||
commentorImage.scaleY = REPLIES_ADAPTER_SCALE
|
commentorImage.scaleY = REPLIES_ADAPTER_SCALE
|
||||||
}
|
}
|
||||||
|
|
||||||
commentInfos.text =
|
commentInfos.text = comment.author + TextUtils.SEPARATOR + comment.commentedTime
|
||||||
comment.author.toString() + TextUtils.SEPARATOR + comment.commentedTime.toString()
|
|
||||||
commentText.text = HtmlCompat.fromHtml(
|
commentText.text = HtmlCompat.fromHtml(
|
||||||
comment.commentText.toString(),
|
comment.commentText,
|
||||||
HtmlCompat.FROM_HTML_MODE_LEGACY
|
HtmlCompat.FROM_HTML_MODE_LEGACY
|
||||||
)
|
)
|
||||||
|
|
||||||
ImageHelper.loadImage(comment.thumbnail, commentorImage)
|
ImageHelper.loadImage(comment.thumbnail, commentorImage)
|
||||||
likesTextView.text = comment.likeCount.formatShort()
|
likesTextView.text = comment.likeCount.formatShort()
|
||||||
|
|
||||||
if (comment.verified == true) verifiedImageView.visibility = View.VISIBLE
|
if (comment.verified) verifiedImageView.visibility = View.VISIBLE
|
||||||
if (comment.pinned == true) pinnedImageView.visibility = View.VISIBLE
|
if (comment.pinned) pinnedImageView.visibility = View.VISIBLE
|
||||||
if (comment.hearted == true) heartedImageView.visibility = View.VISIBLE
|
if (comment.hearted) heartedImageView.visibility = View.VISIBLE
|
||||||
if (comment.repliesPage != null) repliesAvailable.visibility = View.VISIBLE
|
if (comment.repliesPage != null) repliesAvailable.visibility = View.VISIBLE
|
||||||
if ((comment.replyCount ?: -1L) > 0L) {
|
if (comment.replyCount > 0L) {
|
||||||
repliesCount.text = comment.replyCount?.formatShort()
|
repliesCount.text = comment.replyCount.formatShort()
|
||||||
}
|
}
|
||||||
|
|
||||||
commentorImage.setOnClickListener {
|
commentorImage.setOnClickListener {
|
||||||
@ -99,7 +98,7 @@ class CommentsAdapter(
|
|||||||
}
|
}
|
||||||
|
|
||||||
root.setOnLongClickListener {
|
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()
|
Toast.makeText(root.context, R.string.copied, Toast.LENGTH_SHORT).show()
|
||||||
true
|
true
|
||||||
}
|
}
|
||||||
|
@ -48,7 +48,7 @@ class CommentsViewModel : ViewModel() {
|
|||||||
return@launch
|
return@launch
|
||||||
}
|
}
|
||||||
val updatedPage = commentsPage.value?.apply {
|
val updatedPage = commentsPage.value?.apply {
|
||||||
comments = comments.plus(response.comments).toMutableList()
|
comments += response.comments
|
||||||
}
|
}
|
||||||
nextPage = response.nextpage
|
nextPage = response.nextpage
|
||||||
commentsPage.postValue(updatedPage)
|
commentsPage.postValue(updatedPage)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user