mirror of
https://github.com/rebelonion/Dantotsu.git
synced 2026-01-27 02:41:02 +00:00
feat: added comments counter
This commit is contained in:
@@ -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()) {
|
||||
|
||||
@@ -27,6 +27,20 @@
|
||||
android:orientation="horizontal"
|
||||
tools:ignore="UseCompoundDrawables">
|
||||
|
||||
<TextView
|
||||
android:id="@+id/commentCounter"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="match_parent"
|
||||
android:layout_marginStart="18dp"
|
||||
android:fontFamily="@font/poppins_bold"
|
||||
android:gravity="center_vertical"
|
||||
android:text="@string/loading" />
|
||||
|
||||
<Space
|
||||
android:layout_width="0dp"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_weight="1" />
|
||||
|
||||
<ImageView
|
||||
android:id="@+id/commentFilter"
|
||||
android:layout_width="28dp"
|
||||
|
||||
@@ -735,6 +735,8 @@
|
||||
<string name="try_internal_cast_experimental">Try Internal Cast (Experimental)</string>
|
||||
|
||||
<string name="comments">Comments</string>
|
||||
<string name="comments_counter">%1$s Comments</string>
|
||||
<string name="no_comments_found">No Comments found</string>
|
||||
<string name="newest">Newest</string>
|
||||
<string name="oldest">Oldest</string>
|
||||
<string name="highest_rated">Highest rated</string>
|
||||
|
||||
Reference in New Issue
Block a user