|
|
|
@ -35,6 +35,7 @@ import android.os.Build;
|
|
|
|
|
import android.os.Bundle;
|
|
|
|
|
import android.provider.ContactsContract;
|
|
|
|
|
import android.support.annotation.NonNull;
|
|
|
|
|
import android.support.annotation.Nullable;
|
|
|
|
|
import android.support.v4.view.WindowCompat;
|
|
|
|
|
import android.text.Editable;
|
|
|
|
|
import android.text.TextWatcher;
|
|
|
|
@ -85,6 +86,7 @@ import org.thoughtcrime.securesms.database.GroupDatabase;
|
|
|
|
|
import org.thoughtcrime.securesms.database.MmsSmsColumns.Types;
|
|
|
|
|
import org.thoughtcrime.securesms.database.ThreadDatabase;
|
|
|
|
|
import org.thoughtcrime.securesms.mms.AttachmentManager;
|
|
|
|
|
import org.thoughtcrime.securesms.mms.AttachmentManager.MediaType;
|
|
|
|
|
import org.thoughtcrime.securesms.mms.AttachmentTypeSelectorAdapter;
|
|
|
|
|
import org.thoughtcrime.securesms.mms.MediaConstraints;
|
|
|
|
|
import org.thoughtcrime.securesms.mms.MediaTooLargeException;
|
|
|
|
@ -113,6 +115,7 @@ import org.thoughtcrime.securesms.util.DirectoryHelper;
|
|
|
|
|
import org.thoughtcrime.securesms.util.DynamicLanguage;
|
|
|
|
|
import org.thoughtcrime.securesms.util.DynamicTheme;
|
|
|
|
|
import org.thoughtcrime.securesms.util.GroupUtil;
|
|
|
|
|
import org.thoughtcrime.securesms.util.MediaUtil;
|
|
|
|
|
import org.thoughtcrime.securesms.util.TextSecurePreferences;
|
|
|
|
|
import org.thoughtcrime.securesms.util.Util;
|
|
|
|
|
import org.thoughtcrime.securesms.util.concurrent.ListenableFuture;
|
|
|
|
@ -288,13 +291,16 @@ public class ConversationActivity extends PassphraseRequiredActionBarActivity
|
|
|
|
|
|
|
|
|
|
switch (reqCode) {
|
|
|
|
|
case PICK_IMAGE:
|
|
|
|
|
addAttachmentImage(masterSecret, data.getData());
|
|
|
|
|
setMedia(data.getData(),
|
|
|
|
|
MediaUtil.isGif(MediaUtil.getMimeType(this, data.getData())) ? MediaType.GIF
|
|
|
|
|
: MediaType.IMAGE,
|
|
|
|
|
false);
|
|
|
|
|
break;
|
|
|
|
|
case PICK_VIDEO:
|
|
|
|
|
addAttachmentVideo(data.getData());
|
|
|
|
|
setMedia(data.getData(), MediaType.VIDEO, false);
|
|
|
|
|
break;
|
|
|
|
|
case PICK_AUDIO:
|
|
|
|
|
addAttachmentAudio(data.getData());
|
|
|
|
|
setMedia(data.getData(), MediaType.AUDIO, false);
|
|
|
|
|
break;
|
|
|
|
|
case PICK_CONTACT_INFO:
|
|
|
|
|
addAttachmentContactInfo(data.getData());
|
|
|
|
@ -308,7 +314,7 @@ public class ConversationActivity extends PassphraseRequiredActionBarActivity
|
|
|
|
|
break;
|
|
|
|
|
case TAKE_PHOTO:
|
|
|
|
|
if (attachmentManager.getCaptureUri() != null) {
|
|
|
|
|
addAttachmentImage(masterSecret, attachmentManager.getCaptureUri());
|
|
|
|
|
setMedia(attachmentManager.getCaptureUri(), MediaType.IMAGE, true);
|
|
|
|
|
}
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
@ -671,9 +677,10 @@ public class ConversationActivity extends PassphraseRequiredActionBarActivity
|
|
|
|
|
Uri draftVideo = getIntent().getParcelableExtra(DRAFT_VIDEO_EXTRA);
|
|
|
|
|
|
|
|
|
|
if (draftText != null) composeText.setText(draftText);
|
|
|
|
|
if (draftImage != null) addAttachmentImage(masterSecret, draftImage);
|
|
|
|
|
if (draftAudio != null) addAttachmentAudio(draftAudio);
|
|
|
|
|
if (draftVideo != null) addAttachmentVideo(draftVideo);
|
|
|
|
|
|
|
|
|
|
if (draftImage != null) setMedia(draftImage, MediaType.IMAGE, false);
|
|
|
|
|
else if (draftAudio != null) setMedia(draftAudio, MediaType.AUDIO, false);
|
|
|
|
|
else if (draftVideo != null) setMedia(draftVideo, MediaType.VIDEO, false);
|
|
|
|
|
|
|
|
|
|
if (draftText == null && draftImage == null && draftAudio == null && draftVideo == null) {
|
|
|
|
|
initializeDraftFromDatabase();
|
|
|
|
@ -707,11 +714,11 @@ public class ConversationActivity extends PassphraseRequiredActionBarActivity
|
|
|
|
|
if (draft.getType().equals(Draft.TEXT)) {
|
|
|
|
|
composeText.setText(draft.getValue());
|
|
|
|
|
} else if (draft.getType().equals(Draft.IMAGE)) {
|
|
|
|
|
addAttachmentImage(masterSecret, Uri.parse(draft.getValue()));
|
|
|
|
|
setMedia(Uri.parse(draft.getValue()), MediaType.IMAGE, false);
|
|
|
|
|
} else if (draft.getType().equals(Draft.AUDIO)) {
|
|
|
|
|
addAttachmentAudio(Uri.parse(draft.getValue()));
|
|
|
|
|
setMedia(Uri.parse(draft.getValue()), MediaType.AUDIO, false);
|
|
|
|
|
} else if (draft.getType().equals(Draft.VIDEO)) {
|
|
|
|
|
addAttachmentVideo(Uri.parse(draft.getValue()));
|
|
|
|
|
setMedia(Uri.parse(draft.getValue()), MediaType.VIDEO, false);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
@ -917,55 +924,8 @@ public class ConversationActivity extends PassphraseRequiredActionBarActivity
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void addAttachmentImage(MasterSecret masterSecret, Uri imageUri) {
|
|
|
|
|
try {
|
|
|
|
|
attachmentManager.setImage(masterSecret, imageUri);
|
|
|
|
|
} catch (IOException | BitmapDecodingException e) {
|
|
|
|
|
Log.w(TAG, e);
|
|
|
|
|
attachmentManager.clear();
|
|
|
|
|
Toast.makeText(this, R.string.ConversationActivity_sorry_there_was_an_error_setting_your_attachment,
|
|
|
|
|
Toast.LENGTH_LONG).show();
|
|
|
|
|
} catch (MediaTooLargeException e) {
|
|
|
|
|
attachmentManager.clear();
|
|
|
|
|
Toast.makeText(this, getString(R.string.ConversationActivity_the_gif_you_selected_was_too_big),
|
|
|
|
|
Toast.LENGTH_LONG).show();
|
|
|
|
|
Log.w(TAG, e);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void addAttachmentVideo(Uri videoUri) {
|
|
|
|
|
try {
|
|
|
|
|
attachmentManager.setVideo(videoUri);
|
|
|
|
|
} catch (IOException e) {
|
|
|
|
|
attachmentManager.clear();
|
|
|
|
|
Toast.makeText(this, R.string.ConversationActivity_sorry_there_was_an_error_setting_your_attachment,
|
|
|
|
|
Toast.LENGTH_LONG).show();
|
|
|
|
|
Log.w("ComposeMessageActivity", e);
|
|
|
|
|
} catch (MediaTooLargeException e) {
|
|
|
|
|
attachmentManager.clear();
|
|
|
|
|
|
|
|
|
|
Toast.makeText(this, getString(R.string.ConversationActivity_sorry_the_selected_video_exceeds_message_size_restrictions,
|
|
|
|
|
(MmsMediaConstraints.MAX_MESSAGE_SIZE/1024)),
|
|
|
|
|
Toast.LENGTH_LONG).show();
|
|
|
|
|
Log.w("ComposeMessageActivity", e);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void addAttachmentAudio(Uri audioUri) {
|
|
|
|
|
try {
|
|
|
|
|
attachmentManager.setAudio(audioUri);
|
|
|
|
|
} catch (IOException e) {
|
|
|
|
|
attachmentManager.clear();
|
|
|
|
|
Toast.makeText(this, R.string.ConversationActivity_sorry_there_was_an_error_setting_your_attachment,
|
|
|
|
|
Toast.LENGTH_LONG).show();
|
|
|
|
|
Log.w("ComposeMessageActivity", e);
|
|
|
|
|
} catch (MediaTooLargeException e) {
|
|
|
|
|
attachmentManager.clear();
|
|
|
|
|
Toast.makeText(this, getString(R.string.ConversationActivity_sorry_the_selected_audio_exceeds_message_size_restrictions,
|
|
|
|
|
(MmsMediaConstraints.MAX_MESSAGE_SIZE/1024)),
|
|
|
|
|
Toast.LENGTH_LONG).show();
|
|
|
|
|
Log.w("ComposeMessageActivity", e);
|
|
|
|
|
}
|
|
|
|
|
private void setMedia(Uri uri, MediaType mediaType, boolean isCapture) {
|
|
|
|
|
attachmentManager.setMedia(masterSecret, uri, mediaType, getCurrentMediaConstraints(), isCapture);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void addAttachmentContactInfo(Uri contactUri) {
|
|
|
|
@ -1132,6 +1092,12 @@ public class ConversationActivity extends PassphraseRequiredActionBarActivity
|
|
|
|
|
return rawText;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private MediaConstraints getCurrentMediaConstraints() {
|
|
|
|
|
return sendButton.getSelectedTransport().getType() == Type.TEXTSECURE
|
|
|
|
|
? MediaConstraints.PUSH_CONSTRAINTS
|
|
|
|
|
: MediaConstraints.MMS_CONSTRAINTS;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void markThreadAsRead() {
|
|
|
|
|
new AsyncTask<Long, Void, Void>() {
|
|
|
|
|
@Override
|
|
|
|
@ -1198,8 +1164,24 @@ public class ConversationActivity extends PassphraseRequiredActionBarActivity
|
|
|
|
|
final Context context = getApplicationContext();
|
|
|
|
|
SlideDeck slideDeck;
|
|
|
|
|
|
|
|
|
|
if (attachmentManager.isAttachmentPresent()) slideDeck = new SlideDeck(attachmentManager.getSlideDeck());
|
|
|
|
|
else slideDeck = new SlideDeck();
|
|
|
|
|
if (attachmentManager.isAttachmentPresent()) {
|
|
|
|
|
Slide mediaSlide = attachmentManager.getSlideDeck().getThumbnailSlide();
|
|
|
|
|
MediaConstraints constraints = getCurrentMediaConstraints();
|
|
|
|
|
|
|
|
|
|
if (mediaSlide != null &&
|
|
|
|
|
!constraints.isSatisfied(this, masterSecret, mediaSlide.getPart()) &&
|
|
|
|
|
!constraints.canResize(mediaSlide.getPart()))
|
|
|
|
|
{
|
|
|
|
|
Toast.makeText(context,
|
|
|
|
|
R.string.ConversationActivity_attachment_exceeds_size_limits,
|
|
|
|
|
Toast.LENGTH_SHORT).show();
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
slideDeck = new SlideDeck(attachmentManager.getSlideDeck());
|
|
|
|
|
} else {
|
|
|
|
|
slideDeck = new SlideDeck();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
OutgoingMediaMessage outgoingMessage = new OutgoingMediaMessage(this, recipients, slideDeck,
|
|
|
|
|
getMessage(), distributionType);
|
|
|
|
@ -1272,8 +1254,7 @@ public class ConversationActivity extends PassphraseRequiredActionBarActivity
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
public void onImageCapture(@NonNull final byte[] imageBytes) {
|
|
|
|
|
attachmentManager.setCaptureUri(CaptureProvider.getInstance(this).create(masterSecret, recipients, imageBytes));
|
|
|
|
|
addAttachmentImage(masterSecret, attachmentManager.getCaptureUri());
|
|
|
|
|
setMedia(CaptureProvider.getInstance(this).create(masterSecret, recipients, imageBytes), MediaType.IMAGE, true);
|
|
|
|
|
quickAttachmentDrawer.hide(false);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
@ -1397,4 +1378,5 @@ public class ConversationActivity extends PassphraseRequiredActionBarActivity
|
|
|
|
|
initializeSecurity();
|
|
|
|
|
updateToggleButtonState();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|