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

Commit 92e77f6b authored by Tomasz Mikolajewski's avatar Tomasz Mikolajewski
Browse files

Add support for compressing to the current destination.

If possible, compress to the current, if not then ask user
to pick the destination.

Test: Tested manually in read only and not read only destination.
Bug: 20822019
Change-Id: I33ca9c515f344980b7b2fc51c680b6aa3020a715
parent 3cdedd17
Loading
Loading
Loading
Loading
+11 −5
Original line number Diff line number Diff line
@@ -38,11 +38,7 @@
        android:title="@string/menu_copy"
        android:showAsAction="never"
        android:visible="false" />
    <item
        android:id="@+id/menu_compress_to"
        android:title="@string/menu_compress"
        android:showAsAction="never"
        android:visible="false" />

    <item
        android:id="@+id/menu_extract_to"
        android:icon="@drawable/ic_menu_extract"
@@ -54,6 +50,16 @@
        android:title="@string/menu_move"
        android:showAsAction="never"
        android:visible="false" />
    <item
        android:id="@+id/menu_compress_to"
        android:title="@string/menu_compress_to"
        android:showAsAction="never"
        android:visible="false" />
    <item
        android:id="@+id/menu_compress"
        android:title="@string/menu_compress"
        android:showAsAction="never"
        android:visible="false" />
    <item
        android:id="@+id/menu_rename"
        android:title="@string/menu_rename"
+4 −2
Original line number Diff line number Diff line
@@ -52,8 +52,10 @@
    <string name="menu_copy">Copy to\u2026</string>
    <!-- Menu item title that moves the selected documents [CHAR LIMIT=28] -->
    <string name="menu_move">Move to\u2026</string>
    <!-- Menu item title that compresses the selected documents [CHAR LIMIT=28] -->
    <string name="menu_compress">Compress to\u2026</string>
    <!-- Menu item title that compresses the selected documents to the user selected directory [CHAR LIMIT=28] -->
    <string name="menu_compress_to">Compress to\u2026</string>
    <!-- Menu item title that compresses the selected documents to the current directory [CHAR LIMIT=28] -->
    <string name="menu_compress">Compress</string>
    <!-- Menu item title that extracts the selected documents [CHAR LIMIT=28] -->
    <string name="menu_extract">Extract to\u2026</string>
    <!-- Menu item that renames the selected document [CHAR LIMIT=28] -->
