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 {
|
||||
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);
|
||||
}
|
||||
|
|
|
@ -30,17 +30,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 = mXmppConnectionService.getResources().getInteger(R.integer.auto_accept_filesize);
|
||||
this.originalFileSize = FileBackend.getFileSize(mXmppConnectionService,uri);
|
||||
this.isVideoMessage = (mimeType != null && mimeType.startsWith("video/")
|
||||
|
@ -65,7 +67,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();
|
||||
|
|
|
@ -464,9 +464,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);
|
||||
|
@ -480,7 +478,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 {
|
||||
|
@ -502,7 +500,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;
|
||||
|
|
|
@ -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) {
|
||||
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);
|
||||
|
@ -705,10 +705,11 @@ public class ConversationFragment extends XmppFragment implements EditMessage.Ke
|
|||
case ATTACHMENT_CHOICE_RECORD_VIDEO:
|
||||
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/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))) {
|
||||
|
|
|
@ -53,6 +53,7 @@ public class ShareWithActivity extends XmppActivity implements XmppConnectionSer
|
|||
public String text;
|
||||
public String uuid;
|
||||
public boolean multiple = false;
|
||||
public String type;
|
||||
}
|
||||
|
||||
private Share share;
|
||||
|
@ -215,6 +216,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 {
|
||||
this.share.text = text;
|
||||
}
|
||||
|
@ -315,7 +317,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);
|
||||
}
|
||||
};
|
||||
if (account.httpUploadAvailable()
|
||||
|
|
|
@ -55,7 +55,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");
|
||||
|
@ -234,6 +233,7 @@ public final class MimeUtils {
|
|||
add("audio/mpeg", "mp2");
|
||||
add("audio/mpeg", "m4a");
|
||||
add("audio/mpegurl", "m3u");
|
||||
add("audio/ogg","oga");
|
||||
add("audio/prs.sid", "sid");
|
||||
add("audio/x-aiff", "aif");
|
||||
add("audio/x-aiff", "aiff");
|
||||
|
@ -355,6 +355,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");
|
||||
|
@ -489,7 +490,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) {
|
||||
|
|
Loading…
Reference in New Issue