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

Commit 48e3eea0 authored by Tomasz Mikolajewski's avatar Tomasz Mikolajewski Committed by Android (Google) Code Review
Browse files

Merge "Clean up sharing virtual files." into nyc-andromeda-dev

parents 265d36fc 1abcfd11
Loading
Loading
Loading
Loading
+21 −8
Original line number Original line Diff line number Diff line
@@ -56,7 +56,7 @@ public class Model {
    /**
    /**
     * Filter that passes (returns true) all non-partial files and non-archived files.
     * Filter that passes (returns true) all non-partial files and non-archived files.
     */
     */
    public static final Predicate<Cursor> NO_PARTIAL_NOR_ARCHIVED_FILE_FILTER = (Cursor c) -> {
    public static final Predicate<Cursor> SHARABLE_FILE_FILTER = (Cursor c) -> {
        int flags = getCursorInt(c, Document.COLUMN_FLAGS);
        int flags = getCursorInt(c, Document.COLUMN_FLAGS);
        String authority = getCursorString(c, RootCursorWrapper.COLUMN_AUTHORITY);
        String authority = getCursorString(c, RootCursorWrapper.COLUMN_AUTHORITY);
        return (flags & Document.FLAG_PARTIAL) == 0
        return (flags & Document.FLAG_PARTIAL) == 0
@@ -232,29 +232,42 @@ public class Model {
        final int size = (selection != null) ? selection.size() : 0;
        final int size = (selection != null) ? selection.size() : 0;


        final List<DocumentInfo> docs =  new ArrayList<>(size);
        final List<DocumentInfo> docs =  new ArrayList<>(size);
        DocumentInfo doc;
        for (String modelId: selection) {
        for (String modelId: selection) {
            loadDocument(docs, modelId, filter);
            doc = loadDocument(modelId, filter);
            if (doc != null) {
                docs.add(doc);
            }
        }
        }
        return docs;
        return docs;
    }
    }


    public boolean hasDocuments(Selection selection, Predicate<Cursor> filter) {
        for (String modelId: selection) {
            if (loadDocument(modelId, filter) != null) {
                return true;
            }
        }
        return false;
    }

    /**
    /**
     * @param docs
     * @return DocumentInfo, or null. If filter returns false, null will be returned.
     * @return DocumentInfo, or null. If filter returns false, null will be returned.
     */
     */
    private void loadDocument(
    private @Nullable DocumentInfo loadDocument(String modelId, Predicate<Cursor> filter) {
            List<DocumentInfo> docs, String modelId, Predicate<Cursor> filter) {
        final Cursor cursor = getItem(modelId);
        final Cursor cursor = getItem(modelId);


        if (cursor == null) {
        if (cursor == null) {
            Log.w(TAG, "Unable to obtain document for modelId: " + modelId);
            Log.w(TAG, "Unable to obtain document for modelId: " + modelId);
            return null;
        }
        }


        if (filter.test(cursor)) {
        if (filter.test(cursor)) {
            docs.add(DocumentInfo.fromDirectoryCursor(cursor));
            return DocumentInfo.fromDirectoryCursor(cursor);
        } else {
            if (VERBOSE) Log.v(TAG, "Filtered document from results: " + modelId);
        }
        }

        if (VERBOSE) Log.v(TAG, "Filtered out document from results: " + modelId);
        return null;
    }
    }


    public Uri getItemUri(String modelId) {
    public Uri getItemUri(String modelId) {
+3 −5
Original line number Original line Diff line number Diff line
@@ -290,10 +290,7 @@ public class ActionHandler<T extends Activity & Addons> extends AbstractActionHa


        // Model must be accessed in UI thread, since underlying cursor is not threadsafe.
        // Model must be accessed in UI thread, since underlying cursor is not threadsafe.
        List<DocumentInfo> docs =
        List<DocumentInfo> docs =
                mScope.model.loadDocuments(selection, Model.NO_PARTIAL_NOR_ARCHIVED_FILE_FILTER);
                mScope.model.loadDocuments(selection, Model.SHARABLE_FILE_FILTER);

        List<DocumentInfo> virtualDocs =
                mScope.model.loadDocuments(selection, Model.VIRTUAL_DOCUMENT_FILTER);


        Intent intent;
        Intent intent;


@@ -323,7 +320,8 @@ public class ActionHandler<T extends Activity & Addons> extends AbstractActionHa


        intent.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION);
        intent.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION);
        intent.addCategory(Intent.CATEGORY_DEFAULT);
        intent.addCategory(Intent.CATEGORY_DEFAULT);
        if (virtualDocs.size() > 0) {

        if (mScope.model.hasDocuments(selection, Model.VIRTUAL_DOCUMENT_FILTER)) {
            intent.addCategory(Intent.CATEGORY_TYPED_OPENABLE);
            intent.addCategory(Intent.CATEGORY_TYPED_OPENABLE);
        }
        }