Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 9ca41dd8 authored by Soroosh Mariooryad's avatar Soroosh Mariooryad
Browse files

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
parent fc19e30d
Loading
Loading
Loading
Loading
+15 −12
Original line number Diff line number Diff line
@@ -70,6 +70,7 @@ public class DashboardSummary extends InstrumentedFragment
    private SuggestionsChecks mSuggestionsChecks;
    private DashboardFeatureProvider mDashboardFeatureProvider;
    private SuggestionFeatureProvider mSuggestionFeatureProvider;
    private boolean isOnCategoriesChangedCalled;

    @Override
    public int getMetricsCategory() {
@@ -204,25 +205,27 @@ public class DashboardSummary extends InstrumentedFragment
            Log.d(TAG, "onViewCreated took "
                    + (System.currentTimeMillis() - startTime) + " ms");
        }
        rebuildUI(true /* rebuildSuggestions */);
        rebuildUI();
    }

    private void rebuildUI(boolean rebuildSuggestions) {
        if (rebuildSuggestions) {
            // recheck to see if any suggestions have been changed.
    @VisibleForTesting
    void rebuildUI() {
        new SuggestionLoader().execute();
        // Set categories on their own if loading suggestions takes too long.
        mHandler.postDelayed(() -> {
            updateCategoryAndSuggestion(null /* tiles */);
        }, MAX_WAIT_MILLIS);
        } else {
            updateCategoryAndSuggestion(null /* tiles */);
        }
    }

    @Override
    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
+13 −3
Original line number Diff line number Diff line
@@ -34,6 +34,7 @@ import org.robolectric.annotation.Config;
import org.robolectric.util.ReflectionHelpers;

import static org.mockito.Matchers.anyList;
import static org.mockito.Mockito.doNothing;
import static org.mockito.Mockito.doReturn;
import static org.mockito.Mockito.mock;
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.when;


@RunWith(SettingsRobolectricTestRunner.class)
@Config(manifest = TestConfig.MANIFEST_PATH, sdk = TestConfig.SDK_VERSION)
public class DashboardSummaryTest {
@@ -93,11 +95,19 @@ public class DashboardSummaryTest {
    }

    @Test
    public void onCategoryChanged_updateCategoryOnly() {
    public void onCategoryChanged_noRebuildOnFirstCall() {
        doReturn(mock(Activity.class)).when(mSummary).getActivity();
        when(mDashboardFeatureProvider.isEnabled()).thenReturn(true);
        doNothing().when(mSummary).rebuildUI();
        mSummary.onCategoriesChanged();
        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(mAdapter).setCategory(anyList());
        verify(mSummary).rebuildUI();
    }
}
 No newline at end of file