diff --git a/app/src/main/java/com/github/libretube/ui/adapters/CommentsAdapter.kt b/app/src/main/java/com/github/libretube/ui/adapters/CommentsAdapter.kt index 98cf79bfc..35d52c5dc 100644 --- a/app/src/main/java/com/github/libretube/ui/adapters/CommentsAdapter.kt +++ b/app/src/main/java/com/github/libretube/ui/adapters/CommentsAdapter.kt @@ -1,10 +1,10 @@ package com.github.libretube.ui.adapters import android.annotation.SuppressLint +import android.os.Handler +import android.os.Looper import android.text.method.LinkMovementMethod -import android.view.LayoutInflater -import android.view.View -import android.view.ViewGroup +import android.view.* import android.view.ViewGroup.MarginLayoutParams import android.widget.Toast import androidx.appcompat.content.res.AppCompatResources @@ -41,6 +41,7 @@ class CommentsAdapter( private val handleLink: ((url: String) -> Unit)?, private val dismiss: () -> Unit ) : RecyclerView.Adapter() { + fun clear() { val size: Int = comments.size comments.clear() @@ -59,6 +60,17 @@ class CommentsAdapter( return CommentsViewHolder(binding) } + private fun navigateToReplies(comment: Comment) { + val args = bundleOf( + IntentData.videoId to videoId, + IntentData.comment to JsonHelper.json.encodeToString(comment) + ) + fragment!!.parentFragmentManager.commit { + replace(R.id.commentFragContainer, args = args) + addToBackStack(null) + } + } + @SuppressLint("SetTextI18n") override fun onBindViewHolder(holder: CommentsViewHolder, position: Int) { val comment = comments[position] @@ -69,6 +81,10 @@ class CommentsAdapter( commentText.text = comment.commentText ?.parseAsHtml(tagHandler = HtmlParser(LinkHandler(handleLink ?: {}))) + commentText.setOnClickListener { + navigateToReplies(comment) + } + ImageHelper.loadImage(comment.thumbnail, commentorImage) likesTextView.text = comment.likeCount.formatShort() @@ -105,14 +121,7 @@ class CommentsAdapter( if (!isRepliesAdapter && comment.repliesPage != null) { root.setOnClickListener { - val args = bundleOf( - IntentData.videoId to videoId, - IntentData.comment to JsonHelper.json.encodeToString(comment) - ) - fragment!!.parentFragmentManager.commit { - replace(R.id.commentFragContainer, args = args) - addToBackStack(null) - } + navigateToReplies(comment) } } root.setOnLongClickListener {