Code cleanup: DashboardAdapter.category is no longer a list

We only ever display a single DashboardCategory in homepaeg, so the
category doesn't need to be a list in DashboardData/Adapter

Change-Id: I57db02bb45cbc511f0fce1bf33043b51ef9db15c
Fix: 33861822
Test: updated robotests
This commit is contained in:
Fan Zhang
2017-06-29 14:35:41 -07:00
parent 283895c03b
commit b487fae5d8
5 changed files with 58 additions and 80 deletions

View File

@@ -107,7 +107,7 @@ public class DashboardAdapter extends RecyclerView.Adapter<DashboardAdapter.Dash
List<Condition> conditions, SuggestionParser suggestionParser,
SuggestionDismissController.Callback callback) {
List<Tile> suggestions = null;
List<DashboardCategory> categories = null;
DashboardCategory category = null;
int suggestionConditionMode = DashboardData.HEADER_MODE_DEFAULT;
mContext = context;
@@ -123,7 +123,7 @@ public class DashboardAdapter extends RecyclerView.Adapter<DashboardAdapter.Dash
if (savedInstanceState != null) {
suggestions = savedInstanceState.getParcelableArrayList(STATE_SUGGESTION_LIST);
categories = savedInstanceState.getParcelableArrayList(STATE_CATEGORY_LIST);
category = savedInstanceState.getParcelable(STATE_CATEGORY_LIST);
suggestionConditionMode = savedInstanceState.getInt(
STATE_SUGGESTION_CONDITION_MODE, suggestionConditionMode);
mSuggestionsShownLogged = savedInstanceState.getStringArrayList(
@@ -135,7 +135,7 @@ public class DashboardAdapter extends RecyclerView.Adapter<DashboardAdapter.Dash
mDashboardData = new DashboardData.Builder()
.setConditions(conditions)
.setSuggestions(suggestions)
.setCategories(categories)
.setCategory(category)
.setSuggestionConditionMode(suggestionConditionMode)
.build();
}
@@ -144,14 +144,14 @@ public class DashboardAdapter extends RecyclerView.Adapter<DashboardAdapter.Dash
return mDashboardData.getSuggestions();
}
public void setCategoriesAndSuggestions(List<DashboardCategory> categories,
public void setCategoriesAndSuggestions(DashboardCategory category,
List<Tile> suggestions) {
tintIcons(categories, suggestions);
tintIcons(category, suggestions);
final DashboardData prevData = mDashboardData;
mDashboardData = new DashboardData.Builder(prevData)
.setSuggestions(suggestions)
.setCategories(categories)
.setCategory(category)
.build();
notifyDashboardDataChanged(prevData);
List<Tile> shownSuggestions = null;
@@ -173,13 +173,12 @@ public class DashboardAdapter extends RecyclerView.Adapter<DashboardAdapter.Dash
}
}
public void setCategory(List<DashboardCategory> category) {
public void setCategory(DashboardCategory category) {
tintIcons(category, null);
final DashboardData prevData = mDashboardData;
Log.d(TAG, "adapter setCategory called");
mDashboardData = new DashboardData.Builder(prevData)
.setCategories(category)
.setCategory(category)
.build();
notifyDashboardDataChanged(prevData);
}
@@ -480,11 +479,7 @@ public class DashboardAdapter extends RecyclerView.Adapter<DashboardAdapter.Dash
}
}
private void onBindCategory(DashboardItemHolder holder, DashboardCategory category) {
holder.title.setText(category.title);
}
private void tintIcons(List<DashboardCategory> categories, List<Tile> suggestions) {
private void tintIcons(DashboardCategory category, List<Tile> suggestions) {
if (!mDashboardFeatureProvider.shouldTintIcon()) {
return;
}
@@ -493,7 +488,7 @@ public class DashboardAdapter extends RecyclerView.Adapter<DashboardAdapter.Dash
android.R.attr.colorControlNormal});
final int tintColor = a.getColor(0, mContext.getColor(R.color.fallback_tintColor));
a.recycle();
for (DashboardCategory category : categories) {
if (category != null) {
for (Tile tile : category.tiles) {
if (tile.isIconTintable) {
// If this drawable is tintable, tint it to match the color.
@@ -512,12 +507,12 @@ public class DashboardAdapter extends RecyclerView.Adapter<DashboardAdapter.Dash
void onSaveInstanceState(Bundle outState) {
final List<Tile> suggestions = mDashboardData.getSuggestions();
final List<DashboardCategory> categories = mDashboardData.getCategories();
final DashboardCategory category = mDashboardData.getCategory();
if (suggestions != null) {
outState.putParcelableArrayList(STATE_SUGGESTION_LIST, new ArrayList<>(suggestions));
}
if (categories != null) {
outState.putParcelableArrayList(STATE_CATEGORY_LIST, new ArrayList<>(categories));
if (category != null) {
outState.putParcelable(STATE_CATEGORY_LIST, category);
}
outState.putStringArrayList(STATE_SUGGESTIONS_SHOWN_LOGGED, mSuggestionsShownLogged);
outState.putInt(STATE_SUGGESTION_CONDITION_MODE,