delegate mime type from intent
This commit is contained in:
parent
2f71c0cb79
commit
c1c314f47a
|
@ -311,10 +311,10 @@ public class FileBackend {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void copyFileToPrivateStorage(Message message, Uri uri) throws FileCopyException {
|
public void copyFileToPrivateStorage(Message message, Uri uri, String type) throws FileCopyException {
|
||||||
String mime = MimeUtils.guessMimeTypeFromUri(mXmppConnectionService, uri);
|
String mime = type != null ? type : MimeUtils.guessMimeTypeFromUri(mXmppConnectionService, uri);
|
||||||
Log.d(Config.LOGTAG, "copy " + uri.toString() + " to private storage (mime=" + mime + ")");
|
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) {
|
if (extension == null) {
|
||||||
extension = getExtensionFromUri(uri);
|
extension = getExtensionFromUri(uri);
|
||||||
}
|
}
|
||||||
|
|
|
@ -30,17 +30,19 @@ public class AttachFileToConversationRunnable implements Runnable, MediaTranscod
|
||||||
private final XmppConnectionService mXmppConnectionService;
|
private final XmppConnectionService mXmppConnectionService;
|
||||||
private final Message message;
|
private final Message message;
|
||||||
private final Uri uri;
|
private final Uri uri;
|
||||||
|
private final String type;
|
||||||
private final UiCallback<Message> callback;
|
private final UiCallback<Message> callback;
|
||||||
private final boolean isVideoMessage;
|
private final boolean isVideoMessage;
|
||||||
private final long originalFileSize;
|
private final long originalFileSize;
|
||||||
private int currentProgress = -1;
|
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.uri = uri;
|
||||||
|
this.type = type;
|
||||||
this.mXmppConnectionService = xmppConnectionService;
|
this.mXmppConnectionService = xmppConnectionService;
|
||||||
this.message = message;
|
this.message = message;
|
||||||
this.callback = callback;
|
this.callback = callback;
|
||||||
final String mimeType = MimeUtils.guessMimeTypeFromUri(mXmppConnectionService, uri);
|
final String mimeType = type != null ? type : MimeUtils.guessMimeTypeFromUri(mXmppConnectionService, uri);
|
||||||
final int autoAcceptFileSize = mXmppConnectionService.getResources().getInteger(R.integer.auto_accept_filesize);
|
final int autoAcceptFileSize = mXmppConnectionService.getResources().getInteger(R.integer.auto_accept_filesize);
|
||||||
this.originalFileSize = FileBackend.getFileSize(mXmppConnectionService,uri);
|
this.originalFileSize = FileBackend.getFileSize(mXmppConnectionService,uri);
|
||||||
this.isVideoMessage = (mimeType != null && mimeType.startsWith("video/")
|
this.isVideoMessage = (mimeType != null && mimeType.startsWith("video/")
|
||||||
|
@ -65,7 +67,7 @@ public class AttachFileToConversationRunnable implements Runnable, MediaTranscod
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
try {
|
try {
|
||||||
mXmppConnectionService.getFileBackend().copyFileToPrivateStorage(message, uri);
|
mXmppConnectionService.getFileBackend().copyFileToPrivateStorage(message, uri, type);
|
||||||
mXmppConnectionService.getFileBackend().updateFileParams(message);
|
mXmppConnectionService.getFileBackend().updateFileParams(message);
|
||||||
if (message.getEncryption() == Message.ENCRYPTION_DECRYPTED) {
|
if (message.getEncryption() == Message.ENCRYPTION_DECRYPTED) {
|
||||||
final PgpEngine pgpEngine = mXmppConnectionService.getPgpEngine();
|
final PgpEngine pgpEngine = mXmppConnectionService.getPgpEngine();
|
||||||
|
|
|
@ -464,9 +464,7 @@ public class XmppConnectionService extends Service {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void attachFileToConversation(final Conversation conversation,
|
public void attachFileToConversation(final Conversation conversation, final Uri uri, final String type, final UiCallback<Message> callback) {
|
||||||
final Uri uri,
|
|
||||||
final UiCallback<Message> callback) {
|
|
||||||
if (FileBackend.weOwnFile(this, uri)) {
|
if (FileBackend.weOwnFile(this, uri)) {
|
||||||
Log.d(Config.LOGTAG, "trying to attach file that belonged to us");
|
Log.d(Config.LOGTAG, "trying to attach file that belonged to us");
|
||||||
callback.error(R.string.security_error_invalid_file_access, null);
|
callback.error(R.string.security_error_invalid_file_access, null);
|
||||||
|
@ -480,7 +478,7 @@ public class XmppConnectionService extends Service {
|
||||||
}
|
}
|
||||||
message.setCounterpart(conversation.getNextCounterpart());
|
message.setCounterpart(conversation.getNextCounterpart());
|
||||||
message.setType(Message.TYPE_FILE);
|
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()) {
|
if (runnable.isVideoMessage()) {
|
||||||
mVideoCompressionExecutor.execute(runnable);
|
mVideoCompressionExecutor.execute(runnable);
|
||||||
} else {
|
} else {
|
||||||
|
@ -502,7 +500,7 @@ public class XmppConnectionService extends Service {
|
||||||
|| ("auto".equals(compressPictures) && getFileBackend().useImageAsIs(uri))
|
|| ("auto".equals(compressPictures) && getFileBackend().useImageAsIs(uri))
|
||||||
|| (mimeType != null && mimeType.endsWith("/gif"))) {
|
|| (mimeType != null && mimeType.endsWith("/gif"))) {
|
||||||
Log.d(Config.LOGTAG, conversation.getAccount().getJid().toBareJid() + ": not compressing picture. sending as file");
|
Log.d(Config.LOGTAG, conversation.getAccount().getJid().toBareJid() + ": not compressing picture. sending as file");
|
||||||
attachFileToConversation(conversation, uri, callback);
|
attachFileToConversation(conversation, uri, mimeType, callback);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
final Message message;
|
final Message message;
|
||||||
|
|
|
@ -508,14 +508,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) {
|
if (conversation == null) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
final Toast prepareFileToast = Toast.makeText(getActivity(), getText(R.string.preparing_file), Toast.LENGTH_LONG);
|
final Toast prepareFileToast = Toast.makeText(getActivity(), getText(R.string.preparing_file), Toast.LENGTH_LONG);
|
||||||
prepareFileToast.show();
|
prepareFileToast.show();
|
||||||
activity.delegateUriPermissionsToService(uri);
|
activity.delegateUriPermissionsToService(uri);
|
||||||
activity.xmppConnectionService.attachFileToConversation(conversation, uri, new UiInformableCallback<Message>() {
|
activity.xmppConnectionService.attachFileToConversation(conversation, uri, type, new UiInformableCallback<Message>() {
|
||||||
@Override
|
@Override
|
||||||
public void inform(final String text) {
|
public void inform(final String text) {
|
||||||
hidePrepareFileToast(prepareFileToast);
|
hidePrepareFileToast(prepareFileToast);
|
||||||
|
@ -705,10 +705,11 @@ public class ConversationFragment extends XmppFragment implements EditMessage.Ke
|
||||||
case ATTACHMENT_CHOICE_RECORD_VIDEO:
|
case ATTACHMENT_CHOICE_RECORD_VIDEO:
|
||||||
case ATTACHMENT_CHOICE_RECORD_VOICE:
|
case ATTACHMENT_CHOICE_RECORD_VOICE:
|
||||||
final List<Uri> fileUris = AttachmentTool.extractUriFromIntent(data);
|
final List<Uri> fileUris = AttachmentTool.extractUriFromIntent(data);
|
||||||
|
String type = data.getType();
|
||||||
final PresenceSelector.OnPresenceSelected callback = () -> {
|
final PresenceSelector.OnPresenceSelected callback = () -> {
|
||||||
for (Iterator<Uri> i = fileUris.iterator(); i.hasNext(); i.remove()) {
|
for (Iterator<Uri> i = fileUris.iterator(); i.hasNext(); i.remove()) {
|
||||||
Log.d(Config.LOGTAG, "ConversationsActivity.onActivityResult() - attaching file to conversations. CHOOSE_FILE/RECORD_VOICE/RECORD_VIDEO");
|
Log.d(Config.LOGTAG, "ConversationsActivity.onActivityResult() - attaching file to conversations. CHOOSE_FILE/RECORD_VOICE/RECORD_VIDEO");
|
||||||
attachFileToConversation(conversation, i.next());
|
attachFileToConversation(conversation, i.next(), type);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
if (conversation == null || conversation.getMode() == Conversation.MODE_MULTI || FileBackend.allFilesUnderSize(getActivity(), fileUris, getMaxHttpUploadSize(conversation))) {
|
if (conversation == null || conversation.getMode() == Conversation.MODE_MULTI || FileBackend.allFilesUnderSize(getActivity(), fileUris, getMaxHttpUploadSize(conversation))) {
|
||||||
|
|
|
@ -53,6 +53,7 @@ public class ShareWithActivity extends XmppActivity implements XmppConnectionSer
|
||||||
public String text;
|
public String text;
|
||||||
public String uuid;
|
public String uuid;
|
||||||
public boolean multiple = false;
|
public boolean multiple = false;
|
||||||
|
public String type;
|
||||||
}
|
}
|
||||||
|
|
||||||
private Share share;
|
private Share share;
|
||||||
|
@ -215,6 +216,7 @@ public class ShareWithActivity extends XmppActivity implements XmppConnectionSer
|
||||||
this.share.uris.clear();
|
this.share.uris.clear();
|
||||||
this.share.uris.add(uri);
|
this.share.uris.add(uri);
|
||||||
this.share.image = type.startsWith("image/") || isImage(uri);
|
this.share.image = type.startsWith("image/") || isImage(uri);
|
||||||
|
this.share.type = type;
|
||||||
} else {
|
} else {
|
||||||
this.share.text = text;
|
this.share.text = text;
|
||||||
}
|
}
|
||||||
|
@ -315,7 +317,7 @@ public class ShareWithActivity extends XmppActivity implements XmppConnectionSer
|
||||||
replaceToast(getString(R.string.preparing_file));
|
replaceToast(getString(R.string.preparing_file));
|
||||||
final Uri uri = share.uris.get(0);
|
final Uri uri = share.uris.get(0);
|
||||||
delegateUriPermissionsToService(uri);
|
delegateUriPermissionsToService(uri);
|
||||||
xmppConnectionService.attachFileToConversation(conversation, uri, attachFileCallback);
|
xmppConnectionService.attachFileToConversation(conversation, uri, share.type, attachFileCallback);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
if (account.httpUploadAvailable()
|
if (account.httpUploadAvailable()
|
||||||
|
|
|
@ -55,7 +55,6 @@ public final class MimeUtils {
|
||||||
add("application/msaccess", "mdb");
|
add("application/msaccess", "mdb");
|
||||||
add("application/oda", "oda");
|
add("application/oda", "oda");
|
||||||
add("application/ogg", "ogg");
|
add("application/ogg", "ogg");
|
||||||
add("application/ogg", "oga");
|
|
||||||
add("application/pdf", "pdf");
|
add("application/pdf", "pdf");
|
||||||
add("application/pgp-keys", "key");
|
add("application/pgp-keys", "key");
|
||||||
add("application/pgp-signature", "pgp");
|
add("application/pgp-signature", "pgp");
|
||||||
|
@ -234,6 +233,7 @@ public final class MimeUtils {
|
||||||
add("audio/mpeg", "mp2");
|
add("audio/mpeg", "mp2");
|
||||||
add("audio/mpeg", "m4a");
|
add("audio/mpeg", "m4a");
|
||||||
add("audio/mpegurl", "m3u");
|
add("audio/mpegurl", "m3u");
|
||||||
|
add("audio/ogg","oga");
|
||||||
add("audio/prs.sid", "sid");
|
add("audio/prs.sid", "sid");
|
||||||
add("audio/x-aiff", "aif");
|
add("audio/x-aiff", "aif");
|
||||||
add("audio/x-aiff", "aiff");
|
add("audio/x-aiff", "aiff");
|
||||||
|
@ -355,6 +355,7 @@ public final class MimeUtils {
|
||||||
add("video/fli", "fli");
|
add("video/fli", "fli");
|
||||||
add("video/m4v", "m4v");
|
add("video/m4v", "m4v");
|
||||||
add("video/mp2ts", "ts");
|
add("video/mp2ts", "ts");
|
||||||
|
add("video/ogg","ogv");
|
||||||
add("video/mpeg", "mpeg");
|
add("video/mpeg", "mpeg");
|
||||||
add("video/mpeg", "mpg");
|
add("video/mpeg", "mpg");
|
||||||
add("video/mpeg", "mpe");
|
add("video/mpeg", "mpe");
|
||||||
|
@ -489,7 +490,7 @@ public final class MimeUtils {
|
||||||
if (mimeType == null || mimeType.isEmpty()) {
|
if (mimeType == null || mimeType.isEmpty()) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
return mimeTypeToExtensionMap.get(mimeType);
|
return mimeTypeToExtensionMap.get(mimeType.split(";")[0]);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static String guessMimeTypeFromUri(Context context, Uri uri) {
|
public static String guessMimeTypeFromUri(Context context, Uri uri) {
|
||||||
|
|
Loading…
Reference in a new issue