Merge pull request #2910 from faisalcodes/master

Added the original comment as the first item in replies.
This commit is contained in:
Bnyro 2023-01-30 16:57:42 +01:00 committed by GitHub
commit cb88ae9eea
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
8 changed files with 53 additions and 30 deletions

View File

@ -18,5 +18,5 @@ object IntentData {
const val downloading = "downloading" const val downloading = "downloading"
const val openAudioPlayer = "openAudioPlayer" const val openAudioPlayer = "openAudioPlayer"
const val fragmentToOpen = "fragmentToOpen" const val fragmentToOpen = "fragmentToOpen"
const val replyPage = "replyPage" const val comment = "comment"
} }

View File

@ -5,11 +5,16 @@ import android.os.Bundle
import android.view.LayoutInflater import android.view.LayoutInflater
import android.view.View import android.view.View
import android.view.ViewGroup import android.view.ViewGroup
import android.view.ViewGroup.MarginLayoutParams
import android.widget.Toast import android.widget.Toast
import androidx.appcompat.content.res.AppCompatResources
import androidx.core.text.parseAsHtml import androidx.core.text.parseAsHtml
import androidx.core.view.updateLayoutParams
import androidx.core.view.updatePadding
import androidx.fragment.app.Fragment import androidx.fragment.app.Fragment
import androidx.recyclerview.widget.RecyclerView import androidx.recyclerview.widget.RecyclerView
import com.github.libretube.R import com.github.libretube.R
import com.github.libretube.api.JsonHelper
import com.github.libretube.api.obj.Comment import com.github.libretube.api.obj.Comment
import com.github.libretube.constants.IntentData import com.github.libretube.constants.IntentData
import com.github.libretube.databinding.CommentsRowBinding import com.github.libretube.databinding.CommentsRowBinding
@ -20,6 +25,7 @@ import com.github.libretube.util.ClipboardHelper
import com.github.libretube.util.ImageHelper import com.github.libretube.util.ImageHelper
import com.github.libretube.util.NavigationHelper import com.github.libretube.util.NavigationHelper
import com.github.libretube.util.TextUtils import com.github.libretube.util.TextUtils
import com.github.libretube.util.ThemeHelper
class CommentsAdapter( class CommentsAdapter(
private val fragment: Fragment?, private val fragment: Fragment?,
@ -69,11 +75,30 @@ class CommentsAdapter(
dismiss.invoke() dismiss.invoke()
} }
if (isRepliesAdapter) {
repliesCount.visibility = View.GONE
repliesAvailable.visibility = View.GONE
// highlight the comment that is being replied to
if (comment == comments.firstOrNull()) {
root.setBackgroundColor(
ThemeHelper.getThemeColor(root.context, R.attr.colorSurface)
)
root.updatePadding(top = 20)
root.updateLayoutParams<MarginLayoutParams> { bottomMargin = 20 }
} else {
root.background = AppCompatResources.getDrawable(root.context, R.drawable.rounded_ripple)
}
}
if (!isRepliesAdapter && comment.repliesPage != null) { if (!isRepliesAdapter && comment.repliesPage != null) {
val repliesFragment = CommentsRepliesFragment().apply { val repliesFragment = CommentsRepliesFragment().apply {
arguments = Bundle().apply { arguments = Bundle().apply {
putString(IntentData.videoId, videoId) putString(IntentData.videoId, videoId)
putString(IntentData.replyPage, comment.repliesPage) putString(
IntentData.comment,
JsonHelper.json.encodeToString(Comment.serializer(), comment)
)
} }
} }
root.setOnClickListener { root.setOnClickListener {

View File

@ -5,10 +5,13 @@ import android.util.Log
import android.view.LayoutInflater import android.view.LayoutInflater
import android.view.View import android.view.View
import android.view.ViewGroup import android.view.ViewGroup
import androidx.core.view.updatePadding
import androidx.fragment.app.Fragment import androidx.fragment.app.Fragment
import androidx.fragment.app.activityViewModels import androidx.fragment.app.activityViewModels
import androidx.recyclerview.widget.LinearLayoutManager import androidx.recyclerview.widget.LinearLayoutManager
import com.github.libretube.api.JsonHelper
import com.github.libretube.api.RetrofitInstance import com.github.libretube.api.RetrofitInstance
import com.github.libretube.api.obj.Comment
import com.github.libretube.api.obj.CommentsPage import com.github.libretube.api.obj.CommentsPage
import com.github.libretube.constants.IntentData import com.github.libretube.constants.IntentData
import com.github.libretube.databinding.FragmentCommentsBinding import com.github.libretube.databinding.FragmentCommentsBinding
@ -40,13 +43,17 @@ class CommentsRepliesFragment : Fragment() {
override fun onViewCreated(view: View, savedInstanceState: Bundle?) { override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
super.onViewCreated(view, savedInstanceState) super.onViewCreated(view, savedInstanceState)
val videoId = arguments?.getString(IntentData.videoId) ?: "" val videoId = arguments?.getString(IntentData.videoId) ?: ""
val nextPage = arguments?.getString(IntentData.replyPage) ?: "" val comment = JsonHelper.json.decodeFromString(
Comment.serializer(),
arguments?.getString(IntentData.comment)!!
)
repliesAdapter = CommentsAdapter(null, videoId, mutableListOf(), true) { repliesAdapter = CommentsAdapter(null, videoId, mutableListOf(comment), true) {
viewModel.commentsSheetDismiss?.invoke() viewModel.commentsSheetDismiss?.invoke()
} }
binding.commentsRV.layoutManager = LinearLayoutManager(view.context) binding.commentsRV.updatePadding(top = 0)
binding.commentsRV.layoutManager = LinearLayoutManager(context)
binding.commentsRV.adapter = repliesAdapter binding.commentsRV.adapter = repliesAdapter
binding.commentsRV.viewTreeObserver binding.commentsRV.viewTreeObserver
@ -61,7 +68,7 @@ class CommentsRepliesFragment : Fragment() {
} }
} }
loadInitialReplies(videoId, nextPage, repliesAdapter) loadInitialReplies(videoId, comment.repliesPage ?: "", repliesAdapter)
} }
private fun loadInitialReplies( private fun loadInitialReplies(
@ -69,17 +76,10 @@ class CommentsRepliesFragment : Fragment() {
nextPage: String, nextPage: String,
repliesAdapter: CommentsAdapter repliesAdapter: CommentsAdapter
) { ) {
when (repliesAdapter.itemCount) { binding.progress.visibility = View.VISIBLE
0 -> { fetchReplies(videoId, nextPage) {
binding.progress.visibility = View.VISIBLE repliesAdapter.updateItems(it.comments)
fetchReplies(videoId, nextPage) { binding.progress.visibility = View.GONE
repliesAdapter.updateItems(it.comments)
binding.progress.visibility = View.GONE
}
}
else -> {
repliesAdapter.clear()
}
} }
} }

View File

@ -525,9 +525,13 @@ class PlayerFragment : BaseFragment(), OnlinePlayerOptions {
} }
private fun toggleDescription() { private fun toggleDescription() {
var viewInfo = if (!streams.livestream) TextUtils.SEPARATOR + localizedDate( var viewInfo = if (!streams.livestream) {
streams.uploadDate TextUtils.SEPARATOR + localizedDate(
) else "" streams.uploadDate
)
} else {
""
}
if (binding.descLinLayout.isVisible) { if (binding.descLinLayout.isVisible) {
// hide the description and chapters // hide the description and chapters
binding.playerDescriptionArrow.animate().rotation(0F).setDuration(250).start() binding.playerDescriptionArrow.animate().rotation(0F).setDuration(250).start()

View File

@ -4,7 +4,7 @@
xmlns:tools="http://schemas.android.com/tools" xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:background="?selectableItemBackground"> android:background="@drawable/rounded_ripple">
<LinearLayout <LinearLayout
android:layout_width="match_parent" android:layout_width="match_parent"
@ -14,6 +14,7 @@
android:orientation="vertical" android:orientation="vertical"
android:paddingStart="15dp" android:paddingStart="15dp"
android:paddingEnd="15dp" android:paddingEnd="15dp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintTop_toTopOf="parent"> app:layout_constraintTop_toTopOf="parent">
<LinearLayout <LinearLayout
@ -49,7 +50,7 @@
android:ellipsize="end" android:ellipsize="end"
android:maxLines="2" android:maxLines="2"
android:textSize="14sp" android:textSize="14sp"
android:textColor="@color/text_color_secondary" android:textColor="?android:attr/textColorSecondary"
tools:text="Author and Time" /> tools:text="Author and Time" />
<ImageView <ImageView

View File

@ -24,7 +24,7 @@
android:layout_height="20dp" android:layout_height="20dp"
android:paddingTop="8dp" android:paddingTop="8dp"
android:paddingBottom="0dp" android:paddingBottom="0dp"
app:tint="@color/drag_handle_color" /> app:tint="?android:attr/textColorSecondaryInverse" />
<LinearLayout <LinearLayout
android:layout_width="match_parent" android:layout_width="match_parent"

View File

@ -1,5 +0,0 @@
<?xml version="1.0" encoding="utf-8"?>
<resources>
<color name="text_color_secondary">#BFBFBF</color>
<color name="drag_handle_color">#3A3A3A</color>
</resources>

View File

@ -3,8 +3,6 @@
<color name="duration_background_color">#AA000000</color> <color name="duration_background_color">#AA000000</color>
<color name="duration_text_color">#EEFFFFFF</color> <color name="duration_text_color">#EEFFFFFF</color>
<color name="shortcut_color">#0061A6</color> <color name="shortcut_color">#0061A6</color>
<color name="text_color_secondary">#505050</color>
<color name="drag_handle_color">#CCCCCC</color>
<color name="blue_md_theme_light_primary">#0058CB</color> <color name="blue_md_theme_light_primary">#0058CB</color>
<color name="blue_md_theme_light_onPrimary">#FFFFFF</color> <color name="blue_md_theme_light_onPrimary">#FFFFFF</color>