Committed by
GitHub
speaker highlighting added on sample-app (#125) (#126)
* speaker highlighting added on sample-app (#125) * Update ParticipantItem.kt
正在显示
1 个修改的文件
包含
28 行增加
和
0 行删除
| 1 | package io.livekit.android.sample | 1 | package io.livekit.android.sample |
| 2 | 2 | ||
| 3 | + | ||
| 4 | +import android.graphics.Color | ||
| 5 | +import android.graphics.drawable.GradientDrawable | ||
| 3 | import android.view.View | 6 | import android.view.View |
| 4 | import com.github.ajalt.timberkt.Timber | 7 | import com.github.ajalt.timberkt.Timber |
| 5 | import com.xwray.groupie.viewbinding.BindableItem | 8 | import com.xwray.groupie.viewbinding.BindableItem |
| @@ -45,6 +48,15 @@ class ParticipantItem( | @@ -45,6 +48,15 @@ class ParticipantItem( | ||
| 45 | } | 48 | } |
| 46 | } | 49 | } |
| 47 | coroutineScope?.launch { | 50 | coroutineScope?.launch { |
| 51 | + participant::isSpeaking.flow.collect { isSpeaking -> | ||
| 52 | + if (isSpeaking) { | ||
| 53 | + showFocus(viewBinding) | ||
| 54 | + } else { | ||
| 55 | + hideFocus(viewBinding) | ||
| 56 | + } | ||
| 57 | + } | ||
| 58 | + } | ||
| 59 | + coroutineScope?.launch { | ||
| 48 | participant::audioTracks.flow | 60 | participant::audioTracks.flow |
| 49 | .flatMapLatest { tracks -> | 61 | .flatMapLatest { tracks -> |
| 50 | val audioTrack = tracks.firstOrNull()?.first | 62 | val audioTrack = tracks.firstOrNull()?.first |
| @@ -154,3 +166,19 @@ private fun View.visibleOrInvisible(visible: Boolean) { | @@ -154,3 +166,19 @@ private fun View.visibleOrInvisible(visible: Boolean) { | ||
| 154 | View.INVISIBLE | 166 | View.INVISIBLE |
| 155 | } | 167 | } |
| 156 | } | 168 | } |
| 169 | + | ||
| 170 | +private fun showFocus(binding: ParticipantItemBinding) { | ||
| 171 | + val border = GradientDrawable() | ||
| 172 | + border.setColor(Color.BLUE) | ||
| 173 | + border.setStroke(8, -0x1000000) | ||
| 174 | + binding.root.setPadding(16,16,16,16) | ||
| 175 | + binding.root.background = border | ||
| 176 | +} | ||
| 177 | + | ||
| 178 | +private fun hideFocus(binding: ParticipantItemBinding) { | ||
| 179 | + val border = GradientDrawable() | ||
| 180 | + border.setColor(Color.TRANSPARENT) | ||
| 181 | + border.setStroke(0, -0x1000000) | ||
| 182 | + binding.root.setPadding(0,0,0,0) | ||
| 183 | + binding.root.background = border | ||
| 184 | +} |
-
请 注册 或 登录 后发表评论