diff --git a/app/src/main/java/com/simplemobiletools/gallery/Utils.java b/app/src/main/java/com/simplemobiletools/gallery/Utils.java index 20cec3c1b..99cd16ed0 100644 --- a/app/src/main/java/com/simplemobiletools/gallery/Utils.java +++ b/app/src/main/java/com/simplemobiletools/gallery/Utils.java @@ -3,8 +3,10 @@ package com.simplemobiletools.gallery; import android.Manifest; import android.app.Activity; import android.content.Context; +import android.content.Intent; import android.content.pm.PackageManager; import android.content.res.Resources; +import android.net.Uri; import android.os.Build; import android.support.v4.content.ContextCompat; import android.support.v7.app.ActionBar; @@ -19,6 +21,10 @@ import android.view.Window; import android.webkit.MimeTypeMap; import android.widget.Toast; +import com.simplemobiletools.gallery.models.Medium; + +import java.io.File; + public class Utils { public static String getFilename(final String path) { return path.substring(path.lastIndexOf("/") + 1); @@ -89,6 +95,21 @@ public class Utils { return ""; } + public static void shareMedium(Medium medium, Activity activity) { + final String shareTitle = activity.getResources().getString(R.string.share_via); + final Intent intent = new Intent(); + final File file = new File(medium.getPath()); + final Uri uri = Uri.fromFile(file); + intent.setAction(Intent.ACTION_SEND); + intent.putExtra(Intent.EXTRA_STREAM, uri); + if (medium.getIsVideo()) { + intent.setType("video/*"); + } else { + intent.setType("image/*"); + } + activity.startActivity(Intent.createChooser(intent, shareTitle)); + } + public static void showSystemUI(ActionBar actionbar, Window window) { if (actionbar != null) actionbar.show(); diff --git a/app/src/main/java/com/simplemobiletools/gallery/activities/MediaActivity.java b/app/src/main/java/com/simplemobiletools/gallery/activities/MediaActivity.java index a687bf40c..bbc8ec51a 100644 --- a/app/src/main/java/com/simplemobiletools/gallery/activities/MediaActivity.java +++ b/app/src/main/java/com/simplemobiletools/gallery/activities/MediaActivity.java @@ -183,6 +183,43 @@ public class MediaActivity extends SimpleActivity return false; } + private void shareMedia() { + final List selectedMedia = getSelectedMedia(); + if (selectedMedia.size() <= 1) { + Utils.shareMedium(selectedMedia.get(0), this); + } else { + shareMedia(selectedMedia); + } + } + + private void shareMedia(List media) { + final String shareTitle = getResources().getString(R.string.share_via); + final Intent intent = new Intent(); + intent.setAction(Intent.ACTION_SEND_MULTIPLE); + intent.setType("image/* video/*"); + final ArrayList uris = new ArrayList<>(media.size()); + for (Medium medium : media) { + final File file = new File(medium.getPath()); + uris.add(Uri.fromFile(file)); + } + + intent.putParcelableArrayListExtra(Intent.EXTRA_STREAM, uris); + startActivity(Intent.createChooser(intent, shareTitle)); + } + + private List getSelectedMedia() { + final List media = new ArrayList<>(); + final SparseBooleanArray items = mGridView.getCheckedItemPositions(); + final int cnt = items.size(); + for (int i = 0; i < cnt; i++) { + if (items.valueAt(i)) { + final int id = items.keyAt(i); + media.add(mMedia.get(id)); + } + } + return media; + } + private void prepareForDeleting() { Utils.showToast(this, R.string.deleting); final SparseBooleanArray items = mGridView.getCheckedItemPositions(); @@ -277,12 +314,12 @@ public class MediaActivity extends SimpleActivity final int wantedWidth = getWallpaperDesiredMinimumWidth(); final int wantedHeight = getWallpaperDesiredMinimumHeight(); final float ratio = (float) wantedWidth / wantedHeight; - Glide.with(this) - .load(new File(curItemPath)) - .asBitmap() - .override((int) (wantedWidth * ratio), wantedHeight) - .fitCenter() - .into(new SimpleTarget() { + Glide.with(this). + load(new File(curItemPath)). + asBitmap(). + override((int) (wantedWidth * ratio), wantedHeight). + fitCenter(). + into(new SimpleTarget() { @Override public void onResourceReady(Bitmap bitmap, GlideAnimation anim) { try { @@ -335,6 +372,9 @@ public class MediaActivity extends SimpleActivity @Override public boolean onActionItemClicked(ActionMode mode, MenuItem item) { switch (item.getItemId()) { + case R.id.cab_share: + shareMedia(); + return true; case R.id.cab_delete: prepareForDeleting(); mode.finish(); diff --git a/app/src/main/java/com/simplemobiletools/gallery/activities/ViewPagerActivity.java b/app/src/main/java/com/simplemobiletools/gallery/activities/ViewPagerActivity.java index bcd50eb17..094115d16 100644 --- a/app/src/main/java/com/simplemobiletools/gallery/activities/ViewPagerActivity.java +++ b/app/src/main/java/com/simplemobiletools/gallery/activities/ViewPagerActivity.java @@ -1,6 +1,5 @@ package com.simplemobiletools.gallery.activities; -import android.content.Intent; import android.content.res.Configuration; import android.content.res.Resources; import android.database.Cursor; @@ -155,19 +154,8 @@ public class ViewPagerActivity extends SimpleActivity } private void shareMedium() { - final String shareTitle = getResources().getString(R.string.share_via); - final Intent sendIntent = new Intent(); final Medium medium = getCurrentMedium(); - final File file = getCurrentFile(); - final Uri uri = Uri.fromFile(file); - sendIntent.setAction(Intent.ACTION_SEND); - sendIntent.putExtra(Intent.EXTRA_STREAM, uri); - if (medium.getIsVideo()) { - sendIntent.setType("video/*"); - } else { - sendIntent.setType("image/*"); - } - startActivity(Intent.createChooser(sendIntent, shareTitle)); + Utils.shareMedium(medium, this); } private void notifyDeletion() { diff --git a/app/src/main/res/menu/media_menu.xml b/app/src/main/res/menu/media_menu.xml index 6e774a7c3..71f9bc8dc 100644 --- a/app/src/main/res/menu/media_menu.xml +++ b/app/src/main/res/menu/media_menu.xml @@ -1,6 +1,11 @@ +