feat: (wip) limit comment depth to 4
This commit is contained in:
parent
6ccdc10208
commit
526098f2bf
2 changed files with 32 additions and 19 deletions
|
@ -12,7 +12,6 @@ import ani.dantotsu.currActivity
|
|||
import ani.dantotsu.databinding.ItemCommentsBinding
|
||||
import ani.dantotsu.loadImage
|
||||
import ani.dantotsu.openLinkInBrowser
|
||||
import ani.dantotsu.others.ImageViewDialog
|
||||
import ani.dantotsu.settings.saving.PrefManager
|
||||
import ani.dantotsu.settings.saving.PrefName
|
||||
import ani.dantotsu.snackString
|
||||
|
@ -34,9 +33,10 @@ import kotlin.math.sqrt
|
|||
|
||||
class CommentItem(val comment: Comment,
|
||||
private val markwon: Markwon,
|
||||
private val section: Section,
|
||||
val parentSection: Section,
|
||||
private val commentsActivity: CommentsActivity,
|
||||
private val backgroundColor: Int
|
||||
private val backgroundColor: Int,
|
||||
val commentDepth: Int
|
||||
) : BindableItem<ItemCommentsBinding>() {
|
||||
var binding: ItemCommentsBinding? = null
|
||||
val adapter = GroupieAdapter()
|
||||
|
@ -44,6 +44,7 @@ class CommentItem(val comment: Comment,
|
|||
var isEditing = false
|
||||
private var isReplying = false
|
||||
private var repliesVisible = false
|
||||
var MAX_DEPTH = 3
|
||||
|
||||
init {
|
||||
adapter.add(repliesSection)
|
||||
|
@ -111,7 +112,7 @@ class CommentItem(val comment: Comment,
|
|||
val success = CommentsAPI.deleteComment(comment.commentId)
|
||||
if (success) {
|
||||
snackString("Comment Deleted")
|
||||
section.remove(this@CommentItem)
|
||||
parentSection.remove(this@CommentItem)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -179,7 +179,8 @@ class CommentsActivity : AppCompatActivity() {
|
|||
buildMarkwon(),
|
||||
section,
|
||||
this@CommentsActivity,
|
||||
backgroundColor
|
||||
backgroundColor,
|
||||
0
|
||||
)
|
||||
)
|
||||
}
|
||||
|
@ -238,7 +239,8 @@ class CommentsActivity : AppCompatActivity() {
|
|||
buildMarkwon(),
|
||||
section,
|
||||
this@CommentsActivity,
|
||||
backgroundColor
|
||||
backgroundColor,
|
||||
0
|
||||
)
|
||||
)
|
||||
}
|
||||
|
@ -339,20 +341,26 @@ class CommentsActivity : AppCompatActivity() {
|
|||
val replies = withContext(Dispatchers.IO) {
|
||||
CommentsAPI.getRepliesFromId(comment.comment.commentId)
|
||||
}
|
||||
|
||||
replies?.comments?.forEach {
|
||||
comment.repliesSection.add(
|
||||
CommentItem(
|
||||
val depth = if (comment.commentDepth + 1 > comment.MAX_DEPTH) comment.commentDepth else comment.commentDepth + 1
|
||||
val section = if (comment.commentDepth + 1 > comment.MAX_DEPTH) comment.parentSection else comment.repliesSection
|
||||
|
||||
val newCommentItem = CommentItem(
|
||||
it,
|
||||
buildMarkwon(),
|
||||
comment.repliesSection,
|
||||
section,
|
||||
this@CommentsActivity,
|
||||
backgroundColor
|
||||
)
|
||||
backgroundColor,
|
||||
depth
|
||||
)
|
||||
|
||||
section.add(newCommentItem)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Shows the comment rules dialog
|
||||
* Called when the user tries to comment for the first time
|
||||
|
@ -441,20 +449,24 @@ class CommentsActivity : AppCompatActivity() {
|
|||
}
|
||||
success?.let {
|
||||
if (interactionState == InteractionState.REPLY) {
|
||||
commentWithInteraction?.repliesSection?.add(
|
||||
0,
|
||||
if (commentWithInteraction == null) return@let
|
||||
val section = if (commentWithInteraction!!.commentDepth + 1 > commentWithInteraction!!.MAX_DEPTH) commentWithInteraction?.parentSection else commentWithInteraction?.repliesSection
|
||||
val depth = if (commentWithInteraction!!.commentDepth + 1 > commentWithInteraction!!.MAX_DEPTH) commentWithInteraction!!.commentDepth else commentWithInteraction!!.commentDepth + 1
|
||||
section?.add(
|
||||
if (commentWithInteraction!!.commentDepth + 1 > commentWithInteraction!!.MAX_DEPTH) 0 else section.itemCount,
|
||||
CommentItem(
|
||||
it,
|
||||
buildMarkwon(),
|
||||
commentWithInteraction!!.repliesSection,
|
||||
section,
|
||||
this@CommentsActivity,
|
||||
backgroundColor
|
||||
backgroundColor,
|
||||
depth
|
||||
)
|
||||
)
|
||||
} else {
|
||||
section.add(
|
||||
0,
|
||||
CommentItem(it, buildMarkwon(), section, this@CommentsActivity, backgroundColor)
|
||||
CommentItem(it, buildMarkwon(), section, this@CommentsActivity, backgroundColor, 0)
|
||||
)
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue