2014-02-28 12:46:01 -05:00
|
|
|
package eu.siacs.conversations.ui;
|
2014-01-23 20:04:05 -05:00
|
|
|
|
2014-02-18 19:35:23 -05:00
|
|
|
import java.io.FileNotFoundException;
|
2014-01-27 14:40:42 -05:00
|
|
|
import java.util.ArrayList;
|
2014-02-18 19:35:23 -05:00
|
|
|
import java.util.HashMap;
|
2014-02-16 10:32:15 -05:00
|
|
|
import java.util.Hashtable;
|
2014-02-27 18:22:56 -05:00
|
|
|
import java.util.LinkedList;
|
2014-01-27 14:40:42 -05:00
|
|
|
import java.util.List;
|
2014-02-16 10:32:15 -05:00
|
|
|
import java.util.Set;
|
|
|
|
|
|
|
|
import net.java.otr4j.session.SessionStatus;
|
2014-01-27 14:40:42 -05:00
|
|
|
|
2014-02-28 12:46:01 -05:00
|
|
|
import eu.siacs.conversations.R;
|
|
|
|
import eu.siacs.conversations.crypto.PgpEngine.OpenPgpException;
|
|
|
|
import eu.siacs.conversations.crypto.PgpEngine.UserInputRequiredException;
|
|
|
|
import eu.siacs.conversations.entities.Contact;
|
|
|
|
import eu.siacs.conversations.entities.Conversation;
|
|
|
|
import eu.siacs.conversations.entities.Message;
|
2014-03-02 23:01:02 -05:00
|
|
|
import eu.siacs.conversations.entities.MucOptions;
|
2014-03-03 22:09:15 -05:00
|
|
|
import eu.siacs.conversations.entities.MucOptions.OnRenameListener;
|
2014-02-28 12:46:01 -05:00
|
|
|
import eu.siacs.conversations.services.XmppConnectionService;
|
|
|
|
import eu.siacs.conversations.utils.PhoneHelper;
|
|
|
|
import eu.siacs.conversations.utils.UIHelper;
|
2014-02-16 10:32:15 -05:00
|
|
|
import android.app.AlertDialog;
|
2014-01-23 20:04:05 -05:00
|
|
|
import android.app.Fragment;
|
2014-02-16 10:32:15 -05:00
|
|
|
import android.content.DialogInterface;
|
2014-03-03 20:51:01 -05:00
|
|
|
import android.content.Intent;
|
2014-02-27 18:22:56 -05:00
|
|
|
import android.content.IntentSender;
|
2014-02-10 09:24:34 -05:00
|
|
|
import android.content.SharedPreferences;
|
2014-02-27 18:22:56 -05:00
|
|
|
import android.content.IntentSender.SendIntentException;
|
2014-02-18 19:35:23 -05:00
|
|
|
import android.graphics.Bitmap;
|
|
|
|
import android.graphics.BitmapFactory;
|
2014-01-25 21:27:55 -05:00
|
|
|
import android.graphics.Typeface;
|
|
|
|
import android.net.Uri;
|
2014-02-27 18:22:56 -05:00
|
|
|
import android.os.AsyncTask;
|
2014-01-23 20:04:05 -05:00
|
|
|
import android.os.Bundle;
|
2014-02-10 09:24:34 -05:00
|
|
|
import android.preference.PreferenceManager;
|
2014-02-18 19:35:23 -05:00
|
|
|
import android.util.Log;
|
2014-01-23 20:04:05 -05:00
|
|
|
import android.view.LayoutInflater;
|
|
|
|
import android.view.View;
|
2014-01-25 21:27:55 -05:00
|
|
|
import android.view.View.OnClickListener;
|
2014-01-23 20:04:05 -05:00
|
|
|
import android.view.ViewGroup;
|
2014-01-25 21:27:55 -05:00
|
|
|
import android.widget.ArrayAdapter;
|
|
|
|
import android.widget.EditText;
|
2014-02-16 10:32:15 -05:00
|
|
|
import android.widget.LinearLayout;
|
2014-01-25 21:27:55 -05:00
|
|
|
import android.widget.ListView;
|
|
|
|
import android.widget.ImageButton;
|
|
|
|
import android.widget.ImageView;
|
|
|
|
import android.widget.TextView;
|
2014-03-03 22:09:15 -05:00
|
|
|
import android.widget.Toast;
|
2014-01-23 20:04:05 -05:00
|
|
|
|
|
|
|
public class ConversationFragment extends Fragment {
|
2014-02-16 10:32:15 -05:00
|
|
|
|
2014-01-27 14:40:42 -05:00
|
|
|
protected Conversation conversation;
|
|
|
|
protected ListView messagesView;
|
|
|
|
protected LayoutInflater inflater;
|
|
|
|
protected List<Message> messageList = new ArrayList<Message>();
|
2014-02-02 10:33:34 -05:00
|
|
|
protected ArrayAdapter<Message> messageListAdapter;
|
2014-02-09 21:34:00 -05:00
|
|
|
protected Contact contact;
|
2014-02-18 19:35:23 -05:00
|
|
|
protected BitmapCache mBitmapCache = new BitmapCache();
|
2014-02-16 10:32:15 -05:00
|
|
|
|
2014-02-27 18:22:56 -05:00
|
|
|
protected String queuedPqpMessage = null;
|
|
|
|
|
2014-02-13 17:40:08 -05:00
|
|
|
private EditText chatMsg;
|
2014-02-27 18:22:56 -05:00
|
|
|
|
2014-02-20 11:00:50 -05:00
|
|
|
protected Bitmap selfBitmap;
|
2014-02-27 18:22:56 -05:00
|
|
|
|
|
|
|
private IntentSender askForPassphraseIntent = null;
|
2014-02-16 10:32:15 -05:00
|
|
|
|
|
|
|
private OnClickListener sendMsgListener = new OnClickListener() {
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void onClick(View v) {
|
|
|
|
if (chatMsg.getText().length() < 1)
|
|
|
|
return;
|
2014-02-16 13:30:22 -05:00
|
|
|
Message message = new Message(conversation, chatMsg.getText()
|
2014-02-16 10:32:15 -05:00
|
|
|
.toString(), conversation.nextMessageEncryption);
|
|
|
|
if (conversation.nextMessageEncryption == Message.ENCRYPTION_OTR) {
|
2014-02-16 13:30:22 -05:00
|
|
|
sendOtrMessage(message);
|
2014-02-27 18:22:56 -05:00
|
|
|
} else if (conversation.nextMessageEncryption == Message.ENCRYPTION_PGP) {
|
|
|
|
sendPgpMessage(message);
|
2014-02-16 10:32:15 -05:00
|
|
|
} else {
|
2014-02-16 13:30:22 -05:00
|
|
|
sendPlainTextMessage(message);
|
2014-02-16 10:32:15 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
};
|
2014-02-27 18:22:56 -05:00
|
|
|
protected OnClickListener clickToDecryptListener = new OnClickListener() {
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void onClick(View v) {
|
|
|
|
Log.d("gultsch","clicked to decrypt");
|
|
|
|
if (askForPassphraseIntent!=null) {
|
|
|
|
try {
|
|
|
|
getActivity().startIntentSenderForResult(askForPassphraseIntent, ConversationActivity.REQUEST_DECRYPT_PGP, null, 0, 0, 0);
|
|
|
|
} catch (SendIntentException e) {
|
|
|
|
Log.d("gultsch","couldnt fire intent");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
};
|
2014-03-03 20:51:01 -05:00
|
|
|
|
2014-02-27 20:58:15 -05:00
|
|
|
private LinearLayout pgpInfo;
|
2014-03-02 23:01:02 -05:00
|
|
|
private LinearLayout mucError;
|
|
|
|
private TextView mucErrorText;
|
|
|
|
private OnClickListener clickToMuc = new OnClickListener() {
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void onClick(View v) {
|
2014-03-05 09:41:14 -05:00
|
|
|
Intent intent = new Intent(getActivity(),MucDetailsActivity.class);
|
|
|
|
intent.setAction(MucDetailsActivity.ACTION_VIEW_MUC);
|
2014-03-03 20:51:01 -05:00
|
|
|
intent.putExtra("uuid", conversation.getUuid());
|
|
|
|
startActivity(intent);
|
2014-03-02 23:01:02 -05:00
|
|
|
}
|
|
|
|
};
|
2014-02-27 20:58:15 -05:00
|
|
|
|
|
|
|
public void hidePgpPassphraseBox() {
|
|
|
|
pgpInfo.setVisibility(View.GONE);
|
|
|
|
}
|
2014-02-16 10:32:15 -05:00
|
|
|
|
|
|
|
public void updateChatMsgHint() {
|
|
|
|
if (conversation.getMode() == Conversation.MODE_MULTI) {
|
|
|
|
chatMsg.setHint("Send message to conference");
|
|
|
|
} else {
|
|
|
|
switch (conversation.nextMessageEncryption) {
|
|
|
|
case Message.ENCRYPTION_NONE:
|
|
|
|
chatMsg.setHint("Send plain text message");
|
|
|
|
break;
|
|
|
|
case Message.ENCRYPTION_OTR:
|
|
|
|
chatMsg.setHint("Send OTR encrypted message");
|
|
|
|
break;
|
|
|
|
case Message.ENCRYPTION_PGP:
|
|
|
|
chatMsg.setHint("Send openPGP encryted messeage");
|
2014-02-27 18:22:56 -05:00
|
|
|
break;
|
|
|
|
case Message.ENCRYPTION_DECRYPTED:
|
|
|
|
chatMsg.setHint("Send openPGP encryted messeage");
|
|
|
|
break;
|
2014-02-16 10:32:15 -05:00
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-01-27 14:40:42 -05:00
|
|
|
@Override
|
|
|
|
public View onCreateView(final LayoutInflater inflater,
|
|
|
|
ViewGroup container, Bundle savedInstanceState) {
|
2014-01-25 21:27:55 -05:00
|
|
|
|
2014-01-27 14:40:42 -05:00
|
|
|
this.inflater = inflater;
|
2014-01-25 21:27:55 -05:00
|
|
|
|
2014-01-27 14:40:42 -05:00
|
|
|
final View view = inflater.inflate(R.layout.fragment_conversation,
|
|
|
|
container, false);
|
2014-02-13 17:40:08 -05:00
|
|
|
chatMsg = (EditText) view.findViewById(R.id.textinput);
|
2014-02-16 10:32:15 -05:00
|
|
|
ImageButton sendButton = (ImageButton) view
|
|
|
|
.findViewById(R.id.textSendButton);
|
|
|
|
sendButton.setOnClickListener(this.sendMsgListener);
|
2014-02-20 11:00:50 -05:00
|
|
|
|
2014-02-27 20:58:15 -05:00
|
|
|
pgpInfo = (LinearLayout) view.findViewById(R.id.pgp_keyentry);
|
|
|
|
pgpInfo.setOnClickListener(clickToDecryptListener);
|
2014-03-02 23:01:02 -05:00
|
|
|
mucError = (LinearLayout) view.findViewById(R.id.muc_error);
|
|
|
|
mucError.setOnClickListener(clickToMuc );
|
|
|
|
mucErrorText = (TextView) view.findViewById(R.id.muc_error_msg);
|
2014-02-27 20:58:15 -05:00
|
|
|
|
2014-02-27 18:22:56 -05:00
|
|
|
messagesView = (ListView) view.findViewById(R.id.messages_view);
|
|
|
|
|
2014-02-02 10:33:34 -05:00
|
|
|
messageListAdapter = new ArrayAdapter<Message>(this.getActivity()
|
2014-02-16 10:32:15 -05:00
|
|
|
.getApplicationContext(), R.layout.message_sent,
|
|
|
|
this.messageList) {
|
2014-01-27 14:40:42 -05:00
|
|
|
|
|
|
|
private static final int SENT = 0;
|
|
|
|
private static final int RECIEVED = 1;
|
2014-02-20 11:00:50 -05:00
|
|
|
private static final int ERROR = 2;
|
2014-02-16 10:32:15 -05:00
|
|
|
|
2014-01-27 14:40:42 -05:00
|
|
|
@Override
|
|
|
|
public int getViewTypeCount() {
|
2014-02-20 11:00:50 -05:00
|
|
|
return 3;
|
2014-01-27 14:40:42 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public int getItemViewType(int position) {
|
|
|
|
if (getItem(position).getStatus() == Message.STATUS_RECIEVED) {
|
|
|
|
return RECIEVED;
|
2014-02-20 11:00:50 -05:00
|
|
|
} else if (getItem(position).getStatus() == Message.STATUS_ERROR) {
|
|
|
|
return ERROR;
|
2014-01-27 14:40:42 -05:00
|
|
|
} else {
|
|
|
|
return SENT;
|
|
|
|
}
|
|
|
|
}
|
2014-01-25 21:27:55 -05:00
|
|
|
|
|
|
|
@Override
|
|
|
|
public View getView(int position, View view, ViewGroup parent) {
|
|
|
|
Message item = getItem(position);
|
2014-01-27 14:40:42 -05:00
|
|
|
int type = getItemViewType(position);
|
2014-02-18 19:35:23 -05:00
|
|
|
ViewHolder viewHolder;
|
2014-01-27 14:40:42 -05:00
|
|
|
if (view == null) {
|
2014-02-19 02:21:33 -05:00
|
|
|
viewHolder = new ViewHolder();
|
2014-01-27 14:40:42 -05:00
|
|
|
switch (type) {
|
|
|
|
case SENT:
|
|
|
|
view = (View) inflater.inflate(R.layout.message_sent,
|
|
|
|
null);
|
2014-02-18 19:35:23 -05:00
|
|
|
viewHolder.imageView = (ImageView) view
|
|
|
|
.findViewById(R.id.message_photo);
|
2014-02-19 02:21:33 -05:00
|
|
|
viewHolder.imageView.setImageBitmap(selfBitmap);
|
2014-01-27 14:40:42 -05:00
|
|
|
break;
|
|
|
|
case RECIEVED:
|
|
|
|
view = (View) inflater.inflate(
|
|
|
|
R.layout.message_recieved, null);
|
2014-02-18 19:35:23 -05:00
|
|
|
viewHolder.imageView = (ImageView) view
|
|
|
|
.findViewById(R.id.message_photo);
|
2014-02-19 02:21:33 -05:00
|
|
|
if (item.getConversation().getMode() == Conversation.MODE_SINGLE) {
|
2014-02-27 18:22:56 -05:00
|
|
|
Uri uri = item.getConversation()
|
|
|
|
.getProfilePhotoUri();
|
2014-02-19 02:21:33 -05:00
|
|
|
if (uri != null) {
|
|
|
|
viewHolder.imageView
|
|
|
|
.setImageBitmap(mBitmapCache.get(item
|
2014-02-27 18:22:56 -05:00
|
|
|
.getConversation().getName(),
|
|
|
|
uri));
|
2014-02-19 02:21:33 -05:00
|
|
|
} else {
|
|
|
|
viewHolder.imageView
|
|
|
|
.setImageBitmap(mBitmapCache.get(item
|
2014-02-27 18:22:56 -05:00
|
|
|
.getConversation().getName(),
|
|
|
|
null));
|
2014-02-19 02:21:33 -05:00
|
|
|
}
|
|
|
|
}
|
2014-02-18 19:35:23 -05:00
|
|
|
break;
|
2014-02-20 11:00:50 -05:00
|
|
|
case ERROR:
|
2014-02-27 18:22:56 -05:00
|
|
|
view = (View) inflater.inflate(R.layout.message_error,
|
|
|
|
null);
|
2014-02-20 11:00:50 -05:00
|
|
|
viewHolder.imageView = (ImageView) view
|
|
|
|
.findViewById(R.id.message_photo);
|
2014-02-27 18:22:56 -05:00
|
|
|
viewHolder.imageView.setImageBitmap(mBitmapCache
|
|
|
|
.getError());
|
2014-02-20 11:00:50 -05:00
|
|
|
break;
|
2014-02-18 19:35:23 -05:00
|
|
|
default:
|
|
|
|
viewHolder = null;
|
2014-01-27 14:40:42 -05:00
|
|
|
break;
|
|
|
|
}
|
2014-02-19 02:21:33 -05:00
|
|
|
viewHolder.messageBody = (TextView) view
|
|
|
|
.findViewById(R.id.message_body);
|
|
|
|
viewHolder.time = (TextView) view
|
|
|
|
.findViewById(R.id.message_time);
|
|
|
|
view.setTag(viewHolder);
|
2014-02-18 19:35:23 -05:00
|
|
|
} else {
|
|
|
|
viewHolder = (ViewHolder) view.getTag();
|
2014-01-27 14:40:42 -05:00
|
|
|
}
|
|
|
|
if (type == RECIEVED) {
|
2014-02-27 18:22:56 -05:00
|
|
|
if (item.getConversation().getMode() == Conversation.MODE_MULTI) {
|
2014-02-16 10:32:15 -05:00
|
|
|
if (item.getCounterpart() != null) {
|
2014-02-19 02:21:33 -05:00
|
|
|
viewHolder.imageView.setImageBitmap(mBitmapCache
|
|
|
|
.get(item.getCounterpart(), null));
|
2014-02-05 16:33:39 -05:00
|
|
|
} else {
|
2014-02-19 02:21:33 -05:00
|
|
|
viewHolder.imageView
|
|
|
|
.setImageBitmap(mBitmapCache.get(item
|
|
|
|
.getConversation().getName(), null));
|
2014-02-05 16:33:39 -05:00
|
|
|
}
|
2014-02-01 09:07:20 -05:00
|
|
|
}
|
2014-01-25 21:27:55 -05:00
|
|
|
}
|
2014-02-02 11:53:34 -05:00
|
|
|
String body = item.getBody();
|
2014-02-16 10:32:15 -05:00
|
|
|
if (body != null) {
|
2014-02-27 18:22:56 -05:00
|
|
|
if (item.getEncryption() == Message.ENCRYPTION_PGP) {
|
|
|
|
viewHolder.messageBody.setText(getString(R.string.encrypted_message));
|
|
|
|
viewHolder.messageBody.setTextColor(0xff33B5E5);
|
2014-02-27 20:58:15 -05:00
|
|
|
viewHolder.messageBody.setTypeface(null,Typeface.ITALIC);
|
2014-02-27 18:22:56 -05:00
|
|
|
} else {
|
|
|
|
viewHolder.messageBody.setText(body.trim());
|
|
|
|
viewHolder.messageBody.setTextColor(0xff000000);
|
2014-02-27 20:58:15 -05:00
|
|
|
viewHolder.messageBody.setTypeface(null, Typeface.NORMAL);
|
2014-02-27 18:22:56 -05:00
|
|
|
}
|
2014-02-02 11:53:34 -05:00
|
|
|
}
|
2014-01-25 21:27:55 -05:00
|
|
|
if (item.getStatus() == Message.STATUS_UNSEND) {
|
2014-02-18 19:35:23 -05:00
|
|
|
viewHolder.time.setTypeface(null, Typeface.ITALIC);
|
|
|
|
viewHolder.time.setText("sending\u2026");
|
2014-01-25 21:27:55 -05:00
|
|
|
} else {
|
2014-02-18 19:35:23 -05:00
|
|
|
viewHolder.time.setTypeface(null, Typeface.NORMAL);
|
2014-02-16 10:32:15 -05:00
|
|
|
if ((item.getConversation().getMode() == Conversation.MODE_SINGLE)
|
|
|
|
|| (type != RECIEVED)) {
|
2014-02-18 19:35:23 -05:00
|
|
|
viewHolder.time.setText(UIHelper
|
|
|
|
.readableTimeDifference(item.getTimeSent()));
|
2014-02-16 10:32:15 -05:00
|
|
|
} else {
|
2014-02-18 19:35:23 -05:00
|
|
|
viewHolder.time.setText(item.getCounterpart()
|
2014-02-16 10:32:15 -05:00
|
|
|
+ " \u00B7 "
|
|
|
|
+ UIHelper.readableTimeDifference(item
|
|
|
|
.getTimeSent()));
|
2014-02-11 17:55:03 -05:00
|
|
|
}
|
2014-01-25 21:27:55 -05:00
|
|
|
}
|
|
|
|
return view;
|
|
|
|
}
|
2014-02-02 10:33:34 -05:00
|
|
|
};
|
|
|
|
messagesView.setAdapter(messageListAdapter);
|
2014-01-25 21:27:55 -05:00
|
|
|
|
|
|
|
return view;
|
|
|
|
}
|
2014-01-24 17:58:51 -05:00
|
|
|
|
2014-02-20 11:00:50 -05:00
|
|
|
protected Bitmap findSelfPicture() {
|
|
|
|
SharedPreferences sharedPref = PreferenceManager
|
|
|
|
.getDefaultSharedPreferences(getActivity()
|
|
|
|
.getApplicationContext());
|
|
|
|
boolean showPhoneSelfContactPicture = sharedPref.getBoolean(
|
|
|
|
"show_phone_selfcontact_picture", true);
|
|
|
|
|
2014-02-22 12:18:51 -05:00
|
|
|
Bitmap self = null;
|
2014-02-20 11:00:50 -05:00
|
|
|
|
|
|
|
if (showPhoneSelfContactPicture) {
|
|
|
|
Uri selfiUri = PhoneHelper.getSefliUri(getActivity());
|
2014-02-27 18:22:56 -05:00
|
|
|
if (selfiUri != null) {
|
2014-02-22 12:18:51 -05:00
|
|
|
try {
|
|
|
|
self = BitmapFactory.decodeStream(getActivity()
|
|
|
|
.getContentResolver().openInputStream(selfiUri));
|
|
|
|
} catch (FileNotFoundException e) {
|
|
|
|
self = null;
|
|
|
|
}
|
2014-02-20 11:00:50 -05:00
|
|
|
}
|
2014-02-22 12:18:51 -05:00
|
|
|
}
|
2014-02-27 18:22:56 -05:00
|
|
|
if (self == null) {
|
2014-02-20 11:00:50 -05:00
|
|
|
self = UIHelper.getUnknownContactPicture(conversation.getAccount()
|
|
|
|
.getJid(), 200);
|
|
|
|
}
|
|
|
|
|
|
|
|
final Bitmap selfBitmap = self;
|
|
|
|
return selfBitmap;
|
|
|
|
}
|
|
|
|
|
2014-01-27 14:40:42 -05:00
|
|
|
@Override
|
|
|
|
public void onStart() {
|
|
|
|
super.onStart();
|
2014-02-20 11:00:50 -05:00
|
|
|
ConversationActivity activity = (ConversationActivity) getActivity();
|
2014-02-16 10:32:15 -05:00
|
|
|
|
2014-01-27 14:40:42 -05:00
|
|
|
if (activity.xmppConnectionServiceBound) {
|
2014-02-20 11:00:50 -05:00
|
|
|
this.onBackendConnected();
|
2014-01-27 14:40:42 -05:00
|
|
|
}
|
|
|
|
}
|
2014-02-16 10:32:15 -05:00
|
|
|
|
2014-01-27 14:40:42 -05:00
|
|
|
public void onBackendConnected() {
|
|
|
|
final ConversationActivity activity = (ConversationActivity) getActivity();
|
2014-03-10 16:52:58 -04:00
|
|
|
activity.registerListener();
|
2014-02-06 20:57:36 -05:00
|
|
|
this.conversation = activity.getSelectedConversation();
|
2014-03-10 14:22:13 -04:00
|
|
|
if (this.conversation==null) {
|
|
|
|
return;
|
|
|
|
}
|
2014-02-20 11:00:50 -05:00
|
|
|
this.selfBitmap = findSelfPicture();
|
2014-02-05 16:33:39 -05:00
|
|
|
updateMessages();
|
2014-01-28 13:21:54 -05:00
|
|
|
// rendering complete. now go tell activity to close pane
|
2014-03-07 12:13:19 -05:00
|
|
|
if (activity.getSlidingPaneLayout().isSlideable()) {
|
|
|
|
if (!activity.shouldPaneBeOpen()) {
|
|
|
|
activity.getSlidingPaneLayout().closePane();
|
|
|
|
activity.getActionBar().setDisplayHomeAsUpEnabled(true);
|
|
|
|
activity.getActionBar().setTitle(conversation.getName());
|
|
|
|
activity.invalidateOptionsMenu();
|
|
|
|
|
2014-02-10 16:45:59 -05:00
|
|
|
}
|
2014-01-28 13:21:54 -05:00
|
|
|
}
|
2014-02-27 18:22:56 -05:00
|
|
|
if (queuedPqpMessage != null) {
|
|
|
|
this.conversation.nextMessageEncryption = Message.ENCRYPTION_PGP;
|
|
|
|
Message message = new Message(conversation, queuedPqpMessage,
|
|
|
|
Message.ENCRYPTION_PGP);
|
|
|
|
sendPgpMessage(message);
|
|
|
|
}
|
2014-03-03 22:09:15 -05:00
|
|
|
if (conversation.getMode() == Conversation.MODE_MULTI) {
|
|
|
|
activity.xmppConnectionService.setOnRenameListener(new OnRenameListener() {
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void onRename(final boolean success) {
|
|
|
|
getActivity().runOnUiThread(new Runnable() {
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void run() {
|
|
|
|
if (success) {
|
|
|
|
Toast.makeText(getActivity(), "Your nickname has been changed",Toast.LENGTH_SHORT).show();
|
|
|
|
} else {
|
|
|
|
Toast.makeText(getActivity(), "Nichname is already in use",Toast.LENGTH_SHORT).show();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
2014-01-24 17:58:51 -05:00
|
|
|
}
|
2014-02-02 10:33:34 -05:00
|
|
|
|
|
|
|
public void updateMessages() {
|
2014-02-16 10:32:15 -05:00
|
|
|
ConversationActivity activity = (ConversationActivity) getActivity();
|
2014-02-27 18:22:56 -05:00
|
|
|
List<Message> encryptedMessages = new LinkedList<Message>();
|
|
|
|
for(Message message : this.conversation.getMessages()) {
|
|
|
|
if (message.getEncryption() == Message.ENCRYPTION_PGP) {
|
|
|
|
encryptedMessages.add(message);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (encryptedMessages.size() > 0) {
|
|
|
|
DecryptMessage task = new DecryptMessage();
|
|
|
|
Message[] msgs = new Message[encryptedMessages.size()];
|
|
|
|
task.execute(encryptedMessages.toArray(msgs));
|
|
|
|
}
|
2014-02-02 10:33:34 -05:00
|
|
|
this.messageList.clear();
|
|
|
|
this.messageList.addAll(this.conversation.getMessages());
|
|
|
|
this.messageListAdapter.notifyDataSetChanged();
|
2014-03-02 23:01:02 -05:00
|
|
|
if (conversation.getMode() == Conversation.MODE_SINGLE) {
|
|
|
|
if (messageList.size() >= 1) {
|
|
|
|
int latestEncryption = this.conversation.getLatestMessage()
|
|
|
|
.getEncryption();
|
|
|
|
if (latestEncryption== Message.ENCRYPTION_DECRYPTED) {
|
|
|
|
conversation.nextMessageEncryption = Message.ENCRYPTION_PGP;
|
|
|
|
} else {
|
|
|
|
conversation.nextMessageEncryption = latestEncryption;
|
|
|
|
}
|
|
|
|
makeFingerprintWarning(latestEncryption);
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
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));
|
|
|
|
}
|
2014-02-27 18:22:56 -05:00
|
|
|
} else {
|
2014-03-02 23:01:02 -05:00
|
|
|
mucError.setVisibility(View.GONE);
|
2014-02-27 18:22:56 -05:00
|
|
|
}
|
2014-02-13 17:40:08 -05:00
|
|
|
}
|
|
|
|
getActivity().invalidateOptionsMenu();
|
2014-02-16 10:32:15 -05:00
|
|
|
updateChatMsgHint();
|
2014-02-05 16:33:39 -05:00
|
|
|
int size = this.messageList.size();
|
|
|
|
if (size >= 1)
|
|
|
|
messagesView.setSelection(size - 1);
|
2014-02-10 17:12:11 -05:00
|
|
|
if (!activity.shouldPaneBeOpen()) {
|
|
|
|
conversation.markRead();
|
2014-03-08 00:25:35 -05:00
|
|
|
//TODO update notifications
|
|
|
|
UIHelper.updateNotification(getActivity(), activity.getConversationList(), false);
|
2014-02-10 17:12:11 -05:00
|
|
|
activity.updateConversationList();
|
|
|
|
}
|
2014-02-02 10:33:34 -05:00
|
|
|
}
|
2014-02-16 10:32:15 -05:00
|
|
|
|
|
|
|
protected void makeFingerprintWarning(int latestEncryption) {
|
|
|
|
final LinearLayout fingerprintWarning = (LinearLayout) getView()
|
|
|
|
.findViewById(R.id.new_fingerprint);
|
2014-02-18 19:35:23 -05:00
|
|
|
if (conversation.getContact() != null) {
|
|
|
|
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() {
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void onClick(View v) {
|
|
|
|
AlertDialog dialog = UIHelper
|
|
|
|
.getVerifyFingerprintDialog(
|
|
|
|
(ConversationActivity) getActivity(),
|
|
|
|
conversation, fingerprintWarning);
|
|
|
|
dialog.show();
|
|
|
|
}
|
|
|
|
});
|
|
|
|
} else {
|
|
|
|
fingerprintWarning.setVisibility(View.GONE);
|
|
|
|
}
|
2014-02-16 10:32:15 -05:00
|
|
|
} else {
|
|
|
|
fingerprintWarning.setVisibility(View.GONE);
|
|
|
|
}
|
|
|
|
}
|
2014-02-16 13:30:22 -05:00
|
|
|
|
|
|
|
protected void sendPlainTextMessage(Message message) {
|
|
|
|
ConversationActivity activity = (ConversationActivity) getActivity();
|
2014-02-27 18:22:56 -05:00
|
|
|
activity.xmppConnectionService.sendMessage(message, null);
|
2014-02-16 13:30:22 -05:00
|
|
|
chatMsg.setText("");
|
|
|
|
}
|
2014-02-18 19:35:23 -05:00
|
|
|
|
2014-02-27 18:22:56 -05:00
|
|
|
protected void sendPgpMessage(final Message message) {
|
|
|
|
ConversationActivity activity = (ConversationActivity) getActivity();
|
|
|
|
final XmppConnectionService xmppService = activity.xmppConnectionService;
|
|
|
|
Contact contact = message.getConversation().getContact();
|
2014-03-03 10:39:19 -05:00
|
|
|
if (activity.hasPgp()) {
|
|
|
|
if (contact.getPgpKeyId() != 0) {
|
|
|
|
xmppService.sendMessage(message, null);
|
|
|
|
chatMsg.setText("");
|
|
|
|
} else {
|
|
|
|
AlertDialog.Builder builder = new AlertDialog.Builder(getActivity());
|
|
|
|
builder.setTitle("No openPGP key found");
|
|
|
|
builder.setIconAttribute(android.R.attr.alertDialogIcon);
|
|
|
|
builder.setMessage("There is no openPGP key assoziated with this contact");
|
|
|
|
builder.setNegativeButton("Cancel", null);
|
|
|
|
builder.setPositiveButton("Send plain text",
|
|
|
|
new DialogInterface.OnClickListener() {
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void onClick(DialogInterface dialog, int which) {
|
|
|
|
conversation.nextMessageEncryption = Message.ENCRYPTION_NONE;
|
|
|
|
message.setEncryption(Message.ENCRYPTION_NONE);
|
|
|
|
xmppService.sendMessage(message, null);
|
|
|
|
chatMsg.setText("");
|
|
|
|
}
|
|
|
|
});
|
|
|
|
builder.create().show();
|
|
|
|
}
|
2014-02-27 18:22:56 -05:00
|
|
|
}
|
|
|
|
}
|
2014-03-03 10:39:19 -05:00
|
|
|
|
2014-02-16 13:30:22 -05:00
|
|
|
protected void sendOtrMessage(final Message message) {
|
|
|
|
ConversationActivity activity = (ConversationActivity) getActivity();
|
|
|
|
final XmppConnectionService xmppService = activity.xmppConnectionService;
|
|
|
|
if (conversation.hasValidOtrSession()) {
|
2014-02-27 18:22:56 -05:00
|
|
|
activity.xmppConnectionService.sendMessage(message, null);
|
2014-02-16 13:30:22 -05:00
|
|
|
chatMsg.setText("");
|
|
|
|
} else {
|
2014-02-18 19:35:23 -05:00
|
|
|
Hashtable<String, Integer> presences;
|
|
|
|
if (conversation.getContact() != null) {
|
|
|
|
presences = conversation.getContact().getPresences();
|
|
|
|
} else {
|
|
|
|
presences = null;
|
|
|
|
}
|
2014-02-20 11:00:50 -05:00
|
|
|
if ((presences == null) || (presences.size() == 0)) {
|
2014-02-16 13:30:22 -05:00
|
|
|
AlertDialog.Builder builder = new AlertDialog.Builder(
|
|
|
|
getActivity());
|
|
|
|
builder.setTitle("Contact is offline");
|
|
|
|
builder.setIconAttribute(android.R.attr.alertDialogIcon);
|
|
|
|
builder.setMessage("Sending OTR encrypted messages to an offline contact is impossible.");
|
|
|
|
builder.setPositiveButton("Send plain text",
|
|
|
|
new DialogInterface.OnClickListener() {
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void onClick(DialogInterface dialog,
|
|
|
|
int which) {
|
|
|
|
conversation.nextMessageEncryption = Message.ENCRYPTION_NONE;
|
|
|
|
message.setEncryption(Message.ENCRYPTION_NONE);
|
2014-02-27 18:22:56 -05:00
|
|
|
xmppService.sendMessage(message, null);
|
2014-02-16 13:30:22 -05:00
|
|
|
chatMsg.setText("");
|
|
|
|
}
|
|
|
|
});
|
|
|
|
builder.setNegativeButton("Cancel", null);
|
|
|
|
builder.create().show();
|
|
|
|
} else if (presences.size() == 1) {
|
2014-02-27 18:22:56 -05:00
|
|
|
xmppService.sendMessage(message, (String) presences.keySet()
|
|
|
|
.toArray()[0]);
|
2014-02-16 13:30:22 -05:00
|
|
|
chatMsg.setText("");
|
|
|
|
} else {
|
|
|
|
AlertDialog.Builder builder = new AlertDialog.Builder(
|
|
|
|
getActivity());
|
|
|
|
builder.setTitle("Choose Presence");
|
|
|
|
final String[] presencesArray = new String[presences.size()];
|
|
|
|
presences.keySet().toArray(presencesArray);
|
2014-02-18 19:35:23 -05:00
|
|
|
builder.setItems(presencesArray,
|
|
|
|
new DialogInterface.OnClickListener() {
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void onClick(DialogInterface dialog,
|
|
|
|
int which) {
|
2014-02-27 18:22:56 -05:00
|
|
|
xmppService.sendMessage(message,
|
2014-02-18 19:35:23 -05:00
|
|
|
presencesArray[which]);
|
|
|
|
chatMsg.setText("");
|
|
|
|
}
|
|
|
|
});
|
2014-02-16 13:30:22 -05:00
|
|
|
builder.create().show();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2014-02-18 19:35:23 -05:00
|
|
|
|
|
|
|
private static class ViewHolder {
|
|
|
|
|
|
|
|
protected TextView time;
|
|
|
|
protected TextView messageBody;
|
|
|
|
protected ImageView imageView;
|
|
|
|
|
|
|
|
}
|
2014-02-19 02:21:33 -05:00
|
|
|
|
2014-02-18 19:35:23 -05:00
|
|
|
private class BitmapCache {
|
|
|
|
private HashMap<String, Bitmap> bitmaps = new HashMap<String, Bitmap>();
|
2014-02-20 11:00:50 -05:00
|
|
|
private Bitmap error = null;
|
2014-02-19 02:21:33 -05:00
|
|
|
|
2014-02-18 19:35:23 -05:00
|
|
|
public Bitmap get(String name, Uri uri) {
|
|
|
|
if (bitmaps.containsKey(name)) {
|
|
|
|
return bitmaps.get(name);
|
|
|
|
} else {
|
|
|
|
Bitmap bm;
|
2014-02-19 02:21:33 -05:00
|
|
|
if (uri != null) {
|
2014-02-18 19:35:23 -05:00
|
|
|
try {
|
|
|
|
bm = BitmapFactory.decodeStream(getActivity()
|
|
|
|
.getContentResolver().openInputStream(uri));
|
|
|
|
} catch (FileNotFoundException e) {
|
|
|
|
bm = UIHelper.getUnknownContactPicture(name, 200);
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
bm = UIHelper.getUnknownContactPicture(name, 200);
|
|
|
|
}
|
|
|
|
bitmaps.put(name, bm);
|
|
|
|
return bm;
|
|
|
|
}
|
|
|
|
}
|
2014-02-27 18:22:56 -05:00
|
|
|
|
2014-02-20 11:00:50 -05:00
|
|
|
public Bitmap getError() {
|
|
|
|
if (error == null) {
|
|
|
|
error = UIHelper.getErrorPicture(200);
|
|
|
|
}
|
|
|
|
return error;
|
|
|
|
}
|
2014-02-18 19:35:23 -05:00
|
|
|
}
|
2014-02-27 18:22:56 -05:00
|
|
|
|
|
|
|
class DecryptMessage extends AsyncTask<Message, Void, Boolean> {
|
|
|
|
|
|
|
|
@Override
|
|
|
|
protected Boolean doInBackground(Message... params) {
|
2014-02-27 20:58:15 -05:00
|
|
|
final ConversationActivity activity = (ConversationActivity) getActivity();
|
2014-02-27 18:22:56 -05:00
|
|
|
askForPassphraseIntent = null;
|
|
|
|
for(int i = 0; i < params.length; ++i) {
|
|
|
|
if (params[i].getEncryption() == Message.ENCRYPTION_PGP) {
|
|
|
|
String body = params[i].getBody();
|
|
|
|
String decrypted = null;
|
2014-03-08 21:33:32 -05:00
|
|
|
if (activity==null) {
|
|
|
|
return false;
|
|
|
|
} else if (!activity.xmppConnectionServiceBound) {
|
|
|
|
return false;
|
|
|
|
}
|
2014-02-27 18:22:56 -05:00
|
|
|
try {
|
|
|
|
decrypted = activity.xmppConnectionService.getPgpEngine().decrypt(body);
|
|
|
|
} catch (UserInputRequiredException e) {
|
|
|
|
askForPassphraseIntent = e.getPendingIntent().getIntentSender();
|
2014-02-27 20:58:15 -05:00
|
|
|
activity.runOnUiThread(new Runnable() {
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void run() {
|
|
|
|
pgpInfo.setVisibility(View.VISIBLE);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
2014-02-27 18:22:56 -05:00
|
|
|
return false;
|
|
|
|
|
|
|
|
} catch (OpenPgpException e) {
|
|
|
|
Log.d("gultsch","error decrypting pgp");
|
|
|
|
}
|
|
|
|
if (decrypted!=null) {
|
|
|
|
params[i].setBody(decrypted);
|
|
|
|
params[i].setEncryption(Message.ENCRYPTION_DECRYPTED);
|
|
|
|
activity.xmppConnectionService.updateMessage(params[i]);
|
|
|
|
}
|
|
|
|
if (activity!=null) {
|
|
|
|
activity.runOnUiThread(new Runnable() {
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void run() {
|
|
|
|
messageListAdapter.notifyDataSetChanged();
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|
2014-02-27 20:58:15 -05:00
|
|
|
if (activity!=null) {
|
|
|
|
activity.runOnUiThread(new Runnable() {
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void run() {
|
|
|
|
activity.updateConversationList();
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
2014-02-27 18:22:56 -05:00
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
2014-01-23 20:04:05 -05:00
|
|
|
}
|