+5 −0
Original line number Diff line number Diff line
@@ -61,6 +61,7 @@ public abstract class MenuManager {
        updateMoveTo(menu.findItem(R.id.menu_move_to), selection);
        updateCopyTo(menu.findItem(R.id.menu_copy_to), selection);
        updateCompressTo(menu.findItem(R.id.menu_compress_to), selection);
        updateCompress(menu.findItem(R.id.menu_compress), selection);
        updateExtractTo(menu.findItem(R.id.menu_extract_to), selection);

        Menus.disableHiddenItems(menu);
@@ -275,6 +276,10 @@ public abstract class MenuManager {
        compressTo.setVisible(false);
    }

    protected void updateCompress(MenuItem compress, SelectionDetails selectionDetails) {
        compress.setVisible(false);
    }

    protected void updateExtractTo(MenuItem extractTo, SelectionDetails selectionDetails) {
        extractTo.setVisible(false);
    }
+37 −14
Original line number Diff line number Diff line
@@ -81,6 +81,7 @@ import com.android.documentsui.R;
import com.android.documentsui.RecentsLoader;
import com.android.documentsui.ThumbnailCache;
import com.android.documentsui.base.DocumentInfo;
import com.android.documentsui.base.DocumentStack;
import com.android.documentsui.base.EventHandler;
import com.android.documentsui.base.EventListener;
import com.android.documentsui.base.Events.InputEvent;
@@ -614,21 +615,30 @@ public class DirectoryFragment extends Fragment
                return true;

            case R.id.menu_copy_to:
                transferDocuments(selection, FileOperationService.OPERATION_COPY);
                transferDocuments(selection, null, FileOperationService.OPERATION_COPY);
                // TODO: Only finish selection mode if copy-to is not canceled.
                // Need to plum down into handling the way we do with deleteDocuments.
                mActionModeController.finishActionMode();
                return true;

            case R.id.menu_compress:
                transferDocuments(selection, mState.stack,
                        FileOperationService.OPERATION_COMPRESS);
                // TODO: Only finish selection mode if compress is not canceled.
                // Need to plum down into handling the way we do with deleteDocuments.
                mActionModeController.finishActionMode();
                return true;

            case R.id.menu_compress_to:
                transferDocuments(selection, FileOperationService.OPERATION_COMPRESS);
                transferDocuments(selection, null, FileOperationService.OPERATION_COMPRESS);
                // TODO: Only finish selection mode if compress-to is not canceled.
                // Need to plum down into handling the way we do with deleteDocuments.
                mActionModeController.finishActionMode();
                return true;

            // TODO: Implement extract (to the current directory).
            case R.id.menu_extract_to:
                transferDocuments(selection, FileOperationService.OPERATION_EXTRACT);
                transferDocuments(selection, null, FileOperationService.OPERATION_EXTRACT);
                // TODO: Only finish selection mode if compress-to is not canceled.
                // Need to plum down into handling the way we do with deleteDocuments.
                mActionModeController.finishActionMode();
@@ -637,7 +647,7 @@ public class DirectoryFragment extends Fragment
            case R.id.menu_move_to:
                // Exit selection mode first, so we avoid deselecting deleted documents.
                mActionModeController.finishActionMode();
                transferDocuments(selection, FileOperationService.OPERATION_MOVE);
                transferDocuments(selection, null, FileOperationService.OPERATION_MOVE);
                return true;

            case R.id.menu_cut_to_clipboard:
@@ -721,7 +731,8 @@ public class DirectoryFragment extends Fragment
        mActions.showChooserForDoc(doc);
    }

    private void transferDocuments(final Selection selected, final @OpType int mode) {
    private void transferDocuments(final Selection selected, @Nullable DocumentStack destination,
            final @OpType int mode) {
        switch (mode) {
            case FileOperationService.OPERATION_COPY:
                Metrics.logUserAction(getContext(), Metrics.USER_ACTION_COPY_TO);
@@ -737,14 +748,6 @@ public class DirectoryFragment extends Fragment
                break;
        }

        // Pop up a dialog to pick a destination.  This is inadequate but works for now.
        // TODO: Implement a picker that is to spec.
        final Intent intent = new Intent(
                Shared.ACTION_PICK_COPY_DESTINATION,
                Uri.EMPTY,
                getActivity(),
                PickActivity.class);

        UrisSupplier srcs;
        try {
            ClipStore clipStorage = DocumentsApplication.getClipStore(getContext());
@@ -754,12 +757,30 @@ public class DirectoryFragment extends Fragment
        }

        final DocumentInfo parent = mState.stack.peek();
        mLocalState.mPendingOperation = new FileOperation.Builder()
        final FileOperation operation = new FileOperation.Builder()
                .withOpType(mode)
                .withSrcParent(parent == null ? null : parent.derivedUri)
                .withSrcs(srcs)
                .build();

        if (destination != null) {
            operation.setDestination(destination);
            FileOperations.start(
                    mActivity,
                    operation,
                    mInjector.dialogs::showFileOperationStatus);
            return;
        }

        // Pop up a dialog to pick a destination.  This is inadequate but works for now.
        // TODO: Implement a picker that is to spec.
        mLocalState.mPendingOperation = operation;
        final Intent intent = new Intent(
                Shared.ACTION_PICK_COPY_DESTINATION,
                Uri.EMPTY,
                getActivity(),
                PickActivity.class);

        // Set an appropriate title on the drawer when it is shown in the picker.
        // Coupled with the fact that we auto-open the drawer for copy/move operations
        // it should basically be the thing people see first.
@@ -780,6 +801,7 @@ public class DirectoryFragment extends Fragment
            default:
                throw new UnsupportedOperationException("Unknown mode: " + mode);
        }

        intent.putExtra(DocumentsContract.EXTRA_PROMPT, getResources().getString(drawerTitleId));

        // Model must be accessed in UI thread, since underlying cursor is not threadsafe.
@@ -1053,6 +1075,7 @@ public class DirectoryFragment extends Fragment
            final int docFlags = getCursorInt(cursor, Document.COLUMN_FLAGS);
            return mInjector.config.canSelectType(docMimeType, docFlags, mState);
        } else {
        final DocumentInfo parent = mState.stack.peek();
            // Right now all selected items can be deselected.
            return true;
        }
+14 −2
Original line number Diff line number Diff line
@@ -175,8 +175,20 @@ public final class MenuManager extends com.android.documentsui.MenuManager {

    @Override
    protected void updateCompressTo(MenuItem compressTo, SelectionDetails selectionDetails) {
        compressTo.setVisible(true);
        // Do not allow to compress already compressed files for simplicity.
        // (1) Do not allow to compress already compressed files for simplicity.
        // (2) Show only if the current directory *is* read-only.
        final boolean readOnly = !mDirDetails.canCreateDoc();
        compressTo.setVisible(readOnly);
        compressTo.setEnabled(!selectionDetails.containsPartialFiles() &&
                !selectionDetails.canExtract());
    }

    @Override
    protected void updateCompress(MenuItem compressTo, SelectionDetails selectionDetails) {
        // (1) Do not allow to compress already compressed files for simplicity.
        // (2) Show only if the current directory *is not* read only.
        final boolean readOnly = !mDirDetails.canCreateDoc();
        compressTo.setVisible(!readOnly);
        compressTo.setEnabled(!selectionDetails.containsPartialFiles() &&
                !selectionDetails.canExtract());
    }
Loading