feat: add user level to comments
This commit is contained in:
parent
ce355c108e
commit
6ccdc10208
2 changed files with 26 additions and 4 deletions
|
@ -167,7 +167,10 @@ class CommentItem(val comment: Comment,
|
||||||
viewBinding.commentUserAvatar
|
viewBinding.commentUserAvatar
|
||||||
comment.profilePictureUrl?.let { viewBinding.commentUserAvatar.loadImage(it) }
|
comment.profilePictureUrl?.let { viewBinding.commentUserAvatar.loadImage(it) }
|
||||||
viewBinding.commentUserName.text = comment.username
|
viewBinding.commentUserName.text = comment.username
|
||||||
viewBinding.commentUserName.setTextColor(getAvatarColor(comment.upvotes - comment.downvotes, backgroundColor))
|
val levelColor = getAvatarColor(comment.upvotes - comment.downvotes, backgroundColor)
|
||||||
|
viewBinding.commentUserName.setTextColor(levelColor.first)
|
||||||
|
viewBinding.commentUserLevel.text = "Lv. ${levelColor.second}"
|
||||||
|
viewBinding.commentUserLevel.setTextColor(levelColor.first)
|
||||||
viewBinding.commentUserTime.text = "● ${formatTimestamp(comment.timestamp)}"
|
viewBinding.commentUserTime.text = "● ${formatTimestamp(comment.timestamp)}"
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -263,8 +266,8 @@ class CommentItem(val comment: Comment,
|
||||||
return if (l1 > l2) (l1 + 0.05) / (l2 + 0.05) else (l2 + 0.05) / (l1 + 0.05)
|
return if (l1 > l2) (l1 + 0.05) / (l2 + 0.05) else (l2 + 0.05) / (l1 + 0.05)
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun getAvatarColor(voteCount: Int, backgroundColor: Int): Int {
|
private fun getAvatarColor(voteCount: Int, backgroundColor: Int): Pair<Int, Int> {
|
||||||
val level = sqrt(abs(voteCount.toDouble()) / 0.8).toInt()
|
val level = if (voteCount < 0) 0 else sqrt(abs(voteCount.toDouble()) / 0.8).toInt()
|
||||||
val colorString = if (level > usernameColors.size - 1) usernameColors[usernameColors.size - 1] else usernameColors[level]
|
val colorString = if (level > usernameColors.size - 1) usernameColors[usernameColors.size - 1] else usernameColors[level]
|
||||||
var color = Color.parseColor(colorString)
|
var color = Color.parseColor(colorString)
|
||||||
val ratio = getContrastRatio(color, backgroundColor)
|
val ratio = getContrastRatio(color, backgroundColor)
|
||||||
|
@ -272,7 +275,7 @@ class CommentItem(val comment: Comment,
|
||||||
color = adjustColorForContrast(color, backgroundColor)
|
color = adjustColorForContrast(color, backgroundColor)
|
||||||
}
|
}
|
||||||
|
|
||||||
return color
|
return Pair(color, level)
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun adjustColorForContrast(originalColor: Int, backgroundColor: Int): Int {
|
private fun adjustColorForContrast(originalColor: Int, backgroundColor: Int): Int {
|
||||||
|
|
|
@ -15,6 +15,12 @@
|
||||||
android:padding="6dp"
|
android:padding="6dp"
|
||||||
android:orientation="horizontal">
|
android:orientation="horizontal">
|
||||||
|
|
||||||
|
<LinearLayout
|
||||||
|
android:layout_width="wrap_content"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:layout_gravity="center_vertical"
|
||||||
|
android:orientation="vertical">
|
||||||
|
|
||||||
<com.google.android.material.imageview.ShapeableImageView
|
<com.google.android.material.imageview.ShapeableImageView
|
||||||
android:id="@+id/commentUserAvatar"
|
android:id="@+id/commentUserAvatar"
|
||||||
android:layout_marginTop="4dp"
|
android:layout_marginTop="4dp"
|
||||||
|
@ -25,6 +31,19 @@
|
||||||
app:srcCompat="@drawable/ic_round_add_circle_24"
|
app:srcCompat="@drawable/ic_round_add_circle_24"
|
||||||
tools:ignore="ContentDescription,ImageContrastCheck" />
|
tools:ignore="ContentDescription,ImageContrastCheck" />
|
||||||
|
|
||||||
|
<TextView
|
||||||
|
android:id="@+id/commentUserLevel"
|
||||||
|
android:layout_width="wrap_content"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:layout_gravity="center_horizontal"
|
||||||
|
android:fontFamily="@font/poppins_semi_bold"
|
||||||
|
android:text="lvl 1"
|
||||||
|
android:textSize="12sp"
|
||||||
|
android:alpha="0.6"
|
||||||
|
tools:ignore="HardcodedText" />
|
||||||
|
|
||||||
|
</LinearLayout>
|
||||||
|
|
||||||
<LinearLayout
|
<LinearLayout
|
||||||
android:layout_width="0dp"
|
android:layout_width="0dp"
|
||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue