added epub and azw mime types. try to resolve application/octet-stream by file extension instead. added preview icons for ebooks

This commit is contained in:
Christian Schneppe 2018-12-27 20:52:52 +01:00
parent 55058cca9d
commit 815421f92a
20 changed files with 37 additions and 6 deletions

View file

@ -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) {

View file

@ -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)

View file

@ -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 doesnt work with paging.
boolean done;
if (query.isCatchup()) {
done = false;

View file

@ -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 {

View file

@ -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;

View file

@ -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)

View file

@ -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;
}

Binary file not shown.

After

Width:  |  Height:  |  Size: 455 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 458 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 382 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 390 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 806 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 828 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.1 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.1 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.4 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.4 KiB

View file

@ -51,6 +51,7 @@
<attr name="media_preview_app" format="reference" />
<attr name="media_preview_calendar" format="reference" />
<attr name="media_preview_archive" format="reference" />
<attr name="media_preview_ebook" format="reference" />
<attr name="media_preview_unknown" format="reference" />
<attr name="icon_add_group" format="reference" />

View file

@ -849,4 +849,5 @@
<string name="start_orbot">Start Orbot</string>
<string name="no_market_app_installed">No market app installed.</string>
<string name="group_chat_will_make_your_jabber_id_public">This group chat will make your Jabber ID public</string>
<string name="ebook">e-book</string>
</resources>

View file

@ -74,6 +74,7 @@
<item name="media_preview_app" type="reference">@drawable/ic_android_black_48dp</item>
<item name="media_preview_calendar" type="reference">@drawable/ic_event_black_48dp</item>
<item name="media_preview_archive" type="reference">@drawable/ic_archive_black_48dp</item>
<item name="media_preview_ebook" type="reference">@drawable/ic_book_black_48dp</item>
<item name="media_preview_unknown" type="reference">@drawable/ic_help_black_48dp</item>
<item name="icon_add_group" type="reference">@drawable/ic_group_add_white_24dp</item>
@ -249,6 +250,7 @@
<item name="media_preview_app" type="reference">@drawable/ic_android_white_48dp</item>
<item name="media_preview_calendar" type="reference">@drawable/ic_event_white_48dp</item>
<item name="media_preview_archive" type="reference">@drawable/ic_archive_white_48dp</item>
<item name="media_preview_ebook" type="reference">@drawable/ic_book_white_48dp</item>
<item name="media_preview_unknown" type="reference">@drawable/ic_help_white_48dp</item>
<item name="icon_add_group" type="reference">@drawable/ic_group_add_white_24dp</item>