@@ -19,10 +19,9 @@ package com.ichi2.ui
1919import android.content.Context
2020import android.util.AttributeSet
2121import android.view.LayoutInflater
22- import android.widget.Button
2322import android.widget.LinearLayout
24- import android.widget.TextView
2523import com.ichi2.anki.R
24+ import com.ichi2.anki.databinding.AxisDisplayBinding
2625import com.ichi2.anki.reviewer.Axis
2726import com.ichi2.anki.reviewer.Binding
2827import timber.log.Timber
@@ -31,12 +30,13 @@ import timber.log.Timber
3130 * Displays live values of an [Axis] (joystick/trigger), and allows selection of a binding if an
3231 * [extremity][AxisValueDisplay.isExtremity] has been received
3332 *
34- * The [name ] of the Axis (AXIS_X)
33+ * The [axisName][AxisDisplayBinding.axisName ] of the Axis (AXIS_X)
3534 *
3635 * The [value] of the Axis [-1, 1]
3736 * - If a value hits an extremity, the display changes color. See [AxisValueDisplay]
3837 *
39- * Two buttons: [minButton] and [maxButton]
38+ * Two buttons: [selectMinExtremity][AxisDisplayBinding.selectMinExtremity] and
39+ * [selectMaxExtremity][AxisDisplayBinding.selectMaxExtremity]
4040 * - If an [extremity][AxisValueDisplay.isExtremity] is reached, these are activated
4141 * - Calls [onExtremitySelectedListener] if tapped
4242 *
@@ -52,34 +52,24 @@ class AxisSelector : LinearLayout {
5252 defStyle,
5353 )
5454
55- private val name: TextView
56- private val minButton: Button
57- private val axisDisplay: AxisValueDisplay
58- private val maxButton: Button
55+ private val binding = AxisDisplayBinding .inflate(LayoutInflater .from(context), this , true )
5956
6057 private var onExtremitySelectedListener: ((Binding .AxisButtonBinding ) -> Unit )? = null
6158
6259 init {
63- val inflater = LayoutInflater .from(context)
64- inflater.inflate(R .layout.axis_display, this , true )
65- name = findViewById(R .id.axis_name)
66- minButton = findViewById(R .id.select_min_extremity)
67- axisDisplay = findViewById(R .id.axis_value)
68- maxButton = findViewById(R .id.select_max_extremity)
69-
7060 // Disabling buttons ensures that a user cannot map a negative value on a unidirectional
7161 // axis, such as the triggers on my 8BitDo
7262 // It's hard to know if an axis is single, or multidimensional until we've received input
73- axisDisplay.setExtremityListener { valueAtExtremity ->
63+ binding. axisDisplay.setExtremityListener { valueAtExtremity ->
7464 when (valueAtExtremity) {
7565 - 1f -> enableMinButton()
7666 1f -> enableMaxButton()
7767 }
7868 }
7969
8070 // call onExtremitySelectedListener
81- minButton .setOnClickListener { selectMinimumValue() }
82- maxButton .setOnClickListener { selectMaximumValue() }
71+ binding.selectMinExtremity .setOnClickListener { selectMinimumValue() }
72+ binding.selectMaxExtremity .setOnClickListener { selectMaximumValue() }
8373 }
8474
8575 private fun selectMaximumValue () {
@@ -93,15 +83,15 @@ class AxisSelector : LinearLayout {
9383 }
9484
9585 private fun enableMaxButton () {
96- if (maxButton .isEnabled) return
86+ if (binding.selectMaxExtremity .isEnabled) return
9787 Timber .i(" %s: max button enabled" , axis)
98- maxButton .isEnabled = true
88+ binding.selectMaxExtremity .isEnabled = true
9989 }
10090
10191 private fun enableMinButton () {
102- if (minButton .isEnabled) return
92+ if (binding.selectMinExtremity .isEnabled) return
10393 Timber .i(" %s: min button enabled" , axis)
104- minButton .isEnabled = true
94+ binding.selectMinExtremity .isEnabled = true
10595 }
10696
10797 /* *
@@ -117,12 +107,12 @@ class AxisSelector : LinearLayout {
117107
118108 /* * The name of the axis */
119109 var text: String
120- get() = name .text.toString()
110+ get() = binding.axisName .text.toString()
121111 private set(value) {
122- name .text = value
112+ binding.axisName .text = value
123113 }
124114
125- var value: Float by axisDisplay::value
115+ var value: Float by binding. axisDisplay::value
126116
127117 fun setOnExtremitySelectedListener (listener : ((Binding .AxisButtonBinding ) -> Unit )? ) {
128118 onExtremitySelectedListener = listener
0 commit comments