mirror of
https://github.com/FossifyOrg/Gallery.git
synced 2025-01-18 06:17:59 +01:00
allow sharing multiple items at once
This commit is contained in:
parent
427e44f3bd
commit
cdc07b0bff
4 changed files with 73 additions and 19 deletions
|
@ -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();
|
||||
|
|
|
@ -183,6 +183,43 @@ public class MediaActivity extends SimpleActivity
|
|||
return false;
|
||||
}
|
||||
|
||||
private void shareMedia() {
|
||||
final List<Medium> selectedMedia = getSelectedMedia();
|
||||
if (selectedMedia.size() <= 1) {
|
||||
Utils.shareMedium(selectedMedia.get(0), this);
|
||||
} else {
|
||||
shareMedia(selectedMedia);
|
||||
}
|
||||
}
|
||||
|
||||
private void shareMedia(List<Medium> 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<Uri> 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<Medium> getSelectedMedia() {
|
||||
final List<Medium> 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<Bitmap>() {
|
||||
Glide.with(this).
|
||||
load(new File(curItemPath)).
|
||||
asBitmap().
|
||||
override((int) (wantedWidth * ratio), wantedHeight).
|
||||
fitCenter().
|
||||
into(new SimpleTarget<Bitmap>() {
|
||||
@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();
|
||||
|
|
|
@ -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() {
|
||||
|
|
|
@ -1,6 +1,11 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<menu xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
xmlns:app="http://schemas.android.com/apk/res-auto">
|
||||
<item
|
||||
android:id="@+id/cab_share"
|
||||
android:icon="@mipmap/share"
|
||||
android:title="@string/share"
|
||||
app:showAsAction="ifRoom"/>
|
||||
<item
|
||||
android:id="@+id/cab_delete"
|
||||
android:icon="@mipmap/delete"
|
||||
|
|
Loading…
Reference in a new issue