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

Commit ac1554dd authored by TreeHugger Robot's avatar TreeHugger Robot Committed by Android (Google) Code Review
Browse files

Merge "Prevent new Docs getting pushed onto the stack if they already at top...

Merge "Prevent new Docs getting pushed onto the stack if they already at top of stack." into arc-apps
parents f02e4b1e db7a0e72
Loading
Loading
Loading
Loading
+9 −4
Original line number Diff line number Diff line
@@ -84,9 +84,10 @@ public class DocumentStack implements Durable, Parcelable {
    public DocumentStack(DocumentStack src, DocumentInfo... docs) {
        mList = new LinkedList<>(src.mList);
        for (DocumentInfo doc : docs) {
            mList.addLast(doc);
            push(doc);
        }

        mStackTouched = false;
        mRoot = src.mRoot;
    }

@@ -118,10 +119,14 @@ public class DocumentStack implements Durable, Parcelable {
    }

    public void push(DocumentInfo info) {
        boolean alreadyInStack = mList.contains(info);
        assert (!alreadyInStack);
        if (!alreadyInStack) {
            if (DEBUG) Log.d(TAG, "Adding doc to stack: " + info);
            mList.addLast(info);
            mStackTouched = true;
        }
    }

    public DocumentInfo pop() {
        if (DEBUG) Log.d(TAG, "Popping doc off stack.");
+22 −0
Original line number Diff line number Diff line
@@ -230,6 +230,20 @@ public final class DocumentClipper {
        copyFromClipData(destination, docStack, mClipboard.getPrimaryClip(), callback);
    }

    /**
     * Copies documents from clipboard. It's the same as {@link #copyFromClipData} with clipData
     * returned from {@link ClipboardManager#getPrimaryClip()}.
     *
     * @param docStack the document stack to the destination folder,
     * @param callback callback to notify when operation finishes.
     */
    public void copyFromClipboard(
            DocumentStack docStack,
            FileOperations.Callback callback) {

        copyFromClipData(docStack, mClipboard.getPrimaryClip(), callback);
    }

    /**
     * Copied documents from given clip data to a root directory.
     * @param root the root which root directory to copy to
@@ -265,6 +279,14 @@ public final class DocumentClipper {
        copyFromClipData(dstStack, clipData, callback);
    }

    /**
     * Copies documents from given clip data to a folder.
     *
     * @param docStack the document stack to the destination folder, including the destination
     *            folder.
     * @param clipData the clipData to copy from
     * @param callback callback to notify when operation finishes
     */
    private void copyFromClipData(
            final DocumentStack dstStack,
            final @Nullable ClipData clipData,
+19 −10
Original line number Diff line number Diff line
@@ -860,13 +860,14 @@ public class DirectoryFragment extends Fragment
        return mInjector.config.isDocumentEnabled(mimeType, flags, mState);
    }

    /**
     * Paste selection files from the primary clip into the current window.
     */
    public void pasteFromClipboard() {
        Metrics.logUserAction(getContext(), Metrics.USER_ACTION_PASTE_CLIPBOARD);

        BaseActivity activity = (BaseActivity) getActivity();
        DocumentInfo destination = activity.getCurrentDirectory();
        // Since we are pasting into the current window, we already have the destination in the
        // stack. No need for a destination DocumentInfo.
        mClipper.copyFromClipboard(
                destination,
                mState.stack,
                mInjector.dialogs::showFileOperationStatus);
        getActivity().invalidateOptionsMenu();
@@ -881,7 +882,6 @@ public class DirectoryFragment extends Fragment
            Log.w(TAG, "Invalid destination. Can't obtain cursor for modelId: " + modelId);
            return;
        }
        BaseActivity activity = mActivity;
        DocumentInfo destination = DocumentInfo.fromDirectoryCursor(dstCursor);
        mClipper.copyFromClipboard(
                destination,
@@ -968,11 +968,20 @@ public class DirectoryFragment extends Fragment
                        : Metrics.USER_ACTION_DRAG_N_DROP);

        DocumentInfo dst = getDestination(v);
        // If destination is already at top of stack, no need to pass it in
        if (!mState.stack.isEmpty() && mState.stack.peek().equals(dst)) {
            mClipper.copyFromClipData(
                    null,
                    mState.stack,
                    clipData,
                    mInjector.dialogs::showFileOperationStatus);
        } else {
            mClipper.copyFromClipData(
                    dst,
                    mState.stack,
                    clipData,
                    mInjector.dialogs::showFileOperationStatus);
        }
        return true;
    }

+12 −4
Original line number Diff line number Diff line
@@ -120,8 +120,6 @@ public class AbstractActionHandlerTest {
                Arrays.asList(TestEnv.FOLDER_1.documentId, TestEnv.FOLDER_2.documentId));
        mEnv.docs.nextDocuments = Arrays.asList(TestEnv.FOLDER_1, TestEnv.FOLDER_2);

        mEnv.state.stack.push(TestEnv.FOLDER_0);

        mHandler.openContainerDocument(TestEnv.FOLDER_2);

        mEnv.beforeAsserts();
@@ -138,8 +136,6 @@ public class AbstractActionHandlerTest {
        mEnv.searchViewManager.isSearching = true;
        mEnv.docs.nextDocuments = Arrays.asList(TestEnv.FOLDER_1, TestEnv.FOLDER_2);

        mEnv.state.stack.push(TestEnv.FOLDER_0);

        mHandler.openContainerDocument(TestEnv.FOLDER_2);

        mEnv.beforeAsserts();
@@ -149,6 +145,18 @@ public class AbstractActionHandlerTest {
        assertEquals(TestEnv.FOLDER_0, mEnv.state.stack.pop());
    }

    @Test
    public void testOpensDocument_AssertionErrorIfAlreadyInStack() throws Exception {
        mEnv.populateStack();
        boolean threw = false;
        try {
            mEnv.state.stack.push(TestEnv.FOLDER_0);
        } catch (AssertionError e) {
            threw = true;
        }
        assertTrue(threw);
    }

    @Test
    public void testLaunchToDocuments() throws Exception {
        mEnv.docs.nextIsDocumentsUri = true;