diff --git a/app/src/main/java/com/github/libretube/constants/IntentData.kt b/app/src/main/java/com/github/libretube/constants/IntentData.kt index 843d7c797..fd88c6f0c 100644 --- a/app/src/main/java/com/github/libretube/constants/IntentData.kt +++ b/app/src/main/java/com/github/libretube/constants/IntentData.kt @@ -18,5 +18,5 @@ object IntentData { const val downloading = "downloading" const val openAudioPlayer = "openAudioPlayer" const val fragmentToOpen = "fragmentToOpen" - const val replyPage = "replyPage" + const val comment = "comment" } 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 72e9fa107..b7b9a5bbf 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 @@ -5,8 +5,11 @@ import android.os.Bundle import android.view.LayoutInflater import android.view.View import android.view.ViewGroup +import android.view.ViewGroup.MarginLayoutParams import android.widget.Toast +import androidx.core.content.ContextCompat import androidx.core.text.parseAsHtml +import androidx.core.view.updateLayoutParams import androidx.fragment.app.Fragment import androidx.recyclerview.widget.RecyclerView import com.github.libretube.R @@ -20,6 +23,7 @@ import com.github.libretube.util.ClipboardHelper import com.github.libretube.util.ImageHelper import com.github.libretube.util.NavigationHelper import com.github.libretube.util.TextUtils +import kotlinx.serialization.json.Json class CommentsAdapter( private val fragment: Fragment?, @@ -69,11 +73,26 @@ class CommentsAdapter( dismiss.invoke() } + if (isRepliesAdapter) { + repliesCount.visibility = View.GONE + repliesAvailable.visibility = View.GONE + + if (position == 0) { + root.setBackgroundColor(ContextCompat.getColor(root.context, R.color.replies_original_comment_background)) + root.updateLayoutParams { bottomMargin = 40 } + divider.visibility = View.VISIBLE + } else { + root.background = null + root.updateLayoutParams { bottomMargin = 0 } + divider.visibility = View.GONE + } + } + if (!isRepliesAdapter && comment.repliesPage != null) { val repliesFragment = CommentsRepliesFragment().apply { arguments = Bundle().apply { putString(IntentData.videoId, videoId) - putString(IntentData.replyPage, comment.repliesPage) + putString(IntentData.comment, Json.encodeToString(Comment.serializer(), comment)) } } root.setOnClickListener { diff --git a/app/src/main/java/com/github/libretube/ui/fragments/CommentsRepliesFragment.kt b/app/src/main/java/com/github/libretube/ui/fragments/CommentsRepliesFragment.kt index 33f61757b..5ad1046d3 100644 --- a/app/src/main/java/com/github/libretube/ui/fragments/CommentsRepliesFragment.kt +++ b/app/src/main/java/com/github/libretube/ui/fragments/CommentsRepliesFragment.kt @@ -5,10 +5,12 @@ import android.util.Log import android.view.LayoutInflater import android.view.View import android.view.ViewGroup +import androidx.core.view.updatePadding import androidx.fragment.app.Fragment import androidx.fragment.app.activityViewModels import androidx.recyclerview.widget.LinearLayoutManager import com.github.libretube.api.RetrofitInstance +import com.github.libretube.api.obj.Comment import com.github.libretube.api.obj.CommentsPage import com.github.libretube.constants.IntentData import com.github.libretube.databinding.FragmentCommentsBinding @@ -19,6 +21,7 @@ import kotlinx.coroutines.CoroutineScope import kotlinx.coroutines.Dispatchers import kotlinx.coroutines.launch import kotlinx.coroutines.withContext +import kotlinx.serialization.json.Json class CommentsRepliesFragment : Fragment() { private lateinit var binding: FragmentCommentsBinding @@ -40,12 +43,16 @@ class CommentsRepliesFragment : Fragment() { override fun onViewCreated(view: View, savedInstanceState: Bundle?) { super.onViewCreated(view, savedInstanceState) val videoId = arguments?.getString(IntentData.videoId) ?: "" - val nextPage = arguments?.getString(IntentData.replyPage) ?: "" + val comment = Json.decodeFromString( + Comment.serializer(), + arguments?.getString(IntentData.comment) ?: """{}""", + ) - repliesAdapter = CommentsAdapter(null, videoId, mutableListOf(), true) { + repliesAdapter = CommentsAdapter(null, videoId, mutableListOf(comment), true) { viewModel.commentsSheetDismiss?.invoke() } + binding.commentsRV.updatePadding(top = 0) binding.commentsRV.layoutManager = LinearLayoutManager(view.context) binding.commentsRV.adapter = repliesAdapter @@ -61,7 +68,7 @@ class CommentsRepliesFragment : Fragment() { } } - loadInitialReplies(videoId, nextPage, repliesAdapter) + loadInitialReplies(videoId, comment.repliesPage ?: "", repliesAdapter) } private fun loadInitialReplies( @@ -69,17 +76,10 @@ class CommentsRepliesFragment : Fragment() { nextPage: String, repliesAdapter: CommentsAdapter ) { - when (repliesAdapter.itemCount) { - 0 -> { - binding.progress.visibility = View.VISIBLE - fetchReplies(videoId, nextPage) { - repliesAdapter.updateItems(it.comments) - binding.progress.visibility = View.GONE - } - } - else -> { - repliesAdapter.clear() - } + binding.progress.visibility = View.VISIBLE + fetchReplies(videoId, nextPage) { + repliesAdapter.updateItems(it.comments) + binding.progress.visibility = View.GONE } } diff --git a/app/src/main/res/layout/comments_row.xml b/app/src/main/res/layout/comments_row.xml index abad110c8..9ef69d288 100644 --- a/app/src/main/res/layout/comments_row.xml +++ b/app/src/main/res/layout/comments_row.xml @@ -14,6 +14,7 @@ android:orientation="vertical" android:paddingStart="15dp" android:paddingEnd="15dp" + app:layout_constraintBottom_toTopOf="@id/divider" app:layout_constraintTop_toTopOf="parent"> + + diff --git a/app/src/main/res/values-night/colors.xml b/app/src/main/res/values-night/colors.xml index f4247d820..6f15bd6cd 100644 --- a/app/src/main/res/values-night/colors.xml +++ b/app/src/main/res/values-night/colors.xml @@ -2,4 +2,5 @@ #BFBFBF #3A3A3A + #222222 \ No newline at end of file diff --git a/app/src/main/res/values/colors.xml b/app/src/main/res/values/colors.xml index e23e7aa9c..4d70e9767 100644 --- a/app/src/main/res/values/colors.xml +++ b/app/src/main/res/values/colors.xml @@ -5,6 +5,7 @@ #0061A6 #505050 #CCCCCC + #E8E8E8 #0058CB #FFFFFF