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

Commit ed1b9f12 authored by Rohit Yengisetty's avatar Rohit Yengisetty Committed by Matt Garnes
Browse files

CM File Manager - Intent to open video files will have a playlist attached

In SearchActivity, intent to open video files will have an extra added
with the list of all videos in the search results.

Change-Id: Ibf48e74fd9f43ee3ac60575bad6c8f9fe1ec70ee
(cherry picked from commit 70b420be)
parent 8d768662
Loading
Loading
Loading
Loading
+2 −0
Original line number Diff line number Diff line
@@ -836,4 +836,6 @@
    <string name="welcome_title">Welcome</string>
    <!-- Welcome Dialog - Message -->
    <string name="welcome_msg">Welcome to the CyanogenMod file manager.\n\nThis app allows you to explore the file system and do operations that could break your device. To prevent damage, the app will start in a safe, low-privileged mode.\n\nYou can access the advanced, full-privileged mode via Settings. It\'s your responsibility to ensure that an operation doesn\'t break your system.\n\nThe CyanogenMod Team</string>

    <string name="activity_not_found_exception">Couldn\'t find an app to open this file</string>
</resources>
+58 −1
Original line number Diff line number Diff line
@@ -20,6 +20,7 @@ import android.app.ActionBar;
import android.app.Activity;
import android.app.AlertDialog;
import android.app.SearchManager;
import android.content.ActivityNotFoundException;
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.DialogInterface;
@@ -28,6 +29,7 @@ import android.content.IntentFilter;
import android.content.res.Configuration;
import android.graphics.Color;
import android.graphics.PorterDuff;
import android.net.Uri;
import android.os.Bundle;
import android.os.Parcelable;
import android.preference.PreferenceActivity;
@@ -1026,7 +1028,42 @@ public class SearchActivity extends Activity
                fso = symlink.getLinkRef();
            }

            // Open the file with the preferred registered app
            // special treatment for video files
            // all of the video files in the current search will also be sent as an extra in the
            // intent along with the item that was clicked
            MimeTypeCategory fileCategory = MimeTypeHelper.getCategoryFromExt(this,
                    FileHelper.getExtension(fso));
            if (fileCategory == MimeTypeCategory.VIDEO) {

                ArrayList<FileSystemObject> filteredList = filterSearchResults(fileCategory);
                ArrayList<Uri> uris = new ArrayList<Uri>(filteredList.size());

                for (FileSystemObject f : filteredList) {
                    uris.add(f.getFileUri());
                }

                Intent intent = new Intent();
                intent.setAction(Intent.ACTION_VIEW);
                intent.setDataAndType(fso.getFileUri(), MimeTypeHelper.getMimeType(this, fso));
                if (filteredList.size() > 1) {
                    intent.putParcelableArrayListExtra("EXTRA_FILE_LIST", uris);
                }

                if (DEBUG) {
                    Log.i(TAG, "video intent : " + intent);
                }

                try {
                    startActivity(intent);
                } catch(ActivityNotFoundException e) {
                    Log.e(TAG, "ActivityNotFoundException when opening a video file");
                    Toast.makeText(this, R.string.activity_not_found_exception, Toast.LENGTH_SHORT);
                }

                return;
            }

            // for other files, open them with their preferred registered app
            back(false, fso, false);

        } catch (Throwable ex) {
@@ -1034,6 +1071,26 @@ public class SearchActivity extends Activity
        }
    }

    /**
     * Returns a subset of the search results falling into the given category
     * @param category MimeTypeCategory
     * @return list of FileSystemObjects that
     */
    private ArrayList<FileSystemObject> filterSearchResults(MimeTypeCategory category) {
        ArrayList<FileSystemObject> filteredList = new ArrayList<FileSystemObject>();

        if (mAdapter.getCount() < 1) return filteredList;

        for (FileSystemObject fso : mAdapter.getFiles()) {
            if (MimeTypeHelper.getCategoryFromExt(this, FileHelper.getExtension(fso))
                    == category) {
                filteredList.add(fso);
            }
        }

        return filteredList;
    }

    /**
     * {@inheritDoc}
     */
+2 −0
Original line number Diff line number Diff line
@@ -49,6 +49,7 @@ import com.cyanogenmod.filemanager.util.SearchHelper;

import java.io.File;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Comparator;
import java.util.HashMap;
import java.util.List;
@@ -233,6 +234,7 @@ public class SearchResultAdapter extends ArrayAdapter<SearchResult> {
        addAll(mNewItems);
        sort(mSearchResultComparator);
        mOriginalList.addAll(mNewItems);    // cache files so enable mime type filtering later on
        Collections.sort(mOriginalList, mSearchResultComparator);

        // reset buffer
        mNewItems.clear();
+15 −0
Original line number Diff line number Diff line
@@ -16,6 +16,8 @@

package com.cyanogenmod.filemanager.model;

import android.content.ContentResolver;
import android.net.Uri;
import com.cyanogenmod.filemanager.R;
import com.cyanogenmod.filemanager.util.FileHelper;

@@ -335,6 +337,19 @@ public abstract class FileSystemObject implements Serializable, Comparable<FileS
        return this.mParent + File.separator + this.mName;
    }

    /**
     * creates a file uri that references this FileSystemObject
     * @return a file uri
     */
    public Uri getFileUri() {
        Uri uri = new Uri.Builder()
                .scheme(ContentResolver.SCHEME_FILE)
                .path(getFullPath())
                .build();

        return uri;
    }

    /**
     * {@inheritDoc}
     */