2014-02-28 17:46:01 +00:00
|
|
|
package eu.siacs.conversations.ui;
|
2014-01-24 01:04:05 +00:00
|
|
|
|
2018-02-20 13:54:32 +00:00
|
|
|
import android.annotation.SuppressLint;
|
2015-07-19 16:36:28 +00:00
|
|
|
import android.app.Activity;
|
2018-02-21 14:46:56 +00:00
|
|
|
import android.content.SharedPreferences;
|
2018-02-20 13:54:32 +00:00
|
|
|
import android.content.pm.PackageManager;
|
2018-02-21 10:04:48 +00:00
|
|
|
import android.databinding.DataBindingUtil;
|
2018-02-20 13:54:32 +00:00
|
|
|
import android.net.Uri;
|
|
|
|
import android.os.Build;
|
2018-02-21 14:46:56 +00:00
|
|
|
import android.preference.PreferenceManager;
|
2018-02-20 13:54:32 +00:00
|
|
|
import android.provider.MediaStore;
|
2018-02-16 12:29:38 +00:00
|
|
|
import android.support.v7.app.AlertDialog;
|
2014-01-24 01:04:05 +00:00
|
|
|
import android.app.Fragment;
|
2014-05-01 20:33:49 +00:00
|
|
|
import android.app.PendingIntent;
|
2015-07-12 18:17:12 +00:00
|
|
|
import android.content.ActivityNotFoundException;
|
2014-07-31 11:26:05 +00:00
|
|
|
import android.content.Context;
|
2014-02-16 15:32:15 +00:00
|
|
|
import android.content.DialogInterface;
|
2014-03-04 01:51:01 +00:00
|
|
|
import android.content.Intent;
|
2014-02-27 23:22:56 +00:00
|
|
|
import android.content.IntentSender.SendIntentException;
|
2014-01-24 01:04:05 +00:00
|
|
|
import android.os.Bundle;
|
2016-05-12 08:39:04 +00:00
|
|
|
import android.os.Handler;
|
2017-11-17 20:00:01 +00:00
|
|
|
import android.os.SystemClock;
|
2016-12-30 20:48:39 +00:00
|
|
|
import android.support.v13.view.inputmethod.InputConnectionCompat;
|
|
|
|
import android.support.v13.view.inputmethod.InputContentInfoCompat;
|
2016-11-25 14:06:43 +00:00
|
|
|
import android.text.Editable;
|
2016-09-12 19:18:56 +00:00
|
|
|
import android.util.Log;
|
|
|
|
import android.util.Pair;
|
2014-10-23 19:27:41 +00:00
|
|
|
import android.view.ContextMenu;
|
|
|
|
import android.view.ContextMenu.ContextMenuInfo;
|
2014-06-01 16:52:27 +00:00
|
|
|
import android.view.Gravity;
|
2014-01-24 01:04:05 +00:00
|
|
|
import android.view.LayoutInflater;
|
2018-02-20 13:54:32 +00:00
|
|
|
import android.view.Menu;
|
|
|
|
import android.view.MenuInflater;
|
2014-10-23 19:27:41 +00:00
|
|
|
import android.view.MenuItem;
|
2017-11-17 20:00:01 +00:00
|
|
|
import android.view.MotionEvent;
|
2014-01-24 01:04:05 +00:00
|
|
|
import android.view.View;
|
2014-01-26 02:27:55 +00:00
|
|
|
import android.view.View.OnClickListener;
|
2014-01-24 01:04:05 +00:00
|
|
|
import android.view.ViewGroup;
|
2014-07-31 11:26:05 +00:00
|
|
|
import android.view.inputmethod.EditorInfo;
|
|
|
|
import android.view.inputmethod.InputMethodManager;
|
2014-06-14 14:59:07 +00:00
|
|
|
import android.widget.AbsListView;
|
2014-11-04 17:52:29 +00:00
|
|
|
import android.widget.AbsListView.OnScrollListener;
|
2014-10-23 19:27:41 +00:00
|
|
|
import android.widget.AdapterView;
|
|
|
|
import android.widget.AdapterView.AdapterContextMenuInfo;
|
2018-02-20 13:54:32 +00:00
|
|
|
import android.widget.CheckBox;
|
2014-11-04 17:52:29 +00:00
|
|
|
import android.widget.ListView;
|
2017-03-20 11:55:48 +00:00
|
|
|
import android.widget.PopupMenu;
|
2014-11-04 17:52:29 +00:00
|
|
|
import android.widget.TextView.OnEditorActionListener;
|
2014-03-04 03:09:15 +00:00
|
|
|
import android.widget.Toast;
|
2014-01-24 01:04:05 +00:00
|
|
|
|
2018-02-20 13:54:32 +00:00
|
|
|
import org.openintents.openpgp.util.OpenPgpApi;
|
|
|
|
|
2014-11-04 17:52:29 +00:00
|
|
|
import java.util.ArrayList;
|
2017-04-07 17:47:33 +00:00
|
|
|
import java.util.Arrays;
|
2015-09-27 17:17:44 +00:00
|
|
|
import java.util.Collections;
|
2017-11-19 00:53:04 +00:00
|
|
|
import java.util.HashSet;
|
2018-02-20 13:54:32 +00:00
|
|
|
import java.util.Iterator;
|
2014-11-04 17:52:29 +00:00
|
|
|
import java.util.List;
|
2017-11-19 00:53:04 +00:00
|
|
|
import java.util.Set;
|
2016-02-15 22:15:04 +00:00
|
|
|
import java.util.UUID;
|
2017-03-03 10:56:08 +00:00
|
|
|
import java.util.concurrent.atomic.AtomicBoolean;
|
2014-11-04 17:52:29 +00:00
|
|
|
|
2015-02-21 10:06:52 +00:00
|
|
|
import eu.siacs.conversations.Config;
|
2014-11-04 17:52:29 +00:00
|
|
|
import eu.siacs.conversations.R;
|
2018-02-20 13:54:32 +00:00
|
|
|
import eu.siacs.conversations.crypto.axolotl.AxolotlService;
|
|
|
|
import eu.siacs.conversations.crypto.axolotl.FingerprintStatus;
|
2018-02-21 10:04:48 +00:00
|
|
|
import eu.siacs.conversations.databinding.FragmentConversationBinding;
|
2014-11-04 17:52:29 +00:00
|
|
|
import eu.siacs.conversations.entities.Account;
|
2017-03-20 11:55:48 +00:00
|
|
|
import eu.siacs.conversations.entities.Blockable;
|
2014-11-04 17:52:29 +00:00
|
|
|
import eu.siacs.conversations.entities.Contact;
|
|
|
|
import eu.siacs.conversations.entities.Conversation;
|
2014-11-15 14:16:40 +00:00
|
|
|
import eu.siacs.conversations.entities.DownloadableFile;
|
2014-11-04 17:52:29 +00:00
|
|
|
import eu.siacs.conversations.entities.Message;
|
|
|
|
import eu.siacs.conversations.entities.MucOptions;
|
2016-01-17 21:28:38 +00:00
|
|
|
import eu.siacs.conversations.entities.Presence;
|
2017-11-19 00:53:04 +00:00
|
|
|
import eu.siacs.conversations.entities.ReadByMarker;
|
2015-07-20 12:26:29 +00:00
|
|
|
import eu.siacs.conversations.entities.Transferable;
|
|
|
|
import eu.siacs.conversations.entities.TransferablePlaceholder;
|
2016-03-04 10:24:40 +00:00
|
|
|
import eu.siacs.conversations.http.HttpDownloadConnection;
|
2017-01-09 16:00:08 +00:00
|
|
|
import eu.siacs.conversations.persistance.FileBackend;
|
2016-02-21 16:32:46 +00:00
|
|
|
import eu.siacs.conversations.services.MessageArchiveService;
|
2014-11-04 17:52:29 +00:00
|
|
|
import eu.siacs.conversations.services.XmppConnectionService;
|
|
|
|
import eu.siacs.conversations.ui.adapter.MessageAdapter;
|
2018-02-20 13:54:32 +00:00
|
|
|
import eu.siacs.conversations.ui.util.ActivityResult;
|
|
|
|
import eu.siacs.conversations.ui.util.AttachmentTool;
|
|
|
|
import eu.siacs.conversations.ui.util.ConversationMenuConfigurator;
|
2018-02-21 22:07:53 +00:00
|
|
|
import eu.siacs.conversations.ui.util.PendingItem;
|
2018-02-20 13:54:32 +00:00
|
|
|
import eu.siacs.conversations.ui.util.PresenceSelector;
|
2018-02-20 07:21:07 +00:00
|
|
|
import eu.siacs.conversations.ui.util.SendButtonAction;
|
2018-02-20 13:54:32 +00:00
|
|
|
import eu.siacs.conversations.ui.util.SendButtonTool;
|
2017-09-29 17:44:30 +00:00
|
|
|
import eu.siacs.conversations.ui.widget.EditMessage;
|
2017-11-07 21:22:28 +00:00
|
|
|
import eu.siacs.conversations.utils.MessageUtils;
|
2017-04-07 17:47:33 +00:00
|
|
|
import eu.siacs.conversations.utils.NickValidityChecker;
|
2017-11-05 20:34:40 +00:00
|
|
|
import eu.siacs.conversations.utils.StylingHelper;
|
2015-05-13 14:23:20 +00:00
|
|
|
import eu.siacs.conversations.utils.UIHelper;
|
2016-02-14 22:53:17 +00:00
|
|
|
import eu.siacs.conversations.xmpp.XmppConnection;
|
2015-02-21 10:06:52 +00:00
|
|
|
import eu.siacs.conversations.xmpp.chatstate.ChatState;
|
2014-11-06 19:33:13 +00:00
|
|
|
import eu.siacs.conversations.xmpp.jid.Jid;
|
2014-11-04 17:52:29 +00:00
|
|
|
|
2018-02-20 13:54:32 +00:00
|
|
|
import static eu.siacs.conversations.ui.XmppActivity.EXTRA_ACCOUNT;
|
|
|
|
import static eu.siacs.conversations.ui.XmppActivity.REQUEST_ANNOUNCE_PGP;
|
|
|
|
import static eu.siacs.conversations.ui.XmppActivity.REQUEST_CHOOSE_PGP_ID;
|
|
|
|
|
2018-02-20 07:21:07 +00:00
|
|
|
|
2018-02-21 14:46:56 +00:00
|
|
|
public class ConversationFragment extends XmppFragment implements EditMessage.KeyboardListener {
|
2014-02-16 15:32:15 +00:00
|
|
|
|
2018-02-20 13:54:32 +00:00
|
|
|
|
|
|
|
public static final int REQUEST_SEND_MESSAGE = 0x0201;
|
|
|
|
public static final int REQUEST_DECRYPT_PGP = 0x0202;
|
|
|
|
public static final int REQUEST_ENCRYPT_MESSAGE = 0x0207;
|
|
|
|
public static final int REQUEST_TRUST_KEYS_TEXT = 0x0208;
|
|
|
|
public static final int REQUEST_TRUST_KEYS_MENU = 0x0209;
|
|
|
|
public static final int REQUEST_START_DOWNLOAD = 0x0210;
|
|
|
|
public static final int REQUEST_ADD_EDITOR_CONTENT = 0x0211;
|
|
|
|
public static final int ATTACHMENT_CHOICE_CHOOSE_IMAGE = 0x0301;
|
|
|
|
public static final int ATTACHMENT_CHOICE_TAKE_PHOTO = 0x0302;
|
|
|
|
public static final int ATTACHMENT_CHOICE_CHOOSE_FILE = 0x0303;
|
|
|
|
public static final int ATTACHMENT_CHOICE_RECORD_VOICE = 0x0304;
|
|
|
|
public static final int ATTACHMENT_CHOICE_LOCATION = 0x0305;
|
|
|
|
public static final int ATTACHMENT_CHOICE_INVALID = 0x0306;
|
|
|
|
public static final int ATTACHMENT_CHOICE_RECORD_VIDEO = 0x0307;
|
|
|
|
|
|
|
|
public static final String RECENTLY_USED_QUICK_ACTION = "recently_used_quick_action";
|
2018-02-21 22:07:53 +00:00
|
|
|
public static final String STATE_CONVERSATION_UUID = ConversationFragment.class.getName() + ".uuid";
|
|
|
|
public static final String STATE_SCROLL_POSITION = ConversationFragment.class.getName() + ".scroll_position";
|
2018-02-20 13:54:32 +00:00
|
|
|
|
|
|
|
|
2017-11-22 16:57:28 +00:00
|
|
|
final protected List<Message> messageList = new ArrayList<>();
|
2018-02-21 22:07:53 +00:00
|
|
|
private final PendingItem<ActivityResult> postponedActivityResult = new PendingItem<>();
|
|
|
|
private final PendingItem<String> pendingConversationsUuid = new PendingItem<>();
|
|
|
|
public Uri mPendingEditorContent = null;
|
2017-11-22 16:57:28 +00:00
|
|
|
protected MessageAdapter messageListAdapter;
|
2018-02-21 22:07:53 +00:00
|
|
|
private Conversation conversation;
|
|
|
|
private FragmentConversationBinding binding;
|
2017-11-22 16:57:28 +00:00
|
|
|
private Toast messageLoaderToast;
|
2018-02-22 21:23:49 +00:00
|
|
|
private ConversationActivity activity;
|
2018-02-20 13:54:32 +00:00
|
|
|
|
2017-11-22 16:57:28 +00:00
|
|
|
private OnClickListener clickToMuc = new OnClickListener() {
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void onClick(View v) {
|
|
|
|
Intent intent = new Intent(getActivity(), ConferenceDetailsActivity.class);
|
|
|
|
intent.setAction(ConferenceDetailsActivity.ACTION_VIEW_MUC);
|
|
|
|
intent.putExtra("uuid", conversation.getUuid());
|
|
|
|
startActivity(intent);
|
|
|
|
}
|
|
|
|
};
|
2014-07-18 10:44:33 +00:00
|
|
|
private OnClickListener leaveMuc = new OnClickListener() {
|
2014-07-18 17:36:29 +00:00
|
|
|
|
2014-07-18 10:44:33 +00:00
|
|
|
@Override
|
|
|
|
public void onClick(View v) {
|
2018-02-21 14:46:56 +00:00
|
|
|
activity.onConversationArchived(conversation);
|
2014-07-18 10:44:33 +00:00
|
|
|
}
|
|
|
|
};
|
2014-10-06 11:34:19 +00:00
|
|
|
private OnClickListener joinMuc = new OnClickListener() {
|
2014-10-07 13:18:09 +00:00
|
|
|
|
2014-10-06 11:34:19 +00:00
|
|
|
@Override
|
|
|
|
public void onClick(View v) {
|
|
|
|
activity.xmppConnectionService.joinMuc(conversation);
|
|
|
|
}
|
|
|
|
};
|
2014-09-03 17:35:45 +00:00
|
|
|
private OnClickListener enterPassword = new OnClickListener() {
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void onClick(View v) {
|
|
|
|
MucOptions muc = conversation.getMucOptions();
|
|
|
|
String password = muc.getPassword();
|
2014-09-08 18:29:57 +00:00
|
|
|
if (password == null) {
|
2014-09-03 17:35:45 +00:00
|
|
|
password = "";
|
|
|
|
}
|
2018-02-20 13:54:32 +00:00
|
|
|
activity.quickPasswordEdit(password, value -> {
|
|
|
|
activity.xmppConnectionService.providePasswordForMuc(conversation, value);
|
|
|
|
return null;
|
2014-09-03 17:35:45 +00:00
|
|
|
});
|
|
|
|
}
|
|
|
|
};
|
2014-06-14 14:59:07 +00:00
|
|
|
private OnScrollListener mOnScrollListener = new OnScrollListener() {
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void onScrollStateChanged(AbsListView view, int scrollState) {
|
|
|
|
// TODO Auto-generated method stub
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2017-11-10 19:18:47 +00:00
|
|
|
public void onScroll(final AbsListView view, int firstVisibleItem, int visibleItemCount, int totalItemCount) {
|
2014-11-18 13:43:15 +00:00
|
|
|
synchronized (ConversationFragment.this.messageList) {
|
2017-11-22 16:57:28 +00:00
|
|
|
if (firstVisibleItem < 5 && conversation != null && conversation.messagesLoaded.compareAndSet(true, false) && messageList.size() > 0) {
|
2016-02-04 15:29:17 +00:00
|
|
|
long timestamp;
|
|
|
|
if (messageList.get(0).getType() == Message.TYPE_STATUS && messageList.size() >= 2) {
|
|
|
|
timestamp = messageList.get(1).getTimeSent();
|
|
|
|
} else {
|
|
|
|
timestamp = messageList.get(0).getTimeSent();
|
|
|
|
}
|
2014-12-15 22:06:29 +00:00
|
|
|
activity.xmppConnectionService.loadMoreMessages(conversation, timestamp, new XmppConnectionService.OnMoreMessagesLoaded() {
|
|
|
|
@Override
|
2017-02-07 13:03:23 +00:00
|
|
|
public void onMoreMessagesLoaded(final int c, final Conversation conversation) {
|
2014-12-15 22:06:29 +00:00
|
|
|
if (ConversationFragment.this.conversation != conversation) {
|
2017-02-07 13:03:23 +00:00
|
|
|
conversation.messagesLoaded.set(true);
|
2014-12-15 22:06:29 +00:00
|
|
|
return;
|
|
|
|
}
|
2018-02-20 13:54:32 +00:00
|
|
|
getActivity().runOnUiThread(() -> {
|
2018-02-21 10:04:48 +00:00
|
|
|
final int oldPosition = binding.messagesView.getFirstVisiblePosition();
|
2018-02-20 13:54:32 +00:00
|
|
|
Message message = null;
|
|
|
|
int childPos;
|
|
|
|
for (childPos = 0; childPos + oldPosition < messageList.size(); ++childPos) {
|
|
|
|
message = messageList.get(oldPosition + childPos);
|
|
|
|
if (message.getType() != Message.TYPE_STATUS) {
|
|
|
|
break;
|
2016-03-03 10:14:59 +00:00
|
|
|
}
|
2014-12-15 22:06:29 +00:00
|
|
|
}
|
2018-02-20 13:54:32 +00:00
|
|
|
final String uuid = message != null ? message.getUuid() : null;
|
2018-02-21 10:04:48 +00:00
|
|
|
View v = binding.messagesView.getChildAt(childPos);
|
2018-02-20 13:54:32 +00:00
|
|
|
final int pxOffset = (v == null) ? 0 : v.getTop();
|
|
|
|
ConversationFragment.this.conversation.populateWithMessages(ConversationFragment.this.messageList);
|
|
|
|
try {
|
|
|
|
updateStatusMessages();
|
|
|
|
} catch (IllegalStateException e) {
|
|
|
|
Log.d(Config.LOGTAG, "caught illegal state exception while updating status messages");
|
|
|
|
}
|
|
|
|
messageListAdapter.notifyDataSetChanged();
|
|
|
|
int pos = Math.max(getIndexOf(uuid, messageList), 0);
|
2018-02-21 10:04:48 +00:00
|
|
|
binding.messagesView.setSelectionFromTop(pos, pxOffset);
|
2018-02-20 13:54:32 +00:00
|
|
|
if (messageLoaderToast != null) {
|
|
|
|
messageLoaderToast.cancel();
|
|
|
|
}
|
|
|
|
conversation.messagesLoaded.set(true);
|
2014-12-15 22:06:29 +00:00
|
|
|
});
|
|
|
|
}
|
2014-12-17 08:32:51 +00:00
|
|
|
|
|
|
|
@Override
|
2014-12-17 09:50:51 +00:00
|
|
|
public void informUser(final int resId) {
|
|
|
|
|
2018-02-20 13:54:32 +00:00
|
|
|
getActivity().runOnUiThread(() -> {
|
|
|
|
if (messageLoaderToast != null) {
|
|
|
|
messageLoaderToast.cancel();
|
|
|
|
}
|
|
|
|
if (ConversationFragment.this.conversation != conversation) {
|
|
|
|
return;
|
2014-12-17 09:50:51 +00:00
|
|
|
}
|
2018-02-20 13:54:32 +00:00
|
|
|
messageLoaderToast = Toast.makeText(view.getContext(), resId, Toast.LENGTH_LONG);
|
|
|
|
messageLoaderToast.show();
|
2014-12-17 09:50:51 +00:00
|
|
|
});
|
|
|
|
|
2014-12-17 08:32:51 +00:00
|
|
|
}
|
2014-12-15 22:06:29 +00:00
|
|
|
});
|
|
|
|
|
2014-06-14 14:59:07 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
};
|
2016-05-22 15:52:27 +00:00
|
|
|
|
2017-11-22 16:57:28 +00:00
|
|
|
private EditMessage.OnCommitContentListener mEditorContentListener = new EditMessage.OnCommitContentListener() {
|
|
|
|
@Override
|
|
|
|
public boolean onCommitContent(InputContentInfoCompat inputContentInfo, int flags, Bundle opts, String[] contentMimeTypes) {
|
|
|
|
// try to get permission to read the image, if applicable
|
|
|
|
if ((flags & InputConnectionCompat.INPUT_CONTENT_GRANT_READ_URI_PERMISSION) != 0) {
|
|
|
|
try {
|
|
|
|
inputContentInfo.requestPermission();
|
|
|
|
} catch (Exception e) {
|
|
|
|
Log.e(Config.LOGTAG, "InputContentInfoCompat#requestPermission() failed.", e);
|
2018-02-21 22:07:53 +00:00
|
|
|
Toast.makeText(getActivity(), activity.getString(R.string.no_permission_to_access_x, inputContentInfo.getDescription()), Toast.LENGTH_LONG
|
2017-11-22 16:57:28 +00:00
|
|
|
).show();
|
|
|
|
return false;
|
2016-05-22 15:52:27 +00:00
|
|
|
}
|
|
|
|
}
|
2018-02-20 13:54:32 +00:00
|
|
|
if (activity.hasStoragePermission(REQUEST_ADD_EDITOR_CONTENT)) {
|
|
|
|
attachImageToConversation(inputContentInfo.getContentUri());
|
2017-11-22 16:57:28 +00:00
|
|
|
} else {
|
2018-02-20 13:54:32 +00:00
|
|
|
mPendingEditorContent = inputContentInfo.getContentUri();
|
2017-11-22 16:57:28 +00:00
|
|
|
}
|
|
|
|
return true;
|
2016-05-22 15:52:27 +00:00
|
|
|
}
|
2017-11-22 16:57:28 +00:00
|
|
|
};
|
|
|
|
private Message selectedMessage;
|
|
|
|
private OnClickListener mEnableAccountListener = new OnClickListener() {
|
|
|
|
@Override
|
|
|
|
public void onClick(View v) {
|
|
|
|
final Account account = conversation == null ? null : conversation.getAccount();
|
|
|
|
if (account != null) {
|
|
|
|
account.setOption(Account.OPTION_DISABLED, false);
|
|
|
|
activity.xmppConnectionService.updateAccount(account);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
};
|
|
|
|
private OnClickListener mUnblockClickListener = new OnClickListener() {
|
|
|
|
@Override
|
|
|
|
public void onClick(final View v) {
|
2018-02-20 13:54:32 +00:00
|
|
|
v.post(() -> v.setVisibility(View.INVISIBLE));
|
2017-11-22 16:57:28 +00:00
|
|
|
if (conversation.isDomainBlocked()) {
|
|
|
|
BlockContactDialog.show(activity, conversation);
|
2016-09-12 19:18:56 +00:00
|
|
|
} else {
|
2018-02-20 13:54:32 +00:00
|
|
|
unblockConversation(conversation);
|
2016-09-12 19:18:56 +00:00
|
|
|
}
|
|
|
|
}
|
2017-11-22 16:57:28 +00:00
|
|
|
};
|
2018-02-20 13:54:32 +00:00
|
|
|
private OnClickListener mBlockClickListener = this::showBlockSubmenu;
|
2017-11-22 16:57:28 +00:00
|
|
|
private OnClickListener mAddBackClickListener = new OnClickListener() {
|
2016-09-12 19:18:56 +00:00
|
|
|
|
2017-11-22 16:57:28 +00:00
|
|
|
@Override
|
|
|
|
public void onClick(View v) {
|
|
|
|
final Contact contact = conversation == null ? null : conversation.getContact();
|
|
|
|
if (contact != null) {
|
|
|
|
activity.xmppConnectionService.createContact(contact);
|
|
|
|
activity.switchToContactDetails(contact);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
};
|
2018-02-20 13:54:32 +00:00
|
|
|
private View.OnLongClickListener mLongPressBlockListener = this::showBlockSubmenu;
|
2017-11-22 16:57:28 +00:00
|
|
|
private OnClickListener mAllowPresenceSubscription = new OnClickListener() {
|
|
|
|
@Override
|
|
|
|
public void onClick(View v) {
|
|
|
|
final Contact contact = conversation == null ? null : conversation.getContact();
|
|
|
|
if (contact != null) {
|
|
|
|
activity.xmppConnectionService.sendPresencePacket(contact.getAccount(),
|
|
|
|
activity.xmppConnectionService.getPresenceGenerator()
|
|
|
|
.sendPresenceUpdatesTo(contact));
|
|
|
|
hideSnackbar();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
};
|
2018-02-19 12:55:48 +00:00
|
|
|
|
2014-11-07 14:38:20 +00:00
|
|
|
protected OnClickListener clickToDecryptListener = new OnClickListener() {
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void onClick(View v) {
|
2016-06-13 11:32:14 +00:00
|
|
|
PendingIntent pendingIntent = conversation.getAccount().getPgpDecryptionService().getPendingIntent();
|
|
|
|
if (pendingIntent != null) {
|
|
|
|
try {
|
2018-02-20 13:54:32 +00:00
|
|
|
getActivity().startIntentSenderForResult(pendingIntent.getIntentSender(),
|
|
|
|
REQUEST_DECRYPT_PGP,
|
2017-11-22 16:57:28 +00:00
|
|
|
null,
|
|
|
|
0,
|
|
|
|
0,
|
|
|
|
0);
|
2016-06-13 11:32:14 +00:00
|
|
|
} catch (SendIntentException e) {
|
2018-02-20 13:54:32 +00:00
|
|
|
Toast.makeText(getActivity(), R.string.unable_to_connect_to_keychain, Toast.LENGTH_SHORT).show();
|
2016-06-13 11:32:14 +00:00
|
|
|
conversation.getAccount().getPgpDecryptionService().continueDecryption(true);
|
2014-11-07 14:38:20 +00:00
|
|
|
}
|
|
|
|
}
|
2016-06-13 11:32:14 +00:00
|
|
|
updateSnackBar(conversation);
|
2014-11-07 14:38:20 +00:00
|
|
|
}
|
|
|
|
};
|
2017-11-22 16:57:28 +00:00
|
|
|
private AtomicBoolean mSendingPgpMessage = new AtomicBoolean(false);
|
2018-02-20 13:54:32 +00:00
|
|
|
private OnEditorActionListener mEditorActionListener = (v, actionId, event) -> {
|
|
|
|
if (actionId == EditorInfo.IME_ACTION_SEND) {
|
|
|
|
InputMethodManager imm = (InputMethodManager) v.getContext()
|
|
|
|
.getSystemService(Context.INPUT_METHOD_SERVICE);
|
|
|
|
if (imm.isFullscreenMode()) {
|
|
|
|
imm.hideSoftInputFromWindow(v.getWindowToken(), 0);
|
2014-11-07 14:38:20 +00:00
|
|
|
}
|
2018-02-20 13:54:32 +00:00
|
|
|
sendMessage();
|
|
|
|
return true;
|
|
|
|
} else {
|
|
|
|
return false;
|
2014-11-07 14:38:20 +00:00
|
|
|
}
|
|
|
|
};
|
|
|
|
private OnClickListener mSendButtonListener = new OnClickListener() {
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void onClick(View v) {
|
2015-05-02 09:38:56 +00:00
|
|
|
Object tag = v.getTag();
|
|
|
|
if (tag instanceof SendButtonAction) {
|
|
|
|
SendButtonAction action = (SendButtonAction) tag;
|
|
|
|
switch (action) {
|
|
|
|
case TAKE_PHOTO:
|
2017-09-18 09:51:47 +00:00
|
|
|
case RECORD_VIDEO:
|
2015-05-02 09:38:56 +00:00
|
|
|
case SEND_LOCATION:
|
|
|
|
case RECORD_VOICE:
|
2015-05-26 03:34:58 +00:00
|
|
|
case CHOOSE_PICTURE:
|
2018-02-20 13:54:32 +00:00
|
|
|
attachFile(action.toChoice());
|
2015-05-26 03:34:58 +00:00
|
|
|
break;
|
2015-05-03 07:30:30 +00:00
|
|
|
case CANCEL:
|
2016-02-15 22:15:04 +00:00
|
|
|
if (conversation != null) {
|
2017-11-22 16:57:28 +00:00
|
|
|
if (conversation.setCorrectingMessage(null)) {
|
2018-02-21 10:04:48 +00:00
|
|
|
binding.textinput.setText("");
|
|
|
|
binding.textinput.append(conversation.getDraftMessage());
|
2017-03-04 07:04:31 +00:00
|
|
|
conversation.setDraftMessage(null);
|
|
|
|
} else if (conversation.getMode() == Conversation.MODE_MULTI) {
|
2016-02-15 22:15:04 +00:00
|
|
|
conversation.setNextCounterpart(null);
|
|
|
|
}
|
2015-05-03 07:30:30 +00:00
|
|
|
updateChatMsgHint();
|
|
|
|
updateSendButton();
|
2017-07-03 21:58:34 +00:00
|
|
|
updateEditablity();
|
2015-05-03 07:30:30 +00:00
|
|
|
}
|
|
|
|
break;
|
2015-05-02 09:38:56 +00:00
|
|
|
default:
|
|
|
|
sendMessage();
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
sendMessage();
|
|
|
|
}
|
2014-11-07 14:38:20 +00:00
|
|
|
}
|
|
|
|
};
|
2017-11-22 16:57:28 +00:00
|
|
|
private int completionIndex = 0;
|
|
|
|
private int lastCompletionLength = 0;
|
|
|
|
private String incomplete;
|
|
|
|
private int lastCompletionCursor;
|
|
|
|
private boolean firstWord = false;
|
2018-02-20 13:54:32 +00:00
|
|
|
private Message mPendingDownloadableMessage;
|
2014-06-14 14:59:07 +00:00
|
|
|
|
2017-11-22 16:57:28 +00:00
|
|
|
private int getIndexOf(String uuid, List<Message> messages) {
|
|
|
|
if (uuid == null) {
|
|
|
|
return messages.size() - 1;
|
2014-11-07 14:38:20 +00:00
|
|
|
}
|
2017-11-22 16:57:28 +00:00
|
|
|
for (int i = 0; i < messages.size(); ++i) {
|
|
|
|
if (uuid.equals(messages.get(i).getUuid())) {
|
|
|
|
return i;
|
|
|
|
} else {
|
|
|
|
Message next = messages.get(i);
|
|
|
|
while (next != null && next.wasMergedIntoPrevious()) {
|
|
|
|
if (uuid.equals(next.getUuid())) {
|
|
|
|
return i;
|
|
|
|
}
|
|
|
|
next = next.next();
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
public Pair<Integer, Integer> getScrollPosition() {
|
2018-02-21 10:04:48 +00:00
|
|
|
if (this.binding.messagesView.getCount() == 0 ||
|
|
|
|
this.binding.messagesView.getLastVisiblePosition() == this.binding.messagesView.getCount() - 1) {
|
2017-11-22 16:57:28 +00:00
|
|
|
return null;
|
|
|
|
} else {
|
2018-02-21 10:04:48 +00:00
|
|
|
final int pos = this.binding.messagesView.getFirstVisiblePosition();
|
|
|
|
final View view = this.binding.messagesView.getChildAt(0);
|
2017-11-22 16:57:28 +00:00
|
|
|
if (view == null) {
|
|
|
|
return null;
|
|
|
|
} else {
|
|
|
|
return new Pair<>(pos, view.getTop());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
public void setScrollPosition(Pair<Integer, Integer> scrollPosition) {
|
|
|
|
if (scrollPosition != null) {
|
2018-02-21 10:04:48 +00:00
|
|
|
this.binding.messagesView.setSelectionFromTop(scrollPosition.first, scrollPosition.second);
|
2017-11-22 16:57:28 +00:00
|
|
|
}
|
|
|
|
}
|
2014-08-25 13:43:50 +00:00
|
|
|
|
2018-02-20 13:54:32 +00:00
|
|
|
|
|
|
|
private void attachLocationToConversation(Conversation conversation, Uri uri) {
|
|
|
|
if (conversation == null) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
activity.xmppConnectionService.attachLocationToConversation(conversation, uri, new UiCallback<Message>() {
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void success(Message message) {
|
|
|
|
activity.xmppConnectionService.sendMessage(message);
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void error(int errorCode, Message object) {
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void userInputRequried(PendingIntent pi, Message object) {
|
|
|
|
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
private void attachFileToConversation(Conversation conversation, Uri uri) {
|
|
|
|
if (conversation == null) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
final Toast prepareFileToast = Toast.makeText(getActivity(), getText(R.string.preparing_file), Toast.LENGTH_LONG);
|
|
|
|
prepareFileToast.show();
|
|
|
|
activity.delegateUriPermissionsToService(uri);
|
|
|
|
activity.xmppConnectionService.attachFileToConversation(conversation, uri, new UiInformableCallback<Message>() {
|
|
|
|
@Override
|
|
|
|
public void inform(final String text) {
|
|
|
|
hidePrepareFileToast(prepareFileToast);
|
|
|
|
getActivity().runOnUiThread(() -> activity.replaceToast(text));
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void success(Message message) {
|
|
|
|
getActivity().runOnUiThread(() -> activity.hideToast());
|
|
|
|
hidePrepareFileToast(prepareFileToast);
|
|
|
|
activity.xmppConnectionService.sendMessage(message);
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void error(final int errorCode, Message message) {
|
|
|
|
hidePrepareFileToast(prepareFileToast);
|
|
|
|
getActivity().runOnUiThread(() -> activity.replaceToast(getString(errorCode)));
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void userInputRequried(PendingIntent pi, Message message) {
|
|
|
|
hidePrepareFileToast(prepareFileToast);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
public void attachImageToConversation(Uri uri) {
|
|
|
|
this.attachImageToConversation(conversation, uri);
|
|
|
|
}
|
|
|
|
|
|
|
|
private void attachImageToConversation(Conversation conversation, Uri uri) {
|
|
|
|
if (conversation == null) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
final Toast prepareFileToast = Toast.makeText(getActivity(), getText(R.string.preparing_image), Toast.LENGTH_LONG);
|
|
|
|
prepareFileToast.show();
|
|
|
|
activity.delegateUriPermissionsToService(uri);
|
|
|
|
activity.xmppConnectionService.attachImageToConversation(conversation, uri,
|
|
|
|
new UiCallback<Message>() {
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void userInputRequried(PendingIntent pi, Message object) {
|
|
|
|
hidePrepareFileToast(prepareFileToast);
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void success(Message message) {
|
|
|
|
hidePrepareFileToast(prepareFileToast);
|
|
|
|
activity.xmppConnectionService.sendMessage(message);
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void error(final int error, Message message) {
|
|
|
|
hidePrepareFileToast(prepareFileToast);
|
|
|
|
activity.runOnUiThread(() -> activity.replaceToast(getString(error)));
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
private void hidePrepareFileToast(final Toast prepareFileToast) {
|
|
|
|
if (prepareFileToast != null) {
|
|
|
|
activity.runOnUiThread(prepareFileToast::cancel);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-07-31 11:26:05 +00:00
|
|
|
private void sendMessage() {
|
2018-02-21 10:04:48 +00:00
|
|
|
final String body = this.binding.textinput.getText().toString();
|
2017-04-26 10:43:52 +00:00
|
|
|
final Conversation conversation = this.conversation;
|
|
|
|
if (body.length() == 0 || conversation == null) {
|
2014-09-06 22:09:12 +00:00
|
|
|
return;
|
|
|
|
}
|
2016-02-15 22:15:04 +00:00
|
|
|
final Message message;
|
|
|
|
if (conversation.getCorrectingMessage() == null) {
|
|
|
|
message = new Message(conversation, body, conversation.getNextEncryption());
|
|
|
|
if (conversation.getMode() == Conversation.MODE_MULTI) {
|
2018-01-27 19:55:43 +00:00
|
|
|
final Jid nextCounterpart = conversation.getNextCounterpart();
|
|
|
|
if (nextCounterpart != null) {
|
|
|
|
message.setCounterpart(nextCounterpart);
|
|
|
|
message.setTrueCounterpart(conversation.getMucOptions().getTrueCounterpart(nextCounterpart));
|
2016-02-15 22:15:04 +00:00
|
|
|
message.setType(Message.TYPE_PRIVATE);
|
|
|
|
}
|
2014-08-10 13:27:44 +00:00
|
|
|
}
|
2016-02-15 22:15:04 +00:00
|
|
|
} else {
|
|
|
|
message = conversation.getCorrectingMessage();
|
|
|
|
message.setBody(body);
|
|
|
|
message.setEdited(message.getUuid());
|
|
|
|
message.setUuid(UUID.randomUUID().toString());
|
2014-08-10 13:27:44 +00:00
|
|
|
}
|
2017-04-26 10:43:52 +00:00
|
|
|
switch (message.getConversation().getNextEncryption()) {
|
2015-07-30 22:52:46 +00:00
|
|
|
case Message.ENCRYPTION_PGP:
|
|
|
|
sendPgpMessage(message);
|
|
|
|
break;
|
|
|
|
case Message.ENCRYPTION_AXOLOTL:
|
2018-02-20 13:54:32 +00:00
|
|
|
if (!trustKeysIfNeeded(REQUEST_TRUST_KEYS_TEXT)) {
|
2015-07-30 22:52:46 +00:00
|
|
|
sendAxolotlMessage(message);
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
sendPlainTextMessage(message);
|
2014-07-31 11:26:05 +00:00
|
|
|
}
|
|
|
|
}
|
2014-03-13 02:52:41 +00:00
|
|
|
|
2018-02-20 13:54:32 +00:00
|
|
|
protected boolean trustKeysIfNeeded(int requestCode) {
|
|
|
|
return trustKeysIfNeeded(requestCode, ATTACHMENT_CHOICE_INVALID);
|
|
|
|
}
|
|
|
|
|
|
|
|
protected boolean trustKeysIfNeeded(int requestCode, int attachmentChoice) {
|
|
|
|
AxolotlService axolotlService = conversation.getAccount().getAxolotlService();
|
|
|
|
final List<Jid> targets = axolotlService.getCryptoTargets(conversation);
|
|
|
|
boolean hasUnaccepted = !conversation.getAcceptedCryptoTargets().containsAll(targets);
|
|
|
|
boolean hasUndecidedOwn = !axolotlService.getKeysWithTrust(FingerprintStatus.createActiveUndecided()).isEmpty();
|
|
|
|
boolean hasUndecidedContacts = !axolotlService.getKeysWithTrust(FingerprintStatus.createActiveUndecided(), targets).isEmpty();
|
|
|
|
boolean hasPendingKeys = !axolotlService.findDevicesWithoutSession(conversation).isEmpty();
|
|
|
|
boolean hasNoTrustedKeys = axolotlService.anyTargetHasNoTrustedKeys(targets);
|
|
|
|
if (hasUndecidedOwn || hasUndecidedContacts || hasPendingKeys || hasNoTrustedKeys || hasUnaccepted) {
|
|
|
|
axolotlService.createSessionsIfNeeded(conversation);
|
|
|
|
Intent intent = new Intent(getActivity(), TrustKeysActivity.class);
|
|
|
|
String[] contacts = new String[targets.size()];
|
|
|
|
for (int i = 0; i < contacts.length; ++i) {
|
|
|
|
contacts[i] = targets.get(i).toString();
|
|
|
|
}
|
|
|
|
intent.putExtra("contacts", contacts);
|
|
|
|
intent.putExtra(EXTRA_ACCOUNT, conversation.getAccount().getJid().toBareJid().toString());
|
|
|
|
intent.putExtra("choice", attachmentChoice);
|
|
|
|
intent.putExtra("conversation", conversation.getUuid());
|
|
|
|
startActivityForResult(intent, requestCode);
|
|
|
|
return true;
|
|
|
|
} else {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-02-16 15:32:15 +00:00
|
|
|
public void updateChatMsgHint() {
|
2015-09-13 15:13:46 +00:00
|
|
|
final boolean multi = conversation.getMode() == Conversation.MODE_MULTI;
|
2016-02-15 22:15:04 +00:00
|
|
|
if (conversation.getCorrectingMessage() != null) {
|
2018-02-21 10:04:48 +00:00
|
|
|
this.binding.textinput.setHint(R.string.send_corrected_message);
|
2016-02-15 22:15:04 +00:00
|
|
|
} else if (multi && conversation.getNextCounterpart() != null) {
|
2018-02-21 10:04:48 +00:00
|
|
|
this.binding.textinput.setHint(getString(
|
2015-05-02 09:38:56 +00:00
|
|
|
R.string.send_private_message_to,
|
|
|
|
conversation.getNextCounterpart().getResourcepart()));
|
2015-09-13 15:13:46 +00:00
|
|
|
} else if (multi && !conversation.getMucOptions().participating()) {
|
2018-02-21 10:04:48 +00:00
|
|
|
this.binding.textinput.setHint(R.string.you_are_not_participating);
|
2014-08-22 11:22:07 +00:00
|
|
|
} else {
|
2018-02-21 10:04:48 +00:00
|
|
|
this.binding.textinput.setHint(UIHelper.getMessageHint(getActivity(), conversation));
|
2015-01-25 12:07:31 +00:00
|
|
|
getActivity().invalidateOptionsMenu();
|
2014-02-16 15:32:15 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-02-21 10:04:48 +00:00
|
|
|
public void setupIme() {
|
|
|
|
this.binding.textinput.refreshIme();
|
2015-01-14 20:28:27 +00:00
|
|
|
}
|
|
|
|
|
2018-02-20 13:54:32 +00:00
|
|
|
private void handleActivityResult(ActivityResult activityResult) {
|
|
|
|
if (activityResult.resultCode == Activity.RESULT_OK) {
|
|
|
|
handlePositiveActivityResult(activityResult.requestCode, activityResult.data);
|
|
|
|
} else {
|
|
|
|
handleNegativeActivityResult(activityResult.requestCode);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
private void handlePositiveActivityResult(int requestCode, final Intent data) {
|
|
|
|
switch (requestCode) {
|
|
|
|
case REQUEST_DECRYPT_PGP:
|
|
|
|
conversation.getAccount().getPgpDecryptionService().continueDecryption(data);
|
|
|
|
break;
|
|
|
|
case REQUEST_TRUST_KEYS_TEXT:
|
2018-02-21 10:04:48 +00:00
|
|
|
final String body = this.binding.textinput.getText().toString();
|
2018-02-20 13:54:32 +00:00
|
|
|
Message message = new Message(conversation, body, conversation.getNextEncryption());
|
|
|
|
sendAxolotlMessage(message);
|
|
|
|
break;
|
|
|
|
case REQUEST_TRUST_KEYS_MENU:
|
|
|
|
int choice = data.getIntExtra("choice", ATTACHMENT_CHOICE_INVALID);
|
|
|
|
selectPresenceToAttachFile(choice);
|
|
|
|
break;
|
|
|
|
case REQUEST_CHOOSE_PGP_ID:
|
2018-02-21 22:07:53 +00:00
|
|
|
long id = data.getLongExtra(OpenPgpApi.EXTRA_SIGN_KEY_ID, 0);
|
2018-02-20 13:54:32 +00:00
|
|
|
if (id != 0) {
|
|
|
|
conversation.getAccount().setPgpSignId(id);
|
2018-02-21 22:07:53 +00:00
|
|
|
activity.announcePgp(conversation.getAccount(), null, null, activity.onOpenPGPKeyPublished);
|
2018-02-20 13:54:32 +00:00
|
|
|
} else {
|
|
|
|
activity.choosePgpSignId(conversation.getAccount());
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case REQUEST_ANNOUNCE_PGP:
|
|
|
|
activity.announcePgp(conversation.getAccount(), conversation, data, activity.onOpenPGPKeyPublished);
|
|
|
|
break;
|
|
|
|
case ATTACHMENT_CHOICE_CHOOSE_IMAGE:
|
|
|
|
List<Uri> imageUris = AttachmentTool.extractUriFromIntent(data);
|
|
|
|
for (Iterator<Uri> i = imageUris.iterator(); i.hasNext(); i.remove()) {
|
|
|
|
Log.d(Config.LOGTAG, "ConversationsActivity.onActivityResult() - attaching image to conversations. CHOOSE_IMAGE");
|
|
|
|
attachImageToConversation(conversation, i.next());
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case ATTACHMENT_CHOICE_CHOOSE_FILE:
|
|
|
|
case ATTACHMENT_CHOICE_RECORD_VIDEO:
|
|
|
|
case ATTACHMENT_CHOICE_RECORD_VOICE:
|
|
|
|
final List<Uri> fileUris = AttachmentTool.extractUriFromIntent(data);
|
|
|
|
final PresenceSelector.OnPresenceSelected callback = () -> {
|
|
|
|
for (Iterator<Uri> i = fileUris.iterator(); i.hasNext(); i.remove()) {
|
|
|
|
Log.d(Config.LOGTAG, "ConversationsActivity.onActivityResult() - attaching file to conversations. CHOOSE_FILE/RECORD_VOICE/RECORD_VIDEO");
|
|
|
|
attachFileToConversation(conversation, i.next());
|
|
|
|
}
|
|
|
|
};
|
2018-02-21 14:46:56 +00:00
|
|
|
if (conversation == null || conversation.getMode() == Conversation.MODE_MULTI || FileBackend.allFilesUnderSize(getActivity(), fileUris, getMaxHttpUploadSize(conversation))) {
|
2018-02-20 13:54:32 +00:00
|
|
|
callback.onPresenceSelected();
|
|
|
|
} else {
|
|
|
|
activity.selectPresence(conversation, callback);
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case ATTACHMENT_CHOICE_LOCATION:
|
|
|
|
double latitude = data.getDoubleExtra("latitude", 0);
|
|
|
|
double longitude = data.getDoubleExtra("longitude", 0);
|
|
|
|
Uri geo = Uri.parse("geo:" + String.valueOf(latitude) + "," + String.valueOf(longitude));
|
|
|
|
attachLocationToConversation(conversation, geo);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
private void handleNegativeActivityResult(int requestCode) {
|
|
|
|
switch (requestCode) {
|
|
|
|
case REQUEST_DECRYPT_PGP:
|
|
|
|
// discard the message to prevent decryption being blocked
|
|
|
|
conversation.getAccount().getPgpDecryptionService().giveUpCurrentDecryption();
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void onActivityResult(int requestCode, int resultCode, final Intent data) {
|
|
|
|
super.onActivityResult(requestCode, resultCode, data);
|
2018-02-21 22:07:53 +00:00
|
|
|
ActivityResult activityResult = ActivityResult.of(requestCode, resultCode, data);
|
2018-02-20 13:54:32 +00:00
|
|
|
if (activity != null && activity.xmppConnectionService != null) {
|
|
|
|
handleActivityResult(activityResult);
|
|
|
|
} else {
|
2018-02-21 22:07:53 +00:00
|
|
|
this.postponedActivityResult.push(activityResult);
|
2018-02-20 13:54:32 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
public void unblockConversation(final Blockable conversation) {
|
|
|
|
activity.xmppConnectionService.sendUnblockRequest(conversation);
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2018-02-21 22:07:53 +00:00
|
|
|
public void onAttach(Activity activity) {
|
|
|
|
super.onAttach(activity);
|
2018-02-22 21:23:49 +00:00
|
|
|
Log.d(Config.LOGTAG, "ConversationFragment.onAttach()");
|
|
|
|
if (activity instanceof ConversationActivity) {
|
|
|
|
this.activity = (ConversationActivity) activity;
|
2018-02-20 13:54:32 +00:00
|
|
|
} else {
|
|
|
|
throw new IllegalStateException("Trying to attach fragment to activity that is not the ConversationActivity");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-02-23 11:53:47 +00:00
|
|
|
@Override
|
|
|
|
public void onDetach() {
|
|
|
|
super.onDetach();
|
|
|
|
this.activity = null;
|
|
|
|
}
|
|
|
|
|
2018-02-20 13:54:32 +00:00
|
|
|
@Override
|
|
|
|
public void onCreate(Bundle savedInstanceState) {
|
|
|
|
super.onCreate(savedInstanceState);
|
|
|
|
setHasOptionsMenu(true);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void onCreateOptionsMenu(Menu menu, MenuInflater menuInflater) {
|
|
|
|
menuInflater.inflate(R.menu.fragment_conversation, menu);
|
|
|
|
final MenuItem menuMucDetails = menu.findItem(R.id.action_muc_details);
|
|
|
|
final MenuItem menuContactDetails = menu.findItem(R.id.action_contact_details);
|
|
|
|
final MenuItem menuInviteContact = menu.findItem(R.id.action_invite);
|
|
|
|
final MenuItem menuMute = menu.findItem(R.id.action_mute);
|
|
|
|
final MenuItem menuUnmute = menu.findItem(R.id.action_unmute);
|
|
|
|
|
|
|
|
|
|
|
|
if (conversation != null) {
|
|
|
|
if (conversation.getMode() == Conversation.MODE_MULTI) {
|
|
|
|
menuContactDetails.setVisible(false);
|
|
|
|
menuInviteContact.setVisible(conversation.getMucOptions().canInvite());
|
|
|
|
} else {
|
|
|
|
menuContactDetails.setVisible(!this.conversation.withSelf());
|
|
|
|
menuMucDetails.setVisible(false);
|
|
|
|
final XmppConnectionService service = activity.xmppConnectionService;
|
|
|
|
menuInviteContact.setVisible(service != null && service.findConferenceServer(conversation.getAccount()) != null);
|
|
|
|
}
|
|
|
|
if (conversation.isMuted()) {
|
|
|
|
menuMute.setVisible(false);
|
|
|
|
} else {
|
|
|
|
menuUnmute.setVisible(false);
|
|
|
|
}
|
|
|
|
ConversationMenuConfigurator.configureAttachmentMenu(conversation, menu);
|
|
|
|
ConversationMenuConfigurator.configureEncryptionMenu(conversation, menu);
|
|
|
|
}
|
|
|
|
super.onCreateOptionsMenu(menu, menuInflater);
|
|
|
|
}
|
|
|
|
|
2014-01-27 19:40:42 +00:00
|
|
|
@Override
|
2015-09-04 12:48:00 +00:00
|
|
|
public View onCreateView(final LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
|
2018-02-21 22:07:53 +00:00
|
|
|
this.binding = DataBindingUtil.inflate(inflater, R.layout.fragment_conversation, container, false);
|
2018-02-21 10:04:48 +00:00
|
|
|
binding.getRoot().setOnClickListener(null); //TODO why the fuck did we do this?
|
2017-08-22 14:51:42 +00:00
|
|
|
|
2018-02-21 10:04:48 +00:00
|
|
|
binding.textinput.addTextChangedListener(new StylingHelper.MessageEditorStyler(binding.textinput));
|
2017-11-05 20:34:40 +00:00
|
|
|
|
2018-02-21 10:04:48 +00:00
|
|
|
binding.textinput.setOnEditorActionListener(mEditorActionListener);
|
|
|
|
binding.textinput.setRichContentListener(new String[]{"image/*"}, mEditorContentListener);
|
2014-08-25 13:43:50 +00:00
|
|
|
|
2018-02-21 10:04:48 +00:00
|
|
|
binding.textSendButton.setOnClickListener(this.mSendButtonListener);
|
2014-03-13 02:52:41 +00:00
|
|
|
|
2018-02-21 10:04:48 +00:00
|
|
|
binding.messagesView.setOnScrollListener(mOnScrollListener);
|
|
|
|
binding.messagesView.setTranscriptMode(ListView.TRANSCRIPT_MODE_NORMAL);
|
2018-02-21 14:46:56 +00:00
|
|
|
messageListAdapter = new MessageAdapter((XmppActivity) getActivity(), this.messageList);
|
2018-01-27 20:34:32 +00:00
|
|
|
messageListAdapter.setOnContactPictureClicked(message -> {
|
|
|
|
final boolean received = message.getStatus() <= Message.STATUS_RECEIVED;
|
|
|
|
if (received) {
|
|
|
|
if (message.getConversation().getMode() == Conversation.MODE_MULTI) {
|
|
|
|
Jid user = message.getCounterpart();
|
|
|
|
if (user != null && !user.isBareJid()) {
|
|
|
|
if (!message.getConversation().getMucOptions().isUserInRoom(user)) {
|
2018-02-20 13:54:32 +00:00
|
|
|
Toast.makeText(getActivity(), activity.getString(R.string.user_has_left_conference, user.getResourcepart()), Toast.LENGTH_SHORT).show();
|
2016-04-09 08:59:54 +00:00
|
|
|
}
|
2018-01-27 20:34:32 +00:00
|
|
|
highlightInConference(user.getResourcepart());
|
2014-08-10 13:27:44 +00:00
|
|
|
}
|
2018-01-27 20:34:32 +00:00
|
|
|
return;
|
2014-12-21 20:43:58 +00:00
|
|
|
} else {
|
2018-01-27 20:34:32 +00:00
|
|
|
if (!message.getContact().isSelf()) {
|
2016-06-16 10:12:24 +00:00
|
|
|
String fingerprint;
|
|
|
|
if (message.getEncryption() == Message.ENCRYPTION_PGP
|
|
|
|
|| message.getEncryption() == Message.ENCRYPTION_DECRYPTED) {
|
|
|
|
fingerprint = "pgp";
|
|
|
|
} else {
|
|
|
|
fingerprint = message.getFingerprint();
|
|
|
|
}
|
2018-01-27 20:34:32 +00:00
|
|
|
activity.switchToContactDetails(message.getContact(), fingerprint);
|
|
|
|
return;
|
2016-04-22 19:25:06 +00:00
|
|
|
}
|
2014-12-21 20:43:58 +00:00
|
|
|
}
|
|
|
|
}
|
2018-01-27 20:34:32 +00:00
|
|
|
Account account = message.getConversation().getAccount();
|
|
|
|
Intent intent;
|
|
|
|
if (activity.manuallyChangePresence() && !received) {
|
|
|
|
intent = new Intent(activity, SetPresenceActivity.class);
|
2018-02-20 13:54:32 +00:00
|
|
|
intent.putExtra(EXTRA_ACCOUNT, account.getJid().toBareJid().toString());
|
2018-01-27 20:34:32 +00:00
|
|
|
} else {
|
|
|
|
intent = new Intent(activity, EditAccountActivity.class);
|
|
|
|
intent.putExtra("jid", account.getJid().toBareJid().toString());
|
|
|
|
String fingerprint;
|
|
|
|
if (message.getEncryption() == Message.ENCRYPTION_PGP
|
|
|
|
|| message.getEncryption() == Message.ENCRYPTION_DECRYPTED) {
|
|
|
|
fingerprint = "pgp";
|
|
|
|
} else {
|
|
|
|
fingerprint = message.getFingerprint();
|
|
|
|
}
|
|
|
|
intent.putExtra("fingerprint", fingerprint);
|
|
|
|
}
|
|
|
|
startActivity(intent);
|
2014-12-21 20:43:58 +00:00
|
|
|
});
|
2018-01-18 16:35:42 +00:00
|
|
|
messageListAdapter.setOnContactPictureLongClicked(message -> {
|
|
|
|
if (message.getStatus() <= Message.STATUS_RECEIVED) {
|
|
|
|
if (message.getConversation().getMode() == Conversation.MODE_MULTI) {
|
|
|
|
final MucOptions mucOptions = conversation.getMucOptions();
|
|
|
|
if (!mucOptions.allowPm()) {
|
2018-02-20 13:54:32 +00:00
|
|
|
Toast.makeText(getActivity(), R.string.private_messages_are_disabled, Toast.LENGTH_SHORT).show();
|
2018-01-18 16:35:42 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
Jid user = message.getCounterpart();
|
|
|
|
if (user != null && !user.isBareJid()) {
|
|
|
|
if (mucOptions.isUserInRoom(user)) {
|
|
|
|
privateMessageWith(user);
|
2015-05-02 09:38:56 +00:00
|
|
|
} else {
|
2018-02-20 13:54:32 +00:00
|
|
|
Toast.makeText(getActivity(), activity.getString(R.string.user_has_left_conference, user.getResourcepart()), Toast.LENGTH_SHORT).show();
|
2014-08-25 13:43:50 +00:00
|
|
|
}
|
2014-08-10 13:27:44 +00:00
|
|
|
}
|
2018-01-18 16:35:42 +00:00
|
|
|
}
|
|
|
|
} else {
|
|
|
|
activity.showQrCode();
|
2016-11-25 14:06:43 +00:00
|
|
|
}
|
|
|
|
});
|
2018-01-27 20:34:32 +00:00
|
|
|
messageListAdapter.setOnQuoteListener(this::quoteText);
|
2018-02-21 10:04:48 +00:00
|
|
|
binding.messagesView.setAdapter(messageListAdapter);
|
2014-01-26 02:27:55 +00:00
|
|
|
|
2018-02-21 10:04:48 +00:00
|
|
|
registerForContextMenu(binding.messagesView);
|
2014-10-23 19:27:41 +00:00
|
|
|
|
2018-02-21 10:04:48 +00:00
|
|
|
return binding.getRoot();
|
2014-01-26 02:27:55 +00:00
|
|
|
}
|
2014-08-25 13:43:50 +00:00
|
|
|
|
2017-11-07 14:58:27 +00:00
|
|
|
private void quoteText(String text) {
|
2018-02-21 10:04:48 +00:00
|
|
|
if (binding.textinput.isEnabled()) {
|
2017-11-07 14:58:27 +00:00
|
|
|
text = text.replaceAll("(\n *){2,}", "\n").replaceAll("(^|\n)", "$1> ").replaceAll("\n$", "");
|
2018-02-21 10:04:48 +00:00
|
|
|
Editable editable = binding.textinput.getEditableText();
|
|
|
|
int position = binding.textinput.getSelectionEnd();
|
2017-11-07 14:58:27 +00:00
|
|
|
if (position == -1) position = editable.length();
|
|
|
|
if (position > 0 && editable.charAt(position - 1) != '\n') {
|
|
|
|
editable.insert(position++, "\n");
|
|
|
|
}
|
|
|
|
editable.insert(position, text);
|
|
|
|
position += text.length();
|
|
|
|
editable.insert(position++, "\n");
|
|
|
|
if (position < editable.length() && editable.charAt(position) != '\n') {
|
|
|
|
editable.insert(position, "\n");
|
|
|
|
}
|
2018-02-21 10:04:48 +00:00
|
|
|
binding.textinput.setSelection(position);
|
|
|
|
binding.textinput.requestFocus();
|
|
|
|
InputMethodManager inputMethodManager = (InputMethodManager) getActivity().getSystemService(Context.INPUT_METHOD_SERVICE);
|
2017-11-07 14:58:27 +00:00
|
|
|
if (inputMethodManager != null) {
|
2018-02-21 10:04:48 +00:00
|
|
|
inputMethodManager.showSoftInput(binding.textinput, InputMethodManager.SHOW_IMPLICIT);
|
2017-11-07 14:58:27 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
private void quoteMessage(Message message) {
|
2017-11-07 21:22:28 +00:00
|
|
|
quoteText(MessageUtils.prepareQuote(message));
|
2017-11-07 14:58:27 +00:00
|
|
|
}
|
|
|
|
|
2014-10-23 19:27:41 +00:00
|
|
|
@Override
|
2016-02-15 22:15:04 +00:00
|
|
|
public void onCreateContextMenu(ContextMenu menu, View v, ContextMenuInfo menuInfo) {
|
2014-11-18 13:43:15 +00:00
|
|
|
synchronized (this.messageList) {
|
|
|
|
super.onCreateContextMenu(menu, v, menuInfo);
|
|
|
|
AdapterView.AdapterContextMenuInfo acmi = (AdapterContextMenuInfo) menuInfo;
|
|
|
|
this.selectedMessage = this.messageList.get(acmi.position);
|
|
|
|
populateContextMenu(menu);
|
|
|
|
}
|
2014-10-23 19:27:41 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
private void populateContextMenu(ContextMenu menu) {
|
2015-01-02 13:27:49 +00:00
|
|
|
final Message m = this.selectedMessage;
|
2016-03-04 10:24:40 +00:00
|
|
|
final Transferable t = m.getTransferable();
|
2016-02-17 15:51:36 +00:00
|
|
|
Message relevantForCorrection = m;
|
2017-11-22 16:57:28 +00:00
|
|
|
while (relevantForCorrection.mergeable(relevantForCorrection.next())) {
|
2016-02-17 15:51:36 +00:00
|
|
|
relevantForCorrection = relevantForCorrection.next();
|
|
|
|
}
|
2015-01-02 13:27:49 +00:00
|
|
|
if (m.getType() != Message.TYPE_STATUS) {
|
2016-03-23 18:23:22 +00:00
|
|
|
final boolean treatAsFile = m.getType() != Message.TYPE_TEXT
|
|
|
|
&& m.getType() != Message.TYPE_PRIVATE
|
|
|
|
&& t == null;
|
2017-11-07 14:58:27 +00:00
|
|
|
final boolean encrypted = m.getEncryption() == Message.ENCRYPTION_DECRYPTION_FAILED
|
|
|
|
|| m.getEncryption() == Message.ENCRYPTION_PGP;
|
2014-10-23 19:27:41 +00:00
|
|
|
activity.getMenuInflater().inflate(R.menu.message_context, menu);
|
|
|
|
menu.setHeaderTitle(R.string.message_options);
|
2017-11-07 14:58:27 +00:00
|
|
|
MenuItem copyMessage = menu.findItem(R.id.copy_message);
|
|
|
|
MenuItem quoteMessage = menu.findItem(R.id.quote_message);
|
2016-02-23 14:30:41 +00:00
|
|
|
MenuItem retryDecryption = menu.findItem(R.id.retry_decryption);
|
2016-02-15 22:15:04 +00:00
|
|
|
MenuItem correctMessage = menu.findItem(R.id.correct_message);
|
2015-01-12 15:42:20 +00:00
|
|
|
MenuItem shareWith = menu.findItem(R.id.share_with);
|
2014-10-23 19:27:41 +00:00
|
|
|
MenuItem sendAgain = menu.findItem(R.id.send_again);
|
|
|
|
MenuItem copyUrl = menu.findItem(R.id.copy_url);
|
2017-04-20 09:52:54 +00:00
|
|
|
MenuItem downloadFile = menu.findItem(R.id.download_file);
|
2014-11-15 11:37:09 +00:00
|
|
|
MenuItem cancelTransmission = menu.findItem(R.id.cancel_transmission);
|
2016-03-23 18:23:22 +00:00
|
|
|
MenuItem deleteFile = menu.findItem(R.id.delete_file);
|
2016-10-26 10:26:04 +00:00
|
|
|
MenuItem showErrorMessage = menu.findItem(R.id.show_error_message);
|
2017-11-07 14:58:27 +00:00
|
|
|
if (!treatAsFile && !encrypted && !m.isGeoUri() && !m.treatAsDownloadable()) {
|
|
|
|
copyMessage.setVisible(true);
|
2017-11-07 21:22:28 +00:00
|
|
|
quoteMessage.setVisible(MessageUtils.prepareQuote(m).length() > 0);
|
2017-05-02 08:42:50 +00:00
|
|
|
}
|
2016-02-23 14:30:41 +00:00
|
|
|
if (m.getEncryption() == Message.ENCRYPTION_DECRYPTION_FAILED) {
|
|
|
|
retryDecryption.setVisible(true);
|
|
|
|
}
|
2016-02-17 15:51:36 +00:00
|
|
|
if (relevantForCorrection.getType() == Message.TYPE_TEXT
|
2016-11-11 14:01:15 +00:00
|
|
|
&& relevantForCorrection.isLastCorrectableMessage()
|
2016-11-12 19:25:02 +00:00
|
|
|
&& (m.getConversation().getMucOptions().nonanonymous() || m.getConversation().getMode() == Conversation.MODE_SINGLE)) {
|
2016-02-15 22:15:04 +00:00
|
|
|
correctMessage.setVisible(true);
|
|
|
|
}
|
2017-04-30 19:03:44 +00:00
|
|
|
if (treatAsFile || (m.getType() == Message.TYPE_TEXT && !m.treatAsDownloadable())) {
|
2015-07-02 21:13:00 +00:00
|
|
|
shareWith.setVisible(true);
|
2015-03-11 14:48:43 +00:00
|
|
|
}
|
2015-07-02 21:13:00 +00:00
|
|
|
if (m.getStatus() == Message.STATUS_SEND_FAILED) {
|
|
|
|
sendAgain.setVisible(true);
|
2014-10-23 19:27:41 +00:00
|
|
|
}
|
2015-07-02 21:13:00 +00:00
|
|
|
if (m.hasFileOnRemoteHost()
|
2017-08-03 11:24:41 +00:00
|
|
|
|| m.isGeoUri()
|
2017-04-05 20:32:02 +00:00
|
|
|
|| m.treatAsDownloadable()
|
2016-03-04 10:24:40 +00:00
|
|
|
|| (t != null && t instanceof HttpDownloadConnection)) {
|
2015-07-02 21:13:00 +00:00
|
|
|
copyUrl.setVisible(true);
|
2015-05-02 09:38:56 +00:00
|
|
|
}
|
2017-04-20 09:52:54 +00:00
|
|
|
if ((m.isFileOrImage() && t instanceof TransferablePlaceholder && m.hasFileOnRemoteHost())) {
|
|
|
|
downloadFile.setVisible(true);
|
2017-11-22 16:57:28 +00:00
|
|
|
downloadFile.setTitle(activity.getString(R.string.download_x_file, UIHelper.getFileDescriptionString(activity, m)));
|
2017-04-20 09:52:54 +00:00
|
|
|
}
|
2016-09-20 18:02:25 +00:00
|
|
|
boolean waitingOfferedSending = m.getStatus() == Message.STATUS_WAITING
|
|
|
|
|| m.getStatus() == Message.STATUS_UNSEND
|
|
|
|
|| m.getStatus() == Message.STATUS_OFFERED;
|
|
|
|
if ((t != null && !(t instanceof TransferablePlaceholder)) || waitingOfferedSending && m.needsUploading()) {
|
2015-07-02 21:13:00 +00:00
|
|
|
cancelTransmission.setVisible(true);
|
2015-05-02 09:38:56 +00:00
|
|
|
}
|
2016-03-23 18:23:22 +00:00
|
|
|
if (treatAsFile) {
|
2016-09-16 10:29:12 +00:00
|
|
|
String path = m.getRelativeFilePath();
|
|
|
|
if (path == null || !path.startsWith("/")) {
|
|
|
|
deleteFile.setVisible(true);
|
|
|
|
deleteFile.setTitle(activity.getString(R.string.delete_x_file, UIHelper.getFileDescriptionString(activity, m)));
|
|
|
|
}
|
2016-03-23 18:23:22 +00:00
|
|
|
}
|
2016-10-26 10:26:04 +00:00
|
|
|
if (m.getStatus() == Message.STATUS_SEND_FAILED && m.getErrorMessage() != null) {
|
|
|
|
showErrorMessage.setVisible(true);
|
|
|
|
}
|
2014-10-23 19:27:41 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public boolean onContextItemSelected(MenuItem item) {
|
|
|
|
switch (item.getItemId()) {
|
2015-01-12 15:42:20 +00:00
|
|
|
case R.id.share_with:
|
|
|
|
shareWith(selectedMessage);
|
2014-11-04 17:52:29 +00:00
|
|
|
return true;
|
2016-02-15 22:15:04 +00:00
|
|
|
case R.id.correct_message:
|
|
|
|
correctMessage(selectedMessage);
|
|
|
|
return true;
|
2017-11-07 14:58:27 +00:00
|
|
|
case R.id.copy_message:
|
|
|
|
copyMessage(selectedMessage);
|
|
|
|
return true;
|
|
|
|
case R.id.quote_message:
|
|
|
|
quoteMessage(selectedMessage);
|
|
|
|
return true;
|
2014-11-04 17:52:29 +00:00
|
|
|
case R.id.send_again:
|
|
|
|
resendMessage(selectedMessage);
|
|
|
|
return true;
|
|
|
|
case R.id.copy_url:
|
|
|
|
copyUrl(selectedMessage);
|
|
|
|
return true;
|
2017-04-20 09:52:54 +00:00
|
|
|
case R.id.download_file:
|
|
|
|
downloadFile(selectedMessage);
|
|
|
|
return true;
|
2014-11-15 11:37:09 +00:00
|
|
|
case R.id.cancel_transmission:
|
|
|
|
cancelTransmission(selectedMessage);
|
|
|
|
return true;
|
2016-02-23 14:30:41 +00:00
|
|
|
case R.id.retry_decryption:
|
|
|
|
retryDecryption(selectedMessage);
|
|
|
|
return true;
|
2016-03-23 18:23:22 +00:00
|
|
|
case R.id.delete_file:
|
|
|
|
deleteFile(selectedMessage);
|
|
|
|
return true;
|
2016-10-26 10:26:04 +00:00
|
|
|
case R.id.show_error_message:
|
|
|
|
showErrorMessage(selectedMessage);
|
|
|
|
return true;
|
2014-11-04 17:52:29 +00:00
|
|
|
default:
|
|
|
|
return super.onContextItemSelected(item);
|
2014-10-23 19:27:41 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-02-20 13:54:32 +00:00
|
|
|
@Override
|
|
|
|
public boolean onOptionsItemSelected(final MenuItem item) {
|
|
|
|
if (conversation == null) {
|
|
|
|
return super.onOptionsItemSelected(item);
|
|
|
|
}
|
|
|
|
switch (item.getItemId()) {
|
|
|
|
case R.id.encryption_choice_axolotl:
|
|
|
|
case R.id.encryption_choice_pgp:
|
|
|
|
case R.id.encryption_choice_none:
|
|
|
|
handleEncryptionSelection(item);
|
|
|
|
break;
|
|
|
|
case R.id.attach_choose_picture:
|
|
|
|
case R.id.attach_take_picture:
|
|
|
|
case R.id.attach_record_video:
|
|
|
|
case R.id.attach_choose_file:
|
|
|
|
case R.id.attach_record_voice:
|
|
|
|
case R.id.attach_location:
|
|
|
|
handleAttachmentSelection(item);
|
|
|
|
break;
|
|
|
|
case R.id.action_archive:
|
2018-02-21 14:46:56 +00:00
|
|
|
activity.onConversationArchived(conversation);
|
2018-02-20 13:54:32 +00:00
|
|
|
break;
|
|
|
|
case R.id.action_contact_details:
|
|
|
|
activity.switchToContactDetails(conversation.getContact());
|
|
|
|
break;
|
|
|
|
case R.id.action_muc_details:
|
|
|
|
Intent intent = new Intent(getActivity(), ConferenceDetailsActivity.class);
|
|
|
|
intent.setAction(ConferenceDetailsActivity.ACTION_VIEW_MUC);
|
|
|
|
intent.putExtra("uuid", conversation.getUuid());
|
|
|
|
startActivity(intent);
|
|
|
|
break;
|
|
|
|
case R.id.action_invite:
|
|
|
|
activity.inviteToConversation(conversation);
|
|
|
|
break;
|
|
|
|
case R.id.action_clear_history:
|
|
|
|
clearHistoryDialog(conversation);
|
|
|
|
break;
|
|
|
|
case R.id.action_mute:
|
|
|
|
muteConversationDialog(conversation);
|
|
|
|
break;
|
|
|
|
case R.id.action_unmute:
|
|
|
|
unmuteConversation(conversation);
|
|
|
|
break;
|
|
|
|
case R.id.action_block:
|
|
|
|
case R.id.action_unblock:
|
|
|
|
final Activity activity = getActivity();
|
|
|
|
if (activity instanceof XmppActivity) {
|
|
|
|
BlockContactDialog.show((XmppActivity) activity, conversation);
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
return super.onOptionsItemSelected(item);
|
|
|
|
}
|
|
|
|
|
|
|
|
private void handleAttachmentSelection(MenuItem item) {
|
|
|
|
switch (item.getItemId()) {
|
|
|
|
case R.id.attach_choose_picture:
|
|
|
|
attachFile(ATTACHMENT_CHOICE_CHOOSE_IMAGE);
|
|
|
|
break;
|
|
|
|
case R.id.attach_take_picture:
|
|
|
|
attachFile(ATTACHMENT_CHOICE_TAKE_PHOTO);
|
|
|
|
break;
|
|
|
|
case R.id.attach_record_video:
|
|
|
|
attachFile(ATTACHMENT_CHOICE_RECORD_VIDEO);
|
|
|
|
break;
|
|
|
|
case R.id.attach_choose_file:
|
|
|
|
attachFile(ATTACHMENT_CHOICE_CHOOSE_FILE);
|
|
|
|
break;
|
|
|
|
case R.id.attach_record_voice:
|
|
|
|
attachFile(ATTACHMENT_CHOICE_RECORD_VOICE);
|
|
|
|
break;
|
|
|
|
case R.id.attach_location:
|
|
|
|
attachFile(ATTACHMENT_CHOICE_LOCATION);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
private void handleEncryptionSelection(MenuItem item) {
|
|
|
|
if (conversation == null) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
switch (item.getItemId()) {
|
|
|
|
case R.id.encryption_choice_none:
|
|
|
|
conversation.setNextEncryption(Message.ENCRYPTION_NONE);
|
|
|
|
item.setChecked(true);
|
|
|
|
break;
|
|
|
|
case R.id.encryption_choice_pgp:
|
|
|
|
if (activity.hasPgp()) {
|
|
|
|
if (conversation.getAccount().getPgpSignature() != null) {
|
|
|
|
conversation.setNextEncryption(Message.ENCRYPTION_PGP);
|
|
|
|
item.setChecked(true);
|
|
|
|
} else {
|
|
|
|
activity.announcePgp(conversation.getAccount(), conversation, null, activity.onOpenPGPKeyPublished);
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
activity.showInstallPgpDialog();
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case R.id.encryption_choice_axolotl:
|
|
|
|
Log.d(Config.LOGTAG, AxolotlService.getLogprefix(conversation.getAccount())
|
|
|
|
+ "Enabled axolotl for Contact " + conversation.getContact().getJid());
|
|
|
|
conversation.setNextEncryption(Message.ENCRYPTION_AXOLOTL);
|
|
|
|
item.setChecked(true);
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
conversation.setNextEncryption(Message.ENCRYPTION_NONE);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
activity.xmppConnectionService.updateConversation(conversation);
|
2018-02-21 14:46:56 +00:00
|
|
|
updateChatMsgHint();
|
2018-02-20 13:54:32 +00:00
|
|
|
getActivity().invalidateOptionsMenu();
|
|
|
|
activity.refreshUi();
|
|
|
|
}
|
|
|
|
|
|
|
|
public void attachFile(final int attachmentChoice) {
|
|
|
|
if (attachmentChoice != ATTACHMENT_CHOICE_LOCATION) {
|
|
|
|
if (!Config.ONLY_INTERNAL_STORAGE && !activity.hasStoragePermission(attachmentChoice)) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
try {
|
|
|
|
activity.getPreferences().edit()
|
|
|
|
.putString(RECENTLY_USED_QUICK_ACTION, SendButtonAction.of(attachmentChoice).toString())
|
|
|
|
.apply();
|
|
|
|
} catch (IllegalArgumentException e) {
|
|
|
|
//just do not save
|
|
|
|
}
|
|
|
|
final int encryption = conversation.getNextEncryption();
|
|
|
|
final int mode = conversation.getMode();
|
|
|
|
if (encryption == Message.ENCRYPTION_PGP) {
|
|
|
|
if (activity.hasPgp()) {
|
|
|
|
if (mode == Conversation.MODE_SINGLE && conversation.getContact().getPgpKeyId() != 0) {
|
|
|
|
activity.xmppConnectionService.getPgpEngine().hasKey(
|
|
|
|
conversation.getContact(),
|
|
|
|
new UiCallback<Contact>() {
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void userInputRequried(PendingIntent pi, Contact contact) {
|
2018-02-21 14:46:56 +00:00
|
|
|
startPendingIntent(pi, attachmentChoice);
|
2018-02-20 13:54:32 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void success(Contact contact) {
|
|
|
|
selectPresenceToAttachFile(attachmentChoice);
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void error(int error, Contact contact) {
|
|
|
|
activity.replaceToast(getString(error));
|
|
|
|
}
|
|
|
|
});
|
|
|
|
} else if (mode == Conversation.MODE_MULTI && conversation.getMucOptions().pgpKeysInUse()) {
|
|
|
|
if (!conversation.getMucOptions().everybodyHasKeys()) {
|
|
|
|
Toast warning = Toast.makeText(getActivity(), R.string.missing_public_keys, Toast.LENGTH_LONG);
|
|
|
|
warning.setGravity(Gravity.CENTER_VERTICAL, 0, 0);
|
|
|
|
warning.show();
|
|
|
|
}
|
|
|
|
selectPresenceToAttachFile(attachmentChoice);
|
|
|
|
} else {
|
|
|
|
final ConversationFragment fragment = (ConversationFragment) getFragmentManager()
|
|
|
|
.findFragmentByTag("conversation");
|
|
|
|
if (fragment != null) {
|
|
|
|
fragment.showNoPGPKeyDialog(false, (dialog, which) -> {
|
2018-02-21 22:07:53 +00:00
|
|
|
conversation.setNextEncryption(Message.ENCRYPTION_NONE);
|
|
|
|
activity.xmppConnectionService.updateConversation(conversation);
|
|
|
|
selectPresenceToAttachFile(attachmentChoice);
|
|
|
|
});
|
2018-02-20 13:54:32 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
activity.showInstallPgpDialog();
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
if (encryption != Message.ENCRYPTION_AXOLOTL || !trustKeysIfNeeded(REQUEST_TRUST_KEYS_MENU, attachmentChoice)) {
|
|
|
|
selectPresenceToAttachFile(attachmentChoice);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void onRequestPermissionsResult(int requestCode, String permissions[], int[] grantResults) {
|
|
|
|
if (grantResults.length > 0)
|
|
|
|
if (grantResults[0] == PackageManager.PERMISSION_GRANTED) {
|
|
|
|
if (requestCode == REQUEST_START_DOWNLOAD) {
|
|
|
|
if (this.mPendingDownloadableMessage != null) {
|
|
|
|
startDownloadable(this.mPendingDownloadableMessage);
|
|
|
|
}
|
|
|
|
} else if (requestCode == REQUEST_ADD_EDITOR_CONTENT) {
|
|
|
|
if (this.mPendingEditorContent != null) {
|
|
|
|
attachImageToConversation(this.mPendingEditorContent);
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
attachFile(requestCode);
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
Toast.makeText(getActivity(), R.string.no_storage_permission, Toast.LENGTH_SHORT).show();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
public void startDownloadable(Message message) {
|
|
|
|
if (!Config.ONLY_INTERNAL_STORAGE && !activity.hasStoragePermission(REQUEST_START_DOWNLOAD)) {
|
|
|
|
this.mPendingDownloadableMessage = message;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
Transferable transferable = message.getTransferable();
|
|
|
|
if (transferable != null) {
|
|
|
|
if (!transferable.start()) {
|
|
|
|
Toast.makeText(getActivity(), R.string.not_connected_try_again, Toast.LENGTH_SHORT).show();
|
|
|
|
}
|
|
|
|
} else if (message.treatAsDownloadable()) {
|
|
|
|
activity.xmppConnectionService.getHttpConnectionManager().createNewDownloadConnection(message, true);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
@SuppressLint("InflateParams")
|
|
|
|
protected void clearHistoryDialog(final Conversation conversation) {
|
|
|
|
AlertDialog.Builder builder = new AlertDialog.Builder(getActivity());
|
|
|
|
builder.setTitle(getString(R.string.clear_conversation_history));
|
|
|
|
final View dialogView = getActivity().getLayoutInflater().inflate(R.layout.dialog_clear_history, null);
|
|
|
|
final CheckBox endConversationCheckBox = dialogView.findViewById(R.id.end_conversation_checkbox);
|
|
|
|
builder.setView(dialogView);
|
|
|
|
builder.setNegativeButton(getString(R.string.cancel), null);
|
|
|
|
builder.setPositiveButton(getString(R.string.delete_messages), (dialog, which) -> {
|
|
|
|
this.activity.xmppConnectionService.clearConversationHistory(conversation);
|
|
|
|
if (endConversationCheckBox.isChecked()) {
|
2018-02-21 14:46:56 +00:00
|
|
|
this.activity.onConversationArchived(conversation);
|
2018-02-20 13:54:32 +00:00
|
|
|
} else {
|
2018-02-21 14:46:56 +00:00
|
|
|
activity.onConversationsListItemUpdated();
|
2018-02-22 19:12:44 +00:00
|
|
|
refresh();
|
2018-02-20 13:54:32 +00:00
|
|
|
}
|
|
|
|
});
|
|
|
|
builder.create().show();
|
|
|
|
}
|
|
|
|
|
|
|
|
protected void muteConversationDialog(final Conversation conversation) {
|
|
|
|
AlertDialog.Builder builder = new AlertDialog.Builder(getActivity());
|
|
|
|
builder.setTitle(R.string.disable_notifications);
|
|
|
|
final int[] durations = getResources().getIntArray(R.array.mute_options_durations);
|
|
|
|
builder.setItems(R.array.mute_options_descriptions, (dialog, which) -> {
|
|
|
|
final long till;
|
|
|
|
if (durations[which] == -1) {
|
|
|
|
till = Long.MAX_VALUE;
|
|
|
|
} else {
|
|
|
|
till = System.currentTimeMillis() + (durations[which] * 1000);
|
|
|
|
}
|
|
|
|
conversation.setMutedTill(till);
|
|
|
|
activity.xmppConnectionService.updateConversation(conversation);
|
2018-02-21 14:46:56 +00:00
|
|
|
activity.onConversationsListItemUpdated();
|
2018-02-22 19:12:44 +00:00
|
|
|
refresh();
|
2018-02-20 13:54:32 +00:00
|
|
|
getActivity().invalidateOptionsMenu();
|
|
|
|
});
|
|
|
|
builder.create().show();
|
|
|
|
}
|
|
|
|
|
|
|
|
public void unmuteConversation(final Conversation conversation) {
|
|
|
|
conversation.setMutedTill(0);
|
|
|
|
this.activity.xmppConnectionService.updateConversation(conversation);
|
2018-02-21 14:46:56 +00:00
|
|
|
this.activity.onConversationsListItemUpdated();
|
2018-02-22 19:12:44 +00:00
|
|
|
refresh();
|
2018-02-20 13:54:32 +00:00
|
|
|
getActivity().invalidateOptionsMenu();
|
|
|
|
}
|
|
|
|
|
|
|
|
protected void selectPresenceToAttachFile(final int attachmentChoice) {
|
|
|
|
final Account account = conversation.getAccount();
|
|
|
|
final PresenceSelector.OnPresenceSelected callback = () -> {
|
|
|
|
Intent intent = new Intent();
|
|
|
|
boolean chooser = false;
|
|
|
|
String fallbackPackageId = null;
|
|
|
|
switch (attachmentChoice) {
|
|
|
|
case ATTACHMENT_CHOICE_CHOOSE_IMAGE:
|
|
|
|
intent.setAction(Intent.ACTION_GET_CONTENT);
|
|
|
|
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR2) {
|
|
|
|
intent.putExtra(Intent.EXTRA_ALLOW_MULTIPLE, true);
|
|
|
|
}
|
|
|
|
intent.setType("image/*");
|
|
|
|
chooser = true;
|
|
|
|
break;
|
|
|
|
case ATTACHMENT_CHOICE_RECORD_VIDEO:
|
|
|
|
intent.setAction(MediaStore.ACTION_VIDEO_CAPTURE);
|
|
|
|
break;
|
|
|
|
case ATTACHMENT_CHOICE_TAKE_PHOTO:
|
|
|
|
Uri uri = activity.xmppConnectionService.getFileBackend().getTakePhotoUri();
|
2018-02-21 14:46:56 +00:00
|
|
|
//TODO save photo uri
|
2018-02-20 13:54:32 +00:00
|
|
|
//mPendingImageUris.clear();
|
|
|
|
//mPendingImageUris.add(uri);
|
|
|
|
intent.putExtra(MediaStore.EXTRA_OUTPUT, uri);
|
|
|
|
intent.addFlags(Intent.FLAG_GRANT_WRITE_URI_PERMISSION);
|
|
|
|
intent.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION);
|
|
|
|
intent.setAction(MediaStore.ACTION_IMAGE_CAPTURE);
|
|
|
|
break;
|
|
|
|
case ATTACHMENT_CHOICE_CHOOSE_FILE:
|
|
|
|
chooser = true;
|
|
|
|
intent.setType("*/*");
|
|
|
|
intent.addCategory(Intent.CATEGORY_OPENABLE);
|
|
|
|
intent.setAction(Intent.ACTION_GET_CONTENT);
|
|
|
|
break;
|
|
|
|
case ATTACHMENT_CHOICE_RECORD_VOICE:
|
|
|
|
intent.setAction(MediaStore.Audio.Media.RECORD_SOUND_ACTION);
|
|
|
|
fallbackPackageId = "eu.siacs.conversations.voicerecorder";
|
|
|
|
break;
|
|
|
|
case ATTACHMENT_CHOICE_LOCATION:
|
|
|
|
intent.setAction("eu.siacs.conversations.location.request");
|
|
|
|
fallbackPackageId = "eu.siacs.conversations.sharelocation";
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
if (intent.resolveActivity(getActivity().getPackageManager()) != null) {
|
|
|
|
if (chooser) {
|
|
|
|
startActivityForResult(
|
|
|
|
Intent.createChooser(intent, getString(R.string.perform_action_with)),
|
|
|
|
attachmentChoice);
|
|
|
|
} else {
|
|
|
|
startActivityForResult(intent, attachmentChoice);
|
|
|
|
}
|
|
|
|
} else if (fallbackPackageId != null) {
|
|
|
|
startActivity(getInstallApkIntent(fallbackPackageId));
|
|
|
|
}
|
|
|
|
};
|
|
|
|
if (account.httpUploadAvailable() || attachmentChoice == ATTACHMENT_CHOICE_LOCATION) {
|
|
|
|
conversation.setNextCounterpart(null);
|
|
|
|
callback.onPresenceSelected();
|
|
|
|
} else {
|
|
|
|
activity.selectPresence(conversation, callback);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
private Intent getInstallApkIntent(final String packageId) {
|
|
|
|
Intent intent = new Intent(Intent.ACTION_VIEW);
|
|
|
|
intent.setData(Uri.parse("market://details?id=" + packageId));
|
|
|
|
if (intent.resolveActivity(getActivity().getPackageManager()) != null) {
|
|
|
|
return intent;
|
|
|
|
} else {
|
|
|
|
intent.setData(Uri.parse("http://play.google.com/store/apps/details?id=" + packageId));
|
|
|
|
return intent;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void onResume() {
|
|
|
|
new Handler().post(() -> {
|
|
|
|
final PackageManager packageManager = getActivity().getPackageManager();
|
|
|
|
ConversationMenuConfigurator.updateAttachmentAvailability(packageManager);
|
|
|
|
getActivity().invalidateOptionsMenu();
|
|
|
|
});
|
|
|
|
super.onResume();
|
|
|
|
}
|
|
|
|
|
2016-10-26 10:26:04 +00:00
|
|
|
private void showErrorMessage(final Message message) {
|
2018-02-20 13:54:32 +00:00
|
|
|
AlertDialog.Builder builder = new AlertDialog.Builder(getActivity());
|
2016-10-26 10:26:04 +00:00
|
|
|
builder.setTitle(R.string.error_message);
|
|
|
|
builder.setMessage(message.getErrorMessage());
|
2017-11-22 16:57:28 +00:00
|
|
|
builder.setPositiveButton(R.string.confirm, null);
|
2016-10-26 10:26:04 +00:00
|
|
|
builder.create().show();
|
|
|
|
}
|
|
|
|
|
2015-01-12 15:42:20 +00:00
|
|
|
private void shareWith(Message message) {
|
2014-10-23 19:27:41 +00:00
|
|
|
Intent shareIntent = new Intent();
|
|
|
|
shareIntent.setAction(Intent.ACTION_SEND);
|
2017-08-03 11:24:41 +00:00
|
|
|
if (message.isGeoUri()) {
|
2015-03-11 14:48:43 +00:00
|
|
|
shareIntent.putExtra(Intent.EXTRA_TEXT, message.getBody());
|
|
|
|
shareIntent.setType("text/plain");
|
2017-04-30 19:03:44 +00:00
|
|
|
} else if (!message.isFileOrImage()) {
|
|
|
|
shareIntent.putExtra(Intent.EXTRA_TEXT, message.getMergedBody().toString());
|
|
|
|
shareIntent.setType("text/plain");
|
2015-03-11 14:48:43 +00:00
|
|
|
} else {
|
2017-01-09 16:00:08 +00:00
|
|
|
final DownloadableFile file = activity.xmppConnectionService.getFileBackend().getFile(message);
|
|
|
|
try {
|
2018-02-20 13:54:32 +00:00
|
|
|
shareIntent.putExtra(Intent.EXTRA_STREAM, FileBackend.getUriForFile(getActivity(), file));
|
2017-01-09 16:00:08 +00:00
|
|
|
} catch (SecurityException e) {
|
2018-02-20 13:54:32 +00:00
|
|
|
Toast.makeText(getActivity(), activity.getString(R.string.no_permission_to_access_x, file.getAbsolutePath()), Toast.LENGTH_SHORT).show();
|
2017-01-09 16:00:08 +00:00
|
|
|
return;
|
|
|
|
}
|
2018-01-23 21:02:28 +00:00
|
|
|
shareIntent.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION);
|
2015-07-01 14:01:18 +00:00
|
|
|
String mime = message.getMimeType();
|
2015-03-11 14:48:43 +00:00
|
|
|
if (mime == null) {
|
2015-10-20 15:41:07 +00:00
|
|
|
mime = "*/*";
|
2015-03-11 14:48:43 +00:00
|
|
|
}
|
|
|
|
shareIntent.setType(mime);
|
2015-01-12 15:42:20 +00:00
|
|
|
}
|
2015-07-12 18:17:12 +00:00
|
|
|
try {
|
2018-02-20 13:54:32 +00:00
|
|
|
startActivity(Intent.createChooser(shareIntent, getText(R.string.share_with)));
|
2015-07-12 18:17:12 +00:00
|
|
|
} catch (ActivityNotFoundException e) {
|
|
|
|
//This should happen only on faulty androids because normally chooser is always available
|
2018-02-20 13:54:32 +00:00
|
|
|
Toast.makeText(getActivity(), R.string.no_application_found_to_open_file, Toast.LENGTH_SHORT).show();
|
2015-07-12 18:17:12 +00:00
|
|
|
}
|
2014-10-23 19:27:41 +00:00
|
|
|
}
|
|
|
|
|
2017-11-22 16:57:28 +00:00
|
|
|
private void copyMessage(Message message) {
|
2017-11-07 14:58:27 +00:00
|
|
|
if (activity.copyTextToClipboard(message.getMergedBody().toString(), R.string.message)) {
|
2018-02-20 13:54:32 +00:00
|
|
|
Toast.makeText(getActivity(), R.string.message_copied_to_clipboard, Toast.LENGTH_SHORT).show();
|
2016-09-16 22:18:34 +00:00
|
|
|
}
|
2017-11-22 16:57:28 +00:00
|
|
|
}
|
2016-09-16 22:18:34 +00:00
|
|
|
|
2016-03-23 18:23:22 +00:00
|
|
|
private void deleteFile(Message message) {
|
|
|
|
if (activity.xmppConnectionService.getFileBackend().deleteFile(message)) {
|
|
|
|
message.setTransferable(new TransferablePlaceholder(Transferable.STATUS_DELETED));
|
2018-02-21 14:46:56 +00:00
|
|
|
activity.onConversationsListItemUpdated();
|
2018-02-22 19:12:44 +00:00
|
|
|
refresh();
|
2016-03-23 18:23:22 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-09-22 09:14:56 +00:00
|
|
|
private void resendMessage(final Message message) {
|
|
|
|
if (message.isFileOrImage()) {
|
2014-11-15 14:16:40 +00:00
|
|
|
DownloadableFile file = activity.xmppConnectionService.getFileBackend().getFile(message);
|
2017-09-22 09:14:56 +00:00
|
|
|
if (file.exists()) {
|
|
|
|
final Conversation conversation = message.getConversation();
|
|
|
|
final XmppConnection xmppConnection = conversation.getAccount().getXmppConnection();
|
|
|
|
if (!message.hasFileOnRemoteHost()
|
|
|
|
&& xmppConnection != null
|
|
|
|
&& !xmppConnection.getFeatures().httpUpload(message.getFileParams().size)) {
|
2018-02-20 13:54:32 +00:00
|
|
|
activity.selectPresence(conversation, () -> {
|
|
|
|
message.setCounterpart(conversation.getNextCounterpart());
|
|
|
|
activity.xmppConnectionService.resendFailedMessages(message);
|
2017-09-22 09:14:56 +00:00
|
|
|
});
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
} else {
|
2015-05-02 09:38:56 +00:00
|
|
|
Toast.makeText(activity, R.string.file_deleted, Toast.LENGTH_SHORT).show();
|
2015-07-10 13:11:03 +00:00
|
|
|
message.setTransferable(new TransferablePlaceholder(Transferable.STATUS_DELETED));
|
2018-02-21 14:46:56 +00:00
|
|
|
activity.onConversationsListItemUpdated();
|
2018-02-22 19:12:44 +00:00
|
|
|
refresh();
|
2014-11-15 14:16:40 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
2014-10-23 19:27:41 +00:00
|
|
|
activity.xmppConnectionService.resendFailedMessages(message);
|
|
|
|
}
|
|
|
|
|
|
|
|
private void copyUrl(Message message) {
|
2015-03-11 14:48:43 +00:00
|
|
|
final String url;
|
|
|
|
final int resId;
|
2017-08-03 11:24:41 +00:00
|
|
|
if (message.isGeoUri()) {
|
2015-03-11 14:48:43 +00:00
|
|
|
resId = R.string.location;
|
|
|
|
url = message.getBody();
|
2015-07-02 21:13:00 +00:00
|
|
|
} else if (message.hasFileOnRemoteHost()) {
|
|
|
|
resId = R.string.file_url;
|
2015-06-30 15:15:02 +00:00
|
|
|
url = message.getFileParams().url.toString();
|
2015-07-02 21:13:00 +00:00
|
|
|
} else {
|
|
|
|
url = message.getBody().trim();
|
|
|
|
resId = R.string.file_url;
|
2015-03-11 14:48:43 +00:00
|
|
|
}
|
|
|
|
if (activity.copyTextToClipboard(url, resId)) {
|
2018-02-20 13:54:32 +00:00
|
|
|
Toast.makeText(getActivity(), R.string.url_copied_to_clipboard, Toast.LENGTH_SHORT).show();
|
2015-05-02 09:38:56 +00:00
|
|
|
}
|
2014-10-23 19:27:41 +00:00
|
|
|
}
|
|
|
|
|
2017-04-20 09:52:54 +00:00
|
|
|
private void downloadFile(Message message) {
|
2017-11-22 16:57:28 +00:00
|
|
|
activity.xmppConnectionService.getHttpConnectionManager().createNewDownloadConnection(message, true);
|
2017-04-20 09:52:54 +00:00
|
|
|
}
|
|
|
|
|
2014-11-15 11:37:09 +00:00
|
|
|
private void cancelTransmission(Message message) {
|
2015-07-10 13:11:03 +00:00
|
|
|
Transferable transferable = message.getTransferable();
|
|
|
|
if (transferable != null) {
|
|
|
|
transferable.cancel();
|
2017-06-19 11:23:20 +00:00
|
|
|
} else if (message.getStatus() != Message.STATUS_RECEIVED) {
|
2017-11-22 16:57:28 +00:00
|
|
|
activity.xmppConnectionService.markMessage(message, Message.STATUS_SEND_FAILED);
|
2014-11-15 11:37:09 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-02-23 14:30:41 +00:00
|
|
|
private void retryDecryption(Message message) {
|
|
|
|
message.setEncryption(Message.ENCRYPTION_PGP);
|
2018-02-21 14:46:56 +00:00
|
|
|
activity.onConversationsListItemUpdated();
|
2018-02-22 19:12:44 +00:00
|
|
|
refresh();
|
2016-06-15 10:44:29 +00:00
|
|
|
conversation.getAccount().getPgpDecryptionService().decrypt(message, false);
|
2016-02-23 14:30:41 +00:00
|
|
|
}
|
|
|
|
|
2014-11-06 19:33:13 +00:00
|
|
|
protected void privateMessageWith(final Jid counterpart) {
|
2017-03-07 13:36:05 +00:00
|
|
|
if (conversation.setOutgoingChatState(Config.DEFAULT_CHATSTATE)) {
|
|
|
|
activity.xmppConnectionService.sendChatState(conversation);
|
|
|
|
}
|
2018-02-21 10:04:48 +00:00
|
|
|
this.binding.textinput.setText("");
|
2014-11-09 15:21:13 +00:00
|
|
|
this.conversation.setNextCounterpart(counterpart);
|
2014-08-22 11:22:07 +00:00
|
|
|
updateChatMsgHint();
|
2015-05-03 07:30:30 +00:00
|
|
|
updateSendButton();
|
2017-07-03 21:58:34 +00:00
|
|
|
updateEditablity();
|
2014-08-10 13:27:44 +00:00
|
|
|
}
|
2014-01-24 22:58:51 +00:00
|
|
|
|
2016-02-15 22:15:04 +00:00
|
|
|
private void correctMessage(Message message) {
|
2017-11-22 16:57:28 +00:00
|
|
|
while (message.mergeable(message.next())) {
|
2016-02-15 22:15:04 +00:00
|
|
|
message = message.next();
|
|
|
|
}
|
|
|
|
this.conversation.setCorrectingMessage(message);
|
2018-02-21 10:04:48 +00:00
|
|
|
final Editable editable = binding.textinput.getText();
|
2017-03-04 07:04:31 +00:00
|
|
|
this.conversation.setDraftMessage(editable.toString());
|
2018-02-21 10:04:48 +00:00
|
|
|
this.binding.textinput.setText("");
|
|
|
|
this.binding.textinput.append(message.getBody());
|
2016-02-15 22:15:04 +00:00
|
|
|
|
|
|
|
}
|
|
|
|
|
2014-05-20 09:44:43 +00:00
|
|
|
protected void highlightInConference(String nick) {
|
2018-02-21 10:04:48 +00:00
|
|
|
final Editable editable = this.binding.textinput.getText();
|
2017-01-20 12:45:09 +00:00
|
|
|
String oldString = editable.toString().trim();
|
2018-02-21 10:04:48 +00:00
|
|
|
final int pos = this.binding.textinput.getSelectionStart();
|
2017-01-20 12:45:09 +00:00
|
|
|
if (oldString.isEmpty() || pos == 0) {
|
2017-04-06 16:06:07 +00:00
|
|
|
editable.insert(0, nick + ": ");
|
2014-05-20 09:44:43 +00:00
|
|
|
} else {
|
2017-01-20 12:45:09 +00:00
|
|
|
final char before = editable.charAt(pos - 1);
|
|
|
|
final char after = editable.length() > pos ? editable.charAt(pos) : '\0';
|
|
|
|
if (before == '\n') {
|
|
|
|
editable.insert(pos, nick + ": ");
|
|
|
|
} else {
|
2017-11-22 16:57:28 +00:00
|
|
|
if (pos > 2 && editable.subSequence(pos - 2, pos).toString().equals(": ")) {
|
|
|
|
if (NickValidityChecker.check(conversation, Arrays.asList(editable.subSequence(0, pos - 2).toString().split(", ")))) {
|
2017-04-07 17:47:33 +00:00
|
|
|
editable.insert(pos - 2, ", " + nick);
|
|
|
|
return;
|
2017-04-06 16:06:07 +00:00
|
|
|
}
|
2017-01-20 12:45:09 +00:00
|
|
|
}
|
2017-04-07 17:47:33 +00:00
|
|
|
editable.insert(pos, (Character.isWhitespace(before) ? "" : " ") + nick + (Character.isWhitespace(after) ? "" : " "));
|
|
|
|
if (Character.isWhitespace(after)) {
|
2018-02-21 10:04:48 +00:00
|
|
|
this.binding.textinput.setSelection(this.binding.textinput.getSelectionStart() + 1);
|
2017-04-07 17:47:33 +00:00
|
|
|
}
|
2015-05-02 09:38:56 +00:00
|
|
|
}
|
2014-05-20 09:44:43 +00:00
|
|
|
}
|
|
|
|
}
|
2014-06-01 17:29:57 +00:00
|
|
|
|
2018-02-21 22:07:53 +00:00
|
|
|
|
|
|
|
@Override
|
|
|
|
public void onSaveInstanceState(Bundle outState) {
|
|
|
|
super.onSaveInstanceState(outState);
|
|
|
|
if (conversation != null) {
|
|
|
|
outState.putString(STATE_CONVERSATION_UUID, conversation.getUuid());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void onActivityCreated(Bundle savedInstanceState) {
|
2018-02-22 21:23:49 +00:00
|
|
|
Log.d(Config.LOGTAG,"ConversationFragment.onActivityCreated()");
|
2018-02-21 22:07:53 +00:00
|
|
|
super.onActivityCreated(savedInstanceState);
|
|
|
|
if (savedInstanceState == null) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
String uuid = savedInstanceState.getString(STATE_CONVERSATION_UUID);
|
|
|
|
if (uuid != null) {
|
|
|
|
this.pendingConversationsUuid.push(uuid);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-02-21 14:46:56 +00:00
|
|
|
@Override
|
|
|
|
public void onStart() {
|
|
|
|
super.onStart();
|
|
|
|
reInit(conversation);
|
|
|
|
}
|
|
|
|
|
2014-05-07 10:59:15 +00:00
|
|
|
@Override
|
|
|
|
public void onStop() {
|
|
|
|
super.onStop();
|
2018-02-20 13:54:32 +00:00
|
|
|
final Activity activity = getActivity();
|
2017-09-20 13:35:35 +00:00
|
|
|
if (activity == null || !activity.isChangingConfigurations()) {
|
|
|
|
messageListAdapter.stopAudioPlayer();
|
|
|
|
}
|
2014-05-19 13:39:50 +00:00
|
|
|
if (this.conversation != null) {
|
2018-02-21 10:04:48 +00:00
|
|
|
final String msg = this.binding.textinput.getText().toString();
|
2017-10-01 20:52:21 +00:00
|
|
|
if (this.conversation.setNextMessage(msg)) {
|
2018-02-20 13:54:32 +00:00
|
|
|
this.activity.xmppConnectionService.updateConversation(this.conversation);
|
2017-10-01 20:52:21 +00:00
|
|
|
}
|
2015-05-02 09:38:56 +00:00
|
|
|
updateChatState(this.conversation, msg);
|
2015-02-21 10:06:52 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
private void updateChatState(final Conversation conversation, final String msg) {
|
|
|
|
ChatState state = msg.length() == 0 ? Config.DEFAULT_CHATSTATE : ChatState.PAUSED;
|
|
|
|
Account.State status = conversation.getAccount().getStatus();
|
|
|
|
if (status == Account.State.ONLINE && conversation.setOutgoingChatState(state)) {
|
|
|
|
activity.xmppConnectionService.sendChatState(conversation);
|
2014-05-09 18:46:43 +00:00
|
|
|
}
|
2014-05-07 10:59:15 +00:00
|
|
|
}
|
|
|
|
|
2018-02-23 18:22:38 +00:00
|
|
|
public void reInit(Conversation conversation) {
|
2018-02-21 22:07:53 +00:00
|
|
|
Log.d(Config.LOGTAG, "reInit()");
|
2014-11-17 19:02:46 +00:00
|
|
|
if (conversation == null) {
|
2018-02-21 22:07:53 +00:00
|
|
|
Log.d(Config.LOGTAG, "conversation was null :(");
|
2018-02-23 18:22:38 +00:00
|
|
|
return;
|
2014-11-17 19:02:46 +00:00
|
|
|
}
|
2018-02-21 14:46:56 +00:00
|
|
|
|
|
|
|
if (this.activity == null) {
|
2018-02-21 22:07:53 +00:00
|
|
|
Log.d(Config.LOGTAG, "activity was null");
|
2018-02-21 14:46:56 +00:00
|
|
|
this.conversation = conversation;
|
2018-02-23 18:22:38 +00:00
|
|
|
return;
|
2018-02-21 14:46:56 +00:00
|
|
|
}
|
|
|
|
|
2015-09-04 12:48:00 +00:00
|
|
|
setupIme();
|
2014-11-07 14:38:20 +00:00
|
|
|
if (this.conversation != null) {
|
2018-02-21 10:04:48 +00:00
|
|
|
final String msg = this.binding.textinput.getText().toString();
|
2017-10-01 20:52:21 +00:00
|
|
|
if (this.conversation.setNextMessage(msg)) {
|
|
|
|
activity.xmppConnectionService.updateConversation(conversation);
|
|
|
|
}
|
2015-02-21 10:06:52 +00:00
|
|
|
if (this.conversation != conversation) {
|
2015-05-02 09:38:56 +00:00
|
|
|
updateChatState(this.conversation, msg);
|
2017-09-20 13:35:35 +00:00
|
|
|
messageListAdapter.stopAudioPlayer();
|
2015-02-21 10:06:52 +00:00
|
|
|
}
|
2014-12-17 20:05:47 +00:00
|
|
|
this.conversation.trim();
|
2017-04-25 12:11:45 +00:00
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
if (activity != null) {
|
2018-02-21 10:04:48 +00:00
|
|
|
this.binding.textSendButton.setContentDescription(activity.getString(R.string.send_message_to_x, conversation.getName()));
|
2014-01-28 18:21:54 +00:00
|
|
|
}
|
2015-02-21 10:06:52 +00:00
|
|
|
|
2014-11-07 14:38:20 +00:00
|
|
|
this.conversation = conversation;
|
2018-02-21 10:04:48 +00:00
|
|
|
this.binding.textinput.setKeyboardListener(null);
|
|
|
|
this.binding.textinput.setText("");
|
|
|
|
this.binding.textinput.append(this.conversation.getNextMessage());
|
|
|
|
this.binding.textinput.setKeyboardListener(this);
|
2015-08-24 18:56:25 +00:00
|
|
|
messageListAdapter.updatePreferences();
|
2018-02-21 10:04:48 +00:00
|
|
|
this.binding.messagesView.setAdapter(messageListAdapter);
|
2018-02-23 18:22:38 +00:00
|
|
|
refresh(false);
|
2017-01-25 17:35:22 +00:00
|
|
|
this.conversation.messagesLoaded.set(true);
|
2018-02-23 18:22:38 +00:00
|
|
|
final boolean isAtBottom;
|
2016-05-22 15:52:27 +00:00
|
|
|
synchronized (this.messageList) {
|
|
|
|
final Message first = conversation.getFirstUnreadMessage();
|
2016-05-31 14:44:59 +00:00
|
|
|
final int bottom = Math.max(0, this.messageList.size() - 1);
|
2016-05-22 15:52:27 +00:00
|
|
|
final int pos;
|
|
|
|
if (first == null) {
|
2016-05-31 14:44:59 +00:00
|
|
|
pos = bottom;
|
2016-05-22 15:52:27 +00:00
|
|
|
} else {
|
2016-05-31 14:44:59 +00:00
|
|
|
int i = getIndexOf(first.getUuid(), this.messageList);
|
|
|
|
pos = i < 0 ? bottom : i;
|
2016-05-22 15:52:27 +00:00
|
|
|
}
|
2018-02-21 10:04:48 +00:00
|
|
|
this.binding.messagesView.setSelection(pos);
|
2018-02-23 18:22:38 +00:00
|
|
|
isAtBottom = pos == bottom;
|
|
|
|
}
|
|
|
|
if (activity != null) {
|
|
|
|
activity.onConversationRead(this.conversation);
|
2014-12-17 09:50:51 +00:00
|
|
|
}
|
2014-01-24 22:58:51 +00:00
|
|
|
}
|
2014-05-07 10:59:15 +00:00
|
|
|
|
2018-02-20 13:54:32 +00:00
|
|
|
private boolean showBlockSubmenu(View view) {
|
2017-11-22 16:57:28 +00:00
|
|
|
final Jid jid = conversation.getJid();
|
|
|
|
if (jid.isDomainJid()) {
|
|
|
|
BlockContactDialog.show(activity, conversation);
|
|
|
|
} else {
|
2018-02-20 13:54:32 +00:00
|
|
|
PopupMenu popupMenu = new PopupMenu(getActivity(), view);
|
2017-11-22 16:57:28 +00:00
|
|
|
popupMenu.inflate(R.menu.block);
|
2018-02-20 13:54:32 +00:00
|
|
|
popupMenu.setOnMenuItemClickListener(menuItem -> {
|
|
|
|
Blockable blockable;
|
|
|
|
switch (menuItem.getItemId()) {
|
|
|
|
case R.id.block_domain:
|
|
|
|
blockable = conversation.getAccount().getRoster().getContact(jid.toDomainJid());
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
blockable = conversation;
|
2015-02-07 11:17:03 +00:00
|
|
|
}
|
2018-02-20 13:54:32 +00:00
|
|
|
BlockContactDialog.show(activity, blockable);
|
|
|
|
return true;
|
2015-02-07 11:17:03 +00:00
|
|
|
});
|
2017-11-22 16:57:28 +00:00
|
|
|
popupMenu.show();
|
2015-02-07 11:17:03 +00:00
|
|
|
}
|
2018-02-20 13:54:32 +00:00
|
|
|
return true;
|
2017-09-11 07:53:14 +00:00
|
|
|
}
|
|
|
|
|
2015-02-07 11:17:03 +00:00
|
|
|
private void updateSnackBar(final Conversation conversation) {
|
|
|
|
final Account account = conversation.getAccount();
|
2017-03-20 11:16:25 +00:00
|
|
|
final XmppConnection connection = account.getXmppConnection();
|
2015-02-07 11:17:03 +00:00
|
|
|
final int mode = conversation.getMode();
|
2016-12-01 11:50:40 +00:00
|
|
|
final Contact contact = mode == Conversation.MODE_SINGLE ? conversation.getContact() : null;
|
2016-03-06 11:16:29 +00:00
|
|
|
if (account.getStatus() == Account.State.DISABLED) {
|
|
|
|
showSnackbar(R.string.this_account_is_disabled, R.string.enable, this.mEnableAccountListener);
|
|
|
|
} else if (conversation.isBlocked()) {
|
2015-05-02 09:38:56 +00:00
|
|
|
showSnackbar(R.string.contact_blocked, R.string.unblock, this.mUnblockClickListener);
|
2016-12-01 11:50:40 +00:00
|
|
|
} else if (contact != null && !contact.showInRoster() && contact.getOption(Contact.Options.PENDING_SUBSCRIPTION_REQUEST)) {
|
2017-09-11 07:53:14 +00:00
|
|
|
showSnackbar(R.string.contact_added_you, R.string.add_back, this.mAddBackClickListener, this.mLongPressBlockListener);
|
2016-12-01 11:50:40 +00:00
|
|
|
} else if (contact != null && contact.getOption(Contact.Options.PENDING_SUBSCRIPTION_REQUEST)) {
|
2017-09-11 07:53:14 +00:00
|
|
|
showSnackbar(R.string.contact_asks_for_presence_subscription, R.string.allow, this.mAllowPresenceSubscription, this.mLongPressBlockListener);
|
2015-02-07 11:17:03 +00:00
|
|
|
} else if (mode == Conversation.MODE_MULTI
|
2015-05-02 09:38:56 +00:00
|
|
|
&& !conversation.getMucOptions().online()
|
2015-02-07 11:17:03 +00:00
|
|
|
&& account.getStatus() == Account.State.ONLINE) {
|
|
|
|
switch (conversation.getMucOptions().getError()) {
|
2016-02-22 19:19:58 +00:00
|
|
|
case NICK_IN_USE:
|
2015-02-07 11:17:03 +00:00
|
|
|
showSnackbar(R.string.nick_in_use, R.string.edit, clickToMuc);
|
|
|
|
break;
|
2016-02-22 19:19:58 +00:00
|
|
|
case NO_RESPONSE:
|
|
|
|
showSnackbar(R.string.joining_conference, 0, null);
|
2015-02-07 11:17:03 +00:00
|
|
|
break;
|
2016-09-09 09:04:05 +00:00
|
|
|
case SERVER_NOT_FOUND:
|
2017-04-15 15:18:15 +00:00
|
|
|
if (conversation.receivedMessagesCount() > 0) {
|
2017-11-22 16:57:28 +00:00
|
|
|
showSnackbar(R.string.remote_server_not_found, R.string.try_again, joinMuc);
|
2017-04-15 15:18:15 +00:00
|
|
|
} else {
|
|
|
|
showSnackbar(R.string.remote_server_not_found, R.string.leave, leaveMuc);
|
|
|
|
}
|
2016-09-06 10:15:08 +00:00
|
|
|
break;
|
2016-02-22 19:19:58 +00:00
|
|
|
case PASSWORD_REQUIRED:
|
2015-02-07 11:17:03 +00:00
|
|
|
showSnackbar(R.string.conference_requires_password, R.string.enter_password, enterPassword);
|
|
|
|
break;
|
2016-02-22 19:19:58 +00:00
|
|
|
case BANNED:
|
2015-02-07 11:17:03 +00:00
|
|
|
showSnackbar(R.string.conference_banned, R.string.leave, leaveMuc);
|
|
|
|
break;
|
2016-02-22 19:19:58 +00:00
|
|
|
case MEMBERS_ONLY:
|
2015-02-07 11:17:03 +00:00
|
|
|
showSnackbar(R.string.conference_members_only, R.string.leave, leaveMuc);
|
|
|
|
break;
|
2016-02-22 19:19:58 +00:00
|
|
|
case KICKED:
|
2015-02-07 11:17:03 +00:00
|
|
|
showSnackbar(R.string.conference_kicked, R.string.join, joinMuc);
|
|
|
|
break;
|
2016-02-22 19:19:58 +00:00
|
|
|
case UNKNOWN:
|
2017-11-30 12:21:03 +00:00
|
|
|
showSnackbar(R.string.conference_unknown_error, R.string.try_again, joinMuc);
|
2016-02-22 19:19:58 +00:00
|
|
|
break;
|
2017-12-11 14:55:10 +00:00
|
|
|
case INVALID_NICK:
|
|
|
|
showSnackbar(R.string.invalid_muc_nick, R.string.edit, clickToMuc);
|
2016-02-22 19:19:58 +00:00
|
|
|
case SHUTDOWN:
|
2017-11-30 12:21:03 +00:00
|
|
|
showSnackbar(R.string.conference_shutdown, R.string.try_again, joinMuc);
|
2016-02-01 11:11:40 +00:00
|
|
|
break;
|
2015-02-07 11:17:03 +00:00
|
|
|
default:
|
2017-04-15 15:18:15 +00:00
|
|
|
hideSnackbar();
|
2015-02-07 11:17:03 +00:00
|
|
|
break;
|
|
|
|
}
|
2016-06-13 11:32:14 +00:00
|
|
|
} else if (account.hasPendingPgpIntent(conversation)) {
|
2015-05-02 09:38:56 +00:00
|
|
|
showSnackbar(R.string.openpgp_messages_found, R.string.decrypt, clickToDecryptListener);
|
2017-03-20 11:16:25 +00:00
|
|
|
} else if (connection != null
|
|
|
|
&& connection.getFeatures().blocking()
|
|
|
|
&& conversation.countMessages() != 0
|
2017-03-08 10:54:52 +00:00
|
|
|
&& !conversation.isBlocked()
|
|
|
|
&& conversation.isWithStranger()) {
|
2017-11-22 16:57:28 +00:00
|
|
|
showSnackbar(R.string.received_message_from_stranger, R.string.block, mBlockClickListener);
|
2015-02-07 11:17:03 +00:00
|
|
|
} else {
|
|
|
|
hideSnackbar();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-02-22 19:12:44 +00:00
|
|
|
@Override
|
|
|
|
public void refresh() {
|
2018-02-23 18:22:38 +00:00
|
|
|
this.refresh(true);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
private void refresh(boolean notifyConversationRead) {
|
2014-11-18 13:43:15 +00:00
|
|
|
synchronized (this.messageList) {
|
|
|
|
if (this.conversation != null) {
|
2018-02-22 19:12:44 +00:00
|
|
|
conversation.populateWithMessages(this.messageList);
|
2015-10-15 22:21:47 +00:00
|
|
|
updateSnackBar(conversation);
|
2014-12-14 17:10:46 +00:00
|
|
|
updateStatusMessages();
|
2014-11-18 13:43:15 +00:00
|
|
|
this.messageListAdapter.notifyDataSetChanged();
|
|
|
|
updateChatMsgHint();
|
2018-02-23 18:22:38 +00:00
|
|
|
if (notifyConversationRead && activity != null) {
|
2018-02-21 14:46:56 +00:00
|
|
|
activity.onConversationRead(this.conversation);
|
2014-11-18 13:43:15 +00:00
|
|
|
}
|
2017-07-03 17:55:21 +00:00
|
|
|
updateSendButton();
|
|
|
|
updateEditablity();
|
2014-03-03 04:01:02 +00:00
|
|
|
}
|
2014-02-10 22:12:11 +00:00
|
|
|
}
|
2014-02-02 15:33:34 +00:00
|
|
|
}
|
2014-06-06 09:39:17 +00:00
|
|
|
|
2016-06-15 11:53:34 +00:00
|
|
|
protected void messageSent() {
|
2017-03-03 10:56:08 +00:00
|
|
|
mSendingPgpMessage.set(false);
|
2018-02-21 10:04:48 +00:00
|
|
|
this.binding.textinput.setText("");
|
2017-03-04 07:04:31 +00:00
|
|
|
if (conversation.setCorrectingMessage(null)) {
|
2018-02-21 10:04:48 +00:00
|
|
|
this.binding.textinput.append(conversation.getDraftMessage());
|
2017-03-04 07:04:31 +00:00
|
|
|
conversation.setDraftMessage(null);
|
|
|
|
}
|
2018-02-21 10:04:48 +00:00
|
|
|
if (conversation.setNextMessage(this.binding.textinput.getText().toString())) {
|
2017-10-01 20:52:21 +00:00
|
|
|
activity.xmppConnectionService.updateConversation(conversation);
|
|
|
|
}
|
2014-08-10 13:27:44 +00:00
|
|
|
updateChatMsgHint();
|
2018-02-21 10:04:48 +00:00
|
|
|
new Handler().post(() -> {
|
|
|
|
int size = messageList.size();
|
|
|
|
this.binding.messagesView.setSelection(size - 1);
|
2016-05-12 08:39:04 +00:00
|
|
|
});
|
2014-06-10 15:01:19 +00:00
|
|
|
}
|
2014-06-14 14:59:07 +00:00
|
|
|
|
2015-09-07 13:46:22 +00:00
|
|
|
public void setFocusOnInputField() {
|
2018-02-21 10:04:48 +00:00
|
|
|
this.binding.textinput.requestFocus();
|
2015-09-07 13:46:22 +00:00
|
|
|
}
|
|
|
|
|
2017-03-03 10:56:08 +00:00
|
|
|
public void doneSendingPgpMessage() {
|
|
|
|
mSendingPgpMessage.set(false);
|
|
|
|
}
|
|
|
|
|
2018-02-21 14:46:56 +00:00
|
|
|
public long getMaxHttpUploadSize(Conversation conversation) {
|
|
|
|
final XmppConnection connection = conversation.getAccount().getXmppConnection();
|
|
|
|
return connection == null ? -1 : connection.getFeatures().getMaxHttpUploadSize();
|
|
|
|
}
|
2015-05-02 09:38:56 +00:00
|
|
|
|
2017-07-03 17:55:21 +00:00
|
|
|
private void updateEditablity() {
|
2017-07-03 21:58:34 +00:00
|
|
|
boolean canWrite = this.conversation.getMode() == Conversation.MODE_SINGLE || this.conversation.getMucOptions().participating() || this.conversation.getNextCounterpart() != null;
|
2018-02-21 10:04:48 +00:00
|
|
|
this.binding.textinput.setFocusable(canWrite);
|
|
|
|
this.binding.textinput.setFocusableInTouchMode(canWrite);
|
|
|
|
this.binding.textSendButton.setEnabled(canWrite);
|
|
|
|
this.binding.textinput.setCursorVisible(canWrite);
|
2017-07-03 17:55:21 +00:00
|
|
|
}
|
|
|
|
|
2015-05-02 09:38:56 +00:00
|
|
|
public void updateSendButton() {
|
2018-02-21 14:46:56 +00:00
|
|
|
boolean useSendButtonToIndicateStatus = PreferenceManager.getDefaultSharedPreferences(getActivity()).getBoolean("send_button_status", getResources().getBoolean(R.bool.send_button_status));
|
2015-05-02 09:38:56 +00:00
|
|
|
final Conversation c = this.conversation;
|
2016-01-17 21:28:38 +00:00
|
|
|
final Presence.Status status;
|
2018-02-21 10:04:48 +00:00
|
|
|
final String text = this.binding.textinput == null ? "" : this.binding.textinput.getText().toString();
|
2018-02-21 22:07:53 +00:00
|
|
|
final SendButtonAction action = SendButtonTool.getAction(getActivity(), c, text);
|
2018-02-21 14:46:56 +00:00
|
|
|
if (useSendButtonToIndicateStatus && c.getAccount().getStatus() == Account.State.ONLINE) {
|
2017-05-19 11:39:44 +00:00
|
|
|
if (activity.xmppConnectionService != null && activity.xmppConnectionService.getMessageArchiveService().isCatchingUp(c)) {
|
|
|
|
status = Presence.Status.OFFLINE;
|
|
|
|
} else if (c.getMode() == Conversation.MODE_SINGLE) {
|
2016-06-30 21:08:55 +00:00
|
|
|
status = c.getContact().getShownStatus();
|
2015-05-02 09:38:56 +00:00
|
|
|
} else {
|
2016-01-17 21:28:38 +00:00
|
|
|
status = c.getMucOptions().online() ? Presence.Status.ONLINE : Presence.Status.OFFLINE;
|
2014-09-10 15:59:57 +00:00
|
|
|
}
|
|
|
|
} else {
|
2016-01-17 21:28:38 +00:00
|
|
|
status = Presence.Status.OFFLINE;
|
2014-09-10 15:59:57 +00:00
|
|
|
}
|
2018-02-21 10:04:48 +00:00
|
|
|
this.binding.textSendButton.setTag(action);
|
|
|
|
this.binding.textSendButton.setImageResource(SendButtonTool.getSendButtonImageResource(getActivity(), action, status));
|
2014-09-10 15:59:57 +00:00
|
|
|
}
|
|
|
|
|
2017-07-04 09:01:20 +00:00
|
|
|
protected void updateDateSeparators() {
|
|
|
|
synchronized (this.messageList) {
|
2017-11-22 16:57:28 +00:00
|
|
|
for (int i = 0; i < this.messageList.size(); ++i) {
|
2017-07-04 09:01:20 +00:00
|
|
|
final Message current = this.messageList.get(i);
|
2017-11-22 16:57:28 +00:00
|
|
|
if (i == 0 || !UIHelper.sameDay(this.messageList.get(i - 1).getTimeSent(), current.getTimeSent())) {
|
|
|
|
this.messageList.add(i, Message.createDateSeparator(current));
|
2017-07-04 09:01:20 +00:00
|
|
|
i++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-06-04 19:40:17 +00:00
|
|
|
protected void updateStatusMessages() {
|
2017-07-04 09:01:20 +00:00
|
|
|
updateDateSeparators();
|
2014-11-18 13:43:15 +00:00
|
|
|
synchronized (this.messageList) {
|
2016-02-21 16:32:46 +00:00
|
|
|
if (showLoadMoreMessages(conversation)) {
|
2016-02-04 13:39:16 +00:00
|
|
|
this.messageList.add(0, Message.createLoadMoreMessage(conversation));
|
|
|
|
}
|
2014-11-18 13:43:15 +00:00
|
|
|
if (conversation.getMode() == Conversation.MODE_SINGLE) {
|
2015-02-21 10:06:52 +00:00
|
|
|
ChatState state = conversation.getIncomingChatState();
|
|
|
|
if (state == ChatState.COMPOSING) {
|
|
|
|
this.messageList.add(Message.createStatusMessage(conversation, getString(R.string.contact_is_typing, conversation.getName())));
|
|
|
|
} else if (state == ChatState.PAUSED) {
|
|
|
|
this.messageList.add(Message.createStatusMessage(conversation, getString(R.string.contact_has_stopped_typing, conversation.getName())));
|
|
|
|
} else {
|
|
|
|
for (int i = this.messageList.size() - 1; i >= 0; --i) {
|
|
|
|
if (this.messageList.get(i).getStatus() == Message.STATUS_RECEIVED) {
|
2014-11-18 13:43:15 +00:00
|
|
|
return;
|
2015-02-21 10:06:52 +00:00
|
|
|
} else {
|
|
|
|
if (this.messageList.get(i).getStatus() == Message.STATUS_SEND_DISPLAYED) {
|
|
|
|
this.messageList.add(i + 1,
|
|
|
|
Message.createStatusMessage(conversation, getString(R.string.contact_has_read_up_to_this_point, conversation.getName())));
|
|
|
|
return;
|
|
|
|
}
|
2014-11-18 13:43:15 +00:00
|
|
|
}
|
2014-06-04 19:40:17 +00:00
|
|
|
}
|
|
|
|
}
|
2017-03-08 09:32:42 +00:00
|
|
|
} else {
|
2017-11-19 00:53:04 +00:00
|
|
|
final MucOptions mucOptions = conversation.getMucOptions();
|
|
|
|
final List<MucOptions.User> allUsers = mucOptions.getUsers();
|
|
|
|
final Set<ReadByMarker> addedMarkers = new HashSet<>();
|
2017-03-08 09:32:42 +00:00
|
|
|
ChatState state = ChatState.COMPOSING;
|
2017-11-22 16:57:28 +00:00
|
|
|
List<MucOptions.User> users = conversation.getMucOptions().getUsersWithChatState(state, 5);
|
2017-03-08 09:32:42 +00:00
|
|
|
if (users.size() == 0) {
|
|
|
|
state = ChatState.PAUSED;
|
|
|
|
users = conversation.getMucOptions().getUsersWithChatState(state, 5);
|
2017-11-19 00:53:04 +00:00
|
|
|
}
|
2018-01-22 22:21:24 +00:00
|
|
|
if (mucOptions.isPrivateAndNonAnonymous()) {
|
2017-11-19 00:53:04 +00:00
|
|
|
for (int i = this.messageList.size() - 1; i >= 0; --i) {
|
|
|
|
final Set<ReadByMarker> markersForMessage = messageList.get(i).getReadByMarkers();
|
|
|
|
final List<MucOptions.User> shownMarkers = new ArrayList<>();
|
|
|
|
for (ReadByMarker marker : markersForMessage) {
|
|
|
|
if (!ReadByMarker.contains(marker, addedMarkers)) {
|
|
|
|
addedMarkers.add(marker); //may be put outside this condition. set should do dedup anyway
|
|
|
|
MucOptions.User user = mucOptions.findUser(marker);
|
|
|
|
if (user != null && !users.contains(user)) {
|
|
|
|
shownMarkers.add(user);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
final ReadByMarker markerForSender = ReadByMarker.from(messageList.get(i));
|
|
|
|
final Message statusMessage;
|
2017-11-22 16:57:28 +00:00
|
|
|
final int size = shownMarkers.size();
|
|
|
|
if (size > 1) {
|
|
|
|
final String body;
|
|
|
|
if (size <= 4) {
|
|
|
|
body = getString(R.string.contacts_have_read_up_to_this_point, UIHelper.concatNames(shownMarkers));
|
|
|
|
} else {
|
|
|
|
body = getString(R.string.contacts_and_n_more_have_read_up_to_this_point, UIHelper.concatNames(shownMarkers, 3), size - 3);
|
|
|
|
}
|
|
|
|
statusMessage = Message.createStatusMessage(conversation, body);
|
2017-11-19 00:53:04 +00:00
|
|
|
statusMessage.setCounterparts(shownMarkers);
|
2017-11-22 16:57:28 +00:00
|
|
|
} else if (size == 1) {
|
2017-11-19 00:53:04 +00:00
|
|
|
statusMessage = Message.createStatusMessage(conversation, getString(R.string.contact_has_read_up_to_this_point, UIHelper.getDisplayName(shownMarkers.get(0))));
|
|
|
|
statusMessage.setCounterpart(shownMarkers.get(0).getFullJid());
|
|
|
|
statusMessage.setTrueCounterpart(shownMarkers.get(0).getRealJid());
|
|
|
|
} else {
|
|
|
|
statusMessage = null;
|
|
|
|
}
|
|
|
|
if (statusMessage != null) {
|
|
|
|
this.messageList.add(i + 1, statusMessage);
|
|
|
|
}
|
|
|
|
addedMarkers.add(markerForSender);
|
|
|
|
if (ReadByMarker.allUsersRepresented(allUsers, addedMarkers)) {
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2017-03-08 09:32:42 +00:00
|
|
|
}
|
|
|
|
if (users.size() > 0) {
|
|
|
|
Message statusMessage;
|
|
|
|
if (users.size() == 1) {
|
|
|
|
MucOptions.User user = users.get(0);
|
|
|
|
int id = state == ChatState.COMPOSING ? R.string.contact_is_typing : R.string.contact_has_stopped_typing;
|
|
|
|
statusMessage = Message.createStatusMessage(conversation, getString(id, UIHelper.getDisplayName(user)));
|
|
|
|
statusMessage.setTrueCounterpart(user.getRealJid());
|
|
|
|
statusMessage.setCounterpart(user.getFullJid());
|
|
|
|
} else {
|
|
|
|
int id = state == ChatState.COMPOSING ? R.string.contacts_are_typing : R.string.contacts_have_stopped_typing;
|
2017-11-19 00:53:04 +00:00
|
|
|
statusMessage = Message.createStatusMessage(conversation, getString(id, UIHelper.concatNames(users)));
|
|
|
|
statusMessage.setCounterparts(users);
|
2017-03-08 09:32:42 +00:00
|
|
|
}
|
|
|
|
this.messageList.add(statusMessage);
|
|
|
|
}
|
|
|
|
|
2014-06-04 19:40:17 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2014-02-16 15:32:15 +00:00
|
|
|
|
2017-11-17 20:00:01 +00:00
|
|
|
public void stopScrolling() {
|
|
|
|
long now = SystemClock.uptimeMillis();
|
|
|
|
MotionEvent cancel = MotionEvent.obtain(now, now, MotionEvent.ACTION_CANCEL, 0, 0, 0);
|
2018-02-21 10:04:48 +00:00
|
|
|
binding.messagesView.dispatchTouchEvent(cancel);
|
2017-11-17 20:00:01 +00:00
|
|
|
}
|
|
|
|
|
2016-02-21 16:32:46 +00:00
|
|
|
private boolean showLoadMoreMessages(final Conversation c) {
|
2018-01-29 00:39:46 +00:00
|
|
|
final boolean mam = hasMamSupport(c) && !c.getContact().isBlocked();
|
2016-02-21 16:32:46 +00:00
|
|
|
final MessageArchiveService service = activity.xmppConnectionService.getMessageArchiveService();
|
2017-11-22 16:57:28 +00:00
|
|
|
return mam && (c.getLastClearHistory().getTimestamp() != 0 || (c.countMessages() == 0 && c.messagesLoaded.get() && c.hasMessagesLeftOnServer() && !service.queryInProgress(c)));
|
2016-02-21 16:32:46 +00:00
|
|
|
}
|
|
|
|
|
2016-02-22 19:28:58 +00:00
|
|
|
private boolean hasMamSupport(final Conversation c) {
|
|
|
|
if (c.getMode() == Conversation.MODE_SINGLE) {
|
|
|
|
final XmppConnection connection = c.getAccount().getXmppConnection();
|
|
|
|
return connection != null && connection.getFeatures().mam();
|
|
|
|
} else {
|
|
|
|
return c.getMucOptions().mamSupport();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-02-21 16:32:46 +00:00
|
|
|
protected void showSnackbar(final int message, final int action, final OnClickListener clickListener) {
|
2017-11-22 16:57:28 +00:00
|
|
|
showSnackbar(message, action, clickListener, null);
|
2017-09-11 07:53:14 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
protected void showSnackbar(final int message, final int action, final OnClickListener clickListener, final View.OnLongClickListener longClickListener) {
|
2018-02-21 10:04:48 +00:00
|
|
|
this.binding.snackbar.setVisibility(View.VISIBLE);
|
|
|
|
this.binding.snackbar.setOnClickListener(null);
|
|
|
|
this.binding.snackbarMessage.setText(message);
|
|
|
|
this.binding.snackbarMessage.setOnClickListener(null);
|
|
|
|
this.binding.snackbarAction.setVisibility(clickListener == null ? View.GONE : View.VISIBLE);
|
2016-02-22 19:19:58 +00:00
|
|
|
if (action != 0) {
|
2018-02-21 10:04:48 +00:00
|
|
|
this.binding.snackbarAction.setText(action);
|
2016-02-22 19:19:58 +00:00
|
|
|
}
|
2018-02-21 10:04:48 +00:00
|
|
|
this.binding.snackbarAction.setOnClickListener(clickListener);
|
|
|
|
this.binding.snackbarAction.setOnLongClickListener(longClickListener);
|
2014-07-09 19:45:03 +00:00
|
|
|
}
|
2014-07-18 17:36:29 +00:00
|
|
|
|
2014-07-09 19:45:03 +00:00
|
|
|
protected void hideSnackbar() {
|
2018-02-21 10:04:48 +00:00
|
|
|
this.binding.snackbar.setVisibility(View.GONE);
|
2014-07-09 19:45:03 +00:00
|
|
|
}
|
2014-02-16 18:30:22 +00:00
|
|
|
|
|
|
|
protected void sendPlainTextMessage(Message message) {
|
2014-06-11 19:53:25 +00:00
|
|
|
activity.xmppConnectionService.sendMessage(message);
|
2014-06-10 15:01:19 +00:00
|
|
|
messageSent();
|
2014-02-16 18:30:22 +00:00
|
|
|
}
|
2014-02-19 00:35:23 +00:00
|
|
|
|
2014-02-27 23:22:56 +00:00
|
|
|
protected void sendPgpMessage(final Message message) {
|
|
|
|
final XmppConnectionService xmppService = activity.xmppConnectionService;
|
2014-05-01 20:33:49 +00:00
|
|
|
final Contact contact = message.getConversation().getContact();
|
2015-12-02 15:43:55 +00:00
|
|
|
if (!activity.hasPgp()) {
|
|
|
|
activity.showInstallPgpDialog();
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
if (conversation.getAccount().getPgpSignature() == null) {
|
2017-12-05 18:16:53 +00:00
|
|
|
activity.announcePgp(conversation.getAccount(), conversation, null, activity.onOpenPGPKeyPublished);
|
2015-12-02 15:43:55 +00:00
|
|
|
return;
|
|
|
|
}
|
2017-11-22 16:57:28 +00:00
|
|
|
if (!mSendingPgpMessage.compareAndSet(false, true)) {
|
|
|
|
Log.d(Config.LOGTAG, "sending pgp message already in progress");
|
2017-03-03 10:56:08 +00:00
|
|
|
}
|
2015-12-02 15:43:55 +00:00
|
|
|
if (conversation.getMode() == Conversation.MODE_SINGLE) {
|
|
|
|
if (contact.getPgpKeyId() != 0) {
|
|
|
|
xmppService.getPgpEngine().hasKey(contact,
|
|
|
|
new UiCallback<Contact>() {
|
|
|
|
|
|
|
|
@Override
|
2018-02-21 22:07:53 +00:00
|
|
|
public void userInputRequried(PendingIntent pi, Contact contact) {
|
|
|
|
startPendingIntent(pi, REQUEST_ENCRYPT_MESSAGE);
|
2015-12-02 15:43:55 +00:00
|
|
|
}
|
2014-06-01 17:29:57 +00:00
|
|
|
|
2015-12-02 15:43:55 +00:00
|
|
|
@Override
|
|
|
|
public void success(Contact contact) {
|
2018-02-20 13:54:32 +00:00
|
|
|
encryptTextMessage(message);
|
2015-12-02 15:43:55 +00:00
|
|
|
}
|
2014-06-01 17:29:57 +00:00
|
|
|
|
2015-12-02 15:43:55 +00:00
|
|
|
@Override
|
|
|
|
public void error(int error, Contact contact) {
|
2018-02-20 13:54:32 +00:00
|
|
|
activity.runOnUiThread(() -> Toast.makeText(activity,
|
|
|
|
R.string.unable_to_connect_to_keychain,
|
|
|
|
Toast.LENGTH_SHORT
|
|
|
|
).show());
|
2017-03-03 10:56:08 +00:00
|
|
|
mSendingPgpMessage.set(false);
|
2015-12-02 15:43:55 +00:00
|
|
|
}
|
|
|
|
});
|
2014-06-01 17:29:57 +00:00
|
|
|
|
2014-03-03 15:39:19 +00:00
|
|
|
} else {
|
2018-02-20 13:54:32 +00:00
|
|
|
showNoPGPKeyDialog(false, (dialog, which) -> {
|
2018-02-21 22:07:53 +00:00
|
|
|
conversation.setNextEncryption(Message.ENCRYPTION_NONE);
|
|
|
|
xmppService.updateConversation(conversation);
|
|
|
|
message.setEncryption(Message.ENCRYPTION_NONE);
|
|
|
|
xmppService.sendMessage(message);
|
|
|
|
messageSent();
|
|
|
|
});
|
2014-03-03 15:39:19 +00:00
|
|
|
}
|
2014-06-09 19:25:01 +00:00
|
|
|
} else {
|
2015-12-02 15:43:55 +00:00
|
|
|
if (conversation.getMucOptions().pgpKeysInUse()) {
|
|
|
|
if (!conversation.getMucOptions().everybodyHasKeys()) {
|
|
|
|
Toast warning = Toast
|
|
|
|
.makeText(getActivity(),
|
|
|
|
R.string.missing_public_keys,
|
|
|
|
Toast.LENGTH_LONG);
|
|
|
|
warning.setGravity(Gravity.CENTER_VERTICAL, 0, 0);
|
|
|
|
warning.show();
|
|
|
|
}
|
2018-02-20 13:54:32 +00:00
|
|
|
encryptTextMessage(message);
|
2015-12-02 15:43:55 +00:00
|
|
|
} else {
|
2018-02-20 13:54:32 +00:00
|
|
|
showNoPGPKeyDialog(true, (dialog, which) -> {
|
2018-02-21 22:07:53 +00:00
|
|
|
conversation.setNextEncryption(Message.ENCRYPTION_NONE);
|
|
|
|
message.setEncryption(Message.ENCRYPTION_NONE);
|
|
|
|
xmppService.updateConversation(conversation);
|
|
|
|
xmppService.sendMessage(message);
|
|
|
|
messageSent();
|
|
|
|
});
|
2015-12-02 15:43:55 +00:00
|
|
|
}
|
2014-02-27 23:22:56 +00:00
|
|
|
}
|
|
|
|
}
|
2014-05-19 13:39:50 +00:00
|
|
|
|
2018-02-20 13:54:32 +00:00
|
|
|
public void encryptTextMessage(Message message) {
|
|
|
|
activity.xmppConnectionService.getPgpEngine().encrypt(message,
|
|
|
|
new UiCallback<Message>() {
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void userInputRequried(PendingIntent pi, Message message) {
|
2018-02-21 14:46:56 +00:00
|
|
|
startPendingIntent(pi, REQUEST_SEND_MESSAGE);
|
2018-02-20 13:54:32 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void success(Message message) {
|
|
|
|
message.setEncryption(Message.ENCRYPTION_DECRYPTED);
|
|
|
|
activity.xmppConnectionService.sendMessage(message);
|
|
|
|
getActivity().runOnUiThread(() -> messageSent());
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void error(final int error, Message message) {
|
|
|
|
getActivity().runOnUiThread(() -> {
|
|
|
|
doneSendingPgpMessage();
|
2018-02-21 22:07:53 +00:00
|
|
|
Toast.makeText(getActivity(), R.string.unable_to_connect_to_keychain, Toast.LENGTH_SHORT).show();
|
2018-02-20 13:54:32 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
public void showNoPGPKeyDialog(boolean plural, DialogInterface.OnClickListener listener) {
|
2014-05-19 13:39:50 +00:00
|
|
|
AlertDialog.Builder builder = new AlertDialog.Builder(getActivity());
|
2014-05-08 12:23:09 +00:00
|
|
|
builder.setIconAttribute(android.R.attr.alertDialogIcon);
|
2014-06-01 09:24:35 +00:00
|
|
|
if (plural) {
|
|
|
|
builder.setTitle(getString(R.string.no_pgp_keys));
|
|
|
|
builder.setMessage(getText(R.string.contacts_have_no_pgp_keys));
|
|
|
|
} else {
|
|
|
|
builder.setTitle(getString(R.string.no_pgp_key));
|
|
|
|
builder.setMessage(getText(R.string.contact_has_no_pgp_key));
|
|
|
|
}
|
2014-05-08 12:23:09 +00:00
|
|
|
builder.setNegativeButton(getString(R.string.cancel), null);
|
2018-02-20 13:54:32 +00:00
|
|
|
builder.setPositiveButton(getString(R.string.send_unencrypted), listener);
|
2014-05-08 12:23:09 +00:00
|
|
|
builder.create().show();
|
|
|
|
}
|
2014-03-13 02:52:41 +00:00
|
|
|
|
2015-06-25 15:01:42 +00:00
|
|
|
protected void sendAxolotlMessage(final Message message) {
|
2018-02-21 14:46:56 +00:00
|
|
|
activity.xmppConnectionService.sendMessage(message);
|
2015-06-25 15:01:42 +00:00
|
|
|
messageSent();
|
|
|
|
}
|
|
|
|
|
2014-11-07 14:38:20 +00:00
|
|
|
public void appendText(String text) {
|
2015-04-19 17:11:32 +00:00
|
|
|
if (text == null) {
|
|
|
|
return;
|
|
|
|
}
|
2018-02-21 10:04:48 +00:00
|
|
|
String previous = this.binding.textinput.getText().toString();
|
2014-11-07 14:38:20 +00:00
|
|
|
if (previous.length() != 0 && !previous.endsWith(" ")) {
|
|
|
|
text = " " + text;
|
|
|
|
}
|
2018-02-21 10:04:48 +00:00
|
|
|
this.binding.textinput.append(text);
|
2014-03-13 20:37:27 +00:00
|
|
|
}
|
2014-05-08 15:31:53 +00:00
|
|
|
|
2015-02-21 10:06:52 +00:00
|
|
|
@Override
|
2015-03-06 21:22:50 +00:00
|
|
|
public boolean onEnterPressed() {
|
2018-02-21 14:46:56 +00:00
|
|
|
SharedPreferences p = PreferenceManager.getDefaultSharedPreferences(getActivity());
|
|
|
|
final boolean enterIsSend = p.getBoolean("enter_is_send", getResources().getBoolean(R.bool.enter_is_send));
|
|
|
|
if (enterIsSend) {
|
2015-03-06 21:22:50 +00:00
|
|
|
sendMessage();
|
|
|
|
return true;
|
|
|
|
} else {
|
|
|
|
return false;
|
|
|
|
}
|
2015-02-21 10:06:52 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void onTypingStarted() {
|
|
|
|
Account.State status = conversation.getAccount().getStatus();
|
|
|
|
if (status == Account.State.ONLINE && conversation.setOutgoingChatState(ChatState.COMPOSING)) {
|
|
|
|
activity.xmppConnectionService.sendChatState(conversation);
|
|
|
|
}
|
2015-05-02 09:38:56 +00:00
|
|
|
updateSendButton();
|
2015-02-21 10:06:52 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void onTypingStopped() {
|
|
|
|
Account.State status = conversation.getAccount().getStatus();
|
|
|
|
if (status == Account.State.ONLINE && conversation.setOutgoingChatState(ChatState.PAUSED)) {
|
|
|
|
activity.xmppConnectionService.sendChatState(conversation);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void onTextDeleted() {
|
|
|
|
Account.State status = conversation.getAccount().getStatus();
|
|
|
|
if (status == Account.State.ONLINE && conversation.setOutgoingChatState(Config.DEFAULT_CHATSTATE)) {
|
|
|
|
activity.xmppConnectionService.sendChatState(conversation);
|
|
|
|
}
|
2015-05-02 09:38:56 +00:00
|
|
|
updateSendButton();
|
2015-02-21 10:06:52 +00:00
|
|
|
}
|
|
|
|
|
2016-02-15 22:15:04 +00:00
|
|
|
@Override
|
|
|
|
public void onTextChanged() {
|
|
|
|
if (conversation != null && conversation.getCorrectingMessage() != null) {
|
|
|
|
updateSendButton();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-09-27 17:17:44 +00:00
|
|
|
@Override
|
|
|
|
public boolean onTabPressed(boolean repeated) {
|
|
|
|
if (conversation == null || conversation.getMode() == Conversation.MODE_SINGLE) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
if (repeated) {
|
|
|
|
completionIndex++;
|
|
|
|
} else {
|
|
|
|
lastCompletionLength = 0;
|
|
|
|
completionIndex = 0;
|
2018-02-21 10:04:48 +00:00
|
|
|
final String content = this.binding.textinput.getText().toString();
|
|
|
|
lastCompletionCursor = this.binding.textinput.getSelectionEnd();
|
2017-11-22 16:57:28 +00:00
|
|
|
int start = lastCompletionCursor > 0 ? content.lastIndexOf(" ", lastCompletionCursor - 1) + 1 : 0;
|
2015-09-27 17:17:44 +00:00
|
|
|
firstWord = start == 0;
|
2017-11-22 16:57:28 +00:00
|
|
|
incomplete = content.substring(start, lastCompletionCursor);
|
2015-09-27 17:17:44 +00:00
|
|
|
}
|
|
|
|
List<String> completions = new ArrayList<>();
|
2017-11-22 16:57:28 +00:00
|
|
|
for (MucOptions.User user : conversation.getMucOptions().getUsers()) {
|
2016-07-08 11:24:14 +00:00
|
|
|
String name = user.getName();
|
|
|
|
if (name != null && name.startsWith(incomplete)) {
|
2017-11-22 16:57:28 +00:00
|
|
|
completions.add(name + (firstWord ? ": " : " "));
|
2015-09-27 17:17:44 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
Collections.sort(completions);
|
|
|
|
if (completions.size() > completionIndex) {
|
|
|
|
String completion = completions.get(completionIndex).substring(incomplete.length());
|
2018-02-21 10:04:48 +00:00
|
|
|
this.binding.textinput.getEditableText().delete(lastCompletionCursor, lastCompletionCursor + lastCompletionLength);
|
|
|
|
this.binding.textinput.getEditableText().insert(lastCompletionCursor, completion);
|
2015-09-27 17:17:44 +00:00
|
|
|
lastCompletionLength = completion.length();
|
|
|
|
} else {
|
|
|
|
completionIndex = -1;
|
2018-02-21 10:04:48 +00:00
|
|
|
this.binding.textinput.getEditableText().delete(lastCompletionCursor, lastCompletionCursor + lastCompletionLength);
|
2015-09-27 17:17:44 +00:00
|
|
|
lastCompletionLength = 0;
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2018-02-21 14:46:56 +00:00
|
|
|
private void startPendingIntent(PendingIntent pendingIntent, int requestCode) {
|
|
|
|
try {
|
2018-02-21 22:07:53 +00:00
|
|
|
getActivity().startIntentSenderForResult(pendingIntent.getIntentSender(), requestCode, null, 0, 0, 0);
|
2018-02-21 14:46:56 +00:00
|
|
|
} catch (final SendIntentException ignored) {
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2018-02-20 13:54:32 +00:00
|
|
|
public void onBackendConnected() {
|
2018-02-21 22:07:53 +00:00
|
|
|
Log.d(Config.LOGTAG, "ConversationFragment.onBackendConnected()");
|
|
|
|
String uuid = pendingConversationsUuid.pop();
|
|
|
|
if (uuid != null) {
|
|
|
|
Conversation conversation = activity.xmppConnectionService.findConversationByUuid(uuid);
|
|
|
|
if (conversation == null) {
|
|
|
|
Log.d(Config.LOGTAG, "unable to restore activity");
|
|
|
|
clearPending();
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
reInit(conversation);
|
|
|
|
}
|
|
|
|
ActivityResult activityResult = postponedActivityResult.pop();
|
|
|
|
if (activityResult != null) {
|
|
|
|
handleActivityResult(activityResult);
|
2015-07-19 16:36:28 +00:00
|
|
|
}
|
2018-02-21 22:07:53 +00:00
|
|
|
}
|
|
|
|
|
2018-02-20 13:54:32 +00:00
|
|
|
public void clearPending() {
|
2018-02-21 22:07:53 +00:00
|
|
|
if (postponedActivityResult.pop() != null) {
|
|
|
|
Log.d(Config.LOGTAG, "cleared pending intent with unhandled result left");
|
2018-02-20 13:54:32 +00:00
|
|
|
}
|
2018-02-21 22:07:53 +00:00
|
|
|
}
|
|
|
|
|
2018-02-22 18:49:39 +00:00
|
|
|
public static Conversation getConversation(Activity activity) {
|
|
|
|
Fragment fragment = activity.getFragmentManager().findFragmentById(R.id.secondary_fragment);
|
|
|
|
if (fragment != null && fragment instanceof ConversationFragment) {
|
|
|
|
return ((ConversationFragment) fragment).getConversation();
|
|
|
|
} else {
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-02-21 22:07:53 +00:00
|
|
|
public Conversation getConversation() {
|
|
|
|
return conversation;
|
2018-02-20 13:54:32 +00:00
|
|
|
}
|
2014-01-24 01:04:05 +00:00
|
|
|
}
|