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

Commit ab2516bf authored by Jorge Ruesga's avatar Jorge Ruesga Committed by Gerrit Code Review
Browse files

CMFM: Support for Intent.ACTION_SEND_MULTIPLE



This changes allows to send multiple files through selecting
multiple files. Add new "Send selection" global menu, that is shown
when user has some selected files, and all of them are files (send multiple
is not allowed for folders)

Change-Id: I1a889c1188803a6639433d4613fec2246d90fc9b
Signed-off-by: default avatarJorge Ruesga <jorge@ruesga.com>
parent 2f3c6029
Loading
Loading
Loading
Loading
+4 −0
Original line number Diff line number Diff line
@@ -62,6 +62,10 @@
      android:id="@+id/mnu_actions_create_link_global"
      android:showAsAction="ifRoom"
      android:title="@string/actions_menu_create_link"/>
    <item
      android:id="@+id/mnu_actions_send_selection"
      android:showAsAction="ifRoom"
      android:title="@string/actions_menu_send_selection"/>
    <item
      android:id="@+id/mnu_actions_add_to_bookmarks_current_folder"
      android:showAsAction="ifRoom"
+2 −0
Original line number Diff line number Diff line
@@ -499,6 +499,8 @@
  <string name="actions_menu_execute">Execute</string>
  <!-- Actions Dialog * Menu * Send -->
  <string name="actions_menu_send">Send</string>
  <!-- Actions Dialog * Menu * Send selection -->
  <string name="actions_menu_send_selection">Send selection</string>
  <!-- Actions Dialog * Menu * Compress -->
  <string name="actions_menu_compress">Compress</string>
  <!-- Actions Dialog * Menu * Extract -->
+33 −1
Original line number Diff line number Diff line
@@ -292,7 +292,19 @@ public class ActionsDialog implements OnItemClickListener, OnItemLongClickListen
                IntentsActionPolicy.sendFileSystemObject(
                        this.mContext, this.mFso, null, null);
                break;

            case R.id.mnu_actions_send_selection:
                if (this.mOnSelectionListener != null) {
                    List<FileSystemObject> selection =
                            this.mOnSelectionListener.onRequestSelectedFiles();
                    if (selection.size() == 1) {
                        IntentsActionPolicy.sendFileSystemObject(
                                this.mContext, selection.get(0), null, null);
                    } else {
                        IntentsActionPolicy.sendMultipleFileSystemObject(
                                this.mContext, selection, null, null);
                    }
                }
                break;

            // Paste selection
            case R.id.mnu_actions_paste_selection:
@@ -654,6 +666,26 @@ public class ActionsDialog implements OnItemClickListener, OnItemLongClickListen
            if (!this.mGlobal && !FileHelper.isSupportedUncompressedFile(this.mFso)) {
                menu.removeItem(R.id.mnu_actions_extract);
            }

            // Send multiple (only regular files)
            if (this.mGlobal) {
                if (selection == null || selection.size() == 0) {
                    menu.removeItem(R.id.mnu_actions_send_selection);
                } else {
                    boolean areAllFiles = true;
                    int cc = selection.size();
                    for (int i = 0; i < cc; i++) {
                        FileSystemObject fso = selection.get(i);
                        if (FileHelper.isDirectory(fso)) {
                            areAllFiles = false;
                            break;
                        }
                    }
                    if (!areAllFiles) {
                        menu.removeItem(R.id.mnu_actions_send_selection);
                    }
                }
            }
        }

        // Not allowed in search
+6 −1
Original line number Diff line number Diff line
@@ -472,7 +472,12 @@ public class AssociationsDialog implements OnItemClickListener {
        }

        if (intent != null) {
            // Capture security exceptions
            try {
                this.mContext.startActivity(intent);
            } catch (Exception e) {
                ExceptionUtil.translateException(this.mContext, e);
            }
        }
    }
}
+68 −1
Original line number Diff line number Diff line
@@ -18,10 +18,10 @@ package com.cyanogenmod.filemanager.ui.policy;

import android.content.ComponentName;
import android.content.Context;
import android.content.IntentFilter;
import android.content.DialogInterface.OnCancelListener;
import android.content.DialogInterface.OnDismissListener;
import android.content.Intent;
import android.content.IntentFilter;
import android.content.pm.PackageManager;
import android.content.pm.ResolveInfo;
import android.net.Uri;
@@ -157,6 +157,73 @@ public final class IntentsActionPolicy extends ActionsPolicy {
        }
    }

    /**
     * Method that sends a {@link FileSystemObject} with the default registered application
     * by the system, or ask the user for select a registered application.
     *
     * @param ctx The current context
     * @param fsos The file system objects
     * @param onCancelListener The cancel listener
     * @param onDismissListener The dismiss listener
     */
    public static void sendMultipleFileSystemObject(
            final Context ctx, final List<FileSystemObject> fsos,
            OnCancelListener onCancelListener, OnDismissListener onDismissListener) {
        try {
            // Create the intent to
            Intent intent = new Intent();
            intent.setAction(android.content.Intent.ACTION_SEND_MULTIPLE);
            intent.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION);

            // Create an array list of the uris to send
            ArrayList<Uri> uris = new ArrayList<Uri>();
            int cc = fsos.size();
            String lastMimeType = null;
            boolean sameMimeType = true;
            for (int i = 0; i < cc; i++) {
                FileSystemObject fso = fsos.get(i);

                // Folders are not allowed
                if (FileHelper.isDirectory(fso)) continue;

                // Check if we can use a unique mime/type
                String mimeType = MimeTypeHelper.getMimeType(ctx, fso);
                if (mimeType == null) {
                    sameMimeType = false;
                }
                if (sameMimeType &&
                    (mimeType != null && lastMimeType != null &&
                     mimeType.compareTo(lastMimeType) != 0)) {
                    sameMimeType = false;
                }
                lastMimeType = mimeType;

                // Add the uri
                uris.add(Uri.fromFile(new File(fso.getFullPath())));
            }
            if (sameMimeType) {
                intent.setType(lastMimeType);
            } else {
                intent.setType(MimeTypeHelper.ALL_MIME_TYPES);
            }
            intent.putParcelableArrayListExtra(Intent.EXTRA_STREAM, uris);

            // Resolve the intent
            resolveIntent(
                    ctx,
                    intent,
                    false,
                    null,
                    0,
                    R.string.associations_dialog_sendwith_title,
                    R.string.associations_dialog_sendwith_action,
                    false, onCancelListener, onDismissListener);

        } catch (Exception e) {
            ExceptionUtil.translateException(ctx, e);
        }
    }

    /**
     * Method that resolve
     *