Also tint the settings icon in DashboardAdapter.setCategory().

When suggestion loader takes longer time to complete, we will first show
the dashboard with just the categories, and refresh the UI when the
suggestion is ready. However, we only tint the icon when we update both
the categories and suggestions, and hence in some case, some tile
results with icon not being tinted.

Change-Id: I023d50655349731b03c7d7aff153d2cbbd8c63e0
Fix: 37456962
Test: make RunSettingsRoboTests
This commit is contained in:
Doris Ling
2017-06-28 16:12:38 -07:00
parent 051fb19dd4
commit 067122a8e4
2 changed files with 52 additions and 23 deletions

View File

@@ -182,29 +182,7 @@ public class DashboardAdapter extends RecyclerView.Adapter<DashboardAdapter.Dash
public void setCategoriesAndSuggestions(List<DashboardCategory> categories,
List<Tile> suggestions) {
if (mDashboardFeatureProvider.shouldTintIcon()) {
// TODO: Better place for tinting?
final TypedArray a = mContext.obtainStyledAttributes(new int[]{
android.R.attr.colorControlNormal});
final int tintColor = a.getColor(0, mContext.getColor(R.color.fallback_tintColor));
a.recycle();
for (int i = 0; i < categories.size(); i++) {
for (int j = 0; j < categories.get(i).tiles.size(); j++) {
final Tile tile = categories.get(i).tiles.get(j);
if (tile.isIconTintable) {
// If this drawable is tintable, tint it to match the color.
tile.icon.setTint(tintColor);
}
}
}
for (Tile suggestion : suggestions) {
if (suggestion.isIconTintable) {
suggestion.icon.setTint(tintColor);
}
}
}
tintIcons(categories, suggestions);
final DashboardData prevData = mDashboardData;
mDashboardData = new DashboardData.Builder(prevData)
@@ -244,6 +222,8 @@ public class DashboardAdapter extends RecyclerView.Adapter<DashboardAdapter.Dash
}
public void setCategory(List<DashboardCategory> category) {
tintIcons(category, null);
final DashboardData prevData = mDashboardData;
Log.d(TAG, "adapter setCategory called");
mDashboardData = new DashboardData.Builder(prevData)
@@ -669,6 +649,32 @@ public class DashboardAdapter extends RecyclerView.Adapter<DashboardAdapter.Dash
holder.title.setText(category.title);
}
private void tintIcons(List<DashboardCategory> categories, List<Tile> suggestions) {
if (!mDashboardFeatureProvider.shouldTintIcon()) {
return;
}
// TODO: Better place for tinting?
final TypedArray a = mContext.obtainStyledAttributes(new int[]{
android.R.attr.colorControlNormal});
final int tintColor = a.getColor(0, mContext.getColor(R.color.fallback_tintColor));
a.recycle();
for (DashboardCategory category : categories) {
for (Tile tile : category.tiles) {
if (tile.isIconTintable) {
// If this drawable is tintable, tint it to match the color.
tile.icon.setTint(tintColor);
}
}
}
if (suggestions != null) {
for (Tile suggestion : suggestions) {
if (suggestion.isIconTintable) {
suggestion.icon.setTint(tintColor);
}
}
}
}
void onSaveInstanceState(Bundle outState) {
final List<Tile> suggestions = mDashboardData.getSuggestions();
final List<DashboardCategory> categories = mDashboardData.getCategories();

View File

@@ -448,6 +448,28 @@ public class DashboardAdapterTest {
verify(mockIcon).setTint(eq(0x89000000));
}
@Test
public void testSetCategories_iconTinted() {
TypedArray mockTypedArray = mock(TypedArray.class);
doReturn(mockTypedArray).when(mContext).obtainStyledAttributes(any(int[].class));
doReturn(0x89000000).when(mockTypedArray).getColor(anyInt(), anyInt());
final List<DashboardCategory> categories = new ArrayList<>();
final DashboardCategory category = mock(DashboardCategory.class);
final List<Tile> tiles = new ArrayList<>();
final Icon mockIcon = mock(Icon.class);
final Tile tile = new Tile();
tile.isIconTintable = true;
tile.icon = mockIcon;
tiles.add(tile);
category.tiles = tiles;
categories.add(category);
mDashboardAdapter.setCategory(categories);
verify(mockIcon).setTint(eq(0x89000000));
}
@Test
public void testBindConditionAndSuggestion_shouldSetSuggestionAdapterAndNoCrash() {
when(mFactory.dashboardFeatureProvider.combineSuggestionAndCondition()).thenReturn(true);
@@ -458,6 +480,7 @@ public class DashboardAdapterTest {
final List<Tile> tiles = new ArrayList<>();
tiles.add(mock(Tile.class));
category.tiles = tiles;
categories.add(category);
mDashboardAdapter.setCategoriesAndSuggestions(categories, suggestions);
final RecyclerView data = mock(RecyclerView.class);