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

Commit 6c1febbb authored by Kelvin Kwan's avatar Kelvin Kwan Committed by Android (Google) Code Review
Browse files

Merge "Enable navigation between profile tabs, roots"

parents 48886d8a 9feaaf55
Loading
Loading
Loading
Loading
+36 −3
Original line number Diff line number Diff line
@@ -711,11 +711,43 @@ public abstract class AbstractActionHandler<T extends FragmentActivity & CommonA
    }

    @Override
    public final void loadRoot(Uri uri) {
        new LoadRootTask<>(mActivity, mProviders, uri, this::onRootLoaded)
    public final void loadRoot(Uri uri, UserId userId) {
        new LoadRootTask<>(mActivity, mProviders, uri, userId, this::onRootLoaded)
                .executeOnExecutor(mExecutors.lookup(uri.getAuthority()));
    }

    @Override
    public final void loadCrossProfileRoot(RootInfo info, UserId selectedUser) {
        if (info.isRecents()) {
            openRoot(mProviders.getRecentsRoot(selectedUser));
            return;
        }
        new LoadRootTask<>(mActivity, mProviders, info.getUri(), selectedUser,
                new LoadCrossProfileRootCallback(info, selectedUser))
                .executeOnExecutor(mExecutors.lookup(info.getUri().getAuthority()));
    }

    private class LoadCrossProfileRootCallback implements LoadRootTask.LoadRootCallback {
        private final RootInfo mOriginalRoot;
        private final UserId mSelectedUserId;

        LoadCrossProfileRootCallback(RootInfo rootInfo, UserId selectedUser) {
            mOriginalRoot = rootInfo;
            mSelectedUserId = selectedUser;
        }

        @Override
        public void onRootLoaded(@Nullable RootInfo root) {
            if (root == null) {
                // There is no such root in the other profile. Maybe the provider is missing on
                // the other profile. Create a dummy root and open it to show error message.
                root = RootInfo.copyRootInfo(mOriginalRoot);
                root.userId = mSelectedUserId;
            }
            openRoot(root);
        }
    }

    @Override
    public final void loadFirstRoot(Uri uri) {
        new LoadFirstRootTask<>(mActivity, mProviders, uri, this::onRootLoaded)
@@ -799,7 +831,7 @@ public abstract class AbstractActionHandler<T extends FragmentActivity & CommonA
    }

    protected final void loadHomeDir() {
        loadRoot(Shared.getDefaultRootUri(mActivity));
        loadRoot(Shared.getDefaultRootUri(mActivity), UserId.DEFAULT_USER);
    }

    protected final void loadRecent() {
@@ -918,6 +950,7 @@ public abstract class AbstractActionHandler<T extends FragmentActivity & CommonA
        void onDocumentPicked(DocumentInfo doc);
        RootInfo getCurrentRoot();
        DocumentInfo getCurrentDirectory();
        UserId getSelectedUser();
        /**
         * Check whether current directory is root of recent.
         */
+3 −1
Original line number Diff line number Diff line
@@ -95,7 +95,9 @@ public interface ActionHandler {

    void openRoot(ResolveInfo app);

    void loadRoot(Uri uri);
    void loadRoot(Uri uri, UserId userId);

    void loadCrossProfileRoot(RootInfo info, UserId selectedUser);

    void loadFirstRoot(Uri uri);

+15 −1
Original line number Diff line number Diff line
@@ -267,6 +267,16 @@ public abstract class BaseActivity
            mNavigator.update();
        });

        mNavigator.setProfileTabsListener(userId -> {
            // Reload the roots with the selected user is changed.
            final RootsFragment roots = RootsFragment.get(getSupportFragmentManager());
            if (roots != null) {
                roots.onSelectedUserChanged();
            }

            mInjector.actions.loadCrossProfileRoot(getCurrentRoot(), userId);
        });

        mSortController = SortController.create(this, mState.derivedMode, mState.sortModel);

        mPreferencesMonitor = new PreferencesMonitor(
@@ -751,12 +761,16 @@ public abstract class BaseActivity
    }

    @Override
    public UserId getSelectedUser() {
        return mNavigator.getSelectedUser();
    }

    public RootInfo getCurrentRoot() {
        RootInfo root = mState.stack.getRoot();
        if (root != null) {
            return root;
        } else {
            return mProviders.getRecentsRoot(UserId.DEFAULT_USER);
            return mProviders.getRecentsRoot(getSelectedUser());
        }
    }

+8 −5
Original line number Diff line number Diff line
@@ -30,7 +30,6 @@ import androidx.legacy.app.ActionBarDrawerToggle;

import com.android.documentsui.base.Display;
import com.android.documentsui.base.Providers;
import com.android.documentsui.base.UserId;

/**
 * A facade over the various pieces comprising "roots fragment in a Drawer".
@@ -49,7 +48,7 @@ public abstract class DrawerController implements DrawerListener {
    /**
     * Returns a controller suitable for {@code Layout}.
     */
    public static DrawerController create(Activity activity, ActivityConfig activityConfig) {
    public static DrawerController create(BaseActivity activity, ActivityConfig activityConfig) {

        DrawerLayout layout = (DrawerLayout) activity.findViewById(R.id.drawer_layout);

@@ -68,7 +67,8 @@ public abstract class DrawerController implements DrawerListener {
                R.string.drawer_open,
                R.string.drawer_close);

        return new RuntimeDrawerController(layout, drawer, toggle, toolbar, activityConfig);
        return new RuntimeDrawerController(layout, drawer, toggle, toolbar, activityConfig,
                activity);
    }

    /**
@@ -101,19 +101,22 @@ public abstract class DrawerController implements DrawerListener {
        private DrawerLayout mLayout;
        private View mDrawer;
        private Toolbar mToolbar;
        private AbstractActionHandler.CommonAddons mCommonAddons;

        public RuntimeDrawerController(
                DrawerLayout layout,
                View drawer,
                ActionBarDrawerToggle toggle,
                Toolbar drawerToolbar,
                ActivityConfig activityConfig) {
                ActivityConfig activityConfig,
                AbstractActionHandler.CommonAddons commonAddons) {
            mToolbar = drawerToolbar;
            assert(layout != null);

            mLayout = layout;
            mDrawer = drawer;
            mToggle = toggle;
            mCommonAddons = commonAddons;

            mLayout.setDrawerListener(this);

@@ -205,7 +208,7 @@ public abstract class DrawerController implements DrawerListener {
            mToggle.onDrawerOpened(drawerView);
            // Update the information for Storage's root
            DocumentsApplication.getProvidersCache(drawerView.getContext()).updateAuthorityAsync(
                    UserId.DEFAULT_USER, Providers.AUTHORITY_STORAGE);
                    mCommonAddons.getSelectedUser(), Providers.AUTHORITY_STORAGE);
        }

        @Override
+12 −0
Original line number Diff line number Diff line
@@ -31,6 +31,7 @@ import androidx.appcompat.widget.Toolbar;

import com.android.documentsui.base.RootInfo;
import com.android.documentsui.base.State;
import com.android.documentsui.base.UserId;
import com.android.documentsui.dirlist.AnimationView;

import com.google.android.material.appbar.AppBarLayout;
@@ -110,6 +111,13 @@ public class NavigationViewManager {
        return mProfileTabs;
    }

    /**
     * Sets a listener to the profile tabs.
     */
    public void setProfileTabsListener(ProfileTabs.Listener listener) {
        mProfileTabs.setListener(listener);
    }

    private void onNavigationIconClicked() {
        if (mDrawer.isPresent()) {
            mDrawer.setOpen(true);
@@ -127,6 +135,10 @@ public class NavigationViewManager {
        }
    }

    public UserId getSelectedUser() {
        return mProfileTabs.getSelectedUser();
    }

    public void update() {
        updateScrollFlag();
        updateToolbar();
Loading