feat: show toast if the bottom/end of comments/replies is reached

This commit is contained in:
Bnyro 2023-11-17 15:32:08 +01:00
parent 155682bccc
commit 14c6ae36b5
4 changed files with 18 additions and 6 deletions

View File

@ -55,7 +55,7 @@ class CommentsMainFragment : Fragment() {
commentsSheet?.binding?.btnScrollToTop?.isVisible = viewModel.currentCommentsPosition != 0
if (!viewBinding.commentsRV.canScrollVertically(1)) {
viewModel.fetchNextComments()
viewModel.fetchNextComments(requireContext())
}
}
commentsSheet?.updateFragmentInfo(false, getString(R.string.comments))

View File

@ -5,6 +5,7 @@ import android.util.Log
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import android.widget.Toast
import androidx.core.view.isGone
import androidx.core.view.isVisible
import androidx.core.view.updatePadding
@ -78,10 +79,12 @@ class CommentsRepliesFragment : Fragment() {
binding.commentsRV.adapter = repliesAdapter
binding.commentsRV.viewTreeObserver.addOnScrollChangedListener {
if (_binding?.commentsRV?.canScrollVertically(1) == false &&
::repliesPage.isInitialized &&
repliesPage.nextpage != null
) {
if (_binding?.commentsRV?.canScrollVertically(1) == false && ::repliesPage.isInitialized) {
if (repliesPage.nextpage == null) {
Toast.makeText(context, R.string.bottom_reached, Toast.LENGTH_SHORT).show()
return@addOnScrollChangedListener
}
fetchReplies(videoId, repliesPage.nextpage!!)
}
}

View File

@ -1,12 +1,16 @@
package com.github.libretube.ui.models
import android.content.Context
import android.util.Log
import android.widget.Toast
import androidx.lifecycle.MutableLiveData
import androidx.lifecycle.ViewModel
import androidx.lifecycle.viewModelScope
import com.github.libretube.R
import com.github.libretube.api.RetrofitInstance
import com.github.libretube.api.obj.CommentsPage
import com.github.libretube.extensions.TAG
import com.github.libretube.extensions.toastFromMainDispatcher
import com.github.libretube.ui.extensions.filterNonEmptyComments
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.launch
@ -54,7 +58,11 @@ class CommentsViewModel : ViewModel() {
}
}
fun fetchNextComments() {
fun fetchNextComments(context: Context) {
if (nextPage == null) {
Toast.makeText(context, R.string.bottom_reached, Toast.LENGTH_SHORT).show()
}
if (isLoading.value == true || nextPage == null || videoId == null) return
isLoading.value = true

View File

@ -495,6 +495,7 @@
<string name="successfully_removed_from_playlist">Successfully removed \"%1$s\" from the playlist.</string>
<string name="watched">Watched</string>
<string name="no_segments_found">There are no segments for this video yet.</string>
<string name="bottom_reached">Bottom reached!</string>
<!-- Notification channel strings -->
<string name="download_channel_name">Download Service</string>