Skip to content

Commit

Permalink
Merge pull request #20138 from wordpress-mobile/fix/sharing-image-reg…
Browse files Browse the repository at this point in the history
…ression

Fix sharing image regression and add support for heic and heif files
  • Loading branch information
Gerardo Pacheco authored Feb 12, 2024
2 parents db61f3b + 6c13ba8 commit 9972cb5
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import android.content.SharedPreferences;
import android.net.Uri;
import android.os.Bundle;
import android.text.TextUtils;

import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
Expand All @@ -21,6 +22,8 @@
import org.wordpress.android.ui.main.WPMainActivity;
import org.wordpress.android.ui.media.MediaBrowserActivity;
import org.wordpress.android.ui.media.MediaBrowserType;
import org.wordpress.android.util.AppLog;
import org.wordpress.android.util.AppLog.T;
import org.wordpress.android.util.FluxCUtils;
import org.wordpress.android.util.MediaUtils;
import org.wordpress.android.util.ToastUtils;
Expand Down Expand Up @@ -94,23 +97,33 @@ private void refreshContent() {
}

private void downloadExternalMedia() {
if (Intent.ACTION_SEND_MULTIPLE.equals(getIntent().getAction())) {
ArrayList<Uri> externalUris = getIntent().getParcelableArrayListExtra((Intent.EXTRA_STREAM));
for (Uri uri : externalUris) {
if (uri != null && isAllowedMediaType(uri)) {
mLocalMediaUris.add(MediaUtils.downloadExternalMedia(this, uri));
try {
if (Intent.ACTION_SEND_MULTIPLE.equals(getIntent().getAction())) {
ArrayList<Uri> externalUris = getIntent().getParcelableArrayListExtra((Intent.EXTRA_STREAM));
for (Uri uri : externalUris) {
if (uri != null && isAllowedMediaType(uri)) {
mLocalMediaUris.add(MediaUtils.downloadExternalMedia(this, uri));
}
}
} else if (Intent.ACTION_SEND.equals(getIntent().getAction())) {
Uri externalUri = getIntent().getParcelableExtra(Intent.EXTRA_STREAM);
if (externalUri != null && isAllowedMediaType(externalUri)) {
mLocalMediaUris.add(MediaUtils.downloadExternalMedia(this, externalUri));
}
}
} else if (Intent.ACTION_SEND.equals(getIntent().getAction())) {
Uri externalUri = getIntent().getParcelableExtra(Intent.EXTRA_STREAM);
if (externalUri != null && isAllowedMediaType(externalUri)) {
mLocalMediaUris.add(MediaUtils.downloadExternalMedia(this, externalUri));
}
} catch (Exception e) {
ToastUtils.showToast(this,
R.string.error_media_could_not_share_media_from_device, ToastUtils.Duration.LONG);
AppLog.e(T.MEDIA, "ShareIntentReceiver failed to download media ", e);
}
}

private boolean isAllowedMediaType(@NonNull Uri uri) {
String filePath = MediaUtils.getRealPathFromURI(this, uri);
// For cases when getRealPathFromURI returns an empty string
if (TextUtils.isEmpty(filePath)) {
filePath = String.valueOf(uri);
}
return MediaUtils.isValidImage(filePath) || MediaUtils.isVideo(filePath);
}

Expand Down
2 changes: 2 additions & 0 deletions WordPress/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -2006,6 +2006,8 @@
<string name="error_media_file_type_not_allowed">This file type is not allowed</string>
<string name="error_media_unexpected_empty_media_file_path">Unexpected empty file path for Media</string>
<string name="error_media_could_not_find_media_in_path">Could not find media file in path</string>
<string name="error_media_could_not_share_media_from_device">Unable to load the media for sharing. Please check the app\'s permissions
or use the app\'s media library.</string>
<string name="error_media_path_is_directory">The specified path is a directory instead of a Media file</string>
<string name="error_media_upload_failed_for_reason">Media upload failed.\n%1$s</string>
<string name="error_media_xmlrpc_not_allowed">Your action is not allowed</string>
Expand Down
2 changes: 1 addition & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ ext {
wordPressFluxCVersion = '2.64.0'
wordPressLoginVersion = '1.12.0'
wordPressPersistentEditTextVersion = '1.0.2'
wordPressUtilsVersion = '3.12.0'
wordPressUtilsVersion = '3.13.0'
indexosMediaForMobileVersion = '43a9026f0973a2f0a74fa813132f6a16f7499c3a'

// debug
Expand Down

0 comments on commit 9972cb5

Please sign in to comment.