mirror of
https://github.com/kvorschk/Magisk.git
synced 2026-12-05 03:20:46 -05:00
This commit fixes the issue of adding single-span items in between full-span items whilst using `StaggeredGridLayoutManager` on recycler view. Adding such items results in: ``` java.lang.ArrayIndexOutOfBoundsException: Array index out of range: 13 at java.util.Arrays.rangeCheck(Arrays.java:123) at java.util.Arrays.fill(Arrays.java:2828) at androidx.recyclerview.widget.StaggeredGridLayoutManager$LazySpanLookup.invalidateAfter(StaggeredGridLayoutManager.java:2876) at androidx.recyclerview.widget.StaggeredGridLayoutManager.handleUpdate(StaggeredGridLayoutManager.java:1548) at androidx.recyclerview.widget.StaggeredGridLayoutManager.onItemsUpdated(StaggeredGridLayoutManager.java:1524) at androidx.recyclerview.widget.RecyclerView$6.dispatchUpdate(RecyclerView.java:1021) at androidx.recyclerview.widget.RecyclerView$6.onDispatchSecondPass(RecyclerView.java:1032) at androidx.recyclerview.widget.AdapterHelper.consumePostponedUpdates(AdapterHelper.java:121) at androidx.recyclerview.widget.AdapterHelper.consumeUpdatesInOnePass(AdapterHelper.java:557) at androidx.recyclerview.widget.RecyclerView.dispatchLayoutStep2(RecyclerView.java:4128) at androidx.recyclerview.widget.RecyclerView.dispatchLayout(RecyclerView.java:3851) at androidx.recyclerview.widget.RecyclerView.onLayout(RecyclerView.java:4404) ...and more ``` Affects versions including and prior to androidx.recyclerview:recyclerview:1.2.0-alpha02 (at the time of this commit) and possibly more after that. This bug is caused by a single fact and that is - array inside of `LazySpanLookup` is not being invalidated and resized correctly when non-full-span item is being added in between of two full-span items. The invalidation however passes on some (high performance) devices so it doesn't necessarily cause issues for _some_ users; others keep getting the same crash over and over again. Possible fix for anyone reading this, in the hope of fixing the same error, is to copy-paste the `StaggeredGridLayoutManager` and fix the array length before calling `Arrays.fill()`. There's no fix from user's perspective if you need to keep the UI as-is. We however don't need the UI as-is, so we're instead opting to use LinearLayoutManager until is the issue resolved. Continues tracking at https://issuetracker.google.com/issues/37034096 Close #2631
129 lines
5.2 KiB
XML
129 lines
5.2 KiB
XML
<?xml version="1.0" encoding="utf-8"?>
|
|
<layout xmlns:android="http://schemas.android.com/apk/res/android"
|
|
xmlns:app="http://schemas.android.com/apk/res-auto"
|
|
xmlns:tools="http://schemas.android.com/tools">
|
|
|
|
<data>
|
|
|
|
<import type="com.topjohnwu.magisk.core.Config" />
|
|
|
|
<variable
|
|
name="viewModel"
|
|
type="com.topjohnwu.magisk.ui.module.ModuleViewModel" />
|
|
|
|
</data>
|
|
|
|
<FrameLayout
|
|
android:layout_width="match_parent"
|
|
android:layout_height="match_parent">
|
|
|
|
<!--
|
|
The list is reverted to use LinearLayoutManager only. The issue of random crashes lies in
|
|
the way StaggeredGridLayoutManager invalidates view in LazySpanLookup. Since we're adding
|
|
items in between full-span items the array is not yet invalidated and consecutively crashes
|
|
due to index of -end- being out of bounds of the current array.
|
|
|
|
If you'd like to use StaggeredGridLayoutManager, do so without adding single span items in
|
|
between of full-span items.
|
|
https://issuetracker.google.com/issues/37034096
|
|
-->
|
|
|
|
<androidx.recyclerview.widget.RecyclerView
|
|
android:id="@+id/module_list"
|
|
adapter="@{viewModel.adapter}"
|
|
dividerHorizontal="@{@drawable/divider_l1}"
|
|
dividerVertical="@{@drawable/divider_l1}"
|
|
gone="@{viewModel.loading && viewModel.items.empty}"
|
|
itemBinding="@{viewModel.itemBinding}"
|
|
items="@{viewModel.items}"
|
|
spanCount="@{Config.listSpanCount}"
|
|
android:layout_width="match_parent"
|
|
android:layout_height="match_parent"
|
|
android:clipToPadding="false"
|
|
android:orientation="vertical"
|
|
android:paddingStart="@dimen/l1"
|
|
android:paddingTop="@{viewModel.insets.top + (int) @dimen/internal_action_bar_size + (int) @dimen/l1}"
|
|
android:paddingEnd="0dp"
|
|
android:paddingBottom="@{viewModel.insets.bottom + (int) @dimen/internal_action_bar_size + (int) @dimen/l1}"
|
|
app:layoutManager="androidx.recyclerview.widget.LinearLayoutManager"
|
|
tools:listitem="@layout/item_module_md2" />
|
|
|
|
<com.google.android.material.floatingactionbutton.FloatingActionButton
|
|
android:id="@+id/module_filter_toggle"
|
|
android:layout_width="wrap_content"
|
|
android:layout_height="wrap_content"
|
|
android:layout_gravity="bottom|end"
|
|
android:layout_marginStart="@dimen/l1"
|
|
android:layout_marginEnd="@dimen/l1"
|
|
android:layout_marginBottom="@{viewModel.insets.bottom + (int) @dimen/l1}"
|
|
app:backgroundTint="?colorSurfaceSurfaceVariant"
|
|
app:srcCompat="@drawable/ic_filter"
|
|
app:tint="?colorPrimary"
|
|
tools:layout_marginBottom="64dp" />
|
|
|
|
<com.google.android.material.circularreveal.cardview.CircularRevealCardView
|
|
android:id="@+id/module_filter"
|
|
style="@style/WidgetFoundation.Card.Variant"
|
|
android:layout_width="match_parent"
|
|
android:layout_height="match_parent"
|
|
android:layout_gravity="bottom"
|
|
android:visibility="invisible"
|
|
app:cardCornerRadius="0dp">
|
|
|
|
<include
|
|
android:id="@+id/module_filter_include"
|
|
layout="@layout/include_module_filter"
|
|
viewModel="@{viewModel}"
|
|
android:layout_width="match_parent"
|
|
android:layout_height="match_parent" />
|
|
|
|
</com.google.android.material.circularreveal.cardview.CircularRevealCardView>
|
|
|
|
<LinearLayout
|
|
goneUnless="@{viewModel.loading && viewModel.items.empty}"
|
|
android:layout_width="match_parent"
|
|
android:layout_height="wrap_content"
|
|
android:layout_gravity="center"
|
|
android:gravity="center"
|
|
android:orientation="vertical">
|
|
|
|
<androidx.appcompat.widget.AppCompatTextView
|
|
android:layout_width="wrap_content"
|
|
android:layout_height="wrap_content"
|
|
android:text="@string/safetynet_attest_loading"
|
|
android:textAppearance="@style/AppearanceFoundation.Title"
|
|
android:textStyle="bold" />
|
|
|
|
<ProgressBar
|
|
style="@style/WidgetFoundation.ProgressBar.Indeterminate"
|
|
android:layout_marginTop="@dimen/l1" />
|
|
|
|
</LinearLayout>
|
|
|
|
<FrameLayout
|
|
goneUnless="@{viewModel.remoteLoading}"
|
|
android:layout_width="match_parent"
|
|
android:layout_height="4dp"
|
|
android:layout_gravity="bottom">
|
|
|
|
<FrameLayout
|
|
android:layout_width="match_parent"
|
|
android:layout_height="16dp"
|
|
android:layout_gravity="center"
|
|
tools:ignore="UselessParent">
|
|
|
|
<ProgressBar
|
|
style="@style/WidgetFoundation.ProgressBar.Indeterminate"
|
|
android:layout_width="match_parent"
|
|
android:layout_height="match_parent"
|
|
android:layout_gravity="center" />
|
|
|
|
</FrameLayout>
|
|
|
|
</FrameLayout>
|
|
|
|
</FrameLayout>
|
|
|
|
|
|
</layout>
|