diff options
author | Christian Schneppe <christian@pix-art.de> | 2018-04-01 21:04:17 +0200 |
---|---|---|
committer | Christian Schneppe <christian@pix-art.de> | 2018-04-01 21:04:17 +0200 |
commit | 5694150e38eaa9db329916a9d6feb00fc03c0ab6 (patch) | |
tree | 46972e89389a59f26c35cc31686819e39a5c3846 /src/main/java/de/pixart/messenger | |
parent | 0aff702a72c54cd1dd6746e3080a4318fe17b72a (diff) |
delegate mime type from intent
Diffstat (limited to '')
6 files changed, 21 insertions, 18 deletions
diff --git a/src/main/java/de/pixart/messenger/persistance/FileBackend.java b/src/main/java/de/pixart/messenger/persistance/FileBackend.java index 9bf826fe1..d936af86f 100644 --- a/src/main/java/de/pixart/messenger/persistance/FileBackend.java +++ b/src/main/java/de/pixart/messenger/persistance/FileBackend.java @@ -28,7 +28,6 @@ import android.util.Base64; import android.util.Base64OutputStream; import android.util.Log; import android.util.LruCache; -import android.webkit.MimeTypeMap; import java.io.ByteArrayOutputStream; import java.io.Closeable; @@ -354,10 +353,10 @@ public class FileBackend { } } - public void copyFileToPrivateStorage(Message message, Uri uri) throws FileCopyException { - String mime = MimeUtils.guessMimeTypeFromUri(mXmppConnectionService, uri); + public void copyFileToPrivateStorage(Message message, Uri uri, String type) throws FileCopyException { + String mime = type != null ? type : MimeUtils.guessMimeTypeFromUri(mXmppConnectionService, uri); Log.d(Config.LOGTAG, "copy " + uri.toString() + " to private storage (mime=" + mime + ")"); - String extension = MimeTypeMap.getSingleton().getExtensionFromMimeType(mime); + String extension = MimeUtils.guessExtensionFromMimeType(mime); if (extension == null) { extension = getExtensionFromUri(uri); } diff --git a/src/main/java/de/pixart/messenger/services/AttachFileToConversationRunnable.java b/src/main/java/de/pixart/messenger/services/AttachFileToConversationRunnable.java index dc14fe636..780be831b 100644 --- a/src/main/java/de/pixart/messenger/services/AttachFileToConversationRunnable.java +++ b/src/main/java/de/pixart/messenger/services/AttachFileToConversationRunnable.java @@ -31,17 +31,19 @@ public class AttachFileToConversationRunnable implements Runnable, MediaTranscod private final XmppConnectionService mXmppConnectionService; private final Message message; private final Uri uri; + private final String type; private final UiCallback<Message> callback; private final boolean isVideoMessage; private final long originalFileSize; private int currentProgress = -1; - public AttachFileToConversationRunnable(XmppConnectionService xmppConnectionService, Uri uri, Message message, UiCallback<Message> callback) { + public AttachFileToConversationRunnable(XmppConnectionService xmppConnectionService, Uri uri, String type, Message message, UiCallback<Message> callback) { this.uri = uri; + this.type = type; this.mXmppConnectionService = xmppConnectionService; this.message = message; this.callback = callback; - final String mimeType = MimeUtils.guessMimeTypeFromUri(mXmppConnectionService, uri); + final String mimeType = type != null ? type : MimeUtils.guessMimeTypeFromUri(mXmppConnectionService, uri); final int autoAcceptFileSize = Config.FILE_SIZE; this.originalFileSize = FileBackend.getFileSize(mXmppConnectionService, uri); this.isVideoMessage = !getFileBackend().useFileAsIs(uri) @@ -68,7 +70,7 @@ public class AttachFileToConversationRunnable implements Runnable, MediaTranscod } } else { try { - mXmppConnectionService.getFileBackend().copyFileToPrivateStorage(message, uri); + mXmppConnectionService.getFileBackend().copyFileToPrivateStorage(message, uri, type); mXmppConnectionService.getFileBackend().updateFileParams(message); if (message.getEncryption() == Message.ENCRYPTION_DECRYPTED) { final PgpEngine pgpEngine = mXmppConnectionService.getPgpEngine(); diff --git a/src/main/java/de/pixart/messenger/services/XmppConnectionService.java b/src/main/java/de/pixart/messenger/services/XmppConnectionService.java index 69b329dce..06311c441 100644 --- a/src/main/java/de/pixart/messenger/services/XmppConnectionService.java +++ b/src/main/java/de/pixart/messenger/services/XmppConnectionService.java @@ -491,9 +491,7 @@ public class XmppConnectionService extends Service { } } - public void attachFileToConversation(final Conversation conversation, - final Uri uri, - final UiCallback<Message> callback) { + public void attachFileToConversation(final Conversation conversation, final Uri uri, final String type, final UiCallback<Message> callback) { if (FileBackend.weOwnFile(this, uri)) { Log.d(Config.LOGTAG, "trying to attach file that belonged to us"); callback.error(R.string.security_error_invalid_file_access, null); @@ -507,7 +505,7 @@ public class XmppConnectionService extends Service { } message.setCounterpart(conversation.getNextCounterpart()); message.setType(Message.TYPE_FILE); - final AttachFileToConversationRunnable runnable = new AttachFileToConversationRunnable(this, uri, message, callback); + final AttachFileToConversationRunnable runnable = new AttachFileToConversationRunnable(this, uri, type, message, callback); if (runnable.isVideoMessage()) { mVideoCompressionExecutor.execute(runnable); } else { @@ -527,7 +525,7 @@ public class XmppConnectionService extends Service { || ("auto".equals(compressPictures) && getFileBackend().useImageAsIs(uri)) || (mimeType != null && mimeType.endsWith("/gif"))) { Log.d(Config.LOGTAG, conversation.getAccount().getJid().toBareJid() + ": not compressing picture. sending as file"); - attachFileToConversation(conversation, uri, callback); + attachFileToConversation(conversation, uri, mimeType, callback); return; } final Message message; diff --git a/src/main/java/de/pixart/messenger/ui/ConversationFragment.java b/src/main/java/de/pixart/messenger/ui/ConversationFragment.java index 8fab4031f..24bc9163f 100644 --- a/src/main/java/de/pixart/messenger/ui/ConversationFragment.java +++ b/src/main/java/de/pixart/messenger/ui/ConversationFragment.java @@ -625,14 +625,14 @@ public class ConversationFragment extends XmppFragment implements EditMessage.Ke }); } - private void attachFileToConversation(Conversation conversation, Uri uri) { + private void attachFileToConversation(Conversation conversation, Uri uri, String type) { if (conversation == null) { return; } final Toast prepareFileToast = Toast.makeText(getActivity(), getText(R.string.preparing_file), Toast.LENGTH_LONG); prepareFileToast.show(); activity.delegateUriPermissionsToService(uri); - activity.xmppConnectionService.attachFileToConversation(conversation, uri, new UiInformableCallback<Message>() { + activity.xmppConnectionService.attachFileToConversation(conversation, uri, type, new UiInformableCallback<Message>() { @Override public void inform(final String text) { hidePrepareFileToast(prepareFileToast); @@ -970,10 +970,11 @@ public class ConversationFragment extends XmppFragment implements EditMessage.Ke case ATTACHMENT_CHOICE_CHOOSE_FILE: case ATTACHMENT_CHOICE_RECORD_VOICE: final List<Uri> fileUris = AttachmentTool.extractUriFromIntent(data); + String type = data.getType(); final PresenceSelector.OnPresenceSelected callback = () -> { for (Iterator<Uri> i = fileUris.iterator(); i.hasNext(); i.remove()) { Log.d(Config.LOGTAG, "ConversationsActivity.onActivityResult() - attaching file to conversations. CHOOSE_FILE/RECORD_VOICE"); - attachFileToConversation(conversation, i.next()); + attachFileToConversation(conversation, i.next(), type); } }; if (conversation == null || conversation.getMode() == Conversation.MODE_MULTI || FileBackend.allFilesUnderSize(getActivity(), fileUris, getMaxHttpUploadSize(conversation))) { diff --git a/src/main/java/de/pixart/messenger/ui/ShareWithActivity.java b/src/main/java/de/pixart/messenger/ui/ShareWithActivity.java index 2d72d3a26..ad0ed109d 100644 --- a/src/main/java/de/pixart/messenger/ui/ShareWithActivity.java +++ b/src/main/java/de/pixart/messenger/ui/ShareWithActivity.java @@ -57,6 +57,7 @@ public class ShareWithActivity extends XmppActivity implements XmppConnectionSer public String text; public String uuid; public boolean multiple = false; + public String type; } private Share share; @@ -229,6 +230,7 @@ public class ShareWithActivity extends XmppActivity implements XmppConnectionSer this.share.uris.clear(); this.share.uris.add(uri); this.share.image = type.startsWith("image/") || isImage(uri); + this.share.type = type; } else { if (subject != null) { this.share.text = format("[%s]%n%s", subject, text); @@ -348,7 +350,7 @@ public class ShareWithActivity extends XmppActivity implements XmppConnectionSer replaceToast(getString(R.string.preparing_file)); final Uri uri = share.uris.get(0); delegateUriPermissionsToService(uri); - xmppConnectionService.attachFileToConversation(conversation, uri, attachFileCallback); + xmppConnectionService.attachFileToConversation(conversation, uri, share.type, attachFileCallback); finish(); } }; diff --git a/src/main/java/de/pixart/messenger/utils/MimeUtils.java b/src/main/java/de/pixart/messenger/utils/MimeUtils.java index bf3b962ab..f4db070fd 100644 --- a/src/main/java/de/pixart/messenger/utils/MimeUtils.java +++ b/src/main/java/de/pixart/messenger/utils/MimeUtils.java @@ -57,7 +57,6 @@ public final class MimeUtils { add("application/msaccess", "mdb"); add("application/oda", "oda"); add("application/ogg", "ogg"); - add("application/ogg", "oga"); add("application/pdf", "pdf"); add("application/pgp-keys", "key"); add("application/pgp-signature", "pgp"); @@ -236,6 +235,7 @@ public final class MimeUtils { add("audio/mpeg", "mp2"); add("audio/mpeg", "m4a"); add("audio/mpegurl", "m3u"); + add("audio/ogg", "oga"); add("audio/opus", "opus"); add("audio/prs.sid", "sid"); add("audio/x-aiff", "aif"); @@ -358,6 +358,7 @@ public final class MimeUtils { add("video/fli", "fli"); add("video/m4v", "m4v"); add("video/mp2ts", "ts"); + add("video/ogg","ogv"); add("video/mpeg", "mpeg"); add("video/mpeg", "mpg"); add("video/mpeg", "mpe"); @@ -504,7 +505,7 @@ public final class MimeUtils { if (mimeType == null || mimeType.isEmpty()) { return null; } - return mimeTypeToExtensionMap.get(mimeType); + return mimeTypeToExtensionMap.get(mimeType.split(";")[0]); } public static String guessMimeTypeFromUri(Context context, Uri uri) { |