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

Commit 0462a288 authored by Ben Reich's avatar Ben Reich
Browse files

Move the selection menu from the ActionBar to NavigationView

In the >600dp layout, the MaterialToolbar has been moved to be
adjacent to the sidebar. Previously the ActionBar was used to replace
the existing toolbar, unfortunately on the new layout this doesn't
work as it spans the full width.

To get around this (and maintain compatibility when the flag is on or
off) we instead inflate the activity menu OR the action mode menu
depending on whether there is a selection. This is a temporary measure
to not have to refactor the click handlers too much. In the final
product the ActionModeController will be removed and the click
handlers consolidated into a single place.

Bug: 383669583
Test: atest DocumentsUIGoogleTests
Flag: com.android.documentsui.flags.use_material3

Change-Id: Ida4675dafbc2096c986067ba4fbe5a695a8e243b
parent 315018fa
Loading
Loading
Loading
Loading
+24 −0
Original line number Diff line number Diff line
<!--
    Copyright (C) 2025 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.
-->
<vector xmlns:android="http://schemas.android.com/apk/res/android"
    android:width="24dp"
    android:height="24dp"
    android:viewportHeight="960"
    android:viewportWidth="960">
    <path
        android:fillColor="?attr/colorOnSurface"
        android:pathData="M256,760L200,704L424,480L200,256L256,200L480,424L704,200L760,256L536,480L760,704L704,760L480,536L256,760Z" />
</vector>
+31 −15
Original line number Diff line number Diff line
@@ -14,72 +14,88 @@
     limitations under the License.
-->

<menu xmlns:android="http://schemas.android.com/apk/res/android">
<menu
    xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto">
    <item
        android:id="@+id/action_menu_open_with"
        android:title="@string/menu_open_with"
        android:showAsAction="never" />
        android:showAsAction="never"
        app:showAsAction="never" />
    <item
        android:id="@+id/action_menu_share"
        android:icon="@drawable/ic_menu_share"
        android:title="@string/menu_share"
        android:showAsAction="always" />
        android:showAsAction="always"
        app:showAsAction="always" />
    <item
        android:id="@+id/action_menu_delete"
        android:icon="@drawable/ic_menu_delete"
        android:title="@string/menu_delete"
        android:showAsAction="always" />
        android:showAsAction="always"
        app:showAsAction="always" />
    <item
        android:id="@+id/action_menu_sort"
        android:icon="@drawable/ic_sort"
        android:title="@string/menu_sort"
        android:showAsAction="never" />
        android:showAsAction="never"
        app:showAsAction="never" />
    <item
        android:id="@+id/action_menu_select"
        android:title="@string/menu_select"
        android:showAsAction="always" />
        android:showAsAction="always"
        app:showAsAction="always" />
    <item
        android:id="@+id/action_menu_select_all"
        android:title="@string/menu_select_all"
        android:showAsAction="never" />
        android:showAsAction="never"
        app:showAsAction="never" />
    <item
        android:id="@+id/action_menu_deselect_all"
        android:title="@string/menu_deselect_all"
        android:showAsAction="never" />
        android:showAsAction="never"
        app:showAsAction="never" />
    <item
        android:id="@+id/action_menu_copy_to"
        android:title="@string/menu_copy"
        android:showAsAction="never"
        android:visible="false" />
        android:visible="false"
        app:showAsAction="never" />
    <item
        android:id="@+id/action_menu_extract_to"
        android:title="@string/menu_extract"
        android:icon="@drawable/ic_menu_extract"
        android:showAsAction="always"
        android:visible="false" />
        android:visible="false"
        app:showAsAction="always" />
    <item
        android:id="@+id/action_menu_move_to"
        android:title="@string/menu_move"
        android:showAsAction="never"
        android:visible="false" />
        android:visible="false"
        app:showAsAction="never" />
    <item
        android:id="@+id/action_menu_compress"
        android:title="@string/menu_compress"
        android:showAsAction="never"
        android:visible="false" />
        android:visible="false"
        app:showAsAction="never" />
    <item
        android:id="@+id/action_menu_rename"
        android:title="@string/menu_rename"
        android:showAsAction="never"
        android:visible="false" />
        android:visible="false"
        app:showAsAction="never" />
    <item
        android:id="@+id/action_menu_inspect"
        android:title="@string/menu_inspect"
        android:showAsAction="never"
        android:visible="false" />
        android:visible="false"
        app:showAsAction="never" />
    <item
        android:id="@+id/action_menu_view_in_owner"
        android:title="@string/menu_view_in_owner"
        android:showAsAction="never"
        android:visible="false" />
        android:visible="false"
        app:showAsAction="never" />
</menu>
+2 −0
Original line number Diff line number Diff line
@@ -39,6 +39,8 @@ import com.android.documentsui.ui.MessageBuilder;

