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.databinding.ItemCommentsBinding
|
||||||
import ani.dantotsu.loadImage
|
import ani.dantotsu.loadImage
|
||||||
import ani.dantotsu.openLinkInBrowser
|
import ani.dantotsu.openLinkInBrowser
|
||||||
import ani.dantotsu.others.ImageViewDialog
|
|
||||||
import ani.dantotsu.settings.saving.PrefManager
|
import ani.dantotsu.settings.saving.PrefManager
|
||||||
import ani.dantotsu.settings.saving.PrefName
|
import ani.dantotsu.settings.saving.PrefName
|
||||||
import ani.dantotsu.snackString
|
import ani.dantotsu.snackString
|
||||||
|
@ -34,9 +33,10 @@ import kotlin.math.sqrt
|
||||||
|
|
||||||
class CommentItem(val comment: Comment,
|
class CommentItem(val comment: Comment,
|
||||||
private val markwon: Markwon,
|
private val markwon: Markwon,
|
||||||
private val section: Section,
|
val parentSection: Section,
|
||||||
private val commentsActivity: CommentsActivity,
|
private val commentsActivity: CommentsActivity,
|
||||||
private val backgroundColor: Int
|
private val backgroundColor: Int,
|
||||||
|
val commentDepth: Int
|
||||||
) : BindableItem<ItemCommentsBinding>() {
|
) : BindableItem<ItemCommentsBinding>() {
|
||||||
var binding: ItemCommentsBinding? = null
|
var binding: ItemCommentsBinding? = null
|
||||||
val adapter = GroupieAdapter()
|
val adapter = GroupieAdapter()
|
||||||
|
@ -44,6 +44,7 @@ class CommentItem(val comment: Comment,
|
||||||
var isEditing = false
|
var isEditing = false
|
||||||
private var isReplying = false
|
private var isReplying = false
|
||||||
private var repliesVisible = false
|
private var repliesVisible = false
|
||||||
|
var MAX_DEPTH = 3
|
||||||
|
|
||||||
init {
|
init {
|
||||||
adapter.add(repliesSection)
|
adapter.add(repliesSection)
|
||||||
|
@ -111,7 +112,7 @@ class CommentItem(val comment: Comment,
|
||||||
val success = CommentsAPI.deleteComment(comment.commentId)
|
val success = CommentsAPI.deleteComment(comment.commentId)
|
||||||
if (success) {
|
if (success) {
|
||||||
snackString("Comment Deleted")
|
snackString("Comment Deleted")
|
||||||
section.remove(this@CommentItem)
|
parentSection.remove(this@CommentItem)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -179,7 +179,8 @@ class CommentsActivity : AppCompatActivity() {
|
||||||
buildMarkwon(),
|
buildMarkwon(),
|
||||||
section,
|
section,
|
||||||
this@CommentsActivity,
|
this@CommentsActivity,
|
||||||
backgroundColor
|
backgroundColor,
|
||||||
|
0
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
@ -238,7 +239,8 @@ class CommentsActivity : AppCompatActivity() {
|
||||||
buildMarkwon(),
|
buildMarkwon(),
|
||||||
section,
|
section,
|
||||||
this@CommentsActivity,
|
this@CommentsActivity,
|
||||||
backgroundColor
|
backgroundColor,
|
||||||
|
0
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
@ -339,20 +341,26 @@ class CommentsActivity : AppCompatActivity() {
|
||||||
val replies = withContext(Dispatchers.IO) {
|
val replies = withContext(Dispatchers.IO) {
|
||||||
CommentsAPI.getRepliesFromId(comment.comment.commentId)
|
CommentsAPI.getRepliesFromId(comment.comment.commentId)
|
||||||
}
|
}
|
||||||
|
|
||||||
replies?.comments?.forEach {
|
replies?.comments?.forEach {
|
||||||
comment.repliesSection.add(
|
val depth = if (comment.commentDepth + 1 > comment.MAX_DEPTH) comment.commentDepth else comment.commentDepth + 1
|
||||||
CommentItem(
|
val section = if (comment.commentDepth + 1 > comment.MAX_DEPTH) comment.parentSection else comment.repliesSection
|
||||||
|
|
||||||
|
val newCommentItem = CommentItem(
|
||||||
it,
|
it,
|
||||||
buildMarkwon(),
|
buildMarkwon(),
|
||||||
comment.repliesSection,
|
section,
|
||||||
this@CommentsActivity,
|
this@CommentsActivity,
|
||||||
backgroundColor
|
backgroundColor,
|
||||||
)
|
depth
|
||||||
)
|
)
|
||||||
|
|
||||||
|
section.add(newCommentItem)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Shows the comment rules dialog
|
* Shows the comment rules dialog
|
||||||
* Called when the user tries to comment for the first time
|
* Called when the user tries to comment for the first time
|
||||||
|
@ -441,20 +449,24 @@ class CommentsActivity : AppCompatActivity() {
|
||||||
}
|
}
|
||||||
success?.let {
|
success?.let {
|
||||||
if (interactionState == InteractionState.REPLY) {
|
if (interactionState == InteractionState.REPLY) {
|
||||||
commentWithInteraction?.repliesSection?.add(
|
if (commentWithInteraction == null) return@let
|
||||||
0,
|
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(
|
CommentItem(
|
||||||
it,
|
it,
|
||||||
buildMarkwon(),
|
buildMarkwon(),
|
||||||
commentWithInteraction!!.repliesSection,
|
section,
|
||||||
this@CommentsActivity,
|
this@CommentsActivity,
|
||||||
backgroundColor
|
backgroundColor,
|
||||||
|
depth
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
} else {
|
} else {
|
||||||
section.add(
|
section.add(
|
||||||
0,
|
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