Moving load of suggestions from onViewCreated to onCategoriesChanged.
- This is required when a suggestion is completed and it needs to be removed from the list immediately. Test: RunSettingsRoboTests Fixes: b/35657186 Change-Id: I731bd1d4ef4a23a74cb4022513d0824ff5f74b2a
This commit is contained in:
@@ -70,6 +70,7 @@ public class DashboardSummary extends InstrumentedFragment
|
|||||||
private SuggestionsChecks mSuggestionsChecks;
|
private SuggestionsChecks mSuggestionsChecks;
|
||||||
private DashboardFeatureProvider mDashboardFeatureProvider;
|
private DashboardFeatureProvider mDashboardFeatureProvider;
|
||||||
private SuggestionFeatureProvider mSuggestionFeatureProvider;
|
private SuggestionFeatureProvider mSuggestionFeatureProvider;
|
||||||
|
private boolean isOnCategoriesChangedCalled;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public int getMetricsCategory() {
|
public int getMetricsCategory() {
|
||||||
@@ -204,25 +205,27 @@ public class DashboardSummary extends InstrumentedFragment
|
|||||||
Log.d(TAG, "onViewCreated took "
|
Log.d(TAG, "onViewCreated took "
|
||||||
+ (System.currentTimeMillis() - startTime) + " ms");
|
+ (System.currentTimeMillis() - startTime) + " ms");
|
||||||
}
|
}
|
||||||
rebuildUI(true /* rebuildSuggestions */);
|
rebuildUI();
|
||||||
}
|
}
|
||||||
|
|
||||||
private void rebuildUI(boolean rebuildSuggestions) {
|
@VisibleForTesting
|
||||||
if (rebuildSuggestions) {
|
void rebuildUI() {
|
||||||
// recheck to see if any suggestions have been changed.
|
|
||||||
new SuggestionLoader().execute();
|
new SuggestionLoader().execute();
|
||||||
// Set categories on their own if loading suggestions takes too long.
|
// Set categories on their own if loading suggestions takes too long.
|
||||||
mHandler.postDelayed(() -> {
|
mHandler.postDelayed(() -> {
|
||||||
updateCategoryAndSuggestion(null /* tiles */);
|
updateCategoryAndSuggestion(null /* tiles */);
|
||||||
}, MAX_WAIT_MILLIS);
|
}, MAX_WAIT_MILLIS);
|
||||||
} else {
|
|
||||||
updateCategoryAndSuggestion(null /* tiles */);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onCategoriesChanged() {
|
public void onCategoriesChanged() {
|
||||||
rebuildUI(false /* rebuildSuggestions */);
|
// Bypass rebuildUI() on the first call of onCategoriesChanged, since rebuildUI() happens
|
||||||
|
// in onViewCreated as well when app starts. But, on the subsequent calls we need to
|
||||||
|
// rebuildUI() because there might be some changes to suggestions and categories.
|
||||||
|
if (isOnCategoriesChangedCalled) {
|
||||||
|
rebuildUI();
|
||||||
|
}
|
||||||
|
isOnCategoriesChangedCalled = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@@ -34,6 +34,7 @@ import org.robolectric.annotation.Config;
|
|||||||
import org.robolectric.util.ReflectionHelpers;
|
import org.robolectric.util.ReflectionHelpers;
|
||||||
|
|
||||||
import static org.mockito.Matchers.anyList;
|
import static org.mockito.Matchers.anyList;
|
||||||
|
import static org.mockito.Mockito.doNothing;
|
||||||
import static org.mockito.Mockito.doReturn;
|
import static org.mockito.Mockito.doReturn;
|
||||||
import static org.mockito.Mockito.mock;
|
import static org.mockito.Mockito.mock;
|
||||||
import static org.mockito.Mockito.never;
|
import static org.mockito.Mockito.never;
|
||||||
@@ -41,6 +42,7 @@ import static org.mockito.Mockito.spy;
|
|||||||
import static org.mockito.Mockito.verify;
|
import static org.mockito.Mockito.verify;
|
||||||
import static org.mockito.Mockito.when;
|
import static org.mockito.Mockito.when;
|
||||||
|
|
||||||
|
|
||||||
@RunWith(SettingsRobolectricTestRunner.class)
|
@RunWith(SettingsRobolectricTestRunner.class)
|
||||||
@Config(manifest = TestConfig.MANIFEST_PATH, sdk = TestConfig.SDK_VERSION)
|
@Config(manifest = TestConfig.MANIFEST_PATH, sdk = TestConfig.SDK_VERSION)
|
||||||
public class DashboardSummaryTest {
|
public class DashboardSummaryTest {
|
||||||
@@ -93,11 +95,19 @@ public class DashboardSummaryTest {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void onCategoryChanged_updateCategoryOnly() {
|
public void onCategoryChanged_noRebuildOnFirstCall() {
|
||||||
doReturn(mock(Activity.class)).when(mSummary).getActivity();
|
doReturn(mock(Activity.class)).when(mSummary).getActivity();
|
||||||
when(mDashboardFeatureProvider.isEnabled()).thenReturn(true);
|
doNothing().when(mSummary).rebuildUI();
|
||||||
|
|
||||||
mSummary.onCategoriesChanged();
|
mSummary.onCategoriesChanged();
|
||||||
verify(mAdapter).setCategory(anyList());
|
verify(mSummary, never()).rebuildUI();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void onCategoryChanged_rebuildOnSecondCall() {
|
||||||
|
doReturn(mock(Activity.class)).when(mSummary).getActivity();
|
||||||
|
doNothing().when(mSummary).rebuildUI();
|
||||||
|
mSummary.onCategoriesChanged();
|
||||||
|
mSummary.onCategoriesChanged();
|
||||||
|
verify(mSummary).rebuildUI();
|
||||||
}
|
}
|
||||||
}
|
}
|
Reference in New Issue
Block a user