Skip to content

Commit

Permalink
Address review comments, display parent comment
Browse files Browse the repository at this point in the history
  • Loading branch information
Isira-Seneviratne committed Feb 6, 2024
1 parent 47c4976 commit 99099a9
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -35,10 +35,14 @@ class CommentPagingAdapter(
private val fragment: Fragment?,
private val videoId: String,
private val channelAvatar: String?,
private val isRepliesAdapter: Boolean = false,
private val parentComment: Comment? = null,
private val handleLink: ((url: String) -> Unit)?,
private val dismiss: () -> Unit
) : PagingDataAdapter<Comment, CommentsViewHolder>(CommentCallback) {
private val isRepliesAdapter = parentComment != null

override fun getItemCount() = (if (isRepliesAdapter) 1 else 0) + super.getItemCount()

private fun navigateToReplies(comment: Comment) {
val args = bundleOf(IntentData.videoId to videoId, IntentData.comment to comment)
fragment!!.parentFragmentManager.commit {
Expand All @@ -48,7 +52,11 @@ class CommentPagingAdapter(
}

override fun onBindViewHolder(holder: CommentsViewHolder, position: Int) {
val comment = getItem(position)!!
val comment = if (parentComment != null) {

Check failure on line 55 in app/src/main/java/com/github/libretube/ui/adapters/CommentPagingAdapter.kt

View workflow job for this annotation

GitHub Actions / Check Code Quality

[ktlint] reported by reviewdog 🐶 A multiline expression should start on a new line Raw Output: app/src/main/java/com/github/libretube/ui/adapters/CommentPagingAdapter.kt:55:23: error: A multiline expression should start on a new line (standard:multiline-expression-wrapping)
if (position == 0) parentComment else getItem(position - 1)!!
} else {
getItem(position)!!
}
holder.binding.apply {
commentAuthor.text = comment.author
commentAuthor.setBackgroundResource(
Expand All @@ -61,6 +69,7 @@ class CommentPagingAdapter(
commentText.text = comment.commentText?.replace("</a>", "</a> ")
?.parseAsHtml(tagHandler = HtmlParser(LinkHandler(handleLink ?: {})))

commentorImage.setImageDrawable(null)
ImageHelper.loadImage(comment.thumbnail, commentorImage, true)
likesTextView.text = comment.likeCount.formatShort()

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,11 @@ import androidx.lifecycle.lifecycleScope
import androidx.lifecycle.repeatOnLifecycle
import androidx.paging.LoadState
import androidx.recyclerview.widget.LinearLayoutManager
import com.github.libretube.R
import com.github.libretube.api.obj.Comment
import com.github.libretube.constants.IntentData
import com.github.libretube.databinding.FragmentCommentsBinding
import com.github.libretube.extensions.formatShort
import com.github.libretube.extensions.parcelable
import com.github.libretube.ui.adapters.CommentPagingAdapter
import com.github.libretube.ui.models.CommentsViewModel
Expand Down Expand Up @@ -53,11 +55,15 @@ class CommentsRepliesFragment : Fragment() {
null,
videoId,
viewModel.channelAvatar,
true,
comment,
viewModel.handleLink,
) {
viewModel.commentsSheetDismiss?.invoke()
}
(parentFragment as CommentsSheet).updateFragmentInfo(
true,
"${getString(R.string.replies)} (${comment.replyCount.formatShort()})"
)

binding.commentsRV.updatePadding(top = 0)
binding.commentsRV.layoutManager = LinearLayoutManager(context)
Expand All @@ -69,12 +75,11 @@ class CommentsRepliesFragment : Fragment() {
repeatOnLifecycle(Lifecycle.State.STARTED) {
launch {
repliesAdapter.loadStateFlow.collect {
binding.progress.isVisible = it.append is LoadState.Loading
binding.progress.isVisible = it.refresh is LoadState.Loading
}
}

launch {
// TODO: Display the original selected comment as well.
viewModel.commentRepliesFlow.collect {
repliesAdapter.submitData(it)
}
Expand Down

0 comments on commit 99099a9

Please sign in to comment.