From 303274cc6a1f3613b75209c53dc293f019974818 Mon Sep 17 00:00:00 2001
From: sneazy-ibo <41344259+sneazy-ibo@users.noreply.github.com>
Date: Mon, 17 Jun 2024 02:05:42 +0200
Subject: [PATCH 1/2] feat: added comments counter
---
.../media/comments/CommentsFragment.kt | 29 +++++++++++++++++++
app/src/main/res/layout/fragment_comments.xml | 14 +++++++++
app/src/main/res/values/strings.xml | 2 ++
3 files changed, 45 insertions(+)
diff --git a/app/src/main/java/ani/dantotsu/media/comments/CommentsFragment.kt b/app/src/main/java/ani/dantotsu/media/comments/CommentsFragment.kt
index fc21805e67..fd8f68b637 100644
--- a/app/src/main/java/ani/dantotsu/media/comments/CommentsFragment.kt
+++ b/app/src/main/java/ani/dantotsu/media/comments/CommentsFragment.kt
@@ -13,6 +13,7 @@ import android.view.View
import android.view.ViewGroup
import android.view.inputmethod.InputMethodManager
import android.widget.EditText
+import android.widget.TextView
import androidx.appcompat.widget.PopupMenu
import androidx.core.animation.doOnEnd
import androidx.core.content.res.ResourcesCompat
@@ -110,6 +111,10 @@ class CommentsFragment : Fragment() {
activity.binding.commentReplyToContainer.visibility = View.GONE
}
+ lifecycleScope.launch {
+ binding.commentCounter.text = commentCounter(mediaId)
+ }
+
binding.commentsList.adapter = adapter
binding.commentsList.layoutManager = LinearLayoutManager(activity)
@@ -588,6 +593,30 @@ class CommentsFragment : Fragment() {
}
}
+
+ private suspend fun commentCounter(mediaId: Int): String {
+ var totalComments = 0
+ var currentPage = 1
+
+ while (true) {
+ val response = CommentsAPI.getCommentsForId(mediaId, page = currentPage, tag = null, sort = null)
+ totalPages = response?.totalPages ?: 1
+ totalComments += response?.comments?.size ?: 0
+
+ if (currentPage >= totalPages) {
+ break
+ }
+ currentPage++
+ }
+
+ return if (totalComments > 0) {
+ resources.getString(R.string.comments_counter, totalComments.toString())
+ } else {
+ resources.getString(R.string.no_comments_found)
+ }
+ }
+
+
private fun processComment() {
val commentText = activity.binding.commentInput.text.toString()
if (commentText.isEmpty()) {
diff --git a/app/src/main/res/layout/fragment_comments.xml b/app/src/main/res/layout/fragment_comments.xml
index 49c602775a..1ece8040aa 100644
--- a/app/src/main/res/layout/fragment_comments.xml
+++ b/app/src/main/res/layout/fragment_comments.xml
@@ -27,6 +27,20 @@
android:orientation="horizontal"
tools:ignore="UseCompoundDrawables">
+
+
+
+
Try Internal Cast (Experimental)
Comments
+ %1$s Comments
+ No Comments found
Newest
Oldest
Highest rated
From 49e7603135407025ce807694589cb3519921b7cf Mon Sep 17 00:00:00 2001
From: sneazy-ibo <41344259+sneazy-ibo@users.noreply.github.com>
Date: Mon, 17 Jun 2024 02:17:11 +0200
Subject: [PATCH 2/2] feat: update count on refresh
---
.../java/ani/dantotsu/media/comments/CommentsFragment.kt | 7 ++++---
1 file changed, 4 insertions(+), 3 deletions(-)
diff --git a/app/src/main/java/ani/dantotsu/media/comments/CommentsFragment.kt b/app/src/main/java/ani/dantotsu/media/comments/CommentsFragment.kt
index fd8f68b637..1ee6baf17a 100644
--- a/app/src/main/java/ani/dantotsu/media/comments/CommentsFragment.kt
+++ b/app/src/main/java/ani/dantotsu/media/comments/CommentsFragment.kt
@@ -83,7 +83,7 @@ class CommentsFragment : Fragment() {
activity.binding.commentInputLayout
)
- //get the media id from the intent
+ // Get the media id from the intent
val mediaId = arguments?.getInt("mediaId") ?: -1
mediaName = arguments?.getString("mediaName") ?: "unknown"
if (mediaId == -1) {
@@ -106,6 +106,7 @@ class CommentsFragment : Fragment() {
binding.commentsRefresh.setOnRefreshListener {
lifecycleScope.launch {
loadAndDisplayComments()
+ binding.commentCounter.text = commentCounter(mediaId)
binding.commentsRefresh.isRefreshing = false
}
activity.binding.commentReplyToContainer.visibility = View.GONE
@@ -241,7 +242,7 @@ class CommentsFragment : Fragment() {
}
}
- //adds additional comments to the section
+ // Adds additional comments to the section
private suspend fun updateUIWithComment(comment: Comment) {
withContext(Dispatchers.Main) {
section.add(
@@ -302,7 +303,7 @@ class CommentsFragment : Fragment() {
}
activity.binding.commentLabel.setOnClickListener {
- //alert dialog to enter a number, with a cancel and ok button
+ // Alert dialog to enter a number, with a cancel and ok button
activity.customAlertDialog().apply {
val customView = DialogEdittextBinding.inflate(layoutInflater)
setTitle("Enter a chapter/episode number tag")