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

Commit be137de2 authored by Danny Baumann's avatar Danny Baumann Committed by Jorge Ruesga
Browse files

Fall back to showing all files for unknown mime types.

It's better to let the user select among all files than not presenting
him any files at all.

Patchset 2: simplify the logic
Patchset 3: Revert to patchset 1. Verify mime type regexp name instead of mime type name.

Change-Id: I372f00cccce1c9bb69d5d2668bb33c7882580e08
parent b978c844
Loading
Loading
Loading
Loading
+5 −0
Original line number Diff line number Diff line
@@ -58,6 +58,7 @@ import com.cyanogenmod.filemanager.ui.widgets.NavigationView.OnFilePickedListene
import com.cyanogenmod.filemanager.util.DialogHelper;
import com.cyanogenmod.filemanager.util.ExceptionUtil;
import com.cyanogenmod.filemanager.util.FileHelper;
import com.cyanogenmod.filemanager.util.MimeTypeHelper;
import com.cyanogenmod.filemanager.util.StorageHelper;

import java.io.File;
@@ -184,6 +185,10 @@ public class PickerActivity extends Activity
        String mimeType = getIntent().getType();
        Log.d(TAG, "PickerActivity. type: " + String.valueOf(mimeType)); //$NON-NLS-1$
        if (mimeType != null) {
            if (!MimeTypeHelper.isMimeTypeKnown(this, mimeType)) {
                Log.i(TAG, "Mime type " + mimeType + " unknown, falling back to wildcard.");
                mimeType = MimeTypeHelper.ALL_MIME_TYPES;
            }
            restrictions.put(DisplayRestrictions.MIME_TYPE_RESTRICTION, mimeType);
        }
        // Other restrictions
+28 −0
Original line number Diff line number Diff line
@@ -191,6 +191,34 @@ public final class MimeTypeHelper {
        super();
    }

    /**
     * Method that checks whether a certain mime type is known to
     * the application.
     *
     * @param context The current context
     * @param mimeType The mime type to be checked
     * @return true if mime type is known, false otherwise
     */
    public static final boolean isMimeTypeKnown(Context context, String mimeType) {
        //Ensure that mime types are loaded
        if (sMimeTypes == null) {
            loadMimeTypes(context);
        }

        if (mimeType == null) {
            return false;
        }

        for (MimeTypeInfo info : sMimeTypes.values()) {
            String mimeTypeRegExp = convertToRegExp(mimeType);
            if (info.mMimeType.matches(mimeTypeRegExp)) {
                return true;
            }
        }

        return false;
    }

    /**
     * Method that returns the associated mime/type icon resource identifier of
     * the {@link FileSystemObject}.