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

Commit d947f019 authored by Ben Lin's avatar Ben Lin
Browse files

Add Cut/Copy/Delete operation to currently focused item.

Also removed ability to focus on items in the directory list while
there's an on-going selection to avoid having a weird state of both
focus and selection. Shift extension still works, just that once user
puts focus on RootsFragment, they won't be able to focus back into
DirectoryFragment.

Bug: 32141890
Change-Id: I14c06f8616b63d04f0b5f489032f7006f91416a8
parent a9e4522b
Loading
Loading
Loading
Loading
+16 −0
Original line number Diff line number Diff line
@@ -38,6 +38,7 @@ import com.android.documentsui.base.State;
import com.android.documentsui.dirlist.AnimationView.AnimationType;
import com.android.documentsui.dirlist.AnimationView;
import com.android.documentsui.dirlist.DocumentDetails;
import com.android.documentsui.dirlist.FocusHandler;
import com.android.documentsui.files.LauncherActivity;
import com.android.documentsui.queries.SearchViewManager;
import com.android.documentsui.roots.LoadRootTask;
@@ -62,15 +63,18 @@ public abstract class AbstractActionHandler<T extends Activity & CommonAddons>
    protected final State mState;
    protected final RootsAccess mRoots;
    protected final DocumentsAccess mDocs;
    protected final FocusHandler mFocusHandler;
    protected final SelectionManager mSelectionMgr;
    protected final SearchViewManager mSearchMgr;
    protected final Lookup<String, Executor> mExecutors;


    public AbstractActionHandler(
            T activity,
            State state,
            RootsAccess roots,
            DocumentsAccess docs,
            FocusHandler focusHandler,
            SelectionManager selectionMgr,
            SearchViewManager searchMgr,
            Lookup<String, Executor> executors) {
@@ -78,6 +82,7 @@ public abstract class AbstractActionHandler<T extends Activity & CommonAddons>
        assert(activity != null);
        assert(state != null);
        assert(roots != null);
        assert(focusHandler != null);
        assert(selectionMgr != null);
        assert(searchMgr != null);
        assert(docs != null);
@@ -86,6 +91,7 @@ public abstract class AbstractActionHandler<T extends Activity & CommonAddons>
        mState = state;
        mRoots = roots;
        mDocs = docs;
        mFocusHandler = focusHandler;
        mSelectionMgr = selectionMgr;
        mSearchMgr = searchMgr;
        mExecutors = executors;
@@ -231,6 +237,16 @@ public abstract class AbstractActionHandler<T extends Activity & CommonAddons>
        mActivity.refreshCurrentRootAndDirectory(anim);
    }

    @Override
    public void cutToClipboard() {
        throw new UnsupportedOperationException("Cut not supported!");
    }

    @Override
    public void copyToClipboard() {
        throw new UnsupportedOperationException("Copy not supported!");
    }

    @Override
    public void deleteSelectedDocuments() {
        throw new UnsupportedOperationException("Delete not supported!");
+7 −0
Original line number Diff line number Diff line
@@ -65,6 +65,13 @@ public interface ActionHandler {

    void openContainerDocument(DocumentInfo doc);

    void cutToClipboard();

    void copyToClipboard();

    /**
     * In general, selected = selection or single focused item
     */
    void deleteSelectedDocuments();

    void shareSelectedDocuments();
+8 −7
Original line number Diff line number Diff line
@@ -666,21 +666,22 @@ public abstract class BaseActivity<T extends ActionHandler>
     * locked, open/close it as appropriate.
     */
    void toggleNavDrawerFocus() {
        boolean toogleHappened = false;
        if (mNavDrawerHasFocus) {
            mDrawer.setOpen(false);
            DirectoryFragment df = DirectoryFragment.get(getFragmentManager());
            if (df != null) {
                df.requestFocus();
            }
            assert (df != null);
            toogleHappened = df.requestFocus();
        } else {
            mDrawer.setOpen(true);
            RootsFragment rf = RootsFragment.get(getFragmentManager());
            if (rf != null) {
                rf.requestFocus();
            }
            assert (rf != null);
            toogleHappened = rf.requestFocus();
        }
        if (toogleHappened) {
            mNavDrawerHasFocus = !mNavDrawerHasFocus;
        }
    }

    /**
     * Pops the top entry off the directory stack, and returns the user to the previous directory.
+10 −0
Original line number Diff line number Diff line
@@ -146,6 +146,16 @@ public final class FocusManager implements FocusHandler {
        return mScope.lastFocusPosition;
    }

    @Override
    public @Nullable String getFocusModelId() {
        if (mScope.lastFocusPosition != RecyclerView.NO_POSITION) {
            DocumentHolder holder = (DocumentHolder) mScope.view
                    .findViewHolderForAdapterPosition(mScope.lastFocusPosition);
            return holder.getModelId();
        }
        return null;
    }

    /**
     * Finds the destination position where the focus should land for a given navigation event.
     *
+7 −31
Original line number Diff line number Diff line
@@ -581,11 +581,11 @@ public class DirectoryFragment extends Fragment
                return true;

            case R.id.menu_cut_to_clipboard:
                cutSelectedToClipboard();
                mActions.cutToClipboard();
                return true;

            case R.id.menu_copy_to_clipboard:
                copySelectedToClipboard();
                mActions.copyToClipboard();
                return true;

            case R.id.menu_paste_from_clipboard:
@@ -786,34 +786,6 @@ public class DirectoryFragment extends Fragment
        mRecView.requestFocus();
    }

    public void copySelectedToClipboard() {
        Metrics.logUserAction(getContext(), Metrics.USER_ACTION_COPY_CLIPBOARD);

        Selection selection = mSelectionMgr.getSelection(new Selection());
        if (selection.isEmpty()) {
            return;
        }
        mSelectionMgr.clearSelection();

        mClipper.clipDocumentsForCopy(mModel::getItemUri, selection);

        Snackbars.showDocumentsClipped(getActivity(), selection.size());
    }

    public void cutSelectedToClipboard() {
        Metrics.logUserAction(getContext(), Metrics.USER_ACTION_CUT_CLIPBOARD);

        Selection selection = mSelectionMgr.getSelection(new Selection());
        if (selection.isEmpty()) {
            return;
        }
        mSelectionMgr.clearSelection();

        mClipper.clipDocumentsForCut(mModel::getItemUri, selection, mState.stack.peek());

        Snackbars.showDocumentsClipped(getActivity(), selection.size());
    }

    public void pasteFromClipboard() {
        Metrics.logUserAction(getContext(), Metrics.USER_ACTION_PASTE_CLIPBOARD);

@@ -868,8 +840,12 @@ public class DirectoryFragment extends Fragment
    /**
     * Attempts to restore focus on the directory listing.
     */
    public void requestFocus() {
    public boolean requestFocus() {
        if (mSelectionMgr.hasSelection()) {
            return false;
        }
        mFocusManager.restoreLastFocus();
        return true;
    }

    private void setupDragAndDropOnDocumentView(View view, Cursor cursor) {
Loading