Reduce max suggestion to show to 2.

- since we now either have 1 or 2 suggestions, putting most layout
configuration in the xml instead of dynamically setting it in code.
- remove the suggestion header
- vertical center align the suggestion title text for 2 cards to make
the card with single line looks better.
- tint all suggestions icons.

Change-Id: I0130f15d530264e164e5afd7c091f165a4a6adc2
Fixes: 70573674
Fixes: 73293989
Fixes: 64986736
Test: visual and make RunSettingsRoboTests
This commit is contained in:
Doris Ling
2018-02-23 14:59:41 -08:00
parent 46d6ecc2b1
commit 7d59c441b8
11 changed files with 106 additions and 197 deletions

View File

@@ -138,31 +138,6 @@ public class DashboardAdapterTest {
verify(adapter, never()).notifyDashboardDataChanged(any());
}
@Test
public void testSuggestionDismissed_moreThanTwoSuggestions_shouldNotCrash() {
final RecyclerView data = new RecyclerView(RuntimeEnvironment.application);
final View itemView = mock(View.class);
when(itemView.findViewById(R.id.suggestion_list)).thenReturn(data);
when(itemView.findViewById(android.R.id.summary)).thenReturn(mock(TextView.class));
when(itemView.findViewById(android.R.id.title)).thenReturn(mock(TextView.class));
final DashboardAdapter.SuggestionContainerHolder holder =
new DashboardAdapter.SuggestionContainerHolder(itemView);
final List<Suggestion> suggestions = makeSuggestionsV2("pkg1", "pkg2", "pkg3", "pkg4");
final DashboardAdapter adapter = spy(new DashboardAdapter(mContext,
null /*savedInstance */, null /* conditions */,
null /* suggestionControllerMixin */,
null /* lifecycle */));
adapter.setSuggestions(suggestions);
adapter.onBindSuggestion(holder, 0);
adapter.onSuggestionClosed(suggestions.get(1));
// verify operations that access the lists will not cause ConcurrentModificationException
assertThat(holder.data.getAdapter().getItemCount()).isEqualTo(3);
adapter.setSuggestions(suggestions);
// should not crash
}
@Test
public void testSuggestionDismissed_onlySuggestion_updateDashboardData() {
DashboardAdapter adapter =
@@ -205,38 +180,6 @@ public class DashboardAdapterTest {
// should not crash
}
@Test
public void testBindSuggestion_shouldSetSummary() {
mDashboardAdapter = new DashboardAdapter(mContext, null /* savedInstanceState */,
null /* conditions */, null /* suggestionControllerMixin */, null /* lifecycle */);
final List<Suggestion> suggestions = makeSuggestionsV2("pkg1");
mDashboardAdapter.setSuggestions(suggestions);
final RecyclerView data = mock(RecyclerView.class);
when(data.getResources()).thenReturn(mResources);
when(data.getContext()).thenReturn(mContext);
when(mResources.getDisplayMetrics()).thenReturn(mock(DisplayMetrics.class));
final View itemView = mock(View.class);
when(itemView.findViewById(R.id.suggestion_list)).thenReturn(data);
final TextView summary = mock(TextView.class);
when(itemView.findViewById(android.R.id.summary)).thenReturn(summary);
when(itemView.findViewById(android.R.id.title)).thenReturn(mock(TextView.class));
final DashboardAdapter.SuggestionContainerHolder holder =
new DashboardAdapter.SuggestionContainerHolder(itemView);
mDashboardAdapter.onBindSuggestion(holder, 0);
verify(summary).setText("1");
suggestions.addAll(makeSuggestionsV2("pkg2", "pkg3", "pkg4"));
mDashboardAdapter.setSuggestions(suggestions);
mDashboardAdapter.onBindSuggestion(holder, 0);
verify(summary).setText("4");
}
@Test
public void onBindTile_internalTile_shouldNotUseGenericBackgroundIcon() {
final Context context = RuntimeEnvironment.application;

View File

@@ -94,8 +94,6 @@ public class SuggestionAdapterTest {
.thenReturn(10);
when(mResources.getDimensionPixelOffset(R.dimen.suggestion_card_outer_margin))
.thenReturn(20);
when(mResources.getDimensionPixelOffset(R.dimen.suggestion_card_width_multiple_cards))
.thenReturn(120);
mConfig = spy(SuggestionAdapter.CardConfig.get(mActivity));
mFeatureFactory = FakeFeatureFactory.setupForTest();
@@ -238,40 +236,12 @@ public class SuggestionAdapterTest {
}
@Test
public void onBindViewHolder_iconNotTintable_shouldNotTintIcon()
throws PendingIntent.CanceledException {
final Icon icon = mock(Icon.class);
final Suggestion suggestion = new Suggestion.Builder("pkg1")
.setPendingIntent(mock(PendingIntent.class))
.setIcon(icon)
.build();
final List<Suggestion> suggestions = new ArrayList<>();
suggestions.add(suggestion);
mSuggestionAdapter = new SuggestionAdapter(mActivity, mSuggestionControllerMixin,
null /* savedInstanceState */, null /* callback */, null /* lifecycle */);
mSuggestionAdapter.setSuggestions(suggestions);
mSuggestionHolder = mSuggestionAdapter.onCreateViewHolder(
new FrameLayout(RuntimeEnvironment.application),
mSuggestionAdapter.getItemViewType(0));
IconCache cache = mock(IconCache.class);
final Drawable drawable = mock(Drawable.class);
when(cache.getIcon(icon)).thenReturn(drawable);
ReflectionHelpers.setField(mSuggestionAdapter, "mCache", cache);
mSuggestionAdapter.onBindViewHolder(mSuggestionHolder, 0);
verify(drawable, never()).setTint(anyInt());
}
@Test
public void onBindViewHolder_iconTintable_shouldTintIcon()
throws PendingIntent.CanceledException {
public void onBindViewHolder_shouldTintIcon() throws PendingIntent.CanceledException {
final Icon icon = mock(Icon.class);
final int FLAG_ICON_TINTABLE = 1 << 1;
final Suggestion suggestion = new Suggestion.Builder("pkg1")
.setPendingIntent(mock(PendingIntent.class))
.setIcon(icon)
.setFlags(FLAG_ICON_TINTABLE)
.build();
final List<Suggestion> suggestions = new ArrayList<>();
suggestions.add(suggestion);
@@ -308,24 +278,13 @@ public class SuggestionAdapterTest {
.isNotNull();
}
@Test
public void setCardLayout_oneCard_shouldSetCardWidthToMatchParent() {
final List<Suggestion> suggestions = makeSuggestions("pkg1");
setupSuggestions(mContext, suggestions);
mConfig.setCardLayout(mSuggestionHolder, 1, 0);
assertThat(mSuggestionHolder.itemView.getLayoutParams().width)
.isEqualTo(LinearLayout.LayoutParams.MATCH_PARENT);
}
@Test
public void setCardLayout_twoCards_shouldSetCardWidthToHalfScreenMinusPadding() {
final List<Suggestion> suggestions = makeSuggestions("pkg1");
setupSuggestions(mContext, suggestions);
doReturn(200).when(mConfig).getScreenWidth();
mConfig.setCardLayout(mSuggestionHolder, 2, 0);
mConfig.setCardLayout(mSuggestionHolder, 0);
/*
* card width = (screen width - left margin - inner margin - right margin) / 2
@@ -335,17 +294,6 @@ public class SuggestionAdapterTest {
assertThat(mSuggestionHolder.itemView.getLayoutParams().width).isEqualTo(75);
}
@Test
public void setCardLayout_multipleCards_shouldSetCardWidthFromResource() {
final List<Suggestion> suggestions = makeSuggestions("pkg1");
setupSuggestions(mContext, suggestions);
mConfig.setCardLayout(mSuggestionHolder, 3, 0);
assertThat(mSuggestionHolder.itemView.getLayoutParams().width).isEqualTo(120);
}
private void setupSuggestions(Context context, List<Suggestion> suggestions) {
mSuggestionAdapter = new SuggestionAdapter(context, mSuggestionControllerMixin,
null /* savedInstanceState */, null /* callback */, null /* lifecycle */);