Skip to content

Commit 0c54348

Browse files
david-allisonlukstbit
authored andcommitted
chore: convert KeyPicker to ViewBinding
Issue 11116
1 parent d5a66f7 commit 0c54348

File tree

2 files changed

+12
-13
lines changed

2 files changed

+12
-13
lines changed

AnkiDroid/src/main/java/com/ichi2/ui/KeyPicker.kt

Lines changed: 11 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -19,9 +19,7 @@ package com.ichi2.ui
1919
import android.content.Context
2020
import android.view.KeyEvent
2121
import 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
2523
import com.ichi2.anki.dialogs.WarningDisplay
2624
import com.ichi2.anki.reviewer.Binding
2725
import timber.log.Timber
@@ -33,19 +31,19 @@ typealias KeyCode = Int
3331
* This does not yet support bluetooth headsets.
3432
*/
3533
class 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
}

AnkiDroid/src/main/res/layout/dialog_key_picker.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@
3434
app:layout_constraintTop_toTopOf="parent">
3535

3636
<com.ichi2.ui.FixedTextView
37-
android:id="@+id/key_picker_selected_key"
37+
android:id="@+id/selected_key"
3838
android:layout_width="wrap_content"
3939
android:layout_height="wrap_content"
4040
android:focusable="true"

0 commit comments

Comments
 (0)