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

Commit 846158c9 authored by François Degros's avatar François Degros Committed by Android (Google) Code Review
Browse files

Merge "Control visibility of 'Browse' and 'Extract here' menu items" into main

parents ca68059f ba805cd8
Loading
Loading
Loading
Loading
+23 −10
Original line number Original line Diff line number Diff line
@@ -159,11 +159,11 @@ public abstract class MenuManager {
    }
    }


    /**
    /**
     * @see DirectoryFragment#onCreateContextMenu
     *
     * Called when user tries to generate a context menu anchored to a file when the selection
     * Called when user tries to generate a context menu anchored to a file when the selection
     * doesn't contain any folder.
     * doesn't contain any folder.
     *
     *
     * @see DirectoryFragment#onCreateContextMenu
     *
     * @param selectionDetails
     * @param selectionDetails
     *      containsFiles may return false because this may be called when user right clicks on an
     *      containsFiles may return false because this may be called when user right clicks on an
     *      unselectable item in pickers
     *      unselectable item in pickers
@@ -193,11 +193,11 @@ public abstract class MenuManager {
    }
    }


    /**
    /**
     * @see DirectoryFragment#onCreateContextMenu
     *
     * Called when user tries to generate a context menu anchored to a folder when the selection
     * Called when user tries to generate a context menu anchored to a folder when the selection
     * doesn't contain any file.
     * doesn't contain any file.
     *
     *
     * @see DirectoryFragment#onCreateContextMenu
     *
     * @param selectionDetails
     * @param selectionDetails
     *      containDirectories may return false because this may be called when user right clicks on
     *      containDirectories may return false because this may be called when user right clicks on
     *      an unselectable item in pickers
     *      an unselectable item in pickers
@@ -418,25 +418,42 @@ public abstract class MenuManager {
    }
    }


    protected abstract void updateSelectAll(MenuItem selectAll);
    protected abstract void updateSelectAll(MenuItem selectAll);

    protected abstract void updateSelectAll(MenuItem selectAll, SelectionDetails selectionDetails);
    protected abstract void updateSelectAll(MenuItem selectAll, SelectionDetails selectionDetails);

    protected abstract void updateDeselectAll(
    protected abstract void updateDeselectAll(
            MenuItem deselectAll, SelectionDetails selectionDetails);
            MenuItem deselectAll, SelectionDetails selectionDetails);

    protected abstract void updateCreateDir(MenuItem createDir);
    protected abstract void updateCreateDir(MenuItem createDir);


    /**
    /**
     * Access to meta data about the selection.
     * Access to meta data about the selection.
     */
     */
    public interface SelectionDetails {
    public interface SelectionDetails {
        /** Gets the total number of items (files and directories) in the selection. */
        int size();

        /** Returns whether the selection contains at least a directory. */
        boolean containsDirectories();
        boolean containsDirectories();


        /** Returns whether the selection contains at least a file. */
        boolean containsFiles();
        boolean containsFiles();


        int size();
        /**

         * Returns whether the selection contains at least a file that has not been fully downloaded
         * yet.
         */
        boolean containsPartialFiles();
        boolean containsPartialFiles();


        /** Returns whether the selection contains at least a file located in a mounted archive. */
        boolean containsFilesInArchive();
        boolean containsFilesInArchive();


        /**
         * Returns whether the selection contains exactly one file which is also a supported archive
         * type.
         */
        boolean isArchive();

        // TODO: Update these to express characteristics instead of answering concrete questions,
        // TODO: Update these to express characteristics instead of answering concrete questions,
        // since the answer to those questions is (or can be) activity specific.
        // since the answer to those questions is (or can be) activity specific.
        boolean canDelete();
        boolean canDelete();
@@ -450,10 +467,6 @@ public abstract class MenuManager {
        boolean canOpen();
        boolean canOpen();


        boolean canViewInOwner();
        boolean canViewInOwner();

        default boolean isArchive() {
            return false;
        }
    }
    }


    public static class DirectoryDetails {
    public static class DirectoryDetails {
+3 −8
Original line number Original line Diff line number Diff line
@@ -24,13 +24,12 @@ import static org.apache.commons.compress.compressors.CompressorStreamFactory.XZ


import androidx.annotation.Nullable;
import androidx.annotation.Nullable;


import java.util.HashMap;
import java.util.Map;
import java.util.Set;

import org.apache.commons.compress.compressors.brotli.BrotliUtils;
import org.apache.commons.compress.compressors.brotli.BrotliUtils;
import org.apache.commons.compress.compressors.xz.XZUtils;
import org.apache.commons.compress.compressors.xz.XZUtils;


import java.util.HashMap;
import java.util.Map;

/**
/**
 * To query how to generate ArchiveHandle, how to create CompressInputStream and how to create
 * To query how to generate ArchiveHandle, how to create CompressInputStream and how to create
 * ArchiveInputStream by using MIME type in ArchiveRegistry.
 * ArchiveInputStream by using MIME type in ArchiveRegistry.
@@ -136,8 +135,4 @@ final class ArchiveRegistry {
    static Integer getArchiveType(String mimeType) {
    static Integer getArchiveType(String mimeType) {
        return sHandleArchiveMap.get(mimeType);
        return sHandleArchiveMap.get(mimeType);
    }
    }

    static Set<String> getSupportList() {
        return sHandleArchiveMap.keySet();
    }
}
}
+2 −11
Original line number Original line Diff line number Diff line
@@ -44,7 +44,6 @@ import java.io.InputStream;
import java.util.HashMap;
import java.util.HashMap;
import java.util.Map;
import java.util.Map;
import java.util.Objects;
import java.util.Objects;
import java.util.Set;


/**
/**
 * Provides basic implementation for creating, extracting and accessing
 * Provides basic implementation for creating, extracting and accessing
@@ -62,7 +61,6 @@ public class ArchivesProvider extends DocumentsProvider {
    private static final String TAG = "ArchivesProvider";
    private static final String TAG = "ArchivesProvider";
    private static final String METHOD_ACQUIRE_ARCHIVE = "acquireArchive";
    private static final String METHOD_ACQUIRE_ARCHIVE = "acquireArchive";
    private static final String METHOD_RELEASE_ARCHIVE = "releaseArchive";
    private static final String METHOD_RELEASE_ARCHIVE = "releaseArchive";
    private static final Set<String> ZIP_MIME_TYPES = ArchiveRegistry.getSupportList();


    @GuardedBy("mArchives")
    @GuardedBy("mArchives")
    private final Map<Key, Loader> mArchives = new HashMap<>();
    private final Map<Key, Loader> mArchives = new HashMap<>();
@@ -235,16 +233,9 @@ public class ArchivesProvider extends DocumentsProvider {
        return loader.get().openDocumentThumbnail(documentId, sizeHint, signal);
        return loader.get().openDocumentThumbnail(documentId, sizeHint, signal);
    }
    }


    /**
    /** Returns whether the given mime type is a supported archive type. */
     * Returns true if the passed mime type is supported by the helper.
     */
    public static boolean isSupportedArchiveType(String mimeType) {
    public static boolean isSupportedArchiveType(String mimeType) {
        for (final String zipMimeType : ZIP_MIME_TYPES) {
        return ArchiveRegistry.getArchiveType(mimeType) != null;
            if (zipMimeType.equals(mimeType)) {
                return true;
            }
        }
        return false;
    }
    }


    /**
    /**
+17 −2
Original line number Original line Diff line number Diff line
@@ -56,7 +56,13 @@ public class SelectionMetadata extends SelectionObserver<String>
    private int mWritableDirectoryCount = 0;
    private int mWritableDirectoryCount = 0;
    private int mNoDeleteCount = 0;
    private int mNoDeleteCount = 0;
    private int mNoRenameCount = 0;
    private int mNoRenameCount = 0;

    /** Number of files that are located in mounted archives. */
    private int mInArchiveCount = 0;
    private int mInArchiveCount = 0;

    /** Number of archives. */
    private int mArchiveCount = 0;

    private boolean mSupportsSettings = false;
    private boolean mSupportsSettings = false;


    public SelectionMetadata(Function<String, Cursor> docFinder) {
    public SelectionMetadata(Function<String, Cursor> docFinder) {
@@ -79,6 +85,9 @@ public class SelectionMetadata extends SelectionObserver<String>
            mDirectoryCount += delta;
            mDirectoryCount += delta;
        } else {
        } else {
            mFileCount += delta;
            mFileCount += delta;
            if (ArchivesProvider.isSupportedArchiveType(mimeType)) {
                mArchiveCount += delta;
            }
        }
        }


        final int docFlags = getCursorInt(cursor, Document.COLUMN_FLAGS);
        final int docFlags = getCursorInt(cursor, Document.COLUMN_FLAGS);
@@ -97,9 +106,8 @@ public class SelectionMetadata extends SelectionObserver<String>
        if ((docFlags & Document.FLAG_PARTIAL) != 0) {
        if ((docFlags & Document.FLAG_PARTIAL) != 0) {
            mPartialCount += delta;
            mPartialCount += delta;
        }
        }
        mSupportsSettings = (docFlags & Document.FLAG_SUPPORTS_SETTINGS) != 0 &&
                (mFileCount + mDirectoryCount) == 1;


        mSupportsSettings = (docFlags & Document.FLAG_SUPPORTS_SETTINGS) != 0 && size() == 1;


        final String authority = getCursorString(cursor, RootCursorWrapper.COLUMN_AUTHORITY);
        final String authority = getCursorString(cursor, RootCursorWrapper.COLUMN_AUTHORITY);
        if (ArchivesProvider.AUTHORITY.equals(authority)) {
        if (ArchivesProvider.AUTHORITY.equals(authority)) {
@@ -115,6 +123,8 @@ public class SelectionMetadata extends SelectionObserver<String>
        mWritableDirectoryCount = 0;
        mWritableDirectoryCount = 0;
        mNoDeleteCount = 0;
        mNoDeleteCount = 0;
        mNoRenameCount = 0;
        mNoRenameCount = 0;
        mInArchiveCount = 0;
        mArchiveCount = 0;
    }
    }


    @Override
    @Override
@@ -142,6 +152,11 @@ public class SelectionMetadata extends SelectionObserver<String>
        return mInArchiveCount > 0;
        return mInArchiveCount > 0;
    }
    }


    @Override
    public boolean isArchive() {
        return mDirectoryCount == 0 && mFileCount == 1 && mArchiveCount == 1;
    }

    @Override
    @Override
    public boolean canDelete() {
    public boolean canDelete() {
        return size() > 0 && mNoDeleteCount == 0;
        return size() > 0 && mNoDeleteCount == 0;
+7 −1
Original line number Original line Diff line number Diff line
@@ -30,6 +30,7 @@ public class TestSelectionDetails implements SelectionDetails {
    public boolean containsFilesInArchive;
    public boolean containsFilesInArchive;
    public boolean containDirectories;
    public boolean containDirectories;
    public boolean containFiles;
    public boolean containFiles;
    public boolean isArchive;
    public boolean canPasteInto;
    public boolean canPasteInto;
    public boolean canExtract;
    public boolean canExtract;
    public boolean canOpen;
    public boolean canOpen;
@@ -55,6 +56,11 @@ public class TestSelectionDetails implements SelectionDetails {
        return containsFilesInArchive;
        return containsFilesInArchive;
    }
    }


    @Override
    public boolean isArchive() {
        return isArchive;
    }

    @Override
    @Override
    public boolean canRename() {
    public boolean canRename() {
        return canRename;
        return canRename;
Loading