2014-02-28 12:46:01 -05:00
|
|
|
package eu.siacs.conversations.ui;
|
2014-01-23 20:04:05 -05:00
|
|
|
|
2014-01-27 14:40:42 -05:00
|
|
|
import java.util.ArrayList;
|
|
|
|
import java.util.List;
|
2014-02-16 10:32:15 -05:00
|
|
|
import java.util.Set;
|
|
|
|
|
|
|
|
import net.java.otr4j.session.SessionStatus;
|
2014-02-28 12:46:01 -05:00
|
|
|
import eu.siacs.conversations.R;
|
2014-05-01 16:33:49 -04:00
|
|
|
import eu.siacs.conversations.crypto.PgpEngine;
|
2014-07-18 13:36:29 -04:00
|
|
|
import eu.siacs.conversations.entities.Account;
|
2014-02-28 12:46:01 -05:00
|
|
|
import eu.siacs.conversations.entities.Contact;
|
|
|
|
import eu.siacs.conversations.entities.Conversation;
|
|
|
|
import eu.siacs.conversations.entities.Message;
|
2014-03-02 23:01:02 -05:00
|
|
|
import eu.siacs.conversations.entities.MucOptions;
|
2014-02-28 12:46:01 -05:00
|
|
|
import eu.siacs.conversations.services.XmppConnectionService;
|
2014-07-31 07:26:05 -04:00
|
|
|
import eu.siacs.conversations.ui.EditMessage.OnEnterPressed;
|
2014-07-16 18:03:37 -04:00
|
|
|
import eu.siacs.conversations.ui.XmppActivity.OnPresenceSelected;
|
2014-07-22 09:31:54 -04:00
|
|
|
import eu.siacs.conversations.ui.adapter.MessageAdapter;
|
|
|
|
import eu.siacs.conversations.ui.adapter.MessageAdapter.OnContactPictureClicked;
|
2014-02-28 12:46:01 -05:00
|
|
|
import eu.siacs.conversations.utils.UIHelper;
|
2014-02-16 10:32:15 -05:00
|
|
|
import android.app.AlertDialog;
|
2014-01-23 20:04:05 -05:00
|
|
|
import android.app.Fragment;
|
2014-05-01 16:33:49 -04:00
|
|
|
import android.app.PendingIntent;
|
2014-07-31 07:26:05 -04:00
|
|
|
import android.content.Context;
|
2014-02-16 10:32:15 -05:00
|
|
|
import android.content.DialogInterface;
|
2014-03-03 20:51:01 -05:00
|
|
|
import android.content.Intent;
|
2014-02-27 18:22:56 -05:00
|
|
|
import android.content.IntentSender;
|
2014-02-10 09:24:34 -05:00
|
|
|
import android.content.SharedPreferences;
|
2014-02-27 18:22:56 -05:00
|
|
|
import android.content.IntentSender.SendIntentException;
|
2014-01-23 20:04:05 -05:00
|
|
|
import android.os.Bundle;
|
2014-02-10 09:24:34 -05:00
|
|
|
import android.preference.PreferenceManager;
|
2014-05-07 06:59:15 -04:00
|
|
|
import android.text.Editable;
|
|
|
|
import android.text.Selection;
|
2014-06-01 12:52:27 -04:00
|
|
|
import android.view.Gravity;
|
2014-07-31 07:26:05 -04:00
|
|
|
import android.view.KeyEvent;
|
2014-01-23 20:04:05 -05:00
|
|
|
import android.view.LayoutInflater;
|
|
|
|
import android.view.View;
|
2014-01-25 21:27:55 -05:00
|
|
|
import android.view.View.OnClickListener;
|
2014-01-23 20:04:05 -05:00
|
|
|
import android.view.ViewGroup;
|
2014-07-31 07:26:05 -04:00
|
|
|
import android.view.inputmethod.EditorInfo;
|
|
|
|
import android.view.inputmethod.InputMethodManager;
|
2014-06-14 10:59:07 -04:00
|
|
|
import android.widget.AbsListView.OnScrollListener;
|
2014-07-31 07:26:05 -04:00
|
|
|
import android.widget.TextView.OnEditorActionListener;
|
2014-06-14 10:59:07 -04:00
|
|
|
import android.widget.AbsListView;
|
2014-07-22 09:31:54 -04:00
|
|
|
|
2014-01-25 21:27:55 -05:00
|
|
|
import android.widget.ListView;
|
|
|
|
import android.widget.ImageButton;
|
2014-07-09 15:45:03 -04:00
|
|
|
import android.widget.RelativeLayout;
|
2014-01-25 21:27:55 -05:00
|
|
|
import android.widget.TextView;
|
2014-03-03 22:09:15 -05:00
|
|
|
import android.widget.Toast;
|
2014-01-23 20:04:05 -05:00
|
|
|
|
|
|
|
public class ConversationFragment extends Fragment {
|
2014-02-16 10:32:15 -05:00
|
|
|
|
2014-01-27 14:40:42 -05:00
|
|
|
protected Conversation conversation;
|
|
|
|
protected ListView messagesView;
|
|
|
|
protected LayoutInflater inflater;
|
|
|
|
protected List<Message> messageList = new ArrayList<Message>();
|
2014-07-22 09:31:54 -04:00
|
|
|
protected MessageAdapter messageListAdapter;
|
2014-02-09 21:34:00 -05:00
|
|
|
protected Contact contact;
|
2014-02-16 10:32:15 -05:00
|
|
|
|
2014-02-27 18:22:56 -05:00
|
|
|
protected String queuedPqpMessage = null;
|
|
|
|
|
2014-07-31 07:26:05 -04:00
|
|
|
private EditMessage mEditMessage;
|
2014-03-13 16:37:27 -04:00
|
|
|
private String pastedText = null;
|
2014-07-09 15:45:03 -04:00
|
|
|
private RelativeLayout snackbar;
|
|
|
|
private TextView snackbarMessage;
|
|
|
|
private TextView snackbarAction;
|
2014-02-27 18:22:56 -05:00
|
|
|
|
2014-03-14 17:40:56 -04:00
|
|
|
private boolean useSubject = true;
|
2014-06-14 10:59:07 -04:00
|
|
|
private boolean messagesLoaded = false;
|
2014-03-12 22:52:41 -04:00
|
|
|
|
2014-02-27 18:22:56 -05:00
|
|
|
private IntentSender askForPassphraseIntent = null;
|
2014-07-31 07:26:05 -04:00
|
|
|
|
|
|
|
private OnEditorActionListener mEditorActionListener = new OnEditorActionListener() {
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public boolean onEditorAction(TextView v, int actionId, KeyEvent event) {
|
|
|
|
if (actionId == EditorInfo.IME_ACTION_DONE) {
|
|
|
|
InputMethodManager imm = (InputMethodManager) v.getContext()
|
|
|
|
.getSystemService(Context.INPUT_METHOD_SERVICE);
|
|
|
|
imm.hideSoftInputFromWindow(v.getWindowToken(), 0);
|
|
|
|
return true;
|
|
|
|
} else {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
};
|
2014-02-16 10:32:15 -05:00
|
|
|
|
2014-07-31 07:26:05 -04:00
|
|
|
private OnClickListener mSendButtonListener = new OnClickListener() {
|
2014-02-16 10:32:15 -05:00
|
|
|
|
|
|
|
@Override
|
|
|
|
public void onClick(View v) {
|
2014-07-31 07:26:05 -04:00
|
|
|
sendMessage();
|
2014-02-16 10:32:15 -05:00
|
|
|
}
|
|
|
|
};
|
2014-02-27 18:22:56 -05:00
|
|
|
protected OnClickListener clickToDecryptListener = new OnClickListener() {
|
2014-03-12 22:52:41 -04:00
|
|
|
|
2014-02-27 18:22:56 -05:00
|
|
|
@Override
|
|
|
|
public void onClick(View v) {
|
2014-06-01 13:29:57 -04:00
|
|
|
if (activity.hasPgp() && askForPassphraseIntent != null) {
|
2014-02-27 18:22:56 -05:00
|
|
|
try {
|
2014-03-12 22:52:41 -04:00
|
|
|
getActivity().startIntentSenderForResult(
|
|
|
|
askForPassphraseIntent,
|
|
|
|
ConversationActivity.REQUEST_DECRYPT_PGP, null, 0,
|
|
|
|
0, 0);
|
2014-02-27 18:22:56 -05:00
|
|
|
} catch (SendIntentException e) {
|
2014-06-23 17:29:26 -04:00
|
|
|
//
|
2014-02-27 18:22:56 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
};
|
2014-07-18 13:36:29 -04:00
|
|
|
|
2014-03-02 23:01:02 -05:00
|
|
|
private OnClickListener clickToMuc = new OnClickListener() {
|
2014-03-12 22:52:41 -04:00
|
|
|
|
2014-03-02 23:01:02 -05:00
|
|
|
@Override
|
|
|
|
public void onClick(View v) {
|
2014-07-18 13:36:29 -04:00
|
|
|
Intent intent = new Intent(getActivity(),
|
|
|
|
ConferenceDetailsActivity.class);
|
2014-07-16 18:03:37 -04:00
|
|
|
intent.setAction(ConferenceDetailsActivity.ACTION_VIEW_MUC);
|
2014-03-03 20:51:01 -05:00
|
|
|
intent.putExtra("uuid", conversation.getUuid());
|
|
|
|
startActivity(intent);
|
2014-03-02 23:01:02 -05:00
|
|
|
}
|
|
|
|
};
|
2014-07-18 13:36:29 -04:00
|
|
|
|
2014-07-18 06:44:33 -04:00
|
|
|
private OnClickListener leaveMuc = new OnClickListener() {
|
2014-07-18 13:36:29 -04:00
|
|
|
|
2014-07-18 06:44:33 -04:00
|
|
|
@Override
|
|
|
|
public void onClick(View v) {
|
|
|
|
activity.endConversation(conversation);
|
|
|
|
}
|
|
|
|
};
|
2014-06-14 10:59:07 -04: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;
|
|
|
|
List<Message> messages = activity.xmppConnectionService
|
|
|
|
.getMoreMessages(conversation, timestamp);
|
|
|
|
messageList.addAll(0, messages);
|
|
|
|
messageListAdapter.notifyDataSetChanged();
|
|
|
|
if (messages.size() != 0) {
|
|
|
|
messagesLoaded = true;
|
|
|
|
}
|
|
|
|
messagesView.setSelectionFromTop(messages.size() + 1, 0);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2014-03-28 07:22:09 -04:00
|
|
|
private ConversationActivity activity;
|
2014-07-31 07:26:05 -04:00
|
|
|
|
|
|
|
|
|
|
|
private void sendMessage() {
|
|
|
|
if (mEditMessage.getText().length() < 1)
|
|
|
|
return;
|
|
|
|
Message message = new Message(conversation, mEditMessage.getText()
|
|
|
|
.toString(), conversation.getNextEncryption());
|
|
|
|
if (conversation.getNextEncryption() == Message.ENCRYPTION_OTR) {
|
|
|
|
sendOtrMessage(message);
|
|
|
|
} else if (conversation.getNextEncryption() == Message.ENCRYPTION_PGP) {
|
|
|
|
sendPgpMessage(message);
|
|
|
|
} else {
|
|
|
|
sendPlainTextMessage(message);
|
|
|
|
}
|
|
|
|
}
|
2014-03-12 22:52:41 -04:00
|
|
|
|
2014-02-16 10:32:15 -05:00
|
|
|
public void updateChatMsgHint() {
|
2014-06-01 13:08:42 -04:00
|
|
|
switch (conversation.getNextEncryption()) {
|
|
|
|
case Message.ENCRYPTION_NONE:
|
2014-07-31 07:26:05 -04:00
|
|
|
mEditMessage.setHint(getString(R.string.send_plain_text_message));
|
2014-06-01 13:08:42 -04:00
|
|
|
break;
|
|
|
|
case Message.ENCRYPTION_OTR:
|
2014-07-31 07:26:05 -04:00
|
|
|
mEditMessage.setHint(getString(R.string.send_otr_message));
|
2014-06-01 13:08:42 -04:00
|
|
|
break;
|
|
|
|
case Message.ENCRYPTION_PGP:
|
2014-07-31 07:26:05 -04:00
|
|
|
mEditMessage.setHint(getString(R.string.send_pgp_message));
|
2014-06-01 13:08:42 -04:00
|
|
|
break;
|
|
|
|
default:
|
|
|
|
break;
|
2014-02-16 10:32:15 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-01-27 14:40:42 -05: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 07:26:05 -04:00
|
|
|
mEditMessage = (EditMessage) view.findViewById(R.id.textinput);
|
|
|
|
mEditMessage.setOnClickListener(new OnClickListener() {
|
2014-07-18 13:36:29 -04:00
|
|
|
|
2014-07-15 14:41:32 -04:00
|
|
|
@Override
|
|
|
|
public void onClick(View v) {
|
|
|
|
if (activity.getSlidingPaneLayout().isSlideable()) {
|
|
|
|
activity.getSlidingPaneLayout().closePane();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|
2014-07-31 07:26:05 -04:00
|
|
|
mEditMessage.setOnEditorActionListener(mEditorActionListener);
|
|
|
|
mEditMessage.setOnEnterPressedListener(new OnEnterPressed() {
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void onEnterPressed() {
|
|
|
|
sendMessage();
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
2014-02-16 10:32:15 -05:00
|
|
|
ImageButton sendButton = (ImageButton) view
|
|
|
|
.findViewById(R.id.textSendButton);
|
2014-07-31 07:26:05 -04:00
|
|
|
sendButton.setOnClickListener(this.mSendButtonListener);
|
2014-03-12 22:52:41 -04:00
|
|
|
|
2014-07-09 15:45:03 -04: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-12 22:52:41 -04:00
|
|
|
|
2014-02-27 18:22:56 -05:00
|
|
|
messagesView = (ListView) view.findViewById(R.id.messages_view);
|
2014-06-14 10:59:07 -04:00
|
|
|
messagesView.setOnScrollListener(mOnScrollListener);
|
2014-06-10 11:01:19 -04:00
|
|
|
messagesView.setTranscriptMode(ListView.TRANSCRIPT_MODE_NORMAL);
|
2014-07-22 09:31:54 -04:00
|
|
|
messageListAdapter = new MessageAdapter((ConversationActivity) getActivity(), this.messageList);
|
|
|
|
messageListAdapter.setOnContactPictureClicked(new OnContactPictureClicked() {
|
|
|
|
|
2014-01-27 14:40:42 -05:00
|
|
|
@Override
|
2014-07-22 09:31:54 -04:00
|
|
|
public void onContactPictureClicked(Message message) {
|
|
|
|
if (message.getConversation().getMode() == Conversation.MODE_MULTI) {
|
|
|
|
highlightInConference(message.getCounterpart());
|
2014-01-27 14:40:42 -05:00
|
|
|
}
|
|
|
|
}
|
2014-07-22 09:31:54 -04:00
|
|
|
});
|
2014-02-02 10:33:34 -05:00
|
|
|
messagesView.setAdapter(messageListAdapter);
|
2014-01-25 21:27:55 -05:00
|
|
|
|
|
|
|
return view;
|
|
|
|
}
|
2014-01-24 17:58:51 -05:00
|
|
|
|
2014-05-20 05:44:43 -04:00
|
|
|
protected void highlightInConference(String nick) {
|
2014-07-31 07:26:05 -04:00
|
|
|
String oldString = mEditMessage.getText().toString().trim();
|
2014-05-21 10:43:19 -04:00
|
|
|
if (oldString.isEmpty()) {
|
2014-07-31 07:26:05 -04:00
|
|
|
mEditMessage.setText(nick + ": ");
|
2014-05-20 05:44:43 -04:00
|
|
|
} else {
|
2014-07-31 07:26:05 -04:00
|
|
|
mEditMessage.setText(oldString + " " + nick + " ");
|
2014-05-20 05:44:43 -04:00
|
|
|
}
|
2014-07-31 07:26:05 -04:00
|
|
|
int position = mEditMessage.length();
|
|
|
|
Editable etext = mEditMessage.getText();
|
2014-05-20 05:44:43 -04:00
|
|
|
Selection.setSelection(etext, position);
|
|
|
|
}
|
2014-06-01 13:29:57 -04:00
|
|
|
|
2014-01-27 14:40:42 -05:00
|
|
|
@Override
|
|
|
|
public void onStart() {
|
|
|
|
super.onStart();
|
2014-03-28 07:22:09 -04:00
|
|
|
this.activity = (ConversationActivity) getActivity();
|
2014-05-07 06:59:15 -04:00
|
|
|
SharedPreferences preferences = PreferenceManager
|
|
|
|
.getDefaultSharedPreferences(activity);
|
2014-03-15 10:13:35 -04:00
|
|
|
this.useSubject = preferences.getBoolean("use_subject_in_muc", true);
|
2014-01-27 14:40:42 -05:00
|
|
|
if (activity.xmppConnectionServiceBound) {
|
2014-02-20 11:00:50 -05:00
|
|
|
this.onBackendConnected();
|
2014-01-27 14:40:42 -05:00
|
|
|
}
|
|
|
|
}
|
2014-02-16 10:32:15 -05:00
|
|
|
|
2014-05-07 06:59:15 -04:00
|
|
|
@Override
|
|
|
|
public void onStop() {
|
|
|
|
super.onStop();
|
2014-05-19 09:39:50 -04:00
|
|
|
if (this.conversation != null) {
|
2014-07-31 07:26:05 -04:00
|
|
|
this.conversation.setNextMessage(mEditMessage.getText().toString());
|
2014-05-09 14:46:43 -04:00
|
|
|
}
|
2014-05-07 06:59:15 -04:00
|
|
|
}
|
|
|
|
|
2014-01-27 14:40:42 -05:00
|
|
|
public void onBackendConnected() {
|
2014-02-06 20:57:36 -05:00
|
|
|
this.conversation = activity.getSelectedConversation();
|
2014-03-12 22:52:41 -04:00
|
|
|
if (this.conversation == null) {
|
2014-03-10 14:22:13 -04:00
|
|
|
return;
|
|
|
|
}
|
2014-05-21 10:43:19 -04:00
|
|
|
String oldString = conversation.getNextMessage().trim();
|
2014-05-07 06:59:15 -04:00
|
|
|
if (this.pastedText == null) {
|
2014-07-31 07:26:05 -04:00
|
|
|
this.mEditMessage.setText(oldString);
|
2014-05-07 06:59:15 -04:00
|
|
|
} else {
|
2014-06-01 13:29:57 -04:00
|
|
|
|
2014-05-21 10:43:19 -04:00
|
|
|
if (oldString.isEmpty()) {
|
2014-07-31 07:26:05 -04:00
|
|
|
mEditMessage.setText(pastedText);
|
2014-05-21 10:43:19 -04:00
|
|
|
} else {
|
2014-07-31 07:26:05 -04:00
|
|
|
mEditMessage.setText(oldString + " " + pastedText);
|
2014-05-21 10:43:19 -04:00
|
|
|
}
|
2014-05-07 06:59:15 -04:00
|
|
|
pastedText = null;
|
|
|
|
}
|
2014-07-31 07:26:05 -04:00
|
|
|
int position = mEditMessage.length();
|
|
|
|
Editable etext = mEditMessage.getText();
|
2014-05-07 06:59:15 -04:00
|
|
|
Selection.setSelection(etext, position);
|
2014-02-05 16:33:39 -05:00
|
|
|
updateMessages();
|
2014-03-07 12:13:19 -05:00
|
|
|
if (activity.getSlidingPaneLayout().isSlideable()) {
|
|
|
|
if (!activity.shouldPaneBeOpen()) {
|
|
|
|
activity.getSlidingPaneLayout().closePane();
|
|
|
|
activity.getActionBar().setDisplayHomeAsUpEnabled(true);
|
2014-05-30 23:18:50 -04:00
|
|
|
activity.getActionBar().setHomeButtonEnabled(true);
|
2014-05-07 06:59:15 -04:00
|
|
|
activity.getActionBar().setTitle(
|
|
|
|
conversation.getName(useSubject));
|
2014-03-07 12:13:19 -05:00
|
|
|
activity.invalidateOptionsMenu();
|
2014-02-10 16:45:59 -05:00
|
|
|
}
|
2014-01-28 13:21:54 -05:00
|
|
|
}
|
2014-01-24 17:58:51 -05:00
|
|
|
}
|
2014-05-07 06:59:15 -04:00
|
|
|
|
2014-06-07 07:25:27 -04:00
|
|
|
private void decryptMessage(Message message) {
|
2014-05-01 16:33:49 -04:00
|
|
|
PgpEngine engine = activity.xmppConnectionService.getPgpEngine();
|
2014-05-07 06:59:15 -04:00
|
|
|
if (engine != null) {
|
2014-06-07 07:25:27 -04:00
|
|
|
engine.decrypt(message, new UiCallback<Message>() {
|
2014-05-07 06:59:15 -04:00
|
|
|
|
2014-05-01 16:33:49 -04:00
|
|
|
@Override
|
2014-06-07 07:25:27 -04:00
|
|
|
public void userInputRequried(PendingIntent pi, Message message) {
|
2014-05-01 16:33:49 -04:00
|
|
|
askForPassphraseIntent = pi.getIntentSender();
|
2014-07-18 13:36:29 -04:00
|
|
|
showSnackbar(R.string.openpgp_messages_found,
|
|
|
|
R.string.decrypt, clickToDecryptListener);
|
2014-05-01 16:33:49 -04:00
|
|
|
}
|
2014-05-07 06:59:15 -04:00
|
|
|
|
2014-05-01 16:33:49 -04:00
|
|
|
@Override
|
2014-06-07 07:25:27 -04:00
|
|
|
public void success(Message message) {
|
2014-05-07 06:59:15 -04:00
|
|
|
activity.xmppConnectionService.databaseBackend
|
|
|
|
.updateMessage(message);
|
2014-05-01 16:33:49 -04:00
|
|
|
updateMessages();
|
|
|
|
}
|
2014-05-07 06:59:15 -04:00
|
|
|
|
2014-05-01 16:33:49 -04:00
|
|
|
@Override
|
2014-06-07 07:25:27 -04:00
|
|
|
public void error(int error, Message message) {
|
2014-05-01 16:33:49 -04:00
|
|
|
message.setEncryption(Message.ENCRYPTION_DECRYPTION_FAILED);
|
2014-05-07 06:59:15 -04:00
|
|
|
// updateMessages();
|
2014-05-01 16:33:49 -04:00
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|
2014-05-07 06:59:15 -04:00
|
|
|
|
2014-02-02 10:33:34 -05:00
|
|
|
public void updateMessages() {
|
2014-05-19 09:39:50 -04:00
|
|
|
if (getView() == null) {
|
2014-05-10 05:03:32 -04:00
|
|
|
return;
|
|
|
|
}
|
2014-07-18 06:44:33 -04:00
|
|
|
hideSnackbar();
|
2014-07-21 10:16:09 -04:00
|
|
|
final ConversationActivity activity = (ConversationActivity) getActivity();
|
2014-03-21 17:14:52 -04:00
|
|
|
if (this.conversation != null) {
|
2014-07-21 10:16:09 -04:00
|
|
|
final Contact contact = this.conversation.getContact();
|
|
|
|
if (!contact.showInRoster() && 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-03-21 17:14:52 -04:00
|
|
|
for (Message message : this.conversation.getMessages()) {
|
2014-05-19 09:39:50 -04:00
|
|
|
if ((message.getEncryption() == Message.ENCRYPTION_PGP)
|
|
|
|
&& ((message.getStatus() == Message.STATUS_RECIEVED) || (message
|
|
|
|
.getStatus() == Message.STATUS_SEND))) {
|
2014-05-01 16:33:49 -04:00
|
|
|
decryptMessage(message);
|
|
|
|
break;
|
2014-03-02 23:01:02 -05:00
|
|
|
}
|
|
|
|
}
|
2014-06-14 04:29:26 -04:00
|
|
|
if (this.conversation.getMessages().size() == 0) {
|
|
|
|
this.messageList.clear();
|
2014-06-14 10:59:07 -04:00
|
|
|
messagesLoaded = false;
|
2014-06-14 04:29:26 -04:00
|
|
|
} else {
|
2014-06-14 10:59:07 -04:00
|
|
|
for (Message message : this.conversation.getMessages()) {
|
2014-06-14 04:29:26 -04:00
|
|
|
if (!this.messageList.contains(message)) {
|
|
|
|
this.messageList.add(message);
|
|
|
|
}
|
2014-06-10 11:01:19 -04:00
|
|
|
}
|
2014-06-14 10:59:07 -04:00
|
|
|
messagesLoaded = true;
|
2014-06-14 04:29:26 -04:00
|
|
|
updateStatusMessages();
|
2014-06-10 11:01:19 -04:00
|
|
|
}
|
2014-03-21 17:14:52 -04:00
|
|
|
this.messageListAdapter.notifyDataSetChanged();
|
|
|
|
if (conversation.getMode() == Conversation.MODE_SINGLE) {
|
|
|
|
if (messageList.size() >= 1) {
|
2014-05-07 06:33:55 -04:00
|
|
|
makeFingerprintWarning(conversation.getLatestEncryption());
|
2014-03-02 23:01:02 -05:00
|
|
|
}
|
2014-02-27 18:22:56 -05:00
|
|
|
} else {
|
2014-07-18 13:36:29 -04:00
|
|
|
if (!conversation.getMucOptions().online()
|
|
|
|
&& conversation.getAccount().getStatus() == Account.STATUS_ONLINE) {
|
2014-03-21 17:14:52 -04:00
|
|
|
if (conversation.getMucOptions().getError() == MucOptions.ERROR_NICK_IN_USE) {
|
2014-07-18 13:36:29 -04:00
|
|
|
showSnackbar(R.string.nick_in_use, R.string.edit,
|
|
|
|
clickToMuc);
|
2014-07-18 06:44:33 -04:00
|
|
|
} else if (conversation.getMucOptions().getError() == MucOptions.ERROR_ROOM_NOT_FOUND) {
|
2014-07-18 13:36:29 -04:00
|
|
|
showSnackbar(R.string.conference_not_found,
|
|
|
|
R.string.leave, leaveMuc);
|
2014-03-21 17:14:52 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
getActivity().invalidateOptionsMenu();
|
|
|
|
updateChatMsgHint();
|
|
|
|
if (!activity.shouldPaneBeOpen()) {
|
2014-06-04 12:44:15 -04:00
|
|
|
activity.xmppConnectionService.markRead(conversation);
|
2014-03-21 17:14:52 -04:00
|
|
|
// TODO update notifications
|
|
|
|
UIHelper.updateNotification(getActivity(),
|
|
|
|
activity.getConversationList(), null, false);
|
|
|
|
activity.updateConversationList();
|
2014-02-27 18:22:56 -05:00
|
|
|
}
|
2014-02-10 17:12:11 -05:00
|
|
|
}
|
2014-02-02 10:33:34 -05:00
|
|
|
}
|
2014-06-06 05:39:17 -04:00
|
|
|
|
2014-06-10 11:01:19 -04:00
|
|
|
private void messageSent() {
|
|
|
|
int size = this.messageList.size();
|
|
|
|
if (size >= 1) {
|
|
|
|
messagesView.setSelection(size - 1);
|
|
|
|
}
|
2014-07-31 07:26:05 -04:00
|
|
|
mEditMessage.setText("");
|
2014-06-10 11:01:19 -04:00
|
|
|
}
|
2014-06-14 10:59:07 -04:00
|
|
|
|
2014-06-04 15:40:17 -04:00
|
|
|
protected void updateStatusMessages() {
|
2014-06-10 11:01:19 -04:00
|
|
|
boolean addedStatusMsg = false;
|
2014-06-04 15:40:17 -04:00
|
|
|
if (conversation.getMode() == Conversation.MODE_SINGLE) {
|
2014-06-06 05:39:17 -04:00
|
|
|
for (int i = this.messageList.size() - 1; i >= 0; --i) {
|
2014-06-10 11:01:19 -04:00
|
|
|
if (addedStatusMsg) {
|
|
|
|
if (this.messageList.get(i).getType() == Message.TYPE_STATUS) {
|
|
|
|
this.messageList.remove(i);
|
|
|
|
--i;
|
|
|
|
}
|
2014-06-04 15:40:17 -04:00
|
|
|
} else {
|
2014-06-10 11:01:19 -04:00
|
|
|
if (this.messageList.get(i).getStatus() == Message.STATUS_RECIEVED) {
|
|
|
|
addedStatusMsg = true;
|
|
|
|
} else {
|
|
|
|
if (this.messageList.get(i).getStatus() == Message.STATUS_SEND_DISPLAYED) {
|
|
|
|
this.messageList.add(i + 1,
|
|
|
|
Message.createStatusMessage(conversation));
|
|
|
|
addedStatusMsg = true;
|
|
|
|
}
|
2014-06-04 15:40:17 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2014-02-16 10:32:15 -05:00
|
|
|
|
|
|
|
protected void makeFingerprintWarning(int latestEncryption) {
|
2014-05-19 09:39:50 -04:00
|
|
|
Set<String> knownFingerprints = conversation.getContact()
|
|
|
|
.getOtrFingerprints();
|
|
|
|
if ((latestEncryption == Message.ENCRYPTION_OTR)
|
|
|
|
&& (conversation.hasValidOtrSession()
|
|
|
|
&& (conversation.getOtrSession().getSessionStatus() == SessionStatus.ENCRYPTED) && (!knownFingerprints
|
|
|
|
.contains(conversation.getOtrFingerprint())))) {
|
2014-07-18 13:36:29 -04: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 10:32:15 -05:00
|
|
|
}
|
|
|
|
}
|
2014-07-18 13:36:29 -04:00
|
|
|
|
|
|
|
protected void showSnackbar(int message, int action,
|
|
|
|
OnClickListener clickListener) {
|
2014-07-09 15:45:03 -04:00
|
|
|
snackbar.setVisibility(View.VISIBLE);
|
|
|
|
snackbarMessage.setText(message);
|
|
|
|
snackbarAction.setText(action);
|
|
|
|
snackbarAction.setOnClickListener(clickListener);
|
|
|
|
}
|
2014-07-18 13:36:29 -04:00
|
|
|
|
2014-07-09 15:45:03 -04:00
|
|
|
protected void hideSnackbar() {
|
|
|
|
snackbar.setVisibility(View.GONE);
|
|
|
|
}
|
2014-02-16 13:30:22 -05:00
|
|
|
|
|
|
|
protected void sendPlainTextMessage(Message message) {
|
|
|
|
ConversationActivity activity = (ConversationActivity) getActivity();
|
2014-06-11 15:53:25 -04:00
|
|
|
activity.xmppConnectionService.sendMessage(message);
|
2014-06-10 11:01:19 -04:00
|
|
|
messageSent();
|
2014-02-16 13:30:22 -05:00
|
|
|
}
|
2014-02-18 19:35:23 -05:00
|
|
|
|
2014-02-27 18:22:56 -05:00
|
|
|
protected void sendPgpMessage(final Message message) {
|
2014-05-06 15:34:30 -04:00
|
|
|
final ConversationActivity activity = (ConversationActivity) getActivity();
|
2014-02-27 18:22:56 -05:00
|
|
|
final XmppConnectionService xmppService = activity.xmppConnectionService;
|
2014-05-01 16:33:49 -04:00
|
|
|
final Contact contact = message.getConversation().getContact();
|
2014-03-03 10:39:19 -05:00
|
|
|
if (activity.hasPgp()) {
|
2014-05-22 09:36:41 -04:00
|
|
|
if (conversation.getMode() == Conversation.MODE_SINGLE) {
|
|
|
|
if (contact.getPgpKeyId() != 0) {
|
2014-06-01 13:29:57 -04:00
|
|
|
xmppService.getPgpEngine().hasKey(contact,
|
2014-06-07 07:25:27 -04:00
|
|
|
new UiCallback<Contact>() {
|
2014-06-01 13:29:57 -04:00
|
|
|
|
|
|
|
@Override
|
2014-06-09 15:25:01 -04:00
|
|
|
public void userInputRequried(PendingIntent pi,
|
|
|
|
Contact contact) {
|
2014-06-01 13:29:57 -04:00
|
|
|
activity.runIntent(
|
|
|
|
pi,
|
|
|
|
ConversationActivity.REQUEST_ENCRYPT_MESSAGE);
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2014-06-07 07:25:27 -04:00
|
|
|
public void success(Contact contact) {
|
2014-06-10 11:01:19 -04:00
|
|
|
messageSent();
|
2014-06-07 07:25:27 -04:00
|
|
|
activity.encryptTextMessage(message);
|
2014-06-01 13:29:57 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2014-06-07 07:25:27 -04:00
|
|
|
public void error(int error, Contact contact) {
|
2014-06-01 13:29:57 -04:00
|
|
|
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
2014-05-22 09:36:41 -04:00
|
|
|
} else {
|
2014-06-01 13:29:57 -04:00
|
|
|
showNoPGPKeyDialog(false,
|
|
|
|
new DialogInterface.OnClickListener() {
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void onClick(DialogInterface dialog,
|
|
|
|
int which) {
|
|
|
|
conversation
|
|
|
|
.setNextEncryption(Message.ENCRYPTION_NONE);
|
|
|
|
message.setEncryption(Message.ENCRYPTION_NONE);
|
2014-06-11 15:53:25 -04:00
|
|
|
xmppService.sendMessage(message);
|
2014-06-10 11:01:19 -04:00
|
|
|
messageSent();
|
2014-06-01 13:29:57 -04:00
|
|
|
}
|
|
|
|
});
|
2014-05-22 09:36:41 -04:00
|
|
|
}
|
2014-03-03 10:39:19 -05:00
|
|
|
} else {
|
2014-06-01 05:24:35 -04:00
|
|
|
if (conversation.getMucOptions().pgpKeysInUse()) {
|
2014-06-01 12:52:27 -04:00
|
|
|
if (!conversation.getMucOptions().everybodyHasKeys()) {
|
2014-06-01 13:29:57 -04:00
|
|
|
Toast warning = Toast
|
|
|
|
.makeText(getActivity(),
|
|
|
|
R.string.missing_public_keys,
|
|
|
|
Toast.LENGTH_LONG);
|
2014-06-01 12:52:27 -04:00
|
|
|
warning.setGravity(Gravity.CENTER_VERTICAL, 0, 0);
|
|
|
|
warning.show();
|
|
|
|
}
|
2014-06-07 07:25:27 -04:00
|
|
|
activity.encryptTextMessage(message);
|
2014-06-16 17:43:45 -04:00
|
|
|
messageSent();
|
2014-06-01 05:24:35 -04:00
|
|
|
} else {
|
2014-06-01 13:29:57 -04: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-06-11 15:53:25 -04:00
|
|
|
xmppService.sendMessage(message);
|
2014-06-10 11:01:19 -04:00
|
|
|
messageSent();
|
2014-06-01 13:29:57 -04:00
|
|
|
}
|
|
|
|
});
|
2014-06-01 05:24:35 -04:00
|
|
|
}
|
2014-03-03 10:39:19 -05:00
|
|
|
}
|
2014-06-09 15:25:01 -04:00
|
|
|
} else {
|
|
|
|
activity.showInstallPgpDialog();
|
2014-02-27 18:22:56 -05:00
|
|
|
}
|
|
|
|
}
|
2014-05-19 09:39:50 -04:00
|
|
|
|
2014-06-01 13:29:57 -04:00
|
|
|
public void showNoPGPKeyDialog(boolean plural,
|
|
|
|
DialogInterface.OnClickListener listener) {
|
2014-05-19 09:39:50 -04:00
|
|
|
AlertDialog.Builder builder = new AlertDialog.Builder(getActivity());
|
2014-05-08 08:23:09 -04:00
|
|
|
builder.setIconAttribute(android.R.attr.alertDialogIcon);
|
2014-06-01 05:24:35 -04: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 08:23:09 -04:00
|
|
|
builder.setNegativeButton(getString(R.string.cancel), null);
|
2014-05-19 09:39:50 -04:00
|
|
|
builder.setPositiveButton(getString(R.string.send_unencrypted),
|
|
|
|
listener);
|
2014-05-08 08:23:09 -04:00
|
|
|
builder.create().show();
|
|
|
|
}
|
2014-03-12 22:52:41 -04:00
|
|
|
|
2014-02-16 13:30:22 -05:00
|
|
|
protected void sendOtrMessage(final Message message) {
|
2014-06-12 17:04:28 -04:00
|
|
|
final ConversationActivity activity = (ConversationActivity) getActivity();
|
2014-02-16 13:30:22 -05:00
|
|
|
final XmppConnectionService xmppService = activity.xmppConnectionService;
|
|
|
|
if (conversation.hasValidOtrSession()) {
|
2014-06-11 15:53:25 -04:00
|
|
|
activity.xmppConnectionService.sendMessage(message);
|
2014-06-10 11:01:19 -04:00
|
|
|
messageSent();
|
2014-02-16 13:30:22 -05:00
|
|
|
} else {
|
2014-05-07 06:59:15 -04:00
|
|
|
activity.selectPresence(message.getConversation(),
|
|
|
|
new OnPresenceSelected() {
|
2014-02-18 19:35:23 -05:00
|
|
|
|
2014-05-07 06:59:15 -04:00
|
|
|
@Override
|
2014-06-16 08:21:22 -04:00
|
|
|
public void onPresenceSelected() {
|
|
|
|
message.setPresence(conversation.getNextPresence());
|
2014-06-11 15:53:25 -04:00
|
|
|
xmppService.sendMessage(message);
|
2014-06-10 11:01:19 -04:00
|
|
|
messageSent();
|
2014-05-07 06:59:15 -04:00
|
|
|
}
|
2014-06-12 17:04:28 -04:00
|
|
|
});
|
2014-02-16 13:30:22 -05:00
|
|
|
}
|
|
|
|
}
|
2014-02-18 19:35:23 -05:00
|
|
|
|
2014-03-13 16:37:27 -04:00
|
|
|
public void setText(String text) {
|
|
|
|
this.pastedText = text;
|
|
|
|
}
|
2014-05-08 11:31:53 -04:00
|
|
|
|
|
|
|
public void clearInputField() {
|
2014-07-31 07:26:05 -04:00
|
|
|
this.mEditMessage.setText("");
|
2014-05-08 11:31:53 -04:00
|
|
|
}
|
2014-01-23 20:04:05 -05:00
|
|
|
}
|