Skip to content

Commit

Permalink
feat(comments): "reply to" above text input
Browse files Browse the repository at this point in the history
  • Loading branch information
aayush2622 committed Feb 23, 2024
1 parent 70c87b4 commit 8ea6bf8
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 4 deletions.
10 changes: 8 additions & 2 deletions app/src/main/java/ani/dantotsu/media/comments/CommentItem.kt
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@ 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
import com.xwray.groupie.GroupieAdapter
import com.xwray.groupie.Section
Expand All @@ -37,7 +39,7 @@ class CommentItem(val comment: Comment,
var binding: ItemCommentsBinding? = null
val adapter = GroupieAdapter()
val repliesSection = Section()
private var isEditing = false
var isEditing = false
private var isReplying = false
private var repliesVisible = false

Expand Down Expand Up @@ -96,6 +98,7 @@ class CommentItem(val comment: Comment,
}
viewBinding.commentReply.setOnClickListener {
replying(!isReplying)
commentsActivity.replyTo(this, comment.username)
commentsActivity.replyCallback(this)
}
viewBinding.modBadge.visibility = if (comment.isMod == true) View.VISIBLE else View.GONE
Expand Down Expand Up @@ -176,14 +179,17 @@ class CommentItem(val comment: Comment,

fun replying(isReplying: Boolean) {
binding?.commentReply?.text = if (isReplying) currActivity()!!.getString(R.string.cancel) else "Reply"
PrefManager.setVal(PrefName.ReplyTo, isReplying)
this.isReplying = isReplying
}

fun editing(isEditing: Boolean) {
binding?.commentEdit?.text = if (isEditing) currActivity()!!.getString(R.string.cancel) else currActivity()!!.getString(R.string.edit)
this.isEditing = isEditing
}

fun test(isEditing: Boolean){
this.isEditing = isEditing
}
private fun setVoteButtons(viewBinding: ItemCommentsBinding) {
when (comment.userVoteType) {
1 -> {
Expand Down
16 changes: 14 additions & 2 deletions app/src/main/java/ani/dantotsu/media/comments/CommentsActivity.kt
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package ani.dantotsu.media.comments

import android.annotation.SuppressLint
import android.graphics.drawable.Drawable
import android.os.Bundle
import android.text.TextWatcher
Expand Down Expand Up @@ -82,13 +83,13 @@ class CommentsActivity : AppCompatActivity() {
markwonEditor
)
)
binding.commentReplyToContainer.visibility = View.GONE //TODO: implement reply

binding.commentsRefresh.setOnRefreshListener {
lifecycleScope.launch {
loadAndDisplayComments()
binding.commentsRefresh.isRefreshing = false
}
binding.commentReplyToContainer.visibility = View.GONE
}

binding.commentsList.adapter = adapter
Expand Down Expand Up @@ -291,13 +292,24 @@ class CommentsActivity : AppCompatActivity() {
fun replyCallback(comment: CommentItem) {
if (resetOldState() == InteractionState.REPLY) return
commentWithInteraction = comment
binding.commentReplyToContainer.visibility = View.VISIBLE
binding.commentInput.requestFocus()
binding.commentInput.setSelection(binding.commentInput.text.length)
val imm = getSystemService(INPUT_METHOD_SERVICE) as InputMethodManager
imm.showSoftInput(binding.commentInput, InputMethodManager.SHOW_IMPLICIT)
interactionState = InteractionState.REPLY
}

}
@SuppressLint("SetTextI18n")
fun replyTo(comment: CommentItem,Username: String) {
binding.commentReplyToContainer.visibility = if (PrefManager.getVal(PrefName.ReplyTo)) View.VISIBLE else View.GONE
binding.commentReplyTo.text = "Replying to $Username"
binding.commentReplyToCancel.setOnClickListener {
comment.replying(false)
replyCallback(comment)
binding.commentReplyToContainer.visibility = View.GONE
}
}
fun viewReplyCallback(comment: CommentItem) {
lifecycleScope.launch {
val replies = withContext(Dispatchers.IO) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -154,6 +154,7 @@ enum class PrefName(val data: Pref) { //TODO: Split this into multiple files
TagsListNonAdult(Pref(Location.Irrelevant, Set::class, setOf<String>())),
MakeDefault(Pref(Location.Irrelevant, Boolean::class, true)),
FirstComment(Pref(Location.Irrelevant, Boolean::class, true)),
ReplyTo(Pref(Location.Irrelevant, Boolean::class, false)),

//Protected
DiscordToken(Pref(Location.Protected, String::class, "")),
Expand Down
1 change: 1 addition & 0 deletions app/src/main/res/layout/activity_comments.xml
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,7 @@
android:layout_marginTop="10dp"
android:layout_marginBottom="10dp"
android:orientation="horizontal"
android:visibility="gone"
tools:ignore="UseCompoundDrawables">

<TextView
Expand Down

0 comments on commit 8ea6bf8

Please sign in to comment.