diff options
Diffstat (limited to '')
7 files changed, 33 insertions, 6 deletions
diff --git a/src/main/java/de/pixart/messenger/persistance/FileBackend.java b/src/main/java/de/pixart/messenger/persistance/FileBackend.java index 5efadd3ff..2703f0538 100644 --- a/src/main/java/de/pixart/messenger/persistance/FileBackend.java +++ b/src/main/java/de/pixart/messenger/persistance/FileBackend.java @@ -371,7 +371,7 @@ public class FileBackend { } public void copyFileToPrivateStorage(Message message, Uri uri, String type) throws FileCopyException { - String mime = type != null ? type : MimeUtils.guessMimeTypeFromUri(mXmppConnectionService, uri); + String mime = MimeUtils.guessMimeTypeFromUriAndMime(mXmppConnectionService, uri, type); Log.d(Config.LOGTAG, "copy " + uri.toString() + " to private storage (mime=" + mime + ")"); String extension = MimeUtils.guessExtensionFromMimeType(mime); if (extension == null) { diff --git a/src/main/java/de/pixart/messenger/services/AttachFileToConversationRunnable.java b/src/main/java/de/pixart/messenger/services/AttachFileToConversationRunnable.java index d2f623c45..192d9221d 100644 --- a/src/main/java/de/pixart/messenger/services/AttachFileToConversationRunnable.java +++ b/src/main/java/de/pixart/messenger/services/AttachFileToConversationRunnable.java @@ -44,7 +44,7 @@ public class AttachFileToConversationRunnable implements Runnable, MediaTranscod this.mXmppConnectionService = xmppConnectionService; this.message = message; this.callback = callback; - final String mimeType = type != null ? type : MimeUtils.guessMimeTypeFromUri(mXmppConnectionService, uri); + final String mimeType = MimeUtils.guessMimeTypeFromUriAndMime(mXmppConnectionService, uri, type); final int autoAcceptFileSize = Config.FILE_SIZE; this.originalFileSize = FileBackend.getFileSize(mXmppConnectionService, uri); this.isVideoMessage = !getFileBackend().useFileAsIs(uri) diff --git a/src/main/java/de/pixart/messenger/services/MessageArchiveService.java b/src/main/java/de/pixart/messenger/services/MessageArchiveService.java index d9394d4dc..c9c0c0672 100644 --- a/src/main/java/de/pixart/messenger/services/MessageArchiveService.java +++ b/src/main/java/de/pixart/messenger/services/MessageArchiveService.java @@ -338,6 +338,7 @@ public class MessageArchiveService implements OnAdvancedStreamFeaturesLoaded { query.getConversation().setFirstMamReference(first == null ? null : first.getContent()); } if (complete || relevant == null || abort) { + //TODO: FIX done logic to look at complete. using count is probably unreliable because it can be ommited and doesn’t work with paging. boolean done; if (query.isCatchup()) { done = false; diff --git a/src/main/java/de/pixart/messenger/ui/adapter/MediaAdapter.java b/src/main/java/de/pixart/messenger/ui/adapter/MediaAdapter.java index 0472c6d11..8b8c05d05 100644 --- a/src/main/java/de/pixart/messenger/ui/adapter/MediaAdapter.java +++ b/src/main/java/de/pixart/messenger/ui/adapter/MediaAdapter.java @@ -78,6 +78,8 @@ public class MediaAdapter extends RecyclerView.Adapter<MediaAdapter.MediaViewHol attr = R.attr.media_preview_app; } else if (mime.equals("application/zip") || mime.equals("application/rar")) { attr = R.attr.media_preview_archive; + } else if (mime.equals("application/epub+zip") || mime.equals("application/vnd.amazon.mobi8-ebook")) { + attr = R.attr.media_preview_ebook; } else if (DOCUMENT_MIMES.contains(mime)) { attr = R.attr.media_preview_document; } else { diff --git a/src/main/java/de/pixart/messenger/ui/util/Attachment.java b/src/main/java/de/pixart/messenger/ui/util/Attachment.java index 96159c1bd..b63510209 100644 --- a/src/main/java/de/pixart/messenger/ui/util/Attachment.java +++ b/src/main/java/de/pixart/messenger/ui/util/Attachment.java @@ -115,13 +115,13 @@ public class Attachment implements Parcelable { for (int i = 0; i < clipData.getItemCount(); ++i) { final Uri uri = clipData.getItemAt(i).getUri(); Log.d(Config.LOGTAG, "uri=" + uri + " contentType=" + contentType); - final String mime = contentType != null ? contentType : MimeUtils.guessMimeTypeFromUri(context, uri); + final String mime = MimeUtils.guessMimeTypeFromUriAndMime(context, uri, contentType); Log.d(Config.LOGTAG, "mime=" + mime); uris.add(new Attachment(uri, type, mime)); } } } else { - final String mime = contentType != null ? contentType : MimeUtils.guessMimeTypeFromUri(context, data); + final String mime = MimeUtils.guessMimeTypeFromUriAndMime(context, data, contentType); uris.add(new Attachment(data, type, mime)); } return uris; diff --git a/src/main/java/de/pixart/messenger/utils/MimeUtils.java b/src/main/java/de/pixart/messenger/utils/MimeUtils.java index e485dc88f..fc2484a51 100644 --- a/src/main/java/de/pixart/messenger/utils/MimeUtils.java +++ b/src/main/java/de/pixart/messenger/utils/MimeUtils.java @@ -17,6 +17,7 @@ package de.pixart.messenger.utils; import android.content.Context; import android.net.Uri; +import android.util.Log; import java.io.File; import java.io.FileInputStream; @@ -27,6 +28,7 @@ import java.util.HashMap; import java.util.Map; import java.util.Properties; +import de.pixart.messenger.Config; import de.pixart.messenger.entities.Transferable; /** @@ -51,6 +53,7 @@ public final class MimeUtils { // by guessExtensionFromMimeType. add("application/andrew-inset", "ez"); add("application/dsptype", "tsp"); + add("application/epub+zip","pub"); add("application/hta", "hta"); add("application/mac-binhex40", "hqx"); add("application/mathematica", "nb"); @@ -66,6 +69,9 @@ public final class MimeUtils { add("application/rdf+xml", "rdf"); add("application/rss+xml", "rss"); add("application/zip", "zip"); + add("application/vnd.amazon.mobi8-ebook","azw3"); + add("application/vnd.amazon.mobi8-ebook","azw"); + add("application/vnd.amazon.mobi8-ebook","kfx"); add("application/vnd.android.package-archive", "apk"); add("application/vnd.cinderella", "cdy"); add("application/vnd.ms-pki.stl", "stl"); @@ -508,6 +514,19 @@ public final class MimeUtils { return mimeTypeToExtensionMap.get(mimeType.split(";")[0]); } + public static String guessMimeTypeFromUriAndMime(final Context context, final Uri uri, final String mime) { + Log.d(Config.LOGTAG, "guessMimeTypeFromUriAndMime " + uri + " and mime=" + mime); + if (mime == null || mime.equals("application/octet-stream")) { + final String guess = guessMimeTypeFromUri(context, uri); + if (guess != null) { + return guess; + } else { + return mime; + } + } + return guessMimeTypeFromUri(context, uri); + } + public static String guessMimeTypeFromUri(Context context, Uri uri) { // try the content resolver String mimeType; @@ -520,11 +539,14 @@ public final class MimeUtils { mimeType = null; } // try the extension - if (mimeType == null && uri.getPath() != null) { + if ((mimeType == null || mimeType.equals("application/octet-stream")) && uri.getPath() != null) { String path = uri.getPath(); int start = path.lastIndexOf('.') + 1; if (start < path.length()) { - mimeType = MimeUtils.guessMimeTypeFromExtension(path.substring(start)); + final String guess = MimeUtils.guessMimeTypeFromExtension(path.substring(start)); + if (guess != null) { + mimeType = guess; + } } } // sometimes this works (as with the commit content api) diff --git a/src/main/java/de/pixart/messenger/utils/UIHelper.java b/src/main/java/de/pixart/messenger/utils/UIHelper.java index 81eef7ac1..03af31e23 100644 --- a/src/main/java/de/pixart/messenger/utils/UIHelper.java +++ b/src/main/java/de/pixart/messenger/utils/UIHelper.java @@ -475,6 +475,8 @@ public class UIHelper { return context.getString(R.string.apk); } else if (mime.contains("vcard")) { return context.getString(R.string.vcard); + } else if (mime.equals("application/epub+zip") || mime.equals("application/vnd.amazon.mobi8-ebook")) { + return context.getString(R.string.ebook); } else { return mime; } |