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:
@@ -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,
|
||||
|
@@ -66,14 +66,14 @@ public class DashboardData {
|
||||
static final int STABLE_ID_CONDITION_CONTAINER = 4;
|
||||
|
||||
private final List<Item> mItems;
|
||||
private final List<DashboardCategory> mCategories;
|
||||
private final DashboardCategory mCategory;
|
||||
private final List<Condition> mConditions;
|
||||
private final List<Tile> mSuggestions;
|
||||
@HeaderMode
|
||||
private final int mSuggestionConditionMode;
|
||||
|
||||
private DashboardData(Builder builder) {
|
||||
mCategories = builder.mCategories;
|
||||
mCategory = builder.mCategory;
|
||||
mConditions = builder.mConditions;
|
||||
mSuggestions = builder.mSuggestions;
|
||||
mSuggestionConditionMode = builder.mSuggestionConditionMode;
|
||||
@@ -112,8 +112,8 @@ public class DashboardData {
|
||||
return null;
|
||||
}
|
||||
|
||||
public List<DashboardCategory> getCategories() {
|
||||
return mCategories;
|
||||
public DashboardCategory getCategory() {
|
||||
return mCategory;
|
||||
}
|
||||
|
||||
public List<Condition> getConditions() {
|
||||
@@ -262,10 +262,9 @@ public class DashboardData {
|
||||
&& !hasConditions
|
||||
&& hiddenSuggestion == 0);
|
||||
|
||||
for (int i = 0; mCategories != null && i < mCategories.size(); i++) {
|
||||
DashboardCategory category = mCategories.get(i);
|
||||
for (int j = 0; j < category.tiles.size(); j++) {
|
||||
final Tile tile = category.tiles.get(j);
|
||||
if(mCategory != null) {
|
||||
for (int j = 0; j < mCategory.tiles.size(); j++) {
|
||||
final Tile tile = mCategory.tiles.get(j);
|
||||
addToItemList(tile, R.layout.dashboard_tile, Objects.hash(tile.title),
|
||||
true /* add */);
|
||||
}
|
||||
@@ -311,7 +310,7 @@ public class DashboardData {
|
||||
@HeaderMode
|
||||
private int mSuggestionConditionMode = HEADER_MODE_DEFAULT;
|
||||
|
||||
private List<DashboardCategory> mCategories;
|
||||
private DashboardCategory mCategory;
|
||||
private List<Condition> mConditions;
|
||||
private List<Tile> mSuggestions;
|
||||
|
||||
@@ -319,14 +318,14 @@ public class DashboardData {
|
||||
}
|
||||
|
||||
public Builder(DashboardData dashboardData) {
|
||||
mCategories = dashboardData.mCategories;
|
||||
mCategory = dashboardData.mCategory;
|
||||
mConditions = dashboardData.mConditions;
|
||||
mSuggestions = dashboardData.mSuggestions;
|
||||
mSuggestionConditionMode = dashboardData.mSuggestionConditionMode;
|
||||
}
|
||||
|
||||
public Builder setCategories(List<DashboardCategory> categories) {
|
||||
this.mCategories = categories;
|
||||
public Builder setCategory(DashboardCategory category) {
|
||||
this.mCategory = category;
|
||||
return this;
|
||||
}
|
||||
|
||||
|
@@ -292,15 +292,12 @@ public class DashboardSummary extends InstrumentedFragment
|
||||
return;
|
||||
}
|
||||
|
||||
// Temporary hack to wrap homepage category into a list. Soon we will create adapter
|
||||
// API that takes a single category.
|
||||
List<DashboardCategory> categories = new ArrayList<>();
|
||||
categories.add(mDashboardFeatureProvider.getTilesForCategory(
|
||||
CategoryKey.CATEGORY_HOMEPAGE));
|
||||
final DashboardCategory category = mDashboardFeatureProvider.getTilesForCategory(
|
||||
CategoryKey.CATEGORY_HOMEPAGE);
|
||||
if (suggestions != null) {
|
||||
mAdapter.setCategoriesAndSuggestions(categories, suggestions);
|
||||
mAdapter.setCategoriesAndSuggestions(category, suggestions);
|
||||
} else {
|
||||
mAdapter.setCategory(categories);
|
||||
mAdapter.setCategory(category);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@@ -15,32 +15,16 @@
|
||||
*/
|
||||
package com.android.settings.dashboard;
|
||||
|
||||
import static com.google.common.truth.Truth.assertThat;
|
||||
|
||||
import static org.mockito.ArgumentMatchers.anyInt;
|
||||
import static org.mockito.ArgumentMatchers.eq;
|
||||
import static org.mockito.Mockito.any;
|
||||
import static org.mockito.Mockito.doReturn;
|
||||
import static org.mockito.Mockito.mock;
|
||||
import static org.mockito.Mockito.never;
|
||||
import static org.mockito.Mockito.reset;
|
||||
import static org.mockito.Mockito.spy;
|
||||
import static org.mockito.Mockito.times;
|
||||
import static org.mockito.Mockito.verify;
|
||||
import static org.mockito.Mockito.when;
|
||||
|
||||
import android.content.ComponentName;
|
||||
import android.content.Context;
|
||||
import android.content.Intent;
|
||||
import android.content.res.Resources;
|
||||
import android.content.res.TypedArray;
|
||||
import android.graphics.drawable.ColorDrawable;
|
||||
import android.graphics.drawable.Icon;
|
||||
import android.support.v7.widget.RecyclerView;
|
||||
import android.util.DisplayMetrics;
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.View;
|
||||
import android.widget.LinearLayout;
|
||||
import android.widget.RelativeLayout;
|
||||
|
||||
import com.android.internal.logging.nano.MetricsProto.MetricsEvent;
|
||||
@@ -68,9 +52,21 @@ import org.robolectric.RuntimeEnvironment;
|
||||
import org.robolectric.annotation.Config;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
|
||||
import static com.google.common.truth.Truth.assertThat;
|
||||
import static org.mockito.ArgumentMatchers.anyInt;
|
||||
import static org.mockito.ArgumentMatchers.eq;
|
||||
import static org.mockito.Mockito.any;
|
||||
import static org.mockito.Mockito.doReturn;
|
||||
import static org.mockito.Mockito.mock;
|
||||
import static org.mockito.Mockito.never;
|
||||
import static org.mockito.Mockito.reset;
|
||||
import static org.mockito.Mockito.spy;
|
||||
import static org.mockito.Mockito.times;
|
||||
import static org.mockito.Mockito.verify;
|
||||
import static org.mockito.Mockito.when;
|
||||
|
||||
@RunWith(SettingsRobolectricTestRunner.class)
|
||||
@Config(manifest = TestConfig.MANIFEST_PATH,
|
||||
sdk = TestConfig.SDK_VERSION,
|
||||
@@ -321,11 +317,11 @@ public class DashboardAdapterTest {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testSuggestioDismissed_notOnlySuggestion_doNothing() {
|
||||
public void testSuggestionDismissed_notOnlySuggestion_doNothing() {
|
||||
final DashboardAdapter adapter =
|
||||
spy(new DashboardAdapter(mContext, null, null, null, null));
|
||||
adapter.setCategoriesAndSuggestions(
|
||||
new ArrayList<>(), makeSuggestions("pkg1", "pkg2", "pkg3"));
|
||||
null /* category */, makeSuggestions("pkg1", "pkg2", "pkg3"));
|
||||
final DashboardData dashboardData = adapter.mDashboardData;
|
||||
reset(adapter); // clear interactions tracking
|
||||
|
||||
@@ -336,10 +332,10 @@ public class DashboardAdapterTest {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testSuggestioDismissed_onlySuggestion_updateDashboardData() {
|
||||
public void testSuggestionDismissed_onlySuggestion_updateDashboardData() {
|
||||
DashboardAdapter adapter =
|
||||
spy(new DashboardAdapter(mContext, null, null, null, null));
|
||||
adapter.setCategoriesAndSuggestions(new ArrayList<>(), makeSuggestions("pkg1"));
|
||||
adapter.setCategoriesAndSuggestions(null /* category */, makeSuggestions("pkg1"));
|
||||
final DashboardData dashboardData = adapter.mDashboardData;
|
||||
reset(adapter); // clear interactions tracking
|
||||
|
||||
@@ -360,7 +356,7 @@ public class DashboardAdapterTest {
|
||||
packages.get(0).isIconTintable = true;
|
||||
packages.get(0).icon = mockIcon;
|
||||
|
||||
mDashboardAdapter.setCategoriesAndSuggestions(Collections.emptyList(), packages);
|
||||
mDashboardAdapter.setCategoriesAndSuggestions(null /* category */, packages);
|
||||
|
||||
verify(mockIcon).setTint(eq(0x89000000));
|
||||
}
|
||||
@@ -371,7 +367,6 @@ public class DashboardAdapterTest {
|
||||
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);
|
||||
@@ -380,9 +375,8 @@ public class DashboardAdapterTest {
|
||||
tile.icon = mockIcon;
|
||||
tiles.add(tile);
|
||||
category.tiles = tiles;
|
||||
categories.add(category);
|
||||
|
||||
mDashboardAdapter.setCategory(categories);
|
||||
mDashboardAdapter.setCategory(category);
|
||||
|
||||
verify(mockIcon).setTint(eq(0x89000000));
|
||||
}
|
||||
@@ -391,13 +385,12 @@ public class DashboardAdapterTest {
|
||||
public void testBindConditionAndSuggestion_shouldSetSuggestionAdapterAndNoCrash() {
|
||||
mDashboardAdapter = new DashboardAdapter(mContext, null, null, null, null);
|
||||
final List<Tile> suggestions = makeSuggestions("pkg1");
|
||||
final List<DashboardCategory> categories = new ArrayList<>();
|
||||
final DashboardCategory category = mock(DashboardCategory.class);
|
||||
final List<Tile> tiles = new ArrayList<>();
|
||||
tiles.add(mock(Tile.class));
|
||||
category.tiles = tiles;
|
||||
categories.add(category);
|
||||
mDashboardAdapter.setCategoriesAndSuggestions(categories, suggestions);
|
||||
|
||||
mDashboardAdapter.setCategoriesAndSuggestions(category, suggestions);
|
||||
|
||||
final RecyclerView data = mock(RecyclerView.class);
|
||||
when(data.getResources()).thenReturn(mResources);
|
||||
@@ -427,7 +420,7 @@ public class DashboardAdapterTest {
|
||||
}
|
||||
|
||||
private void setupSuggestions(List<Tile> suggestions) {
|
||||
mDashboardAdapter.setCategoriesAndSuggestions(new ArrayList<>(), suggestions);
|
||||
mDashboardAdapter.setCategoriesAndSuggestions(null /* category */, suggestions);
|
||||
final Context context = RuntimeEnvironment.application;
|
||||
mSuggestionHolder = new DashboardAdapter.SuggestionAndConditionHeaderHolder(
|
||||
LayoutInflater.from(context).inflate(
|
||||
|
@@ -88,32 +88,30 @@ public class DashboardDataTest {
|
||||
twoItemsConditions.add(mTestCondition);
|
||||
twoItemsConditions.add(mSecondCondition);
|
||||
|
||||
// Build categories
|
||||
final List<DashboardCategory> categories = new ArrayList<>();
|
||||
// Build category
|
||||
mTestCategoryTile.title = TEST_CATEGORY_TILE_TITLE;
|
||||
mDashboardCategory.title = "test";
|
||||
mDashboardCategory.tiles = new ArrayList<>();
|
||||
mDashboardCategory.tiles.add(mTestCategoryTile);
|
||||
categories.add(mDashboardCategory);
|
||||
|
||||
// Build DashboardData
|
||||
mDashboardDataWithOneConditions = new DashboardData.Builder()
|
||||
.setConditions(oneItemConditions)
|
||||
.setCategories(categories)
|
||||
.setCategory(mDashboardCategory)
|
||||
.setSuggestions(suggestions)
|
||||
.setSuggestionConditionMode(DashboardData.HEADER_MODE_FULLY_EXPANDED)
|
||||
.build();
|
||||
|
||||
mDashboardDataWithTwoConditions = new DashboardData.Builder()
|
||||
.setConditions(twoItemsConditions)
|
||||
.setCategories(categories)
|
||||
.setCategory(mDashboardCategory)
|
||||
.setSuggestions(suggestions)
|
||||
.setSuggestionConditionMode(DashboardData.HEADER_MODE_FULLY_EXPANDED)
|
||||
.build();
|
||||
|
||||
mDashboardDataWithNoItems = new DashboardData.Builder()
|
||||
.setConditions(null)
|
||||
.setCategories(null)
|
||||
.setCategory(null)
|
||||
.setSuggestions(null)
|
||||
.build();
|
||||
}
|
||||
@@ -136,7 +134,7 @@ public class DashboardDataTest {
|
||||
public void testBuildItemsData_containsAllData() {
|
||||
final DashboardData.SuggestionConditionHeaderData data =
|
||||
new DashboardData.SuggestionConditionHeaderData(
|
||||
mDashboardDataWithOneConditions.getConditions(), 0);
|
||||
mDashboardDataWithOneConditions.getConditions(), 0);
|
||||
final Object[] expectedObjects = {data,
|
||||
mDashboardDataWithOneConditions.getSuggestions(),
|
||||
mDashboardDataWithOneConditions.getConditions(),
|
||||
@@ -151,9 +149,9 @@ public class DashboardDataTest {
|
||||
assertThat(item).isEqualTo(expectedObjects[i]);
|
||||
} else if (item instanceof DashboardData.SuggestionConditionHeaderData) {
|
||||
DashboardData.SuggestionConditionHeaderData i1 =
|
||||
(DashboardData.SuggestionConditionHeaderData)item;
|
||||
(DashboardData.SuggestionConditionHeaderData) item;
|
||||
DashboardData.SuggestionConditionHeaderData i2 =
|
||||
(DashboardData.SuggestionConditionHeaderData)expectedObjects[i];
|
||||
(DashboardData.SuggestionConditionHeaderData) expectedObjects[i];
|
||||
assertThat(i1.title).isEqualTo(i2.title);
|
||||
assertThat(i1.conditionCount).isEqualTo(i2.conditionCount);
|
||||
assertThat(i1.hiddenSuggestionCount).isEqualTo(i2.hiddenSuggestionCount);
|
||||
@@ -218,7 +216,7 @@ public class DashboardDataTest {
|
||||
// Item in position 3 is the condition container containing the list of conditions, which
|
||||
// gets 1 more item
|
||||
testResultData.add(new ListUpdateResult.ResultData(
|
||||
ListUpdateResult.ResultData.TYPE_OPERATION_CHANGE, 2, 1));
|
||||
ListUpdateResult.ResultData.TYPE_OPERATION_CHANGE, 2, 1));
|
||||
|
||||
testDiffUtil(mDashboardDataWithOneConditions,
|
||||
mDashboardDataWithTwoConditions, testResultData);
|
||||
@@ -252,10 +250,6 @@ public class DashboardDataTest {
|
||||
* <p>
|
||||
* Because baseResultData and {@paramref testResultData} don't have sequence. When do the
|
||||
* comparison, we will sort them first and then compare the inside data from them one by one.
|
||||
*
|
||||
* @param baseDashboardData
|
||||
* @param diffDashboardData
|
||||
* @param testResultData
|
||||
*/
|
||||
private void testDiffUtil(DashboardData baseDashboardData, DashboardData diffDashboardData,
|
||||
List<ListUpdateResult.ResultData> testResultData) {
|
||||
|
Reference in New Issue
Block a user