Fix like button checked when not logged into polycentric

Open video details when tapping title

Changelog: changed
This commit is contained in:
Kai
2025-06-12 10:42:08 -05:00
parent 0653f88c49
commit 1f5a069877
2 changed files with 59 additions and 50 deletions
@@ -343,6 +343,13 @@ class ShortView : FrameLayout {
mainFragment.navigate<ChannelFragment>(video?.author)
}
videoTitle.setOnClickListener {
playSoundEffect(SoundEffectConstants.CLICK)
if (!bottomSheet.isAdded) {
bottomSheet.show(mainFragment.childFragmentManager, CommentsModalBottomSheet.TAG)
}
}
commentsButton.setOnClickListener {
playSoundEffect(SoundEffectConstants.CLICK)
if (!bottomSheet.isAdded) {
@@ -370,6 +377,56 @@ class ShortView : FrameLayout {
showVideoSettings()
}
likeButton.setOnClickListener {
playSoundEffect(SoundEffectConstants.CLICK)
val checked = !likeButton.isChecked
StatePolycentric.instance.requireLogin(context, context.getString(R.string.please_login_to_like)) {
if (checked) {
likes++
} else {
likes--
}
likeButton.isChecked = checked
if (dislikeButton.isChecked && checked) {
dislikeButton.isChecked = false
dislikes--
}
onLikeDislikeUpdated.emit(
OnLikeDislikeUpdatedArgs(
it, likes, likeButton.isChecked, dislikes, dislikeButton.isChecked
)
)
}
}
dislikeButton.setOnClickListener {
playSoundEffect(SoundEffectConstants.CLICK)
val checked = !dislikeButton.isChecked
StatePolycentric.instance.requireLogin(context, context.getString(R.string.please_login_to_like)) {
if (checked) {
dislikes++
} else {
dislikes--
}
dislikeButton.isChecked = checked
if (likeButton.isChecked && checked) {
likeButton.isChecked = false
likes--
}
onLikeDislikeUpdated.emit(
OnLikeDislikeUpdatedArgs(
it, likes, likeButton.isChecked, dislikes, dislikeButton.isChecked
)
)
}
}
onLikesLoaded.subscribe(tag) { rating, liked, disliked ->
likes = rating.likes
dislikes = rating.dislikes
@@ -378,52 +435,6 @@ class ShortView : FrameLayout {
dislikeContainer.visibility = VISIBLE
likeContainer.visibility = VISIBLE
likeButton.addOnCheckedChangeListener { button, checked ->
playSoundEffect(SoundEffectConstants.CLICK)
StatePolycentric.instance.requireLogin(context, context.getString(R.string.please_login_to_like)) {
if (checked) {
likes++
} else {
likes--
}
if (dislikeButton.isChecked && checked) {
// Chain reaction
dislikeButton.isChecked = false
} else {
// No chain reaction submit changes
onLikeDislikeUpdated.emit(
OnLikeDislikeUpdatedArgs(
it, likes, likeButton.isChecked, dislikes, dislikeButton.isChecked
)
)
}
}
}
dislikeButton.addOnCheckedChangeListener { button, checked ->
playSoundEffect(SoundEffectConstants.CLICK)
StatePolycentric.instance.requireLogin(context, context.getString(R.string.please_login_to_like)) {
if (checked) {
dislikes++
} else {
dislikes--
}
if (likeButton.isChecked && checked) {
// Chain reaction
likeButton.isChecked = false
} else {
// No chain reaction submit changes
onLikeDislikeUpdated.emit(
OnLikeDislikeUpdatedArgs(
it, likes, likeButton.isChecked, dislikes, dislikeButton.isChecked
)
)
}
}
}
}
}
@@ -732,8 +743,6 @@ class ShortView : FrameLayout {
private fun loadLikes(video: IPlatformVideo) {
likeContainer.visibility = GONE
dislikeContainer.visibility = GONE
likeButton.clearOnCheckedChangeListeners()
dislikeButton.clearOnCheckedChangeListeners()
loadLikesTask?.cancel()
loadLikesTask =
@@ -99,7 +99,7 @@
app:iconSize="24dp"
app:iconTint="@android:color/white"
app:rippleColor="@color/ripple"
app:toggleCheckedStateOnClick="true" />
app:toggleCheckedStateOnClick="false" />
<TextView
android:id="@+id/like_count"
@@ -133,7 +133,7 @@
app:iconSize="24dp"
app:iconTint="@android:color/white"
app:rippleColor="@color/ripple"
app:toggleCheckedStateOnClick="true" />
app:toggleCheckedStateOnClick="false" />
<TextView
android:id="@+id/dislike_count"