/**
 * A controller that listens to selection changes and manages life cycles of action modes.
 * TODO(b/379776735): This class (and action mode in general) is no longer in use when the
 * use_material3 flag is enabled. Remove the class once the flag is rolled out.
 */
public class ActionModeController extends SelectionObserver<String>
        implements ActionMode.Callback, ActionModeAddons {
+55 −17
Original line number Diff line number Diff line
@@ -401,13 +401,27 @@ public abstract class BaseActivity
    private NavigationViewManager getNavigationViewManager(Breadcrumb breadcrumb,
            View profileTabsContainer) {
        if (mConfigStore.isPrivateSpaceInDocsUIEnabled()) {
            return new NavigationViewManager(this, mDrawer, mState, this, breadcrumb,
                    profileTabsContainer, DocumentsApplication.getUserManagerState(this),
                    mConfigStore);
            return new NavigationViewManager(
                    this,
                    mDrawer,
                    mState,
                    this,
                    breadcrumb,
                    profileTabsContainer,
                    DocumentsApplication.getUserManagerState(this),
                    mConfigStore,
                    mInjector);
        }
        return new NavigationViewManager(this, mDrawer, mState, this, breadcrumb,
                profileTabsContainer, DocumentsApplication.getUserIdManager(this),
                mConfigStore);
        return new NavigationViewManager(
                this,
                mDrawer,
                mState,
                this,
                breadcrumb,
                profileTabsContainer,
                DocumentsApplication.getUserIdManager(this),
                mConfigStore,
                mInjector);
    }

    public void onPreferenceChanged(String pref) {
@@ -421,14 +435,21 @@ public abstract class BaseActivity
    protected void onPostCreate(Bundle savedInstanceState) {
        super.onPostCreate(savedInstanceState);

        mRootsMonitor = new RootsMonitor<>(
        Runnable finishActionMode =
                (useMaterial3())
                        ? mNavigator::closeSelectionBar
                        : mInjector.actionModeController::finishActionMode;

        mRootsMonitor =
                new RootsMonitor<>(
                        this,
                        mInjector.actions,
                        mProviders,
                        mDocs,
                        mState,
                        mSearchManager,
                mInjector.actionModeController::finishActionMode);
                        finishActionMode);

        mRootsMonitor.start();
    }

@@ -440,6 +461,13 @@ public abstract class BaseActivity

    @Override
    public boolean onCreateOptionsMenu(Menu menu) {
        if (useMaterial3()) {
            // In Material3 the menu is now inflated in the `NavigationViewMenu`. This is currently
            // to allow for us to inflate between the action_menu and the activity menu. Once the
            // Material 3 flag is removed, the menus will be merged and we can rely on this single
            // inflation point.
            return super.onCreateOptionsMenu(menu);
        }
        boolean showMenu = super.onCreateOptionsMenu(menu);

        getMenuInflater().inflate(R.menu.activity, menu);
@@ -463,11 +491,13 @@ public abstract class BaseActivity
    @CallSuper
    public boolean onPrepareOptionsMenu(Menu menu) {
        super.onPrepareOptionsMenu(menu);
        mSearchManager.showMenu(mState.stack);
        // Remove the subMenu when material3 is launched b/379776735.
        if (useMaterial3()) {
            mInjector.menuManager.updateSubMenu(null);
            if (mNavigator != null) {
                mNavigator.updateActionMenu();
            }
        } else {
            mSearchManager.showMenu(mState.stack);
            final ActionMenuView subMenuView = findViewById(R.id.sub_menu);
            mInjector.menuManager.updateSubMenu(subMenuView.getMenu());
        }
@@ -569,7 +599,11 @@ public abstract class BaseActivity
            return;
        }

        if (useMaterial3()) {
            mNavigator.closeSelectionBar();
        } else {
            mInjector.actionModeController.finishActionMode();
        }
        mSortController.onViewModeChanged(mState.derivedMode);

        // Set summary header's visibility. Only recents and downloads root may have summary in
@@ -668,6 +702,10 @@ public abstract class BaseActivity
        mNavigator.update();
    }

    public final NavigationViewManager getNavigator() {
        return mNavigator;
    }

    @Override
    public void restoreRootAndDirectory() {
        // We're trying to restore stuff in document stack from saved instance. If we didn't have a
+5 −0
Original line number Diff line number Diff line
@@ -15,6 +15,8 @@
 */
package com.android.documentsui;

import static com.android.documentsui.flags.Flags.useMaterial3;

import static java.lang.annotation.ElementType.FIELD;
import static java.lang.annotation.RetentionPolicy.SOURCE;

@@ -127,6 +129,9 @@ public class Injector<T extends ActionHandler> {

    public final ActionModeController getActionModeController(
            SelectionDetails selectionDetails, EventHandler<MenuItem> menuItemClicker) {
        if (useMaterial3()) {
            return null;
        }
        return actionModeController.reset(selectionDetails, menuItemClicker);
    }

Loading