diff --git a/app/src/main/java/com/github/libretube/ui/sheets/CommentsSheet.kt b/app/src/main/java/com/github/libretube/ui/sheets/CommentsSheet.kt index ed79cea37..eed7a9dd5 100644 --- a/app/src/main/java/com/github/libretube/ui/sheets/CommentsSheet.kt +++ b/app/src/main/java/com/github/libretube/ui/sheets/CommentsSheet.kt @@ -7,11 +7,14 @@ import android.view.View import android.view.ViewGroup import androidx.lifecycle.lifecycleScope import androidx.recyclerview.widget.LinearLayoutManager +import com.github.libretube.R import com.github.libretube.api.RetrofitInstance import com.github.libretube.api.obj.Comment -import com.github.libretube.databinding.BottomSheetBinding +import com.github.libretube.databinding.CommentsSheetBinding import com.github.libretube.extensions.TAG import com.github.libretube.ui.adapters.CommentsAdapter +import kotlinx.coroutines.Dispatchers +import kotlinx.coroutines.withContext class CommentsSheet( private val videoId: String, @@ -19,61 +22,71 @@ class CommentsSheet( private var nextPage: String?, private val onMoreComments: (comments: List, nextPage: String?) -> Unit ) : ExpandedBottomSheet() { - private lateinit var binding: BottomSheetBinding + private lateinit var binding: CommentsSheetBinding - private var commentsAdapter: CommentsAdapter? = null - private var isLoading = true + private lateinit var commentsAdapter: CommentsAdapter + private var isLoading = false override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle?): View { - binding = BottomSheetBinding.inflate(layoutInflater) + binding = CommentsSheetBinding.inflate(layoutInflater) return binding.root } override fun onViewCreated(view: View, savedInstanceState: Bundle?) { super.onViewCreated(view, savedInstanceState) - binding.optionsRecycler.layoutManager = LinearLayoutManager(requireContext()) - binding.optionsRecycler.setItemViewCacheSize(20) + binding.commentsRV.layoutManager = LinearLayoutManager(requireContext()) + binding.commentsRV.setItemViewCacheSize(20) - binding.optionsRecycler.viewTreeObserver + binding.commentsRV.viewTreeObserver .addOnScrollChangedListener { - if (!binding.optionsRecycler.canScrollVertically(1)) { + if (!binding.commentsRV.canScrollVertically(1)) { fetchNextComments() } } - if (comments.isNotEmpty()) { - setCommentsAdapter(comments) - } else { - fetchComments() - } - } - - private fun setCommentsAdapter(comments: MutableList) { commentsAdapter = CommentsAdapter(videoId, comments) { dialog?.dismiss() } - binding.optionsRecycler.adapter = commentsAdapter - isLoading = false + binding.commentsRV.adapter = commentsAdapter + + if (comments.isEmpty()) fetchComments() } private fun fetchComments() { + binding.progress.visibility = View.VISIBLE lifecycleScope.launchWhenCreated { + isLoading = true val response = try { RetrofitInstance.api.getComments(videoId) } catch (e: Exception) { Log.e(TAG(), e.toString()) return@launchWhenCreated } - setCommentsAdapter(response.comments) + if (response.disabled == true) { + withContext(Dispatchers.Main) { + binding.errorTV.visibility = View.VISIBLE + } + return@launchWhenCreated + } + if (response.comments.isEmpty()) { + withContext(Dispatchers.Main) { + binding.errorTV.text = getString(R.string.no_comments_available) + binding.errorTV.visibility = View.VISIBLE + } + return@launchWhenCreated + } + binding.progress.visibility = View.GONE + commentsAdapter.updateItems(response.comments) nextPage = response.nextpage onMoreComments.invoke(response.comments, response.nextpage) + isLoading = false } } private fun fetchNextComments() { + if (isLoading || nextPage == null) return lifecycleScope.launchWhenCreated { - if (isLoading || nextPage == null) return@launchWhenCreated isLoading = true val response = try { RetrofitInstance.api.getCommentsNextPage(videoId, nextPage!!) @@ -82,7 +95,7 @@ class CommentsSheet( return@launchWhenCreated } nextPage = response.nextpage - commentsAdapter?.updateItems(response.comments) + commentsAdapter.updateItems(response.comments) onMoreComments.invoke(response.comments, response.nextpage) isLoading = false } diff --git a/app/src/main/java/com/github/libretube/ui/views/CustomExoPlayerView.kt b/app/src/main/java/com/github/libretube/ui/views/CustomExoPlayerView.kt index 1e407a661..f7ebb754c 100644 --- a/app/src/main/java/com/github/libretube/ui/views/CustomExoPlayerView.kt +++ b/app/src/main/java/com/github/libretube/ui/views/CustomExoPlayerView.kt @@ -247,6 +247,8 @@ internal class CustomExoPlayerView( binding.exoCenterControls.visibility = visibility binding.exoBottomBar.visibility = visibility binding.closeImageButton.visibility = visibility + binding.exoTitle.visibility = visibility + binding.exoPlayPause.visibility = visibility // disable tap and swipe gesture if the player is locked playerGestureController.isEnabled = isLocked diff --git a/app/src/main/res/layout/comments_sheet.xml b/app/src/main/res/layout/comments_sheet.xml new file mode 100644 index 000000000..6beb68f0c --- /dev/null +++ b/app/src/main/res/layout/comments_sheet.xml @@ -0,0 +1,57 @@ + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index 8f26d0f3f..3d6df189f 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -396,6 +396,8 @@ Use swipe gesture to adjust the brightness and volume. Defaults Pop-Up + Comments are disabled by the author. + This video has no comments available. Download Service