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

Commit d071895e authored by Steve McKay's avatar Steve McKay
Browse files

Move share impl into files ActionHandler.

Don't include partial files when sharing.
Add test coverage.

Filter documents as list is loaded for sharing, eliminating need to copy.
Rename MimePredicate to MimeTypes and drop the Predicate impl (since nobody was using it).
    Move additional mime type functioanlity to the class.

Input DocumentsAdapter.Environment and LoaderCallbacks in inner classes.
    This reduces the number of public methods hanging off of DirectoryFragment.
In DirFragment normalize access to context/activity and State.

Added an IntentAssert class with some handy assert methods.

Addressed xutan@'s comment from last CL.

Add friendly support for selecting documents in TestEnv.

Change-Id: I55ea78ab5bef3a2b2644f6e0a3384adeaba78599
parent bd9f05aa
Loading
Loading
Loading
Loading
+5 −0
Original line number Diff line number Diff line
@@ -155,6 +155,11 @@ public abstract class AbstractActionHandler<T extends Activity & CommonAddons>
        throw new UnsupportedOperationException("Delete not supported!");
    }

    @Override
    public void shareSelectedDocuments() {
        throw new UnsupportedOperationException("Share not supported!");
    }

    @Override
    public final void loadDocument(Uri uri) {
        new OpenUriForViewTask<>(mActivity, mState, mRoots, mDocs, uri)
+2 −0
Original line number Diff line number Diff line
@@ -67,6 +67,8 @@ public interface ActionHandler {

    void deleteSelectedDocuments();

    void shareSelectedDocuments();

    /**
     * Called when initial activity setup is complete. Implementations
     * should override this method to set the initial location of the
+2 −2
Original line number Diff line number Diff line
@@ -55,13 +55,13 @@ public class FilteringCursorWrapper extends AbstractCursor {
        while (cursor.moveToNext() && mCount < count) {
            final String mimeType = getCursorString(cursor, Document.COLUMN_MIME_TYPE);
            final long lastModified = getCursorLong(cursor, Document.COLUMN_LAST_MODIFIED);
            if (rejectMimes != null && MimePredicate.mimeMatches(rejectMimes, mimeType)) {
            if (rejectMimes != null && MimeTypes.mimeMatches(rejectMimes, mimeType)) {
                continue;
            }
            if (lastModified < rejectBefore) {
                continue;
            }
            if (MimePredicate.mimeMatches(acceptMimes, mimeType)) {
            if (MimeTypes.mimeMatches(acceptMimes, mimeType)) {
                mPosition[mCount++] = cursor.getPosition();
            }
        }
+25 −16
Original line number Diff line number Diff line
/*
 * Copyright (C) 2013 The Android Open Source Project
 * Copyright (C) 2016 The Android Open Source Project
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
@@ -13,16 +13,16 @@
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package com.android.documentsui.base;

import android.annotation.Nullable;
import android.provider.DocumentsContract.Document;

import com.android.internal.util.Predicate;
import java.util.List;

public final class MimeTypes {

public class MimePredicate implements Predicate<DocumentInfo> {
    private final String[] mFilters;
    private MimeTypes() {}

    private static final String APK_TYPE = "application/vnd.android.package-archive";
    /**
@@ -31,19 +31,28 @@ public class MimePredicate implements Predicate<DocumentInfo> {
     */
    public static final String[] VISUAL_MIMES = new String[] { "image/*", "video/*" };

    public MimePredicate(String[] filters) {
        mFilters = filters;
    public static String findCommonMimeType(List<String> mimeTypes) {
        String[] commonType = mimeTypes.get(0).split("/");
        if (commonType.length != 2) {
            return "*/*";
        }

    @Override
    public boolean apply(DocumentInfo doc) {
        if (doc.isDirectory()) {
            return true;
        for (int i = 1; i < mimeTypes.size(); i++) {
            String[] type = mimeTypes.get(i).split("/");
            if (type.length != 2) continue;

            if (!commonType[1].equals(type[1])) {
                commonType[1] = "*";
            }
        if (mimeMatches(mFilters, doc.mimeType)) {
            return true;

            if (!commonType[0].equals(type[0])) {
                commonType[0] = "*";
                commonType[1] = "*";
                break;
            }
        return false;
        }

        return commonType[0] + "/" + commonType[1];
    }

    public static boolean mimeMatches(String[] filters, String[] tests) {
+228 −278

File changed.

Preview size limit exceeded, changes collapsed.

Loading