From 526098f2bffe0e9133c201c773d846e81e2d1652 Mon Sep 17 00:00:00 2001 From: rebelonion <87634197+rebelonion@users.noreply.github.com> Date: Fri, 23 Feb 2024 19:24:17 -0600 Subject: [PATCH] feat: (wip) limit comment depth to 4 --- .../dantotsu/media/comments/CommentItem.kt | 9 ++-- .../media/comments/CommentsActivity.kt | 42 ++++++++++++------- 2 files changed, 32 insertions(+), 19 deletions(-) diff --git a/app/src/main/java/ani/dantotsu/media/comments/CommentItem.kt b/app/src/main/java/ani/dantotsu/media/comments/CommentItem.kt index 9e4f8071..03f61c18 100644 --- a/app/src/main/java/ani/dantotsu/media/comments/CommentItem.kt +++ b/app/src/main/java/ani/dantotsu/media/comments/CommentItem.kt @@ -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() { 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) } } } diff --git a/app/src/main/java/ani/dantotsu/media/comments/CommentsActivity.kt b/app/src/main/java/ani/dantotsu/media/comments/CommentsActivity.kt index c395d71f..68ca901c 100644 --- a/app/src/main/java/ani/dantotsu/media/comments/CommentsActivity.kt +++ b/app/src/main/java/ani/dantotsu/media/comments/CommentsActivity.kt @@ -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( - it, - buildMarkwon(), - comment.repliesSection, - this@CommentsActivity, - backgroundColor - ) + 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(), + section, + this@CommentsActivity, + 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) ) } }