1+ package live.hms.roomkit.ui.meeting
2+
3+ import android.graphics.PorterDuff
4+ import android.os.Build
5+ import android.view.View
6+ import androidx.annotation.DrawableRes
7+ import androidx.core.text.bold
8+ import androidx.core.text.buildSpannedString
9+ import com.xwray.groupie.viewbinding.BindableItem
10+ import live.hms.roomkit.R
11+ import live.hms.roomkit.databinding.ItemDeviceDetailBinding
12+ import live.hms.roomkit.drawableEnd
13+ import live.hms.roomkit.drawableStart
14+ import live.hms.roomkit.setDrawables
15+ import live.hms.roomkit.setOnSingleClickListener
16+ import live.hms.roomkit.ui.theme.HMSPrebuiltTheme
17+ import live.hms.roomkit.ui.theme.getColorOrDefault
18+ import live.hms.video.audio.HMSAudioManager
19+ import live.hms.video.audio.manager.AudioManagerUtil
20+ import kotlin.math.roundToInt
21+
22+ class AudioItem (
23+ private var title : String ,
24+ private var subTitle : String? = null ,
25+ private val isSelected : Boolean ,
26+ @DrawableRes private val drawableRes : Int ,
27+ val type : HMSAudioManager .AudioDevice = HMSAudioManager .AudioDevice .AUTOMATIC ,
28+ val id : Int? = null ,
29+ private val onClick : (HMSAudioManager .AudioDevice , Int? ) -> Unit ,
30+
31+ ) : BindableItem<ItemDeviceDetailBinding>() {
32+
33+
34+ override fun bind (binding : ItemDeviceDetailBinding , position : Int ) {
35+ if (isSelected) binding.audioText.setDrawables(
36+ end = binding.audioText.context?.getDrawable(
37+ R .drawable.tick
38+ )
39+ )
40+ else binding.audioText.setDrawables(end = null )
41+
42+ binding.audioText.setDrawables(
43+ start = binding.audioText.context?.getDrawable(
44+ drawableRes
45+ )
46+ )
47+
48+
49+ binding.audioText.text = buildSpannedString {
50+ append(title)
51+ if (subTitle.isNullOrEmpty().not () && type.toString() == AudioManagerUtil .AudioDevice .BLUETOOTH .toString()) {
52+ bold { append(" ( ${subTitle.orEmpty()} )" ) }
53+ }
54+ }
55+
56+ binding.root.setOnSingleClickListener {
57+ onClick.invoke(type, id)
58+ }
59+
60+
61+ binding.audioText.setTextColor(
62+ getColorOrDefault(
63+ HMSPrebuiltTheme .getColours()?.onSurfaceHigh,
64+ HMSPrebuiltTheme .getDefaults().onsurface_high_emp
65+ )
66+ )
67+
68+ binding.audioText.drawableEnd?.setTint(
69+ getColorOrDefault(
70+ HMSPrebuiltTheme .getColours()?.onSurfaceHigh,
71+ HMSPrebuiltTheme .getDefaults().onsurface_high_emp
72+ )
73+ )
74+
75+ binding.audioText.drawableStart?.setTint(
76+ getColorOrDefault(
77+ HMSPrebuiltTheme .getColours()?.onSurfaceHigh,
78+ HMSPrebuiltTheme .getDefaults().onsurface_high_emp
79+ )
80+ )
81+
82+
83+
84+
85+ binding.border4.setBackgroundColor(
86+ getColorOrDefault(
87+ HMSPrebuiltTheme .getColours()?.borderDefault,
88+ HMSPrebuiltTheme .getDefaults().border_bright
89+ )
90+ )
91+ }
92+
93+
94+ override fun getLayout (): Int = R .layout.item_device_detail
95+
96+
97+ override fun initializeViewBinding (view : View ) = ItemDeviceDetailBinding .bind(view)
98+
99+ }
0 commit comments