Fix ControllerActivity Controller Type Change Crash

If the controller type was changed from a type with a larger amount of buttons/axes to one with a fewer amount, a crash would occur due to the transition animation retaining those elements as children yet returning `NO_POSITION` from `getChildAdapterPosition` in `DividerItemDecoration` which was an unhandled case and led to an OOB array access.
This commit is contained in:
PixelyIon 2022-01-10 21:28:57 +05:30
parent 2c46709064
commit 8f0db18624

View File

@ -195,7 +195,8 @@ class ControllerActivity : AppCompatActivity() {
val divider = drawable!! val divider = drawable!!
for (i in 0 until parent.childCount) { for (i in 0 until parent.childCount) {
val view = parent.getChildAt(i) val view = parent.getChildAt(i)
if (parent.adapter!!.getItemViewType(parent.getChildAdapterPosition(view)) == adapter.getFactoryViewType(ControllerHeaderBindingFactory)) { val position = parent.getChildAdapterPosition(view)
if (position != RecyclerView.NO_POSITION && parent.adapter!!.getItemViewType(position) == adapter.getFactoryViewType(ControllerHeaderBindingFactory)) {
val bottom = view.top - view.marginTop val bottom = view.top - view.marginTop
val top = bottom - divider.intrinsicHeight val top = bottom - divider.intrinsicHeight
divider.setBounds(0, top, parent.width, bottom) divider.setBounds(0, top, parent.width, bottom)