Browse Source

voice: played bars white, yellow cursor line on waveform

topo_upd
evgeny 2 months ago
parent
commit
b8e15ad1f2
  1. 22
      tools/chatgui-android/app/src/main/java/com/utun/chat/ui/components/MessageBubble.kt

22
tools/chatgui-android/app/src/main/java/com/utun/chat/ui/components/MessageBubble.kt

@ -125,23 +125,33 @@ private fun VoiceBubble(message: Message, textColor: Color, onPlay: (String, ()
Canvas(modifier = Modifier.weight(1f).height(28.dp)) { Canvas(modifier = Modifier.weight(1f).height(28.dp)) {
val barW = size.width / wfCount val barW = size.width / wfCount
val ph = size.height val ph = size.height
val playedIdx = if (progress > 0f) (progress * wfCount).toInt() else 0 val playedIdx = if (playing && progress > 0f) (progress * wfCount).toInt() else 0
for (i in 0 until wfCount) { for (i in 0 until wfCount) {
val level = wf[i].coerceIn(0f, 1f) val level = wf[i].coerceIn(0f, 1f)
val barH = (2f + level * (ph - 2f)).coerceAtMost(ph) val barH = (2f + level * (ph - 2f)).coerceAtMost(ph)
val x = i.toFloat() * barW val x = i.toFloat() * barW
val y = ph - barH val y = ph - barH
val played = i < playedIdx val played = playing && i < playedIdx
drawRect( drawRect(
color = if (playing) { color = when {
if (played) Color(0xFF3390EC) else Color(0xFF3390EC).copy(alpha = 0.35f) played -> Color.White
} else { playing -> Color(0xFFCCCCD4).copy(alpha = 0.8f)
Color(0xFFCCCCD4).copy(alpha = 0.8f) else -> Color(0xFFCCCCD4).copy(alpha = 0.8f)
}, },
topLeft = Offset(x, y), topLeft = Offset(x, y),
size = Size(barW * 0.75f, barH) size = Size(barW * 0.75f, barH)
) )
} }
/* yellow cursor line */
if (playing && progress > 0f && progress < 1f) {
val cursorX = progress * size.width
drawLine(
color = Color(0xFFFFD600),
start = Offset(cursorX, 0f),
end = Offset(cursorX, ph),
strokeWidth = 2.5f
)
}
} }
} }
} }

Loading…
Cancel
Save