2014-02-28 17:46:01 +00:00
|
|
|
package eu.siacs.conversations.ui;
|
2014-01-24 01:04:05 +00:00
|
|
|
|
2014-01-27 19:40:42 +00:00
|
|
|
import java.util.ArrayList;
|
|
|
|
import java.util.List;
|
2014-02-16 15:32:15 +00:00
|
|
|
import java.util.Set;
|
2014-10-15 00:09:20 +00:00
|
|
|
import java.util.concurrent.ConcurrentLinkedQueue;
|
2014-02-16 15:32:15 +00:00
|
|
|
|
|
|
|
import net.java.otr4j.session.SessionStatus;
|
2014-02-28 17:46:01 +00:00
|
|
|
import eu.siacs.conversations.R;
|
2014-05-01 20:33:49 +00:00
|
|
|
import eu.siacs.conversations.crypto.PgpEngine;
|
2014-07-18 17:36:29 +00:00
|
|
|
import eu.siacs.conversations.entities.Account;
|
2014-02-28 17:46:01 +00:00
|
|
|
import eu.siacs.conversations.entities.Contact;
|
|
|
|
import eu.siacs.conversations.entities.Conversation;
|
2014-10-23 19:27:41 +00:00
|
|
|
import eu.siacs.conversations.entities.Downloadable;
|
2014-02-28 17:46:01 +00:00
|
|
|
import eu.siacs.conversations.entities.Message;
|
2014-03-03 04:01:02 +00:00
|
|
|
import eu.siacs.conversations.entities.MucOptions;
|
2014-09-10 15:59:57 +00:00
|
|
|
import eu.siacs.conversations.entities.Presences;
|
2014-02-28 17:46:01 +00:00
|
|
|
import eu.siacs.conversations.services.XmppConnectionService;
|
2014-07-31 11:26:05 +00:00
|
|
|
import eu.siacs.conversations.ui.EditMessage.OnEnterPressed;
|
2014-07-16 22:03:37 +00:00
|
|
|
import eu.siacs.conversations.ui.XmppActivity.OnPresenceSelected;
|
2014-09-03 17:35:45 +00:00
|
|
|
import eu.siacs.conversations.ui.XmppActivity.OnValueEdited;
|
2014-07-22 13:31:54 +00:00
|
|
|
import eu.siacs.conversations.ui.adapter.MessageAdapter;
|
|
|
|
import eu.siacs.conversations.ui.adapter.MessageAdapter.OnContactPictureClicked;
|
2014-08-10 13:27:44 +00:00
|
|
|
import eu.siacs.conversations.ui.adapter.MessageAdapter.OnContactPictureLongClicked;
|
2014-02-28 17:46:01 +00:00
|
|
|
import eu.siacs.conversations.utils.UIHelper;
|
2014-02-16 15:32:15 +00:00
|
|
|
import android.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;
|
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;
|
|
|
|
import android.content.IntentSender.SendIntentException;
|
2014-01-24 01:04:05 +00:00
|
|
|
import android.os.Bundle;
|
2014-05-07 10:59:15 +00:00
|
|
|
import android.text.Editable;
|
|
|
|
import android.text.Selection;
|
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-07-31 11:26:05 +00:00
|
|
|
import android.view.KeyEvent;
|
2014-01-24 01:04:05 +00:00
|
|
|
import android.view.LayoutInflater;
|
2014-10-23 19:27:41 +00:00
|
|
|
import android.view.MenuItem;
|
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.OnScrollListener;
|
2014-07-31 11:26:05 +00:00
|
|
|
import android.widget.TextView.OnEditorActionListener;
|
2014-06-14 14:59:07 +00:00
|
|
|
import android.widget.AbsListView;
|
2014-07-22 13:31:54 +00:00
|
|
|
|
2014-10-23 19:27:41 +00:00
|
|
|
import android.widget.AdapterView;
|
|
|
|
import android.widget.AdapterView.AdapterContextMenuInfo;
|
2014-01-26 02:27:55 +00:00
|
|
|
import android.widget.ListView;
|
|
|
|
import android.widget.ImageButton;
|
2014-07-09 19:45:03 +00:00
|
|
|
import android.widget.RelativeLayout;
|
2014-01-26 02:27:55 +00:00
|
|
|
import android.widget.TextView;
|
2014-03-04 03:09:15 +00:00
|
|
|
import android.widget.Toast;
|
2014-01-24 01:04:05 +00:00
|
|
|
|
|
|
|
public class ConversationFragment extends Fragment {
|
2014-02-16 15:32:15 +00:00
|
|
|
|
2014-01-27 19:40:42 +00:00
|
|
|
protected Conversation conversation;
|
|
|
|
protected ListView messagesView;
|
|
|
|
protected LayoutInflater inflater;
|
|
|
|
protected List<Message> messageList = new ArrayList<Message>();
|
2014-07-22 13:31:54 +00:00
|
|
|
protected MessageAdapter messageListAdapter;
|
2014-02-10 02:34:00 +00:00
|
|
|
protected Contact contact;
|
2014-02-16 15:32:15 +00:00
|
|
|
|
2014-02-27 23:22:56 +00:00
|
|
|
protected String queuedPqpMessage = null;
|
|
|
|
|
2014-07-31 11:26:05 +00:00
|
|
|
private EditMessage mEditMessage;
|
2014-09-10 15:59:57 +00:00
|
|
|
private ImageButton mSendButton;
|
2014-03-13 20:37:27 +00:00
|
|
|
private String pastedText = null;
|
2014-07-09 19:45:03 +00:00
|
|
|
private RelativeLayout snackbar;
|
|
|
|
private TextView snackbarMessage;
|
|
|
|
private TextView snackbarAction;
|
2014-02-27 23:22:56 +00:00
|
|
|
|
2014-06-14 14:59:07 +00:00
|
|
|
private boolean messagesLoaded = false;
|
2014-03-13 02:52:41 +00:00
|
|
|
|
2014-02-27 23:22:56 +00:00
|
|
|
private IntentSender askForPassphraseIntent = null;
|
2014-10-15 17:32:12 +00:00
|
|
|
|
2014-10-15 00:09:20 +00:00
|
|
|
private ConcurrentLinkedQueue<Message> mEncryptedMessages = new ConcurrentLinkedQueue<Message>();
|
|
|
|
private boolean mDecryptJobRunning = false;
|
2014-08-25 13:43:50 +00:00
|
|
|
|
2014-07-31 11:26:05 +00:00
|
|
|
private OnEditorActionListener mEditorActionListener = new OnEditorActionListener() {
|
2014-08-25 13:43:50 +00:00
|
|
|
|
2014-07-31 11:26:05 +00:00
|
|
|
@Override
|
|
|
|
public boolean onEditorAction(TextView v, int actionId, KeyEvent event) {
|
2014-09-27 08:51:46 +00:00
|
|
|
if (actionId == EditorInfo.IME_ACTION_SEND) {
|
2014-08-25 13:43:50 +00:00
|
|
|
InputMethodManager imm = (InputMethodManager) v.getContext()
|
|
|
|
.getSystemService(Context.INPUT_METHOD_SERVICE);
|
|
|
|
imm.hideSoftInputFromWindow(v.getWindowToken(), 0);
|
2014-09-27 08:51:46 +00:00
|
|
|
sendMessage();
|
2014-08-25 13:43:50 +00:00
|
|
|
return true;
|
|
|
|
} else {
|
|
|
|
return false;
|
|
|
|
}
|
2014-07-31 11:26:05 +00:00
|
|
|
}
|
|
|
|
};
|
2014-02-16 15:32:15 +00:00
|
|
|
|
2014-07-31 11:26:05 +00:00
|
|
|
private OnClickListener mSendButtonListener = new OnClickListener() {
|
2014-02-16 15:32:15 +00:00
|
|
|
|
|
|
|
@Override
|
|
|
|
public void onClick(View v) {
|
2014-07-31 11:26:05 +00:00
|
|
|
sendMessage();
|
2014-02-16 15:32:15 +00:00
|
|
|
}
|
|
|
|
};
|
2014-02-27 23:22:56 +00:00
|
|
|
protected OnClickListener clickToDecryptListener = new OnClickListener() {
|
2014-03-13 02:52:41 +00:00
|
|
|
|
2014-02-27 23:22:56 +00:00
|
|
|
@Override
|
|
|
|
public void onClick(View v) {
|
2014-06-01 17:29:57 +00:00
|
|
|
if (activity.hasPgp() && askForPassphraseIntent != null) {
|
2014-02-27 23:22:56 +00:00
|
|
|
try {
|
2014-03-13 02:52:41 +00:00
|
|
|
getActivity().startIntentSenderForResult(
|
|
|
|
askForPassphraseIntent,
|
|
|
|
ConversationActivity.REQUEST_DECRYPT_PGP, null, 0,
|
|
|
|
0, 0);
|
2014-02-27 23:22:56 +00:00
|
|
|
} catch (SendIntentException e) {
|
2014-06-23 21:29:26 +00:00
|
|
|
//
|
2014-02-27 23:22:56 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
};
|
2014-07-18 17:36:29 +00:00
|
|
|
|
2014-03-03 04:01:02 +00:00
|
|
|
private OnClickListener clickToMuc = new OnClickListener() {
|
2014-03-13 02:52:41 +00:00
|
|
|
|
2014-03-03 04:01:02 +00:00
|
|
|
@Override
|
|
|
|
public void onClick(View v) {
|
2014-07-18 17:36:29 +00:00
|
|
|
Intent intent = new Intent(getActivity(),
|
|
|
|
ConferenceDetailsActivity.class);
|
2014-07-16 22:03:37 +00:00
|
|
|
intent.setAction(ConferenceDetailsActivity.ACTION_VIEW_MUC);
|
2014-03-04 01:51:01 +00:00
|
|
|
intent.putExtra("uuid", conversation.getUuid());
|
|
|
|
startActivity(intent);
|
2014-03-03 04:01:02 +00:00
|
|
|
}
|
|
|
|
};
|
2014-07-18 17:36:29 +00:00
|
|
|
|
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) {
|
|
|
|
activity.endConversation(conversation);
|
|
|
|
}
|
|
|
|
};
|
2014-10-07 13:18:09 +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-06-14 14:59:07 +00:00
|
|
|
|
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 = "";
|
|
|
|
}
|
2014-09-04 09:46:13 +00:00
|
|
|
activity.quickPasswordEdit(password, new OnValueEdited() {
|
2014-09-08 18:29:57 +00:00
|
|
|
|
2014-09-03 17:35:45 +00:00
|
|
|
@Override
|
|
|
|
public void onValueEdited(String value) {
|
2014-09-08 18:29:57 +00:00
|
|
|
activity.xmppConnectionService.providePasswordForMuc(
|
|
|
|
conversation, value);
|
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
|
|
|
|
public void onScroll(AbsListView view, int firstVisibleItem,
|
|
|
|
int visibleItemCount, int totalItemCount) {
|
|
|
|
if (firstVisibleItem == 0 && messagesLoaded) {
|
|
|
|
long timestamp = messageList.get(0).getTimeSent();
|
|
|
|
messagesLoaded = false;
|
2014-09-19 19:09:54 +00:00
|
|
|
int size = activity.xmppConnectionService.loadMoreMessages(
|
|
|
|
conversation, timestamp);
|
|
|
|
messageList.clear();
|
|
|
|
messageList.addAll(conversation.getMessages());
|
2014-10-04 12:32:51 +00:00
|
|
|
updateStatusMessages();
|
2014-06-14 14:59:07 +00:00
|
|
|
messageListAdapter.notifyDataSetChanged();
|
2014-09-19 19:09:54 +00:00
|
|
|
if (size != 0) {
|
2014-06-14 14:59:07 +00:00
|
|
|
messagesLoaded = true;
|
|
|
|
}
|
2014-09-19 19:09:54 +00:00
|
|
|
messagesView.setSelectionFromTop(size + 1, 0);
|
2014-06-14 14:59:07 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2014-03-28 11:22:09 +00:00
|
|
|
private ConversationActivity activity;
|
2014-10-23 19:27:41 +00:00
|
|
|
private Message selectedMessage;
|
2014-08-25 13:43:50 +00:00
|
|
|
|
2014-07-31 11:26:05 +00:00
|
|
|
private void sendMessage() {
|
2014-09-08 18:29:57 +00:00
|
|
|
if (this.conversation == null) {
|
2014-09-06 22:09:12 +00:00
|
|
|
return;
|
|
|
|
}
|
2014-08-10 13:27:44 +00:00
|
|
|
if (mEditMessage.getText().length() < 1) {
|
|
|
|
if (this.conversation.getMode() == Conversation.MODE_MULTI) {
|
|
|
|
conversation.setNextPresence(null);
|
|
|
|
updateChatMsgHint();
|
|
|
|
}
|
2014-07-31 11:26:05 +00:00
|
|
|
return;
|
2014-08-10 13:27:44 +00:00
|
|
|
}
|
2014-07-31 11:26:05 +00:00
|
|
|
Message message = new Message(conversation, mEditMessage.getText()
|
2014-09-08 18:29:57 +00:00
|
|
|
.toString(), conversation.getNextEncryption(activity
|
|
|
|
.forceEncryption()));
|
2014-08-10 13:27:44 +00:00
|
|
|
if (conversation.getMode() == Conversation.MODE_MULTI) {
|
|
|
|
if (conversation.getNextPresence() != null) {
|
|
|
|
message.setPresence(conversation.getNextPresence());
|
|
|
|
message.setType(Message.TYPE_PRIVATE);
|
|
|
|
conversation.setNextPresence(null);
|
|
|
|
}
|
|
|
|
}
|
2014-09-08 11:37:22 +00:00
|
|
|
if (conversation.getNextEncryption(activity.forceEncryption()) == Message.ENCRYPTION_OTR) {
|
2014-07-31 11:26:05 +00:00
|
|
|
sendOtrMessage(message);
|
2014-09-08 11:37:22 +00:00
|
|
|
} else if (conversation.getNextEncryption(activity.forceEncryption()) == Message.ENCRYPTION_PGP) {
|
2014-07-31 11:26:05 +00:00
|
|
|
sendPgpMessage(message);
|
|
|
|
} else {
|
|
|
|
sendPlainTextMessage(message);
|
|
|
|
}
|
|
|
|
}
|
2014-03-13 02:52:41 +00:00
|
|
|
|
2014-02-16 15:32:15 +00:00
|
|
|
public void updateChatMsgHint() {
|
2014-08-25 13:43:50 +00:00
|
|
|
if (conversation.getMode() == Conversation.MODE_MULTI
|
|
|
|
&& conversation.getNextPresence() != null) {
|
|
|
|
this.mEditMessage.setHint(getString(
|
|
|
|
R.string.send_private_message_to,
|
|
|
|
conversation.getNextPresence()));
|
2014-08-22 11:22:07 +00:00
|
|
|
} else {
|
2014-09-08 11:37:22 +00:00
|
|
|
switch (conversation.getNextEncryption(activity.forceEncryption())) {
|
2014-08-22 11:22:07 +00:00
|
|
|
case Message.ENCRYPTION_NONE:
|
2014-08-25 13:43:50 +00:00
|
|
|
mEditMessage
|
|
|
|
.setHint(getString(R.string.send_plain_text_message));
|
2014-08-22 11:22:07 +00:00
|
|
|
break;
|
|
|
|
case Message.ENCRYPTION_OTR:
|
|
|
|
mEditMessage.setHint(getString(R.string.send_otr_message));
|
|
|
|
break;
|
|
|
|
case Message.ENCRYPTION_PGP:
|
|
|
|
mEditMessage.setHint(getString(R.string.send_pgp_message));
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
2014-02-16 15:32:15 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-01-27 19:40:42 +00:00
|
|
|
@Override
|
|
|
|
public View onCreateView(final LayoutInflater inflater,
|
|
|
|
ViewGroup container, Bundle savedInstanceState) {
|
|
|
|
final View view = inflater.inflate(R.layout.fragment_conversation,
|
|
|
|
container, false);
|
2014-07-31 11:26:05 +00:00
|
|
|
mEditMessage = (EditMessage) view.findViewById(R.id.textinput);
|
|
|
|
mEditMessage.setOnClickListener(new OnClickListener() {
|
2014-07-18 17:36:29 +00:00
|
|
|
|
2014-07-15 18:41:32 +00:00
|
|
|
@Override
|
|
|
|
public void onClick(View v) {
|
2014-10-03 13:00:29 +00:00
|
|
|
activity.hideConversationsOverview();
|
2014-07-15 18:41:32 +00:00
|
|
|
}
|
|
|
|
});
|
2014-07-31 11:26:05 +00:00
|
|
|
mEditMessage.setOnEditorActionListener(mEditorActionListener);
|
|
|
|
mEditMessage.setOnEnterPressedListener(new OnEnterPressed() {
|
2014-08-25 13:43:50 +00:00
|
|
|
|
2014-07-31 11:26:05 +00:00
|
|
|
@Override
|
|
|
|
public void onEnterPressed() {
|
|
|
|
sendMessage();
|
|
|
|
}
|
|
|
|
});
|
2014-08-25 13:43:50 +00:00
|
|
|
|
2014-09-10 15:59:57 +00:00
|
|
|
mSendButton = (ImageButton) view.findViewById(R.id.textSendButton);
|
|
|
|
mSendButton.setOnClickListener(this.mSendButtonListener);
|
2014-03-13 02:52:41 +00:00
|
|
|
|
2014-07-09 19:45:03 +00:00
|
|
|
snackbar = (RelativeLayout) view.findViewById(R.id.snackbar);
|
|
|
|
snackbarMessage = (TextView) view.findViewById(R.id.snackbar_message);
|
|
|
|
snackbarAction = (TextView) view.findViewById(R.id.snackbar_action);
|
2014-03-13 02:52:41 +00:00
|
|
|
|
2014-02-27 23:22:56 +00:00
|
|
|
messagesView = (ListView) view.findViewById(R.id.messages_view);
|
2014-06-14 14:59:07 +00:00
|
|
|
messagesView.setOnScrollListener(mOnScrollListener);
|
2014-06-10 15:01:19 +00:00
|
|
|
messagesView.setTranscriptMode(ListView.TRANSCRIPT_MODE_NORMAL);
|
2014-08-25 13:43:50 +00:00
|
|
|
messageListAdapter = new MessageAdapter(
|
|
|
|
(ConversationActivity) getActivity(), this.messageList);
|
|
|
|
messageListAdapter
|
|
|
|
.setOnContactPictureClicked(new OnContactPictureClicked() {
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void onContactPictureClicked(Message message) {
|
2014-09-20 14:02:49 +00:00
|
|
|
if (message.getStatus() <= Message.STATUS_RECEIVED) {
|
|
|
|
if (message.getConversation().getMode() == Conversation.MODE_MULTI) {
|
|
|
|
if (message.getPresence() != null) {
|
|
|
|
highlightInConference(message.getPresence());
|
|
|
|
} else {
|
|
|
|
highlightInConference(message
|
|
|
|
.getCounterpart());
|
|
|
|
}
|
2014-08-25 13:43:50 +00:00
|
|
|
} else {
|
2014-09-20 14:02:49 +00:00
|
|
|
Contact contact = message.getConversation()
|
|
|
|
.getContact();
|
|
|
|
if (contact.showInRoster()) {
|
|
|
|
activity.switchToContactDetails(contact);
|
|
|
|
} else {
|
|
|
|
activity.showAddToRosterDialog(message
|
|
|
|
.getConversation());
|
|
|
|
}
|
2014-08-25 13:43:50 +00:00
|
|
|
}
|
|
|
|
}
|
2014-08-10 13:27:44 +00:00
|
|
|
}
|
2014-08-25 13:43:50 +00:00
|
|
|
});
|
|
|
|
messageListAdapter
|
|
|
|
.setOnContactPictureLongClicked(new OnContactPictureLongClicked() {
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void onContactPictureLongClicked(Message message) {
|
2014-09-20 14:02:49 +00:00
|
|
|
if (message.getStatus() <= Message.STATUS_RECEIVED) {
|
|
|
|
if (message.getConversation().getMode() == Conversation.MODE_MULTI) {
|
|
|
|
if (message.getPresence() != null) {
|
|
|
|
privateMessageWith(message.getPresence());
|
|
|
|
} else {
|
|
|
|
privateMessageWith(message.getCounterpart());
|
|
|
|
}
|
2014-08-25 13:43:50 +00:00
|
|
|
}
|
|
|
|
}
|
2014-08-10 13:27:44 +00:00
|
|
|
}
|
2014-08-25 13:43:50 +00:00
|
|
|
});
|
2014-02-02 15:33:34 +00:00
|
|
|
messagesView.setAdapter(messageListAdapter);
|
2014-01-26 02:27:55 +00:00
|
|
|
|
2014-10-23 19:27:41 +00:00
|
|
|
registerForContextMenu(messagesView);
|
|
|
|
|
2014-01-26 02:27:55 +00:00
|
|
|
return view;
|
|
|
|
}
|
2014-08-25 13:43:50 +00:00
|
|
|
|
2014-10-23 19:27:41 +00:00
|
|
|
@Override
|
|
|
|
public void onCreateContextMenu(ContextMenu menu, View v,
|
|
|
|
ContextMenuInfo menuInfo) {
|
|
|
|
super.onCreateContextMenu(menu, v, menuInfo);
|
|
|
|
AdapterView.AdapterContextMenuInfo acmi = (AdapterContextMenuInfo) menuInfo;
|
|
|
|
this.selectedMessage = this.messageList.get(acmi.position);
|
|
|
|
populateContextMenu(menu);
|
|
|
|
}
|
|
|
|
|
|
|
|
private void populateContextMenu(ContextMenu menu) {
|
|
|
|
if (this.selectedMessage.getType() != Message.TYPE_STATUS) {
|
|
|
|
activity.getMenuInflater().inflate(R.menu.message_context, menu);
|
|
|
|
menu.setHeaderTitle(R.string.message_options);
|
|
|
|
MenuItem copyText = menu.findItem(R.id.copy_text);
|
|
|
|
MenuItem shareImage = menu.findItem(R.id.share_image);
|
|
|
|
MenuItem sendAgain = menu.findItem(R.id.send_again);
|
|
|
|
MenuItem copyUrl = menu.findItem(R.id.copy_url);
|
2014-10-24 17:30:03 +00:00
|
|
|
MenuItem downloadImage = menu.findItem(R.id.download_image);
|
2014-10-23 19:27:41 +00:00
|
|
|
if (this.selectedMessage.getType() != Message.TYPE_TEXT
|
|
|
|
|| this.selectedMessage.getDownloadable() != null) {
|
|
|
|
copyText.setVisible(false);
|
|
|
|
}
|
|
|
|
if (this.selectedMessage.getType() != Message.TYPE_IMAGE
|
|
|
|
|| (this.selectedMessage.getDownloadable() != null && this.selectedMessage
|
|
|
|
.getDownloadable().getStatus() == Downloadable.STATUS_DELETED)) {
|
|
|
|
shareImage.setVisible(false);
|
|
|
|
}
|
|
|
|
if (this.selectedMessage.getStatus() != Message.STATUS_SEND_FAILED) {
|
|
|
|
sendAgain.setVisible(false);
|
|
|
|
}
|
|
|
|
if ((this.selectedMessage.getType() != Message.TYPE_IMAGE && this.selectedMessage
|
|
|
|
.getDownloadable() == null)
|
|
|
|
|| this.selectedMessage.getImageParams().url == null) {
|
|
|
|
copyUrl.setVisible(false);
|
|
|
|
}
|
2014-10-24 17:30:03 +00:00
|
|
|
|
|
|
|
if (this.selectedMessage.getType() != Message.TYPE_TEXT
|
|
|
|
|| this.selectedMessage.getDownloadable() != null
|
|
|
|
|| !this.selectedMessage.bodyContainsDownloadable()) {
|
|
|
|
downloadImage.setVisible(false);
|
|
|
|
}
|
2014-10-23 19:27:41 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public boolean onContextItemSelected(MenuItem item) {
|
|
|
|
switch (item.getItemId()) {
|
|
|
|
case R.id.share_image:
|
|
|
|
shareImage(selectedMessage);
|
|
|
|
return true;
|
|
|
|
case R.id.copy_text:
|
|
|
|
copyText(selectedMessage);
|
|
|
|
return true;
|
|
|
|
case R.id.send_again:
|
|
|
|
resendMessage(selectedMessage);
|
|
|
|
return true;
|
|
|
|
case R.id.copy_url:
|
|
|
|
copyUrl(selectedMessage);
|
|
|
|
return true;
|
2014-10-24 17:30:03 +00:00
|
|
|
case R.id.download_image:
|
|
|
|
downloadImage(selectedMessage);
|
2014-10-26 17:30:58 +00:00
|
|
|
return true;
|
2014-10-23 19:27:41 +00:00
|
|
|
default:
|
|
|
|
return super.onContextItemSelected(item);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
private void shareImage(Message message) {
|
|
|
|
Intent shareIntent = new Intent();
|
|
|
|
shareIntent.setAction(Intent.ACTION_SEND);
|
|
|
|
shareIntent.putExtra(Intent.EXTRA_STREAM,
|
|
|
|
activity.xmppConnectionService.getFileBackend()
|
|
|
|
.getJingleFileUri(message));
|
|
|
|
shareIntent.setFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION);
|
|
|
|
shareIntent.setType("image/webp");
|
|
|
|
activity.startActivity(Intent.createChooser(shareIntent,
|
|
|
|
getText(R.string.share_with)));
|
|
|
|
}
|
|
|
|
|
|
|
|
private void copyText(Message message) {
|
|
|
|
if (activity.copyTextToClipboard(message.getMergedBody(),
|
|
|
|
R.string.message_text)) {
|
|
|
|
Toast.makeText(activity, R.string.message_copied_to_clipboard,
|
|
|
|
Toast.LENGTH_SHORT).show();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
private void resendMessage(Message message) {
|
|
|
|
activity.xmppConnectionService.resendFailedMessages(message);
|
|
|
|
}
|
|
|
|
|
|
|
|
private void copyUrl(Message message) {
|
|
|
|
if (activity.copyTextToClipboard(
|
|
|
|
message.getImageParams().url.toString(), R.string.image_url)) {
|
|
|
|
Toast.makeText(activity, R.string.url_copied_to_clipboard,
|
|
|
|
Toast.LENGTH_SHORT).show();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-10-24 17:30:03 +00:00
|
|
|
private void downloadImage(Message message) {
|
|
|
|
activity.xmppConnectionService.getHttpConnectionManager()
|
|
|
|
.createNewConnection(message);
|
|
|
|
}
|
|
|
|
|
2014-08-10 13:27:44 +00:00
|
|
|
protected void privateMessageWith(String counterpart) {
|
|
|
|
this.mEditMessage.setText("");
|
|
|
|
this.conversation.setNextPresence(counterpart);
|
2014-08-22 11:22:07 +00:00
|
|
|
updateChatMsgHint();
|
2014-08-10 13:27:44 +00:00
|
|
|
}
|
2014-01-24 22:58:51 +00:00
|
|
|
|
2014-05-20 09:44:43 +00:00
|
|
|
protected void highlightInConference(String nick) {
|
2014-07-31 11:26:05 +00:00
|
|
|
String oldString = mEditMessage.getText().toString().trim();
|
2014-08-31 15:24:52 +00:00
|
|
|
if (oldString.isEmpty() || mEditMessage.getSelectionStart() == 0) {
|
|
|
|
mEditMessage.getText().insert(0, nick + ": ");
|
2014-05-20 09:44:43 +00:00
|
|
|
} else {
|
2014-09-03 17:35:45 +00:00
|
|
|
if (mEditMessage.getText().charAt(
|
|
|
|
mEditMessage.getSelectionStart() - 1) != ' ') {
|
|
|
|
nick = " " + nick;
|
2014-08-31 15:48:00 +00:00
|
|
|
}
|
2014-09-03 17:35:45 +00:00
|
|
|
mEditMessage.getText().insert(mEditMessage.getSelectionStart(),
|
|
|
|
nick + " ");
|
2014-05-20 09:44:43 +00:00
|
|
|
}
|
|
|
|
}
|
2014-06-01 17:29:57 +00:00
|
|
|
|
2014-01-27 19:40:42 +00:00
|
|
|
@Override
|
|
|
|
public void onStart() {
|
|
|
|
super.onStart();
|
2014-03-28 11:22:09 +00:00
|
|
|
this.activity = (ConversationActivity) getActivity();
|
2014-01-27 19:40:42 +00:00
|
|
|
if (activity.xmppConnectionServiceBound) {
|
2014-02-20 16:00:50 +00:00
|
|
|
this.onBackendConnected();
|
2014-01-27 19:40:42 +00:00
|
|
|
}
|
|
|
|
}
|
2014-02-16 15:32:15 +00:00
|
|
|
|
2014-05-07 10:59:15 +00:00
|
|
|
@Override
|
|
|
|
public void onStop() {
|
2014-10-15 00:09:20 +00:00
|
|
|
mDecryptJobRunning = false;
|
2014-05-07 10:59:15 +00:00
|
|
|
super.onStop();
|
2014-05-19 13:39:50 +00:00
|
|
|
if (this.conversation != null) {
|
2014-07-31 11:26:05 +00:00
|
|
|
this.conversation.setNextMessage(mEditMessage.getText().toString());
|
2014-05-09 18:46:43 +00:00
|
|
|
}
|
2014-05-07 10:59:15 +00:00
|
|
|
}
|
|
|
|
|
2014-01-27 19:40:42 +00:00
|
|
|
public void onBackendConnected() {
|
2014-08-10 12:04:59 +00:00
|
|
|
this.activity = (ConversationActivity) getActivity();
|
2014-02-07 01:57:36 +00:00
|
|
|
this.conversation = activity.getSelectedConversation();
|
2014-03-13 02:52:41 +00:00
|
|
|
if (this.conversation == null) {
|
2014-03-10 18:22:13 +00:00
|
|
|
return;
|
|
|
|
}
|
2014-05-21 14:43:19 +00:00
|
|
|
String oldString = conversation.getNextMessage().trim();
|
2014-05-07 10:59:15 +00:00
|
|
|
if (this.pastedText == null) {
|
2014-07-31 11:26:05 +00:00
|
|
|
this.mEditMessage.setText(oldString);
|
2014-05-07 10:59:15 +00:00
|
|
|
} else {
|
2014-06-01 17:29:57 +00:00
|
|
|
|
2014-05-21 14:43:19 +00:00
|
|
|
if (oldString.isEmpty()) {
|
2014-07-31 11:26:05 +00:00
|
|
|
mEditMessage.setText(pastedText);
|
2014-05-21 14:43:19 +00:00
|
|
|
} else {
|
2014-07-31 11:26:05 +00:00
|
|
|
mEditMessage.setText(oldString + " " + pastedText);
|
2014-05-21 14:43:19 +00:00
|
|
|
}
|
2014-05-07 10:59:15 +00:00
|
|
|
pastedText = null;
|
|
|
|
}
|
2014-07-31 11:26:05 +00:00
|
|
|
int position = mEditMessage.length();
|
|
|
|
Editable etext = mEditMessage.getText();
|
2014-05-07 10:59:15 +00:00
|
|
|
Selection.setSelection(etext, position);
|
2014-10-03 13:00:29 +00:00
|
|
|
if (activity.isConversationsOverviewHideable()) {
|
2014-03-07 17:13:19 +00:00
|
|
|
if (!activity.shouldPaneBeOpen()) {
|
2014-10-03 13:00:29 +00:00
|
|
|
activity.hideConversationsOverview();
|
2014-09-29 16:28:13 +00:00
|
|
|
activity.openConversation(conversation);
|
2014-02-10 21:45:59 +00:00
|
|
|
}
|
2014-01-28 18:21:54 +00:00
|
|
|
}
|
2014-08-10 13:27:44 +00:00
|
|
|
if (this.conversation.getMode() == Conversation.MODE_MULTI) {
|
|
|
|
conversation.setNextPresence(null);
|
|
|
|
}
|
2014-08-22 11:22:07 +00:00
|
|
|
updateMessages();
|
2014-01-24 22:58:51 +00:00
|
|
|
}
|
2014-05-07 10:59:15 +00:00
|
|
|
|
2014-02-02 15:33:34 +00:00
|
|
|
public void updateMessages() {
|
2014-05-19 13:39:50 +00:00
|
|
|
if (getView() == null) {
|
2014-05-10 09:03:32 +00:00
|
|
|
return;
|
|
|
|
}
|
2014-07-18 10:44:33 +00:00
|
|
|
hideSnackbar();
|
2014-07-21 14:16:09 +00:00
|
|
|
final ConversationActivity activity = (ConversationActivity) getActivity();
|
2014-03-21 21:14:52 +00:00
|
|
|
if (this.conversation != null) {
|
2014-07-21 14:16:09 +00:00
|
|
|
final Contact contact = this.conversation.getContact();
|
2014-09-03 16:58:46 +00:00
|
|
|
if (this.conversation.isMuted()) {
|
2014-09-03 17:35:45 +00:00
|
|
|
showSnackbar(R.string.notifications_disabled, R.string.enable,
|
|
|
|
new OnClickListener() {
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void onClick(View v) {
|
|
|
|
conversation.setMutedTill(0);
|
2014-10-07 13:18:09 +00:00
|
|
|
activity.xmppConnectionService.databaseBackend
|
|
|
|
.updateConversation(conversation);
|
2014-09-03 17:35:45 +00:00
|
|
|
updateMessages();
|
|
|
|
}
|
|
|
|
});
|
2014-09-03 16:58:46 +00:00
|
|
|
} else if (!contact.showInRoster()
|
2014-08-25 13:43:50 +00:00
|
|
|
&& contact
|
|
|
|
.getOption(Contact.Options.PENDING_SUBSCRIPTION_REQUEST)) {
|
|
|
|
showSnackbar(R.string.contact_added_you, R.string.add_back,
|
|
|
|
new OnClickListener() {
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void onClick(View v) {
|
|
|
|
activity.xmppConnectionService
|
|
|
|
.createContact(contact);
|
|
|
|
activity.switchToContactDetails(contact);
|
|
|
|
}
|
|
|
|
});
|
2014-07-21 14:16:09 +00:00
|
|
|
}
|
2014-03-21 21:14:52 +00:00
|
|
|
for (Message message : this.conversation.getMessages()) {
|
2014-10-22 17:05:15 +00:00
|
|
|
if (message.getEncryption() == Message.ENCRYPTION_PGP
|
|
|
|
&& (message.getStatus() == Message.STATUS_RECEIVED || message
|
2014-10-23 19:27:41 +00:00
|
|
|
.getStatus() >= Message.STATUS_SEND)
|
|
|
|
&& message.getDownloadable() == null) {
|
2014-10-15 00:09:20 +00:00
|
|
|
if (!mEncryptedMessages.contains(message)) {
|
|
|
|
mEncryptedMessages.add(message);
|
|
|
|
}
|
2014-03-03 04:01:02 +00:00
|
|
|
}
|
|
|
|
}
|
2014-10-15 00:09:20 +00:00
|
|
|
decryptNext();
|
2014-09-08 18:29:57 +00:00
|
|
|
this.messageList.clear();
|
2014-06-14 08:29:26 +00:00
|
|
|
if (this.conversation.getMessages().size() == 0) {
|
2014-06-14 14:59:07 +00:00
|
|
|
messagesLoaded = false;
|
2014-06-14 08:29:26 +00:00
|
|
|
} else {
|
2014-09-08 18:29:57 +00:00
|
|
|
this.messageList.addAll(this.conversation.getMessages());
|
2014-06-14 14:59:07 +00:00
|
|
|
messagesLoaded = true;
|
2014-06-14 08:29:26 +00:00
|
|
|
updateStatusMessages();
|
2014-06-10 15:01:19 +00:00
|
|
|
}
|
2014-03-21 21:14:52 +00:00
|
|
|
this.messageListAdapter.notifyDataSetChanged();
|
|
|
|
if (conversation.getMode() == Conversation.MODE_SINGLE) {
|
|
|
|
if (messageList.size() >= 1) {
|
2014-10-28 16:15:13 +00:00
|
|
|
makeFingerprintWarning();
|
2014-03-03 04:01:02 +00:00
|
|
|
}
|
2014-02-27 23:22:56 +00:00
|
|
|
} else {
|
2014-07-18 17:36:29 +00:00
|
|
|
if (!conversation.getMucOptions().online()
|
|
|
|
&& conversation.getAccount().getStatus() == Account.STATUS_ONLINE) {
|
2014-09-03 17:35:45 +00:00
|
|
|
int error = conversation.getMucOptions().getError();
|
|
|
|
switch (error) {
|
|
|
|
case MucOptions.ERROR_NICK_IN_USE:
|
2014-07-18 17:36:29 +00:00
|
|
|
showSnackbar(R.string.nick_in_use, R.string.edit,
|
|
|
|
clickToMuc);
|
2014-09-03 17:35:45 +00:00
|
|
|
break;
|
|
|
|
case MucOptions.ERROR_ROOM_NOT_FOUND:
|
2014-07-18 17:36:29 +00:00
|
|
|
showSnackbar(R.string.conference_not_found,
|
|
|
|
R.string.leave, leaveMuc);
|
2014-09-07 10:43:01 +00:00
|
|
|
break;
|
2014-09-03 17:35:45 +00:00
|
|
|
case MucOptions.ERROR_PASSWORD_REQUIRED:
|
|
|
|
showSnackbar(R.string.conference_requires_password,
|
|
|
|
R.string.enter_password, enterPassword);
|
2014-09-07 10:43:01 +00:00
|
|
|
break;
|
2014-10-05 10:31:49 +00:00
|
|
|
case MucOptions.ERROR_BANNED:
|
|
|
|
showSnackbar(R.string.conference_banned,
|
|
|
|
R.string.leave, leaveMuc);
|
|
|
|
break;
|
|
|
|
case MucOptions.ERROR_MEMBERS_ONLY:
|
|
|
|
showSnackbar(R.string.conference_members_only,
|
|
|
|
R.string.leave, leaveMuc);
|
|
|
|
break;
|
|
|
|
case MucOptions.KICKED_FROM_ROOM:
|
2014-10-07 13:18:09 +00:00
|
|
|
showSnackbar(R.string.conference_kicked, R.string.join,
|
|
|
|
joinMuc);
|
2014-10-05 10:31:49 +00:00
|
|
|
break;
|
2014-09-03 17:35:45 +00:00
|
|
|
default:
|
|
|
|
break;
|
2014-03-21 21:14:52 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
getActivity().invalidateOptionsMenu();
|
|
|
|
updateChatMsgHint();
|
|
|
|
if (!activity.shouldPaneBeOpen()) {
|
2014-10-05 10:31:49 +00:00
|
|
|
activity.xmppConnectionService.markRead(conversation, true);
|
2014-03-21 21:14:52 +00:00
|
|
|
activity.updateConversationList();
|
2014-02-27 23:22:56 +00:00
|
|
|
}
|
2014-09-10 15:59:57 +00:00
|
|
|
this.updateSendButton();
|
2014-02-10 22:12:11 +00:00
|
|
|
}
|
2014-02-02 15:33:34 +00:00
|
|
|
}
|
2014-06-06 09:39:17 +00:00
|
|
|
|
2014-10-15 00:09:20 +00:00
|
|
|
private void decryptNext() {
|
|
|
|
Message next = this.mEncryptedMessages.peek();
|
|
|
|
PgpEngine engine = activity.xmppConnectionService.getPgpEngine();
|
2014-10-15 17:32:12 +00:00
|
|
|
|
|
|
|
if (next != null && engine != null && !mDecryptJobRunning) {
|
2014-10-15 00:09:20 +00:00
|
|
|
mDecryptJobRunning = true;
|
|
|
|
engine.decrypt(next, new UiCallback<Message>() {
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void userInputRequried(PendingIntent pi, Message message) {
|
|
|
|
mDecryptJobRunning = false;
|
|
|
|
askForPassphraseIntent = pi.getIntentSender();
|
|
|
|
showSnackbar(R.string.openpgp_messages_found,
|
|
|
|
R.string.decrypt, clickToDecryptListener);
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void success(Message message) {
|
|
|
|
mDecryptJobRunning = false;
|
|
|
|
mEncryptedMessages.remove();
|
|
|
|
activity.xmppConnectionService.updateMessage(message);
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void error(int error, Message message) {
|
|
|
|
message.setEncryption(Message.ENCRYPTION_DECRYPTION_FAILED);
|
|
|
|
mDecryptJobRunning = false;
|
|
|
|
mEncryptedMessages.remove();
|
|
|
|
activity.xmppConnectionService.updateConversationUi();
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|
2014-10-15 17:32:12 +00:00
|
|
|
|
2014-06-10 15:01:19 +00:00
|
|
|
private void messageSent() {
|
|
|
|
int size = this.messageList.size();
|
2014-10-06 20:03:01 +00:00
|
|
|
messagesView.setSelection(size - 1);
|
2014-07-31 11:26:05 +00:00
|
|
|
mEditMessage.setText("");
|
2014-08-10 13:27:44 +00:00
|
|
|
updateChatMsgHint();
|
2014-06-10 15:01:19 +00:00
|
|
|
}
|
2014-06-14 14:59:07 +00:00
|
|
|
|
2014-09-10 15:59:57 +00:00
|
|
|
public void updateSendButton() {
|
|
|
|
Conversation c = this.conversation;
|
|
|
|
if (activity.useSendButtonToIndicateStatus() && c != null
|
|
|
|
&& c.getAccount().getStatus() == Account.STATUS_ONLINE) {
|
|
|
|
if (c.getMode() == Conversation.MODE_SINGLE) {
|
|
|
|
switch (c.getContact().getMostAvailableStatus()) {
|
2014-09-11 11:19:46 +00:00
|
|
|
case Presences.CHAT:
|
|
|
|
this.mSendButton
|
|
|
|
.setImageResource(R.drawable.ic_action_send_now_online);
|
|
|
|
break;
|
2014-09-10 15:59:57 +00:00
|
|
|
case Presences.ONLINE:
|
|
|
|
this.mSendButton
|
|
|
|
.setImageResource(R.drawable.ic_action_send_now_online);
|
|
|
|
break;
|
|
|
|
case Presences.AWAY:
|
|
|
|
this.mSendButton
|
|
|
|
.setImageResource(R.drawable.ic_action_send_now_away);
|
|
|
|
break;
|
|
|
|
case Presences.XA:
|
|
|
|
this.mSendButton
|
|
|
|
.setImageResource(R.drawable.ic_action_send_now_away);
|
|
|
|
break;
|
|
|
|
case Presences.DND:
|
|
|
|
this.mSendButton
|
|
|
|
.setImageResource(R.drawable.ic_action_send_now_dnd);
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
this.mSendButton
|
|
|
|
.setImageResource(R.drawable.ic_action_send_now_offline);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
} else if (c.getMode() == Conversation.MODE_MULTI) {
|
|
|
|
if (c.getMucOptions().online()) {
|
|
|
|
this.mSendButton
|
|
|
|
.setImageResource(R.drawable.ic_action_send_now_online);
|
|
|
|
} else {
|
|
|
|
this.mSendButton
|
|
|
|
.setImageResource(R.drawable.ic_action_send_now_offline);
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
this.mSendButton
|
|
|
|
.setImageResource(R.drawable.ic_action_send_now_offline);
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
this.mSendButton
|
|
|
|
.setImageResource(R.drawable.ic_action_send_now_offline);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-06-04 19:40:17 +00:00
|
|
|
protected void updateStatusMessages() {
|
|
|
|
if (conversation.getMode() == Conversation.MODE_SINGLE) {
|
2014-06-06 09:39:17 +00:00
|
|
|
for (int i = this.messageList.size() - 1; i >= 0; --i) {
|
2014-09-08 18:29:57 +00:00
|
|
|
if (this.messageList.get(i).getStatus() == Message.STATUS_RECEIVED) {
|
|
|
|
return;
|
2014-06-04 19:40:17 +00:00
|
|
|
} else {
|
2014-09-08 18:29:57 +00:00
|
|
|
if (this.messageList.get(i).getStatus() == Message.STATUS_SEND_DISPLAYED) {
|
|
|
|
this.messageList.add(i + 1,
|
|
|
|
Message.createStatusMessage(conversation));
|
|
|
|
return;
|
2014-06-04 19:40:17 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2014-02-16 15:32:15 +00:00
|
|
|
|
2014-10-28 16:15:13 +00:00
|
|
|
protected void makeFingerprintWarning() {
|
2014-05-19 13:39:50 +00:00
|
|
|
Set<String> knownFingerprints = conversation.getContact()
|
|
|
|
.getOtrFingerprints();
|
2014-10-28 16:15:13 +00:00
|
|
|
if (conversation.hasValidOtrSession()
|
2014-09-03 17:35:45 +00:00
|
|
|
&& (!conversation.isMuted())
|
2014-05-19 13:39:50 +00:00
|
|
|
&& (conversation.getOtrSession().getSessionStatus() == SessionStatus.ENCRYPTED) && (!knownFingerprints
|
2014-10-28 16:15:13 +00:00
|
|
|
.contains(conversation.getOtrFingerprint()))) {
|
2014-07-18 17:36:29 +00:00
|
|
|
showSnackbar(R.string.unknown_otr_fingerprint, R.string.verify,
|
|
|
|
new OnClickListener() {
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void onClick(View v) {
|
|
|
|
if (conversation.getOtrFingerprint() != null) {
|
|
|
|
AlertDialog dialog = UIHelper
|
|
|
|
.getVerifyFingerprintDialog(
|
|
|
|
(ConversationActivity) getActivity(),
|
|
|
|
conversation, snackbar);
|
|
|
|
dialog.show();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|
2014-02-16 15:32:15 +00:00
|
|
|
}
|
|
|
|
}
|
2014-07-18 17:36:29 +00:00
|
|
|
|
|
|
|
protected void showSnackbar(int message, int action,
|
|
|
|
OnClickListener clickListener) {
|
2014-07-09 19:45:03 +00:00
|
|
|
snackbar.setVisibility(View.VISIBLE);
|
2014-08-12 21:23:25 +00:00
|
|
|
snackbar.setOnClickListener(null);
|
2014-07-09 19:45:03 +00:00
|
|
|
snackbarMessage.setText(message);
|
2014-08-12 21:23:25 +00:00
|
|
|
snackbarMessage.setOnClickListener(null);
|
2014-07-09 19:45:03 +00:00
|
|
|
snackbarAction.setText(action);
|
|
|
|
snackbarAction.setOnClickListener(clickListener);
|
|
|
|
}
|
2014-07-18 17:36:29 +00:00
|
|
|
|
2014-07-09 19:45:03 +00:00
|
|
|
protected void hideSnackbar() {
|
|
|
|
snackbar.setVisibility(View.GONE);
|
|
|
|
}
|
2014-02-16 18:30:22 +00:00
|
|
|
|
|
|
|
protected void sendPlainTextMessage(Message message) {
|
|
|
|
ConversationActivity activity = (ConversationActivity) getActivity();
|
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) {
|
2014-05-06 19:34:30 +00:00
|
|
|
final ConversationActivity activity = (ConversationActivity) getActivity();
|
2014-02-27 23:22:56 +00:00
|
|
|
final XmppConnectionService xmppService = activity.xmppConnectionService;
|
2014-05-01 20:33:49 +00:00
|
|
|
final Contact contact = message.getConversation().getContact();
|
2014-03-03 15:39:19 +00:00
|
|
|
if (activity.hasPgp()) {
|
2014-05-22 13:36:41 +00:00
|
|
|
if (conversation.getMode() == Conversation.MODE_SINGLE) {
|
|
|
|
if (contact.getPgpKeyId() != 0) {
|
2014-06-01 17:29:57 +00:00
|
|
|
xmppService.getPgpEngine().hasKey(contact,
|
2014-06-07 11:25:27 +00:00
|
|
|
new UiCallback<Contact>() {
|
2014-06-01 17:29:57 +00:00
|
|
|
|
|
|
|
@Override
|
2014-06-09 19:25:01 +00:00
|
|
|
public void userInputRequried(PendingIntent pi,
|
|
|
|
Contact contact) {
|
2014-06-01 17:29:57 +00:00
|
|
|
activity.runIntent(
|
|
|
|
pi,
|
|
|
|
ConversationActivity.REQUEST_ENCRYPT_MESSAGE);
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2014-06-07 11:25:27 +00:00
|
|
|
public void success(Contact contact) {
|
2014-06-10 15:01:19 +00:00
|
|
|
messageSent();
|
2014-06-07 11:25:27 +00:00
|
|
|
activity.encryptTextMessage(message);
|
2014-06-01 17:29:57 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2014-06-07 11:25:27 +00:00
|
|
|
public void error(int error, Contact contact) {
|
2014-06-01 17:29:57 +00:00
|
|
|
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
2014-05-22 13:36:41 +00:00
|
|
|
} else {
|
2014-06-01 17:29:57 +00:00
|
|
|
showNoPGPKeyDialog(false,
|
|
|
|
new DialogInterface.OnClickListener() {
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void onClick(DialogInterface dialog,
|
|
|
|
int which) {
|
|
|
|
conversation
|
|
|
|
.setNextEncryption(Message.ENCRYPTION_NONE);
|
2014-09-28 13:21:56 +00:00
|
|
|
xmppService.databaseBackend
|
|
|
|
.updateConversation(conversation);
|
2014-06-01 17:29:57 +00:00
|
|
|
message.setEncryption(Message.ENCRYPTION_NONE);
|
2014-06-11 19:53:25 +00:00
|
|
|
xmppService.sendMessage(message);
|
2014-06-10 15:01:19 +00:00
|
|
|
messageSent();
|
2014-06-01 17:29:57 +00:00
|
|
|
}
|
|
|
|
});
|
2014-05-22 13:36:41 +00:00
|
|
|
}
|
2014-03-03 15:39:19 +00:00
|
|
|
} else {
|
2014-06-01 09:24:35 +00:00
|
|
|
if (conversation.getMucOptions().pgpKeysInUse()) {
|
2014-06-01 16:52:27 +00:00
|
|
|
if (!conversation.getMucOptions().everybodyHasKeys()) {
|
2014-06-01 17:29:57 +00:00
|
|
|
Toast warning = Toast
|
|
|
|
.makeText(getActivity(),
|
|
|
|
R.string.missing_public_keys,
|
|
|
|
Toast.LENGTH_LONG);
|
2014-06-01 16:52:27 +00:00
|
|
|
warning.setGravity(Gravity.CENTER_VERTICAL, 0, 0);
|
|
|
|
warning.show();
|
|
|
|
}
|
2014-06-07 11:25:27 +00:00
|
|
|
activity.encryptTextMessage(message);
|
2014-06-16 21:43:45 +00:00
|
|
|
messageSent();
|
2014-06-01 09:24:35 +00:00
|
|
|
} else {
|
2014-06-01 17:29:57 +00:00
|
|
|
showNoPGPKeyDialog(true,
|
|
|
|
new DialogInterface.OnClickListener() {
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void onClick(DialogInterface dialog,
|
|
|
|
int which) {
|
|
|
|
conversation
|
|
|
|
.setNextEncryption(Message.ENCRYPTION_NONE);
|
|
|
|
message.setEncryption(Message.ENCRYPTION_NONE);
|
2014-09-28 13:21:56 +00:00
|
|
|
xmppService.databaseBackend
|
|
|
|
.updateConversation(conversation);
|
2014-06-11 19:53:25 +00:00
|
|
|
xmppService.sendMessage(message);
|
2014-06-10 15:01:19 +00:00
|
|
|
messageSent();
|
2014-06-01 17:29:57 +00:00
|
|
|
}
|
|
|
|
});
|
2014-06-01 09:24:35 +00:00
|
|
|
}
|
2014-03-03 15:39:19 +00:00
|
|
|
}
|
2014-06-09 19:25:01 +00:00
|
|
|
} else {
|
|
|
|
activity.showInstallPgpDialog();
|
2014-02-27 23:22:56 +00:00
|
|
|
}
|
|
|
|
}
|
2014-05-19 13:39:50 +00:00
|
|
|
|
2014-06-01 17:29:57 +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);
|
2014-05-19 13:39:50 +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
|
|
|
|
2014-02-16 18:30:22 +00:00
|
|
|
protected void sendOtrMessage(final Message message) {
|
2014-06-12 21:04:28 +00:00
|
|
|
final ConversationActivity activity = (ConversationActivity) getActivity();
|
2014-02-16 18:30:22 +00:00
|
|
|
final XmppConnectionService xmppService = activity.xmppConnectionService;
|
|
|
|
if (conversation.hasValidOtrSession()) {
|
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
|
|
|
} else {
|
2014-05-07 10:59:15 +00:00
|
|
|
activity.selectPresence(message.getConversation(),
|
|
|
|
new OnPresenceSelected() {
|
2014-02-19 00:35:23 +00:00
|
|
|
|
2014-05-07 10:59:15 +00:00
|
|
|
@Override
|
2014-06-16 12:21:22 +00:00
|
|
|
public void onPresenceSelected() {
|
|
|
|
message.setPresence(conversation.getNextPresence());
|
2014-06-11 19:53:25 +00:00
|
|
|
xmppService.sendMessage(message);
|
2014-06-10 15:01:19 +00:00
|
|
|
messageSent();
|
2014-05-07 10:59:15 +00:00
|
|
|
}
|
2014-06-12 21:04:28 +00:00
|
|
|
});
|
2014-02-16 18:30:22 +00:00
|
|
|
}
|
|
|
|
}
|
2014-02-19 00:35:23 +00:00
|
|
|
|
2014-03-13 20:37:27 +00:00
|
|
|
public void setText(String text) {
|
|
|
|
this.pastedText = text;
|
|
|
|
}
|
2014-05-08 15:31:53 +00:00
|
|
|
|
|
|
|
public void clearInputField() {
|
2014-07-31 11:26:05 +00:00
|
|
|
this.mEditMessage.setText("");
|
2014-05-08 15:31:53 +00:00
|
|
|
}
|
2014-01-24 01:04:05 +00:00
|
|
|
}
|