mirror of
https://github.com/libre-tube/LibreTube.git
synced 2025-04-29 16:30:31 +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
|
package com.github.libretube.ui.adapters
|
||||||
|
|
||||||
import android.annotation.SuppressLint
|
import android.annotation.SuppressLint
|
||||||
|
import android.text.method.LinkMovementMethod
|
||||||
import android.view.LayoutInflater
|
import android.view.LayoutInflater
|
||||||
import android.view.View
|
import android.view.View
|
||||||
import android.view.ViewGroup
|
import android.view.ViewGroup
|
||||||
@ -27,6 +28,8 @@ import com.github.libretube.helpers.NavigationHelper
|
|||||||
import com.github.libretube.helpers.ThemeHelper
|
import com.github.libretube.helpers.ThemeHelper
|
||||||
import com.github.libretube.ui.fragments.CommentsRepliesFragment
|
import com.github.libretube.ui.fragments.CommentsRepliesFragment
|
||||||
import com.github.libretube.ui.viewholders.CommentsViewHolder
|
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 com.github.libretube.util.TextUtils
|
||||||
import kotlinx.serialization.encodeToString
|
import kotlinx.serialization.encodeToString
|
||||||
|
|
||||||
@ -35,6 +38,7 @@ class CommentsAdapter(
|
|||||||
private val videoId: String,
|
private val videoId: String,
|
||||||
private val comments: MutableList<Comment>,
|
private val comments: MutableList<Comment>,
|
||||||
private val isRepliesAdapter: Boolean = false,
|
private val isRepliesAdapter: Boolean = false,
|
||||||
|
private val handleLink: ((url: String) -> Unit)?,
|
||||||
private val dismiss: () -> Unit
|
private val dismiss: () -> Unit
|
||||||
) : RecyclerView.Adapter<CommentsViewHolder>() {
|
) : RecyclerView.Adapter<CommentsViewHolder>() {
|
||||||
fun clear() {
|
fun clear() {
|
||||||
@ -60,7 +64,10 @@ class CommentsAdapter(
|
|||||||
val comment = comments[position]
|
val comment = comments[position]
|
||||||
holder.binding.apply {
|
holder.binding.apply {
|
||||||
commentInfos.text = comment.author + TextUtils.SEPARATOR + comment.commentedTime
|
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)
|
ImageHelper.loadImage(comment.thumbnail, commentorImage)
|
||||||
likesTextView.text = comment.likeCount.formatShort()
|
likesTextView.text = comment.likeCount.formatShort()
|
||||||
@ -108,7 +115,6 @@ class CommentsAdapter(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
root.setOnLongClickListener {
|
root.setOnLongClickListener {
|
||||||
ClipboardHelper.save(root.context, comment.commentText ?: "")
|
ClipboardHelper.save(root.context, comment.commentText ?: "")
|
||||||
Toast.makeText(root.context, R.string.copied, Toast.LENGTH_SHORT).show()
|
Toast.makeText(root.context, R.string.copied, Toast.LENGTH_SHORT).show()
|
||||||
|
@ -43,7 +43,8 @@ class CommentsMainFragment : Fragment() {
|
|||||||
commentsAdapter = CommentsAdapter(
|
commentsAdapter = CommentsAdapter(
|
||||||
this,
|
this,
|
||||||
viewModel.videoId!!,
|
viewModel.videoId!!,
|
||||||
viewModel.commentsPage.value?.comments.orEmpty().toMutableList()
|
viewModel.commentsPage.value?.comments.orEmpty().toMutableList(),
|
||||||
|
handleLink = viewModel.handleLink
|
||||||
) {
|
) {
|
||||||
viewModel.commentsSheetDismiss?.invoke()
|
viewModel.commentsSheetDismiss?.invoke()
|
||||||
}
|
}
|
||||||
|
@ -49,7 +49,13 @@ class CommentsRepliesFragment : Fragment() {
|
|||||||
arguments?.getString(IntentData.comment)!!
|
arguments?.getString(IntentData.comment)!!
|
||||||
)
|
)
|
||||||
|
|
||||||
repliesAdapter = CommentsAdapter(null, videoId, mutableListOf(comment), true) {
|
repliesAdapter = CommentsAdapter(
|
||||||
|
null,
|
||||||
|
videoId,
|
||||||
|
mutableListOf(comment),
|
||||||
|
true,
|
||||||
|
viewModel.handleLink
|
||||||
|
) {
|
||||||
viewModel.commentsSheetDismiss?.invoke()
|
viewModel.commentsSheetDismiss?.invoke()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -367,6 +367,7 @@ class PlayerFragment : Fragment(R.layout.fragment_player), OnlinePlayerOptions {
|
|||||||
binding.commentsToggle.setOnClickListener {
|
binding.commentsToggle.setOnClickListener {
|
||||||
videoId ?: return@setOnClickListener
|
videoId ?: return@setOnClickListener
|
||||||
// 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.maxHeight = binding.root.height - binding.player.height
|
commentsViewModel.maxHeight = binding.root.height - binding.player.height
|
||||||
commentsViewModel.videoId = videoId
|
commentsViewModel.videoId = videoId
|
||||||
CommentsSheet().show(childFragmentManager)
|
CommentsSheet().show(childFragmentManager)
|
||||||
|
@ -21,6 +21,7 @@ class CommentsViewModel : ViewModel() {
|
|||||||
var videoId: String? = null
|
var videoId: String? = null
|
||||||
var maxHeight: Int = 0
|
var maxHeight: Int = 0
|
||||||
var commentsSheetDismiss: (() -> Unit)? = null
|
var commentsSheetDismiss: (() -> Unit)? = null
|
||||||
|
var handleLink: ((url: String) -> Unit)? = null
|
||||||
|
|
||||||
fun fetchComments() {
|
fun fetchComments() {
|
||||||
videoId ?: return
|
videoId ?: return
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
<?xml version="1.0" encoding="utf-8"?>
|
<?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:app="http://schemas.android.com/apk/res-auto"
|
||||||
xmlns:tools="http://schemas.android.com/tools"
|
xmlns:tools="http://schemas.android.com/tools"
|
||||||
android:layout_width="match_parent"
|
android:layout_width="match_parent"
|
||||||
@ -14,9 +14,7 @@
|
|||||||
android:layout_marginBottom="16dp"
|
android:layout_marginBottom="16dp"
|
||||||
android:orientation="horizontal"
|
android:orientation="horizontal"
|
||||||
android:paddingStart="15dp"
|
android:paddingStart="15dp"
|
||||||
android:paddingEnd="15dp"
|
android:paddingEnd="15dp">
|
||||||
app:layout_constraintBottom_toBottomOf="parent"
|
|
||||||
app:layout_constraintTop_toTopOf="parent">
|
|
||||||
|
|
||||||
<com.google.android.material.imageview.ShapeableImageView
|
<com.google.android.material.imageview.ShapeableImageView
|
||||||
android:id="@+id/commentor_image"
|
android:id="@+id/commentor_image"
|
||||||
@ -75,7 +73,6 @@
|
|||||||
android:layout_marginTop="5dp"
|
android:layout_marginTop="5dp"
|
||||||
android:layout_marginBottom="8dp"
|
android:layout_marginBottom="8dp"
|
||||||
android:textSize="15sp"
|
android:textSize="15sp"
|
||||||
android:autoLink="web"
|
|
||||||
android:textAlignment="viewStart"
|
android:textAlignment="viewStart"
|
||||||
tools:text="Comment Text" />
|
tools:text="Comment Text" />
|
||||||
|
|
||||||
@ -125,4 +122,4 @@
|
|||||||
|
|
||||||
|
|
||||||
</LinearLayout>
|
</LinearLayout>
|
||||||
</androidx.constraintlayout.widget.ConstraintLayout>
|
</LinearLayout>
|
||||||
|
Loading…
x
Reference in New Issue
Block a user