Merge pull request #3229 from Bnyro/master

Clickable comment timestamps
This commit is contained in:
Bnyro 2023-03-03 17:55:12 +01:00 committed by GitHub
commit c50bd97344
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
6 changed files with 22 additions and 10 deletions

View File

@ -1,6 +1,7 @@
package com.github.libretube.ui.adapters
import android.annotation.SuppressLint
import android.text.method.LinkMovementMethod
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
@ -27,6 +28,8 @@ import com.github.libretube.helpers.NavigationHelper
import com.github.libretube.helpers.ThemeHelper
import com.github.libretube.ui.fragments.CommentsRepliesFragment
import com.github.libretube.ui.viewholders.CommentsViewHolder
import com.github.libretube.util.HtmlParser
import com.github.libretube.util.LinkHandler
import com.github.libretube.util.TextUtils
import kotlinx.serialization.encodeToString
@ -35,6 +38,7 @@ class CommentsAdapter(
private val videoId: String,
private val comments: MutableList<Comment>,
private val isRepliesAdapter: Boolean = false,
private val handleLink: ((url: String) -> Unit)?,
private val dismiss: () -> Unit
) : RecyclerView.Adapter<CommentsViewHolder>() {
fun clear() {
@ -60,7 +64,10 @@ class CommentsAdapter(
val comment = comments[position]
holder.binding.apply {
commentInfos.text = comment.author + TextUtils.SEPARATOR + comment.commentedTime
commentText.text = comment.commentText?.parseAsHtml()
commentText.movementMethod = LinkMovementMethod.getInstance()
commentText.text = comment.commentText
?.parseAsHtml(tagHandler = HtmlParser(LinkHandler(handleLink ?: {})))
ImageHelper.loadImage(comment.thumbnail, commentorImage)
likesTextView.text = comment.likeCount.formatShort()
@ -108,7 +115,6 @@ class CommentsAdapter(
}
}
}
root.setOnLongClickListener {
ClipboardHelper.save(root.context, comment.commentText ?: "")
Toast.makeText(root.context, R.string.copied, Toast.LENGTH_SHORT).show()

View File

@ -43,7 +43,8 @@ class CommentsMainFragment : Fragment() {
commentsAdapter = CommentsAdapter(
this,
viewModel.videoId!!,
viewModel.commentsPage.value?.comments.orEmpty().toMutableList()
viewModel.commentsPage.value?.comments.orEmpty().toMutableList(),
handleLink = viewModel.handleLink
) {
viewModel.commentsSheetDismiss?.invoke()
}

View File

@ -49,7 +49,13 @@ class CommentsRepliesFragment : Fragment() {
arguments?.getString(IntentData.comment)!!
)
repliesAdapter = CommentsAdapter(null, videoId, mutableListOf(comment), true) {
repliesAdapter = CommentsAdapter(
null,
videoId,
mutableListOf(comment),
true,
viewModel.handleLink
) {
viewModel.commentsSheetDismiss?.invoke()
}

View File

@ -367,6 +367,7 @@ class PlayerFragment : Fragment(R.layout.fragment_player), OnlinePlayerOptions {
binding.commentsToggle.setOnClickListener {
videoId ?: return@setOnClickListener
// set the max height to not cover the currently playing video
commentsViewModel.handleLink = this::handleLink
commentsViewModel.maxHeight = binding.root.height - binding.player.height
commentsViewModel.videoId = videoId
CommentsSheet().show(childFragmentManager)

View File

@ -21,6 +21,7 @@ class CommentsViewModel : ViewModel() {
var videoId: String? = null
var maxHeight: Int = 0
var commentsSheetDismiss: (() -> Unit)? = null
var handleLink: ((url: String) -> Unit)? = null
fun fetchComments() {
videoId ?: return

View File

@ -1,5 +1,5 @@
<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
@ -14,9 +14,7 @@
android:layout_marginBottom="16dp"
android:orientation="horizontal"
android:paddingStart="15dp"
android:paddingEnd="15dp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintTop_toTopOf="parent">
android:paddingEnd="15dp">
<com.google.android.material.imageview.ShapeableImageView
android:id="@+id/commentor_image"
@ -75,7 +73,6 @@
android:layout_marginTop="5dp"
android:layout_marginBottom="8dp"
android:textSize="15sp"
android:autoLink="web"
android:textAlignment="viewStart"
tools:text="Comment Text" />
@ -125,4 +122,4 @@
</LinearLayout>
</androidx.constraintlayout.widget.ConstraintLayout>
</LinearLayout>