2014-02-28 12:46:01 -05:00
|
|
|
package eu.siacs.conversations.ui;
|
2014-01-23 20:04:05 -05:00
|
|
|
|
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;
|
|
|
|
import android.content.IntentSender.SendIntentException;
|
2014-01-23 20:04:05 -05:00
|
|
|
import android.os.Bundle;
|
2014-10-23 15:27:41 -04:00
|
|
|
import android.view.ContextMenu;
|
|
|
|
import android.view.ContextMenu.ContextMenuInfo;
|
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;
|
2014-10-23 15:27:41 -04:00
|
|
|
import android.view.MenuItem;
|
2014-01-23 20:04:05 -05:00
|
|
|
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;
|
2014-11-04 12:52:29 -05:00
|
|
|
import android.widget.AbsListView.OnScrollListener;
|
2014-10-23 15:27:41 -04:00
|
|
|
import android.widget.AdapterView;
|
|
|
|
import android.widget.AdapterView.AdapterContextMenuInfo;
|
2014-01-25 21:27:55 -05:00
|
|
|
import android.widget.ImageButton;
|
2014-11-04 12:52:29 -05:00
|
|
|
import android.widget.ListView;
|
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-11-04 12:52:29 -05:00
|
|
|
import android.widget.TextView.OnEditorActionListener;
|
2014-03-03 22:09:15 -05:00
|
|
|
import android.widget.Toast;
|
2014-01-23 20:04:05 -05:00
|
|
|
|
2014-11-04 12:52:29 -05:00
|
|
|
import net.java.otr4j.session.SessionStatus;
|
|
|
|
|
|
|
|
import java.util.ArrayList;
|
|
|
|
import java.util.List;
|
2014-12-01 05:18:55 -05:00
|
|
|
import java.util.NoSuchElementException;
|
2014-11-04 12:52:29 -05:00
|
|
|
import java.util.concurrent.ConcurrentLinkedQueue;
|
|
|
|
|
|
|
|
import eu.siacs.conversations.R;
|
|
|
|
import eu.siacs.conversations.crypto.PgpEngine;
|
|
|
|
import eu.siacs.conversations.entities.Account;
|
|
|
|
import eu.siacs.conversations.entities.Contact;
|
|
|
|
import eu.siacs.conversations.entities.Conversation;
|
2014-11-15 06:37:09 -05:00
|
|
|
import eu.siacs.conversations.entities.Downloadable;
|
2014-11-15 09:16:40 -05:00
|
|
|
import eu.siacs.conversations.entities.DownloadableFile;
|
2014-11-15 08:40:43 -05:00
|
|
|
import eu.siacs.conversations.entities.DownloadablePlaceholder;
|
2014-11-04 12:52:29 -05:00
|
|
|
import eu.siacs.conversations.entities.Message;
|
|
|
|
import eu.siacs.conversations.entities.MucOptions;
|
|
|
|
import eu.siacs.conversations.entities.Presences;
|
|
|
|
import eu.siacs.conversations.services.XmppConnectionService;
|
|
|
|
import eu.siacs.conversations.ui.EditMessage.OnEnterPressed;
|
|
|
|
import eu.siacs.conversations.ui.XmppActivity.OnPresenceSelected;
|
|
|
|
import eu.siacs.conversations.ui.XmppActivity.OnValueEdited;
|
|
|
|
import eu.siacs.conversations.ui.adapter.MessageAdapter;
|
|
|
|
import eu.siacs.conversations.ui.adapter.MessageAdapter.OnContactPictureClicked;
|
|
|
|
import eu.siacs.conversations.ui.adapter.MessageAdapter.OnContactPictureLongClicked;
|
2014-11-06 14:33:13 -05:00
|
|
|
import eu.siacs.conversations.xmpp.jid.Jid;
|
2014-11-04 12:52:29 -05:00
|
|
|
|
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;
|
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-10-06 07:34:19 -04:00
|
|
|
private OnClickListener joinMuc = new OnClickListener() {
|
2014-10-07 09:18:09 -04:00
|
|
|
|
2014-10-06 07:34:19 -04:00
|
|
|
@Override
|
|
|
|
public void onClick(View v) {
|
|
|
|
activity.xmppConnectionService.joinMuc(conversation);
|
|
|
|
}
|
|
|
|
};
|
2014-09-03 13:35:45 -04:00
|
|
|
private OnClickListener enterPassword = new OnClickListener() {
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void onClick(View v) {
|
|
|
|
MucOptions muc = conversation.getMucOptions();
|
|
|
|
String password = muc.getPassword();
|
2014-09-08 14:29:57 -04:00
|
|
|
if (password == null) {
|
2014-09-03 13:35:45 -04:00
|
|
|
password = "";
|
|
|
|
}
|
2014-09-04 05:46:13 -04:00
|
|
|
activity.quickPasswordEdit(password, new OnValueEdited() {
|
2014-09-08 14:29:57 -04:00
|
|
|
|
2014-09-03 13:35:45 -04:00
|
|
|
@Override
|
|
|
|
public void onValueEdited(String value) {
|
2014-09-08 14:29:57 -04:00
|
|
|
activity.xmppConnectionService.providePasswordForMuc(
|
|
|
|
conversation, value);
|
2014-09-03 13:35:45 -04:00
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
|
|
|
};
|
2014-11-07 09:38:20 -05:00
|
|
|
protected ListView messagesView;
|
2014-11-17 21:10:59 -05:00
|
|
|
final protected List<Message> messageList = new ArrayList<>();
|
2014-11-07 09:38:20 -05:00
|
|
|
protected MessageAdapter messageListAdapter;
|
|
|
|
protected Contact contact;
|
|
|
|
private EditMessage mEditMessage;
|
|
|
|
private ImageButton mSendButton;
|
|
|
|
private RelativeLayout snackbar;
|
|
|
|
private TextView snackbarMessage;
|
|
|
|
private TextView snackbarAction;
|
2014-12-17 04:50:51 -05:00
|
|
|
private boolean messagesLoaded = true;
|
2014-12-17 03:32:51 -05:00
|
|
|
private Toast messageLoaderToast;
|
2014-12-15 17:06:29 -05:00
|
|
|
|
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,
|
2014-12-21 15:43:58 -05:00
|
|
|
int visibleItemCount, int totalItemCount) {
|
2014-11-18 08:43:15 -05:00
|
|
|
synchronized (ConversationFragment.this.messageList) {
|
2014-12-17 04:50:51 -05:00
|
|
|
if (firstVisibleItem < 5 && messagesLoaded && messageList.size() > 0) {
|
2014-11-18 08:43:15 -05:00
|
|
|
long timestamp = ConversationFragment.this.messageList.get(0).getTimeSent();
|
|
|
|
messagesLoaded = false;
|
2014-12-15 17:06:29 -05:00
|
|
|
activity.xmppConnectionService.loadMoreMessages(conversation, timestamp, new XmppConnectionService.OnMoreMessagesLoaded() {
|
|
|
|
@Override
|
|
|
|
public void onMoreMessagesLoaded(final int count, Conversation conversation) {
|
|
|
|
if (ConversationFragment.this.conversation != conversation) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
activity.runOnUiThread(new Runnable() {
|
|
|
|
@Override
|
|
|
|
public void run() {
|
2014-12-17 04:50:51 -05:00
|
|
|
final int oldPosition = messagesView.getFirstVisiblePosition();
|
|
|
|
View v = messagesView.getChildAt(0);
|
|
|
|
final int pxOffset = (v == null) ? 0 : v.getTop();
|
2014-12-15 17:06:29 -05:00
|
|
|
ConversationFragment.this.conversation.populateWithMessages(ConversationFragment.this.messageList);
|
|
|
|
updateStatusMessages();
|
|
|
|
messageListAdapter.notifyDataSetChanged();
|
|
|
|
if (count != 0) {
|
2014-12-17 03:32:51 -05:00
|
|
|
final int newPosition = oldPosition + count;
|
|
|
|
int offset = 0;
|
2014-12-17 04:50:51 -05:00
|
|
|
try {
|
|
|
|
Message tmpMessage = messageList.get(newPosition);
|
|
|
|
|
|
|
|
while(tmpMessage.wasMergedIntoPrevious()) {
|
|
|
|
offset++;
|
|
|
|
tmpMessage = tmpMessage.prev();
|
|
|
|
}
|
|
|
|
} catch (final IndexOutOfBoundsException ignored) {
|
|
|
|
|
2014-12-17 03:32:51 -05:00
|
|
|
}
|
2014-12-17 04:50:51 -05:00
|
|
|
messagesView.setSelectionFromTop(newPosition - offset, pxOffset);
|
2014-12-15 17:06:29 -05:00
|
|
|
messagesLoaded = true;
|
2014-12-17 03:32:51 -05:00
|
|
|
if (messageLoaderToast != null) {
|
|
|
|
messageLoaderToast.cancel();
|
|
|
|
}
|
2014-12-15 17:06:29 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
2014-12-17 03:32:51 -05:00
|
|
|
|
|
|
|
@Override
|
2014-12-17 04:50:51 -05:00
|
|
|
public void informUser(final int resId) {
|
|
|
|
|
|
|
|
activity.runOnUiThread(new Runnable() {
|
|
|
|
@Override
|
|
|
|
public void run() {
|
|
|
|
if (messageLoaderToast != null) {
|
|
|
|
messageLoaderToast.cancel();
|
|
|
|
}
|
|
|
|
if (ConversationFragment.this.conversation != conversation) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
messageLoaderToast = Toast.makeText(activity,resId,Toast.LENGTH_LONG);
|
|
|
|
messageLoaderToast.show();
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
2014-12-17 03:32:51 -05:00
|
|
|
}
|
2014-12-15 17:06:29 -05:00
|
|
|
});
|
|
|
|
|
2014-06-14 10:59:07 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
};
|
2014-11-07 09:38:20 -05:00
|
|
|
private IntentSender askForPassphraseIntent = null;
|
|
|
|
protected OnClickListener clickToDecryptListener = new OnClickListener() {
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void onClick(View v) {
|
|
|
|
if (activity.hasPgp() && askForPassphraseIntent != null) {
|
|
|
|
try {
|
|
|
|
getActivity().startIntentSenderForResult(
|
|
|
|
askForPassphraseIntent,
|
|
|
|
ConversationActivity.REQUEST_DECRYPT_PGP, null, 0,
|
|
|
|
0, 0);
|
|
|
|
} catch (SendIntentException e) {
|
|
|
|
//
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
};
|
2014-11-10 16:03:23 -05:00
|
|
|
protected OnClickListener clickToVerify = new OnClickListener() {
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void onClick(View v) {
|
2015-01-01 19:21:14 -05:00
|
|
|
activity.verifyOtrSessionDialog(conversation,v);
|
2014-11-10 16:03:23 -05:00
|
|
|
}
|
|
|
|
};
|
2014-11-06 14:33:13 -05:00
|
|
|
private ConcurrentLinkedQueue<Message> mEncryptedMessages = new ConcurrentLinkedQueue<>();
|
2014-11-07 09:38:20 -05:00
|
|
|
private boolean mDecryptJobRunning = false;
|
|
|
|
private OnEditorActionListener mEditorActionListener = new OnEditorActionListener() {
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public boolean onEditorAction(TextView v, int actionId, KeyEvent event) {
|
|
|
|
if (actionId == EditorInfo.IME_ACTION_SEND) {
|
|
|
|
InputMethodManager imm = (InputMethodManager) v.getContext()
|
2014-12-21 15:43:58 -05:00
|
|
|
.getSystemService(Context.INPUT_METHOD_SERVICE);
|
2014-11-07 09:38:20 -05:00
|
|
|
imm.hideSoftInputFromWindow(v.getWindowToken(), 0);
|
|
|
|
sendMessage();
|
|
|
|
return true;
|
|
|
|
} else {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
};
|
|
|
|
private OnClickListener mSendButtonListener = new OnClickListener() {
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void onClick(View v) {
|
|
|
|
sendMessage();
|
|
|
|
}
|
|
|
|
};
|
|
|
|
private OnClickListener clickToMuc = new OnClickListener() {
|
2014-06-14 10:59:07 -04:00
|
|
|
|
2014-11-07 09:38:20 -05:00
|
|
|
@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-03-28 07:22:09 -04:00
|
|
|
private ConversationActivity activity;
|
2014-10-23 15:27:41 -04:00
|
|
|
private Message selectedMessage;
|
2014-08-25 09:43:50 -04:00
|
|
|
|
2014-07-31 07:26:05 -04:00
|
|
|
private void sendMessage() {
|
2014-09-08 14:29:57 -04:00
|
|
|
if (this.conversation == null) {
|
2014-09-06 18:09:12 -04:00
|
|
|
return;
|
|
|
|
}
|
2014-08-10 09:27:44 -04:00
|
|
|
if (mEditMessage.getText().length() < 1) {
|
|
|
|
if (this.conversation.getMode() == Conversation.MODE_MULTI) {
|
2014-11-09 10:21:13 -05:00
|
|
|
conversation.setNextCounterpart(null);
|
2014-08-10 09:27:44 -04:00
|
|
|
updateChatMsgHint();
|
|
|
|
}
|
2014-07-31 07:26:05 -04:00
|
|
|
return;
|
2014-08-10 09:27:44 -04:00
|
|
|
}
|
2014-07-31 07:26:05 -04:00
|
|
|
Message message = new Message(conversation, mEditMessage.getText()
|
2014-09-08 14:29:57 -04:00
|
|
|
.toString(), conversation.getNextEncryption(activity
|
2014-12-21 15:43:58 -05:00
|
|
|
.forceEncryption()));
|
2014-08-10 09:27:44 -04:00
|
|
|
if (conversation.getMode() == Conversation.MODE_MULTI) {
|
2014-11-09 10:21:13 -05:00
|
|
|
if (conversation.getNextCounterpart() != null) {
|
|
|
|
message.setCounterpart(conversation.getNextCounterpart());
|
2014-08-10 09:27:44 -04:00
|
|
|
message.setType(Message.TYPE_PRIVATE);
|
2014-11-09 10:21:13 -05:00
|
|
|
conversation.setNextCounterpart(null);
|
2014-08-10 09:27:44 -04:00
|
|
|
}
|
|
|
|
}
|
2014-09-08 07:37:22 -04:00
|
|
|
if (conversation.getNextEncryption(activity.forceEncryption()) == Message.ENCRYPTION_OTR) {
|
2014-07-31 07:26:05 -04:00
|
|
|
sendOtrMessage(message);
|
2014-09-08 07:37:22 -04:00
|
|
|
} else if (conversation.getNextEncryption(activity.forceEncryption()) == Message.ENCRYPTION_PGP) {
|
2014-07-31 07:26:05 -04:00
|
|
|
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-08-25 09:43:50 -04:00
|
|
|
if (conversation.getMode() == Conversation.MODE_MULTI
|
2014-11-09 10:21:13 -05:00
|
|
|
&& conversation.getNextCounterpart() != null) {
|
2014-08-25 09:43:50 -04:00
|
|
|
this.mEditMessage.setHint(getString(
|
2014-12-21 15:43:58 -05:00
|
|
|
R.string.send_private_message_to,
|
|
|
|
conversation.getNextCounterpart().getResourcepart()));
|
2014-08-22 07:22:07 -04:00
|
|
|
} else {
|
2014-09-08 07:37:22 -04:00
|
|
|
switch (conversation.getNextEncryption(activity.forceEncryption())) {
|
2014-11-04 12:52:29 -05:00
|
|
|
case Message.ENCRYPTION_NONE:
|
|
|
|
mEditMessage
|
2014-12-21 15:43:58 -05:00
|
|
|
.setHint(getString(R.string.send_plain_text_message));
|
2014-11-04 12:52:29 -05: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-08-22 07:22:07 -04:00
|
|
|
}
|
2014-02-16 10:32:15 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-01-27 14:40:42 -05:00
|
|
|
@Override
|
|
|
|
public View onCreateView(final LayoutInflater inflater,
|
2014-12-21 15:43:58 -05:00
|
|
|
ViewGroup container, Bundle savedInstanceState) {
|
2014-01-27 14:40:42 -05:00
|
|
|
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) {
|
2014-10-03 09:00:29 -04:00
|
|
|
activity.hideConversationsOverview();
|
2014-07-15 14:41:32 -04:00
|
|
|
}
|
|
|
|
});
|
2014-07-31 07:26:05 -04:00
|
|
|
mEditMessage.setOnEditorActionListener(mEditorActionListener);
|
|
|
|
mEditMessage.setOnEnterPressedListener(new OnEnterPressed() {
|
2014-08-25 09:43:50 -04:00
|
|
|
|
2014-07-31 07:26:05 -04:00
|
|
|
@Override
|
|
|
|
public void onEnterPressed() {
|
|
|
|
sendMessage();
|
|
|
|
}
|
|
|
|
});
|
2014-08-25 09:43:50 -04:00
|
|
|
|
2014-09-10 11:59:57 -04:00
|
|
|
mSendButton = (ImageButton) view.findViewById(R.id.textSendButton);
|
|
|
|
mSendButton.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-11-18 08:43:15 -05:00
|
|
|
messageListAdapter = new MessageAdapter((ConversationActivity) getActivity(), this.messageList);
|
|
|
|
messageListAdapter.setOnContactPictureClicked(new OnContactPictureClicked() {
|
2014-08-25 09:43:50 -04:00
|
|
|
|
2014-12-21 15:43:58 -05:00
|
|
|
@Override
|
|
|
|
public void onContactPictureClicked(Message message) {
|
|
|
|
if (message.getStatus() <= Message.STATUS_RECEIVED) {
|
|
|
|
if (message.getConversation().getMode() == Conversation.MODE_MULTI) {
|
|
|
|
if (message.getCounterpart() != null) {
|
|
|
|
if (!message.getCounterpart().isBareJid()) {
|
|
|
|
highlightInConference(message.getCounterpart().getResourcepart());
|
2014-08-25 09:43:50 -04:00
|
|
|
} else {
|
2014-12-21 15:43:58 -05:00
|
|
|
highlightInConference(message.getCounterpart().toString());
|
2014-08-25 09:43:50 -04:00
|
|
|
}
|
2014-12-21 15:43:58 -05:00
|
|
|
}
|
|
|
|
} else {
|
|
|
|
Contact contact = message.getConversation()
|
|
|
|
.getContact();
|
|
|
|
if (contact.showInRoster()) {
|
|
|
|
activity.switchToContactDetails(contact);
|
2014-11-10 16:03:23 -05:00
|
|
|
} else {
|
2014-12-21 15:43:58 -05:00
|
|
|
activity.showAddToRosterDialog(message
|
|
|
|
.getConversation());
|
2014-08-25 09:43:50 -04:00
|
|
|
}
|
2014-08-10 09:27:44 -04:00
|
|
|
}
|
2014-12-21 15:43:58 -05:00
|
|
|
} else {
|
|
|
|
Account account = message.getConversation().getAccount();
|
|
|
|
Intent intent = new Intent(activity, EditAccountActivity.class);
|
|
|
|
intent.putExtra("jid", account.getJid().toBareJid().toString());
|
|
|
|
startActivity(intent);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|
2014-08-25 09:43:50 -04:00
|
|
|
messageListAdapter
|
2014-12-21 15:43:58 -05:00
|
|
|
.setOnContactPictureLongClicked(new OnContactPictureLongClicked() {
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void onContactPictureLongClicked(Message message) {
|
|
|
|
if (message.getStatus() <= Message.STATUS_RECEIVED) {
|
|
|
|
if (message.getConversation().getMode() == Conversation.MODE_MULTI) {
|
|
|
|
if (message.getCounterpart() != null) {
|
|
|
|
privateMessageWith(message.getCounterpart());
|
2014-08-25 09:43:50 -04:00
|
|
|
}
|
|
|
|
}
|
2014-08-10 09:27:44 -04:00
|
|
|
}
|
2014-12-21 15:43:58 -05:00
|
|
|
}
|
|
|
|
});
|
2014-02-02 10:33:34 -05:00
|
|
|
messagesView.setAdapter(messageListAdapter);
|
2014-01-25 21:27:55 -05:00
|
|
|
|
2014-10-23 15:27:41 -04:00
|
|
|
registerForContextMenu(messagesView);
|
|
|
|
|
2014-01-25 21:27:55 -05:00
|
|
|
return view;
|
|
|
|
}
|
2014-08-25 09:43:50 -04:00
|
|
|
|
2014-10-23 15:27:41 -04:00
|
|
|
@Override
|
|
|
|
public void onCreateContextMenu(ContextMenu menu, View v,
|
2014-12-21 15:43:58 -05:00
|
|
|
ContextMenuInfo menuInfo) {
|
2014-11-18 08:43:15 -05: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 15:27:41 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
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 13:30:03 -04:00
|
|
|
MenuItem downloadImage = menu.findItem(R.id.download_image);
|
2014-11-15 06:37:09 -05:00
|
|
|
MenuItem cancelTransmission = menu.findItem(R.id.cancel_transmission);
|
2014-10-23 15:27:41 -04:00
|
|
|
if (this.selectedMessage.getType() != Message.TYPE_TEXT
|
|
|
|
|| this.selectedMessage.getDownloadable() != null) {
|
|
|
|
copyText.setVisible(false);
|
2014-12-21 15:43:58 -05:00
|
|
|
}
|
2014-10-23 15:27:41 -04:00
|
|
|
if (this.selectedMessage.getType() != Message.TYPE_IMAGE
|
2014-10-29 04:57:34 -04:00
|
|
|
|| this.selectedMessage.getDownloadable() != null) {
|
2014-10-23 15:27:41 -04:00
|
|
|
shareImage.setVisible(false);
|
2014-12-21 15:43:58 -05:00
|
|
|
}
|
2014-10-23 15:27:41 -04:00
|
|
|
if (this.selectedMessage.getStatus() != Message.STATUS_SEND_FAILED) {
|
|
|
|
sendAgain.setVisible(false);
|
|
|
|
}
|
|
|
|
if ((this.selectedMessage.getType() != Message.TYPE_IMAGE && this.selectedMessage
|
2014-12-21 15:43:58 -05:00
|
|
|
.getDownloadable() == null)
|
2014-10-23 15:27:41 -04:00
|
|
|
|| this.selectedMessage.getImageParams().url == null) {
|
|
|
|
copyUrl.setVisible(false);
|
2014-12-21 15:43:58 -05:00
|
|
|
}
|
2014-10-24 13:30:03 -04:00
|
|
|
if (this.selectedMessage.getType() != Message.TYPE_TEXT
|
|
|
|
|| this.selectedMessage.getDownloadable() != null
|
|
|
|
|| !this.selectedMessage.bodyContainsDownloadable()) {
|
|
|
|
downloadImage.setVisible(false);
|
2014-12-21 15:43:58 -05:00
|
|
|
}
|
2014-11-15 06:37:09 -05:00
|
|
|
if (this.selectedMessage.getDownloadable() == null
|
2014-11-15 08:40:43 -05:00
|
|
|
|| this.selectedMessage.getDownloadable() instanceof DownloadablePlaceholder) {
|
2014-11-15 06:37:09 -05:00
|
|
|
cancelTransmission.setVisible(false);
|
2014-12-21 15:43:58 -05:00
|
|
|
}
|
2014-10-23 15:27:41 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public boolean onContextItemSelected(MenuItem item) {
|
|
|
|
switch (item.getItemId()) {
|
2014-11-04 12:52:29 -05:00
|
|
|
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;
|
|
|
|
case R.id.download_image:
|
|
|
|
downloadImage(selectedMessage);
|
|
|
|
return true;
|
2014-11-15 06:37:09 -05:00
|
|
|
case R.id.cancel_transmission:
|
|
|
|
cancelTransmission(selectedMessage);
|
|
|
|
return true;
|
2014-11-04 12:52:29 -05:00
|
|
|
default:
|
|
|
|
return super.onContextItemSelected(item);
|
2014-10-23 15:27:41 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
private void shareImage(Message message) {
|
|
|
|
Intent shareIntent = new Intent();
|
|
|
|
shareIntent.setAction(Intent.ACTION_SEND);
|
|
|
|
shareIntent.putExtra(Intent.EXTRA_STREAM,
|
|
|
|
activity.xmppConnectionService.getFileBackend()
|
2014-12-21 15:43:58 -05:00
|
|
|
.getJingleFileUri(message));
|
2014-10-23 15:27:41 -04:00
|
|
|
shareIntent.setFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION);
|
|
|
|
shareIntent.setType("image/webp");
|
|
|
|
activity.startActivity(Intent.createChooser(shareIntent,
|
2014-12-21 15:43:58 -05:00
|
|
|
getText(R.string.share_with)));
|
2014-10-23 15:27:41 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
private void copyText(Message message) {
|
|
|
|
if (activity.copyTextToClipboard(message.getMergedBody(),
|
2014-12-21 15:43:58 -05:00
|
|
|
R.string.message_text)) {
|
2014-10-23 15:27:41 -04:00
|
|
|
Toast.makeText(activity, R.string.message_copied_to_clipboard,
|
|
|
|
Toast.LENGTH_SHORT).show();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
private void resendMessage(Message message) {
|
2014-11-15 09:16:40 -05:00
|
|
|
if (message.getType() == Message.TYPE_FILE || message.getType() == Message.TYPE_IMAGE) {
|
|
|
|
DownloadableFile file = activity.xmppConnectionService.getFileBackend().getFile(message);
|
|
|
|
if (!file.exists()) {
|
|
|
|
Toast.makeText(activity,R.string.file_deleted,Toast.LENGTH_SHORT).show();
|
|
|
|
message.setDownloadable(new DownloadablePlaceholder(Downloadable.STATUS_DELETED));
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
2014-10-23 15:27:41 -04:00
|
|
|
activity.xmppConnectionService.resendFailedMessages(message);
|
|
|
|
}
|
|
|
|
|
|
|
|
private void copyUrl(Message message) {
|
|
|
|
if (activity.copyTextToClipboard(
|
2014-12-21 15:43:58 -05:00
|
|
|
message.getImageParams().url.toString(), R.string.image_url)) {
|
2014-10-23 15:27:41 -04:00
|
|
|
Toast.makeText(activity, R.string.url_copied_to_clipboard,
|
|
|
|
Toast.LENGTH_SHORT).show();
|
2014-12-21 15:43:58 -05:00
|
|
|
}
|
2014-10-23 15:27:41 -04:00
|
|
|
}
|
|
|
|
|
2014-10-24 13:30:03 -04:00
|
|
|
private void downloadImage(Message message) {
|
|
|
|
activity.xmppConnectionService.getHttpConnectionManager()
|
2014-12-21 15:43:58 -05:00
|
|
|
.createNewConnection(message);
|
2014-10-24 13:30:03 -04:00
|
|
|
}
|
|
|
|
|
2014-11-15 06:37:09 -05:00
|
|
|
private void cancelTransmission(Message message) {
|
|
|
|
Downloadable downloadable = message.getDownloadable();
|
|
|
|
if (downloadable!=null) {
|
|
|
|
downloadable.cancel();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-11-06 14:33:13 -05:00
|
|
|
protected void privateMessageWith(final Jid counterpart) {
|
2014-08-10 09:27:44 -04:00
|
|
|
this.mEditMessage.setText("");
|
2014-11-09 10:21:13 -05:00
|
|
|
this.conversation.setNextCounterpart(counterpart);
|
2014-08-22 07:22:07 -04:00
|
|
|
updateChatMsgHint();
|
2014-08-10 09:27:44 -04:00
|
|
|
}
|
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-08-31 11:24:52 -04:00
|
|
|
if (oldString.isEmpty() || mEditMessage.getSelectionStart() == 0) {
|
|
|
|
mEditMessage.getText().insert(0, nick + ": ");
|
2014-05-20 05:44:43 -04:00
|
|
|
} else {
|
2014-09-03 13:35:45 -04:00
|
|
|
if (mEditMessage.getText().charAt(
|
2014-12-21 15:43:58 -05:00
|
|
|
mEditMessage.getSelectionStart() - 1) != ' ') {
|
2014-09-03 13:35:45 -04:00
|
|
|
nick = " " + nick;
|
2014-12-21 15:43:58 -05:00
|
|
|
}
|
2014-09-03 13:35:45 -04:00
|
|
|
mEditMessage.getText().insert(mEditMessage.getSelectionStart(),
|
|
|
|
nick + " ");
|
2014-05-20 05:44:43 -04:00
|
|
|
}
|
|
|
|
}
|
2014-06-01 13:29:57 -04:00
|
|
|
|
2014-05-07 06:59:15 -04:00
|
|
|
@Override
|
|
|
|
public void onStop() {
|
2014-10-14 20:09:20 -04:00
|
|
|
mDecryptJobRunning = false;
|
2014-05-07 06:59:15 -04:00
|
|
|
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-11-07 09:38:20 -05:00
|
|
|
public void reInit(Conversation conversation) {
|
2014-11-17 14:02:46 -05:00
|
|
|
if (conversation == null) {
|
|
|
|
return;
|
|
|
|
}
|
2014-11-07 09:38:20 -05:00
|
|
|
if (this.conversation != null) {
|
|
|
|
this.conversation.setNextMessage(mEditMessage.getText().toString());
|
2014-12-17 15:05:47 -05:00
|
|
|
this.conversation.trim();
|
2014-01-28 13:21:54 -05:00
|
|
|
}
|
2014-11-07 09:38:20 -05:00
|
|
|
this.activity = (ConversationActivity) getActivity();
|
|
|
|
this.conversation = conversation;
|
2014-12-01 05:18:55 -05:00
|
|
|
this.mDecryptJobRunning = false;
|
|
|
|
this.mEncryptedMessages.clear();
|
2014-08-10 09:27:44 -04:00
|
|
|
if (this.conversation.getMode() == Conversation.MODE_MULTI) {
|
2014-11-09 10:21:13 -05:00
|
|
|
this.conversation.setNextCounterpart(null);
|
2014-08-10 09:27:44 -04:00
|
|
|
}
|
2014-11-07 09:38:20 -05:00
|
|
|
this.mEditMessage.setText("");
|
|
|
|
this.mEditMessage.append(this.conversation.getNextMessage());
|
2014-12-25 13:53:56 -05:00
|
|
|
this.messagesView.invalidateViews();
|
2014-08-22 07:22:07 -04:00
|
|
|
updateMessages();
|
2014-12-17 04:50:51 -05:00
|
|
|
this.messagesLoaded = true;
|
|
|
|
int size = this.messageList.size();
|
|
|
|
if (size > 0) {
|
|
|
|
messagesView.setSelection(size - 1);
|
|
|
|
}
|
2014-01-24 17:58:51 -05:00
|
|
|
}
|
2014-05-07 06:59:15 -04:00
|
|
|
|
2014-02-02 10:33:34 -05:00
|
|
|
public void updateMessages() {
|
2014-11-18 08:43:15 -05:00
|
|
|
synchronized (this.messageList) {
|
|
|
|
if (getView() == null) {
|
|
|
|
return;
|
2014-07-21 10:16:09 -04:00
|
|
|
}
|
2014-11-18 08:43:15 -05:00
|
|
|
hideSnackbar();
|
|
|
|
final ConversationActivity activity = (ConversationActivity) getActivity();
|
|
|
|
if (this.conversation != null) {
|
|
|
|
final Contact contact = this.conversation.getContact();
|
2014-12-21 15:43:58 -05:00
|
|
|
if (this.conversation.isBlocked()) {
|
|
|
|
showSnackbar(R.string.contact_blocked, R.string.unblock,
|
|
|
|
new OnClickListener() {
|
|
|
|
@Override
|
|
|
|
public void onClick(final View v) {
|
|
|
|
v.post(new Runnable() {
|
|
|
|
@Override
|
|
|
|
public void run() {
|
|
|
|
v.setVisibility(View.INVISIBLE);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
if (conversation.isDomainBlocked()) {
|
|
|
|
BlockContactDialog.show(getActivity(), ((ConversationActivity) getActivity()).xmppConnectionService, conversation);
|
|
|
|
} else {
|
|
|
|
((ConversationActivity) getActivity()).unblockConversation(conversation);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|
|
|
|
} else if (this.conversation.isMuted()) {
|
2014-11-18 08:43:15 -05:00
|
|
|
showSnackbar(R.string.notifications_disabled, R.string.enable,
|
|
|
|
new OnClickListener() {
|
|
|
|
|
|
|
|
@Override
|
2014-12-21 15:43:58 -05:00
|
|
|
public void onClick(final View v) {
|
2014-11-18 08:43:15 -05:00
|
|
|
activity.unmuteConversation(conversation);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
} else 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
|
2014-12-21 15:43:58 -05:00
|
|
|
.createContact(contact);
|
2014-11-18 08:43:15 -05:00
|
|
|
activity.switchToContactDetails(contact);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
} else if (conversation.getMode() == Conversation.MODE_SINGLE) {
|
|
|
|
makeFingerprintWarning();
|
|
|
|
} else if (!conversation.getMucOptions().online()
|
|
|
|
&& conversation.getAccount().getStatus() == Account.State.ONLINE) {
|
|
|
|
int error = conversation.getMucOptions().getError();
|
|
|
|
switch (error) {
|
|
|
|
case MucOptions.ERROR_NICK_IN_USE:
|
|
|
|
showSnackbar(R.string.nick_in_use, R.string.edit,
|
|
|
|
clickToMuc);
|
|
|
|
break;
|
2014-11-20 12:20:42 -05:00
|
|
|
case MucOptions.ERROR_UNKNOWN:
|
2014-11-18 08:43:15 -05:00
|
|
|
showSnackbar(R.string.conference_not_found,
|
|
|
|
R.string.leave, leaveMuc);
|
|
|
|
break;
|
|
|
|
case MucOptions.ERROR_PASSWORD_REQUIRED:
|
|
|
|
showSnackbar(R.string.conference_requires_password,
|
|
|
|
R.string.enter_password, enterPassword);
|
|
|
|
break;
|
|
|
|
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:
|
|
|
|
showSnackbar(R.string.conference_kicked, R.string.join,
|
|
|
|
joinMuc);
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
break;
|
2014-10-14 20:09:20 -04:00
|
|
|
}
|
2014-12-21 15:43:58 -05:00
|
|
|
}
|
2014-12-14 12:10:46 -05:00
|
|
|
conversation.populateWithMessages(ConversationFragment.this.messageList);
|
|
|
|
for (Message message : this.messageList) {
|
|
|
|
if (message.getEncryption() == Message.ENCRYPTION_PGP
|
|
|
|
&& (message.getStatus() == Message.STATUS_RECEIVED || message
|
2014-12-21 15:43:58 -05:00
|
|
|
.getStatus() >= Message.STATUS_SEND)
|
2014-12-14 12:10:46 -05:00
|
|
|
&& message.getDownloadable() == null) {
|
|
|
|
if (!mEncryptedMessages.contains(message)) {
|
|
|
|
mEncryptedMessages.add(message);
|
2014-12-02 18:54:07 -05:00
|
|
|
}
|
2014-12-21 15:43:58 -05:00
|
|
|
}
|
2014-11-18 08:43:15 -05:00
|
|
|
}
|
2014-12-14 12:10:46 -05:00
|
|
|
decryptNext();
|
|
|
|
updateStatusMessages();
|
2014-11-18 08:43:15 -05:00
|
|
|
this.messageListAdapter.notifyDataSetChanged();
|
|
|
|
updateChatMsgHint();
|
|
|
|
if (!activity.isConversationsOverviewVisable() || !activity.isConversationsOverviewHideable()) {
|
|
|
|
activity.xmppConnectionService.markRead(conversation, true);
|
|
|
|
activity.updateConversationList();
|
|
|
|
}
|
|
|
|
this.updateSendButton();
|
2014-03-02 23:01:02 -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-10-14 20:09:20 -04:00
|
|
|
private void decryptNext() {
|
|
|
|
Message next = this.mEncryptedMessages.peek();
|
|
|
|
PgpEngine engine = activity.xmppConnectionService.getPgpEngine();
|
2014-10-15 13:32:12 -04:00
|
|
|
|
|
|
|
if (next != null && engine != null && !mDecryptJobRunning) {
|
2014-10-14 20:09:20 -04: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;
|
2014-12-01 05:18:55 -05:00
|
|
|
try {
|
|
|
|
mEncryptedMessages.remove();
|
|
|
|
} catch (final NoSuchElementException ignored) {
|
|
|
|
|
|
|
|
}
|
2014-10-14 20:09:20 -04:00
|
|
|
activity.xmppConnectionService.updateMessage(message);
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void error(int error, Message message) {
|
|
|
|
message.setEncryption(Message.ENCRYPTION_DECRYPTION_FAILED);
|
|
|
|
mDecryptJobRunning = false;
|
2014-12-01 05:18:55 -05:00
|
|
|
try {
|
|
|
|
mEncryptedMessages.remove();
|
|
|
|
} catch (final NoSuchElementException ignored) {
|
|
|
|
|
|
|
|
}
|
2014-10-14 20:09:20 -04:00
|
|
|
activity.xmppConnectionService.updateConversationUi();
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|
2014-10-15 13:32:12 -04:00
|
|
|
|
2014-06-10 11:01:19 -04:00
|
|
|
private void messageSent() {
|
|
|
|
int size = this.messageList.size();
|
2014-10-06 16:03:01 -04:00
|
|
|
messagesView.setSelection(size - 1);
|
2014-07-31 07:26:05 -04:00
|
|
|
mEditMessage.setText("");
|
2014-08-10 09:27:44 -04:00
|
|
|
updateChatMsgHint();
|
2014-06-10 11:01:19 -04:00
|
|
|
}
|
2014-06-14 10:59:07 -04:00
|
|
|
|
2014-09-10 11:59:57 -04:00
|
|
|
public void updateSendButton() {
|
|
|
|
Conversation c = this.conversation;
|
|
|
|
if (activity.useSendButtonToIndicateStatus() && c != null
|
2014-11-15 11:09:02 -05:00
|
|
|
&& c.getAccount().getStatus() == Account.State.ONLINE) {
|
2014-09-10 11:59:57 -04:00
|
|
|
if (c.getMode() == Conversation.MODE_SINGLE) {
|
|
|
|
switch (c.getContact().getMostAvailableStatus()) {
|
2014-11-04 12:52:29 -05:00
|
|
|
case Presences.CHAT:
|
|
|
|
this.mSendButton
|
2014-12-21 15:43:58 -05:00
|
|
|
.setImageResource(R.drawable.ic_action_send_now_online);
|
2014-11-04 12:52:29 -05:00
|
|
|
break;
|
|
|
|
case Presences.ONLINE:
|
|
|
|
this.mSendButton
|
2014-12-21 15:43:58 -05:00
|
|
|
.setImageResource(R.drawable.ic_action_send_now_online);
|
2014-11-04 12:52:29 -05:00
|
|
|
break;
|
|
|
|
case Presences.AWAY:
|
|
|
|
this.mSendButton
|
2014-12-21 15:43:58 -05:00
|
|
|
.setImageResource(R.drawable.ic_action_send_now_away);
|
2014-11-04 12:52:29 -05:00
|
|
|
break;
|
|
|
|
case Presences.XA:
|
|
|
|
this.mSendButton
|
2014-12-21 15:43:58 -05:00
|
|
|
.setImageResource(R.drawable.ic_action_send_now_away);
|
2014-11-04 12:52:29 -05:00
|
|
|
break;
|
|
|
|
case Presences.DND:
|
|
|
|
this.mSendButton
|
2014-12-21 15:43:58 -05:00
|
|
|
.setImageResource(R.drawable.ic_action_send_now_dnd);
|
2014-11-04 12:52:29 -05:00
|
|
|
break;
|
|
|
|
default:
|
|
|
|
this.mSendButton
|
2014-12-21 15:43:58 -05:00
|
|
|
.setImageResource(R.drawable.ic_action_send_now_offline);
|
2014-11-04 12:52:29 -05:00
|
|
|
break;
|
2014-09-10 11:59:57 -04:00
|
|
|
}
|
|
|
|
} else if (c.getMode() == Conversation.MODE_MULTI) {
|
|
|
|
if (c.getMucOptions().online()) {
|
|
|
|
this.mSendButton
|
2014-12-21 15:43:58 -05:00
|
|
|
.setImageResource(R.drawable.ic_action_send_now_online);
|
2014-09-10 11:59:57 -04:00
|
|
|
} else {
|
|
|
|
this.mSendButton
|
2014-12-21 15:43:58 -05:00
|
|
|
.setImageResource(R.drawable.ic_action_send_now_offline);
|
2014-09-10 11:59:57 -04:00
|
|
|
}
|
|
|
|
} else {
|
|
|
|
this.mSendButton
|
2014-12-21 15:43:58 -05:00
|
|
|
.setImageResource(R.drawable.ic_action_send_now_offline);
|
2014-09-10 11:59:57 -04:00
|
|
|
}
|
|
|
|
} else {
|
|
|
|
this.mSendButton
|
2014-12-21 15:43:58 -05:00
|
|
|
.setImageResource(R.drawable.ic_action_send_now_offline);
|
2014-09-10 11:59:57 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-06-04 15:40:17 -04:00
|
|
|
protected void updateStatusMessages() {
|
2014-11-18 08:43:15 -05:00
|
|
|
synchronized (this.messageList) {
|
|
|
|
if (conversation.getMode() == Conversation.MODE_SINGLE) {
|
|
|
|
for (int i = this.messageList.size() - 1; i >= 0; --i) {
|
|
|
|
if (this.messageList.get(i).getStatus() == Message.STATUS_RECEIVED) {
|
2014-09-08 14:29:57 -04:00
|
|
|
return;
|
2014-11-18 08:43:15 -05:00
|
|
|
} else {
|
|
|
|
if (this.messageList.get(i).getStatus() == Message.STATUS_SEND_DISPLAYED) {
|
2014-12-20 06:52:08 -05:00
|
|
|
this.messageList.add(i + 1,Message.createStatusMessage(conversation));
|
2014-11-18 08:43:15 -05:00
|
|
|
return;
|
|
|
|
}
|
2014-06-04 15:40:17 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2014-02-16 10:32:15 -05:00
|
|
|
|
2014-10-28 12:15:13 -04:00
|
|
|
protected void makeFingerprintWarning() {
|
2014-11-10 16:03:23 -05:00
|
|
|
if (conversation.smpRequested()) {
|
2015-01-01 19:21:14 -05:00
|
|
|
showSnackbar(R.string.smp_requested, R.string.verify, new OnClickListener() {
|
|
|
|
@Override
|
|
|
|
public void onClick(View view) {
|
|
|
|
Intent intent = new Intent(activity, VerifyOTRActivity.class);
|
|
|
|
intent.setAction(VerifyOTRActivity.ACTION_VERIFY_CONTACT);
|
|
|
|
intent.putExtra("contact", conversation.getContact().getJid().toBareJid().toString());
|
|
|
|
intent.putExtra("account", conversation.getAccount().getJid().toBareJid().toString());
|
|
|
|
intent.putExtra("mode",VerifyOTRActivity.MODE_ANSWER_QUESTION);
|
|
|
|
startActivity(intent);
|
|
|
|
}
|
|
|
|
});
|
2014-11-10 16:03:23 -05:00
|
|
|
} else if (conversation.hasValidOtrSession() && (conversation.getOtrSession().getSessionStatus() == SessionStatus.ENCRYPTED)
|
2014-11-10 13:23:54 -05:00
|
|
|
&& (!conversation.isOtrFingerprintVerified())) {
|
2014-11-10 16:03:23 -05:00
|
|
|
showSnackbar(R.string.unknown_otr_fingerprint, R.string.verify, clickToVerify);
|
2014-12-21 15:43:58 -05:00
|
|
|
}
|
2014-02-16 10:32:15 -05:00
|
|
|
}
|
2014-07-18 13:36:29 -04:00
|
|
|
|
2014-12-21 15:43:58 -05:00
|
|
|
protected void showSnackbar(final int message, final int action,
|
|
|
|
final OnClickListener clickListener) {
|
2014-07-09 15:45:03 -04:00
|
|
|
snackbar.setVisibility(View.VISIBLE);
|
2014-08-12 17:23:25 -04:00
|
|
|
snackbar.setOnClickListener(null);
|
2014-07-09 15:45:03 -04:00
|
|
|
snackbarMessage.setText(message);
|
2014-08-12 17:23:25 -04:00
|
|
|
snackbarMessage.setOnClickListener(null);
|
2014-12-21 15:43:58 -05:00
|
|
|
snackbarAction.setVisibility(View.VISIBLE);
|
2014-07-09 15:45:03 -04:00
|
|
|
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,
|
2014-12-21 15:43:58 -05:00
|
|
|
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,
|
2014-12-21 15:43:58 -05:00
|
|
|
int which) {
|
2014-06-01 13:29:57 -04:00
|
|
|
conversation
|
2014-12-21 15:43:58 -05:00
|
|
|
.setNextEncryption(Message.ENCRYPTION_NONE);
|
2014-09-28 09:21:56 -04:00
|
|
|
xmppService.databaseBackend
|
2014-12-21 15:43:58 -05:00
|
|
|
.updateConversation(conversation);
|
2014-06-01 13:29:57 -04:00
|
|
|
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
|
2014-12-21 15:43:58 -05:00
|
|
|
.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,
|
2014-12-21 15:43:58 -05:00
|
|
|
int which) {
|
2014-06-01 13:29:57 -04:00
|
|
|
conversation
|
2014-12-21 15:43:58 -05:00
|
|
|
.setNextEncryption(Message.ENCRYPTION_NONE);
|
2014-06-01 13:29:57 -04:00
|
|
|
message.setEncryption(Message.ENCRYPTION_NONE);
|
2014-09-28 09:21:56 -04:00
|
|
|
xmppService.databaseBackend
|
2014-12-21 15:43:58 -05:00
|
|
|
.updateConversation(conversation);
|
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,
|
2014-12-21 15:43:58 -05:00
|
|
|
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;
|
2014-11-09 19:24:35 -05:00
|
|
|
activity.selectPresence(message.getConversation(),
|
2014-11-10 16:03:23 -05:00
|
|
|
new OnPresenceSelected() {
|
2014-02-18 19:35:23 -05:00
|
|
|
|
2014-11-10 16:03:23 -05:00
|
|
|
@Override
|
|
|
|
public void onPresenceSelected() {
|
|
|
|
message.setCounterpart(conversation.getNextCounterpart());
|
|
|
|
xmppService.sendMessage(message);
|
|
|
|
messageSent();
|
|
|
|
}
|
|
|
|
});
|
2014-02-16 13:30:22 -05:00
|
|
|
}
|
2014-02-18 19:35:23 -05:00
|
|
|
|
2014-11-07 09:38:20 -05:00
|
|
|
public void appendText(String text) {
|
|
|
|
String previous = this.mEditMessage.getText().toString();
|
|
|
|
if (previous.length() != 0 && !previous.endsWith(" ")) {
|
|
|
|
text = " " + text;
|
|
|
|
}
|
|
|
|
this.mEditMessage.append(text);
|
2014-03-13 16:37:27 -04:00
|
|
|
}
|
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
|
|
|
}
|