Fixed shared URI types

master
M66B 3 months ago
parent 614bbc578c
commit b724113798

@ -259,7 +259,7 @@ public class ActivityCompose extends ActivityBase implements FragmentManager.OnB
Uri stream = (item == null ? null : item.getUri());
if (stream != null)
uris.add(new UriType(stream,
description != null && i < description.getMimeTypeCount() ? description.getMimeType(i) : null));
description != null && i < description.getMimeTypeCount() ? description.getMimeType(i) : null, this));
}
if (intent.hasExtra(Intent.EXTRA_STREAM)) {
@ -277,7 +277,7 @@ public class ActivityCompose extends ActivityBase implements FragmentManager.OnB
break;
}
if (!found)
uris.add(new UriType(stream, streams.size() == 1 ? intent.getType() : null));
uris.add(new UriType(stream, streams.size() == 1 ? intent.getType() : null, this));
}
}
}

@ -580,7 +580,7 @@ public class EntityAnswer implements Serializable {
for (Uri file : attachments)
try {
EntityAttachment attachment = new EntityAttachment();
Helper.UriInfo info = Helper.getInfo(new UriType(file, null), context);
Helper.UriInfo info = Helper.getInfo(new UriType(file, null, null), context);
attachment.message = id;
attachment.sequence = db.attachment().getAttachmentSequence(id) + 1;

@ -251,15 +251,18 @@ public class EntityAttachment {
}
String getMimeType() {
if (encryption != null)
return type;
return getMimeType(type, name);
}
static String getMimeType(String type, String name) {
// Try to guess a better content type
// For example, sometimes PDF files are sent as application/octet-stream
// https://android.googlesource.com/platform/libcore/+/refs/tags/android-9.0.0_r49/luni/src/main/java/libcore/net/MimeUtils.java
// https://docs.microsoft.com/en-us/archive/blogs/vsofficedeveloper/office-2007-file-format-mime-types-for-http-content-streaming-2
if (encryption != null)
return type;
if ("audio/mid".equals(type))
return "audio/midi";

@ -393,7 +393,7 @@ public class FragmentCompose extends FragmentBase {
pickImages =
registerForActivityResult(new ActivityResultContracts.PickMultipleVisualMedia(max), uris -> {
if (!uris.isEmpty())
onAddImageFile(UriType.getList(uris), false);
onAddImageFile(UriType.getList(uris, getContext()), false);
});
}
@ -655,7 +655,7 @@ public class FragmentCompose extends FragmentBase {
int resize = prefs.getInt("resize", FragmentCompose.REDUCED_IMAGE_SIZE);
boolean resize_width_only = prefs.getBoolean("resize_width_only", false);
onAddAttachment(
Arrays.asList(new UriType(uri, type)),
Arrays.asList(new UriType(uri, type, etBody.getContext())),
true,
resize_paste ? resize : 0,
resize_width_only,
@ -3382,7 +3382,7 @@ public class FragmentCompose extends FragmentBase {
case REQUEST_TAKE_PHOTO:
if (resultCode == RESULT_OK) {
if (photoURI != null)
onAddImageFile(Arrays.asList(new UriType(photoURI, null)), false);
onAddImageFile(Arrays.asList(new UriType(photoURI, null, null)), false);
}
break;
case REQUEST_ATTACHMENT:
@ -3944,7 +3944,7 @@ public class FragmentCompose extends FragmentBase {
if (clipData == null) {
Uri uri = data.getData();
if (uri != null)
result.add(new UriType(uri, data.getType()));
result.add(new UriType(uri, data.getType(), getContext()));
} else {
ClipDescription description = clipData.getDescription();
for (int i = 0; i < clipData.getItemCount(); i++) {
@ -3952,7 +3952,8 @@ public class FragmentCompose extends FragmentBase {
Uri uri = item.getUri();
if (uri != null)
result.add(new UriType(uri,
description != null && i < description.getMimeTypeCount() ? description.getMimeType(i) : null));
description != null && i < description.getMimeTypeCount() ? description.getMimeType(i) : null,
getContext()));
}
}
@ -3962,7 +3963,7 @@ public class FragmentCompose extends FragmentBase {
if (result.size() == 0 && data.hasExtra("media-uri-list"))
try {
List<Uri> uris = data.getParcelableArrayListExtra("media-uri-list");
result.addAll(UriType.getList(uris));
result.addAll(UriType.getList(uris, getContext()));
} catch (Throwable ex) {
Log.e(ex);
}

@ -19,6 +19,7 @@ package eu.faircode.email;
Copyright 2018-2025 by Marcel Bokhorst (M66B)
*/
import android.content.Context;
import android.net.Uri;
import android.os.Parcel;
import android.os.Parcelable;
@ -38,10 +39,15 @@ public class UriType implements Parcelable {
this.type = in.readString();
}
public UriType(Uri uri, String type) {
public UriType(Uri uri, String type, Context context) {
this.uri = uri;
if (!TextUtils.isEmpty(type))
this.type = type;
if (context != null) {
Helper.UriInfo info = Helper.getInfo(this, context);
this.type = EntityAttachment.getMimeType(type, info.name);
}
}
public Uri getUri() {
@ -75,10 +81,11 @@ public class UriType implements Parcelable {
}
};
public static List<UriType> getList(List<Uri> uris) {
public static List<UriType> getList(List<Uri> uris, Context context) {
List<UriType> result = new ArrayList<>();
if (uris != null)
for (Uri uri : uris)
result.add(new UriType(uri, null));
result.add(new UriType(uri, null, context));
return result;
}

Loading…
Cancel
Save