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;
|
2014-02-19 00:35:23 +00:00
|
|
|
import java.util.HashMap;
|
2014-01-27 19:40:42 +00:00
|
|
|
import java.util.List;
|
2014-02-16 15:32:15 +00:00
|
|
|
import java.util.Set;
|
|
|
|
|
|
|
|
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-02-28 17:46:01 +00:00
|
|
|
import eu.siacs.conversations.entities.Contact;
|
|
|
|
import eu.siacs.conversations.entities.Conversation;
|
|
|
|
import eu.siacs.conversations.entities.Message;
|
2014-03-03 04:01:02 +00:00
|
|
|
import eu.siacs.conversations.entities.MucOptions;
|
2014-03-04 03:09:15 +00:00
|
|
|
import eu.siacs.conversations.entities.MucOptions.OnRenameListener;
|
2014-05-13 13:37:11 +00:00
|
|
|
import eu.siacs.conversations.services.ImageProvider;
|
2014-02-28 17:46:01 +00:00
|
|
|
import eu.siacs.conversations.services.XmppConnectionService;
|
|
|
|
import eu.siacs.conversations.utils.UIHelper;
|
2014-04-22 16:46:40 +00:00
|
|
|
import eu.siacs.conversations.xmpp.jingle.JingleConnection;
|
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-03-13 02:52:41 +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;
|
2014-02-10 14:24:34 +00:00
|
|
|
import android.content.SharedPreferences;
|
2014-02-27 23:22:56 +00:00
|
|
|
import android.content.IntentSender.SendIntentException;
|
2014-02-19 00:35:23 +00:00
|
|
|
import android.graphics.Bitmap;
|
2014-01-26 02:27:55 +00:00
|
|
|
import android.graphics.Typeface;
|
2014-01-24 01:04:05 +00:00
|
|
|
import android.os.Bundle;
|
2014-02-10 14:24:34 +00:00
|
|
|
import android.preference.PreferenceManager;
|
2014-05-07 10:59:15 +00:00
|
|
|
import android.text.Editable;
|
|
|
|
import android.text.Selection;
|
2014-04-07 18:05:45 +00:00
|
|
|
import android.util.DisplayMetrics;
|
2014-02-19 00:35:23 +00:00
|
|
|
import android.util.Log;
|
2014-06-01 16:52:27 +00:00
|
|
|
import android.view.Gravity;
|
2014-01-24 01:04:05 +00:00
|
|
|
import android.view.LayoutInflater;
|
|
|
|
import android.view.View;
|
2014-01-26 02:27:55 +00:00
|
|
|
import android.view.View.OnClickListener;
|
2014-06-02 19:27:40 +00:00
|
|
|
import android.view.View.OnLongClickListener;
|
2014-01-24 01:04:05 +00:00
|
|
|
import android.view.ViewGroup;
|
2014-06-14 14:59:07 +00:00
|
|
|
import android.widget.AbsListView.OnScrollListener;
|
|
|
|
import android.widget.AbsListView;
|
2014-01-26 02:27:55 +00:00
|
|
|
import android.widget.ArrayAdapter;
|
2014-04-22 16:46:40 +00:00
|
|
|
import android.widget.Button;
|
2014-01-26 02:27:55 +00:00
|
|
|
import android.widget.EditText;
|
2014-02-16 15:32:15 +00:00
|
|
|
import android.widget.LinearLayout;
|
2014-01-26 02:27:55 +00:00
|
|
|
import android.widget.ListView;
|
|
|
|
import android.widget.ImageButton;
|
|
|
|
import android.widget.ImageView;
|
|
|
|
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-02-02 15:33:34 +00:00
|
|
|
protected ArrayAdapter<Message> messageListAdapter;
|
2014-02-10 02:34:00 +00:00
|
|
|
protected Contact contact;
|
2014-02-19 00:35:23 +00:00
|
|
|
protected BitmapCache mBitmapCache = new BitmapCache();
|
2014-02-16 15:32:15 +00:00
|
|
|
|
2014-02-27 23:22:56 +00:00
|
|
|
protected String queuedPqpMessage = null;
|
|
|
|
|
2014-02-13 22:40:08 +00:00
|
|
|
private EditText chatMsg;
|
2014-03-13 20:37:27 +00:00
|
|
|
private String pastedText = null;
|
2014-02-27 23:22:56 +00:00
|
|
|
|
2014-02-20 16:00:50 +00:00
|
|
|
protected Bitmap selfBitmap;
|
2014-05-07 10:59:15 +00:00
|
|
|
|
2014-03-14 21:40:56 +00:00
|
|
|
private boolean useSubject = true;
|
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-02-16 15:32:15 +00:00
|
|
|
|
|
|
|
private OnClickListener sendMsgListener = new OnClickListener() {
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void onClick(View v) {
|
|
|
|
if (chatMsg.getText().length() < 1)
|
|
|
|
return;
|
2014-02-16 18:30:22 +00:00
|
|
|
Message message = new Message(conversation, chatMsg.getText()
|
2014-05-07 10:33:55 +00:00
|
|
|
.toString(), conversation.getNextEncryption());
|
|
|
|
if (conversation.getNextEncryption() == Message.ENCRYPTION_OTR) {
|
2014-02-16 18:30:22 +00:00
|
|
|
sendOtrMessage(message);
|
2014-05-07 10:33:55 +00:00
|
|
|
} else if (conversation.getNextEncryption() == Message.ENCRYPTION_PGP) {
|
2014-02-27 23:22:56 +00:00
|
|
|
sendPgpMessage(message);
|
2014-02-16 15:32:15 +00:00
|
|
|
} else {
|
2014-02-16 18:30:22 +00:00
|
|
|
sendPlainTextMessage(message);
|
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-04-06 13:34:08 +00:00
|
|
|
Log.d("xmppService", "couldnt fire intent");
|
2014-02-27 23:22:56 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
};
|
2014-03-13 02:52:41 +00:00
|
|
|
|
2014-02-28 01:58:15 +00:00
|
|
|
private LinearLayout pgpInfo;
|
2014-03-03 04:01:02 +00:00
|
|
|
private LinearLayout mucError;
|
|
|
|
private TextView mucErrorText;
|
|
|
|
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-03-13 02:52:41 +00:00
|
|
|
Intent intent = new Intent(getActivity(), MucDetailsActivity.class);
|
2014-03-05 14:41:14 +00:00
|
|
|
intent.setAction(MucDetailsActivity.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-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;
|
|
|
|
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 11:22:09 +00:00
|
|
|
private ConversationActivity activity;
|
2014-03-13 02:52:41 +00:00
|
|
|
|
2014-02-28 01:58:15 +00:00
|
|
|
public void hidePgpPassphraseBox() {
|
|
|
|
pgpInfo.setVisibility(View.GONE);
|
|
|
|
}
|
2014-02-16 15:32:15 +00:00
|
|
|
|
|
|
|
public void updateChatMsgHint() {
|
2014-06-01 17:08:42 +00:00
|
|
|
switch (conversation.getNextEncryption()) {
|
|
|
|
case Message.ENCRYPTION_NONE:
|
|
|
|
chatMsg.setHint(getString(R.string.send_plain_text_message));
|
|
|
|
break;
|
|
|
|
case Message.ENCRYPTION_OTR:
|
|
|
|
chatMsg.setHint(getString(R.string.send_otr_message));
|
|
|
|
break;
|
|
|
|
case Message.ENCRYPTION_PGP:
|
|
|
|
chatMsg.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) {
|
2014-01-26 02:27:55 +00:00
|
|
|
|
2014-04-07 18:05:45 +00:00
|
|
|
final DisplayMetrics metrics = getResources().getDisplayMetrics();
|
2014-05-07 10:59:15 +00:00
|
|
|
|
2014-01-27 19:40:42 +00:00
|
|
|
this.inflater = inflater;
|
2014-01-26 02:27:55 +00:00
|
|
|
|
2014-01-27 19:40:42 +00:00
|
|
|
final View view = inflater.inflate(R.layout.fragment_conversation,
|
|
|
|
container, false);
|
2014-02-13 22:40:08 +00:00
|
|
|
chatMsg = (EditText) view.findViewById(R.id.textinput);
|
2014-05-07 10:59:15 +00:00
|
|
|
|
2014-02-16 15:32:15 +00:00
|
|
|
ImageButton sendButton = (ImageButton) view
|
|
|
|
.findViewById(R.id.textSendButton);
|
|
|
|
sendButton.setOnClickListener(this.sendMsgListener);
|
2014-03-13 02:52:41 +00:00
|
|
|
|
2014-02-28 01:58:15 +00:00
|
|
|
pgpInfo = (LinearLayout) view.findViewById(R.id.pgp_keyentry);
|
|
|
|
pgpInfo.setOnClickListener(clickToDecryptListener);
|
2014-03-03 04:01:02 +00:00
|
|
|
mucError = (LinearLayout) view.findViewById(R.id.muc_error);
|
2014-03-13 02:52:41 +00:00
|
|
|
mucError.setOnClickListener(clickToMuc);
|
2014-03-03 04:01:02 +00:00
|
|
|
mucErrorText = (TextView) view.findViewById(R.id.muc_error_msg);
|
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-02-27 23:22:56 +00:00
|
|
|
|
2014-02-02 15:33:34 +00:00
|
|
|
messageListAdapter = new ArrayAdapter<Message>(this.getActivity()
|
2014-02-16 15:32:15 +00:00
|
|
|
.getApplicationContext(), R.layout.message_sent,
|
|
|
|
this.messageList) {
|
2014-01-27 19:40:42 +00:00
|
|
|
|
|
|
|
private static final int SENT = 0;
|
|
|
|
private static final int RECIEVED = 1;
|
2014-06-04 19:40:17 +00:00
|
|
|
private static final int STATUS = 2;
|
2014-02-16 15:32:15 +00:00
|
|
|
|
2014-01-27 19:40:42 +00:00
|
|
|
@Override
|
|
|
|
public int getViewTypeCount() {
|
2014-06-04 19:40:17 +00:00
|
|
|
return 3;
|
2014-01-27 19:40:42 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public int getItemViewType(int position) {
|
2014-06-04 19:40:17 +00:00
|
|
|
if (getItem(position).getType() == Message.TYPE_STATUS) {
|
|
|
|
return STATUS;
|
2014-06-06 09:39:17 +00:00
|
|
|
} else if (getItem(position).getStatus() <= Message.STATUS_RECIEVED) {
|
2014-01-27 19:40:42 +00:00
|
|
|
return RECIEVED;
|
|
|
|
} else {
|
|
|
|
return SENT;
|
|
|
|
}
|
|
|
|
}
|
2014-01-26 02:27:55 +00:00
|
|
|
|
2014-05-08 09:53:00 +00:00
|
|
|
private void displayStatus(ViewHolder viewHolder, Message message) {
|
|
|
|
String filesize = null;
|
|
|
|
String info = null;
|
|
|
|
boolean error = false;
|
2014-06-13 13:05:35 +00:00
|
|
|
boolean multiReceived = message.getConversation().getMode() == Conversation.MODE_MULTI
|
|
|
|
&& message.getStatus() <= Message.STATUS_RECIEVED;
|
2014-05-08 09:53:00 +00:00
|
|
|
if (message.getType() == Message.TYPE_IMAGE) {
|
|
|
|
String[] fileParams = message.getBody().split(",");
|
2014-05-10 09:03:32 +00:00
|
|
|
try {
|
|
|
|
long size = Long.parseLong(fileParams[0]);
|
|
|
|
filesize = size / 1024 + " KB";
|
|
|
|
} catch (NumberFormatException e) {
|
|
|
|
filesize = "0 KB";
|
|
|
|
}
|
2014-05-08 09:53:00 +00:00
|
|
|
}
|
|
|
|
switch (message.getStatus()) {
|
2014-06-12 21:04:28 +00:00
|
|
|
case Message.STATUS_WAITING:
|
|
|
|
info = getString(R.string.waiting);
|
|
|
|
break;
|
2014-05-08 09:53:00 +00:00
|
|
|
case Message.STATUS_UNSEND:
|
|
|
|
info = getString(R.string.sending);
|
|
|
|
break;
|
|
|
|
case Message.STATUS_OFFERED:
|
|
|
|
info = getString(R.string.offering);
|
|
|
|
break;
|
|
|
|
case Message.STATUS_SEND_FAILED:
|
|
|
|
info = getString(R.string.send_failed);
|
|
|
|
error = true;
|
|
|
|
break;
|
|
|
|
case Message.STATUS_SEND_REJECTED:
|
|
|
|
info = getString(R.string.send_rejected);
|
|
|
|
error = true;
|
|
|
|
break;
|
|
|
|
default:
|
2014-06-13 13:05:35 +00:00
|
|
|
if (multiReceived) {
|
2014-05-08 09:53:00 +00:00
|
|
|
info = message.getCounterpart();
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
if (error) {
|
|
|
|
viewHolder.time.setTextColor(0xFFe92727);
|
|
|
|
} else {
|
|
|
|
viewHolder.time.setTextColor(0xFF8e8e8e);
|
|
|
|
}
|
|
|
|
if (message.getEncryption() == Message.ENCRYPTION_NONE) {
|
|
|
|
viewHolder.indicator.setVisibility(View.GONE);
|
|
|
|
} else {
|
|
|
|
viewHolder.indicator.setVisibility(View.VISIBLE);
|
|
|
|
}
|
|
|
|
|
2014-06-01 17:29:57 +00:00
|
|
|
String formatedTime = UIHelper.readableTimeDifference(
|
|
|
|
getContext(), message.getTimeSent());
|
2014-05-08 09:53:00 +00:00
|
|
|
if (message.getStatus() <= Message.STATUS_RECIEVED) {
|
|
|
|
if ((filesize != null) && (info != null)) {
|
|
|
|
viewHolder.time.setText(filesize + " \u00B7 " + info);
|
|
|
|
} else if ((filesize == null) && (info != null)) {
|
|
|
|
viewHolder.time.setText(formatedTime + " \u00B7 "
|
|
|
|
+ info);
|
|
|
|
} else if ((filesize != null) && (info == null)) {
|
|
|
|
viewHolder.time.setText(formatedTime + " \u00B7 "
|
|
|
|
+ filesize);
|
|
|
|
} else {
|
|
|
|
viewHolder.time.setText(formatedTime);
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
if ((filesize != null) && (info != null)) {
|
|
|
|
viewHolder.time.setText(filesize + " \u00B7 " + info);
|
|
|
|
} else if ((filesize == null) && (info != null)) {
|
2014-06-13 13:05:35 +00:00
|
|
|
if (error) {
|
|
|
|
viewHolder.time.setText(info + " \u00B7 "
|
2014-06-14 14:59:07 +00:00
|
|
|
+ formatedTime);
|
2014-06-13 13:05:35 +00:00
|
|
|
} else {
|
|
|
|
viewHolder.time.setText(info);
|
|
|
|
}
|
2014-05-08 09:53:00 +00:00
|
|
|
} else if ((filesize != null) && (info == null)) {
|
|
|
|
viewHolder.time.setText(filesize + " \u00B7 "
|
|
|
|
+ formatedTime);
|
|
|
|
} else {
|
|
|
|
viewHolder.time.setText(formatedTime);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
private void displayInfoMessage(ViewHolder viewHolder, int r) {
|
2014-05-19 13:39:50 +00:00
|
|
|
if (viewHolder.download_button != null) {
|
2014-05-15 08:27:36 +00:00
|
|
|
viewHolder.download_button.setVisibility(View.GONE);
|
|
|
|
}
|
2014-05-08 09:53:00 +00:00
|
|
|
viewHolder.image.setVisibility(View.GONE);
|
|
|
|
viewHolder.messageBody.setVisibility(View.VISIBLE);
|
|
|
|
viewHolder.messageBody.setText(getString(r));
|
|
|
|
viewHolder.messageBody.setTextColor(0xff33B5E5);
|
|
|
|
viewHolder.messageBody.setTypeface(null, Typeface.ITALIC);
|
2014-06-09 19:25:01 +00:00
|
|
|
viewHolder.messageBody.setTextIsSelectable(false);
|
2014-05-08 09:53:00 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
private void displayDecryptionFailed(ViewHolder viewHolder) {
|
2014-06-20 15:30:19 +00:00
|
|
|
if (viewHolder.download_button != null) {
|
|
|
|
viewHolder.download_button.setVisibility(View.GONE);
|
|
|
|
}
|
2014-05-08 09:53:00 +00:00
|
|
|
viewHolder.image.setVisibility(View.GONE);
|
|
|
|
viewHolder.messageBody.setVisibility(View.VISIBLE);
|
|
|
|
viewHolder.messageBody
|
|
|
|
.setText(getString(R.string.decryption_failed));
|
|
|
|
viewHolder.messageBody.setTextColor(0xFFe92727);
|
|
|
|
viewHolder.messageBody.setTypeface(null, Typeface.NORMAL);
|
2014-06-09 19:25:01 +00:00
|
|
|
viewHolder.messageBody.setTextIsSelectable(false);
|
2014-05-08 09:53:00 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
private void displayTextMessage(ViewHolder viewHolder, String text) {
|
|
|
|
if (viewHolder.download_button != null) {
|
|
|
|
viewHolder.download_button.setVisibility(View.GONE);
|
|
|
|
}
|
|
|
|
viewHolder.image.setVisibility(View.GONE);
|
|
|
|
viewHolder.messageBody.setVisibility(View.VISIBLE);
|
|
|
|
if (text != null) {
|
|
|
|
viewHolder.messageBody.setText(text.trim());
|
|
|
|
} else {
|
|
|
|
viewHolder.messageBody.setText("");
|
|
|
|
}
|
|
|
|
viewHolder.messageBody.setTextColor(0xff333333);
|
|
|
|
viewHolder.messageBody.setTypeface(null, Typeface.NORMAL);
|
2014-06-09 19:25:01 +00:00
|
|
|
viewHolder.messageBody.setTextIsSelectable(true);
|
2014-05-08 09:53:00 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
private void displayImageMessage(ViewHolder viewHolder,
|
|
|
|
final Message message) {
|
|
|
|
if (viewHolder.download_button != null) {
|
|
|
|
viewHolder.download_button.setVisibility(View.GONE);
|
|
|
|
}
|
|
|
|
viewHolder.messageBody.setVisibility(View.GONE);
|
|
|
|
viewHolder.image.setVisibility(View.VISIBLE);
|
|
|
|
String[] fileParams = message.getBody().split(",");
|
|
|
|
if (fileParams.length == 3) {
|
|
|
|
double target = metrics.density * 288;
|
|
|
|
int w = Integer.parseInt(fileParams[1]);
|
|
|
|
int h = Integer.parseInt(fileParams[2]);
|
|
|
|
int scalledW;
|
|
|
|
int scalledH;
|
|
|
|
if (w <= h) {
|
|
|
|
scalledW = (int) (w / ((double) h / target));
|
|
|
|
scalledH = (int) target;
|
|
|
|
} else {
|
|
|
|
scalledW = (int) target;
|
|
|
|
scalledH = (int) (h / ((double) w / target));
|
|
|
|
}
|
|
|
|
viewHolder.image
|
|
|
|
.setLayoutParams(new LinearLayout.LayoutParams(
|
|
|
|
scalledW, scalledH));
|
|
|
|
}
|
|
|
|
activity.loadBitmap(message, viewHolder.image);
|
|
|
|
viewHolder.image.setOnClickListener(new OnClickListener() {
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void onClick(View v) {
|
|
|
|
Intent intent = new Intent(Intent.ACTION_VIEW);
|
2014-05-19 13:39:50 +00:00
|
|
|
intent.setDataAndType(
|
|
|
|
ImageProvider.getContentUri(message), "image/*");
|
2014-05-08 09:53:00 +00:00
|
|
|
startActivity(intent);
|
|
|
|
}
|
|
|
|
});
|
2014-06-06 09:39:17 +00:00
|
|
|
viewHolder.image
|
|
|
|
.setOnLongClickListener(new OnLongClickListener() {
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public boolean onLongClick(View v) {
|
|
|
|
Intent shareIntent = new Intent();
|
|
|
|
shareIntent.setAction(Intent.ACTION_SEND);
|
|
|
|
shareIntent.putExtra(Intent.EXTRA_STREAM,
|
|
|
|
ImageProvider.getContentUri(message));
|
|
|
|
shareIntent.setType("image/webp");
|
|
|
|
startActivity(Intent.createChooser(shareIntent,
|
|
|
|
getText(R.string.share_with)));
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
});
|
2014-05-08 09:53:00 +00:00
|
|
|
}
|
|
|
|
|
2014-01-26 02:27:55 +00:00
|
|
|
@Override
|
|
|
|
public View getView(int position, View view, ViewGroup parent) {
|
2014-04-21 17:51:03 +00:00
|
|
|
final Message item = getItem(position);
|
2014-01-27 19:40:42 +00:00
|
|
|
int type = getItemViewType(position);
|
2014-02-19 00:35:23 +00:00
|
|
|
ViewHolder viewHolder;
|
2014-01-27 19:40:42 +00:00
|
|
|
if (view == null) {
|
2014-02-19 07:21:33 +00:00
|
|
|
viewHolder = new ViewHolder();
|
2014-01-27 19:40:42 +00:00
|
|
|
switch (type) {
|
|
|
|
case SENT:
|
|
|
|
view = (View) inflater.inflate(R.layout.message_sent,
|
|
|
|
null);
|
2014-06-09 19:25:01 +00:00
|
|
|
viewHolder.message_box = (LinearLayout) view
|
|
|
|
.findViewById(R.id.message_box);
|
2014-04-15 13:19:02 +00:00
|
|
|
viewHolder.contact_picture = (ImageView) view
|
2014-02-19 00:35:23 +00:00
|
|
|
.findViewById(R.id.message_photo);
|
2014-04-15 13:19:02 +00:00
|
|
|
viewHolder.contact_picture.setImageBitmap(selfBitmap);
|
2014-06-04 19:40:17 +00:00
|
|
|
viewHolder.indicator = (ImageView) view
|
|
|
|
.findViewById(R.id.security_indicator);
|
|
|
|
viewHolder.image = (ImageView) view
|
|
|
|
.findViewById(R.id.message_image);
|
|
|
|
viewHolder.messageBody = (TextView) view
|
|
|
|
.findViewById(R.id.message_body);
|
|
|
|
viewHolder.time = (TextView) view
|
|
|
|
.findViewById(R.id.message_time);
|
|
|
|
view.setTag(viewHolder);
|
2014-01-27 19:40:42 +00:00
|
|
|
break;
|
|
|
|
case RECIEVED:
|
|
|
|
view = (View) inflater.inflate(
|
|
|
|
R.layout.message_recieved, null);
|
2014-06-09 19:25:01 +00:00
|
|
|
viewHolder.message_box = (LinearLayout) view
|
|
|
|
.findViewById(R.id.message_box);
|
2014-04-15 13:19:02 +00:00
|
|
|
viewHolder.contact_picture = (ImageView) view
|
2014-02-19 00:35:23 +00:00
|
|
|
.findViewById(R.id.message_photo);
|
2014-05-07 10:59:15 +00:00
|
|
|
|
|
|
|
viewHolder.download_button = (Button) view
|
|
|
|
.findViewById(R.id.download_button);
|
|
|
|
|
2014-02-19 07:21:33 +00:00
|
|
|
if (item.getConversation().getMode() == Conversation.MODE_SINGLE) {
|
2014-03-13 02:52:41 +00:00
|
|
|
|
2014-05-07 10:59:15 +00:00
|
|
|
viewHolder.contact_picture
|
|
|
|
.setImageBitmap(mBitmapCache.get(
|
|
|
|
item.getConversation().getName(
|
|
|
|
useSubject), item
|
|
|
|
.getConversation()
|
|
|
|
.getContact(),
|
2014-03-13 02:52:41 +00:00
|
|
|
getActivity()
|
|
|
|
.getApplicationContext()));
|
|
|
|
|
2014-06-04 19:40:17 +00:00
|
|
|
}
|
|
|
|
viewHolder.indicator = (ImageView) view
|
|
|
|
.findViewById(R.id.security_indicator);
|
|
|
|
viewHolder.image = (ImageView) view
|
|
|
|
.findViewById(R.id.message_image);
|
|
|
|
viewHolder.messageBody = (TextView) view
|
|
|
|
.findViewById(R.id.message_body);
|
|
|
|
viewHolder.time = (TextView) view
|
|
|
|
.findViewById(R.id.message_time);
|
|
|
|
view.setTag(viewHolder);
|
|
|
|
break;
|
|
|
|
case STATUS:
|
2014-06-06 09:39:17 +00:00
|
|
|
view = (View) inflater.inflate(R.layout.message_status,
|
|
|
|
null);
|
2014-06-04 19:40:17 +00:00
|
|
|
viewHolder.contact_picture = (ImageView) view
|
|
|
|
.findViewById(R.id.message_photo);
|
|
|
|
if (item.getConversation().getMode() == Conversation.MODE_SINGLE) {
|
|
|
|
|
|
|
|
viewHolder.contact_picture
|
|
|
|
.setImageBitmap(mBitmapCache.get(
|
|
|
|
item.getConversation().getName(
|
|
|
|
useSubject), item
|
|
|
|
.getConversation()
|
|
|
|
.getContact(),
|
|
|
|
getActivity()
|
|
|
|
.getApplicationContext()));
|
2014-06-04 23:57:00 +00:00
|
|
|
viewHolder.contact_picture.setAlpha(128);
|
2014-06-04 19:40:17 +00:00
|
|
|
|
2014-02-19 07:21:33 +00:00
|
|
|
}
|
2014-02-19 00:35:23 +00:00
|
|
|
break;
|
|
|
|
default:
|
|
|
|
viewHolder = null;
|
2014-01-27 19:40:42 +00:00
|
|
|
break;
|
|
|
|
}
|
2014-02-19 00:35:23 +00:00
|
|
|
} else {
|
|
|
|
viewHolder = (ViewHolder) view.getTag();
|
2014-01-27 19:40:42 +00:00
|
|
|
}
|
2014-06-06 09:39:17 +00:00
|
|
|
|
2014-06-04 19:40:17 +00:00
|
|
|
if (type == STATUS) {
|
|
|
|
return view;
|
|
|
|
}
|
2014-05-07 10:59:15 +00:00
|
|
|
|
2014-01-27 19:40:42 +00:00
|
|
|
if (type == RECIEVED) {
|
2014-02-27 23:22:56 +00:00
|
|
|
if (item.getConversation().getMode() == Conversation.MODE_MULTI) {
|
2014-05-20 09:44:43 +00:00
|
|
|
viewHolder.contact_picture.setImageBitmap(mBitmapCache
|
|
|
|
.get(item.getCounterpart(), null, getActivity()
|
|
|
|
.getApplicationContext()));
|
|
|
|
viewHolder.contact_picture
|
|
|
|
.setOnClickListener(new OnClickListener() {
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void onClick(View v) {
|
2014-06-01 17:29:57 +00:00
|
|
|
highlightInConference(item
|
|
|
|
.getCounterpart());
|
2014-05-20 09:44:43 +00:00
|
|
|
}
|
|
|
|
});
|
2014-02-01 14:07:20 +00:00
|
|
|
}
|
2014-01-26 02:27:55 +00:00
|
|
|
}
|
2014-05-07 10:59:15 +00:00
|
|
|
|
2014-05-08 08:14:12 +00:00
|
|
|
if (item.getType() == Message.TYPE_IMAGE) {
|
2014-05-08 09:53:00 +00:00
|
|
|
if (item.getStatus() == Message.STATUS_RECIEVING) {
|
|
|
|
displayInfoMessage(viewHolder, R.string.receiving_image);
|
2014-04-22 16:46:40 +00:00
|
|
|
} else if (item.getStatus() == Message.STATUS_RECEIVED_OFFER) {
|
2014-04-15 13:19:02 +00:00
|
|
|
viewHolder.image.setVisibility(View.GONE);
|
2014-04-14 19:21:13 +00:00
|
|
|
viewHolder.messageBody.setVisibility(View.GONE);
|
2014-04-22 16:46:40 +00:00
|
|
|
viewHolder.download_button.setVisibility(View.VISIBLE);
|
2014-05-07 10:59:15 +00:00
|
|
|
viewHolder.download_button
|
|
|
|
.setOnClickListener(new OnClickListener() {
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void onClick(View v) {
|
|
|
|
JingleConnection connection = item
|
|
|
|
.getJingleConnection();
|
|
|
|
if (connection != null) {
|
|
|
|
connection.accept();
|
|
|
|
} else {
|
|
|
|
Log.d("xmppService",
|
|
|
|
"attached jingle connection was null");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|
2014-05-08 08:14:12 +00:00
|
|
|
} else if ((item.getEncryption() == Message.ENCRYPTION_DECRYPTED)
|
2014-06-20 15:30:19 +00:00
|
|
|
|| (item.getEncryption() == Message.ENCRYPTION_NONE)
|
|
|
|
|| (item.getEncryption() == Message.ENCRYPTION_OTR)) {
|
2014-05-08 09:53:00 +00:00
|
|
|
displayImageMessage(viewHolder, item);
|
2014-05-08 08:14:12 +00:00
|
|
|
} else if (item.getEncryption() == Message.ENCRYPTION_PGP) {
|
2014-05-08 09:53:00 +00:00
|
|
|
displayInfoMessage(viewHolder,
|
|
|
|
R.string.encrypted_message);
|
2014-05-08 08:14:12 +00:00
|
|
|
} else {
|
2014-05-08 09:53:00 +00:00
|
|
|
displayDecryptionFailed(viewHolder);
|
2014-04-14 19:21:13 +00:00
|
|
|
}
|
2014-04-06 13:34:08 +00:00
|
|
|
} else {
|
2014-05-08 09:53:00 +00:00
|
|
|
if (item.getEncryption() == Message.ENCRYPTION_PGP) {
|
2014-06-09 19:25:01 +00:00
|
|
|
if (activity.hasPgp()) {
|
|
|
|
displayInfoMessage(viewHolder,
|
|
|
|
R.string.encrypted_message);
|
|
|
|
} else {
|
|
|
|
displayInfoMessage(viewHolder,
|
|
|
|
R.string.install_openkeychain);
|
2014-06-14 14:59:07 +00:00
|
|
|
viewHolder.message_box
|
|
|
|
.setOnClickListener(new OnClickListener() {
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void onClick(View v) {
|
|
|
|
activity.showInstallPgpDialog();
|
|
|
|
}
|
|
|
|
});
|
2014-06-09 19:25:01 +00:00
|
|
|
}
|
2014-05-08 09:53:00 +00:00
|
|
|
} else if (item.getEncryption() == Message.ENCRYPTION_DECRYPTION_FAILED) {
|
|
|
|
displayDecryptionFailed(viewHolder);
|
2014-02-16 15:32:15 +00:00
|
|
|
} else {
|
2014-05-08 09:53:00 +00:00
|
|
|
displayTextMessage(viewHolder, item.getBody());
|
2014-02-11 22:55:03 +00:00
|
|
|
}
|
2014-01-26 02:27:55 +00:00
|
|
|
}
|
2014-05-08 09:53:00 +00:00
|
|
|
|
|
|
|
displayStatus(viewHolder, item);
|
|
|
|
|
2014-01-26 02:27:55 +00:00
|
|
|
return view;
|
|
|
|
}
|
2014-02-02 15:33:34 +00:00
|
|
|
};
|
|
|
|
messagesView.setAdapter(messageListAdapter);
|
2014-01-26 02:27:55 +00:00
|
|
|
|
|
|
|
return view;
|
|
|
|
}
|
2014-01-24 22:58:51 +00:00
|
|
|
|
2014-05-20 09:44:43 +00:00
|
|
|
protected void highlightInConference(String nick) {
|
2014-05-21 14:43:19 +00:00
|
|
|
String oldString = chatMsg.getText().toString().trim();
|
|
|
|
if (oldString.isEmpty()) {
|
2014-06-01 17:29:57 +00:00
|
|
|
chatMsg.setText(nick + ": ");
|
2014-05-20 09:44:43 +00:00
|
|
|
} else {
|
2014-06-01 17:29:57 +00:00
|
|
|
chatMsg.setText(oldString + " " + nick + " ");
|
2014-05-20 09:44:43 +00:00
|
|
|
}
|
|
|
|
int position = chatMsg.length();
|
|
|
|
Editable etext = chatMsg.getText();
|
|
|
|
Selection.setSelection(etext, position);
|
|
|
|
}
|
2014-06-01 17:29:57 +00:00
|
|
|
|
2014-02-20 16:00:50 +00:00
|
|
|
protected Bitmap findSelfPicture() {
|
|
|
|
SharedPreferences sharedPref = PreferenceManager
|
|
|
|
.getDefaultSharedPreferences(getActivity()
|
|
|
|
.getApplicationContext());
|
|
|
|
boolean showPhoneSelfContactPicture = sharedPref.getBoolean(
|
|
|
|
"show_phone_selfcontact_picture", true);
|
|
|
|
|
2014-04-13 18:41:06 +00:00
|
|
|
return UIHelper.getSelfContactPicture(conversation.getAccount(), 48,
|
2014-03-13 02:52:41 +00:00
|
|
|
showPhoneSelfContactPicture, getActivity());
|
2014-02-20 16:00:50 +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-05-07 10:59:15 +00:00
|
|
|
SharedPreferences preferences = PreferenceManager
|
|
|
|
.getDefaultSharedPreferences(activity);
|
2014-03-15 14:13:35 +00:00
|
|
|
this.useSubject = preferences.getBoolean("use_subject_in_muc", true);
|
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() {
|
|
|
|
super.onStop();
|
2014-05-19 13:39:50 +00:00
|
|
|
if (this.conversation != null) {
|
2014-05-09 18:46:43 +00:00
|
|
|
this.conversation.setNextMessage(chatMsg.getText().toString());
|
|
|
|
}
|
2014-05-07 10:59:15 +00:00
|
|
|
}
|
|
|
|
|
2014-01-27 19:40:42 +00:00
|
|
|
public void onBackendConnected() {
|
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-05-21 14:43:19 +00:00
|
|
|
this.chatMsg.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()) {
|
|
|
|
chatMsg.setText(pastedText);
|
|
|
|
} else {
|
|
|
|
chatMsg.setText(oldString + " " + pastedText);
|
|
|
|
}
|
2014-05-07 10:59:15 +00:00
|
|
|
pastedText = null;
|
|
|
|
}
|
|
|
|
int position = chatMsg.length();
|
|
|
|
Editable etext = chatMsg.getText();
|
|
|
|
Selection.setSelection(etext, position);
|
2014-02-20 16:00:50 +00:00
|
|
|
this.selfBitmap = findSelfPicture();
|
2014-02-05 21:33:39 +00:00
|
|
|
updateMessages();
|
2014-03-07 17:13:19 +00:00
|
|
|
if (activity.getSlidingPaneLayout().isSlideable()) {
|
|
|
|
if (!activity.shouldPaneBeOpen()) {
|
|
|
|
activity.getSlidingPaneLayout().closePane();
|
|
|
|
activity.getActionBar().setDisplayHomeAsUpEnabled(true);
|
2014-05-31 03:18:50 +00:00
|
|
|
activity.getActionBar().setHomeButtonEnabled(true);
|
2014-05-07 10:59:15 +00:00
|
|
|
activity.getActionBar().setTitle(
|
|
|
|
conversation.getName(useSubject));
|
2014-03-07 17:13:19 +00:00
|
|
|
activity.invalidateOptionsMenu();
|
2014-02-10 21:45:59 +00:00
|
|
|
}
|
2014-01-28 18:21:54 +00:00
|
|
|
}
|
2014-03-04 03:09:15 +00:00
|
|
|
if (conversation.getMode() == Conversation.MODE_MULTI) {
|
2014-03-13 02:52:41 +00:00
|
|
|
activity.xmppConnectionService
|
|
|
|
.setOnRenameListener(new OnRenameListener() {
|
|
|
|
|
2014-03-04 03:09:15 +00:00
|
|
|
@Override
|
2014-03-13 02:52:41 +00:00
|
|
|
public void onRename(final boolean success) {
|
2014-05-07 10:59:15 +00:00
|
|
|
activity.xmppConnectionService
|
|
|
|
.updateConversation(conversation);
|
2014-03-13 02:52:41 +00:00
|
|
|
getActivity().runOnUiThread(new Runnable() {
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void run() {
|
|
|
|
if (success) {
|
|
|
|
Toast.makeText(
|
|
|
|
getActivity(),
|
2014-04-16 21:58:53 +00:00
|
|
|
getString(R.string.your_nick_has_been_changed),
|
2014-03-13 02:52:41 +00:00
|
|
|
Toast.LENGTH_SHORT).show();
|
|
|
|
} else {
|
2014-05-07 10:59:15 +00:00
|
|
|
Toast.makeText(
|
|
|
|
getActivity(),
|
2014-04-16 21:58:53 +00:00
|
|
|
getString(R.string.nick_in_use),
|
2014-03-13 02:52:41 +00:00
|
|
|
Toast.LENGTH_SHORT).show();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|
2014-03-04 03:09:15 +00:00
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
2014-01-24 22:58:51 +00:00
|
|
|
}
|
2014-05-07 10:59:15 +00:00
|
|
|
|
2014-06-07 11:25:27 +00:00
|
|
|
private void decryptMessage(Message message) {
|
2014-05-01 20:33:49 +00:00
|
|
|
PgpEngine engine = activity.xmppConnectionService.getPgpEngine();
|
2014-05-07 10:59:15 +00:00
|
|
|
if (engine != null) {
|
2014-06-07 11:25:27 +00:00
|
|
|
engine.decrypt(message, new UiCallback<Message>() {
|
2014-05-07 10:59:15 +00:00
|
|
|
|
2014-05-01 20:33:49 +00:00
|
|
|
@Override
|
2014-06-07 11:25:27 +00:00
|
|
|
public void userInputRequried(PendingIntent pi, Message message) {
|
2014-05-01 20:33:49 +00:00
|
|
|
askForPassphraseIntent = pi.getIntentSender();
|
|
|
|
pgpInfo.setVisibility(View.VISIBLE);
|
|
|
|
}
|
2014-05-07 10:59:15 +00:00
|
|
|
|
2014-05-01 20:33:49 +00:00
|
|
|
@Override
|
2014-06-07 11:25:27 +00:00
|
|
|
public void success(Message message) {
|
2014-05-07 10:59:15 +00:00
|
|
|
activity.xmppConnectionService.databaseBackend
|
|
|
|
.updateMessage(message);
|
2014-05-01 20:33:49 +00:00
|
|
|
updateMessages();
|
|
|
|
}
|
2014-05-07 10:59:15 +00:00
|
|
|
|
2014-05-01 20:33:49 +00:00
|
|
|
@Override
|
2014-06-07 11:25:27 +00:00
|
|
|
public void error(int error, Message message) {
|
2014-05-01 20:33:49 +00:00
|
|
|
message.setEncryption(Message.ENCRYPTION_DECRYPTION_FAILED);
|
2014-05-07 10:59:15 +00:00
|
|
|
// updateMessages();
|
2014-05-01 20:33:49 +00:00
|
|
|
}
|
|
|
|
});
|
|
|
|
} else {
|
2014-06-09 19:25:01 +00:00
|
|
|
pgpInfo.setVisibility(View.GONE);
|
2014-05-01 20:33:49 +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-02-16 15:32:15 +00:00
|
|
|
ConversationActivity activity = (ConversationActivity) getActivity();
|
2014-03-21 21:14:52 +00:00
|
|
|
if (this.conversation != null) {
|
|
|
|
for (Message message : this.conversation.getMessages()) {
|
2014-05-19 13:39:50 +00:00
|
|
|
if ((message.getEncryption() == Message.ENCRYPTION_PGP)
|
|
|
|
&& ((message.getStatus() == Message.STATUS_RECIEVED) || (message
|
|
|
|
.getStatus() == Message.STATUS_SEND))) {
|
2014-05-01 20:33:49 +00:00
|
|
|
decryptMessage(message);
|
|
|
|
break;
|
2014-03-03 04:01:02 +00:00
|
|
|
}
|
|
|
|
}
|
2014-06-14 08:29:26 +00:00
|
|
|
if (this.conversation.getMessages().size() == 0) {
|
|
|
|
this.messageList.clear();
|
2014-06-14 14:59:07 +00:00
|
|
|
messagesLoaded = false;
|
2014-06-14 08:29:26 +00:00
|
|
|
} else {
|
2014-06-14 14:59:07 +00:00
|
|
|
for (Message message : this.conversation.getMessages()) {
|
2014-06-14 08:29:26 +00:00
|
|
|
if (!this.messageList.contains(message)) {
|
|
|
|
this.messageList.add(message);
|
|
|
|
}
|
2014-06-10 15:01:19 +00:00
|
|
|
}
|
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-05-07 10:33:55 +00:00
|
|
|
makeFingerprintWarning(conversation.getLatestEncryption());
|
2014-03-03 04:01:02 +00:00
|
|
|
}
|
2014-02-27 23:22:56 +00:00
|
|
|
} else {
|
2014-03-21 21:14:52 +00:00
|
|
|
if (conversation.getMucOptions().getError() != 0) {
|
|
|
|
mucError.setVisibility(View.VISIBLE);
|
|
|
|
if (conversation.getMucOptions().getError() == MucOptions.ERROR_NICK_IN_USE) {
|
|
|
|
mucErrorText.setText(getString(R.string.nick_in_use));
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
mucError.setVisibility(View.GONE);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
getActivity().invalidateOptionsMenu();
|
|
|
|
updateChatMsgHint();
|
|
|
|
if (!activity.shouldPaneBeOpen()) {
|
2014-06-04 16:44:15 +00:00
|
|
|
activity.xmppConnectionService.markRead(conversation);
|
2014-03-21 21:14:52 +00:00
|
|
|
// TODO update notifications
|
|
|
|
UIHelper.updateNotification(getActivity(),
|
|
|
|
activity.getConversationList(), null, false);
|
|
|
|
activity.updateConversationList();
|
2014-02-27 23:22:56 +00:00
|
|
|
}
|
2014-02-10 22:12:11 +00:00
|
|
|
}
|
2014-02-02 15:33:34 +00:00
|
|
|
}
|
2014-06-06 09:39:17 +00:00
|
|
|
|
2014-06-10 15:01:19 +00:00
|
|
|
private void messageSent() {
|
|
|
|
int size = this.messageList.size();
|
|
|
|
if (size >= 1) {
|
|
|
|
messagesView.setSelection(size - 1);
|
|
|
|
}
|
|
|
|
chatMsg.setText("");
|
|
|
|
}
|
2014-06-14 14:59:07 +00:00
|
|
|
|
2014-06-04 19:40:17 +00:00
|
|
|
protected void updateStatusMessages() {
|
2014-06-10 15:01:19 +00:00
|
|
|
boolean addedStatusMsg = false;
|
2014-06-04 19:40:17 +00:00
|
|
|
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-06-10 15:01:19 +00:00
|
|
|
if (addedStatusMsg) {
|
|
|
|
if (this.messageList.get(i).getType() == Message.TYPE_STATUS) {
|
|
|
|
this.messageList.remove(i);
|
|
|
|
--i;
|
|
|
|
}
|
2014-06-04 19:40:17 +00:00
|
|
|
} else {
|
2014-06-10 15:01:19 +00: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 19:40:17 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2014-02-16 15:32:15 +00:00
|
|
|
|
|
|
|
protected void makeFingerprintWarning(int latestEncryption) {
|
|
|
|
final LinearLayout fingerprintWarning = (LinearLayout) getView()
|
|
|
|
.findViewById(R.id.new_fingerprint);
|
2014-05-19 13:39:50 +00:00
|
|
|
Set<String> knownFingerprints = conversation.getContact()
|
|
|
|
.getOtrFingerprints();
|
|
|
|
if ((latestEncryption == Message.ENCRYPTION_OTR)
|
|
|
|
&& (conversation.hasValidOtrSession()
|
|
|
|
&& (conversation.getOtrSession().getSessionStatus() == SessionStatus.ENCRYPTED) && (!knownFingerprints
|
|
|
|
.contains(conversation.getOtrFingerprint())))) {
|
|
|
|
fingerprintWarning.setVisibility(View.VISIBLE);
|
|
|
|
TextView fingerprint = (TextView) getView().findViewById(
|
|
|
|
R.id.otr_fingerprint);
|
|
|
|
fingerprint.setText(conversation.getOtrFingerprint());
|
|
|
|
fingerprintWarning.setOnClickListener(new OnClickListener() {
|
2014-02-19 00:35:23 +00:00
|
|
|
|
2014-05-19 13:39:50 +00:00
|
|
|
@Override
|
|
|
|
public void onClick(View v) {
|
|
|
|
AlertDialog dialog = UIHelper.getVerifyFingerprintDialog(
|
|
|
|
(ConversationActivity) getActivity(), conversation,
|
|
|
|
fingerprintWarning);
|
|
|
|
dialog.show();
|
|
|
|
}
|
|
|
|
});
|
2014-02-16 15:32:15 +00:00
|
|
|
} else {
|
|
|
|
fingerprintWarning.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);
|
|
|
|
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-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
|
|
|
|
|
|
|
private static class ViewHolder {
|
|
|
|
|
2014-06-09 19:25:01 +00:00
|
|
|
protected LinearLayout message_box;
|
2014-04-22 16:46:40 +00:00
|
|
|
protected Button download_button;
|
2014-04-06 13:34:08 +00:00
|
|
|
protected ImageView image;
|
2014-03-14 23:19:42 +00:00
|
|
|
protected ImageView indicator;
|
2014-02-19 00:35:23 +00:00
|
|
|
protected TextView time;
|
|
|
|
protected TextView messageBody;
|
2014-04-15 13:19:02 +00:00
|
|
|
protected ImageView contact_picture;
|
2014-02-19 00:35:23 +00:00
|
|
|
|
|
|
|
}
|
2014-02-19 07:21:33 +00:00
|
|
|
|
2014-02-19 00:35:23 +00:00
|
|
|
private class BitmapCache {
|
|
|
|
private HashMap<String, Bitmap> bitmaps = new HashMap<String, Bitmap>();
|
2014-02-19 07:21:33 +00:00
|
|
|
|
2014-03-13 02:52:41 +00:00
|
|
|
public Bitmap get(String name, Contact contact, Context context) {
|
2014-02-19 00:35:23 +00:00
|
|
|
if (bitmaps.containsKey(name)) {
|
|
|
|
return bitmaps.get(name);
|
|
|
|
} else {
|
2014-04-11 23:36:44 +00:00
|
|
|
Bitmap bm;
|
2014-05-07 10:59:15 +00:00
|
|
|
if (contact != null) {
|
|
|
|
bm = UIHelper
|
|
|
|
.getContactPicture(contact, 48, context, false);
|
2014-04-11 23:36:44 +00:00
|
|
|
} else {
|
2014-04-13 18:41:06 +00:00
|
|
|
bm = UIHelper.getContactPicture(name, 48, context, false);
|
2014-04-11 23:36:44 +00:00
|
|
|
}
|
2014-02-19 00:35:23 +00:00
|
|
|
bitmaps.put(name, bm);
|
|
|
|
return bm;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2014-03-13 02:52:41 +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() {
|
|
|
|
this.chatMsg.setText("");
|
|
|
|
}
|
2014-01-24 01:04:05 +00:00
|
|
|
}
|