diff options
author | Christian Schneppe <christian@pix-art.de> | 2016-08-26 23:48:48 +0200 |
---|---|---|
committer | Christian Schneppe <christian@pix-art.de> | 2016-08-28 21:33:19 +0200 |
commit | b3b3475e93a9b08f9e35edbf74673728b560ad3b (patch) | |
tree | fc72bfce668b358310061c0a94736a0bd14e8b5d /src/main/java/de/pixart/messenger/ui/ConversationActivity.java | |
parent | 1f7f535d37b844dbd87447e1872c270edbca1302 (diff) |
compress videos bigger than 10 MB before sending
Diffstat (limited to '')
-rw-r--r-- | src/main/java/de/pixart/messenger/ui/ConversationActivity.java | 75 |
1 files changed, 73 insertions, 2 deletions
diff --git a/src/main/java/de/pixart/messenger/ui/ConversationActivity.java b/src/main/java/de/pixart/messenger/ui/ConversationActivity.java index 6442acaa3..bcb9e81fd 100644 --- a/src/main/java/de/pixart/messenger/ui/ConversationActivity.java +++ b/src/main/java/de/pixart/messenger/ui/ConversationActivity.java @@ -104,12 +104,14 @@ public class ConversationActivity extends XmppActivity public static final int ATTACHMENT_CHOICE_CHOOSE_FILE = 0x0303; public static final int ATTACHMENT_CHOICE_RECORD_VOICE = 0x0304; public static final int ATTACHMENT_CHOICE_LOCATION = 0x0305; - public static final int ATTACHMENT_CHOICE_INVALID = 0x0306; + public static final int ATTACHMENT_CHOICE_CHOOSE_VIDEO = 0x0306; + public static final int ATTACHMENT_CHOICE_INVALID = 0x0399; private static final String STATE_OPEN_CONVERSATION = "state_open_conversation"; private static final String STATE_PANEL_OPEN = "state_panel_open"; private static final String STATE_PENDING_URI = "state_pending_uri"; final private List<Uri> mPendingImageUris = new ArrayList<>(); final private List<Uri> mPendingFileUris = new ArrayList<>(); + final private List<Uri> mPendingVideoUris = new ArrayList<>(); private String mOpenConverstaion = null; private boolean mPanelOpen = true; private Uri mPendingGeoUri = null; @@ -610,6 +612,11 @@ public class ConversationActivity extends XmppActivity intent.setType("image/*"); chooser = true; break; + case ATTACHMENT_CHOICE_CHOOSE_VIDEO: + intent.setAction(Intent.ACTION_GET_CONTENT); + intent.setType("video/*"); + chooser = true; + break; case ATTACHMENT_CHOICE_TAKE_PHOTO: Uri uri = xmppConnectionService.getFileBackend().getTakePhotoUri(); intent.setAction(MediaStore.ACTION_IMAGE_CAPTURE); @@ -692,6 +699,9 @@ public class ConversationActivity extends XmppActivity case ATTACHMENT_CHOICE_CHOOSE_IMAGE: getPreferences().edit().putString("recently_used_quick_action", "picture").apply(); break; + case ATTACHMENT_CHOICE_CHOOSE_VIDEO: + getPreferences().edit().putString("recently_used_quick_action", "video").apply(); + break; } final Conversation conversation = getSelectedConversation(); final int encryption = conversation.getNextEncryption(); @@ -932,6 +942,9 @@ public class ConversationActivity extends XmppActivity case R.id.attach_take_picture: attachFile(ATTACHMENT_CHOICE_TAKE_PHOTO); break; + case R.id.attach_choose_video: + attachFile(ATTACHMENT_CHOICE_CHOOSE_VIDEO); + break; case R.id.attach_choose_file: attachFile(ATTACHMENT_CHOICE_CHOOSE_FILE); break; @@ -1413,6 +1426,10 @@ public class ConversationActivity extends XmppActivity } } + for (Iterator<Uri> i = mPendingVideoUris.iterator(); i.hasNext(); i.remove()) { + attachVideoToConversation(getSelectedConversation(), i.next()); + } + for (Iterator<Uri> i = mPendingFileUris.iterator(); i.hasNext(); i.remove()) { attachFileToConversation(getSelectedConversation(), i.next()); } @@ -1569,6 +1586,28 @@ public class ConversationActivity extends XmppActivity } else { selectPresence(c, callback); } + } else if (requestCode == ATTACHMENT_CHOICE_CHOOSE_VIDEO) { + final List<Uri> uris = extractUriFromIntent(data); + final Conversation c = getSelectedConversation(); + final OnPresenceSelected callback = new OnPresenceSelected() { + @Override + public void onPresenceSelected() { + mPendingVideoUris.clear(); + mPendingVideoUris.addAll(uris); + if (xmppConnectionServiceBound) { + for (Iterator<Uri> i = mPendingVideoUris.iterator(); i.hasNext(); i.remove()) { + attachVideoToConversation(c, i.next()); + } + } + } + }; + if (c == null || c.getMode() == Conversation.MODE_MULTI + || FileBackend.allFilesUnderSize(this, uris, getMaxHttpUploadSize(c)) + || c.getNextEncryption() == Message.ENCRYPTION_OTR) { + callback.onPresenceSelected(); + } else { + selectPresence(c, callback); + } } else if (requestCode == ATTACHMENT_CHOICE_TAKE_PHOTO) { if (mPendingImageUris.size() == 1) { Uri uri = mPendingImageUris.get(0); @@ -1582,7 +1621,7 @@ public class ConversationActivity extends XmppActivity } else { mPendingImageUris.clear(); } - } else if (requestCode == ATTACHMENT_CHOICE_LOCATION) { + } else if (requestCode == ATTACHMENT_CHOICE_LOCATION) { double latitude = data.getDoubleExtra("latitude", 0); double longitude = data.getDoubleExtra("longitude", 0); this.mPendingGeoUri = Uri.parse("geo:" + String.valueOf(latitude) + "," + String.valueOf(longitude)); @@ -1717,6 +1756,38 @@ public class ConversationActivity extends XmppActivity }); } + private void attachVideoToConversation(Conversation conversation, Uri uri) { + if (conversation == null) { + return; + } + final Toast prepareFileToast = Toast.makeText(getApplicationContext(),getText(R.string.preparing_video), Toast.LENGTH_LONG); + prepareFileToast.show(); + xmppConnectionService.attachVideoToConversation(conversation, uri, new UiCallback<Message>() { + @Override + public void success(Message message) { + hidePrepareFileToast(prepareFileToast); + xmppConnectionService.sendMessage(message); + } + + @Override + public void error(final int errorCode, Message message) { + hidePrepareFileToast(prepareFileToast); + runOnUiThread(new Runnable() { + @Override + public void run() { + replaceToast(getString(errorCode)); + } + }); + + } + + @Override + public void userInputRequried(PendingIntent pi, Message message) { + hidePrepareFileToast(prepareFileToast); + } + }); + } + private void attachImagesToConversation(Conversation conversation, Uri uri) { if (conversation == null) { return; |