@@ -19,9 +19,7 @@ package com.ichi2.ui
1919import android.content.Context
2020import android.view.KeyEvent
2121import android.view.LayoutInflater
22- import android.view.View
23- import android.widget.TextView
24- import com.ichi2.anki.R
22+ import com.ichi2.anki.databinding.DialogKeyPickerBinding
2523import com.ichi2.anki.dialogs.WarningDisplay
2624import com.ichi2.anki.reviewer.Binding
2725import timber.log.Timber
@@ -33,19 +31,19 @@ typealias KeyCode = Int
3331 * This does not yet support bluetooth headsets.
3432 */
3533class KeyPicker (
36- val rootLayout : View ,
34+ private val viewBinding : DialogKeyPickerBinding ,
3735) : WarningDisplay {
38- private val textView : TextView = rootLayout.findViewById( R .id.key_picker_selected_key)
36+ val rootLayout = viewBinding.root
3937
40- override val warningTextView: FixedTextView = rootLayout.findViewById( R .id. warning)
38+ override val warningTextView: FixedTextView = viewBinding. warning
4139
4240 private val context: Context get() = rootLayout.context
4341
4442 private var text: String
4543 set(value) {
46- textView .text = value
44+ viewBinding.selectedKey .text = value
4745 }
48- get() = textView .text.toString()
46+ get() = viewBinding.selectedKey .text.toString()
4947
5048 private var onBindingChangedListener: ((Binding ) -> Unit )? = null
5149 private var isValidKeyCode: ((KeyCode ) -> Boolean )? = null
@@ -80,14 +78,15 @@ class KeyPicker(
8078 }
8179
8280 init {
83- textView .requestFocus()
84- textView .setOnKeyListener { _, _, event -> dispatchKeyEvent(event) }
81+ viewBinding.selectedKey .requestFocus()
82+ viewBinding.selectedKey .setOnKeyListener { _, _, event -> dispatchKeyEvent(event) }
8583 }
8684
8785 companion object {
8886 fun inflate (context : Context ): KeyPicker {
89- val layout = LayoutInflater .from(context).inflate(R .layout.dialog_key_picker, null )
90- return KeyPicker (layout)
87+ val layoutInflater = LayoutInflater .from(context)
88+ val binding = DialogKeyPickerBinding .inflate(layoutInflater)
89+ return KeyPicker (binding)
9190 }
9291 }
9392}
0 commit comments