mirror of
https://github.com/moparisthebest/k-9
synced 2024-11-23 18:02:15 -05:00
Use MIME type used for intent resolution in content provider
This commit is contained in:
parent
f87ab53b9b
commit
44ecf5d588
@ -51,11 +51,20 @@ public class AttachmentProvider extends ContentProvider {
|
||||
|
||||
|
||||
public static Uri getAttachmentUri(Account account, long id) {
|
||||
return getAttachmentUri(account.getUuid(), id, true);
|
||||
return CONTENT_URI.buildUpon()
|
||||
.appendPath(account.getUuid())
|
||||
.appendPath(Long.toString(id))
|
||||
.appendPath(FORMAT_RAW)
|
||||
.build();
|
||||
}
|
||||
|
||||
public static Uri getAttachmentUriForViewing(Account account, long id) {
|
||||
return getAttachmentUri(account.getUuid(), id, false);
|
||||
public static Uri getAttachmentUriForViewing(Account account, long id, String mimeType) {
|
||||
return CONTENT_URI.buildUpon()
|
||||
.appendPath(account.getUuid())
|
||||
.appendPath(Long.toString(id))
|
||||
.appendPath(FORMAT_VIEW)
|
||||
.appendPath(mimeType)
|
||||
.build();
|
||||
}
|
||||
|
||||
public static Uri getAttachmentThumbnailUri(Account account, long id, int width, int height) {
|
||||
@ -68,14 +77,6 @@ public class AttachmentProvider extends ContentProvider {
|
||||
.build();
|
||||
}
|
||||
|
||||
private static Uri getAttachmentUri(String db, long id, boolean raw) {
|
||||
return CONTENT_URI.buildUpon()
|
||||
.appendPath(db)
|
||||
.appendPath(Long.toString(id))
|
||||
.appendPath(raw ? FORMAT_RAW : FORMAT_VIEW)
|
||||
.build();
|
||||
}
|
||||
|
||||
public static void clear(Context context) {
|
||||
/*
|
||||
* We use the cache dir as a temporary directory (since Android doesn't give us one) so
|
||||
@ -146,8 +147,9 @@ public class AttachmentProvider extends ContentProvider {
|
||||
String dbName = segments.get(0);
|
||||
String id = segments.get(1);
|
||||
String format = segments.get(2);
|
||||
String mimeType = (segments.size() < 4) ? null : segments.get(3);
|
||||
|
||||
return getType(dbName, id, format);
|
||||
return getType(dbName, id, format, mimeType);
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -165,7 +167,7 @@ public class AttachmentProvider extends ContentProvider {
|
||||
|
||||
file = getThumbnailFile(getContext(), accountUuid, attachmentId);
|
||||
if (!file.exists()) {
|
||||
String type = getType(accountUuid, attachmentId, FORMAT_VIEW);
|
||||
String type = getType(accountUuid, attachmentId, FORMAT_VIEW, null);
|
||||
try {
|
||||
FileInputStream in = new FileInputStream(getFile(accountUuid, attachmentId));
|
||||
try {
|
||||
@ -258,7 +260,7 @@ public class AttachmentProvider extends ContentProvider {
|
||||
return null;
|
||||
}
|
||||
|
||||
private String getType(String dbName, String id, String format) {
|
||||
private String getType(String dbName, String id, String format, String mimeType) {
|
||||
String type;
|
||||
if (FORMAT_THUMBNAIL.equals(format)) {
|
||||
type = "image/png";
|
||||
@ -269,10 +271,9 @@ public class AttachmentProvider extends ContentProvider {
|
||||
final LocalStore localStore = LocalStore.getLocalInstance(account, K9.app);
|
||||
|
||||
AttachmentInfo attachmentInfo = localStore.getAttachmentInfo(id);
|
||||
if (FORMAT_VIEW.equals(format)) {
|
||||
type = MimeUtility.getMimeTypeForViewing(attachmentInfo.type, attachmentInfo.name);
|
||||
if (FORMAT_VIEW.equals(format) && mimeType != null) {
|
||||
type = mimeType;
|
||||
} else {
|
||||
// When accessing the "raw" message we deliver the original MIME type.
|
||||
type = attachmentInfo.type;
|
||||
}
|
||||
} catch (MessagingException e) {
|
||||
|
@ -256,16 +256,19 @@ public class AttachmentView extends FrameLayout implements OnClickListener, OnLo
|
||||
|
||||
private Intent constructViewIntent() {
|
||||
Intent intent;
|
||||
Uri uri = AttachmentProvider.getAttachmentUriForViewing(account, part.getAttachmentId());
|
||||
|
||||
Intent originalMimeTypeIntent = createViewIntentForContentUri(contentType, uri);
|
||||
Uri originalMimeTypeUri = AttachmentProvider.getAttachmentUriForViewing(account, part.getAttachmentId(),
|
||||
contentType);
|
||||
Intent originalMimeTypeIntent = createViewIntentForContentUri(contentType, originalMimeTypeUri);
|
||||
int originalMimeTypeActivitiesCount = getResolvedIntentActivitiesCount(originalMimeTypeIntent);
|
||||
|
||||
String inferredMimeType = MimeUtility.getMimeTypeByExtension(name);
|
||||
if (inferredMimeType.equals(contentType)) {
|
||||
intent = originalMimeTypeIntent;
|
||||
} else {
|
||||
Intent inferredMimeTypeIntent = createViewIntentForContentUri(inferredMimeType, uri);
|
||||
Uri inferredMimeTypeUri = AttachmentProvider.getAttachmentUriForViewing(account, part.getAttachmentId(),
|
||||
inferredMimeType);
|
||||
Intent inferredMimeTypeIntent = createViewIntentForContentUri(inferredMimeType, inferredMimeTypeUri);
|
||||
int inferredMimeTypeActivitiesCount = getResolvedIntentActivitiesCount(inferredMimeTypeIntent);
|
||||
|
||||
if (inferredMimeTypeActivitiesCount > originalMimeTypeActivitiesCount) {
|
||||
|
Loading…
Reference in New Issue
Block a user