主播评级:私聊回复率展示优化

This commit is contained in:
huangjian
2023-02-20 14:44:56 +08:00
parent e4637305fa
commit dfe2f0d1c9
4 changed files with 62 additions and 103 deletions

View File

@@ -49,8 +49,8 @@ class AnchorGradeDialog : BaseDialog<DialogAnchorGradeBinding>() {
}
override var width: Int = WindowManager.LayoutParams.MATCH_PARENT
override var height: Int = WindowManager.LayoutParams.WRAP_CONTENT
override var width: Int = ScreenUtil.dip2px(300f)
override var height: Int = ScreenUtil.dip2px(280f)
private val meViewModel: MeViewModel by viewModels()
@@ -64,6 +64,7 @@ class AnchorGradeDialog : BaseDialog<DialogAnchorGradeBinding>() {
anchorDrawableResIds[it.grade.uppercase(Locale.getDefault())]?.let { resId ->
binding.ivCurrLevel.setImageResource(resId)
}
binding.tvCurrentGrade.text = it.currentGrade
setupDiamond(it)
setupReply(it)
@@ -183,80 +184,43 @@ class AnchorGradeDialog : BaseDialog<DialogAnchorGradeBinding>() {
if (!it.satisfyReply) {
binding.groupReply.isVisible = false
binding.tvSatisfyReply.isVisible = true
binding.tvReplayTargetNum.isVisible = false
return
}
binding.pbReplay.max = 1000
binding.pbReplay.max = 100
binding.tvReplayTargetNum.text = "${(it.currentReply * 100).toInt()}%"
var startEndIDReply = R.id.tv_replay_d
var endEndIDReply = R.id.tv_replay_c
if (0 <= it.currentReply && it.currentReply < it.levelCReply) {
binding.ivReplayLevelD.setImageResource(R.drawable.anchor_grade_ic_level_current)
binding.pbReplay.progress =
((it.currentReply / it.levelCReply * 250).toInt()
.coerceAtLeast(30))
.coerceAtMost(220)
binding.tvReplayGap.text =
"还差${((it.levelCReply - it.currentReply) * 100).toInt()}%"
} else if (it.levelCReply <= it.currentReply && it.currentReply < it.levelBReply) {
binding.ivReplayLevelC.setImageResource(R.drawable.anchor_grade_ic_level_current)
binding.ivReplayLevelC.isVisible = true
binding.pbDiamond.progress =
(((it.currentReply - it.levelCReply) / (it.levelBReply - it.levelCReply) * 250).toInt()
.coerceAtLeast(15) + 250)
.coerceAtMost(485)
startEndIDReply = R.id.tv_replay_c
endEndIDReply = R.id.tv_replay_b
binding.tvReplayGap.text =
"还差${((it.levelBReply - it.currentReply) * 100).toInt()}%"
} else if (it.levelBReply <= it.currentReply && it.currentReply < it.levelAReply) {
binding.ivReplayLevelB.setImageResource(R.drawable.anchor_grade_ic_level_current)
binding.ivReplayLevelC.isVisible = true
binding.ivReplayLevelB.isVisible = true
binding.pbReplay.progress =
(((it.currentReply - it.levelBReply) / (it.levelAReply - it.levelBReply) * 250).toInt()
.coerceAtLeast(15) + 500)
.coerceAtMost(735)
startEndIDReply = R.id.tv_replay_b
endEndIDReply = R.id.tv_replay_a
binding.tvReplayGap.text =
"还差${((it.levelAReply - it.currentReply) * 100).toInt()}%"
} else if (it.levelAReply <= it.currentReply && it.currentReply < it.levelSReply) {
binding.ivReplayLevelA.setImageResource(R.drawable.anchor_grade_ic_level_current)
binding.ivReplayLevelC.isVisible = true
binding.ivReplayLevelB.isVisible = true
binding.ivReplayLevelA.isVisible = true
binding.pbReplay.progress =
(((it.currentReply - it.levelAReply) / (it.levelSReply - it.levelAReply) * 250).toInt()
.coerceAtLeast(30) + 750)
.coerceAtMost(970)
startEndIDReply = R.id.tv_replay_a
endEndIDReply = R.id.tv_replay_s
binding.tvReplayGap.text =
"还差${((it.levelSReply - it.currentReply) * 100).toInt()}%"
} else {
binding.ivReplayLevelS.setImageResource(R.drawable.anchor_grade_ic_level_current)
binding.ivReplayLevelC.isVisible = true
binding.ivReplayLevelB.isVisible = true
binding.ivReplayLevelA.isVisible = true
binding.ivReplayLevelS.isVisible = true
binding.pbReplay.progress = binding.pbReplay.max
binding.tvReplayGap.isGone = true
when (it.replyRateGrade) {
"D" -> {
binding.ivReplayLevelD.setImageResource(R.drawable.anchor_grade_ic_level_current)
binding.pbReplay.progress = 0
}
"C" -> {
binding.ivReplayLevelC.setImageResource(R.drawable.anchor_grade_ic_level_current)
binding.ivReplayLevelC.isVisible = true
binding.pbDiamond.progress = 25
}
"B" -> {
binding.ivReplayLevelB.setImageResource(R.drawable.anchor_grade_ic_level_current)
binding.ivReplayLevelC.isVisible = true
binding.ivReplayLevelB.isVisible = true
binding.pbReplay.progress = 50
}
"A" -> {
binding.ivReplayLevelA.setImageResource(R.drawable.anchor_grade_ic_level_current)
binding.ivReplayLevelC.isVisible = true
binding.ivReplayLevelB.isVisible = true
binding.ivReplayLevelA.isVisible = true
binding.pbReplay.progress = 75
}
"S" -> {
binding.ivReplayLevelS.setImageResource(R.drawable.anchor_grade_ic_level_current)
binding.ivReplayLevelC.isVisible = true
binding.ivReplayLevelB.isVisible = true
binding.ivReplayLevelA.isVisible = true
binding.ivReplayLevelS.isVisible = true
binding.pbReplay.progress = binding.pbReplay.max
}
}
val constraintSet = ConstraintSet()
constraintSet.clone(binding.clRoot)
constraintSet.connect(
R.id.tv_replay_gap,
ConstraintSet.START,
startEndIDReply,
ConstraintSet.END
)
constraintSet.connect(
R.id.tv_replay_gap,
ConstraintSet.END,
endEndIDReply,
ConstraintSet.START
)
constraintSet.applyTo(binding.clRoot)
}
override fun onDestroyView() {

Binary file not shown.

Before

Width:  |  Height:  |  Size: 97 KiB

After

Width:  |  Height:  |  Size: 93 KiB

View File

@@ -15,23 +15,12 @@
android:background="@drawable/anchor_grade_bg"
android:orientation="vertical">
<TextView
android:id="@+id/tv_curr_text"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="16dp"
android:text="当前评级"
android:textColor="@color/white"
android:textSize="10sp"
app:layout_constraintEnd_toStartOf="@id/iv_curr_level"
app:layout_constraintTop_toTopOf="parent" />
<ImageView
android:id="@+id/iv_curr_level"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="11dp"
android:layout_marginEnd="8dp"
android:layout_marginEnd="9dp"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintTop_toTopOf="parent"
tools:src="@drawable/anchor_grade_ic_level_a" />
@@ -46,12 +35,33 @@
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
<TextView
android:id="@+id/tv_curr_grade_text"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="4dp"
android:text="实时评级:"
android:textColor="#ff171a58"
android:textSize="12sp"
app:layout_constraintStart_toStartOf="@id/iv_title"
app:layout_constraintTop_toBottomOf="@id/iv_title" />
<TextView
android:id="@+id/tv_current_grade"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textColor="#fff86099"
android:textSize="12sp"
app:layout_constraintBaseline_toBaselineOf="@id/tv_curr_grade_text"
app:layout_constraintStart_toEndOf="@id/tv_curr_grade_text"
tools:text="X" />
<TextView
android:id="@+id/tv_diamond"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="20dp"
android:layout_marginTop="25dp"
android:layout_marginTop="36dp"
android:text="收礼钻石数:"
android:textColor="#8A8CAB"
android:textSize="11sp"
@@ -364,19 +374,6 @@
app:layout_constraintStart_toStartOf="@id/iv_replay_level_s"
app:layout_constraintTop_toBottomOf="@id/view_bg_replay_pb" />
<TextView
android:id="@+id/tv_replay_gap"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="2dp"
android:fontFamily="sans-serif"
android:textColor="@color/color_babbcd"
android:textSize="10dp"
app:layout_constraintEnd_toEndOf="@id/tv_replay_s"
app:layout_constraintStart_toStartOf="@id/tv_replay_a"
app:layout_constraintTop_toBottomOf="@id/view_bg_replay_pb"
tools:text="还差10%" />
<TextView
android:id="@+id/tv_satisfy_reply"
android:layout_width="260dp"
@@ -396,7 +393,7 @@
android:id="@+id/group_reply"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
app:constraint_referenced_ids="iv_replay_level_d,tv_replay_d,tv_replay_c,tv_replay_b,tv_replay_a,tv_replay_s,pb_replay,view_bg_replay_pb,tv_replay_gap" />
app:constraint_referenced_ids="iv_replay_level_d,tv_replay_d,tv_replay_c,tv_replay_b,tv_replay_a,tv_replay_s,pb_replay,view_bg_replay_pb" />
<ImageView
android:id="@+id/iv_update_text"