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

Commit 7c8ae62c authored by Olivia Tardjono's avatar Olivia Tardjono
Browse files

[DocsUI] Update grid/list view state to be a global setting.

Previously, grid/list states were saved per root/sidetab vs. as a
global setting. This CL allows the grid/list view states to persist
after changing roots/sidetabs.

Bug: 370629029
Test: m DocumentsUI && manual inspection
Test: atest FilesActivityUiTest#testRootChange_GlobalGridListViewState
Test: atest FilesActivityUiTest#testRootChange_UpdatesSortHeader
      && flag useMaterial3 off
Flag: com.android.documentsui.flags.use_material3
Change-Id: I756b37f6b46eabedfc2aa68661312691ec0ab5fb
parent dce2b226
Loading
Loading
Loading
Loading
+12 −1
Original line number Diff line number Diff line
@@ -17,6 +17,7 @@
package com.android.documentsui.prefs;

import static com.android.documentsui.base.State.MODE_UNKNOWN;
import static com.android.documentsui.util.FlagUtils.isUseMaterial3FlagEnabled;

import android.content.Context;
import android.content.SharedPreferences;
@@ -36,10 +37,14 @@ import java.lang.annotation.RetentionPolicy;
 */
public class LocalPreferences {
    private static final String ROOT_VIEW_MODE_PREFIX = "rootViewMode-";
    private static final String VIEW_MODE_STATE = "viewModeState";
    private static final String SHOW_HIDDEN_FILES = "showHiddenFiles";

    public static @ViewMode int getViewMode(Context context, RootInfo root,
            @ViewMode int fallback) {
        if (isUseMaterial3FlagEnabled()) {
            return getPrefs(context).getInt(VIEW_MODE_STATE, fallback);
        }
        return getPrefs(context).getInt(createKey(ROOT_VIEW_MODE_PREFIX, root), fallback);
    }

@@ -50,7 +55,13 @@ public class LocalPreferences {

    public static void setViewMode(Context context, RootInfo root, @ViewMode int viewMode) {
        assert(viewMode != MODE_UNKNOWN);
        getPrefs(context).edit().putInt(createKey(ROOT_VIEW_MODE_PREFIX, root), viewMode).apply();
        if (isUseMaterial3FlagEnabled()) {
            getPrefs(context).edit().putInt(VIEW_MODE_STATE, viewMode).apply();
        } else {
            getPrefs(context).edit()
                    .putInt(createKey(ROOT_VIEW_MODE_PREFIX, root), viewMode)
                    .apply();
        }
    }

    /** Sets if hidden files should be shown. */
+18 −0
Original line number Diff line number Diff line
@@ -185,6 +185,24 @@ public class UiBot extends Bots.BaseBot {
                .check(matches(withText(is(expected))));
    }

    /**
     * Checks that the current view state is in list mode.
     */
    public void assertInListMode() {
        // In list mode, there should be the grid mode button that is visible.
        final UiObject2 gridModeBtn = menuGridMode();
        assertNotNull(gridModeBtn);
    }

    /**
     * Checks that the current view state is in grid mode.
     */
    public void assertInGridMode() {
        // In grid mode, there should be the list mode button that is visible.
        final UiObject2 listModeBtn = menuListMode();
        assertNotNull(listModeBtn);
    }

    public boolean inFixedLayout() {
        TypedValue val = new TypedValue();
        // We alias files_activity to either fixed or drawer layouts based
+38 −0
Original line number Diff line number Diff line
@@ -239,6 +239,44 @@ public class FilesActivityUiTest extends ActivityTestJunit4<FilesActivity> {
        }
    }

    @Test
    @RequiresFlagsDisabled(FLAG_USE_MATERIAL3)
    public void testRootChange_NonM3PerRootViewModeState() throws Exception {
        // Assign different view modes across "Images" and "Videos" roots.
        // Images root --> grid mode
        // Videos root --> list mode
        bots.roots.openRoot("Images");
        bots.main.switchToGridMode();
        bots.main.assertInGridMode();
        bots.roots.openRoot("Videos");
        bots.main.switchToListMode();
        bots.main.assertInListMode();

        // Assert that the different roots maintain their respective view modes.
        bots.roots.openRoot("Images");
        bots.main.assertInGridMode();
        bots.roots.openRoot("Videos");
        bots.main.assertInListMode();
    }

    @Test
    @RequiresFlagsEnabled(FLAG_USE_MATERIAL3)
    public void testRootChange_M3GlobalViewModeState() throws Exception {
        bots.roots.openRoot("Recent");
        bots.main.switchToGridMode();
        bots.main.assertInGridMode();

        // Switch to a different root and assert still in grid mode.
        bots.roots.openRoot(ROOT_0_ID);
        bots.main.assertInGridMode();

        // Switch back to list mode and assert still in list mode on a different root.
        bots.main.switchToListMode();
        bots.main.assertInListMode();
        bots.roots.openRoot("Recent");
        bots.main.assertInListMode();
    }

    @Test
    @RequiresFlagsEnabled(FLAG_USE_MATERIAL3)
    public void testClearSelectionInRecentsResetsActions() throws Exception {