mirror of
https://gitlab.futo.org/videostreaming/grayjay.git
synced 2025-04-20 03:24:50 +00:00
Fade mostly disliked comments.
This commit is contained in:
parent
9cf81ad20a
commit
f433cb1280
5 changed files with 49 additions and 28 deletions
|
@ -346,24 +346,24 @@ class PostDetailFragment : MainFragment {
|
|||
|
||||
_rating.visibility = VISIBLE;
|
||||
_rating.setRating(RatingLikeDislikes(likes, dislikes), hasLiked, hasDisliked);
|
||||
_rating.onLikeDislikeUpdated.subscribe(this) { processHandle, newHasLiked, newHasDisliked ->
|
||||
if (newHasLiked) {
|
||||
processHandle.opinion(ref, Opinion.like);
|
||||
} else if (newHasDisliked) {
|
||||
processHandle.opinion(ref, Opinion.dislike);
|
||||
_rating.onLikeDislikeUpdated.subscribe(this) { args ->
|
||||
if (args.hasLiked) {
|
||||
args.processHandle.opinion(ref, Opinion.like);
|
||||
} else if (args.hasDisliked) {
|
||||
args.processHandle.opinion(ref, Opinion.dislike);
|
||||
} else {
|
||||
processHandle.opinion(ref, Opinion.neutral);
|
||||
args.processHandle.opinion(ref, Opinion.neutral);
|
||||
}
|
||||
|
||||
StateApp.instance.scopeOrNull?.launch(Dispatchers.IO) {
|
||||
try {
|
||||
processHandle.fullyBackfillServers();
|
||||
args.processHandle.fullyBackfillServers();
|
||||
} catch (e: Throwable) {
|
||||
Logger.e(TAG, "Failed to backfill servers", e)
|
||||
}
|
||||
}
|
||||
|
||||
StatePolycentric.instance.updateLikeMap(ref, newHasLiked, newHasDisliked)
|
||||
StatePolycentric.instance.updateLikeMap(ref, args.hasLiked, args.hasDisliked)
|
||||
};
|
||||
}
|
||||
} catch (e: Throwable) {
|
||||
|
|
|
@ -1042,24 +1042,24 @@ class VideoDetailView : ConstraintLayout {
|
|||
withContext(Dispatchers.Main) {
|
||||
_rating.visibility = View.VISIBLE;
|
||||
_rating.setRating(RatingLikeDislikes(likes, dislikes), hasLiked, hasDisliked);
|
||||
_rating.onLikeDislikeUpdated.subscribe(this) { processHandle, newHasLiked, newHasDisliked ->
|
||||
if (newHasLiked) {
|
||||
processHandle.opinion(ref, Opinion.like);
|
||||
} else if (newHasDisliked) {
|
||||
processHandle.opinion(ref, Opinion.dislike);
|
||||
_rating.onLikeDislikeUpdated.subscribe(this) { args ->
|
||||
if (args.hasLiked) {
|
||||
args.processHandle.opinion(ref, Opinion.like);
|
||||
} else if (args.hasDisliked) {
|
||||
args.processHandle.opinion(ref, Opinion.dislike);
|
||||
} else {
|
||||
processHandle.opinion(ref, Opinion.neutral);
|
||||
args.processHandle.opinion(ref, Opinion.neutral);
|
||||
}
|
||||
|
||||
fragment.lifecycleScope.launch(Dispatchers.IO) {
|
||||
try {
|
||||
processHandle.fullyBackfillServers();
|
||||
args.processHandle.fullyBackfillServers();
|
||||
} catch (e: Throwable) {
|
||||
Logger.e(TAG, "Failed to backfill servers", e)
|
||||
}
|
||||
}
|
||||
|
||||
StatePolycentric.instance.updateLikeMap(ref, newHasLiked, newHasDisliked)
|
||||
StatePolycentric.instance.updateLikeMap(ref, args.hasLiked, args.hasDisliked)
|
||||
};
|
||||
}
|
||||
} catch (e: Throwable) {
|
||||
|
|
|
@ -43,7 +43,7 @@ class StateTelemetry {
|
|||
);
|
||||
|
||||
val headers = hashMapOf(
|
||||
"Content-Type" to "text/plain"
|
||||
"Content-Type" to "application/json"
|
||||
);
|
||||
|
||||
val json = Json.encodeToString(telemetry);
|
||||
|
|
|
@ -6,6 +6,7 @@ import android.view.ViewGroup
|
|||
import android.widget.ImageView
|
||||
import android.widget.LinearLayout
|
||||
import android.widget.TextView
|
||||
import androidx.constraintlayout.widget.ConstraintLayout
|
||||
import androidx.recyclerview.widget.RecyclerView.ViewHolder
|
||||
import com.futo.platformplayer.*
|
||||
import com.futo.platformplayer.api.media.models.comments.IPlatformComment
|
||||
|
@ -35,12 +36,14 @@ class CommentViewHolder : ViewHolder {
|
|||
private val _buttonReplies: PillButton;
|
||||
private val _layoutRating: LinearLayout;
|
||||
private val _pillRatingLikesDislikes: PillRatingLikesDislikes;
|
||||
private val _layoutComment: ConstraintLayout;
|
||||
|
||||
var onClick = Event1<IPlatformComment>();
|
||||
var comment: IPlatformComment? = null
|
||||
private set;
|
||||
|
||||
constructor(viewGroup: ViewGroup) : super(LayoutInflater.from(viewGroup.context).inflate(R.layout.list_comment, viewGroup, false)) {
|
||||
_layoutComment = itemView.findViewById(R.id.layout_comment);
|
||||
_creatorThumbnail = itemView.findViewById(R.id.image_thumbnail);
|
||||
_textAuthor = itemView.findViewById(R.id.text_author);
|
||||
_textMetadata = itemView.findViewById(R.id.text_metadata);
|
||||
|
@ -53,29 +56,31 @@ class CommentViewHolder : ViewHolder {
|
|||
_layoutRating = itemView.findViewById(R.id.layout_rating);
|
||||
_pillRatingLikesDislikes = itemView.findViewById(R.id.rating);
|
||||
|
||||
_pillRatingLikesDislikes.onLikeDislikeUpdated.subscribe { processHandle, hasLiked, hasDisliked ->
|
||||
_pillRatingLikesDislikes.onLikeDislikeUpdated.subscribe { args ->
|
||||
val c = comment
|
||||
if (c !is PolycentricPlatformComment) {
|
||||
throw Exception("Not implemented for non polycentric comments")
|
||||
}
|
||||
|
||||
if (hasLiked) {
|
||||
processHandle.opinion(c.reference, Opinion.like);
|
||||
} else if (hasDisliked) {
|
||||
processHandle.opinion(c.reference, Opinion.dislike);
|
||||
if (args.hasLiked) {
|
||||
args.processHandle.opinion(c.reference, Opinion.like);
|
||||
} else if (args.hasDisliked) {
|
||||
args.processHandle.opinion(c.reference, Opinion.dislike);
|
||||
} else {
|
||||
processHandle.opinion(c.reference, Opinion.neutral);
|
||||
args.processHandle.opinion(c.reference, Opinion.neutral);
|
||||
}
|
||||
|
||||
_layoutComment.alpha = if (args.dislikes > 2 && args.dislikes / (args.likes + args.dislikes) >= 0.7) 0.5f else 1.0f;
|
||||
|
||||
StateApp.instance.scopeOrNull?.launch(Dispatchers.IO) {
|
||||
try {
|
||||
processHandle.fullyBackfillServers();
|
||||
args.processHandle.fullyBackfillServers();
|
||||
} catch (e: Throwable) {
|
||||
Logger.e(TAG, "Failed to backfill servers.", e)
|
||||
}
|
||||
}
|
||||
|
||||
StatePolycentric.instance.updateLikeMap(c.reference, hasLiked, hasDisliked)
|
||||
StatePolycentric.instance.updateLikeMap(c.reference, args.hasLiked, args.hasDisliked)
|
||||
};
|
||||
|
||||
_buttonReplies.onClick.subscribe {
|
||||
|
@ -98,6 +103,13 @@ class CommentViewHolder : ViewHolder {
|
|||
_textMetadata.visibility = View.GONE;
|
||||
}
|
||||
|
||||
val rating = comment.rating;
|
||||
if (rating is RatingLikeDislikes) {
|
||||
_layoutComment.alpha = if (rating.dislikes > 0 && rating.dislikes / (rating.likes + rating.dislikes) >= 0.7) 0.5f else 1.0f;
|
||||
} else {
|
||||
_layoutComment.alpha = 1.0f;
|
||||
}
|
||||
|
||||
_textBody.text = comment.message.fixHtmlLinks();
|
||||
|
||||
if (readonly) {
|
||||
|
|
|
@ -12,11 +12,20 @@ import com.futo.platformplayer.R
|
|||
import com.futo.platformplayer.api.media.models.ratings.IRating
|
||||
import com.futo.platformplayer.api.media.models.ratings.RatingLikeDislikes
|
||||
import com.futo.platformplayer.api.media.models.ratings.RatingLikes
|
||||
import com.futo.platformplayer.constructs.Event1
|
||||
import com.futo.platformplayer.constructs.Event3
|
||||
import com.futo.platformplayer.states.StatePolycentric
|
||||
import com.futo.platformplayer.toHumanNumber
|
||||
import com.futo.polycentric.core.ProcessHandle
|
||||
|
||||
data class OnLikeDislikeUpdatedArgs(
|
||||
val processHandle: ProcessHandle,
|
||||
val likes: Long,
|
||||
val hasLiked: Boolean,
|
||||
val dislikes: Long,
|
||||
val hasDisliked: Boolean,
|
||||
);
|
||||
|
||||
class PillRatingLikesDislikes : LinearLayout {
|
||||
private val _textLikes: TextView;
|
||||
private val _textDislikes: TextView;
|
||||
|
@ -29,7 +38,7 @@ class PillRatingLikesDislikes : LinearLayout {
|
|||
private var _dislikes = 0L;
|
||||
private var _hasDisliked = false;
|
||||
|
||||
val onLikeDislikeUpdated = Event3<ProcessHandle, Boolean, Boolean>();
|
||||
val onLikeDislikeUpdated = Event1<OnLikeDislikeUpdatedArgs>();
|
||||
|
||||
constructor(context : Context, attrs : AttributeSet?) : super(context, attrs) {
|
||||
LayoutInflater.from(context).inflate(R.layout.rating_likesdislikes, this, true);
|
||||
|
@ -76,7 +85,7 @@ class PillRatingLikesDislikes : LinearLayout {
|
|||
|
||||
_textLikes.text = _likes.toHumanNumber();
|
||||
updateColors();
|
||||
onLikeDislikeUpdated.emit(processHandle, _hasLiked, _hasDisliked);
|
||||
onLikeDislikeUpdated.emit(OnLikeDislikeUpdatedArgs(processHandle, _likes, _hasLiked, _dislikes, _hasDisliked));
|
||||
}
|
||||
|
||||
fun dislike(processHandle: ProcessHandle) {
|
||||
|
@ -96,7 +105,7 @@ class PillRatingLikesDislikes : LinearLayout {
|
|||
|
||||
_textDislikes.text = _dislikes.toHumanNumber();
|
||||
updateColors();
|
||||
onLikeDislikeUpdated.emit(processHandle, _hasLiked, _hasDisliked);
|
||||
onLikeDislikeUpdated.emit(OnLikeDislikeUpdatedArgs(processHandle, _likes, _hasLiked, _dislikes, _hasDisliked));
|
||||
}
|
||||
|
||||
private fun updateColors() {
|
||||
|
|
Loading…
Add table
Reference in a new issue