mirror of
https://github.com/libre-tube/LibreTube.git
synced 2024-12-14 22:30:30 +05:30
Merge pull request #5962 from Bnyro/master
fix: comments reloading on sheet reopen and scroll position not restored
This commit is contained in:
commit
421100cc42
@ -19,7 +19,9 @@ import com.github.libretube.extensions.formatShort
|
|||||||
import com.github.libretube.ui.adapters.CommentPagingAdapter
|
import com.github.libretube.ui.adapters.CommentPagingAdapter
|
||||||
import com.github.libretube.ui.models.CommentsViewModel
|
import com.github.libretube.ui.models.CommentsViewModel
|
||||||
import com.github.libretube.ui.sheets.CommentsSheet
|
import com.github.libretube.ui.sheets.CommentsSheet
|
||||||
|
import kotlinx.coroutines.Dispatchers
|
||||||
import kotlinx.coroutines.launch
|
import kotlinx.coroutines.launch
|
||||||
|
import kotlinx.coroutines.withContext
|
||||||
|
|
||||||
class CommentsMainFragment : Fragment() {
|
class CommentsMainFragment : Fragment() {
|
||||||
private var _binding: FragmentCommentsBinding? = null
|
private var _binding: FragmentCommentsBinding? = null
|
||||||
@ -74,11 +76,22 @@ class CommentsMainFragment : Fragment() {
|
|||||||
binding.commentsRV.adapter = commentPagingAdapter
|
binding.commentsRV.adapter = commentPagingAdapter
|
||||||
|
|
||||||
viewLifecycleOwner.lifecycleScope.launch {
|
viewLifecycleOwner.lifecycleScope.launch {
|
||||||
|
var restoredScrollPosition = false
|
||||||
|
|
||||||
repeatOnLifecycle(Lifecycle.State.STARTED) {
|
repeatOnLifecycle(Lifecycle.State.STARTED) {
|
||||||
launch {
|
launch {
|
||||||
commentPagingAdapter.loadStateFlow.collect {
|
commentPagingAdapter.loadStateFlow.collect {
|
||||||
binding.progress.isVisible = it.refresh is LoadState.Loading
|
binding.progress.isVisible = it.refresh is LoadState.Loading
|
||||||
|
|
||||||
|
if (!restoredScrollPosition && it.refresh is LoadState.NotLoading) {
|
||||||
|
viewModel.currentCommentsPosition.value?.let { position ->
|
||||||
|
withContext(Dispatchers.Main) {
|
||||||
|
binding.commentsRV.scrollToPosition(position)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
restoredScrollPosition = true
|
||||||
|
}
|
||||||
|
|
||||||
if (it.append is LoadState.NotLoading && it.append.endOfPaginationReached && commentPagingAdapter.itemCount == 0) {
|
if (it.append is LoadState.NotLoading && it.append.endOfPaginationReached && commentPagingAdapter.itemCount == 0) {
|
||||||
binding.errorTV.text = getString(R.string.no_comments_available)
|
binding.errorTV.text = getString(R.string.no_comments_available)
|
||||||
binding.errorTV.isVisible = true
|
binding.errorTV.isVisible = true
|
||||||
|
@ -528,7 +528,9 @@ class PlayerFragment : Fragment(), OnlinePlayerOptions {
|
|||||||
// set the max height to not cover the currently playing video
|
// set the max height to not cover the currently playing video
|
||||||
commentsViewModel.handleLink = this::handleLink
|
commentsViewModel.handleLink = this::handleLink
|
||||||
updateMaxSheetHeight()
|
updateMaxSheetHeight()
|
||||||
|
if (commentsViewModel.videoIdLiveData.value != videoId) {
|
||||||
commentsViewModel.videoIdLiveData.postValue(videoId)
|
commentsViewModel.videoIdLiveData.postValue(videoId)
|
||||||
|
}
|
||||||
commentsViewModel.channelAvatar = streams.uploaderAvatar
|
commentsViewModel.channelAvatar = streams.uploaderAvatar
|
||||||
CommentsSheet().show(childFragmentManager)
|
CommentsSheet().show(childFragmentManager)
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user