Merge pull request #5180 from Bnyro/master

feat: show toast if the bottom/end of comments/replies is reached
This commit is contained in:
Bnyro 2023-11-17 15:32:38 +01:00 committed by GitHub
commit 39afe071b6
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
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 commentsSheet?.binding?.btnScrollToTop?.isVisible = viewModel.currentCommentsPosition != 0
if (!viewBinding.commentsRV.canScrollVertically(1)) { if (!viewBinding.commentsRV.canScrollVertically(1)) {
viewModel.fetchNextComments() viewModel.fetchNextComments(requireContext())
} }
} }
commentsSheet?.updateFragmentInfo(false, getString(R.string.comments)) commentsSheet?.updateFragmentInfo(false, getString(R.string.comments))

View File

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

View File

@ -1,12 +1,16 @@
package com.github.libretube.ui.models package com.github.libretube.ui.models
import android.content.Context
import android.util.Log import android.util.Log
import android.widget.Toast
import androidx.lifecycle.MutableLiveData import androidx.lifecycle.MutableLiveData
import androidx.lifecycle.ViewModel import androidx.lifecycle.ViewModel
import androidx.lifecycle.viewModelScope import androidx.lifecycle.viewModelScope
import com.github.libretube.R
import com.github.libretube.api.RetrofitInstance import com.github.libretube.api.RetrofitInstance
import com.github.libretube.api.obj.CommentsPage import com.github.libretube.api.obj.CommentsPage
import com.github.libretube.extensions.TAG import com.github.libretube.extensions.TAG
import com.github.libretube.extensions.toastFromMainDispatcher
import com.github.libretube.ui.extensions.filterNonEmptyComments import com.github.libretube.ui.extensions.filterNonEmptyComments
import kotlinx.coroutines.Dispatchers import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.launch 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 if (isLoading.value == true || nextPage == null || videoId == null) return
isLoading.value = true 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="successfully_removed_from_playlist">Successfully removed \"%1$s\" from the playlist.</string>
<string name="watched">Watched</string> <string name="watched">Watched</string>
<string name="no_segments_found">There are no segments for this video yet.</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 --> <!-- Notification channel strings -->
<string name="download_channel_name">Download Service</string> <string name="download_channel_name">Download Service</string>