Fix search highlight issues

This cl fixes two kinds of issues.
1) Highlight two different preferences while clicking a search result.
2) Preference only is  highlighted one time.

For the first problem, we don't allow to reuse view holder in the
highlight scenario, and then allow it later.

The root cause of second problem is scrolling to target preference
needs x milliseconds. Thus, we should wait a few milliseconds, and
then start to highlight preference.

Test: Test some search results, and see the correct behavior
Fix: 186060148
Fix: 186010165
Fix: 187886982
Change-Id: I7df3e34efe39ee386fe9ce91d7d6c52cf390e2e7
This commit is contained in:
Tsung-Mao Fang
2021-05-13 21:22:56 +08:00
parent 15d75cf59a
commit 582f4a961e
2 changed files with 23 additions and 12 deletions

View File

@@ -184,7 +184,7 @@ public class HighlightablePreferenceGroupAdapterTest {
assertThat(mAdapter.mFadeInAnimated).isTrue();
assertThat(mViewHolder.itemView.getBackground()).isInstanceOf(ColorDrawable.class);
assertThat(mViewHolder.itemView.getTag(R.id.preference_highlighted)).isEqualTo(true);
verify(mAdapter).requestRemoveHighlightDelayed(mViewHolder.itemView);
verify(mAdapter).requestRemoveHighlightDelayed(mViewHolder);
}
@Test
@@ -197,14 +197,14 @@ public class HighlightablePreferenceGroupAdapterTest {
// through animation.
assertThat(mAdapter.mFadeInAnimated).isTrue();
// remove highlight should be requested.
verify(mAdapter).requestRemoveHighlightDelayed(mViewHolder.itemView);
verify(mAdapter).requestRemoveHighlightDelayed(mViewHolder);
ReflectionHelpers.setField(mAdapter, "mHighlightPosition", 10);
mAdapter.updateBackground(mViewHolder, 10);
// only sets background color once - if it's animation this would be called many times
verify(mViewHolder.itemView).setBackgroundColor(mAdapter.mHighlightColor);
// remove highlight should be requested.
verify(mAdapter, times(2)).requestRemoveHighlightDelayed(mViewHolder.itemView);
verify(mAdapter, times(2)).requestRemoveHighlightDelayed(mViewHolder);
}
@Test