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

Commit 168e4648 authored by Steve McKay's avatar Steve McKay
Browse files

Add FLAG_PARTIAL. Partial files can't be copied.

This allows us to exclude in-progress downloads from copy.
Will update Downloads in a followup CL to flag active downloads.

Bug: 27526321
Change-Id: I50d1db5cfb69bc6b47e10cc0f520a51e3d3cb43e
parent 93a075ec
Loading
Loading
Loading
Loading
+11 −1
Original line number Original line Diff line number Diff line
@@ -379,8 +379,18 @@ public final class DocumentsContract {
         * @see DocumentsProvider#queryChildDocuments(String, String[], String)
         * @see DocumentsProvider#queryChildDocuments(String, String[], String)
         * @hide
         * @hide
         */
         */

        public static final int FLAG_ARCHIVE = 1 << 15;
        public static final int FLAG_ARCHIVE = 1 << 15;

        /**
         * Flag indicating that a document is not complete, likely its
         * contents are being downloaded. Partial files cannot be opened,
         * copied, moved in the UI. But they can be deleted and retried
         * if they represent a failed download.
         *
         * @see #COLUMN_FLAGS
         * @hide
         */
        public static final int FLAG_PARTIAL = 1 << 16;
    }
    }


    /**
    /**
+12 −3
Original line number Original line Diff line number Diff line
@@ -440,6 +440,7 @@ public class DirectoryFragment extends Fragment


        private Selection mSelected = new Selection();
        private Selection mSelected = new Selection();
        private ActionMode mActionMode;
        private ActionMode mActionMode;
        private int mNoCopyCount = 0;
        private int mNoDeleteCount = 0;
        private int mNoDeleteCount = 0;
        private int mNoRenameCount = -1;
        private int mNoRenameCount = -1;
        private Menu mMenu;
        private Menu mMenu;
@@ -471,6 +472,9 @@ public class DirectoryFragment extends Fragment
            // triggered on "silent" selection updates (i.e. we might be reacting to unfinalized
            // triggered on "silent" selection updates (i.e. we might be reacting to unfinalized
            // selection changes here)
            // selection changes here)
            final int docFlags = getCursorInt(cursor, Document.COLUMN_FLAGS);
            final int docFlags = getCursorInt(cursor, Document.COLUMN_FLAGS);
            if ((docFlags & Document.FLAG_PARTIAL) != 0) {
                mNoCopyCount += selected ? 1 : -1;
            }
            if ((docFlags & Document.FLAG_SUPPORTS_DELETE) == 0
            if ((docFlags & Document.FLAG_SUPPORTS_DELETE) == 0
                    && (docFlags & Document.FLAG_SUPPORTS_DELETE) == 0) {
                    && (docFlags & Document.FLAG_SUPPORTS_DELETE) == 0) {
                mNoDeleteCount += selected ? 1 : -1;
                mNoDeleteCount += selected ? 1 : -1;
@@ -537,19 +541,24 @@ public class DirectoryFragment extends Fragment
            return true;
            return true;
        }
        }


        boolean canRenameSelection() {
        boolean canCopySelection() {
            return mNoRenameCount == 0 && mSelectionManager.getSelection().size() == 1;
            return mNoCopyCount == 0;
        }
        }


        boolean canDeleteSelection() {
        boolean canDeleteSelection() {
            return mNoDeleteCount == 0;
            return mNoDeleteCount == 0;
        }
        }


        boolean canRenameSelection() {
            return mNoRenameCount == 0 && mSelectionManager.getSelection().size() == 1;
        }

        private void updateActionMenu() {
        private void updateActionMenu() {
            assert(mMenu != null);
            assert(mMenu != null);


            // Delegate update logic to our owning action, since specialized logic is desired.
            // Delegate update logic to our owning action, since specialized logic is desired.
            mTuner.updateActionMenu(mMenu, mType, canDeleteSelection(), canRenameSelection());
            mTuner.updateActionMenu(
                    mMenu, mType, canCopySelection(), canDeleteSelection(), canRenameSelection());
            Menus.disableHiddenItems(mMenu);
            Menus.disableHiddenItems(mMenu);
        }
        }


+15 −8
Original line number Original line Diff line number Diff line
@@ -58,9 +58,9 @@ public abstract class FragmentTuner {
        }
        }
    }
    }



    public abstract void updateActionMenu(
    public abstract void updateActionMenu(
            Menu menu, @ResultType int dirType, boolean canDelete, boolean canRename);
            Menu menu, @ResultType int dirType,
            boolean canCopy, boolean canDelete, boolean canRename);


    // Subtly different from isDocumentEnabled. The reason may be illuminated as follows.
    // Subtly different from isDocumentEnabled. The reason may be illuminated as follows.
    // A folder is enabled such that it may be double clicked, even in settings
    // A folder is enabled such that it may be double clicked, even in settings
@@ -140,7 +140,8 @@ public abstract class FragmentTuner {


        @Override
        @Override
        public void updateActionMenu(
        public void updateActionMenu(
                Menu menu, @ResultType int dirType, boolean canDelete, boolean canRename) {
                Menu menu, @ResultType int dirType,
                boolean canCopy, boolean canDelete, boolean canRename) {


            MenuItem open = menu.findItem(R.id.menu_open);
            MenuItem open = menu.findItem(R.id.menu_open);
            MenuItem share = menu.findItem(R.id.menu_share);
            MenuItem share = menu.findItem(R.id.menu_share);
@@ -198,22 +199,28 @@ public abstract class FragmentTuner {


        @Override
        @Override
        public void updateActionMenu(
        public void updateActionMenu(
                Menu menu, @ResultType int dirType, boolean canDelete, boolean canRename) {
                Menu menu, @ResultType int dirType,
                boolean canCopy, boolean canDelete, boolean canRename) {


            MenuItem copy = menu.findItem(R.id.menu_copy_to_clipboard);
            MenuItem copy = menu.findItem(R.id.menu_copy_to_clipboard);
            MenuItem paste = menu.findItem(R.id.menu_paste_from_clipboard);
            MenuItem paste = menu.findItem(R.id.menu_paste_from_clipboard);
            copy.setEnabled(dirType != DirectoryFragment.TYPE_RECENT_OPEN);
            copy.setEnabled(canCopy);


            MenuItem rename = menu.findItem(R.id.menu_rename);
            MenuItem rename = menu.findItem(R.id.menu_rename);
            MenuItem moveTo = menu.findItem(R.id.menu_move_to);
            MenuItem copyTo = menu.findItem(R.id.menu_copy_to);

            copyTo.setVisible(true);
            moveTo.setVisible(true);
            rename.setVisible(true);
            rename.setVisible(true);

            copyTo.setEnabled(canCopy);
            moveTo.setEnabled(canCopy && canDelete);
            rename.setEnabled(canRename);
            rename.setEnabled(canRename);


            menu.findItem(R.id.menu_share).setVisible(true);
            menu.findItem(R.id.menu_share).setVisible(true);
            menu.findItem(R.id.menu_delete).setVisible(canDelete);
            menu.findItem(R.id.menu_delete).setVisible(canDelete);
            menu.findItem(R.id.menu_open).setVisible(false);
            menu.findItem(R.id.menu_open).setVisible(false);
            menu.findItem(R.id.menu_copy_to).setVisible(true);
            menu.findItem(R.id.menu_move_to).setVisible(true);
            menu.findItem(R.id.menu_move_to).setEnabled(canDelete);


            Menus.disableHiddenItems(menu, copy, paste);
            Menus.disableHiddenItems(menu, copy, paste);
        }
        }
+5 −1
Original line number Original line Diff line number Diff line
@@ -74,7 +74,6 @@ public class DocumentInfo implements Durable, Parcelable {
        summary = null;
        summary = null;
        size = -1;
        size = -1;
        icon = 0;
        icon = 0;

        derivedUri = null;
        derivedUri = null;
    }
    }


@@ -210,6 +209,7 @@ public class DocumentInfo implements Durable, Parcelable {
                + ", isContainer=" + isContainer()
                + ", isContainer=" + isContainer()
                + ", isDirectory=" + isDirectory()
                + ", isDirectory=" + isDirectory()
                + ", isArchive=" + isArchive()
                + ", isArchive=" + isArchive()
                + ", isPartial=" + isPartial()
                + ", isVirtualDocument=" + isVirtualDocument()
                + ", isVirtualDocument=" + isVirtualDocument()
                + ", isDeleteSupported=" + isDeleteSupported()
                + ", isDeleteSupported=" + isDeleteSupported()
                + ", isCreateSupported=" + isCreateSupported()
                + ", isCreateSupported=" + isCreateSupported()
@@ -249,6 +249,10 @@ public class DocumentInfo implements Durable, Parcelable {
        return (flags & Document.FLAG_ARCHIVE) != 0;
        return (flags & Document.FLAG_ARCHIVE) != 0;
    }
    }


    public boolean isPartial() {
        return (flags & Document.FLAG_PARTIAL) != 0;
    }

    public boolean isContainer() {
    public boolean isContainer() {
        return isDirectory() || isArchive();
        return isDirectory() || isArchive();
    }
    }