Do not load old category when IA is enabled.
Bug: 34026031
Test: RunSettingsRoboTests
Change-Id: Ie4ede018c8e3e906093cba4b9d4bf9d75c0bd972
diff --git a/src/com/android/settings/dashboard/DashboardSummary.java b/src/com/android/settings/dashboard/DashboardSummary.java
index ebc9b52..8602490 100644
--- a/src/com/android/settings/dashboard/DashboardSummary.java
+++ b/src/com/android/settings/dashboard/DashboardSummary.java
@@ -21,6 +21,7 @@
import android.os.AsyncTask;
import android.os.Bundle;
import android.os.Handler;
+import android.support.annotation.VisibleForTesting;
import android.support.v7.widget.LinearLayoutManager;
import android.util.Log;
import android.view.LayoutInflater;
@@ -246,11 +247,7 @@
new SuggestionLoader().execute();
// Set categories on their own if loading suggestions takes too long.
mHandler.postDelayed(() -> {
- final Activity activity = getActivity();
- if (activity != null) {
- mAdapter.setCategoriesAndSuggestions(
- ((SettingsActivity) activity).getDashboardCategories(), null);
- }
+ updateCategoryAndSuggestion(null /* tiles */);
}, MAX_WAIT_MILLIS);
}
@@ -293,23 +290,27 @@
protected void onPostExecute(List<Tile> tiles) {
// tell handler that suggestions were loaded quickly enough
mHandler.removeCallbacksAndMessages(null);
+ updateCategoryAndSuggestion(tiles);
+ }
+ }
- final Activity activity = getActivity();
- if (activity == null) {
- return;
- }
+ @VisibleForTesting
+ void updateCategoryAndSuggestion(List<Tile> tiles) {
+ final Activity activity = getActivity();
+ if (activity == null) {
+ return;
+ }
- if (mDashboardFeatureProvider.isEnabled()) {
- // 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));
- mAdapter.setCategoriesAndSuggestions(categories, tiles);
- } else {
- mAdapter.setCategoriesAndSuggestions(
- ((SettingsActivity) activity).getDashboardCategories(), tiles);
- }
+ if (mDashboardFeatureProvider.isEnabled()) {
+ // 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));
+ mAdapter.setCategoriesAndSuggestions(categories, tiles);
+ } else {
+ mAdapter.setCategoriesAndSuggestions(
+ ((SettingsActivity) activity).getDashboardCategories(), tiles);
}
}
}
diff --git a/tests/robotests/src/com/android/settings/dashboard/DashboardSummaryTest.java b/tests/robotests/src/com/android/settings/dashboard/DashboardSummaryTest.java
new file mode 100644
index 0000000..69836d8
--- /dev/null
+++ b/tests/robotests/src/com/android/settings/dashboard/DashboardSummaryTest.java
@@ -0,0 +1,66 @@
+/*
+ * Copyright (C) 2017 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package com.android.settings.dashboard;
+
+import android.app.Activity;
+
+import com.android.settings.SettingsRobolectricTestRunner;
+import com.android.settings.TestConfig;
+import com.android.settingslib.drawer.CategoryKey;
+
+import org.junit.Before;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.mockito.Mock;
+import org.mockito.MockitoAnnotations;
+import org.robolectric.annotation.Config;
+import org.robolectric.util.ReflectionHelpers;
+
+import static org.mockito.Mockito.doReturn;
+import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.spy;
+import static org.mockito.Mockito.verify;
+import static org.mockito.Mockito.when;
+
+@RunWith(SettingsRobolectricTestRunner.class)
+@Config(manifest = TestConfig.MANIFEST_PATH, sdk = TestConfig.SDK_VERSION)
+public class DashboardSummaryTest {
+
+ @Mock
+ private DashboardAdapter mAdapter;
+ @Mock
+ private DashboardFeatureProvider mDashboardFeatureProvider;
+
+ private DashboardSummary mSummary;
+
+ @Before
+ public void setUp() {
+ MockitoAnnotations.initMocks(this);
+ mSummary = spy(new DashboardSummary());
+ ReflectionHelpers.setField(mSummary, "mAdapter", mAdapter);
+ ReflectionHelpers.setField(mSummary, "mDashboardFeatureProvider",
+ mDashboardFeatureProvider);
+ }
+
+ @Test
+ public void updateCategoryAndSuggestion_shouldGetCategoryFromFeatureProvider() {
+ doReturn(mock(Activity.class)).when(mSummary).getActivity();
+ when(mDashboardFeatureProvider.isEnabled()).thenReturn(true);
+ mSummary.updateCategoryAndSuggestion(null);
+ verify(mDashboardFeatureProvider).getTilesForCategory(CategoryKey.CATEGORY_HOMEPAGE);
+ }
+}