@@ -4,28 +4,42 @@ import android.os.Build
44import android.support.constraint.ConstraintLayout
55import android.text.Html
66import android.view.View
7+ import android.widget.ImageView
8+ import android.widget.TextView
79import com.algolia.instantsearch.voice.R
8- import kotlinx.android.synthetic.main.voice_input.view.*
9-
1010
1111class VoiceAndroidView (
1212 private val view : ConstraintLayout
1313) : VoiceUI {
1414
1515 private val context = view.context
16-
17- override val formatterSuggestion = { suggestion: String -> context.getString(R .string.format_voice_suggestion_html, suggestion) }
16+ private val voiceInput: ConstraintLayout get() = view.findViewById(R .id.voiceInput)
17+ private val suggestionsView: TextView ? get() = view.findViewById(R .id.voiceInput)
18+ private val ConstraintLayout .close: ImageView get() = findViewById(R .id.close)
19+ private val ConstraintLayout .microphone: VoiceMicrophone get() = findViewById(R .id.microphone)
20+ private val ConstraintLayout .title: TextView get() = findViewById(R .id.microphone)
21+ private val ConstraintLayout .subtitle: TextView get() = findViewById(R .id.subtitle)
22+ private val ConstraintLayout .suggestions: TextView ? get() = findViewById(R .id.suggestions)
23+ private val ConstraintLayout .hint: TextView get() = findViewById(R .id.hint)
24+ private val ConstraintLayout .ripple: RippleView get() = findViewById(R .id.ripple)
25+
26+ override val formatterSuggestion = { suggestion: String ->
27+ context.getString(
28+ R .string.format_voice_suggestion_html,
29+ suggestion
30+ )
31+ }
1832
1933 override fun setOnClickListenerClose (onClickListener : View .OnClickListener ) {
20- view. voiceInput.close.setOnClickListener(onClickListener)
34+ voiceInput.close.setOnClickListener(onClickListener)
2135 }
2236
2337 override fun setOnClickMicrophoneListener (onClickListener : View .OnClickListener ) {
24- view. voiceInput.microphone.setOnClickListener(onClickListener)
38+ voiceInput.microphone.setOnClickListener(onClickListener)
2539 }
2640
2741 override fun setSuggestions (suggestions : Array <out String >) {
28- view.suggestions ?.let {
42+ suggestionsView ?.let {
2943 val formattedSuggestions = suggestions.joinToString(" " ) { formatterSuggestion(it) }
3044 val html = if (Build .VERSION .SDK_INT >= Build .VERSION_CODES .N ) {
3145 Html .fromHtml(formattedSuggestions, Html .FROM_HTML_MODE_LEGACY )
@@ -37,31 +51,31 @@ class VoiceAndroidView(
3751 }
3852
3953 override fun setTitle (title : VoiceUI .Title ) {
40- view. voiceInput.title.setText(title.resource)
54+ voiceInput.title.setText(title.resource)
4155 }
4256
4357 override fun setSubtitle (subtitle : String ) {
44- view. voiceInput.subtitle.text = subtitle
58+ voiceInput.subtitle.text = subtitle
4559 }
4660
4761 override fun setSubtitle (subtitle : VoiceUI .Subtitle ) {
48- view. voiceInput.subtitle.setText(subtitle.resource)
62+ voiceInput.subtitle.setText(subtitle.resource)
4963 }
5064
5165 override fun setSuggestionVisibility (isVisible : Boolean ) {
52- view. voiceInput.suggestions?.visibility = if (isVisible) View .VISIBLE else View .INVISIBLE
66+ voiceInput.suggestions?.visibility = if (isVisible) View .VISIBLE else View .INVISIBLE
5367 }
5468
5569 override fun setHintVisibility (isVisible : Boolean ) {
56- view. voiceInput.hint.visibility = if (isVisible) View .VISIBLE else View .INVISIBLE
70+ voiceInput.hint.visibility = if (isVisible) View .VISIBLE else View .INVISIBLE
5771 }
5872
5973 override fun setRippleActivity (isActive : Boolean ) =
60- if (isActive) view. voiceInput.ripple.start() else view. voiceInput.ripple.cancel()
74+ if (isActive) voiceInput.ripple.start() else voiceInput.ripple.cancel()
6175
6276 override fun setMicrophoneState (state : VoiceMicrophone .State ) {
63- view. voiceInput.microphone.state = state
77+ voiceInput.microphone.state = state
6478 }
6579
66- override fun getMicrophoneState (): VoiceMicrophone .State = view. voiceInput.microphone.state
67- }
80+ override fun getMicrophoneState (): VoiceMicrophone .State = voiceInput.microphone.state
81+ }
0 commit comments