2017-10-16 13:11:42 -07:00
|
|
|
/*
|
2012-07-19 14:22:03 -07:00
|
|
|
* Copyright (C) 2011 Whisper Systems
|
|
|
|
*
|
|
|
|
* This program is free software: you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU General Public License as published by
|
|
|
|
* the Free Software Foundation, either version 3 of the License, or
|
|
|
|
* (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
*/
|
|
|
|
package org.thoughtcrime.securesms;
|
|
|
|
|
2017-11-24 22:00:30 -08:00
|
|
|
import android.Manifest;
|
2017-11-14 10:49:54 -08:00
|
|
|
import android.annotation.SuppressLint;
|
2016-11-20 15:56:47 -08:00
|
|
|
import android.annotation.TargetApi;
|
2013-06-18 14:43:27 -07:00
|
|
|
import android.content.ActivityNotFoundException;
|
2013-03-05 19:32:15 -08:00
|
|
|
import android.content.BroadcastReceiver;
|
|
|
|
import android.content.Context;
|
|
|
|
import android.content.Intent;
|
|
|
|
import android.content.IntentFilter;
|
2015-07-07 14:25:41 -07:00
|
|
|
import android.content.res.Configuration;
|
2015-06-30 17:45:39 -07:00
|
|
|
import android.content.res.TypedArray;
|
|
|
|
import android.graphics.Color;
|
|
|
|
import android.graphics.PorterDuff;
|
|
|
|
import android.graphics.PorterDuff.Mode;
|
2015-06-23 15:10:50 -07:00
|
|
|
import android.graphics.drawable.ColorDrawable;
|
2013-03-05 19:32:15 -08:00
|
|
|
import android.net.Uri;
|
|
|
|
import android.os.AsyncTask;
|
2015-11-24 11:47:50 -08:00
|
|
|
import android.os.Build;
|
2013-03-05 19:32:15 -08:00
|
|
|
import android.os.Bundle;
|
2015-11-18 14:52:26 -08:00
|
|
|
import android.os.Vibrator;
|
2016-03-29 17:52:54 -05:00
|
|
|
import android.provider.Browser;
|
2013-10-17 02:28:36 +02:00
|
|
|
import android.provider.ContactsContract;
|
2016-11-20 15:56:47 -08:00
|
|
|
import android.provider.Telephony;
|
2014-12-15 12:25:55 -08:00
|
|
|
import android.support.annotation.NonNull;
|
2016-12-26 15:14:23 -08:00
|
|
|
import android.support.annotation.Nullable;
|
2016-09-25 20:04:13 -07:00
|
|
|
import android.support.v4.view.MenuItemCompat;
|
2015-04-16 01:38:33 -04:00
|
|
|
import android.support.v4.view.WindowCompat;
|
2017-12-05 11:52:03 -08:00
|
|
|
import android.support.v7.app.ActionBar;
|
2015-05-20 23:36:30 +02:00
|
|
|
import android.support.v7.app.AlertDialog;
|
2013-03-05 19:32:15 -08:00
|
|
|
import android.text.Editable;
|
2016-12-26 15:14:23 -08:00
|
|
|
import android.text.TextUtils;
|
2013-03-05 19:32:15 -08:00
|
|
|
import android.text.TextWatcher;
|
|
|
|
import android.util.Log;
|
2015-09-29 14:26:37 -07:00
|
|
|
import android.util.Pair;
|
2013-03-05 19:32:15 -08:00
|
|
|
import android.view.KeyEvent;
|
2014-06-28 20:40:57 -07:00
|
|
|
import android.view.Menu;
|
|
|
|
import android.view.MenuInflater;
|
|
|
|
import android.view.MenuItem;
|
2013-03-05 19:32:15 -08:00
|
|
|
import android.view.View;
|
|
|
|
import android.view.View.OnClickListener;
|
2014-05-28 20:53:34 -07:00
|
|
|
import android.view.View.OnFocusChangeListener;
|
2013-03-05 19:32:15 -08:00
|
|
|
import android.view.View.OnKeyListener;
|
2017-02-16 21:28:06 +01:00
|
|
|
import android.view.WindowManager;
|
2013-03-05 19:32:15 -08:00
|
|
|
import android.view.inputmethod.EditorInfo;
|
2015-06-09 07:37:20 -07:00
|
|
|
import android.widget.Button;
|
2015-05-18 10:26:32 -07:00
|
|
|
import android.widget.ImageButton;
|
2015-11-24 11:47:50 -08:00
|
|
|
import android.widget.LinearLayout;
|
2013-03-05 19:32:15 -08:00
|
|
|
import android.widget.TextView;
|
|
|
|
import android.widget.Toast;
|
2012-07-19 14:22:03 -07:00
|
|
|
|
2015-12-18 14:37:11 -08:00
|
|
|
import com.google.android.gms.location.places.ui.PlacePicker;
|
2014-02-22 10:54:43 -08:00
|
|
|
import com.google.protobuf.ByteString;
|
2013-11-25 17:00:20 -08:00
|
|
|
|
2017-02-17 20:43:24 -08:00
|
|
|
import org.greenrobot.eventbus.EventBus;
|
|
|
|
import org.greenrobot.eventbus.Subscribe;
|
|
|
|
import org.greenrobot.eventbus.ThreadMode;
|
2015-11-18 14:52:26 -08:00
|
|
|
import org.thoughtcrime.securesms.audio.AudioRecorder;
|
2015-10-23 17:00:51 -07:00
|
|
|
import org.thoughtcrime.securesms.audio.AudioSlidePlayer;
|
2015-06-30 09:16:05 -07:00
|
|
|
import org.thoughtcrime.securesms.color.MaterialColor;
|
2015-05-18 10:26:32 -07:00
|
|
|
import org.thoughtcrime.securesms.components.AnimatingToggle;
|
2015-10-28 09:47:09 -07:00
|
|
|
import org.thoughtcrime.securesms.components.AttachmentTypeSelector;
|
2015-03-11 14:23:45 -07:00
|
|
|
import org.thoughtcrime.securesms.components.ComposeText;
|
2015-11-18 14:52:26 -08:00
|
|
|
import org.thoughtcrime.securesms.components.HidingLinearLayout;
|
2015-09-21 17:41:27 -07:00
|
|
|
import org.thoughtcrime.securesms.components.InputAwareLayout;
|
2015-11-18 14:52:26 -08:00
|
|
|
import org.thoughtcrime.securesms.components.InputPanel;
|
2015-07-02 16:47:03 -07:00
|
|
|
import org.thoughtcrime.securesms.components.KeyboardAwareLinearLayout.OnKeyboardShownListener;
|
2015-06-09 07:37:20 -07:00
|
|
|
import org.thoughtcrime.securesms.components.SendButton;
|
2015-09-21 17:41:27 -07:00
|
|
|
import org.thoughtcrime.securesms.components.camera.QuickAttachmentDrawer;
|
|
|
|
import org.thoughtcrime.securesms.components.camera.QuickAttachmentDrawer.AttachmentDrawerListener;
|
2015-07-24 13:22:28 -07:00
|
|
|
import org.thoughtcrime.securesms.components.camera.QuickAttachmentDrawer.DrawerState;
|
2015-07-13 15:45:14 -07:00
|
|
|
import org.thoughtcrime.securesms.components.emoji.EmojiDrawer;
|
2018-04-26 17:03:54 -07:00
|
|
|
import org.thoughtcrime.securesms.components.emoji.EmojiStrings;
|
2017-06-06 18:03:09 -07:00
|
|
|
import org.thoughtcrime.securesms.components.identity.UntrustedSendDialog;
|
|
|
|
import org.thoughtcrime.securesms.components.identity.UnverifiedBannerView;
|
|
|
|
import org.thoughtcrime.securesms.components.identity.UnverifiedSendDialog;
|
2016-01-04 13:02:22 -08:00
|
|
|
import org.thoughtcrime.securesms.components.location.SignalPlace;
|
2017-11-15 16:29:00 -08:00
|
|
|
import org.thoughtcrime.securesms.components.reminder.ExpiredBuildReminder;
|
2015-11-09 14:51:53 -08:00
|
|
|
import org.thoughtcrime.securesms.components.reminder.InviteReminder;
|
|
|
|
import org.thoughtcrime.securesms.components.reminder.ReminderView;
|
2017-11-15 16:29:00 -08:00
|
|
|
import org.thoughtcrime.securesms.components.reminder.UnauthorizedReminder;
|
2013-10-17 02:28:36 +02:00
|
|
|
import org.thoughtcrime.securesms.contacts.ContactAccessor;
|
|
|
|
import org.thoughtcrime.securesms.contacts.ContactAccessor.ContactData;
|
2018-04-26 17:03:54 -07:00
|
|
|
import org.thoughtcrime.securesms.contactshare.Contact;
|
|
|
|
import org.thoughtcrime.securesms.contactshare.ContactShareEditActivity;
|
|
|
|
import org.thoughtcrime.securesms.contactshare.ContactUtil;
|
2017-06-06 18:03:09 -07:00
|
|
|
import org.thoughtcrime.securesms.crypto.IdentityKeyParcelable;
|
2014-11-03 15:16:04 -08:00
|
|
|
import org.thoughtcrime.securesms.crypto.SecurityEvent;
|
2017-07-26 09:59:15 -07:00
|
|
|
import org.thoughtcrime.securesms.database.Address;
|
Major storage layer refactoring to set the stage for clean GCM.
1) We now try to hand out cursors at a minimum. There has always been
a fairly clean insertion layer that handles encrypting message bodies,
but the process of decrypting message bodies has always been less than
ideal. Here we introduce a "Reader" interface that will decrypt message
bodies when appropriate and return objects that encapsulate record state.
No more MessageDisplayHelper. The MmsSmsDatabase interface is also more
sane.
2) We finally rid ourselves of the technical debt associated with TextSecure's
initial usage of the default SMS DB. In that world, we weren't able to use
anything other than the default "Inbox, Outbox, Sent" types to describe a
message, and had to overload the message content itself with a set of
local "prefixes" to describe what it was (encrypted, asymetric encrypted,
remote encrypted, a key exchange, procssed key exchange), and so on.
This includes a major schema update that transforms the "type" field into
a bitmask that describes everything that used to be encoded in a prefix,
and prefixes have been completely eliminated from the system.
No more Prefix.java
3) Refactoring of the MultipartMessageHandler code. It's less of a mess, and
hopefully more clear as to what's going on.
The next step is to remove what we can from SmsTransportDetails and genericize
that interface for a GCM equivalent.
2013-04-20 12:22:04 -07:00
|
|
|
import org.thoughtcrime.securesms.database.DatabaseFactory;
|
|
|
|
import org.thoughtcrime.securesms.database.DraftDatabase;
|
|
|
|
import org.thoughtcrime.securesms.database.DraftDatabase.Draft;
|
2014-12-11 17:13:01 -08:00
|
|
|
import org.thoughtcrime.securesms.database.DraftDatabase.Drafts;
|
2017-06-06 18:03:09 -07:00
|
|
|
import org.thoughtcrime.securesms.database.IdentityDatabase;
|
|
|
|
import org.thoughtcrime.securesms.database.IdentityDatabase.IdentityRecord;
|
|
|
|
import org.thoughtcrime.securesms.database.IdentityDatabase.VerifiedStatus;
|
2016-10-10 11:13:37 -07:00
|
|
|
import org.thoughtcrime.securesms.database.MessagingDatabase.MarkedMessageInfo;
|
2014-12-11 17:13:01 -08:00
|
|
|
import org.thoughtcrime.securesms.database.MmsSmsColumns.Types;
|
2017-08-22 10:44:04 -07:00
|
|
|
import org.thoughtcrime.securesms.database.RecipientDatabase.RegisteredState;
|
2013-04-25 18:59:49 -07:00
|
|
|
import org.thoughtcrime.securesms.database.ThreadDatabase;
|
2017-06-06 18:03:09 -07:00
|
|
|
import org.thoughtcrime.securesms.database.identity.IdentityRecordList;
|
2018-02-07 14:01:37 -08:00
|
|
|
import org.thoughtcrime.securesms.database.model.MessageRecord;
|
|
|
|
import org.thoughtcrime.securesms.database.model.MmsMessageRecord;
|
2017-11-15 16:29:00 -08:00
|
|
|
import org.thoughtcrime.securesms.events.ReminderUpdateEvent;
|
2018-03-20 11:27:11 -07:00
|
|
|
import org.thoughtcrime.securesms.giph.ui.GiphyActivity;
|
2016-08-26 16:53:23 -07:00
|
|
|
import org.thoughtcrime.securesms.jobs.MultiDeviceBlockedUpdateJob;
|
2017-05-19 18:01:40 -07:00
|
|
|
import org.thoughtcrime.securesms.jobs.RetrieveProfileJob;
|
Major storage layer refactoring to set the stage for clean GCM.
1) We now try to hand out cursors at a minimum. There has always been
a fairly clean insertion layer that handles encrypting message bodies,
but the process of decrypting message bodies has always been less than
ideal. Here we introduce a "Reader" interface that will decrypt message
bodies when appropriate and return objects that encapsulate record state.
No more MessageDisplayHelper. The MmsSmsDatabase interface is also more
sane.
2) We finally rid ourselves of the technical debt associated with TextSecure's
initial usage of the default SMS DB. In that world, we weren't able to use
anything other than the default "Inbox, Outbox, Sent" types to describe a
message, and had to overload the message content itself with a set of
local "prefixes" to describe what it was (encrypted, asymetric encrypted,
remote encrypted, a key exchange, procssed key exchange), and so on.
This includes a major schema update that transforms the "type" field into
a bitmask that describes everything that used to be encoded in a prefix,
and prefixes have been completely eliminated from the system.
No more Prefix.java
3) Refactoring of the MultipartMessageHandler code. It's less of a mess, and
hopefully more clear as to what's going on.
The next step is to remove what we can from SmsTransportDetails and genericize
that interface for a GCM equivalent.
2013-04-20 12:22:04 -07:00
|
|
|
import org.thoughtcrime.securesms.mms.AttachmentManager;
|
2015-09-04 17:33:22 -07:00
|
|
|
import org.thoughtcrime.securesms.mms.AttachmentManager.MediaType;
|
2015-11-18 14:52:26 -08:00
|
|
|
import org.thoughtcrime.securesms.mms.AudioSlide;
|
2017-10-16 13:11:42 -07:00
|
|
|
import org.thoughtcrime.securesms.mms.GlideApp;
|
|
|
|
import org.thoughtcrime.securesms.mms.GlideRequests;
|
2016-01-04 13:02:22 -08:00
|
|
|
import org.thoughtcrime.securesms.mms.LocationSlide;
|
2015-07-28 13:17:01 -07:00
|
|
|
import org.thoughtcrime.securesms.mms.MediaConstraints;
|
2016-08-15 20:23:56 -07:00
|
|
|
import org.thoughtcrime.securesms.mms.OutgoingExpirationUpdateMessage;
|
2014-02-22 10:54:43 -08:00
|
|
|
import org.thoughtcrime.securesms.mms.OutgoingGroupMediaMessage;
|
2014-02-24 00:19:54 -08:00
|
|
|
import org.thoughtcrime.securesms.mms.OutgoingMediaMessage;
|
|
|
|
import org.thoughtcrime.securesms.mms.OutgoingSecureMediaMessage;
|
2018-04-24 11:09:54 -07:00
|
|
|
import org.thoughtcrime.securesms.mms.QuoteId;
|
|
|
|
import org.thoughtcrime.securesms.mms.QuoteModel;
|
Major storage layer refactoring to set the stage for clean GCM.
1) We now try to hand out cursors at a minimum. There has always been
a fairly clean insertion layer that handles encrypting message bodies,
but the process of decrypting message bodies has always been less than
ideal. Here we introduce a "Reader" interface that will decrypt message
bodies when appropriate and return objects that encapsulate record state.
No more MessageDisplayHelper. The MmsSmsDatabase interface is also more
sane.
2) We finally rid ourselves of the technical debt associated with TextSecure's
initial usage of the default SMS DB. In that world, we weren't able to use
anything other than the default "Inbox, Outbox, Sent" types to describe a
message, and had to overload the message content itself with a set of
local "prefixes" to describe what it was (encrypted, asymetric encrypted,
remote encrypted, a key exchange, procssed key exchange), and so on.
This includes a major schema update that transforms the "type" field into
a bitmask that describes everything that used to be encoded in a prefix,
and prefixes have been completely eliminated from the system.
No more Prefix.java
3) Refactoring of the MultipartMessageHandler code. It's less of a mess, and
hopefully more clear as to what's going on.
The next step is to remove what we can from SmsTransportDetails and genericize
that interface for a GCM equivalent.
2013-04-20 12:22:04 -07:00
|
|
|
import org.thoughtcrime.securesms.mms.Slide;
|
2015-11-18 14:52:26 -08:00
|
|
|
import org.thoughtcrime.securesms.mms.SlideDeck;
|
2016-10-10 11:13:37 -07:00
|
|
|
import org.thoughtcrime.securesms.notifications.MarkReadReceiver;
|
Major storage layer refactoring to set the stage for clean GCM.
1) We now try to hand out cursors at a minimum. There has always been
a fairly clean insertion layer that handles encrypting message bodies,
but the process of decrypting message bodies has always been less than
ideal. Here we introduce a "Reader" interface that will decrypt message
bodies when appropriate and return objects that encapsulate record state.
No more MessageDisplayHelper. The MmsSmsDatabase interface is also more
sane.
2) We finally rid ourselves of the technical debt associated with TextSecure's
initial usage of the default SMS DB. In that world, we weren't able to use
anything other than the default "Inbox, Outbox, Sent" types to describe a
message, and had to overload the message content itself with a set of
local "prefixes" to describe what it was (encrypted, asymetric encrypted,
remote encrypted, a key exchange, procssed key exchange), and so on.
This includes a major schema update that transforms the "type" field into
a bitmask that describes everything that used to be encoded in a prefix,
and prefixes have been completely eliminated from the system.
No more Prefix.java
3) Refactoring of the MultipartMessageHandler code. It's less of a mess, and
hopefully more clear as to what's going on.
The next step is to remove what we can from SmsTransportDetails and genericize
that interface for a GCM equivalent.
2013-04-20 12:22:04 -07:00
|
|
|
import org.thoughtcrime.securesms.notifications.MessageNotifier;
|
2017-11-24 22:00:30 -08:00
|
|
|
import org.thoughtcrime.securesms.permissions.Permissions;
|
2017-08-22 11:51:01 -07:00
|
|
|
import org.thoughtcrime.securesms.profiles.GroupShareProfileView;
|
2015-10-15 14:40:45 -07:00
|
|
|
import org.thoughtcrime.securesms.providers.PersistentBlobProvider;
|
Major storage layer refactoring to set the stage for clean GCM.
1) We now try to hand out cursors at a minimum. There has always been
a fairly clean insertion layer that handles encrypting message bodies,
but the process of decrypting message bodies has always been less than
ideal. Here we introduce a "Reader" interface that will decrypt message
bodies when appropriate and return objects that encapsulate record state.
No more MessageDisplayHelper. The MmsSmsDatabase interface is also more
sane.
2) We finally rid ourselves of the technical debt associated with TextSecure's
initial usage of the default SMS DB. In that world, we weren't able to use
anything other than the default "Inbox, Outbox, Sent" types to describe a
message, and had to overload the message content itself with a set of
local "prefixes" to describe what it was (encrypted, asymetric encrypted,
remote encrypted, a key exchange, procssed key exchange), and so on.
This includes a major schema update that transforms the "type" field into
a bitmask that describes everything that used to be encoded in a prefix,
and prefixes have been completely eliminated from the system.
No more Prefix.java
3) Refactoring of the MultipartMessageHandler code. It's less of a mess, and
hopefully more clear as to what's going on.
The next step is to remove what we can from SmsTransportDetails and genericize
that interface for a GCM equivalent.
2013-04-20 12:22:04 -07:00
|
|
|
import org.thoughtcrime.securesms.recipients.Recipient;
|
|
|
|
import org.thoughtcrime.securesms.recipients.RecipientFormattingException;
|
2017-08-01 08:56:00 -07:00
|
|
|
import org.thoughtcrime.securesms.recipients.RecipientModifiedListener;
|
2016-12-08 14:20:38 -08:00
|
|
|
import org.thoughtcrime.securesms.scribbles.ScribbleActivity;
|
Major storage layer refactoring to set the stage for clean GCM.
1) We now try to hand out cursors at a minimum. There has always been
a fairly clean insertion layer that handles encrypting message bodies,
but the process of decrypting message bodies has always been less than
ideal. Here we introduce a "Reader" interface that will decrypt message
bodies when appropriate and return objects that encapsulate record state.
No more MessageDisplayHelper. The MmsSmsDatabase interface is also more
sane.
2) We finally rid ourselves of the technical debt associated with TextSecure's
initial usage of the default SMS DB. In that world, we weren't able to use
anything other than the default "Inbox, Outbox, Sent" types to describe a
message, and had to overload the message content itself with a set of
local "prefixes" to describe what it was (encrypted, asymetric encrypted,
remote encrypted, a key exchange, procssed key exchange), and so on.
This includes a major schema update that transforms the "type" field into
a bitmask that describes everything that used to be encoded in a prefix,
and prefixes have been completely eliminated from the system.
No more Prefix.java
3) Refactoring of the MultipartMessageHandler code. It's less of a mess, and
hopefully more clear as to what's going on.
The next step is to remove what we can from SmsTransportDetails and genericize
that interface for a GCM equivalent.
2013-04-20 12:22:04 -07:00
|
|
|
import org.thoughtcrime.securesms.service.KeyCachingService;
|
|
|
|
import org.thoughtcrime.securesms.sms.MessageSender;
|
|
|
|
import org.thoughtcrime.securesms.sms.OutgoingEncryptedMessage;
|
2014-02-19 13:46:49 -08:00
|
|
|
import org.thoughtcrime.securesms.sms.OutgoingEndSessionMessage;
|
Major storage layer refactoring to set the stage for clean GCM.
1) We now try to hand out cursors at a minimum. There has always been
a fairly clean insertion layer that handles encrypting message bodies,
but the process of decrypting message bodies has always been less than
ideal. Here we introduce a "Reader" interface that will decrypt message
bodies when appropriate and return objects that encapsulate record state.
No more MessageDisplayHelper. The MmsSmsDatabase interface is also more
sane.
2) We finally rid ourselves of the technical debt associated with TextSecure's
initial usage of the default SMS DB. In that world, we weren't able to use
anything other than the default "Inbox, Outbox, Sent" types to describe a
message, and had to overload the message content itself with a set of
local "prefixes" to describe what it was (encrypted, asymetric encrypted,
remote encrypted, a key exchange, procssed key exchange), and so on.
This includes a major schema update that transforms the "type" field into
a bitmask that describes everything that used to be encoded in a prefix,
and prefixes have been completely eliminated from the system.
No more Prefix.java
3) Refactoring of the MultipartMessageHandler code. It's less of a mess, and
hopefully more clear as to what's going on.
The next step is to remove what we can from SmsTransportDetails and genericize
that interface for a GCM equivalent.
2013-04-20 12:22:04 -07:00
|
|
|
import org.thoughtcrime.securesms.sms.OutgoingTextMessage;
|
2015-02-16 02:38:09 -08:00
|
|
|
import org.thoughtcrime.securesms.util.CharacterCalculator.CharacterState;
|
2018-04-26 17:03:54 -07:00
|
|
|
import org.thoughtcrime.securesms.util.CommunicationActions;
|
2014-03-01 01:32:00 +01:00
|
|
|
import org.thoughtcrime.securesms.util.Dialogs;
|
2014-03-26 14:49:40 -07:00
|
|
|
import org.thoughtcrime.securesms.util.DirectoryHelper;
|
2013-06-29 18:03:55 -07:00
|
|
|
import org.thoughtcrime.securesms.util.DynamicLanguage;
|
2013-06-21 11:56:59 -07:00
|
|
|
import org.thoughtcrime.securesms.util.DynamicTheme;
|
2016-09-25 20:04:13 -07:00
|
|
|
import org.thoughtcrime.securesms.util.ExpirationUtil;
|
2014-02-22 10:54:43 -08:00
|
|
|
import org.thoughtcrime.securesms.util.GroupUtil;
|
2017-06-06 18:03:09 -07:00
|
|
|
import org.thoughtcrime.securesms.util.IdentityUtil;
|
2015-09-04 17:33:22 -07:00
|
|
|
import org.thoughtcrime.securesms.util.MediaUtil;
|
2017-12-05 11:52:03 -08:00
|
|
|
import org.thoughtcrime.securesms.util.ServiceUtil;
|
2013-07-09 18:26:18 -07:00
|
|
|
import org.thoughtcrime.securesms.util.TextSecurePreferences;
|
2014-11-12 11:15:05 -08:00
|
|
|
import org.thoughtcrime.securesms.util.Util;
|
2015-10-13 21:44:01 -07:00
|
|
|
import org.thoughtcrime.securesms.util.ViewUtil;
|
2015-11-09 14:51:53 -08:00
|
|
|
import org.thoughtcrime.securesms.util.concurrent.AssertedSuccessListener;
|
2015-06-22 08:46:43 -07:00
|
|
|
import org.thoughtcrime.securesms.util.concurrent.ListenableFuture;
|
|
|
|
import org.thoughtcrime.securesms.util.concurrent.SettableFuture;
|
2017-01-18 18:46:40 -08:00
|
|
|
import org.thoughtcrime.securesms.util.views.Stub;
|
2016-03-23 10:34:41 -07:00
|
|
|
import org.whispersystems.libsignal.InvalidMessageException;
|
|
|
|
import org.whispersystems.libsignal.util.guava.Optional;
|
Major storage layer refactoring to set the stage for clean GCM.
1) We now try to hand out cursors at a minimum. There has always been
a fairly clean insertion layer that handles encrypting message bodies,
but the process of decrypting message bodies has always been less than
ideal. Here we introduce a "Reader" interface that will decrypt message
bodies when appropriate and return objects that encapsulate record state.
No more MessageDisplayHelper. The MmsSmsDatabase interface is also more
sane.
2) We finally rid ourselves of the technical debt associated with TextSecure's
initial usage of the default SMS DB. In that world, we weren't able to use
anything other than the default "Inbox, Outbox, Sent" types to describe a
message, and had to overload the message content itself with a set of
local "prefixes" to describe what it was (encrypted, asymetric encrypted,
remote encrypted, a key exchange, procssed key exchange), and so on.
This includes a major schema update that transforms the "type" field into
a bitmask that describes everything that used to be encoded in a prefix,
and prefixes have been completely eliminated from the system.
No more Prefix.java
3) Refactoring of the MultipartMessageHandler code. It's less of a mess, and
hopefully more clear as to what's going on.
The next step is to remove what we can from SmsTransportDetails and genericize
that interface for a GCM equivalent.
2013-04-20 12:22:04 -07:00
|
|
|
|
|
|
|
import java.io.IOException;
|
2014-12-12 18:31:20 -08:00
|
|
|
import java.security.NoSuchAlgorithmException;
|
|
|
|
import java.security.SecureRandom;
|
2018-04-26 17:03:54 -07:00
|
|
|
import java.util.Collections;
|
2017-08-01 08:56:00 -07:00
|
|
|
import java.util.LinkedList;
|
Major storage layer refactoring to set the stage for clean GCM.
1) We now try to hand out cursors at a minimum. There has always been
a fairly clean insertion layer that handles encrypting message bodies,
but the process of decrypting message bodies has always been less than
ideal. Here we introduce a "Reader" interface that will decrypt message
bodies when appropriate and return objects that encapsulate record state.
No more MessageDisplayHelper. The MmsSmsDatabase interface is also more
sane.
2) We finally rid ourselves of the technical debt associated with TextSecure's
initial usage of the default SMS DB. In that world, we weren't able to use
anything other than the default "Inbox, Outbox, Sent" types to describe a
message, and had to overload the message content itself with a set of
local "prefixes" to describe what it was (encrypted, asymetric encrypted,
remote encrypted, a key exchange, procssed key exchange), and so on.
This includes a major schema update that transforms the "type" field into
a bitmask that describes everything that used to be encoded in a prefix,
and prefixes have been completely eliminated from the system.
No more Prefix.java
3) Refactoring of the MultipartMessageHandler code. It's less of a mess, and
hopefully more clear as to what's going on.
The next step is to remove what we can from SmsTransportDetails and genericize
that interface for a GCM equivalent.
2013-04-20 12:22:04 -07:00
|
|
|
import java.util.List;
|
2015-11-18 14:52:26 -08:00
|
|
|
import java.util.concurrent.ExecutionException;
|
Major storage layer refactoring to set the stage for clean GCM.
1) We now try to hand out cursors at a minimum. There has always been
a fairly clean insertion layer that handles encrypting message bodies,
but the process of decrypting message bodies has always been less than
ideal. Here we introduce a "Reader" interface that will decrypt message
bodies when appropriate and return objects that encapsulate record state.
No more MessageDisplayHelper. The MmsSmsDatabase interface is also more
sane.
2) We finally rid ourselves of the technical debt associated with TextSecure's
initial usage of the default SMS DB. In that world, we weren't able to use
anything other than the default "Inbox, Outbox, Sent" types to describe a
message, and had to overload the message content itself with a set of
local "prefixes" to describe what it was (encrypted, asymetric encrypted,
remote encrypted, a key exchange, procssed key exchange), and so on.
This includes a major schema update that transforms the "type" field into
a bitmask that describes everything that used to be encoded in a prefix,
and prefixes have been completely eliminated from the system.
No more Prefix.java
3) Refactoring of the MultipartMessageHandler code. It's less of a mess, and
hopefully more clear as to what's going on.
The next step is to remove what we can from SmsTransportDetails and genericize
that interface for a GCM equivalent.
2013-04-20 12:22:04 -07:00
|
|
|
|
2015-03-11 14:23:45 -07:00
|
|
|
import static org.thoughtcrime.securesms.TransportOption.Type;
|
2014-02-22 10:54:43 -08:00
|
|
|
import static org.thoughtcrime.securesms.database.GroupDatabase.GroupRecord;
|
2017-06-06 18:03:09 -07:00
|
|
|
import static org.whispersystems.libsignal.SessionCipher.SESSION_LOCK;
|
2016-03-23 10:34:41 -07:00
|
|
|
import static org.whispersystems.signalservice.internal.push.SignalServiceProtos.GroupContext;
|
2014-02-22 10:54:43 -08:00
|
|
|
|
2012-07-19 14:22:03 -07:00
|
|
|
/**
|
|
|
|
* Activity for displaying a message thread, as well as
|
|
|
|
* composing/sending a new message into that thread.
|
|
|
|
*
|
|
|
|
* @author Moxie Marlinspike
|
|
|
|
*
|
|
|
|
*/
|
2017-11-14 10:49:54 -08:00
|
|
|
@SuppressLint("StaticFieldLeak")
|
2014-06-28 20:40:57 -07:00
|
|
|
public class ConversationActivity extends PassphraseRequiredActionBarActivity
|
2014-04-15 12:43:14 +02:00
|
|
|
implements ConversationFragment.ConversationFragmentListener,
|
2015-02-10 03:15:50 -08:00
|
|
|
AttachmentManager.AttachmentListener,
|
2017-11-24 22:00:30 -08:00
|
|
|
RecipientModifiedListener,
|
2015-06-08 11:07:46 -07:00
|
|
|
OnKeyboardShownListener,
|
2015-11-18 14:52:26 -08:00
|
|
|
AttachmentDrawerListener,
|
2016-12-26 15:14:23 -08:00
|
|
|
InputPanel.Listener,
|
|
|
|
InputPanel.MediaListener
|
2013-04-25 18:59:49 -07:00
|
|
|
{
|
2014-02-18 16:28:54 -08:00
|
|
|
private static final String TAG = ConversationActivity.class.getSimpleName();
|
2012-07-19 14:22:03 -07:00
|
|
|
|
2017-08-01 08:56:00 -07:00
|
|
|
public static final String ADDRESS_EXTRA = "address";
|
2013-04-25 18:59:49 -07:00
|
|
|
public static final String THREAD_ID_EXTRA = "thread_id";
|
2015-12-01 01:38:37 +01:00
|
|
|
public static final String IS_ARCHIVED_EXTRA = "is_archived";
|
2015-11-18 12:54:40 -08:00
|
|
|
public static final String TEXT_EXTRA = "draft_text";
|
2013-04-25 18:59:49 -07:00
|
|
|
public static final String DISTRIBUTION_TYPE_EXTRA = "distribution_type";
|
2017-01-19 11:37:19 -08:00
|
|
|
public static final String TIMING_EXTRA = "timing";
|
2017-02-13 22:35:47 -08:00
|
|
|
public static final String LAST_SEEN_EXTRA = "last_seen";
|
2018-04-06 18:15:24 -07:00
|
|
|
public static final String STARTING_POSITION_EXTRA = "starting_position";
|
2013-02-02 20:37:40 -08:00
|
|
|
|
2018-04-26 17:03:54 -07:00
|
|
|
private static final int PICK_GALLERY = 1;
|
|
|
|
private static final int PICK_DOCUMENT = 2;
|
|
|
|
private static final int PICK_AUDIO = 3;
|
|
|
|
private static final int PICK_CONTACT = 4;
|
|
|
|
private static final int GET_CONTACT_DETAILS = 5;
|
|
|
|
private static final int GROUP_EDIT = 6;
|
|
|
|
private static final int TAKE_PHOTO = 7;
|
|
|
|
private static final int ADD_CONTACT = 8;
|
|
|
|
private static final int PICK_LOCATION = 9;
|
|
|
|
private static final int PICK_GIF = 10;
|
|
|
|
private static final int SMS_DEFAULT = 11;
|
2012-07-19 14:22:03 -07:00
|
|
|
|
2017-10-16 13:11:42 -07:00
|
|
|
private GlideRequests glideRequests;
|
2017-08-22 11:51:01 -07:00
|
|
|
protected ComposeText composeText;
|
|
|
|
private AnimatingToggle buttonToggle;
|
|
|
|
private SendButton sendButton;
|
|
|
|
private ImageButton attachButton;
|
|
|
|
protected ConversationTitleView titleView;
|
|
|
|
private TextView charactersLeft;
|
|
|
|
private ConversationFragment fragment;
|
|
|
|
private Button unblockButton;
|
|
|
|
private Button makeDefaultSmsButton;
|
2017-12-25 15:57:33 -08:00
|
|
|
private Button registerButton;
|
2017-08-22 11:51:01 -07:00
|
|
|
private InputAwareLayout container;
|
|
|
|
private View composePanel;
|
|
|
|
protected Stub<ReminderView> reminderView;
|
|
|
|
private Stub<UnverifiedBannerView> unverifiedBannerView;
|
|
|
|
private Stub<GroupShareProfileView> groupShareProfileView;
|
2012-07-19 14:22:03 -07:00
|
|
|
|
2015-10-28 09:47:09 -07:00
|
|
|
private AttachmentTypeSelector attachmentTypeSelector;
|
|
|
|
private AttachmentManager attachmentManager;
|
2015-11-18 14:52:26 -08:00
|
|
|
private AudioRecorder audioRecorder;
|
2015-10-28 09:47:09 -07:00
|
|
|
private BroadcastReceiver securityUpdateReceiver;
|
2017-01-19 11:31:41 -08:00
|
|
|
private Stub<EmojiDrawer> emojiDrawerStub;
|
2015-11-18 14:52:26 -08:00
|
|
|
protected HidingLinearLayout quickAttachmentToggle;
|
2015-10-28 09:47:09 -07:00
|
|
|
private QuickAttachmentDrawer quickAttachmentDrawer;
|
2015-11-18 14:52:26 -08:00
|
|
|
private InputPanel inputPanel;
|
2012-07-19 14:22:03 -07:00
|
|
|
|
2017-08-01 08:56:00 -07:00
|
|
|
private Recipient recipient;
|
2014-02-17 20:25:40 -08:00
|
|
|
private long threadId;
|
|
|
|
private int distributionType;
|
2015-12-01 01:38:37 +01:00
|
|
|
private boolean archived;
|
2015-09-29 14:26:37 -07:00
|
|
|
private boolean isSecureText;
|
2017-09-06 17:54:32 -07:00
|
|
|
private boolean isDefaultSms = true;
|
|
|
|
private boolean isMmsEnabled = true;
|
|
|
|
private boolean isSecurityInitialized = false;
|
2012-07-19 14:22:03 -07:00
|
|
|
|
2017-06-06 18:03:09 -07:00
|
|
|
private final IdentityRecordList identityRecords = new IdentityRecordList();
|
|
|
|
private final DynamicTheme dynamicTheme = new DynamicTheme();
|
|
|
|
private final DynamicLanguage dynamicLanguage = new DynamicLanguage();
|
2012-07-19 14:22:03 -07:00
|
|
|
|
|
|
|
@Override
|
2014-12-15 12:25:55 -08:00
|
|
|
protected void onPreCreate() {
|
2013-06-21 11:56:59 -07:00
|
|
|
dynamicTheme.onCreate(this);
|
2013-06-29 18:03:55 -07:00
|
|
|
dynamicLanguage.onCreate(this);
|
2014-12-15 12:25:55 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2018-02-01 19:22:48 -08:00
|
|
|
protected void onCreate(Bundle state, boolean ready) {
|
2015-11-02 14:03:38 -08:00
|
|
|
Log.w(TAG, "onCreate()");
|
2012-07-19 14:22:03 -07:00
|
|
|
|
2015-04-16 01:38:33 -04:00
|
|
|
supportRequestWindowFeature(WindowCompat.FEATURE_ACTION_BAR_OVERLAY);
|
2012-07-19 14:22:03 -07:00
|
|
|
setContentView(R.layout.conversation_activity);
|
2015-06-09 07:37:20 -07:00
|
|
|
|
2017-11-13 18:01:05 -08:00
|
|
|
TypedArray typedArray = obtainStyledAttributes(new int[] {R.attr.conversation_background});
|
|
|
|
int color = typedArray.getColor(0, Color.WHITE);
|
|
|
|
typedArray.recycle();
|
|
|
|
|
|
|
|
getWindow().getDecorView().setBackgroundColor(color);
|
|
|
|
|
2018-02-01 19:22:48 -08:00
|
|
|
fragment = initFragment(R.id.fragment_content, new ConversationFragment(), dynamicLanguage.getCurrentLocale());
|
2012-07-19 14:22:03 -07:00
|
|
|
|
|
|
|
initializeReceivers();
|
2015-06-09 07:37:20 -07:00
|
|
|
initializeActionBar();
|
2014-12-24 18:32:51 -08:00
|
|
|
initializeViews();
|
2012-07-19 14:22:03 -07:00
|
|
|
initializeResources();
|
2017-03-14 13:24:24 -07:00
|
|
|
initializeSecurity(false, isDefaultSms).addListener(new AssertedSuccessListener<Boolean>() {
|
2015-10-01 17:46:47 -07:00
|
|
|
@Override
|
|
|
|
public void onSuccess(Boolean result) {
|
2017-06-14 09:53:22 -07:00
|
|
|
initializeProfiles();
|
2015-10-01 17:46:47 -07:00
|
|
|
initializeDraft();
|
|
|
|
}
|
|
|
|
});
|
2012-07-19 14:22:03 -07:00
|
|
|
}
|
|
|
|
|
2013-02-03 18:41:34 -08:00
|
|
|
@Override
|
2014-12-24 18:32:51 -08:00
|
|
|
protected void onNewIntent(Intent intent) {
|
2014-12-15 12:25:55 -08:00
|
|
|
Log.w(TAG, "onNewIntent()");
|
2016-01-30 15:33:47 -08:00
|
|
|
|
|
|
|
if (isFinishing()) {
|
|
|
|
Log.w(TAG, "Activity is finishing...");
|
|
|
|
return;
|
|
|
|
}
|
2014-12-15 12:25:55 -08:00
|
|
|
|
2014-12-24 18:32:51 -08:00
|
|
|
if (!Util.isEmpty(composeText) || attachmentManager.isAttachmentPresent()) {
|
|
|
|
saveDraft();
|
2017-10-16 13:11:42 -07:00
|
|
|
attachmentManager.clear(glideRequests, false);
|
2014-12-24 18:32:51 -08:00
|
|
|
composeText.setText("");
|
|
|
|
}
|
|
|
|
|
|
|
|
setIntent(intent);
|
|
|
|
initializeResources();
|
2017-03-14 13:24:24 -07:00
|
|
|
initializeSecurity(false, isDefaultSms).addListener(new AssertedSuccessListener<Boolean>() {
|
2015-10-01 17:46:47 -07:00
|
|
|
@Override
|
|
|
|
public void onSuccess(Boolean result) {
|
|
|
|
initializeDraft();
|
|
|
|
}
|
|
|
|
});
|
2014-10-08 21:11:02 +03:00
|
|
|
|
2014-12-24 18:32:51 -08:00
|
|
|
if (fragment != null) {
|
|
|
|
fragment.onNewIntent();
|
|
|
|
}
|
2013-02-03 18:41:34 -08:00
|
|
|
}
|
|
|
|
|
2017-02-17 20:43:24 -08:00
|
|
|
@Override
|
|
|
|
protected void onStart() {
|
|
|
|
super.onStart();
|
|
|
|
EventBus.getDefault().register(this);
|
|
|
|
}
|
|
|
|
|
2012-07-19 14:22:03 -07:00
|
|
|
@Override
|
|
|
|
protected void onResume() {
|
|
|
|
super.onResume();
|
2013-06-21 11:56:59 -07:00
|
|
|
dynamicTheme.onResume(this);
|
2013-06-29 18:03:55 -07:00
|
|
|
dynamicLanguage.onResume(this);
|
2015-04-16 01:38:33 -04:00
|
|
|
quickAttachmentDrawer.onResume();
|
2013-06-21 11:56:59 -07:00
|
|
|
|
2014-02-22 10:54:43 -08:00
|
|
|
initializeEnabledCheck();
|
2013-03-04 17:43:04 -08:00
|
|
|
initializeMmsEnabledCheck();
|
2017-06-06 18:03:09 -07:00
|
|
|
initializeIdentityRecords();
|
2015-07-20 19:25:54 -07:00
|
|
|
composeText.setTransport(sendButton.getSelectedTransport());
|
2015-06-09 07:37:20 -07:00
|
|
|
|
2017-10-16 13:11:42 -07:00
|
|
|
titleView.setTitle(glideRequests, recipient);
|
2017-08-01 08:56:00 -07:00
|
|
|
setActionBarColor(recipient.getColor());
|
|
|
|
setBlockedUserState(recipient, isSecureText, isDefaultSms);
|
2017-08-22 11:51:01 -07:00
|
|
|
setGroupShareProfileReminder(recipient);
|
2012-07-19 14:22:03 -07:00
|
|
|
calculateCharactersRemaining();
|
2013-02-03 18:41:34 -08:00
|
|
|
|
|
|
|
MessageNotifier.setVisibleThread(threadId);
|
|
|
|
markThreadAsRead();
|
2017-01-19 11:37:19 -08:00
|
|
|
|
|
|
|
Log.w(TAG, "onResume() Finished: " + (System.currentTimeMillis() - getIntent().getLongExtra(TIMING_EXTRA, 0)));
|
2012-07-19 14:22:03 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2013-03-04 17:43:04 -08:00
|
|
|
protected void onPause() {
|
|
|
|
super.onPause();
|
|
|
|
MessageNotifier.setVisibleThread(-1L);
|
2014-04-08 10:45:55 -07:00
|
|
|
if (isFinishing()) overridePendingTransition(R.anim.fade_scale_in, R.anim.slide_to_right);
|
2015-04-16 01:38:33 -04:00
|
|
|
quickAttachmentDrawer.onPause();
|
2015-11-18 14:52:26 -08:00
|
|
|
inputPanel.onPause();
|
|
|
|
|
2017-02-13 22:35:47 -08:00
|
|
|
fragment.setLastSeen(System.currentTimeMillis());
|
|
|
|
markLastSeen();
|
2015-10-23 17:00:51 -07:00
|
|
|
AudioSlidePlayer.stopAll();
|
2017-02-17 20:43:24 -08:00
|
|
|
EventBus.getDefault().unregister(this);
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
protected void onStop() {
|
|
|
|
super.onStop();
|
|
|
|
EventBus.getDefault().unregister(this);
|
2012-07-19 14:22:03 -07:00
|
|
|
}
|
|
|
|
|
2015-09-23 15:47:48 -07:00
|
|
|
@Override
|
|
|
|
public void onConfigurationChanged(Configuration newConfig) {
|
2015-07-24 13:22:28 -07:00
|
|
|
Log.w(TAG, "onConfigurationChanged(" + newConfig.orientation + ")");
|
2015-06-08 11:07:46 -07:00
|
|
|
super.onConfigurationChanged(newConfig);
|
2015-07-20 19:25:54 -07:00
|
|
|
composeText.setTransport(sendButton.getSelectedTransport());
|
2015-06-08 11:07:46 -07:00
|
|
|
quickAttachmentDrawer.onConfigurationChanged();
|
2017-01-19 11:31:41 -08:00
|
|
|
|
|
|
|
if (emojiDrawerStub.resolved() && container.getCurrentInput() == emojiDrawerStub.get()) {
|
|
|
|
container.hideAttachedInput(true);
|
|
|
|
}
|
2015-06-08 11:07:46 -07:00
|
|
|
}
|
|
|
|
|
2012-07-19 14:22:03 -07:00
|
|
|
@Override
|
|
|
|
protected void onDestroy() {
|
2014-12-24 18:32:51 -08:00
|
|
|
saveDraft();
|
2017-08-01 08:56:00 -07:00
|
|
|
if (recipient != null) recipient.removeListener(this);
|
2016-08-15 20:23:56 -07:00
|
|
|
if (securityUpdateReceiver != null) unregisterReceiver(securityUpdateReceiver);
|
2012-07-19 14:22:03 -07:00
|
|
|
super.onDestroy();
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2015-12-18 14:37:11 -08:00
|
|
|
public void onActivityResult(final int reqCode, int resultCode, Intent data) {
|
2014-02-23 21:18:08 -08:00
|
|
|
Log.w(TAG, "onActivityResult called: " + reqCode + ", " + resultCode + " , " + data);
|
2012-07-19 14:22:03 -07:00
|
|
|
super.onActivityResult(reqCode, resultCode, data);
|
|
|
|
|
2017-03-15 02:05:48 +01:00
|
|
|
if ((data == null && reqCode != TAKE_PHOTO && reqCode != SMS_DEFAULT) ||
|
|
|
|
(resultCode != RESULT_OK && reqCode != SMS_DEFAULT))
|
|
|
|
{
|
|
|
|
return;
|
|
|
|
}
|
2015-05-18 10:26:32 -07:00
|
|
|
|
2012-07-19 14:22:03 -07:00
|
|
|
switch (reqCode) {
|
2017-04-18 16:33:03 -07:00
|
|
|
case PICK_GALLERY:
|
|
|
|
MediaType mediaType;
|
|
|
|
|
|
|
|
String mimeType = MediaUtil.getMimeType(this, data.getData());
|
|
|
|
|
|
|
|
if (MediaUtil.isGif(mimeType)) mediaType = MediaType.GIF;
|
|
|
|
else if (MediaUtil.isVideo(mimeType)) mediaType = MediaType.VIDEO;
|
|
|
|
else mediaType = MediaType.IMAGE;
|
|
|
|
|
|
|
|
setMedia(data.getData(), mediaType);
|
2018-03-20 11:27:11 -07:00
|
|
|
|
2012-07-19 14:22:03 -07:00
|
|
|
break;
|
2017-04-18 16:33:03 -07:00
|
|
|
case PICK_DOCUMENT:
|
|
|
|
setMedia(data.getData(), MediaType.DOCUMENT);
|
2012-07-19 14:22:03 -07:00
|
|
|
break;
|
|
|
|
case PICK_AUDIO:
|
2015-10-15 14:40:45 -07:00
|
|
|
setMedia(data.getData(), MediaType.AUDIO);
|
2012-07-19 14:22:03 -07:00
|
|
|
break;
|
2018-04-26 17:03:54 -07:00
|
|
|
case PICK_CONTACT:
|
2018-05-21 10:44:30 -04:00
|
|
|
// TODO(greyson): Re-enable shared contact sending after receiving has been enabled for a few releases
|
2018-05-21 19:57:50 -04:00
|
|
|
addAttachmentContactInfo(data.getData());
|
|
|
|
// if (isSecureText && !isSmsForced()) {
|
|
|
|
// openContactShareEditor(data.getData());
|
|
|
|
// } else {
|
|
|
|
// addAttachmentContactInfo(data.getData());
|
|
|
|
// }
|
2018-04-26 17:03:54 -07:00
|
|
|
break;
|
|
|
|
case GET_CONTACT_DETAILS:
|
|
|
|
sendSharedContact(data.getParcelableArrayListExtra(ContactShareEditActivity.KEY_CONTACTS));
|
2013-10-17 02:28:36 +02:00
|
|
|
break;
|
2014-02-20 15:41:52 -08:00
|
|
|
case GROUP_EDIT:
|
2017-10-16 13:11:42 -07:00
|
|
|
recipient = Recipient.from(this, data.getParcelableExtra(GroupCreateActivity.GROUP_ADDRESS_EXTRA), true);
|
2017-08-01 08:56:00 -07:00
|
|
|
recipient.addListener(this);
|
2017-10-16 13:11:42 -07:00
|
|
|
titleView.setTitle(glideRequests, recipient);
|
2017-08-01 08:56:00 -07:00
|
|
|
setBlockedUserState(recipient, isSecureText, isDefaultSms);
|
2015-06-09 07:37:20 -07:00
|
|
|
supportInvalidateOptionsMenu();
|
2014-02-20 15:41:52 -08:00
|
|
|
break;
|
2015-07-10 18:45:55 -07:00
|
|
|
case TAKE_PHOTO:
|
|
|
|
if (attachmentManager.getCaptureUri() != null) {
|
2015-10-15 14:40:45 -07:00
|
|
|
setMedia(attachmentManager.getCaptureUri(), MediaType.IMAGE);
|
2015-07-10 18:45:55 -07:00
|
|
|
}
|
|
|
|
break;
|
2015-10-16 15:39:27 +02:00
|
|
|
case ADD_CONTACT:
|
2017-08-21 18:32:38 -07:00
|
|
|
recipient = Recipient.from(this, recipient.getAddress(), true);
|
2017-08-01 08:56:00 -07:00
|
|
|
recipient.addListener(this);
|
2015-10-16 15:39:27 +02:00
|
|
|
fragment.reloadList();
|
|
|
|
break;
|
2015-12-18 14:37:11 -08:00
|
|
|
case PICK_LOCATION:
|
2016-01-04 13:02:22 -08:00
|
|
|
SignalPlace place = new SignalPlace(PlacePicker.getPlace(data, this));
|
2018-01-24 19:17:44 -08:00
|
|
|
attachmentManager.setLocation(place, getCurrentMediaConstraints());
|
2015-12-18 14:37:11 -08:00
|
|
|
break;
|
2016-10-16 19:05:07 -07:00
|
|
|
case PICK_GIF:
|
2018-03-20 11:27:11 -07:00
|
|
|
setMedia(data.getData(),
|
|
|
|
MediaType.GIF,
|
|
|
|
data.getIntExtra(GiphyActivity.EXTRA_WIDTH, 0),
|
|
|
|
data.getIntExtra(GiphyActivity.EXTRA_HEIGHT, 0));
|
2016-10-16 19:05:07 -07:00
|
|
|
break;
|
2016-12-08 14:20:38 -08:00
|
|
|
case ScribbleActivity.SCRIBBLE_REQUEST_CODE:
|
|
|
|
setMedia(data.getData(), MediaType.IMAGE);
|
|
|
|
break;
|
2017-01-18 11:01:13 -08:00
|
|
|
case SMS_DEFAULT:
|
2017-03-14 13:24:24 -07:00
|
|
|
initializeSecurity(isSecureText, isDefaultSms);
|
2017-01-18 11:01:13 -08:00
|
|
|
break;
|
2012-07-19 14:22:03 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-03-29 17:52:54 -05:00
|
|
|
@Override
|
|
|
|
public void startActivity(Intent intent) {
|
|
|
|
if (intent.getStringExtra(Browser.EXTRA_APPLICATION_ID) != null) {
|
|
|
|
intent.removeExtra(Browser.EXTRA_APPLICATION_ID);
|
|
|
|
}
|
2016-08-14 12:23:51 +02:00
|
|
|
|
|
|
|
try {
|
|
|
|
super.startActivity(intent);
|
|
|
|
} catch (ActivityNotFoundException e) {
|
|
|
|
Log.w(TAG, e);
|
|
|
|
Toast.makeText(this, R.string.ConversationActivity_there_is_no_app_available_to_handle_this_link_on_your_device, Toast.LENGTH_LONG).show();
|
|
|
|
}
|
2016-03-29 17:52:54 -05:00
|
|
|
}
|
|
|
|
|
2012-07-19 14:22:03 -07:00
|
|
|
@Override
|
|
|
|
public boolean onPrepareOptionsMenu(Menu menu) {
|
2014-06-28 20:40:57 -07:00
|
|
|
MenuInflater inflater = this.getMenuInflater();
|
2012-07-19 14:22:03 -07:00
|
|
|
menu.clear();
|
|
|
|
|
2016-09-25 20:04:13 -07:00
|
|
|
if (isSecureText) {
|
2017-08-01 08:56:00 -07:00
|
|
|
if (recipient.getExpireMessages() > 0) {
|
2016-09-25 20:04:13 -07:00
|
|
|
inflater.inflate(R.menu.conversation_expiring_on, menu);
|
|
|
|
|
|
|
|
final MenuItem item = menu.findItem(R.id.menu_expiring_messages);
|
|
|
|
final View actionView = MenuItemCompat.getActionView(item);
|
2017-12-05 11:52:03 -08:00
|
|
|
final TextView badgeView = actionView.findViewById(R.id.expiration_badge);
|
2016-09-25 20:04:13 -07:00
|
|
|
|
2017-08-01 08:56:00 -07:00
|
|
|
badgeView.setText(ExpirationUtil.getExpirationAbbreviatedDisplayValue(this, recipient.getExpireMessages()));
|
2017-12-05 11:52:03 -08:00
|
|
|
actionView.setOnClickListener(v -> onOptionsItemSelected(item));
|
2016-09-25 20:04:13 -07:00
|
|
|
} else {
|
|
|
|
inflater.inflate(R.menu.conversation_expiring_off, menu);
|
|
|
|
}
|
|
|
|
}
|
2016-08-15 20:23:56 -07:00
|
|
|
|
2012-08-07 19:03:28 -07:00
|
|
|
if (isSingleConversation()) {
|
2016-11-09 09:37:40 -08:00
|
|
|
if (isSecureText) inflater.inflate(R.menu.conversation_callable_secure, menu);
|
|
|
|
else inflater.inflate(R.menu.conversation_callable_insecure, menu);
|
2012-10-21 14:34:09 -07:00
|
|
|
} else if (isGroupConversation()) {
|
|
|
|
inflater.inflate(R.menu.conversation_group_options, menu);
|
2013-04-25 18:59:49 -07:00
|
|
|
|
2014-02-17 20:25:40 -08:00
|
|
|
if (!isPushGroupConversation()) {
|
|
|
|
inflater.inflate(R.menu.conversation_mms_group_options, menu);
|
|
|
|
if (distributionType == ThreadDatabase.DistributionTypes.BROADCAST) {
|
|
|
|
menu.findItem(R.id.menu_distribution_broadcast).setChecked(true);
|
|
|
|
} else {
|
|
|
|
menu.findItem(R.id.menu_distribution_conversation).setChecked(true);
|
|
|
|
}
|
2014-02-22 10:54:43 -08:00
|
|
|
} else if (isActiveGroup()) {
|
2014-02-20 15:41:52 -08:00
|
|
|
inflater.inflate(R.menu.conversation_push_group_options, menu);
|
2013-04-25 18:59:49 -07:00
|
|
|
}
|
2012-08-07 19:03:28 -07:00
|
|
|
}
|
|
|
|
|
2012-07-19 14:22:03 -07:00
|
|
|
inflater.inflate(R.menu.conversation, menu);
|
2014-06-04 01:24:44 +02:00
|
|
|
|
2015-09-29 14:26:37 -07:00
|
|
|
if (isSingleConversation() && isSecureText) {
|
|
|
|
inflater.inflate(R.menu.conversation_secure, menu);
|
|
|
|
} else if (isSingleConversation()) {
|
|
|
|
inflater.inflate(R.menu.conversation_insecure, menu);
|
|
|
|
}
|
|
|
|
|
2017-08-01 08:56:00 -07:00
|
|
|
if (recipient != null && recipient.isMuted()) inflater.inflate(R.menu.conversation_muted, menu);
|
|
|
|
else inflater.inflate(R.menu.conversation_unmuted, menu);
|
2015-06-09 07:37:20 -07:00
|
|
|
|
2017-08-01 08:56:00 -07:00
|
|
|
if (isSingleConversation() && getRecipient().getContactUri() == null) {
|
2014-06-04 01:24:44 +02:00
|
|
|
inflater.inflate(R.menu.conversation_add_to_contacts, menu);
|
|
|
|
}
|
|
|
|
|
2012-07-19 14:22:03 -07:00
|
|
|
super.onPrepareOptionsMenu(menu);
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public boolean onOptionsItemSelected(MenuItem item) {
|
|
|
|
super.onOptionsItemSelected(item);
|
|
|
|
switch (item.getItemId()) {
|
2015-09-29 14:26:37 -07:00
|
|
|
case R.id.menu_call_secure:
|
2017-08-01 08:56:00 -07:00
|
|
|
case R.id.menu_call_insecure: handleDial(getRecipient()); return true;
|
2013-04-25 18:59:49 -07:00
|
|
|
case R.id.menu_add_attachment: handleAddAttachment(); return true;
|
2015-01-18 16:11:30 -10:00
|
|
|
case R.id.menu_view_media: handleViewMedia(); return true;
|
2014-06-04 01:24:44 +02:00
|
|
|
case R.id.menu_add_to_contacts: handleAddToContacts(); return true;
|
2015-10-04 12:13:34 +09:00
|
|
|
case R.id.menu_reset_secure_session: handleResetSecureSession(); return true;
|
2013-04-25 18:59:49 -07:00
|
|
|
case R.id.menu_group_recipients: handleDisplayGroupRecipients(); return true;
|
|
|
|
case R.id.menu_distribution_broadcast: handleDistributionBroadcastEnabled(item); return true;
|
|
|
|
case R.id.menu_distribution_conversation: handleDistributionConversationEnabled(item); return true;
|
2014-02-20 15:41:52 -08:00
|
|
|
case R.id.menu_edit_group: handleEditPushGroup(); return true;
|
|
|
|
case R.id.menu_leave: handleLeavePushGroup(); return true;
|
2014-12-12 18:31:20 -08:00
|
|
|
case R.id.menu_invite: handleInviteLink(); return true;
|
2015-06-09 07:37:20 -07:00
|
|
|
case R.id.menu_mute_notifications: handleMuteNotifications(); return true;
|
|
|
|
case R.id.menu_unmute_notifications: handleUnmuteNotifications(); return true;
|
2015-07-08 12:22:51 -07:00
|
|
|
case R.id.menu_conversation_settings: handleConversationSettings(); return true;
|
2016-08-15 20:23:56 -07:00
|
|
|
case R.id.menu_expiring_messages_off:
|
|
|
|
case R.id.menu_expiring_messages: handleSelectMessageExpiration(); return true;
|
2013-04-25 18:59:49 -07:00
|
|
|
case android.R.id.home: handleReturnToConversationList(); return true;
|
2012-07-19 14:22:03 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2013-06-27 20:57:27 -07:00
|
|
|
@Override
|
|
|
|
public void onBackPressed() {
|
2015-07-13 15:45:14 -07:00
|
|
|
Log.w(TAG, "onBackPressed()");
|
2015-07-24 13:22:28 -07:00
|
|
|
if (container.isInputOpen()) container.hideCurrentInput(composeText);
|
|
|
|
else super.onBackPressed();
|
2013-06-27 20:57:27 -07:00
|
|
|
}
|
|
|
|
|
2015-07-02 16:47:03 -07:00
|
|
|
@Override
|
|
|
|
public void onKeyboardShown() {
|
2015-11-22 10:44:53 -08:00
|
|
|
inputPanel.onKeyboardShown();
|
2015-07-02 16:47:03 -07:00
|
|
|
}
|
|
|
|
|
2017-11-15 16:29:00 -08:00
|
|
|
@Subscribe(threadMode = ThreadMode.MAIN)
|
|
|
|
public void onEvent(ReminderUpdateEvent event) {
|
|
|
|
updateReminders(recipient.hasSeenInviteReminder());
|
|
|
|
}
|
|
|
|
|
2017-11-24 22:00:30 -08:00
|
|
|
@Override
|
|
|
|
public void onRequestPermissionsResult(int requestCode, @NonNull String[] permissions, @NonNull int[] grantResults) {
|
|
|
|
Permissions.onRequestPermissionsResult(this, requestCode, permissions, grantResults);
|
|
|
|
}
|
|
|
|
|
2012-07-19 14:22:03 -07:00
|
|
|
//////// Event Handlers
|
|
|
|
|
2013-02-17 11:42:30 -08:00
|
|
|
private void handleReturnToConversationList() {
|
2015-12-01 01:38:37 +01:00
|
|
|
Intent intent = new Intent(this, (archived ? ConversationListArchiveActivity.class : ConversationListActivity.class));
|
2013-02-17 11:42:30 -08:00
|
|
|
intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
|
|
|
|
startActivity(intent);
|
|
|
|
finish();
|
|
|
|
}
|
|
|
|
|
2016-08-15 20:23:56 -07:00
|
|
|
private void handleSelectMessageExpiration() {
|
2017-01-03 13:36:34 -08:00
|
|
|
if (isPushGroupConversation() && !isActiveGroup()) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2017-12-05 11:52:03 -08:00
|
|
|
//noinspection CodeBlock2Expr
|
|
|
|
ExpirationDialog.show(this, recipient.getExpireMessages(), expirationTime -> {
|
|
|
|
new AsyncTask<Void, Void, Void>() {
|
|
|
|
@Override
|
|
|
|
protected Void doInBackground(Void... params) {
|
|
|
|
DatabaseFactory.getRecipientDatabase(ConversationActivity.this).setExpireMessages(recipient, expirationTime);
|
2018-01-12 11:39:10 +00:00
|
|
|
OutgoingExpirationUpdateMessage outgoingMessage = new OutgoingExpirationUpdateMessage(getRecipient(), System.currentTimeMillis(), expirationTime * 1000L);
|
2018-01-24 19:17:44 -08:00
|
|
|
MessageSender.send(ConversationActivity.this, outgoingMessage, threadId, false, null);
|
2016-08-15 20:23:56 -07:00
|
|
|
|
2017-12-05 11:52:03 -08:00
|
|
|
return null;
|
|
|
|
}
|
2017-02-13 22:35:47 -08:00
|
|
|
|
2017-12-05 11:52:03 -08:00
|
|
|
@Override
|
|
|
|
protected void onPostExecute(Void result) {
|
|
|
|
invalidateOptionsMenu();
|
|
|
|
if (fragment != null) fragment.setLastSeen(0);
|
|
|
|
}
|
|
|
|
}.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
|
2016-08-15 20:23:56 -07:00
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2015-06-09 07:37:20 -07:00
|
|
|
private void handleMuteNotifications() {
|
2017-12-05 11:52:03 -08:00
|
|
|
MuteDialog.show(this, until -> {
|
|
|
|
recipient.setMuted(until);
|
2015-06-09 07:37:20 -07:00
|
|
|
|
2017-12-05 11:52:03 -08:00
|
|
|
new AsyncTask<Void, Void, Void>() {
|
|
|
|
@Override
|
|
|
|
protected Void doInBackground(Void... params) {
|
|
|
|
DatabaseFactory.getRecipientDatabase(ConversationActivity.this)
|
|
|
|
.setMuted(recipient, until);
|
2015-06-09 07:37:20 -07:00
|
|
|
|
2017-12-05 11:52:03 -08:00
|
|
|
return null;
|
|
|
|
}
|
|
|
|
}.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
|
2015-06-09 07:37:20 -07:00
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2015-07-08 12:22:51 -07:00
|
|
|
private void handleConversationSettings() {
|
2017-10-03 16:27:12 -07:00
|
|
|
Intent intent = new Intent(ConversationActivity.this, RecipientPreferenceActivity.class);
|
|
|
|
intent.putExtra(RecipientPreferenceActivity.ADDRESS_EXTRA, recipient.getAddress());
|
|
|
|
intent.putExtra(RecipientPreferenceActivity.CAN_HAVE_SAFETY_NUMBER_EXTRA,
|
|
|
|
isSecureText && !isSelfConversation());
|
|
|
|
|
|
|
|
startActivitySceneTransition(intent, titleView.findViewById(R.id.contact_photo_image), "avatar");
|
2015-07-08 12:22:51 -07:00
|
|
|
}
|
|
|
|
|
2015-06-09 07:37:20 -07:00
|
|
|
private void handleUnmuteNotifications() {
|
2017-08-01 08:56:00 -07:00
|
|
|
recipient.setMuted(0);
|
2015-06-09 07:37:20 -07:00
|
|
|
|
|
|
|
new AsyncTask<Void, Void, Void>() {
|
|
|
|
@Override
|
|
|
|
protected Void doInBackground(Void... params) {
|
2017-08-21 18:47:37 -07:00
|
|
|
DatabaseFactory.getRecipientDatabase(ConversationActivity.this)
|
2017-08-01 08:56:00 -07:00
|
|
|
.setMuted(recipient, 0);
|
2015-06-09 07:37:20 -07:00
|
|
|
|
|
|
|
return null;
|
|
|
|
}
|
2017-10-23 13:03:32 -07:00
|
|
|
}.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
|
2015-06-09 07:37:20 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
private void handleUnblock() {
|
2017-12-05 11:52:03 -08:00
|
|
|
//noinspection CodeBlock2Expr
|
2015-05-20 23:36:30 +02:00
|
|
|
new AlertDialog.Builder(this)
|
2016-09-17 17:00:11 +02:00
|
|
|
.setTitle(R.string.ConversationActivity_unblock_this_contact_question)
|
|
|
|
.setMessage(R.string.ConversationActivity_you_will_once_again_be_able_to_receive_messages_and_calls_from_this_contact)
|
2015-06-09 07:37:20 -07:00
|
|
|
.setNegativeButton(android.R.string.cancel, null)
|
2017-12-05 11:52:03 -08:00
|
|
|
.setPositiveButton(R.string.ConversationActivity_unblock, (dialog, which) -> {
|
|
|
|
new AsyncTask<Void, Void, Void>() {
|
|
|
|
@Override
|
|
|
|
protected Void doInBackground(Void... params) {
|
|
|
|
DatabaseFactory.getRecipientDatabase(ConversationActivity.this)
|
|
|
|
.setBlocked(recipient, false);
|
2016-08-26 16:53:23 -07:00
|
|
|
|
2017-12-05 11:52:03 -08:00
|
|
|
ApplicationContext.getInstance(ConversationActivity.this)
|
|
|
|
.getJobManager()
|
|
|
|
.add(new MultiDeviceBlockedUpdateJob(ConversationActivity.this));
|
2016-08-26 16:53:23 -07:00
|
|
|
|
2017-12-05 11:52:03 -08:00
|
|
|
return null;
|
|
|
|
}
|
|
|
|
}.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
|
2015-06-09 07:37:20 -07:00
|
|
|
}).show();
|
|
|
|
}
|
|
|
|
|
2016-11-20 15:56:47 -08:00
|
|
|
@TargetApi(Build.VERSION_CODES.KITKAT)
|
|
|
|
private void handleMakeDefaultSms() {
|
|
|
|
Intent intent = new Intent(Telephony.Sms.Intents.ACTION_CHANGE_DEFAULT);
|
|
|
|
intent.putExtra(Telephony.Sms.Intents.EXTRA_PACKAGE_NAME, getPackageName());
|
2017-01-18 11:01:13 -08:00
|
|
|
startActivityForResult(intent, SMS_DEFAULT);
|
2016-11-20 15:56:47 -08:00
|
|
|
}
|
|
|
|
|
2017-12-25 15:57:33 -08:00
|
|
|
private void handleRegisterForSignal() {
|
|
|
|
Intent intent = new Intent(this, RegistrationActivity.class);
|
2018-03-11 17:12:42 -07:00
|
|
|
intent.putExtra(RegistrationActivity.RE_REGISTRATION_EXTRA, true);
|
2017-12-25 15:57:33 -08:00
|
|
|
startActivity(intent);
|
|
|
|
}
|
|
|
|
|
2014-12-12 18:31:20 -08:00
|
|
|
private void handleInviteLink() {
|
|
|
|
try {
|
2017-03-16 14:32:08 +01:00
|
|
|
String inviteText;
|
|
|
|
|
2014-12-12 18:31:20 -08:00
|
|
|
boolean a = SecureRandom.getInstance("SHA1PRNG").nextBoolean();
|
2017-03-16 14:32:08 +01:00
|
|
|
if (a) inviteText = getString(R.string.ConversationActivity_lets_switch_to_signal, "https://sgnl.link/1LoIMUl");
|
|
|
|
else inviteText = getString(R.string.ConversationActivity_lets_use_this_to_chat, "https://sgnl.link/1MF56H1");
|
|
|
|
|
|
|
|
if (isDefaultSms) {
|
|
|
|
composeText.appendInvite(inviteText);
|
|
|
|
} else {
|
|
|
|
Intent intent = new Intent(Intent.ACTION_SENDTO);
|
2017-08-01 08:56:00 -07:00
|
|
|
intent.setData(Uri.parse("smsto:" + recipient.getAddress().serialize()));
|
2017-03-16 14:32:08 +01:00
|
|
|
intent.putExtra("sms_body", inviteText);
|
|
|
|
intent.putExtra(Intent.EXTRA_TEXT, inviteText);
|
|
|
|
startActivity(intent);
|
|
|
|
}
|
2014-12-12 18:31:20 -08:00
|
|
|
} catch (NoSuchAlgorithmException e) {
|
|
|
|
throw new AssertionError(e);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-10-04 12:13:34 +09:00
|
|
|
private void handleResetSecureSession() {
|
2015-05-20 23:36:30 +02:00
|
|
|
AlertDialog.Builder builder = new AlertDialog.Builder(this);
|
2015-11-20 01:05:31 +09:00
|
|
|
builder.setTitle(R.string.ConversationActivity_reset_secure_session_question);
|
2015-03-24 13:44:22 +01:00
|
|
|
builder.setIconAttribute(R.attr.dialog_alert_icon);
|
2012-07-19 14:22:03 -07:00
|
|
|
builder.setCancelable(true);
|
2015-11-20 01:05:31 +09:00
|
|
|
builder.setMessage(R.string.ConversationActivity_this_may_help_if_youre_having_encryption_problems);
|
2017-12-05 11:52:03 -08:00
|
|
|
builder.setPositiveButton(R.string.ConversationActivity_reset, (dialog, which) -> {
|
|
|
|
if (isSingleConversation()) {
|
|
|
|
final Context context = getApplicationContext();
|
2014-04-22 14:33:29 -07:00
|
|
|
|
2017-12-05 11:52:03 -08:00
|
|
|
OutgoingEndSessionMessage endSessionMessage =
|
|
|
|
new OutgoingEndSessionMessage(new OutgoingTextMessage(getRecipient(), "TERMINATE", 0, -1));
|
2014-04-22 14:33:29 -07:00
|
|
|
|
2017-12-05 11:52:03 -08:00
|
|
|
new AsyncTask<OutgoingEndSessionMessage, Void, Long>() {
|
|
|
|
@Override
|
|
|
|
protected Long doInBackground(OutgoingEndSessionMessage... messages) {
|
2018-01-24 19:17:44 -08:00
|
|
|
return MessageSender.send(context, messages[0], threadId, false, null);
|
2017-12-05 11:52:03 -08:00
|
|
|
}
|
2014-11-08 11:35:58 -08:00
|
|
|
|
2017-12-05 11:52:03 -08:00
|
|
|
@Override
|
|
|
|
protected void onPostExecute(Long result) {
|
|
|
|
sendComplete(result);
|
|
|
|
}
|
|
|
|
}.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR, endSessionMessage);
|
2012-07-19 14:22:03 -07:00
|
|
|
}
|
|
|
|
});
|
2015-11-20 01:05:31 +09:00
|
|
|
builder.setNegativeButton(android.R.string.cancel, null);
|
2012-07-19 14:22:03 -07:00
|
|
|
builder.show();
|
|
|
|
}
|
|
|
|
|
2015-01-18 16:11:30 -10:00
|
|
|
private void handleViewMedia() {
|
|
|
|
Intent intent = new Intent(this, MediaOverviewActivity.class);
|
2017-08-01 08:56:00 -07:00
|
|
|
intent.putExtra(MediaOverviewActivity.ADDRESS_EXTRA, recipient.getAddress());
|
2015-01-18 16:11:30 -10:00
|
|
|
startActivity(intent);
|
|
|
|
}
|
|
|
|
|
2014-02-22 10:54:43 -08:00
|
|
|
private void handleLeavePushGroup() {
|
2017-08-01 08:56:00 -07:00
|
|
|
if (getRecipient() == null) {
|
2014-02-22 10:54:43 -08:00
|
|
|
Toast.makeText(this, getString(R.string.ConversationActivity_invalid_recipient),
|
|
|
|
Toast.LENGTH_LONG).show();
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2015-05-20 23:36:30 +02:00
|
|
|
AlertDialog.Builder builder = new AlertDialog.Builder(this);
|
2014-02-22 10:54:43 -08:00
|
|
|
builder.setTitle(getString(R.string.ConversationActivity_leave_group));
|
2015-03-24 13:44:22 +01:00
|
|
|
builder.setIconAttribute(R.attr.dialog_info_icon);
|
2014-02-22 10:54:43 -08:00
|
|
|
builder.setCancelable(true);
|
|
|
|
builder.setMessage(getString(R.string.ConversationActivity_are_you_sure_you_want_to_leave_this_group));
|
2017-12-05 11:52:03 -08:00
|
|
|
builder.setPositiveButton(R.string.yes, (dialog, which) -> {
|
|
|
|
Context self = ConversationActivity.this;
|
|
|
|
|
|
|
|
try {
|
|
|
|
String groupId = getRecipient().getAddress().toGroupString();
|
|
|
|
DatabaseFactory.getGroupDatabase(self).setActive(groupId, false);
|
|
|
|
|
|
|
|
GroupContext context = GroupContext.newBuilder()
|
|
|
|
.setId(ByteString.copyFrom(GroupUtil.getDecodedId(groupId)))
|
|
|
|
.setType(GroupContext.Type.QUIT)
|
|
|
|
.build();
|
|
|
|
|
2018-04-26 17:03:54 -07:00
|
|
|
OutgoingGroupMediaMessage outgoingMessage = new OutgoingGroupMediaMessage(getRecipient(), context, null, System.currentTimeMillis(), 0, null, Collections.emptyList());
|
2018-01-24 19:17:44 -08:00
|
|
|
MessageSender.send(self, outgoingMessage, threadId, false, null);
|
2017-12-05 11:52:03 -08:00
|
|
|
DatabaseFactory.getGroupDatabase(self).remove(groupId, Address.fromSerialized(TextSecurePreferences.getLocalNumber(self)));
|
|
|
|
initializeEnabledCheck();
|
|
|
|
} catch (IOException e) {
|
|
|
|
Log.w(TAG, e);
|
|
|
|
Toast.makeText(self, R.string.ConversationActivity_error_leaving_group, Toast.LENGTH_LONG).show();
|
2014-02-22 10:54:43 -08:00
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
builder.setNegativeButton(R.string.no, null);
|
|
|
|
builder.show();
|
|
|
|
}
|
|
|
|
|
|
|
|
private void handleEditPushGroup() {
|
|
|
|
Intent intent = new Intent(ConversationActivity.this, GroupCreateActivity.class);
|
2017-08-01 08:56:00 -07:00
|
|
|
intent.putExtra(GroupCreateActivity.GROUP_ADDRESS_EXTRA, recipient.getAddress());
|
2014-02-22 10:54:43 -08:00
|
|
|
startActivityForResult(intent, GROUP_EDIT);
|
|
|
|
}
|
|
|
|
|
2013-04-25 18:59:49 -07:00
|
|
|
private void handleDistributionBroadcastEnabled(MenuItem item) {
|
|
|
|
distributionType = ThreadDatabase.DistributionTypes.BROADCAST;
|
|
|
|
item.setChecked(true);
|
|
|
|
|
|
|
|
if (threadId != -1) {
|
|
|
|
new AsyncTask<Void, Void, Void>() {
|
|
|
|
@Override
|
|
|
|
protected Void doInBackground(Void... params) {
|
|
|
|
DatabaseFactory.getThreadDatabase(ConversationActivity.this)
|
|
|
|
.setDistributionType(threadId, ThreadDatabase.DistributionTypes.BROADCAST);
|
|
|
|
return null;
|
|
|
|
}
|
2017-10-23 13:03:32 -07:00
|
|
|
}.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
|
2013-04-25 18:59:49 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
private void handleDistributionConversationEnabled(MenuItem item) {
|
|
|
|
distributionType = ThreadDatabase.DistributionTypes.CONVERSATION;
|
|
|
|
item.setChecked(true);
|
|
|
|
|
|
|
|
if (threadId != -1) {
|
|
|
|
new AsyncTask<Void, Void, Void>() {
|
|
|
|
@Override
|
|
|
|
protected Void doInBackground(Void... params) {
|
|
|
|
DatabaseFactory.getThreadDatabase(ConversationActivity.this)
|
|
|
|
.setDistributionType(threadId, ThreadDatabase.DistributionTypes.CONVERSATION);
|
|
|
|
return null;
|
|
|
|
}
|
2017-10-23 13:03:32 -07:00
|
|
|
}.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
|
2013-04-25 18:59:49 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-09-21 17:41:27 -07:00
|
|
|
private void handleDial(final Recipient recipient) {
|
|
|
|
if (recipient == null) return;
|
|
|
|
|
2017-03-14 13:24:24 -07:00
|
|
|
if (isSecureText) {
|
2018-04-26 17:03:54 -07:00
|
|
|
CommunicationActions.startVoiceCall(this, recipient);
|
2015-09-21 17:41:27 -07:00
|
|
|
} else {
|
|
|
|
try {
|
|
|
|
Intent dialIntent = new Intent(Intent.ACTION_DIAL,
|
2017-07-26 09:59:15 -07:00
|
|
|
Uri.parse("tel:" + recipient.getAddress().serialize()));
|
2015-09-21 17:41:27 -07:00
|
|
|
startActivity(dialIntent);
|
|
|
|
} catch (ActivityNotFoundException anfe) {
|
|
|
|
Log.w(TAG, anfe);
|
|
|
|
Dialogs.showAlertDialog(this,
|
|
|
|
getString(R.string.ConversationActivity_calls_not_supported),
|
|
|
|
getString(R.string.ConversationActivity_this_device_does_not_appear_to_support_dial_actions));
|
|
|
|
}
|
|
|
|
}
|
2012-07-19 14:22:03 -07:00
|
|
|
}
|
|
|
|
|
2012-10-21 14:34:09 -07:00
|
|
|
private void handleDisplayGroupRecipients() {
|
2017-08-01 08:56:00 -07:00
|
|
|
new GroupMembersDialog(this, getRecipient()).display();
|
2012-10-21 14:34:09 -07:00
|
|
|
}
|
|
|
|
|
2014-06-04 01:24:44 +02:00
|
|
|
private void handleAddToContacts() {
|
2017-08-01 08:56:00 -07:00
|
|
|
if (recipient.getAddress().isGroup()) return;
|
2017-07-26 09:59:15 -07:00
|
|
|
|
2015-12-11 22:57:18 -08:00
|
|
|
try {
|
|
|
|
final Intent intent = new Intent(Intent.ACTION_INSERT_OR_EDIT);
|
2017-08-01 08:56:00 -07:00
|
|
|
if (recipient.getAddress().isEmail()) {
|
|
|
|
intent.putExtra(ContactsContract.Intents.Insert.EMAIL, recipient.getAddress().toEmailString());
|
2017-07-26 09:59:15 -07:00
|
|
|
} else {
|
2017-08-01 08:56:00 -07:00
|
|
|
intent.putExtra(ContactsContract.Intents.Insert.PHONE, recipient.getAddress().toPhoneString());
|
2017-07-26 09:59:15 -07:00
|
|
|
}
|
2015-12-11 22:57:18 -08:00
|
|
|
intent.setType(ContactsContract.Contacts.CONTENT_ITEM_TYPE);
|
|
|
|
startActivityForResult(intent, ADD_CONTACT);
|
|
|
|
} catch (ActivityNotFoundException e) {
|
|
|
|
Log.w(TAG, e);
|
|
|
|
}
|
2013-10-17 02:28:36 +02:00
|
|
|
}
|
|
|
|
|
2017-10-05 20:07:44 +02:00
|
|
|
private boolean handleDisplayQuickContact() {
|
|
|
|
if (recipient.getAddress().isGroup()) return false;
|
|
|
|
|
|
|
|
if (recipient.getContactUri() != null) {
|
|
|
|
ContactsContract.QuickContact.showQuickContact(ConversationActivity.this, titleView, recipient.getContactUri(), ContactsContract.QuickContact.MODE_LARGE, null);
|
|
|
|
} else {
|
|
|
|
handleAddToContacts();
|
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2012-07-19 14:22:03 -07:00
|
|
|
private void handleAddAttachment() {
|
2015-09-29 14:26:37 -07:00
|
|
|
if (this.isMmsEnabled || isSecureText) {
|
2017-01-18 18:46:40 -08:00
|
|
|
if (attachmentTypeSelector == null) {
|
|
|
|
attachmentTypeSelector = new AttachmentTypeSelector(this, getSupportLoaderManager(), new AttachmentTypeListener());
|
|
|
|
}
|
2015-10-28 09:47:09 -07:00
|
|
|
attachmentTypeSelector.show(this, attachButton);
|
2013-03-04 17:43:04 -08:00
|
|
|
} else {
|
2013-09-16 00:55:01 -07:00
|
|
|
handleManualMmsRequired();
|
2013-03-04 17:43:04 -08:00
|
|
|
}
|
2012-07-19 14:22:03 -07:00
|
|
|
}
|
|
|
|
|
2013-09-16 00:55:01 -07:00
|
|
|
private void handleManualMmsRequired() {
|
|
|
|
Toast.makeText(this, R.string.MmsDownloader_error_reading_mms_settings, Toast.LENGTH_LONG).show();
|
|
|
|
|
2017-12-05 11:52:03 -08:00
|
|
|
Bundle extras = getIntent().getExtras();
|
2013-09-16 00:55:01 -07:00
|
|
|
Intent intent = new Intent(this, PromptMmsActivity.class);
|
2017-12-05 11:52:03 -08:00
|
|
|
if (extras != null) intent.putExtras(extras);
|
2013-09-16 00:55:01 -07:00
|
|
|
startActivity(intent);
|
|
|
|
}
|
|
|
|
|
2017-06-06 18:03:09 -07:00
|
|
|
private void handleUnverifiedRecipients() {
|
|
|
|
List<Recipient> unverifiedRecipients = identityRecords.getUnverifiedRecipients(this);
|
|
|
|
List<IdentityRecord> unverifiedRecords = identityRecords.getUnverifiedRecords();
|
|
|
|
String message = IdentityUtil.getUnverifiedSendDialogDescription(this, unverifiedRecipients);
|
|
|
|
|
|
|
|
if (message == null) return;
|
|
|
|
|
2017-12-05 11:52:03 -08:00
|
|
|
//noinspection CodeBlock2Expr
|
|
|
|
new UnverifiedSendDialog(this, message, unverifiedRecords, () -> {
|
|
|
|
initializeIdentityRecords().addListener(new ListenableFuture.Listener<Boolean>() {
|
|
|
|
@Override
|
|
|
|
public void onSuccess(Boolean result) {
|
|
|
|
sendMessage();
|
|
|
|
}
|
2017-06-06 18:03:09 -07:00
|
|
|
|
2017-12-05 11:52:03 -08:00
|
|
|
@Override
|
|
|
|
public void onFailure(ExecutionException e) {
|
|
|
|
throw new AssertionError(e);
|
|
|
|
}
|
|
|
|
});
|
2017-06-06 18:03:09 -07:00
|
|
|
}).show();
|
|
|
|
}
|
|
|
|
|
|
|
|
private void handleUntrustedRecipients() {
|
|
|
|
List<Recipient> untrustedRecipients = identityRecords.getUntrustedRecipients(this);
|
|
|
|
List<IdentityRecord> untrustedRecords = identityRecords.getUntrustedRecords();
|
|
|
|
String untrustedMessage = IdentityUtil.getUntrustedSendDialogDescription(this, untrustedRecipients);
|
|
|
|
|
|
|
|
if (untrustedMessage == null) return;
|
|
|
|
|
2017-12-05 11:52:03 -08:00
|
|
|
//noinspection CodeBlock2Expr
|
|
|
|
new UntrustedSendDialog(this, untrustedMessage, untrustedRecords, () -> {
|
|
|
|
initializeIdentityRecords().addListener(new ListenableFuture.Listener<Boolean>() {
|
|
|
|
@Override
|
|
|
|
public void onSuccess(Boolean result) {
|
|
|
|
sendMessage();
|
|
|
|
}
|
2017-06-06 18:03:09 -07:00
|
|
|
|
2017-12-05 11:52:03 -08:00
|
|
|
@Override
|
|
|
|
public void onFailure(ExecutionException e) {
|
|
|
|
throw new AssertionError(e);
|
|
|
|
}
|
|
|
|
});
|
2017-06-06 18:03:09 -07:00
|
|
|
}).show();
|
|
|
|
}
|
|
|
|
|
2017-03-14 13:24:24 -07:00
|
|
|
private void handleSecurityChange(boolean isSecureText, boolean isDefaultSms) {
|
2017-11-14 10:49:54 -08:00
|
|
|
Log.w(TAG, "handleSecurityChange(" + isSecureText + ", " + isDefaultSms + ")");
|
2017-09-06 17:54:32 -07:00
|
|
|
if (isSecurityInitialized && isSecureText == this.isSecureText && isDefaultSms == this.isDefaultSms) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
this.isSecureText = isSecureText;
|
|
|
|
this.isDefaultSms = isDefaultSms;
|
|
|
|
this.isSecurityInitialized = true;
|
2015-09-29 14:26:37 -07:00
|
|
|
|
2017-08-01 08:56:00 -07:00
|
|
|
boolean isMediaMessage = recipient.isMmsGroupRecipient() || attachmentManager.isAttachmentPresent();
|
2015-09-23 15:47:48 -07:00
|
|
|
|
|
|
|
sendButton.resetAvailableTransports(isMediaMessage);
|
|
|
|
|
2017-12-25 15:57:33 -08:00
|
|
|
if (!isSecureText && !isPushGroupConversation()) sendButton.disableTransport(Type.TEXTSECURE);
|
|
|
|
if (recipient.isPushGroupRecipient()) sendButton.disableTransport(Type.SMS);
|
2015-09-23 15:47:48 -07:00
|
|
|
|
2017-12-25 15:57:33 -08:00
|
|
|
if (isSecureText || isPushGroupConversation()) sendButton.setDefaultTransport(Type.TEXTSECURE);
|
|
|
|
else sendButton.setDefaultTransport(Type.SMS);
|
2015-09-23 15:47:48 -07:00
|
|
|
|
|
|
|
calculateCharactersRemaining();
|
|
|
|
supportInvalidateOptionsMenu();
|
2017-08-01 08:56:00 -07:00
|
|
|
setBlockedUserState(recipient, isSecureText, isDefaultSms);
|
2015-09-23 15:47:48 -07:00
|
|
|
}
|
|
|
|
|
2012-07-19 14:22:03 -07:00
|
|
|
///// Initializers
|
|
|
|
|
2013-02-02 20:37:40 -08:00
|
|
|
private void initializeDraft() {
|
2015-11-18 12:54:40 -08:00
|
|
|
final String draftText = getIntent().getStringExtra(TEXT_EXTRA);
|
|
|
|
final Uri draftMedia = getIntent().getData();
|
|
|
|
final MediaType draftMediaType = MediaType.from(getIntent().getType());
|
2017-05-10 15:21:52 -07:00
|
|
|
|
2015-11-18 12:54:40 -08:00
|
|
|
if (draftText != null) composeText.setText(draftText);
|
|
|
|
if (draftMedia != null && draftMediaType != null) setMedia(draftMedia, draftMediaType);
|
2015-09-04 17:33:22 -07:00
|
|
|
|
2015-11-18 12:54:40 -08:00
|
|
|
if (draftText == null && draftMedia == null && draftMediaType == null) {
|
2013-02-04 00:13:07 -08:00
|
|
|
initializeDraftFromDatabase();
|
2015-05-18 10:26:32 -07:00
|
|
|
} else {
|
|
|
|
updateToggleButtonState();
|
2013-02-04 00:13:07 -08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-02-22 10:54:43 -08:00
|
|
|
private void initializeEnabledCheck() {
|
2014-02-23 14:37:41 -08:00
|
|
|
boolean enabled = !(isPushGroupConversation() && !isActiveGroup());
|
2015-11-22 10:44:57 -08:00
|
|
|
inputPanel.setEnabled(enabled);
|
2014-02-22 10:54:43 -08:00
|
|
|
sendButton.setEnabled(enabled);
|
2015-11-22 10:44:57 -08:00
|
|
|
attachButton.setEnabled(enabled);
|
2014-02-22 10:54:43 -08:00
|
|
|
}
|
|
|
|
|
2013-02-04 00:13:07 -08:00
|
|
|
private void initializeDraftFromDatabase() {
|
|
|
|
new AsyncTask<Void, Void, List<Draft>>() {
|
|
|
|
@Override
|
|
|
|
protected List<Draft> doInBackground(Void... params) {
|
|
|
|
DraftDatabase draftDatabase = DatabaseFactory.getDraftDatabase(ConversationActivity.this);
|
2018-01-24 19:17:44 -08:00
|
|
|
List<Draft> results = draftDatabase.getDrafts(threadId);
|
2013-02-04 00:13:07 -08:00
|
|
|
|
|
|
|
draftDatabase.clearDrafts(threadId);
|
|
|
|
|
|
|
|
return results;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
protected void onPostExecute(List<Draft> drafts) {
|
|
|
|
for (Draft draft : drafts) {
|
2016-01-04 13:02:22 -08:00
|
|
|
try {
|
2017-12-05 11:52:03 -08:00
|
|
|
switch (draft.getType()) {
|
|
|
|
case Draft.TEXT:
|
|
|
|
composeText.setText(draft.getValue());
|
|
|
|
break;
|
|
|
|
case Draft.LOCATION:
|
2018-01-24 19:17:44 -08:00
|
|
|
attachmentManager.setLocation(SignalPlace.deserialize(draft.getValue()), getCurrentMediaConstraints());
|
2017-12-05 11:52:03 -08:00
|
|
|
break;
|
|
|
|
case Draft.IMAGE:
|
|
|
|
setMedia(Uri.parse(draft.getValue()), MediaType.IMAGE);
|
|
|
|
break;
|
|
|
|
case Draft.AUDIO:
|
|
|
|
setMedia(Uri.parse(draft.getValue()), MediaType.AUDIO);
|
|
|
|
break;
|
|
|
|
case Draft.VIDEO:
|
|
|
|
setMedia(Uri.parse(draft.getValue()), MediaType.VIDEO);
|
|
|
|
break;
|
2018-04-24 11:09:54 -07:00
|
|
|
case Draft.QUOTE:
|
|
|
|
new QuoteRestorationTask(draft.getValue()).execute();
|
|
|
|
break;
|
2016-01-04 13:02:22 -08:00
|
|
|
}
|
|
|
|
} catch (IOException e) {
|
|
|
|
Log.w(TAG, e);
|
2014-05-22 23:00:53 +02:00
|
|
|
}
|
2013-02-04 00:13:07 -08:00
|
|
|
}
|
2015-05-18 10:26:32 -07:00
|
|
|
|
|
|
|
updateToggleButtonState();
|
2013-02-04 00:13:07 -08:00
|
|
|
}
|
2017-10-23 13:03:32 -07:00
|
|
|
}.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
|
2013-02-02 20:37:40 -08:00
|
|
|
}
|
|
|
|
|
2015-10-01 17:46:47 -07:00
|
|
|
private ListenableFuture<Boolean> initializeSecurity(final boolean currentSecureText,
|
2017-01-18 11:01:13 -08:00
|
|
|
final boolean currentIsDefaultSms)
|
2015-09-29 14:26:37 -07:00
|
|
|
{
|
2015-10-01 17:46:47 -07:00
|
|
|
final SettableFuture<Boolean> future = new SettableFuture<>();
|
|
|
|
|
2017-03-14 13:24:24 -07:00
|
|
|
handleSecurityChange(currentSecureText || isPushGroupConversation(), currentIsDefaultSms);
|
2015-09-21 17:41:27 -07:00
|
|
|
|
2017-08-01 08:56:00 -07:00
|
|
|
new AsyncTask<Recipient, Void, boolean[]>() {
|
2015-09-21 17:41:27 -07:00
|
|
|
@Override
|
2017-08-01 08:56:00 -07:00
|
|
|
protected boolean[] doInBackground(Recipient... params) {
|
2017-08-22 10:44:04 -07:00
|
|
|
Context context = ConversationActivity.this;
|
|
|
|
Recipient recipient = params[0];
|
2017-11-14 10:49:54 -08:00
|
|
|
Log.w(TAG, "Resolving registered state...");
|
2017-11-25 09:50:36 -08:00
|
|
|
RegisteredState registeredState;
|
|
|
|
|
2017-11-27 09:44:50 -08:00
|
|
|
if (recipient.isPushGroupRecipient()) {
|
|
|
|
Log.w(TAG, "Push group recipient...");
|
|
|
|
registeredState = RegisteredState.REGISTERED;
|
|
|
|
} else if (recipient.isResolving()) {
|
2017-11-25 09:50:36 -08:00
|
|
|
Log.w(TAG, "Talking to DB directly.");
|
|
|
|
registeredState = DatabaseFactory.getRecipientDatabase(ConversationActivity.this).isRegistered(recipient.getAddress());
|
|
|
|
} else {
|
|
|
|
Log.w(TAG, "Checking through resolved recipient");
|
|
|
|
registeredState = recipient.resolve().getRegistered();
|
|
|
|
}
|
|
|
|
|
2017-11-14 10:49:54 -08:00
|
|
|
Log.w(TAG, "Resolved registered state: " + registeredState);
|
2017-09-14 16:46:12 -07:00
|
|
|
boolean signalEnabled = TextSecurePreferences.isPushRegistered(context);
|
2015-09-29 14:26:37 -07:00
|
|
|
|
2017-08-22 10:44:04 -07:00
|
|
|
if (registeredState == RegisteredState.UNKNOWN) {
|
2017-01-31 21:46:20 -08:00
|
|
|
try {
|
2017-11-14 10:49:54 -08:00
|
|
|
Log.w(TAG, "Refreshing directory for user: " + recipient.getAddress().serialize());
|
2018-01-24 19:17:44 -08:00
|
|
|
registeredState = DirectoryHelper.refreshDirectoryFor(context, recipient);
|
2017-01-31 21:46:20 -08:00
|
|
|
} catch (IOException e) {
|
|
|
|
Log.w(TAG, e);
|
2015-09-29 14:26:37 -07:00
|
|
|
}
|
2015-09-21 17:41:27 -07:00
|
|
|
}
|
2017-01-31 21:46:20 -08:00
|
|
|
|
2017-11-14 10:49:54 -08:00
|
|
|
Log.w(TAG, "Returning registered state...");
|
2017-09-14 16:46:12 -07:00
|
|
|
return new boolean[] {registeredState == RegisteredState.REGISTERED && signalEnabled,
|
|
|
|
Util.isDefaultSmsProvider(context)};
|
2015-09-21 17:41:27 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2017-01-18 11:01:13 -08:00
|
|
|
protected void onPostExecute(boolean[] result) {
|
2017-03-14 13:24:24 -07:00
|
|
|
if (result[0] != currentSecureText || result[1] != currentIsDefaultSms) {
|
2017-11-14 10:49:54 -08:00
|
|
|
Log.w(TAG, "onPostExecute() handleSecurityChange: " + result[0] + " , " + result[1]);
|
2017-03-14 13:24:24 -07:00
|
|
|
handleSecurityChange(result[0], result[1]);
|
2015-09-21 17:41:27 -07:00
|
|
|
}
|
2015-10-01 17:46:47 -07:00
|
|
|
future.set(true);
|
2015-10-13 21:44:01 -07:00
|
|
|
onSecurityUpdated();
|
2015-09-21 17:41:27 -07:00
|
|
|
}
|
2017-10-23 13:03:32 -07:00
|
|
|
}.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR, recipient);
|
2015-10-01 17:46:47 -07:00
|
|
|
|
|
|
|
return future;
|
2015-09-21 17:41:27 -07:00
|
|
|
}
|
|
|
|
|
2015-10-13 21:44:01 -07:00
|
|
|
private void onSecurityUpdated() {
|
2017-11-14 10:49:54 -08:00
|
|
|
Log.w(TAG, "onSecurityUpdated()");
|
2017-11-15 16:29:00 -08:00
|
|
|
updateReminders(recipient.hasSeenInviteReminder());
|
2017-08-22 10:44:04 -07:00
|
|
|
updateDefaultSubscriptionId(recipient.getDefaultSubscriptionId());
|
2016-02-05 16:10:33 -08:00
|
|
|
}
|
|
|
|
|
2017-11-15 16:29:00 -08:00
|
|
|
protected void updateReminders(boolean seenInvite) {
|
|
|
|
Log.w(TAG, "updateReminders(" + seenInvite+")");
|
|
|
|
|
|
|
|
if (UnauthorizedReminder.isEligible(this)) {
|
|
|
|
reminderView.get().showReminder(new UnauthorizedReminder(this));
|
|
|
|
} else if (ExpiredBuildReminder.isEligible()) {
|
|
|
|
reminderView.get().showReminder(new ExpiredBuildReminder(this));
|
|
|
|
} else if (TextSecurePreferences.isPushRegistered(this) &&
|
|
|
|
TextSecurePreferences.isShowInviteReminders(this) &&
|
|
|
|
!isSecureText &&
|
|
|
|
!seenInvite &&
|
|
|
|
!recipient.isGroupRecipient())
|
2015-10-26 12:36:45 -07:00
|
|
|
{
|
2017-08-01 08:56:00 -07:00
|
|
|
InviteReminder reminder = new InviteReminder(this, recipient);
|
2017-11-15 16:29:00 -08:00
|
|
|
reminder.setOkListener(v -> {
|
|
|
|
handleInviteLink();
|
|
|
|
reminderView.get().requestDismiss();
|
2016-02-05 16:10:33 -08:00
|
|
|
});
|
2017-01-18 18:46:40 -08:00
|
|
|
reminderView.get().showReminder(reminder);
|
|
|
|
} else if (reminderView.resolved()) {
|
|
|
|
reminderView.get().hide();
|
2015-10-13 21:44:01 -07:00
|
|
|
}
|
|
|
|
}
|
2014-04-14 03:55:20 +03:00
|
|
|
|
2016-02-05 16:10:33 -08:00
|
|
|
private void updateDefaultSubscriptionId(Optional<Integer> defaultSubscriptionId) {
|
|
|
|
Log.w(TAG, "updateDefaultSubscriptionId(" + defaultSubscriptionId.orNull() + ")");
|
|
|
|
sendButton.setDefaultSubscriptionId(defaultSubscriptionId);
|
|
|
|
}
|
|
|
|
|
2013-03-04 17:43:04 -08:00
|
|
|
private void initializeMmsEnabledCheck() {
|
|
|
|
new AsyncTask<Void, Void, Boolean>() {
|
|
|
|
@Override
|
|
|
|
protected Boolean doInBackground(Void... params) {
|
2014-12-29 14:01:02 -08:00
|
|
|
return Util.isMmsCapable(ConversationActivity.this);
|
2013-03-04 17:43:04 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
protected void onPostExecute(Boolean isMmsEnabled) {
|
|
|
|
ConversationActivity.this.isMmsEnabled = isMmsEnabled;
|
|
|
|
}
|
2017-10-23 13:03:32 -07:00
|
|
|
}.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
|
2013-03-04 17:43:04 -08:00
|
|
|
}
|
|
|
|
|
2017-06-06 18:03:09 -07:00
|
|
|
private ListenableFuture<Boolean> initializeIdentityRecords() {
|
|
|
|
final SettableFuture<Boolean> future = new SettableFuture<>();
|
|
|
|
|
2017-08-01 08:56:00 -07:00
|
|
|
new AsyncTask<Recipient, Void, Pair<IdentityRecordList, String>>() {
|
2017-06-06 18:03:09 -07:00
|
|
|
@Override
|
2017-08-01 08:56:00 -07:00
|
|
|
protected @NonNull Pair<IdentityRecordList, String> doInBackground(Recipient... params) {
|
|
|
|
IdentityDatabase identityDatabase = DatabaseFactory.getIdentityDatabase(ConversationActivity.this);
|
|
|
|
IdentityRecordList identityRecordList = new IdentityRecordList();
|
|
|
|
List<Recipient> recipients = new LinkedList<>();
|
|
|
|
|
|
|
|
if (params[0].isGroupRecipient()) {
|
|
|
|
recipients.addAll(DatabaseFactory.getGroupDatabase(ConversationActivity.this)
|
|
|
|
.getGroupMembers(params[0].getAddress().toGroupString(), false));
|
|
|
|
} else {
|
|
|
|
recipients.add(params[0]);
|
|
|
|
}
|
2017-06-06 18:03:09 -07:00
|
|
|
|
2017-08-01 08:56:00 -07:00
|
|
|
for (Recipient recipient : recipients) {
|
|
|
|
Log.w(TAG, "Loading identity for: " + recipient.getAddress());
|
|
|
|
identityRecordList.add(identityDatabase.getIdentity(recipient.getAddress()));
|
|
|
|
}
|
2017-06-06 18:03:09 -07:00
|
|
|
|
2017-08-01 08:56:00 -07:00
|
|
|
String message = null;
|
2017-06-06 18:03:09 -07:00
|
|
|
|
2017-08-01 08:56:00 -07:00
|
|
|
if (identityRecordList.isUnverified()) {
|
|
|
|
message = IdentityUtil.getUnverifiedBannerDescription(ConversationActivity.this, identityRecordList.getUnverifiedRecipients(ConversationActivity.this));
|
2017-06-06 18:03:09 -07:00
|
|
|
}
|
2017-08-01 08:56:00 -07:00
|
|
|
|
|
|
|
return new Pair<>(identityRecordList, message);
|
2017-06-06 18:03:09 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
protected void onPostExecute(@NonNull Pair<IdentityRecordList, String> result) {
|
|
|
|
Log.w(TAG, "Got identity records: " + result.first.isUnverified());
|
|
|
|
identityRecords.replaceWith(result.first);
|
|
|
|
|
|
|
|
if (result.second != null) {
|
|
|
|
Log.w(TAG, "Replacing banner...");
|
|
|
|
unverifiedBannerView.get().display(result.second, result.first.getUnverifiedRecords(),
|
|
|
|
new UnverifiedClickedListener(),
|
|
|
|
new UnverifiedDismissedListener());
|
|
|
|
} else if (unverifiedBannerView.resolved()) {
|
|
|
|
Log.w(TAG, "Clearing banner...");
|
|
|
|
unverifiedBannerView.get().hide();
|
|
|
|
}
|
|
|
|
|
2017-06-22 10:37:26 -07:00
|
|
|
titleView.setVerified(isSecureText && identityRecords.isVerified());
|
2017-06-06 18:03:09 -07:00
|
|
|
|
|
|
|
future.set(true);
|
|
|
|
}
|
|
|
|
|
2017-10-23 13:03:32 -07:00
|
|
|
}.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR, recipient);
|
2017-06-06 18:03:09 -07:00
|
|
|
|
|
|
|
return future;
|
|
|
|
}
|
|
|
|
|
2014-12-24 18:32:51 -08:00
|
|
|
private void initializeViews() {
|
2017-12-05 11:52:03 -08:00
|
|
|
ActionBar supportActionBar = getSupportActionBar();
|
|
|
|
if (supportActionBar == null) throw new AssertionError();
|
|
|
|
|
|
|
|
titleView = (ConversationTitleView) supportActionBar.getCustomView();
|
2015-10-13 21:44:01 -07:00
|
|
|
buttonToggle = ViewUtil.findById(this, R.id.button_toggle);
|
|
|
|
sendButton = ViewUtil.findById(this, R.id.send_button);
|
|
|
|
attachButton = ViewUtil.findById(this, R.id.attach_button);
|
|
|
|
composeText = ViewUtil.findById(this, R.id.embedded_text_editor);
|
|
|
|
charactersLeft = ViewUtil.findById(this, R.id.space_left);
|
2017-01-19 11:31:41 -08:00
|
|
|
emojiDrawerStub = ViewUtil.findStubById(this, R.id.emoji_drawer_stub);
|
2015-10-13 21:44:01 -07:00
|
|
|
unblockButton = ViewUtil.findById(this, R.id.unblock_button);
|
2016-11-20 15:56:47 -08:00
|
|
|
makeDefaultSmsButton = ViewUtil.findById(this, R.id.make_default_sms_button);
|
2017-12-25 15:57:33 -08:00
|
|
|
registerButton = ViewUtil.findById(this, R.id.register_button);
|
2015-10-13 21:44:01 -07:00
|
|
|
composePanel = ViewUtil.findById(this, R.id.bottom_panel);
|
|
|
|
container = ViewUtil.findById(this, R.id.layout_container);
|
2017-01-18 18:46:40 -08:00
|
|
|
reminderView = ViewUtil.findStubById(this, R.id.reminder_stub);
|
2017-06-06 18:03:09 -07:00
|
|
|
unverifiedBannerView = ViewUtil.findStubById(this, R.id.unverified_banner_stub);
|
2017-08-22 11:51:01 -07:00
|
|
|
groupShareProfileView = ViewUtil.findStubById(this, R.id.group_share_profile_view_stub);
|
2015-10-13 21:44:01 -07:00
|
|
|
quickAttachmentDrawer = ViewUtil.findById(this, R.id.quick_attachment_drawer);
|
|
|
|
quickAttachmentToggle = ViewUtil.findById(this, R.id.quick_attachment_toggle);
|
2015-11-18 14:52:26 -08:00
|
|
|
inputPanel = ViewUtil.findById(this, R.id.bottom_panel);
|
|
|
|
|
|
|
|
ImageButton quickCameraToggle = ViewUtil.findById(this, R.id.quick_camera_toggle);
|
|
|
|
View composeBubble = ViewUtil.findById(this, R.id.compose_bubble);
|
2015-04-16 01:38:33 -04:00
|
|
|
|
2015-07-25 16:58:51 +02:00
|
|
|
container.addOnKeyboardShownListener(this);
|
2017-01-19 11:31:41 -08:00
|
|
|
inputPanel.setListener(this);
|
2016-12-26 15:14:23 -08:00
|
|
|
inputPanel.setMediaListener(this);
|
2015-07-25 16:58:51 +02:00
|
|
|
|
2015-06-30 17:45:39 -07:00
|
|
|
int[] attributes = new int[]{R.attr.conversation_item_bubble_background};
|
|
|
|
TypedArray colors = obtainStyledAttributes(attributes);
|
|
|
|
int defaultColor = colors.getColor(0, Color.WHITE);
|
|
|
|
composeBubble.getBackground().setColorFilter(defaultColor, PorterDuff.Mode.MULTIPLY);
|
|
|
|
colors.recycle();
|
2012-07-19 14:22:03 -07:00
|
|
|
|
2017-01-18 18:46:40 -08:00
|
|
|
attachmentTypeSelector = null;
|
2015-10-28 09:47:09 -07:00
|
|
|
attachmentManager = new AttachmentManager(this, this);
|
2018-01-24 19:17:44 -08:00
|
|
|
audioRecorder = new AudioRecorder(this);
|
2012-07-19 14:22:03 -07:00
|
|
|
|
2013-06-27 20:57:27 -07:00
|
|
|
SendButtonListener sendButtonListener = new SendButtonListener();
|
|
|
|
ComposeKeyPressedListener composeKeyPressedListener = new ComposeKeyPressedListener();
|
2012-07-19 14:22:03 -07:00
|
|
|
|
2015-07-20 19:25:54 -07:00
|
|
|
composeText.setOnEditorActionListener(sendButtonListener);
|
2015-05-18 10:26:32 -07:00
|
|
|
attachButton.setOnClickListener(new AttachButtonListener());
|
2015-07-26 22:49:43 +01:00
|
|
|
attachButton.setOnLongClickListener(new AttachButtonLongClickListener());
|
2012-07-19 14:22:03 -07:00
|
|
|
sendButton.setOnClickListener(sendButtonListener);
|
2013-03-13 17:45:32 -07:00
|
|
|
sendButton.setEnabled(true);
|
2017-12-05 11:52:03 -08:00
|
|
|
sendButton.addOnTransportChangedListener((newTransport, manuallySelected) -> {
|
|
|
|
calculateCharactersRemaining();
|
|
|
|
composeText.setTransport(newTransport);
|
|
|
|
buttonToggle.getBackground().setColorFilter(newTransport.getBackgroundColor(), Mode.MULTIPLY);
|
|
|
|
buttonToggle.getBackground().invalidateSelf();
|
|
|
|
if (manuallySelected) recordSubscriptionIdPreference(newTransport.getSimSubscriptionId());
|
2015-02-16 02:38:09 -08:00
|
|
|
});
|
|
|
|
|
2017-10-03 16:27:12 -07:00
|
|
|
titleView.setOnClickListener(v -> handleConversationSettings());
|
2017-10-05 20:07:44 +02:00
|
|
|
titleView.setOnLongClickListener(v -> handleDisplayQuickContact());
|
2017-10-08 17:44:18 -07:00
|
|
|
titleView.setOnBackClickedListener(view -> super.onBackPressed());
|
2017-09-12 22:48:30 -07:00
|
|
|
unblockButton.setOnClickListener(v -> handleUnblock());
|
|
|
|
makeDefaultSmsButton.setOnClickListener(v -> handleMakeDefaultSms());
|
2017-12-25 15:57:33 -08:00
|
|
|
registerButton.setOnClickListener(v -> handleRegisterForSignal());
|
2016-11-20 15:56:47 -08:00
|
|
|
|
2013-06-27 20:57:27 -07:00
|
|
|
composeText.setOnKeyListener(composeKeyPressedListener);
|
|
|
|
composeText.addTextChangedListener(composeKeyPressedListener);
|
2012-07-19 14:22:03 -07:00
|
|
|
composeText.setOnEditorActionListener(sendButtonListener);
|
2013-06-27 20:57:27 -07:00
|
|
|
composeText.setOnClickListener(composeKeyPressedListener);
|
2014-05-28 20:53:34 -07:00
|
|
|
composeText.setOnFocusChangeListener(composeKeyPressedListener);
|
2015-04-16 01:38:33 -04:00
|
|
|
|
2015-06-08 11:07:46 -07:00
|
|
|
if (QuickAttachmentDrawer.isDeviceSupported(this)) {
|
|
|
|
quickAttachmentDrawer.setListener(this);
|
2015-11-18 14:52:26 -08:00
|
|
|
quickCameraToggle.setOnClickListener(new QuickCameraToggleListener());
|
2015-04-16 01:38:33 -04:00
|
|
|
} else {
|
2015-11-18 14:52:26 -08:00
|
|
|
quickCameraToggle.setVisibility(View.GONE);
|
|
|
|
quickCameraToggle.setEnabled(false);
|
2015-04-16 01:38:33 -04:00
|
|
|
}
|
2014-12-24 18:32:51 -08:00
|
|
|
}
|
|
|
|
|
2015-06-22 08:46:43 -07:00
|
|
|
protected void initializeActionBar() {
|
2017-12-05 11:52:03 -08:00
|
|
|
ActionBar supportActionBar = getSupportActionBar();
|
|
|
|
if (supportActionBar == null) throw new AssertionError();
|
|
|
|
|
|
|
|
supportActionBar.setDisplayHomeAsUpEnabled(false);
|
|
|
|
supportActionBar.setCustomView(R.layout.conversation_title_view);
|
|
|
|
supportActionBar.setDisplayShowCustomEnabled(true);
|
|
|
|
supportActionBar.setDisplayShowTitleEnabled(false);
|
2015-06-09 07:37:20 -07:00
|
|
|
}
|
|
|
|
|
2014-12-24 18:32:51 -08:00
|
|
|
private void initializeResources() {
|
2017-08-01 08:56:00 -07:00
|
|
|
if (recipient != null) recipient.removeListener(this);
|
2016-08-15 20:23:56 -07:00
|
|
|
|
2017-12-05 11:52:03 -08:00
|
|
|
recipient = Recipient.from(this, getIntent().getParcelableExtra(ADDRESS_EXTRA), true);
|
2014-12-24 18:32:51 -08:00
|
|
|
threadId = getIntent().getLongExtra(THREAD_ID_EXTRA, -1);
|
2015-12-01 01:38:37 +01:00
|
|
|
archived = getIntent().getBooleanExtra(IS_ARCHIVED_EXTRA, false);
|
2014-12-24 18:32:51 -08:00
|
|
|
distributionType = getIntent().getIntExtra(DISTRIBUTION_TYPE_EXTRA, ThreadDatabase.DistributionTypes.DEFAULT);
|
2017-10-16 13:11:42 -07:00
|
|
|
glideRequests = GlideApp.with(this);
|
2012-07-19 14:22:03 -07:00
|
|
|
|
2015-11-24 11:47:50 -08:00
|
|
|
if (Build.VERSION.SDK_INT < Build.VERSION_CODES.JELLY_BEAN) {
|
|
|
|
LinearLayout conversationContainer = ViewUtil.findById(this, R.id.conversation_container);
|
|
|
|
conversationContainer.setClipChildren(true);
|
|
|
|
conversationContainer.setClipToPadding(true);
|
|
|
|
}
|
|
|
|
|
2017-08-01 08:56:00 -07:00
|
|
|
recipient.addListener(this);
|
2015-02-10 03:15:50 -08:00
|
|
|
}
|
|
|
|
|
2017-05-19 18:01:40 -07:00
|
|
|
private void initializeProfiles() {
|
2017-06-14 09:53:22 -07:00
|
|
|
if (!isSecureText) {
|
|
|
|
Log.w(TAG, "SMS contact, no profile fetch needed.");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2017-05-19 18:01:40 -07:00
|
|
|
ApplicationContext.getInstance(this)
|
|
|
|
.getJobManager()
|
2017-08-01 08:56:00 -07:00
|
|
|
.add(new RetrieveProfileJob(this, recipient));
|
2017-05-19 18:01:40 -07:00
|
|
|
}
|
|
|
|
|
2015-02-10 03:15:50 -08:00
|
|
|
@Override
|
2017-08-01 08:56:00 -07:00
|
|
|
public void onModified(final Recipient recipient) {
|
2017-11-14 10:49:54 -08:00
|
|
|
Log.w(TAG, "onModified(" + recipient.getAddress().serialize() + ")");
|
2017-10-04 14:56:31 -07:00
|
|
|
Util.runOnMain(() -> {
|
2017-11-14 10:49:54 -08:00
|
|
|
Log.w(TAG, "onModifiedRun(): " + recipient.getRegistered());
|
2017-10-16 13:11:42 -07:00
|
|
|
titleView.setTitle(glideRequests, recipient);
|
2017-10-04 14:56:31 -07:00
|
|
|
titleView.setVerified(identityRecords.isVerified());
|
|
|
|
setBlockedUserState(recipient, isSecureText, isDefaultSms);
|
|
|
|
setActionBarColor(recipient.getColor());
|
|
|
|
setGroupShareProfileReminder(recipient);
|
2017-11-15 16:29:00 -08:00
|
|
|
updateReminders(recipient.hasSeenInviteReminder());
|
2017-10-04 14:56:31 -07:00
|
|
|
updateDefaultSubscriptionId(recipient.getDefaultSubscriptionId());
|
|
|
|
initializeSecurity(isSecureText, isDefaultSms);
|
|
|
|
invalidateOptionsMenu();
|
2015-06-11 12:53:38 -07:00
|
|
|
});
|
2012-07-19 14:22:03 -07:00
|
|
|
}
|
2014-02-15 18:40:08 -08:00
|
|
|
|
2017-06-06 18:03:09 -07:00
|
|
|
@Subscribe(threadMode = ThreadMode.MAIN)
|
|
|
|
public void onIdentityRecordUpdate(final IdentityRecord event) {
|
|
|
|
initializeIdentityRecords();
|
|
|
|
}
|
|
|
|
|
2012-07-19 14:22:03 -07:00
|
|
|
private void initializeReceivers() {
|
|
|
|
securityUpdateReceiver = new BroadcastReceiver() {
|
|
|
|
@Override
|
|
|
|
public void onReceive(Context context, Intent intent) {
|
2017-03-14 13:24:24 -07:00
|
|
|
initializeSecurity(isSecureText, isDefaultSms);
|
2015-09-23 15:47:48 -07:00
|
|
|
calculateCharactersRemaining();
|
2012-07-19 14:22:03 -07:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
registerReceiver(securityUpdateReceiver,
|
2014-11-03 15:16:04 -08:00
|
|
|
new IntentFilter(SecurityEvent.SECURITY_UPDATE_EVENT),
|
2012-07-19 14:22:03 -07:00
|
|
|
KeyCachingService.KEY_PERMISSION, null);
|
|
|
|
}
|
|
|
|
|
|
|
|
//////// Helper Methods
|
|
|
|
|
|
|
|
private void addAttachment(int type) {
|
|
|
|
Log.w("ComposeMessageActivity", "Selected: " + type);
|
|
|
|
switch (type) {
|
2017-04-18 16:33:03 -07:00
|
|
|
case AttachmentTypeSelector.ADD_GALLERY:
|
|
|
|
AttachmentManager.selectGallery(this, PICK_GALLERY); break;
|
|
|
|
case AttachmentTypeSelector.ADD_DOCUMENT:
|
|
|
|
AttachmentManager.selectDocument(this, PICK_DOCUMENT); break;
|
|
|
|
case AttachmentTypeSelector.ADD_SOUND:
|
2012-07-19 14:22:03 -07:00
|
|
|
AttachmentManager.selectAudio(this, PICK_AUDIO); break;
|
2017-04-18 16:33:03 -07:00
|
|
|
case AttachmentTypeSelector.ADD_CONTACT_INFO:
|
2018-04-26 17:03:54 -07:00
|
|
|
AttachmentManager.selectContactInfo(this, PICK_CONTACT); break;
|
2015-12-18 14:37:11 -08:00
|
|
|
case AttachmentTypeSelector.ADD_LOCATION:
|
|
|
|
AttachmentManager.selectLocation(this, PICK_LOCATION); break;
|
2017-04-18 16:33:03 -07:00
|
|
|
case AttachmentTypeSelector.TAKE_PHOTO:
|
2015-11-23 17:56:41 -08:00
|
|
|
attachmentManager.capturePhoto(this, TAKE_PHOTO); break;
|
2016-10-16 19:05:07 -07:00
|
|
|
case AttachmentTypeSelector.ADD_GIF:
|
2016-12-14 11:58:47 -08:00
|
|
|
AttachmentManager.selectGif(this, PICK_GIF, !isSecureText); break;
|
2012-07-19 14:22:03 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-12-26 15:14:23 -08:00
|
|
|
private void setMedia(@Nullable Uri uri, @NonNull MediaType mediaType) {
|
2018-03-20 11:27:11 -07:00
|
|
|
setMedia(uri, mediaType, 0, 0);
|
|
|
|
}
|
|
|
|
|
|
|
|
private void setMedia(@Nullable Uri uri, @NonNull MediaType mediaType, int width, int height) {
|
2016-04-12 08:40:48 +02:00
|
|
|
if (uri == null) return;
|
2018-05-16 23:40:14 -07:00
|
|
|
|
2018-05-21 10:44:30 -04:00
|
|
|
// TODO(greyson): Re-enable shared contact sending after receiving has been enabled for a few releases
|
|
|
|
attachmentManager.setMedia(glideRequests, uri, mediaType, getCurrentMediaConstraints(), width, height);
|
|
|
|
// if (MediaType.VCARD.equals(mediaType) && isSecureText) {
|
|
|
|
// openContactShareEditor(uri);
|
|
|
|
// } else {
|
|
|
|
// attachmentManager.setMedia(glideRequests, uri, mediaType, getCurrentMediaConstraints(), width, height);
|
|
|
|
// }
|
2012-07-19 14:22:03 -07:00
|
|
|
}
|
|
|
|
|
2018-04-26 17:03:54 -07:00
|
|
|
private void openContactShareEditor(Uri contactUri) {
|
2018-05-16 23:40:14 -07:00
|
|
|
Intent intent = ContactShareEditActivity.getIntent(this, Collections.singletonList(contactUri));
|
2018-04-26 17:03:54 -07:00
|
|
|
startActivityForResult(intent, GET_CONTACT_DETAILS);
|
|
|
|
}
|
|
|
|
|
2014-06-04 01:24:44 +02:00
|
|
|
private void addAttachmentContactInfo(Uri contactUri) {
|
2013-10-17 02:28:36 +02:00
|
|
|
ContactAccessor contactDataList = ContactAccessor.getInstance();
|
|
|
|
ContactData contactData = contactDataList.getContactData(this, contactUri);
|
|
|
|
|
|
|
|
if (contactData.numbers.size() == 1) composeText.append(contactData.numbers.get(0).number);
|
|
|
|
else if (contactData.numbers.size() > 1) selectContactInfo(contactData);
|
|
|
|
}
|
|
|
|
|
2018-04-26 17:03:54 -07:00
|
|
|
private void sendSharedContact(List<Contact> contacts) {
|
|
|
|
int subscriptionId = sendButton.getSelectedTransport().getSimSubscriptionId().or(-1);
|
|
|
|
long expiresIn = recipient.getExpireMessages() * 1000L;
|
|
|
|
boolean initiating = threadId == -1;
|
|
|
|
|
|
|
|
sendMediaMessage(isSmsForced(), "", attachmentManager.buildSlideDeck(), contacts, expiresIn, subscriptionId, initiating);
|
|
|
|
}
|
|
|
|
|
2013-10-17 02:28:36 +02:00
|
|
|
private void selectContactInfo(ContactData contactData) {
|
2014-12-12 18:31:20 -08:00
|
|
|
final CharSequence[] numbers = new CharSequence[contactData.numbers.size()];
|
2013-10-17 02:28:36 +02:00
|
|
|
final CharSequence[] numberItems = new CharSequence[contactData.numbers.size()];
|
2014-12-12 18:31:20 -08:00
|
|
|
|
2013-10-17 02:28:36 +02:00
|
|
|
for (int i = 0; i < contactData.numbers.size(); i++) {
|
2014-12-12 18:31:20 -08:00
|
|
|
numbers[i] = contactData.numbers.get(i).number;
|
2013-10-17 02:28:36 +02:00
|
|
|
numberItems[i] = contactData.numbers.get(i).type + ": " + contactData.numbers.get(i).number;
|
|
|
|
}
|
|
|
|
|
2015-05-20 23:36:30 +02:00
|
|
|
AlertDialog.Builder builder = new AlertDialog.Builder(this);
|
2015-03-24 13:44:22 +01:00
|
|
|
builder.setIconAttribute(R.attr.conversation_attach_contact_info);
|
2013-10-17 02:28:36 +02:00
|
|
|
builder.setTitle(R.string.ConversationActivity_select_contact_info);
|
|
|
|
|
2017-12-05 11:52:03 -08:00
|
|
|
builder.setItems(numberItems, (dialog, which) -> composeText.append(numbers[which]));
|
2013-10-17 02:28:36 +02:00
|
|
|
builder.show();
|
|
|
|
}
|
|
|
|
|
2014-12-11 17:13:01 -08:00
|
|
|
private Drafts getDraftsForCurrentState() {
|
|
|
|
Drafts drafts = new Drafts();
|
2013-02-04 00:13:07 -08:00
|
|
|
|
|
|
|
if (!Util.isEmpty(composeText)) {
|
2017-07-04 19:09:36 +02:00
|
|
|
drafts.add(new Draft(Draft.TEXT, composeText.getTextTrimmed()));
|
2013-02-04 00:13:07 -08:00
|
|
|
}
|
|
|
|
|
2015-10-15 14:40:45 -07:00
|
|
|
for (Slide slide : attachmentManager.buildSlideDeck().getSlides()) {
|
2016-12-11 13:37:27 -08:00
|
|
|
if (slide.hasAudio() && slide.getUri() != null) drafts.add(new Draft(Draft.AUDIO, slide.getUri().toString()));
|
|
|
|
else if (slide.hasVideo() && slide.getUri() != null) drafts.add(new Draft(Draft.VIDEO, slide.getUri().toString()));
|
|
|
|
else if (slide.hasLocation()) drafts.add(new Draft(Draft.LOCATION, ((LocationSlide)slide).getPlace().serialize()));
|
|
|
|
else if (slide.hasImage() && slide.getUri() != null) drafts.add(new Draft(Draft.IMAGE, slide.getUri().toString()));
|
2013-02-04 00:13:07 -08:00
|
|
|
}
|
|
|
|
|
2018-04-24 11:09:54 -07:00
|
|
|
Optional<QuoteModel> quote = inputPanel.getQuote();
|
|
|
|
|
|
|
|
if (quote.isPresent()) {
|
|
|
|
drafts.add(new Draft(Draft.QUOTE, new QuoteId(quote.get().getId(), quote.get().getAuthor()).serialize()));
|
|
|
|
}
|
|
|
|
|
2013-02-04 00:13:07 -08:00
|
|
|
return drafts;
|
|
|
|
}
|
|
|
|
|
2015-06-22 08:46:43 -07:00
|
|
|
protected ListenableFuture<Long> saveDraft() {
|
|
|
|
final SettableFuture<Long> future = new SettableFuture<>();
|
|
|
|
|
2017-08-01 08:56:00 -07:00
|
|
|
if (this.recipient == null) {
|
2015-06-22 08:46:43 -07:00
|
|
|
future.set(threadId);
|
|
|
|
return future;
|
|
|
|
}
|
2013-02-04 00:13:07 -08:00
|
|
|
|
2015-01-04 00:25:35 +01:00
|
|
|
final Drafts drafts = getDraftsForCurrentState();
|
|
|
|
final long thisThreadId = this.threadId;
|
|
|
|
final int thisDistributionType = this.distributionType;
|
2013-02-04 00:13:07 -08:00
|
|
|
|
2015-06-22 08:46:43 -07:00
|
|
|
new AsyncTask<Long, Void, Long>() {
|
2013-02-04 00:13:07 -08:00
|
|
|
@Override
|
2015-06-22 08:46:43 -07:00
|
|
|
protected Long doInBackground(Long... params) {
|
2014-12-11 17:13:01 -08:00
|
|
|
ThreadDatabase threadDatabase = DatabaseFactory.getThreadDatabase(ConversationActivity.this);
|
2015-01-04 00:25:35 +01:00
|
|
|
DraftDatabase draftDatabase = DatabaseFactory.getDraftDatabase(ConversationActivity.this);
|
|
|
|
long threadId = params[0];
|
|
|
|
|
2014-12-11 17:13:01 -08:00
|
|
|
if (drafts.size() > 0) {
|
2017-08-01 08:56:00 -07:00
|
|
|
if (threadId == -1) threadId = threadDatabase.getThreadIdFor(getRecipient(), thisDistributionType);
|
2015-01-04 00:25:35 +01:00
|
|
|
|
2018-01-24 19:17:44 -08:00
|
|
|
draftDatabase.insertDrafts(threadId, drafts);
|
2015-10-16 13:59:40 -07:00
|
|
|
threadDatabase.updateSnippet(threadId, drafts.getSnippet(ConversationActivity.this),
|
2018-01-24 19:17:44 -08:00
|
|
|
drafts.getUriSnippet(),
|
2015-11-23 15:07:41 -08:00
|
|
|
System.currentTimeMillis(), Types.BASE_DRAFT_TYPE, true);
|
2015-01-04 00:25:35 +01:00
|
|
|
} else if (threadId > 0) {
|
2015-11-23 15:07:41 -08:00
|
|
|
threadDatabase.update(threadId, false);
|
2014-12-11 17:13:01 -08:00
|
|
|
}
|
2015-06-22 08:46:43 -07:00
|
|
|
|
|
|
|
return threadId;
|
2013-02-04 00:13:07 -08:00
|
|
|
}
|
2015-06-22 08:46:43 -07:00
|
|
|
|
|
|
|
@Override
|
|
|
|
protected void onPostExecute(Long result) {
|
|
|
|
future.set(result);
|
|
|
|
}
|
|
|
|
|
2017-10-23 13:03:32 -07:00
|
|
|
}.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR, thisThreadId);
|
2015-06-22 08:46:43 -07:00
|
|
|
|
|
|
|
return future;
|
2013-02-04 00:13:07 -08:00
|
|
|
}
|
|
|
|
|
2015-06-30 09:16:05 -07:00
|
|
|
private void setActionBarColor(MaterialColor color) {
|
2017-12-05 11:52:03 -08:00
|
|
|
ActionBar supportActionBar = getSupportActionBar();
|
|
|
|
if (supportActionBar == null) throw new AssertionError();
|
|
|
|
supportActionBar.setBackgroundDrawable(new ColorDrawable(color.toActionBarColor(this)));
|
2015-10-19 11:23:12 -07:00
|
|
|
setStatusBarColor(color.toStatusBarColor(this));
|
2015-06-23 15:10:50 -07:00
|
|
|
}
|
|
|
|
|
2017-08-01 08:56:00 -07:00
|
|
|
private void setBlockedUserState(Recipient recipient, boolean isSecureText, boolean isDefaultSms) {
|
|
|
|
if (recipient.isBlocked()) {
|
2015-06-09 07:37:20 -07:00
|
|
|
unblockButton.setVisibility(View.VISIBLE);
|
|
|
|
composePanel.setVisibility(View.GONE);
|
2016-11-20 15:56:47 -08:00
|
|
|
makeDefaultSmsButton.setVisibility(View.GONE);
|
2017-12-25 15:57:33 -08:00
|
|
|
registerButton.setVisibility(View.GONE);
|
|
|
|
} else if (!isSecureText && isPushGroupConversation()) {
|
|
|
|
unblockButton.setVisibility(View.GONE);
|
|
|
|
composePanel.setVisibility(View.GONE);
|
|
|
|
makeDefaultSmsButton.setVisibility(View.GONE);
|
|
|
|
registerButton.setVisibility(View.VISIBLE);
|
2017-01-18 11:01:13 -08:00
|
|
|
} else if (!isSecureText && !isDefaultSms) {
|
2016-11-20 15:56:47 -08:00
|
|
|
unblockButton.setVisibility(View.GONE);
|
|
|
|
composePanel.setVisibility(View.GONE);
|
|
|
|
makeDefaultSmsButton.setVisibility(View.VISIBLE);
|
2017-12-25 15:57:33 -08:00
|
|
|
registerButton.setVisibility(View.GONE);
|
2015-06-09 07:37:20 -07:00
|
|
|
} else {
|
|
|
|
composePanel.setVisibility(View.VISIBLE);
|
|
|
|
unblockButton.setVisibility(View.GONE);
|
2016-11-20 15:56:47 -08:00
|
|
|
makeDefaultSmsButton.setVisibility(View.GONE);
|
2017-12-25 15:57:33 -08:00
|
|
|
registerButton.setVisibility(View.GONE);
|
2015-06-09 07:37:20 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-08-22 11:51:01 -07:00
|
|
|
private void setGroupShareProfileReminder(@NonNull Recipient recipient) {
|
|
|
|
if (recipient.isPushGroupRecipient() && !recipient.isProfileSharing()) {
|
|
|
|
groupShareProfileView.get().setRecipient(recipient);
|
|
|
|
groupShareProfileView.get().setVisibility(View.VISIBLE);
|
|
|
|
} else if (groupShareProfileView.resolved()) {
|
|
|
|
groupShareProfileView.get().setVisibility(View.GONE);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-07-19 14:22:03 -07:00
|
|
|
private void calculateCharactersRemaining() {
|
2017-07-04 19:09:36 +02:00
|
|
|
String messageBody = composeText.getTextTrimmed();
|
2015-03-07 09:02:10 -08:00
|
|
|
TransportOption transportOption = sendButton.getSelectedTransport();
|
2016-04-17 18:09:31 +02:00
|
|
|
CharacterState characterState = transportOption.calculateCharacters(messageBody);
|
2015-03-07 09:02:10 -08:00
|
|
|
|
2015-03-11 14:23:45 -07:00
|
|
|
if (characterState.charactersRemaining <= 15 || characterState.messagesSpent > 1) {
|
2017-12-05 11:52:03 -08:00
|
|
|
charactersLeft.setText(String.format(dynamicLanguage.getCurrentLocale(),
|
|
|
|
"%d/%d (%d)",
|
|
|
|
characterState.charactersRemaining,
|
|
|
|
characterState.maxMessageSize,
|
|
|
|
characterState.messagesSpent));
|
2015-03-11 14:23:45 -07:00
|
|
|
charactersLeft.setVisibility(View.VISIBLE);
|
|
|
|
} else {
|
|
|
|
charactersLeft.setVisibility(View.GONE);
|
2014-01-08 12:29:05 -10:00
|
|
|
}
|
2012-07-19 14:22:03 -07:00
|
|
|
}
|
|
|
|
|
2012-08-01 17:39:36 -07:00
|
|
|
private boolean isSingleConversation() {
|
2017-08-01 08:56:00 -07:00
|
|
|
return getRecipient() != null && !getRecipient().isGroupRecipient();
|
2012-10-21 14:34:09 -07:00
|
|
|
}
|
|
|
|
|
2014-02-22 10:54:43 -08:00
|
|
|
private boolean isActiveGroup() {
|
|
|
|
if (!isGroupConversation()) return false;
|
|
|
|
|
2017-08-07 16:47:38 -07:00
|
|
|
Optional<GroupRecord> record = DatabaseFactory.getGroupDatabase(this).getGroup(getRecipient().getAddress().toGroupString());
|
|
|
|
return record.isPresent() && record.get().isActive();
|
2014-02-22 10:54:43 -08:00
|
|
|
}
|
|
|
|
|
2017-12-05 11:52:03 -08:00
|
|
|
@SuppressWarnings("SimplifiableIfStatement")
|
2015-10-01 11:14:00 -07:00
|
|
|
private boolean isSelfConversation() {
|
2017-08-01 08:56:00 -07:00
|
|
|
if (!TextSecurePreferences.isPushRegistered(this)) return false;
|
2017-12-05 11:52:03 -08:00
|
|
|
if (recipient.isGroupRecipient()) return false;
|
2015-10-01 11:14:00 -07:00
|
|
|
|
2017-08-01 08:56:00 -07:00
|
|
|
return Util.isOwnNumber(this, recipient.getAddress());
|
2015-10-01 11:14:00 -07:00
|
|
|
}
|
|
|
|
|
2012-10-21 14:34:09 -07:00
|
|
|
private boolean isGroupConversation() {
|
2017-08-01 08:56:00 -07:00
|
|
|
return getRecipient() != null && getRecipient().isGroupRecipient();
|
2012-07-19 14:22:03 -07:00
|
|
|
}
|
|
|
|
|
2014-02-17 20:25:40 -08:00
|
|
|
private boolean isPushGroupConversation() {
|
2017-08-01 08:56:00 -07:00
|
|
|
return getRecipient() != null && getRecipient().isPushGroupRecipient();
|
2014-02-17 20:25:40 -08:00
|
|
|
}
|
|
|
|
|
2018-04-26 17:03:54 -07:00
|
|
|
private boolean isSmsForced() {
|
|
|
|
return sendButton.isManualSelection() && sendButton.getSelectedTransport().isSms();
|
|
|
|
}
|
|
|
|
|
2017-08-01 08:56:00 -07:00
|
|
|
protected Recipient getRecipient() {
|
|
|
|
return this.recipient;
|
2012-07-19 14:22:03 -07:00
|
|
|
}
|
|
|
|
|
2015-06-22 08:46:43 -07:00
|
|
|
protected long getThreadId() {
|
|
|
|
return this.threadId;
|
|
|
|
}
|
|
|
|
|
2012-07-19 14:22:03 -07:00
|
|
|
private String getMessage() throws InvalidMessageException {
|
2017-07-04 19:09:36 +02:00
|
|
|
String rawText = composeText.getTextTrimmed();
|
2012-07-19 14:22:03 -07:00
|
|
|
|
|
|
|
if (rawText.length() < 1 && !attachmentManager.isAttachmentPresent())
|
2012-09-19 19:56:04 -07:00
|
|
|
throw new InvalidMessageException(getString(R.string.ConversationActivity_message_is_empty_exclamation));
|
2012-07-19 14:22:03 -07:00
|
|
|
|
|
|
|
return rawText;
|
|
|
|
}
|
|
|
|
|
2015-09-04 17:33:22 -07:00
|
|
|
private MediaConstraints getCurrentMediaConstraints() {
|
|
|
|
return sendButton.getSelectedTransport().getType() == Type.TEXTSECURE
|
2017-05-08 15:32:59 -07:00
|
|
|
? MediaConstraints.getPushMediaConstraints()
|
|
|
|
: MediaConstraints.getMmsMediaConstraints(sendButton.getSelectedTransport().getSimSubscriptionId().or(-1));
|
2015-09-04 17:33:22 -07:00
|
|
|
}
|
|
|
|
|
2013-02-03 18:41:34 -08:00
|
|
|
private void markThreadAsRead() {
|
|
|
|
new AsyncTask<Long, Void, Void>() {
|
|
|
|
@Override
|
|
|
|
protected Void doInBackground(Long... params) {
|
2016-10-10 11:13:37 -07:00
|
|
|
Context context = ConversationActivity.this;
|
2017-02-22 15:05:35 -08:00
|
|
|
List<MarkedMessageInfo> messageIds = DatabaseFactory.getThreadDatabase(context).setRead(params[0], false);
|
2016-02-19 17:07:41 -08:00
|
|
|
|
2018-01-24 19:17:44 -08:00
|
|
|
MessageNotifier.updateNotification(context);
|
2016-10-10 11:13:37 -07:00
|
|
|
MarkReadReceiver.process(context, messageIds);
|
2016-02-19 17:07:41 -08:00
|
|
|
|
2013-02-03 18:41:34 -08:00
|
|
|
return null;
|
|
|
|
}
|
2017-10-23 13:03:32 -07:00
|
|
|
}.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR, threadId);
|
2013-02-03 18:41:34 -08:00
|
|
|
}
|
|
|
|
|
2017-02-13 22:35:47 -08:00
|
|
|
private void markLastSeen() {
|
|
|
|
new AsyncTask<Long, Void, Void>() {
|
|
|
|
@Override
|
|
|
|
protected Void doInBackground(Long... params) {
|
|
|
|
DatabaseFactory.getThreadDatabase(ConversationActivity.this).setLastSeen(params[0]);
|
|
|
|
return null;
|
|
|
|
}
|
2017-10-23 13:03:32 -07:00
|
|
|
}.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR, threadId);
|
2017-02-13 22:35:47 -08:00
|
|
|
}
|
|
|
|
|
2015-06-22 08:46:43 -07:00
|
|
|
protected void sendComplete(long threadId) {
|
2014-11-08 11:35:58 -08:00
|
|
|
boolean refreshFragment = (threadId != this.threadId);
|
|
|
|
this.threadId = threadId;
|
2012-07-19 14:22:03 -07:00
|
|
|
|
2015-04-08 17:43:14 -07:00
|
|
|
if (fragment == null || !fragment.isVisible() || isFinishing()) {
|
2014-11-24 22:48:50 -08:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2017-02-13 22:35:47 -08:00
|
|
|
fragment.setLastSeen(0);
|
|
|
|
|
2014-02-17 15:47:58 -08:00
|
|
|
if (refreshFragment) {
|
2017-08-01 08:56:00 -07:00
|
|
|
fragment.reload(recipient, threadId);
|
2015-10-08 19:15:07 +02:00
|
|
|
MessageNotifier.setVisibleThread(threadId);
|
2012-07-19 14:22:03 -07:00
|
|
|
}
|
2014-11-08 11:35:58 -08:00
|
|
|
|
2014-03-26 15:11:56 -07:00
|
|
|
fragment.scrollToBottom();
|
2015-05-18 10:26:32 -07:00
|
|
|
attachmentManager.cleanup();
|
2012-07-19 14:22:03 -07:00
|
|
|
}
|
|
|
|
|
2014-07-18 19:31:03 -07:00
|
|
|
private void sendMessage() {
|
2012-07-19 14:22:03 -07:00
|
|
|
try {
|
2017-08-01 08:56:00 -07:00
|
|
|
Recipient recipient = getRecipient();
|
2016-11-28 09:14:44 -08:00
|
|
|
|
2017-08-01 08:56:00 -07:00
|
|
|
if (recipient == null) {
|
2016-11-28 09:14:44 -08:00
|
|
|
throw new RecipientFormattingException("Badly formatted");
|
|
|
|
}
|
|
|
|
|
2016-02-05 16:10:33 -08:00
|
|
|
boolean forceSms = sendButton.isManualSelection() && sendButton.getSelectedTransport().isSms();
|
|
|
|
int subscriptionId = sendButton.getSelectedTransport().getSimSubscriptionId().or(-1);
|
2018-01-12 11:39:10 +00:00
|
|
|
long expiresIn = recipient.getExpireMessages() * 1000L;
|
2017-08-16 21:49:41 -07:00
|
|
|
boolean initiating = threadId == -1;
|
2015-03-11 14:23:45 -07:00
|
|
|
|
|
|
|
Log.w(TAG, "isManual Selection: " + sendButton.isManualSelection());
|
|
|
|
Log.w(TAG, "forceSms: " + forceSms);
|
2012-08-01 17:39:36 -07:00
|
|
|
|
2017-09-11 13:04:20 -07:00
|
|
|
if ((recipient.isMmsGroupRecipient() || recipient.getAddress().isEmail()) && !isMmsEnabled) {
|
2013-09-16 00:55:01 -07:00
|
|
|
handleManualMmsRequired();
|
2017-06-06 18:03:09 -07:00
|
|
|
} else if (!forceSms && identityRecords.isUnverified()) {
|
|
|
|
handleUnverifiedRecipients();
|
|
|
|
} else if (!forceSms && identityRecords.isUntrusted()) {
|
|
|
|
handleUntrustedRecipients();
|
2018-02-07 14:01:37 -08:00
|
|
|
} else if (attachmentManager.isAttachmentPresent() || recipient.isGroupRecipient() || recipient.getAddress().isEmail() || inputPanel.getQuote().isPresent()) {
|
2017-08-16 21:49:41 -07:00
|
|
|
sendMediaMessage(forceSms, expiresIn, subscriptionId, initiating);
|
2012-07-19 14:22:03 -07:00
|
|
|
} else {
|
2017-08-16 21:49:41 -07:00
|
|
|
sendTextMessage(forceSms, expiresIn, subscriptionId, initiating);
|
2012-07-19 14:22:03 -07:00
|
|
|
}
|
|
|
|
} catch (RecipientFormattingException ex) {
|
2012-09-07 20:03:23 -07:00
|
|
|
Toast.makeText(ConversationActivity.this,
|
2012-09-19 19:56:04 -07:00
|
|
|
R.string.ConversationActivity_recipient_is_not_a_valid_sms_or_email_address_exclamation,
|
2012-09-07 20:03:23 -07:00
|
|
|
Toast.LENGTH_LONG).show();
|
2014-02-17 20:25:40 -08:00
|
|
|
Log.w(TAG, ex);
|
2012-07-19 14:22:03 -07:00
|
|
|
} catch (InvalidMessageException ex) {
|
2012-09-19 19:56:04 -07:00
|
|
|
Toast.makeText(ConversationActivity.this, R.string.ConversationActivity_message_is_empty_exclamation,
|
2012-09-07 20:03:23 -07:00
|
|
|
Toast.LENGTH_SHORT).show();
|
2014-02-17 20:25:40 -08:00
|
|
|
Log.w(TAG, ex);
|
2012-07-19 14:22:03 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-08-16 21:49:41 -07:00
|
|
|
private void sendMediaMessage(final boolean forceSms, final long expiresIn, final int subscriptionId, boolean initiating)
|
2014-11-08 11:35:58 -08:00
|
|
|
throws InvalidMessageException
|
2014-06-11 15:31:59 -07:00
|
|
|
{
|
2018-02-07 14:01:37 -08:00
|
|
|
Log.w(TAG, "Sending media message...");
|
2018-04-26 17:03:54 -07:00
|
|
|
sendMediaMessage(forceSms, getMessage(), attachmentManager.buildSlideDeck(), Collections.emptyList(), expiresIn, subscriptionId, initiating);
|
2015-11-18 14:52:26 -08:00
|
|
|
}
|
|
|
|
|
2018-04-26 17:03:54 -07:00
|
|
|
private ListenableFuture<Void> sendMediaMessage(final boolean forceSms, String body, SlideDeck slideDeck, List<Contact> contacts, final long expiresIn, final int subscriptionId, final boolean initiating) {
|
|
|
|
OutgoingMediaMessage outgoingMessageCandidate = new OutgoingMediaMessage(recipient, slideDeck, body, System.currentTimeMillis(), subscriptionId, expiresIn, distributionType, inputPanel.getQuote().orNull(), contacts);
|
2014-06-11 15:31:59 -07:00
|
|
|
|
2017-12-05 11:35:15 -08:00
|
|
|
final SettableFuture<Void> future = new SettableFuture<>();
|
|
|
|
final Context context = getApplicationContext();
|
2014-11-08 11:35:58 -08:00
|
|
|
|
2017-12-05 11:35:15 -08:00
|
|
|
final OutgoingMediaMessage outgoingMessage;
|
2017-08-16 21:49:41 -07:00
|
|
|
|
2017-12-05 11:35:15 -08:00
|
|
|
if (isSecureText && !forceSms) {
|
|
|
|
outgoingMessage = new OutgoingSecureMediaMessage(outgoingMessageCandidate);
|
|
|
|
} else {
|
|
|
|
outgoingMessage = outgoingMessageCandidate;
|
|
|
|
}
|
2014-11-08 11:35:58 -08:00
|
|
|
|
2017-12-05 11:35:15 -08:00
|
|
|
Permissions.with(this)
|
2017-12-20 11:21:00 -08:00
|
|
|
.request(Manifest.permission.SEND_SMS, Manifest.permission.READ_SMS)
|
2017-12-13 10:29:19 -08:00
|
|
|
.ifNecessary(!isSecureText || forceSms)
|
2017-12-05 11:35:15 -08:00
|
|
|
.withPermanentDenialDialog(getString(R.string.ConversationActivity_signal_needs_sms_permission_in_order_to_send_an_sms))
|
|
|
|
.onAllGranted(() -> {
|
2018-02-07 14:01:37 -08:00
|
|
|
inputPanel.clearQuote();
|
2017-12-05 11:35:15 -08:00
|
|
|
attachmentManager.clear(glideRequests, false);
|
|
|
|
composeText.setText("");
|
|
|
|
final long id = fragment.stageOutgoingMessage(outgoingMessage);
|
|
|
|
|
|
|
|
new AsyncTask<Void, Void, Long>() {
|
|
|
|
@Override
|
|
|
|
protected Long doInBackground(Void... param) {
|
|
|
|
if (initiating) {
|
|
|
|
DatabaseFactory.getRecipientDatabase(context).setProfileSharing(recipient, true);
|
|
|
|
}
|
|
|
|
|
2018-01-24 19:17:44 -08:00
|
|
|
return MessageSender.send(context, outgoingMessage, threadId, forceSms, () -> fragment.releaseOutgoingMessage(id));
|
2017-12-05 11:35:15 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
protected void onPostExecute(Long result) {
|
|
|
|
sendComplete(result);
|
|
|
|
future.set(null);
|
|
|
|
}
|
|
|
|
}.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
|
|
|
|
})
|
|
|
|
.onAnyDenied(() -> future.set(null))
|
|
|
|
.execute();
|
2015-11-18 14:52:26 -08:00
|
|
|
|
|
|
|
return future;
|
2014-06-11 15:31:59 -07:00
|
|
|
}
|
|
|
|
|
2017-08-16 21:49:41 -07:00
|
|
|
private void sendTextMessage(final boolean forceSms, final long expiresIn, final int subscriptionId, final boolean initiatingConversation)
|
2014-06-11 15:31:59 -07:00
|
|
|
throws InvalidMessageException
|
|
|
|
{
|
2017-12-05 11:35:15 -08:00
|
|
|
final Context context = getApplicationContext();
|
|
|
|
final String messageBody = getMessage();
|
|
|
|
|
2014-06-11 15:31:59 -07:00
|
|
|
OutgoingTextMessage message;
|
|
|
|
|
2015-09-29 14:26:37 -07:00
|
|
|
if (isSecureText && !forceSms) {
|
2017-12-05 11:35:15 -08:00
|
|
|
message = new OutgoingEncryptedMessage(recipient, messageBody, expiresIn);
|
2014-06-11 15:31:59 -07:00
|
|
|
} else {
|
2017-12-05 11:35:15 -08:00
|
|
|
message = new OutgoingTextMessage(recipient, messageBody, expiresIn, subscriptionId);
|
2014-06-11 15:31:59 -07:00
|
|
|
}
|
|
|
|
|
2017-12-05 11:35:15 -08:00
|
|
|
Permissions.with(this)
|
|
|
|
.request(Manifest.permission.SEND_SMS)
|
|
|
|
.ifNecessary(forceSms || !isSecureText)
|
|
|
|
.withPermanentDenialDialog(getString(R.string.ConversationActivity_signal_needs_sms_permission_in_order_to_send_an_sms))
|
|
|
|
.onAllGranted(() -> {
|
|
|
|
this.composeText.setText("");
|
|
|
|
final long id = fragment.stageOutgoingMessage(message);
|
|
|
|
|
|
|
|
new AsyncTask<OutgoingTextMessage, Void, Long>() {
|
|
|
|
@Override
|
|
|
|
protected Long doInBackground(OutgoingTextMessage... messages) {
|
|
|
|
if (initiatingConversation) {
|
|
|
|
DatabaseFactory.getRecipientDatabase(context).setProfileSharing(recipient, true);
|
|
|
|
}
|
|
|
|
|
2018-01-24 19:17:44 -08:00
|
|
|
return MessageSender.send(context, messages[0], threadId, forceSms, () -> fragment.releaseOutgoingMessage(id));
|
2017-12-05 11:35:15 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
protected void onPostExecute(Long result) {
|
|
|
|
sendComplete(result);
|
|
|
|
}
|
|
|
|
}.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR, message);
|
|
|
|
|
|
|
|
})
|
|
|
|
.execute();
|
2014-06-11 15:31:59 -07:00
|
|
|
}
|
|
|
|
|
2015-05-18 10:26:32 -07:00
|
|
|
private void updateToggleButtonState() {
|
2017-11-19 16:53:12 -08:00
|
|
|
if (composeText.getText().length() == 0 && !attachmentManager.isAttachmentPresent()) {
|
2015-05-18 10:26:32 -07:00
|
|
|
buttonToggle.display(attachButton);
|
2015-06-08 11:07:46 -07:00
|
|
|
quickAttachmentToggle.show();
|
2015-05-18 10:26:32 -07:00
|
|
|
} else {
|
|
|
|
buttonToggle.display(sendButton);
|
2015-06-08 11:07:46 -07:00
|
|
|
quickAttachmentToggle.hide();
|
2015-05-18 10:26:32 -07:00
|
|
|
}
|
|
|
|
}
|
2014-06-11 15:31:59 -07:00
|
|
|
|
2016-02-05 16:10:33 -08:00
|
|
|
private void recordSubscriptionIdPreference(final Optional<Integer> subscriptionId) {
|
|
|
|
new AsyncTask<Void, Void, Void>() {
|
|
|
|
@Override
|
|
|
|
protected Void doInBackground(Void... params) {
|
2017-08-21 18:47:37 -07:00
|
|
|
DatabaseFactory.getRecipientDatabase(ConversationActivity.this)
|
2017-08-01 08:56:00 -07:00
|
|
|
.setDefaultSubscriptionId(recipient, subscriptionId.or(-1));
|
2016-02-05 16:10:33 -08:00
|
|
|
return null;
|
|
|
|
}
|
2017-10-23 13:03:32 -07:00
|
|
|
}.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
|
2016-02-05 16:10:33 -08:00
|
|
|
}
|
|
|
|
|
2015-06-08 11:07:46 -07:00
|
|
|
@Override
|
2015-07-24 13:22:28 -07:00
|
|
|
public void onAttachmentDrawerStateChanged(DrawerState drawerState) {
|
2017-12-05 11:52:03 -08:00
|
|
|
ActionBar supportActionBar = getSupportActionBar();
|
|
|
|
if (supportActionBar == null) throw new AssertionError();
|
|
|
|
|
2015-07-24 13:22:28 -07:00
|
|
|
if (drawerState == DrawerState.FULL_EXPANDED) {
|
2017-12-05 11:52:03 -08:00
|
|
|
supportActionBar.hide();
|
2015-07-24 13:22:28 -07:00
|
|
|
} else {
|
2017-12-05 11:52:03 -08:00
|
|
|
supportActionBar.show();
|
2015-07-24 13:22:28 -07:00
|
|
|
}
|
2015-11-16 17:11:03 -08:00
|
|
|
|
|
|
|
if (drawerState == DrawerState.COLLAPSED) {
|
|
|
|
container.hideAttachedInput(true);
|
|
|
|
}
|
2015-06-08 11:07:46 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2015-07-13 17:35:34 -07:00
|
|
|
public void onImageCapture(@NonNull final byte[] imageBytes) {
|
2015-11-21 16:18:19 +09:00
|
|
|
setMedia(PersistentBlobProvider.getInstance(this)
|
2018-01-24 19:17:44 -08:00
|
|
|
.create(this, imageBytes, MediaUtil.IMAGE_JPEG, null),
|
2015-11-21 16:18:19 +09:00
|
|
|
MediaType.IMAGE);
|
2015-07-24 13:22:28 -07:00
|
|
|
quickAttachmentDrawer.hide(false);
|
2015-06-08 11:07:46 -07:00
|
|
|
}
|
|
|
|
|
2015-07-13 17:35:34 -07:00
|
|
|
@Override
|
2015-11-13 17:13:40 -08:00
|
|
|
public void onCameraFail() {
|
2015-09-24 16:53:48 -07:00
|
|
|
Toast.makeText(this, R.string.ConversationActivity_quick_camera_unavailable, Toast.LENGTH_SHORT).show();
|
2015-07-24 13:22:28 -07:00
|
|
|
quickAttachmentDrawer.hide(false);
|
2015-07-13 17:35:34 -07:00
|
|
|
quickAttachmentToggle.disable();
|
|
|
|
}
|
|
|
|
|
2015-11-23 15:19:05 -08:00
|
|
|
@Override
|
|
|
|
public void onCameraStart() {}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void onCameraStop() {}
|
|
|
|
|
2017-11-24 22:00:30 -08:00
|
|
|
@Override
|
|
|
|
public void onRecorderPermissionRequired() {
|
|
|
|
Permissions.with(this)
|
|
|
|
.request(Manifest.permission.RECORD_AUDIO)
|
|
|
|
.ifNecessary()
|
|
|
|
.withRationaleDialog(getString(R.string.ConversationActivity_to_send_audio_messages_allow_signal_access_to_your_microphone), R.drawable.ic_mic_white_48dp)
|
|
|
|
.withPermanentDenialDialog(getString(R.string.ConversationActivity_signal_requires_the_microphone_permission_in_order_to_send_audio_messages))
|
|
|
|
.execute();
|
|
|
|
}
|
|
|
|
|
2015-11-18 14:52:26 -08:00
|
|
|
@Override
|
|
|
|
public void onRecorderStarted() {
|
2017-12-05 11:52:03 -08:00
|
|
|
Vibrator vibrator = ServiceUtil.getVibrator(this);
|
2015-11-22 10:44:44 -08:00
|
|
|
vibrator.vibrate(20);
|
2017-12-05 11:52:03 -08:00
|
|
|
|
2017-02-16 21:28:06 +01:00
|
|
|
getWindow().addFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON);
|
2015-11-18 14:52:26 -08:00
|
|
|
|
2015-11-22 10:44:44 -08:00
|
|
|
audioRecorder.startRecording();
|
2015-11-18 14:52:26 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void onRecorderFinished() {
|
2017-12-05 11:52:03 -08:00
|
|
|
Vibrator vibrator = ServiceUtil.getVibrator(this);
|
2015-11-18 14:52:26 -08:00
|
|
|
vibrator.vibrate(20);
|
2017-12-05 11:52:03 -08:00
|
|
|
|
2017-02-16 21:28:06 +01:00
|
|
|
getWindow().clearFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON);
|
2015-11-18 14:52:26 -08:00
|
|
|
|
|
|
|
ListenableFuture<Pair<Uri, Long>> future = audioRecorder.stopRecording();
|
|
|
|
future.addListener(new ListenableFuture.Listener<Pair<Uri, Long>>() {
|
|
|
|
@Override
|
|
|
|
public void onSuccess(final @NonNull Pair<Uri, Long> result) {
|
2017-12-05 11:35:15 -08:00
|
|
|
boolean forceSms = sendButton.isManualSelection() && sendButton.getSelectedTransport().isSms();
|
|
|
|
int subscriptionId = sendButton.getSelectedTransport().getSimSubscriptionId().or(-1);
|
2018-01-12 11:39:10 +00:00
|
|
|
long expiresIn = recipient.getExpireMessages() * 1000L;
|
2017-12-05 11:35:15 -08:00
|
|
|
boolean initiating = threadId == -1;
|
|
|
|
AudioSlide audioSlide = new AudioSlide(ConversationActivity.this, result.first, result.second, MediaUtil.AUDIO_AAC, true);
|
|
|
|
SlideDeck slideDeck = new SlideDeck();
|
|
|
|
slideDeck.addSlide(audioSlide);
|
|
|
|
|
2018-04-26 17:03:54 -07:00
|
|
|
sendMediaMessage(forceSms, "", slideDeck, Collections.emptyList(), expiresIn, subscriptionId, initiating).addListener(new AssertedSuccessListener<Void>() {
|
2017-12-05 11:35:15 -08:00
|
|
|
@Override
|
|
|
|
public void onSuccess(Void nothing) {
|
|
|
|
new AsyncTask<Void, Void, Void>() {
|
|
|
|
@Override
|
|
|
|
protected Void doInBackground(Void... params) {
|
2018-01-24 19:17:44 -08:00
|
|
|
PersistentBlobProvider.getInstance(ConversationActivity.this).delete(ConversationActivity.this, result.first);
|
2017-12-05 11:35:15 -08:00
|
|
|
return null;
|
|
|
|
}
|
|
|
|
}.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
|
|
|
|
}
|
|
|
|
});
|
2015-11-18 14:52:26 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void onFailure(ExecutionException e) {
|
|
|
|
Toast.makeText(ConversationActivity.this, R.string.ConversationActivity_unable_to_record_audio, Toast.LENGTH_LONG).show();
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void onRecorderCanceled() {
|
2017-12-05 11:52:03 -08:00
|
|
|
Vibrator vibrator = ServiceUtil.getVibrator(this);
|
2015-11-18 14:52:26 -08:00
|
|
|
vibrator.vibrate(50);
|
2017-12-05 11:52:03 -08:00
|
|
|
|
2017-02-16 21:28:06 +01:00
|
|
|
getWindow().clearFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON);
|
2015-11-18 14:52:26 -08:00
|
|
|
|
|
|
|
ListenableFuture<Pair<Uri, Long>> future = audioRecorder.stopRecording();
|
|
|
|
future.addListener(new ListenableFuture.Listener<Pair<Uri, Long>>() {
|
|
|
|
@Override
|
|
|
|
public void onSuccess(final Pair<Uri, Long> result) {
|
|
|
|
new AsyncTask<Void, Void, Void>() {
|
|
|
|
@Override
|
|
|
|
protected Void doInBackground(Void... params) {
|
2018-01-24 19:17:44 -08:00
|
|
|
PersistentBlobProvider.getInstance(ConversationActivity.this).delete(ConversationActivity.this, result.first);
|
2015-11-18 14:52:26 -08:00
|
|
|
return null;
|
|
|
|
}
|
2017-10-23 13:03:32 -07:00
|
|
|
}.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
|
2015-11-18 14:52:26 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void onFailure(ExecutionException e) {}
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2015-11-22 10:44:53 -08:00
|
|
|
@Override
|
|
|
|
public void onEmojiToggle() {
|
2017-01-19 11:31:41 -08:00
|
|
|
if (!emojiDrawerStub.resolved()) {
|
|
|
|
inputPanel.setEmojiDrawer(emojiDrawerStub.get());
|
|
|
|
emojiDrawerStub.get().setEmojiEventListener(inputPanel);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (container.getCurrentInput() == emojiDrawerStub.get()) {
|
|
|
|
container.showSoftkey(composeText);
|
|
|
|
} else {
|
|
|
|
container.show(composeText, emojiDrawerStub.get());
|
|
|
|
}
|
2015-11-22 10:44:53 -08:00
|
|
|
}
|
|
|
|
|
2016-12-26 15:14:23 -08:00
|
|
|
@Override
|
|
|
|
public void onMediaSelected(@NonNull Uri uri, String contentType) {
|
|
|
|
if (!TextUtils.isEmpty(contentType) && contentType.trim().equals("image/gif")) {
|
|
|
|
setMedia(uri, MediaType.GIF);
|
2017-05-08 15:32:59 -07:00
|
|
|
} else if (MediaUtil.isImageType(contentType)) {
|
2016-12-26 15:14:23 -08:00
|
|
|
setMedia(uri, MediaType.IMAGE);
|
2017-05-08 15:32:59 -07:00
|
|
|
} else if (MediaUtil.isVideoType(contentType)) {
|
2016-12-26 15:14:23 -08:00
|
|
|
setMedia(uri, MediaType.VIDEO);
|
2017-05-08 15:32:59 -07:00
|
|
|
} else if (MediaUtil.isAudioType(contentType)) {
|
2016-12-26 15:14:23 -08:00
|
|
|
setMedia(uri, MediaType.AUDIO);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2012-07-19 14:22:03 -07:00
|
|
|
// Listeners
|
|
|
|
|
2015-10-28 09:47:09 -07:00
|
|
|
private class AttachmentTypeListener implements AttachmentTypeSelector.AttachmentClickedListener {
|
2013-02-02 20:37:40 -08:00
|
|
|
@Override
|
2015-10-28 09:47:09 -07:00
|
|
|
public void onClick(int type) {
|
|
|
|
addAttachment(type);
|
2012-07-19 14:22:03 -07:00
|
|
|
}
|
2016-11-25 22:37:23 -08:00
|
|
|
|
|
|
|
@Override
|
|
|
|
public void onQuickAttachment(Uri uri) {
|
|
|
|
Intent intent = new Intent();
|
|
|
|
intent.setData(uri);
|
|
|
|
|
2017-04-18 16:33:03 -07:00
|
|
|
onActivityResult(PICK_GALLERY, RESULT_OK, intent);
|
2016-11-25 22:37:23 -08:00
|
|
|
}
|
2012-07-19 14:22:03 -07:00
|
|
|
}
|
|
|
|
|
2015-11-18 14:52:26 -08:00
|
|
|
private class QuickCameraToggleListener implements OnClickListener {
|
2015-04-16 01:38:33 -04:00
|
|
|
@Override
|
|
|
|
public void onClick(View v) {
|
2015-07-18 17:06:02 -04:00
|
|
|
if (!quickAttachmentDrawer.isShowing()) {
|
2017-11-24 22:00:30 -08:00
|
|
|
Permissions.with(ConversationActivity.this)
|
|
|
|
.request(Manifest.permission.CAMERA)
|
|
|
|
.ifNecessary()
|
|
|
|
.withRationaleDialog(getString(R.string.ConversationActivity_to_capture_photos_and_video_allow_signal_access_to_the_camera), R.drawable.ic_photo_camera_white_48dp)
|
|
|
|
.withPermanentDenialDialog(getString(R.string.ConversationActivity_signal_needs_the_camera_permission_to_take_photos_or_video))
|
|
|
|
.onAllGranted(() -> {
|
|
|
|
composeText.clearFocus();
|
|
|
|
container.show(composeText, quickAttachmentDrawer);
|
|
|
|
})
|
|
|
|
.onAnyDenied(() -> Toast.makeText(ConversationActivity.this, R.string.ConversationActivity_signal_needs_camera_permissions_to_take_photos_or_video, Toast.LENGTH_LONG).show())
|
|
|
|
.execute();
|
2015-07-18 17:06:02 -04:00
|
|
|
} else {
|
|
|
|
container.hideAttachedInput(false);
|
|
|
|
}
|
2015-04-16 01:38:33 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-07-19 14:22:03 -07:00
|
|
|
private class SendButtonListener implements OnClickListener, TextView.OnEditorActionListener {
|
2013-02-02 20:37:40 -08:00
|
|
|
@Override
|
2012-07-19 14:22:03 -07:00
|
|
|
public void onClick(View v) {
|
2014-07-18 19:31:03 -07:00
|
|
|
sendMessage();
|
2012-07-19 14:22:03 -07:00
|
|
|
}
|
|
|
|
|
2013-02-02 20:37:40 -08:00
|
|
|
@Override
|
2012-07-19 14:22:03 -07:00
|
|
|
public boolean onEditorAction(TextView v, int actionId, KeyEvent event) {
|
|
|
|
if (actionId == EditorInfo.IME_ACTION_SEND) {
|
|
|
|
sendButton.performClick();
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
2013-04-25 18:59:49 -07:00
|
|
|
}
|
2012-07-19 14:22:03 -07:00
|
|
|
|
2015-05-18 10:26:32 -07:00
|
|
|
private class AttachButtonListener implements OnClickListener {
|
|
|
|
@Override
|
|
|
|
public void onClick(View v) {
|
|
|
|
handleAddAttachment();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-07-26 22:49:43 +01:00
|
|
|
private class AttachButtonLongClickListener implements View.OnLongClickListener {
|
|
|
|
@Override
|
|
|
|
public boolean onLongClick(View v) {
|
|
|
|
return sendButton.performLongClick();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-05-28 20:53:34 -07:00
|
|
|
private class ComposeKeyPressedListener implements OnKeyListener, OnClickListener, TextWatcher, OnFocusChangeListener {
|
2015-05-18 10:26:32 -07:00
|
|
|
|
|
|
|
int beforeLength;
|
|
|
|
|
2013-06-27 20:57:27 -07:00
|
|
|
@Override
|
|
|
|
public boolean onKey(View v, int keyCode, KeyEvent event) {
|
|
|
|
if (event.getAction() == KeyEvent.ACTION_DOWN) {
|
|
|
|
if (keyCode == KeyEvent.KEYCODE_ENTER) {
|
2013-07-09 18:26:18 -07:00
|
|
|
if (TextSecurePreferences.isEnterSendsEnabled(ConversationActivity.this)) {
|
2013-06-27 20:57:27 -07:00
|
|
|
sendButton.dispatchKeyEvent(new KeyEvent(KeyEvent.ACTION_DOWN, KeyEvent.KEYCODE_ENTER));
|
|
|
|
sendButton.dispatchKeyEvent(new KeyEvent(KeyEvent.ACTION_UP, KeyEvent.KEYCODE_ENTER));
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void onClick(View v) {
|
2015-07-24 13:22:28 -07:00
|
|
|
container.showSoftkey(composeText);
|
2013-06-27 20:57:27 -07:00
|
|
|
}
|
|
|
|
|
2015-05-18 10:26:32 -07:00
|
|
|
@Override
|
|
|
|
public void beforeTextChanged(CharSequence s, int start, int count,int after) {
|
2017-07-04 19:09:36 +02:00
|
|
|
beforeLength = composeText.getTextTrimmed().length();
|
2015-05-18 10:26:32 -07:00
|
|
|
}
|
|
|
|
|
2013-02-02 20:37:40 -08:00
|
|
|
@Override
|
2012-07-19 14:22:03 -07:00
|
|
|
public void afterTextChanged(Editable s) {
|
|
|
|
calculateCharactersRemaining();
|
2015-05-18 10:26:32 -07:00
|
|
|
|
2017-07-04 19:09:36 +02:00
|
|
|
if (composeText.getTextTrimmed().length() == 0 || beforeLength == 0) {
|
2017-12-05 11:52:03 -08:00
|
|
|
composeText.postDelayed(ConversationActivity.this::updateToggleButtonState, 50);
|
2015-05-18 10:26:32 -07:00
|
|
|
}
|
2012-07-19 14:22:03 -07:00
|
|
|
}
|
2015-05-18 10:26:32 -07:00
|
|
|
|
2013-02-02 20:37:40 -08:00
|
|
|
@Override
|
2012-07-19 14:22:03 -07:00
|
|
|
public void onTextChanged(CharSequence s, int start, int before,int count) {}
|
2014-05-28 20:53:34 -07:00
|
|
|
|
|
|
|
@Override
|
2015-07-24 13:22:28 -07:00
|
|
|
public void onFocusChange(View v, boolean hasFocus) {}
|
2012-07-19 14:22:03 -07:00
|
|
|
}
|
2012-08-03 17:34:09 -07:00
|
|
|
|
2015-03-31 13:36:04 -07:00
|
|
|
@Override
|
|
|
|
public void setThreadId(long threadId) {
|
|
|
|
this.threadId = threadId;
|
|
|
|
}
|
|
|
|
|
2018-02-07 14:01:37 -08:00
|
|
|
@Override
|
|
|
|
public void handleReplyMessage(MessageRecord messageRecord) {
|
|
|
|
Recipient author;
|
|
|
|
|
|
|
|
if (messageRecord.isOutgoing()) {
|
|
|
|
author = Recipient.from(this, Address.fromSerialized(TextSecurePreferences.getLocalNumber(this)), true);
|
|
|
|
} else {
|
|
|
|
author = messageRecord.getIndividualRecipient();
|
|
|
|
}
|
|
|
|
|
2018-04-26 17:03:54 -07:00
|
|
|
if (messageRecord.isMms() && !((MmsMessageRecord) messageRecord).getSharedContacts().isEmpty()) {
|
|
|
|
Contact contact = ((MmsMessageRecord) messageRecord).getSharedContacts().get(0);
|
|
|
|
String displayName = ContactUtil.getDisplayName(contact);
|
|
|
|
String body = getString(R.string.ConversationActivity_quoted_contact_message, EmojiStrings.BUST_IN_SILHOUETTE, displayName);
|
|
|
|
SlideDeck slideDeck = new SlideDeck();
|
|
|
|
|
|
|
|
if (contact.getAvatarAttachment() != null) {
|
|
|
|
slideDeck.addSlide(MediaUtil.getSlideForAttachment(this, contact.getAvatarAttachment()));
|
|
|
|
}
|
|
|
|
|
|
|
|
inputPanel.setQuote(GlideApp.with(this),
|
|
|
|
messageRecord.getDateSent(),
|
|
|
|
author,
|
|
|
|
body,
|
|
|
|
slideDeck);
|
|
|
|
} else {
|
|
|
|
inputPanel.setQuote(GlideApp.with(this),
|
|
|
|
messageRecord.getDateSent(),
|
|
|
|
author,
|
|
|
|
messageRecord.getBody(),
|
|
|
|
messageRecord.isMms() ? ((MmsMessageRecord) messageRecord).getSlideDeck() : new SlideDeck());
|
|
|
|
}
|
2018-02-07 14:01:37 -08:00
|
|
|
}
|
|
|
|
|
2014-04-15 12:43:14 +02:00
|
|
|
@Override
|
|
|
|
public void onAttachmentChanged() {
|
2017-03-14 13:24:24 -07:00
|
|
|
handleSecurityChange(isSecureText, isDefaultSms);
|
2015-05-18 10:26:32 -07:00
|
|
|
updateToggleButtonState();
|
2014-04-15 12:43:14 +02:00
|
|
|
}
|
2015-09-04 17:33:22 -07:00
|
|
|
|
2017-06-06 18:03:09 -07:00
|
|
|
private class UnverifiedDismissedListener implements UnverifiedBannerView.DismissListener {
|
|
|
|
@Override
|
|
|
|
public void onDismissed(final List<IdentityRecord> unverifiedIdentities) {
|
|
|
|
final IdentityDatabase identityDatabase = DatabaseFactory.getIdentityDatabase(ConversationActivity.this);
|
|
|
|
|
|
|
|
new AsyncTask<Void, Void, Void>() {
|
|
|
|
@Override
|
|
|
|
protected Void doInBackground(Void... params) {
|
|
|
|
synchronized (SESSION_LOCK) {
|
|
|
|
for (IdentityRecord identityRecord : unverifiedIdentities) {
|
2017-07-26 09:59:15 -07:00
|
|
|
identityDatabase.setVerified(identityRecord.getAddress(),
|
2017-06-06 18:03:09 -07:00
|
|
|
identityRecord.getIdentityKey(),
|
|
|
|
VerifiedStatus.DEFAULT);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
protected void onPostExecute(Void result) {
|
|
|
|
initializeIdentityRecords();
|
|
|
|
}
|
2017-10-23 13:03:32 -07:00
|
|
|
}.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
|
2017-06-06 18:03:09 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
private class UnverifiedClickedListener implements UnverifiedBannerView.ClickListener {
|
|
|
|
@Override
|
|
|
|
public void onClicked(final List<IdentityRecord> unverifiedIdentities) {
|
|
|
|
Log.w(TAG, "onClicked: " + unverifiedIdentities.size());
|
|
|
|
if (unverifiedIdentities.size() == 1) {
|
|
|
|
Intent intent = new Intent(ConversationActivity.this, VerifyIdentityActivity.class);
|
2017-07-26 09:59:15 -07:00
|
|
|
intent.putExtra(VerifyIdentityActivity.ADDRESS_EXTRA, unverifiedIdentities.get(0).getAddress());
|
2017-06-06 18:03:09 -07:00
|
|
|
intent.putExtra(VerifyIdentityActivity.IDENTITY_EXTRA, new IdentityKeyParcelable(unverifiedIdentities.get(0).getIdentityKey()));
|
|
|
|
intent.putExtra(VerifyIdentityActivity.VERIFIED_EXTRA, false);
|
|
|
|
|
|
|
|
startActivity(intent);
|
|
|
|
} else {
|
|
|
|
String[] unverifiedNames = new String[unverifiedIdentities.size()];
|
|
|
|
|
|
|
|
for (int i=0;i<unverifiedIdentities.size();i++) {
|
2017-08-21 18:32:38 -07:00
|
|
|
unverifiedNames[i] = Recipient.from(ConversationActivity.this, unverifiedIdentities.get(i).getAddress(), false).toShortString();
|
2017-06-06 18:03:09 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
AlertDialog.Builder builder = new AlertDialog.Builder(ConversationActivity.this);
|
|
|
|
builder.setIconAttribute(R.attr.dialog_alert_icon);
|
|
|
|
builder.setTitle("No longer verified");
|
2017-12-05 11:52:03 -08:00
|
|
|
builder.setItems(unverifiedNames, (dialog, which) -> {
|
|
|
|
Intent intent = new Intent(ConversationActivity.this, VerifyIdentityActivity.class);
|
|
|
|
intent.putExtra(VerifyIdentityActivity.ADDRESS_EXTRA, unverifiedIdentities.get(which).getAddress());
|
|
|
|
intent.putExtra(VerifyIdentityActivity.IDENTITY_EXTRA, new IdentityKeyParcelable(unverifiedIdentities.get(which).getIdentityKey()));
|
|
|
|
intent.putExtra(VerifyIdentityActivity.VERIFIED_EXTRA, false);
|
2017-06-06 18:03:09 -07:00
|
|
|
|
2017-12-05 11:52:03 -08:00
|
|
|
startActivity(intent);
|
2017-06-06 18:03:09 -07:00
|
|
|
});
|
|
|
|
builder.show();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2018-04-24 11:09:54 -07:00
|
|
|
|
|
|
|
private class QuoteRestorationTask extends AsyncTask<Void, Void, MessageRecord> {
|
|
|
|
|
|
|
|
private final String serialized;
|
|
|
|
|
|
|
|
QuoteRestorationTask(@NonNull String serialized) {
|
|
|
|
this.serialized = serialized;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
protected MessageRecord doInBackground(Void... voids) {
|
|
|
|
QuoteId quoteId = QuoteId.deserialize(serialized);
|
|
|
|
|
|
|
|
if (quoteId != null) {
|
|
|
|
return DatabaseFactory.getMmsSmsDatabase(getApplicationContext()).getMessageFor(quoteId.getId(), quoteId.getAuthor());
|
|
|
|
}
|
|
|
|
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
protected void onPostExecute(MessageRecord messageRecord) {
|
|
|
|
if (messageRecord != null) {
|
|
|
|
handleReplyMessage(messageRecord);
|
|
|
|
} else {
|
|
|
|
Log.e(TAG, "Failed to restore a quote from a draft. No matching message record.");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2012-07-19 14:22:03 -07:00
|
|
|
}
|