mirror of
https://github.com/libre-tube/LibreTube.git
synced 2024-12-14 06:10:31 +05:30
Added the original comment as first item in replies.
This commit is contained in:
parent
c5e21b5f18
commit
042cf26c1c
@ -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"
|
||||
}
|
||||
|
@ -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<MarginLayoutParams> { bottomMargin = 40 }
|
||||
divider.visibility = View.VISIBLE
|
||||
} else {
|
||||
root.background = null
|
||||
root.updateLayoutParams<MarginLayoutParams> { 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 {
|
||||
|
@ -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
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -14,6 +14,7 @@
|
||||
android:orientation="vertical"
|
||||
android:paddingStart="15dp"
|
||||
android:paddingEnd="15dp"
|
||||
app:layout_constraintBottom_toTopOf="@id/divider"
|
||||
app:layout_constraintTop_toTopOf="parent">
|
||||
|
||||
<LinearLayout
|
||||
@ -132,4 +133,11 @@
|
||||
</LinearLayout>
|
||||
|
||||
</LinearLayout>
|
||||
|
||||
<com.google.android.material.divider.MaterialDivider
|
||||
android:id="@+id/divider"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:visibility="gone"
|
||||
app:layout_constraintBottom_toBottomOf="parent" />
|
||||
</androidx.constraintlayout.widget.ConstraintLayout>
|
||||
|
@ -2,4 +2,5 @@
|
||||
<resources>
|
||||
<color name="text_color_secondary">#BFBFBF</color>
|
||||
<color name="drag_handle_color">#3A3A3A</color>
|
||||
<color name="replies_original_comment_background">#222222</color>
|
||||
</resources>
|
@ -5,6 +5,7 @@
|
||||
<color name="shortcut_color">#0061A6</color>
|
||||
<color name="text_color_secondary">#505050</color>
|
||||
<color name="drag_handle_color">#CCCCCC</color>
|
||||
<color name="replies_original_comment_background">#E8E8E8</color>
|
||||
|
||||
<color name="blue_md_theme_light_primary">#0058CB</color>
|
||||
<color name="blue_md_theme_light_onPrimary">#FFFFFF</color>
|
||||
|
Loading…
Reference in New Issue
Block a user