mirror of
https://github.com/libre-tube/LibreTube.git
synced 2025-04-29 08:20:32 +05:30
Merge pull request #3229 from Bnyro/master
Clickable comment timestamps
This commit is contained in:
commit
c50bd97344
@ -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()
|
||||
|
@ -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()
|
||||
}
|
||||
|
@ -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()
|
||||
}
|
||||
|
||||
|
@ -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)
|
||||
|
@ -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
|
||||
|
@ -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>
|
||||
|
Loading…
x
Reference in New Issue
Block a user