@@ -20,10 +20,7 @@ import android.content.Context
2020import android.view.LayoutInflater
2121import android.view.MotionEvent
2222import android.view.View
23- import android.widget.LinearLayout
24- import android.widget.TextView
25- import androidx.constraintlayout.widget.ConstraintLayout
26- import com.ichi2.anki.R
23+ import com.ichi2.anki.databinding.DialogAxisPickerBinding
2724import com.ichi2.anki.reviewer.Axis
2825import com.ichi2.anki.reviewer.Binding
2926import timber.log.Timber
@@ -37,20 +34,9 @@ import timber.log.Timber
3734 * @see AxisSelector
3835 */
3936class AxisPicker (
40- val rootLayout : ConstraintLayout ,
37+ private val binding : DialogAxisPickerBinding ,
4138) {
42- // DDisplays a message asking a user to provide input to the screen
43- // We use a TextView to listen due to issues with handling AXIS_BRAKE and AXIS_GAS
44- // When listening to 'rootLayout', these axes are ONLY detected after another joystick is moved
45- private val textView: TextView = rootLayout.findViewById(R .id.axis_picker_selected_axis)
46-
47- /* * Contains [availableAxes], initially invisible */
48- private val availableAxesContainer: View = rootLayout.findViewById(R .id.axis_picker_scrollview)
49-
50- /* * Where [AxisSelector] are added dynamically if motion is detected*/
51- private val availableAxes: LinearLayout = rootLayout.findViewById(R .id.axis_picker_available_axes)
52-
53- private val context: Context get() = rootLayout.context
39+ val rootLayout = binding.root
5440
5541 /* * Maps from an [Axis] to the [AxisSelector] displaying + allowing selection of it */
5642 private val axisMap = mutableMapOf<Axis , AxisSelector >()
@@ -62,8 +48,10 @@ class AxisPicker(
6248 }
6349
6450 init {
65- textView.requestFocus()
66- textView.setOnGenericMotionListener { _, event -> handleMotionEvent(event) }
51+ // We use a TextView to listen due to issues with handling AXIS_BRAKE and AXIS_GAS
52+ // When listening to 'rootLayout', these axes are ONLY detected after another joystick is moved
53+ binding.selectedAxisTextView.requestFocus()
54+ binding.selectedAxisTextView.setOnGenericMotionListener { _, event -> handleMotionEvent(event) }
6755 }
6856
6957 @Suppress(" SameReturnValue" )
@@ -91,28 +79,28 @@ class AxisPicker(
9179
9280 // when adding the first control, we want to make the
9381 // available axes visible, so the user can see their current values
94- availableAxesContainer.visibility = View .VISIBLE
82+ binding. availableAxesContainer.visibility = View .VISIBLE
9583 // we also want to hide the TextView, but we can't make it invisible as it's
9684 // providing our input events. Blanking the text has the same effect
97- textView .text = " "
85+ binding.selectedAxisTextView .text = " "
9886
9987 // setup & return the control
100- return AxisSelector (context).also { view ->
88+ return AxisSelector (binding.root. context).also { view ->
10189 view.axis = axis
10290 view.setOnExtremitySelectedListener { binding ->
10391 Timber .d(" selected binding %s" , binding)
10492 onBindingChangedListener?.invoke(binding)
10593 }
10694
10795 axisMap[axis] = view
108- availableAxes.addView(view)
96+ binding. availableAxes.addView(view)
10997 }
11098 }
11199
112100 companion object {
113101 fun inflate (context : Context ): AxisPicker {
114- val layout = LayoutInflater .from(context).inflate( R .layout.dialog_axis_picker, null )
115- return AxisPicker (layout as ConstraintLayout )
102+ val binding = DialogAxisPickerBinding .inflate( LayoutInflater .from(context))
103+ return AxisPicker (binding )
116104 }
117105 }
118106}
0 commit comments