Ensure search highlight position when scheduled runnable starts

Search highlight function includes two steps: Scroll list to target position first, then notifyItemChanged to it.

We use a Handler.postDelay to implement this. However, when scheduled runnable starts, the original target position could have changed due to preference list update, calling recyclerview's methods after that will be easy to cause an exception.

This CL ensures highlight position every time before calling recyclerView update, which also contribute to origin fix of RecyclerView IllegalArgumentException to a certain extent.

Test: atest, also test some search results, and see the correct behavior
Fixes: 246411107

Change-Id: Ifa758ce3718b047138079246cdfce99fdf66d5b2
This commit is contained in:
Shen Lin
2022-10-20 10:18:09 +08:00
parent bdcd3a3975
commit bb2fb2ffd6
2 changed files with 28 additions and 6 deletions

View File

@@ -129,7 +129,7 @@ public class HighlightablePreferenceGroupAdapterTest {
}
@Test
public void adjustInitialExpandedChildCount_hasHightlightKey_shouldExpandAllChildren() {
public void adjustInitialExpandedChildCount_hasHighlightKey_shouldExpandAllChildren() {
final Bundle args = new Bundle();
when(mFragment.getArguments()).thenReturn(args);
args.putString(SettingsActivity.EXTRA_FRAGMENT_ARG_KEY, "testkey");
@@ -208,7 +208,7 @@ public class HighlightablePreferenceGroupAdapterTest {
}
@Test
public void updateBackground_reuseHightlightedRowForNormalRow_shouldResetBackgroundAndTag() {
public void updateBackground_reuseHighlightedRowForNormalRow_shouldResetBackgroundAndTag() {
ReflectionHelpers.setField(mAdapter, "mHighlightPosition", 10);
mViewHolder.itemView.setTag(R.id.preference_highlighted, true);