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

Commit 60e78569 authored by Treehugger Robot's avatar Treehugger Robot Committed by Android (Google) Code Review
Browse files

Merge "Add "Open" to context menu when a single file is selected" into main

parents 0945472f 05e57300
Loading
Loading
Loading
Loading
+5 −0
Original line number Diff line number Diff line
@@ -251,6 +251,11 @@ public abstract class AbstractActionHandler<T extends FragmentActivity & CommonA
        throw new UnsupportedOperationException("Can't open document.");
    }

    @Override
    public void openDocumentViewOnly(DocumentInfo doc) {
        throw new UnsupportedOperationException("Open doc not supported!");
    }

    @Override
    public void showInspector(DocumentInfo doc) {
        throw new UnsupportedOperationException("Can't open properties.");
+6 −0
Original line number Diff line number Diff line
@@ -128,6 +128,12 @@ public interface ActionHandler {
     */
    boolean openItem(ItemDetails<String> doc, @ViewType int type, @ViewType int fallback);

    /**
     * Similar to openItem but takes DocumentInfo instead of DocumentItemDetails and uses
     * VIEW_TYPE_VIEW with no fallback.
     */
    void openDocumentViewOnly(DocumentInfo doc);

    /**
     * This is called when user hovers over a doc for enough time during a drag n' drop, to open a
     * folder that accepts drop. We should only open a container that's not an archive, since archives
+1 −1
Original line number Diff line number Diff line
@@ -427,7 +427,7 @@ public abstract class MenuManager {

        boolean canExtract();

        boolean canOpenWith();
        boolean canOpen();

        boolean canViewInOwner();
    }
+26 −1
Original line number Diff line number Diff line
@@ -21,6 +21,7 @@ import static com.android.documentsui.base.SharedMinimal.DEBUG;
import static com.android.documentsui.base.SharedMinimal.VERBOSE;
import static com.android.documentsui.base.State.MODE_GRID;
import static com.android.documentsui.base.State.MODE_LIST;
import static com.android.documentsui.flags.Flags.desktopFileHandling;

import android.app.ActivityManager;
import android.content.BroadcastReceiver;
@@ -924,7 +925,17 @@ public class DirectoryFragment extends Fragment implements SwipeRefreshLayout.On
        mSelectionMgr.copySelection(selection);

        final int id = item.getItemId();
        if (id == R.id.action_menu_select || id == R.id.dir_menu_open) {
        if (desktopFileHandling() && id == R.id.dir_menu_open) {
            // On desktop, "open" is displayed in file management mode (i.e. `files.MenuManager`).
            // This menu item behaves the same as double click on the menu item which is handled by
            // onItemActivated but since onItemActivated requires a RecylcerView ItemDetails, we're
            // using viewDocument that takes a Selection.
            viewDocument(selection);
            return true;
        } else if (id == R.id.action_menu_select || id == R.id.dir_menu_open) {
            // Note: this code path is never executed for `dir_menu_open`. The menu item is always
            // hidden unless the desktopFileHandling flag is enabled, in which case the menu item
            // will be handled by the condition above.
            openDocuments(selection);
            mActionModeController.finishActionMode();
            return true;
@@ -1082,6 +1093,20 @@ public class DirectoryFragment extends Fragment implements SwipeRefreshLayout.On
        mActions.showChooserForDoc(doc);
    }

    private void viewDocument(final Selection<String> selected) {
        Metrics.logUserAction(MetricConsts.USER_ACTION_OPEN);

        if (selected.isEmpty()) {
            return;
        }

        assert selected.size() == 1;
        DocumentInfo doc =
                DocumentInfo.fromDirectoryCursor(mModel.getItem(selected.iterator().next()));

        mActions.openDocumentViewOnly(doc);
    }

    private void transferDocuments(
            final Selection<String> selected, @Nullable DocumentStack destination,
            final @OpType int mode) {
+1 −1
Original line number Diff line number Diff line
@@ -168,7 +168,7 @@ public class SelectionMetadata extends SelectionObserver<String>
    }

    @Override
    public boolean canOpenWith() {
    public boolean canOpen() {
        return size() == 1 && mDirectoryCount == 0 && mInArchiveCount == 0 && mPartialCount == 0;
    }
}
Loading