anotherim/src/eu/siacs/conversations/ui/ConversationFragment.java

777 lines
25 KiB
Java
Raw Normal View History

2014-02-28 17:46:01 +00:00
package eu.siacs.conversations.ui;
2014-01-24 01:04:05 +00:00
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
2014-02-16 15:32:15 +00:00
import java.util.Set;
2014-05-01 20:33:49 +00:00
import org.openintents.openpgp.OpenPgpError;
2014-02-16 15:32:15 +00:00
import net.java.otr4j.session.SessionStatus;
2014-02-28 17:46:01 +00:00
import eu.siacs.conversations.R;
2014-05-01 20:33:49 +00:00
import eu.siacs.conversations.crypto.OnPgpEngineResult;
import eu.siacs.conversations.crypto.PgpEngine;
2014-04-03 15:39:57 +00:00
import eu.siacs.conversations.entities.Account;
2014-02-28 17:46:01 +00:00
import eu.siacs.conversations.entities.Contact;
import eu.siacs.conversations.entities.Conversation;
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-02-28 17:46:01 +00:00
import eu.siacs.conversations.services.XmppConnectionService;
import eu.siacs.conversations.utils.UIHelper;
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;
import android.content.Context;
2014-02-16 15:32:15 +00:00
import android.content.DialogInterface;
2014-03-04 01:51:01 +00:00
import android.content.Intent;
2014-02-27 23:22:56 +00:00
import android.content.IntentSender;
import android.content.SharedPreferences;
2014-02-27 23:22:56 +00:00
import android.content.IntentSender.SendIntentException;
import android.graphics.Bitmap;
2014-01-26 02:27:55 +00:00
import android.graphics.Typeface;
import android.net.Uri;
2014-01-24 01:04:05 +00:00
import android.os.Bundle;
import android.preference.PreferenceManager;
import android.util.DisplayMetrics;
import android.util.Log;
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-01-24 01:04:05 +00:00
import android.view.ViewGroup;
2014-01-26 02:27:55 +00:00
import android.widget.ArrayAdapter;
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
protected Conversation conversation;
protected ListView messagesView;
protected LayoutInflater inflater;
protected List<Message> messageList = new ArrayList<Message>();
protected ArrayAdapter<Message> messageListAdapter;
2014-02-10 02:34:00 +00:00
protected Contact contact;
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
protected Bitmap selfBitmap;
2014-03-14 21:40:56 +00:00
private boolean useSubject = true;
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;
Message message = new Message(conversation, chatMsg.getText()
2014-05-07 10:33:55 +00:00
.toString(), conversation.getNextEncryption());
if (conversation.getNextEncryption() == Message.ENCRYPTION_OTR) {
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 {
sendPlainTextMessage(message);
2014-02-16 15:32:15 +00:00
}
}
};
2014-02-27 23:22:56 +00:00
protected OnClickListener clickToDecryptListener = new OnClickListener() {
2014-02-27 23:22:56 +00:00
@Override
public void onClick(View v) {
if (askForPassphraseIntent != null) {
2014-02-27 23:22:56 +00:00
try {
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
}
}
}
};
private LinearLayout pgpInfo;
2014-03-03 04:01:02 +00:00
private LinearLayout mucError;
private TextView mucErrorText;
private OnClickListener clickToMuc = new OnClickListener() {
2014-03-03 04:01:02 +00:00
@Override
public void onClick(View v) {
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
}
};
private ConversationActivity activity;
public void hidePgpPassphraseBox() {
pgpInfo.setVisibility(View.GONE);
}
2014-02-16 15:32:15 +00:00
public void updateChatMsgHint() {
if (conversation.getMode() == Conversation.MODE_MULTI) {
2014-04-16 21:58:53 +00:00
chatMsg.setHint(getString(R.string.send_message_to_conference));
2014-02-16 15:32:15 +00:00
} else {
2014-05-07 10:33:55 +00:00
switch (conversation.getNextEncryption()) {
2014-02-16 15:32:15 +00:00
case Message.ENCRYPTION_NONE:
2014-04-16 21:58:53 +00:00
chatMsg.setHint(getString(R.string.send_plain_text_message));
2014-02-16 15:32:15 +00:00
break;
case Message.ENCRYPTION_OTR:
2014-04-16 21:58:53 +00:00
chatMsg.setHint(getString(R.string.send_otr_message));
2014-02-16 15:32:15 +00:00
break;
case Message.ENCRYPTION_PGP:
2014-04-16 21:58:53 +00:00
chatMsg.setHint(getString(R.string.send_pgp_message));
2014-02-27 23:22:56 +00:00
break;
2014-02-16 15:32:15 +00:00
default:
break;
}
}
}
@Override
public View onCreateView(final LayoutInflater inflater,
ViewGroup container, Bundle savedInstanceState) {
2014-01-26 02:27:55 +00:00
final DisplayMetrics metrics = getResources().getDisplayMetrics();
this.inflater = inflater;
2014-01-26 02:27:55 +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-03-13 20:37:27 +00:00
if (pastedText!=null) {
chatMsg.setText(pastedText);
}
2014-02-16 15:32:15 +00:00
ImageButton sendButton = (ImageButton) view
.findViewById(R.id.textSendButton);
sendButton.setOnClickListener(this.sendMsgListener);
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);
mucError.setOnClickListener(clickToMuc);
2014-03-03 04:01:02 +00:00
mucErrorText = (TextView) view.findViewById(R.id.muc_error_msg);
2014-02-27 23:22:56 +00:00
messagesView = (ListView) view.findViewById(R.id.messages_view);
messageListAdapter = new ArrayAdapter<Message>(this.getActivity()
2014-02-16 15:32:15 +00:00
.getApplicationContext(), R.layout.message_sent,
this.messageList) {
private static final int SENT = 0;
private static final int RECIEVED = 1;
2014-02-16 15:32:15 +00:00
@Override
public int getViewTypeCount() {
2014-04-11 07:13:56 +00:00
return 2;
}
@Override
public int getItemViewType(int position) {
2014-04-11 07:13:56 +00:00
if (getItem(position).getStatus() <= Message.STATUS_RECIEVED) {
return RECIEVED;
} else {
return SENT;
}
}
2014-01-26 02:27:55 +00:00
@Override
public View getView(int position, View view, ViewGroup parent) {
final Message item = getItem(position);
int type = getItemViewType(position);
ViewHolder viewHolder;
if (view == null) {
2014-02-19 07:21:33 +00:00
viewHolder = new ViewHolder();
switch (type) {
case SENT:
view = (View) inflater.inflate(R.layout.message_sent,
null);
viewHolder.contact_picture = (ImageView) view
.findViewById(R.id.message_photo);
viewHolder.contact_picture.setImageBitmap(selfBitmap);
break;
case RECIEVED:
view = (View) inflater.inflate(
R.layout.message_recieved, null);
viewHolder.contact_picture = (ImageView) view
.findViewById(R.id.message_photo);
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) {
viewHolder.contact_picture.setImageBitmap(mBitmapCache
2014-03-14 21:40:56 +00:00
.get(item.getConversation().getName(useSubject), item
.getConversation().getContact(),
getActivity()
.getApplicationContext()));
2014-02-19 07:21:33 +00:00
}
break;
default:
viewHolder = null;
break;
}
viewHolder.indicator = (ImageView) view.findViewById(R.id.security_indicator);
viewHolder.image = (ImageView) view.findViewById(R.id.message_image);
2014-02-19 07:21:33 +00:00
viewHolder.messageBody = (TextView) view
.findViewById(R.id.message_body);
viewHolder.time = (TextView) view
.findViewById(R.id.message_time);
view.setTag(viewHolder);
} else {
viewHolder = (ViewHolder) view.getTag();
}
2014-05-01 20:33:49 +00:00
if (type == RECIEVED) {
2014-02-27 23:22:56 +00:00
if (item.getConversation().getMode() == Conversation.MODE_MULTI) {
2014-02-16 15:32:15 +00:00
if (item.getCounterpart() != null) {
viewHolder.contact_picture.setImageBitmap(mBitmapCache
.get(item.getCounterpart(), null,
getActivity()
.getApplicationContext()));
} else {
viewHolder.contact_picture.setImageBitmap(mBitmapCache
2014-03-14 21:40:56 +00:00
.get(item.getConversation().getName(useSubject),
null, getActivity()
.getApplicationContext()));
}
2014-02-01 14:07:20 +00:00
}
2014-01-26 02:27:55 +00:00
}
if (item.getEncryption() == Message.ENCRYPTION_NONE) {
viewHolder.indicator.setVisibility(View.GONE);
} else {
viewHolder.indicator.setVisibility(View.VISIBLE);
}
2014-05-01 20:33:49 +00:00
String filesize = "";
2014-05-06 19:34:30 +00:00
if ((item.getType() == Message.TYPE_IMAGE)&&((item.getEncryption() == Message.ENCRYPTION_DECRYPTED)||(item.getEncryption() == Message.ENCRYPTION_NONE))) {
2014-05-01 20:33:49 +00:00
String[] fileParams = item.getBody().split(",");
if ((fileParams.length>=1)&&(item.getStatus() != Message.STATUS_PREPARING)) {
2014-05-01 20:33:49 +00:00
long size = Long.parseLong(fileParams[0]);
filesize = size/1024+" KB \u00B7 ";
}
if ((item.getStatus() == Message.STATUS_PREPARING)||(item.getStatus() == Message.STATUS_RECIEVING)) {
viewHolder.image.setVisibility(View.GONE);
viewHolder.messageBody.setVisibility(View.VISIBLE);
if (item.getStatus() == Message.STATUS_PREPARING) {
viewHolder.messageBody.setText(getString(R.string.preparing_image));
} else if (item.getStatus() == Message.STATUS_RECIEVING) {
viewHolder.download_button.setVisibility(View.GONE);
viewHolder.messageBody.setText(getString(R.string.receiving_image));
}
viewHolder.messageBody.setTextColor(0xff33B5E5);
viewHolder.messageBody.setTypeface(null,Typeface.ITALIC);
} else if (item.getStatus() == Message.STATUS_RECEIVED_OFFER) {
viewHolder.image.setVisibility(View.GONE);
viewHolder.messageBody.setVisibility(View.GONE);
viewHolder.download_button.setVisibility(View.VISIBLE);
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");
}
}
});
} else {
2014-04-25 14:24:56 +00:00
viewHolder.messageBody.setVisibility(View.GONE);
viewHolder.image.setVisibility(View.VISIBLE);
2014-05-01 20:33:49 +00:00
if (fileParams.length==3) {
double target = metrics.density * 288;
2014-05-01 20:33:49 +00:00
int w = Integer.parseInt(fileParams[1]);
int h = Integer.parseInt(fileParams[2]);
2014-04-25 14:24:56 +00:00
int scalledW;
int scalledH;
if (w <= h) {
scalledW = (int) (w / ((double) h / target));
scalledH = (int) target;
2014-04-25 14:24:56 +00:00
} else {
scalledW = (int) target;
2014-04-25 14:24:56 +00:00
scalledH = (int) (h / ((double) w / target));
}
viewHolder.image.setLayoutParams(new LinearLayout.LayoutParams(scalledW, scalledH));
} else {
Log.d("xmppService","message body has less than 3 params");
}
activity.loadBitmap(item, viewHolder.image);
viewHolder.image.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
Uri uri = Uri.parse("content://eu.siacs.conversations.images/"+item.getConversationUuid()+"/"+item.getUuid());
Log.d("xmppService","staring intent with uri:"+uri.toString());
Intent intent = new Intent(Intent.ACTION_VIEW);
intent.setDataAndType(uri, "image/*");
startActivity(intent);
}
});
}
2014-04-06 13:34:08 +00:00
} else {
viewHolder.image.setVisibility(View.GONE);
2014-04-06 13:34:08 +00:00
viewHolder.messageBody.setVisibility(View.VISIBLE);
String body = item.getBody();
if (body != null) {
if (item.getEncryption() == Message.ENCRYPTION_PGP) {
viewHolder.messageBody
.setText(getString(R.string.encrypted_message));
viewHolder.messageBody.setTextColor(0xff33B5E5);
viewHolder.messageBody.setTypeface(null,
Typeface.ITALIC);
2014-05-01 20:33:49 +00:00
} else if (item.getEncryption() == Message.ENCRYPTION_DECRYPTION_FAILED) {
viewHolder.messageBody.setText(getString(R.string.decryption_failed));
viewHolder.messageBody.setTextColor(0xFFe92727);
viewHolder.messageBody.setTypeface(null,Typeface.NORMAL);
2014-04-06 13:34:08 +00:00
} else {
viewHolder.messageBody.setText(body.trim());
2014-04-11 07:13:56 +00:00
viewHolder.messageBody.setTextColor(0xff333333);
2014-04-06 13:34:08 +00:00
viewHolder.messageBody.setTypeface(null,
Typeface.NORMAL);
2014-03-15 03:59:18 +00:00
}
2014-02-27 23:22:56 +00:00
}
2014-02-02 16:53:34 +00:00
}
2014-04-11 07:13:56 +00:00
switch (item.getStatus()) {
case Message.STATUS_UNSEND:
viewHolder.time.setTypeface(null, Typeface.ITALIC);
2014-04-11 07:13:56 +00:00
viewHolder.time.setTextColor(0xFF8e8e8e);
2014-05-01 20:33:49 +00:00
viewHolder.time.setText(filesize+"sending\u2026");
2014-04-11 07:13:56 +00:00
break;
case Message.STATUS_OFFERED:
viewHolder.time.setTypeface(null, Typeface.ITALIC);
viewHolder.time.setTextColor(0xFF8e8e8e);
2014-05-01 20:33:49 +00:00
viewHolder.time.setText(filesize+"offering\u2026");
break;
2014-04-11 07:13:56 +00:00
case Message.STATUS_SEND_FAILED:
2014-05-01 20:33:49 +00:00
viewHolder.time.setText(filesize+getString(R.string.send_failed) + " \u00B7 " + UIHelper.readableTimeDifference(item
2014-04-11 07:13:56 +00:00
.getTimeSent()));
viewHolder.time.setTextColor(0xFFe92727);
viewHolder.time.setTypeface(null,Typeface.NORMAL);
break;
case Message.STATUS_SEND_REJECTED:
2014-05-01 20:33:49 +00:00
viewHolder.time.setText(filesize+getString(R.string.send_rejected));
2014-04-11 07:13:56 +00:00
viewHolder.time.setTextColor(0xFFe92727);
viewHolder.time.setTypeface(null,Typeface.NORMAL);
break;
default:
viewHolder.time.setTypeface(null, Typeface.NORMAL);
2014-04-11 07:13:56 +00:00
viewHolder.time.setTextColor(0xFF8e8e8e);
if (item.getConversation().getMode() == Conversation.MODE_SINGLE) {
2014-05-01 20:33:49 +00:00
viewHolder.time.setText(filesize+UIHelper
.readableTimeDifference(item.getTimeSent()));
2014-02-16 15:32:15 +00:00
} else {
viewHolder.time.setText(item.getCounterpart()
2014-02-16 15:32:15 +00:00
+ " \u00B7 "
+ UIHelper.readableTimeDifference(item
.getTimeSent()));
2014-02-11 22:55:03 +00:00
}
2014-04-11 07:13:56 +00:00
break;
2014-01-26 02:27:55 +00:00
}
return view;
}
};
messagesView.setAdapter(messageListAdapter);
2014-01-26 02:27:55 +00:00
return view;
}
protected Bitmap findSelfPicture() {
SharedPreferences sharedPref = PreferenceManager
.getDefaultSharedPreferences(getActivity()
.getApplicationContext());
boolean showPhoneSelfContactPicture = sharedPref.getBoolean(
"show_phone_selfcontact_picture", true);
return UIHelper.getSelfContactPicture(conversation.getAccount(), 48,
showPhoneSelfContactPicture, getActivity());
}
@Override
public void onStart() {
super.onStart();
this.activity = (ConversationActivity) getActivity();
SharedPreferences preferences = PreferenceManager.getDefaultSharedPreferences(activity);
this.useSubject = preferences.getBoolean("use_subject_in_muc", true);
if (activity.xmppConnectionServiceBound) {
this.onBackendConnected();
}
}
2014-02-16 15:32:15 +00:00
public void onBackendConnected() {
2014-02-07 01:57:36 +00:00
this.conversation = activity.getSelectedConversation();
if (this.conversation == null) {
2014-03-10 18:22:13 +00:00
return;
}
this.selfBitmap = findSelfPicture();
updateMessages();
2014-01-28 18:21:54 +00:00
// rendering complete. now go tell activity to close pane
2014-03-07 17:13:19 +00:00
if (activity.getSlidingPaneLayout().isSlideable()) {
if (!activity.shouldPaneBeOpen()) {
activity.getSlidingPaneLayout().closePane();
activity.getActionBar().setDisplayHomeAsUpEnabled(true);
2014-03-14 21:40:56 +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) {
activity.xmppConnectionService
.setOnRenameListener(new OnRenameListener() {
2014-03-04 03:09:15 +00:00
@Override
public void onRename(final boolean success) {
2014-03-14 18:12:24 +00:00
activity.xmppConnectionService.updateConversation(conversation);
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),
Toast.LENGTH_SHORT).show();
} else {
Toast.makeText(getActivity(),
2014-04-16 21:58:53 +00:00
getString(R.string.nick_in_use),
Toast.LENGTH_SHORT).show();
}
}
});
2014-03-04 03:09:15 +00:00
}
});
}
}
2014-05-01 20:33:49 +00:00
private void decryptMessage(final Message message) {
Log.d("xmppService","called to decrypt");
PgpEngine engine = activity.xmppConnectionService.getPgpEngine();
if (engine!=null) {
engine.decrypt(message,new OnPgpEngineResult() {
@Override
public void userInputRequried(PendingIntent pi) {
askForPassphraseIntent = pi.getIntentSender();
pgpInfo.setVisibility(View.VISIBLE);
}
@Override
public void success() {
Log.d("xmppService","successfully decrypted");
activity.xmppConnectionService.databaseBackend.updateMessage(message);
updateMessages();
}
@Override
public void error(OpenPgpError openPgpError) {
Log.d("xmppService","decryption error"+openPgpError.getMessage());
message.setEncryption(Message.ENCRYPTION_DECRYPTION_FAILED);
//updateMessages();
}
});
} else {
Log.d("xmppService","engine was null");
}
}
public void updateMessages() {
2014-02-16 15:32:15 +00:00
ConversationActivity activity = (ConversationActivity) getActivity();
if (this.conversation != null) {
for (Message message : this.conversation.getMessages()) {
2014-05-06 19:34:30 +00:00
if ((message.getEncryption() == Message.ENCRYPTION_PGP)&&(message.getStatus() == Message.STATUS_RECIEVED)) {
2014-05-01 20:33:49 +00:00
decryptMessage(message);
break;
2014-03-03 04:01:02 +00:00
}
}
this.messageList.clear();
this.messageList.addAll(this.conversation.getMessages());
this.messageListAdapter.notifyDataSetChanged();
if (conversation.getMode() == Conversation.MODE_SINGLE) {
if (messageList.size() >= 1) {
2014-05-07 10:33:55 +00:00
conversation.setNextEncryption(conversation.getLatestEncryption());
makeFingerprintWarning(conversation.getLatestEncryption());
2014-03-03 04:01:02 +00:00
}
2014-02-27 23:22:56 +00:00
} 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));
}
} else {
mucError.setVisibility(View.GONE);
}
}
getActivity().invalidateOptionsMenu();
updateChatMsgHint();
int size = this.messageList.size();
if (size >= 1)
messagesView.setSelection(size - 1);
if (!activity.shouldPaneBeOpen()) {
conversation.markRead();
// TODO update notifications
UIHelper.updateNotification(getActivity(),
activity.getConversationList(), null, false);
activity.updateConversationList();
2014-02-27 23:22:56 +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);
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 15:32:15 +00:00
} else {
fingerprintWarning.setVisibility(View.GONE);
}
}
protected void sendPlainTextMessage(Message message) {
ConversationActivity activity = (ConversationActivity) getActivity();
2014-02-27 23:22:56 +00:00
activity.xmppConnectionService.sendMessage(message, null);
chatMsg.setText("");
}
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();
final Account account = message.getConversation().getAccount();
if (activity.hasPgp()) {
if (contact.getPgpKeyId() != 0) {
2014-05-07 10:33:55 +00:00
xmppService.getPgpEngine().hasKey(contact, new OnPgpEngineResult() {
2014-05-01 20:33:49 +00:00
@Override
public void userInputRequried(PendingIntent pi) {
2014-05-07 10:33:55 +00:00
activity.runIntent(pi, ConversationActivity.REQUEST_SEND_MESSAGE);
2014-04-03 15:39:57 +00:00
}
2014-05-01 20:33:49 +00:00
@Override
public void success() {
2014-05-06 19:34:30 +00:00
xmppService.getPgpEngine().encrypt(account, message,new OnPgpEngineResult() {
2014-05-01 20:33:49 +00:00
@Override
public void userInputRequried(PendingIntent pi) {
2014-05-07 10:33:55 +00:00
activity.runIntent(pi, ConversationActivity.REQUEST_SEND_MESSAGE);
2014-05-01 20:33:49 +00:00
}
@Override
public void success() {
xmppService.sendMessage(message, null);
chatMsg.setText("");
}
@Override
public void error(OpenPgpError openPgpError) {
// TODO Auto-generated method stub
}
});
}
@Override
public void error(OpenPgpError openPgpError) {
Log.d("xmppService","openpgp error"+openPgpError.getMessage());
}
});
} 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 associated with this contact");
builder.setNegativeButton("Cancel", null);
builder.setPositiveButton("Send plain text",
new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog,
int which) {
2014-05-07 10:33:55 +00:00
conversation.setNextEncryption(Message.ENCRYPTION_NONE);
message.setEncryption(Message.ENCRYPTION_NONE);
xmppService.sendMessage(message, null);
chatMsg.setText("");
}
});
builder.create().show();
}
2014-02-27 23:22:56 +00:00
}
}
protected void sendOtrMessage(final Message message) {
ConversationActivity activity = (ConversationActivity) getActivity();
final XmppConnectionService xmppService = activity.xmppConnectionService;
if (conversation.hasValidOtrSession()) {
2014-02-27 23:22:56 +00:00
activity.xmppConnectionService.sendMessage(message, null);
chatMsg.setText("");
} else {
activity.selectPresence(message.getConversation(), new OnPresenceSelected() {
@Override
public void onPresenceSelected(boolean success, String presence) {
if (success) {
xmppService.sendMessage(message,presence);
chatMsg.setText("");
}
}
@Override
public void onSendPlainTextInstead() {
message.setEncryption(Message.ENCRYPTION_NONE);
xmppService.sendMessage(message,null);
chatMsg.setText("");
}
},"otr");
}
}
private static class ViewHolder {
protected Button download_button;
2014-04-06 13:34:08 +00:00
protected ImageView image;
protected ImageView indicator;
protected TextView time;
protected TextView messageBody;
protected ImageView contact_picture;
}
2014-02-19 07:21:33 +00:00
private class BitmapCache {
private HashMap<String, Bitmap> bitmaps = new HashMap<String, Bitmap>();
private Bitmap error = null;
2014-02-19 07:21:33 +00:00
public Bitmap get(String name, Contact contact, Context context) {
if (bitmaps.containsKey(name)) {
return bitmaps.get(name);
} else {
Bitmap bm;
if (contact != null){
bm = UIHelper.getContactPicture(contact, 48, context, false);
} else {
bm = UIHelper.getContactPicture(name, 48, context, false);
}
bitmaps.put(name, bm);
return bm;
}
}
}
2014-05-01 20:33:49 +00:00
/*class DecryptMessage extends AsyncTask<Message, Void, Boolean> {
2014-02-27 23:22:56 +00:00
@Override
protected Boolean doInBackground(Message... params) {
final ConversationActivity activity = (ConversationActivity) getActivity();
2014-02-27 23:22:56 +00:00
askForPassphraseIntent = null;
for (int i = 0; i < params.length; ++i) {
2014-02-27 23:22:56 +00:00
if (params[i].getEncryption() == Message.ENCRYPTION_PGP) {
String body = params[i].getBody();
String decrypted = null;
if (activity == null) {
2014-03-09 02:33:32 +00:00
return false;
} else if (!activity.xmppConnectionServiceBound) {
return false;
}
2014-02-27 23:22:56 +00:00
try {
decrypted = activity.xmppConnectionService
2014-04-03 15:39:57 +00:00
.getPgpEngine().decrypt(conversation.getAccount(),body);
2014-02-27 23:22:56 +00:00
} catch (UserInputRequiredException e) {
askForPassphraseIntent = e.getPendingIntent()
.getIntentSender();
activity.runOnUiThread(new Runnable() {
@Override
public void run() {
pgpInfo.setVisibility(View.VISIBLE);
}
});
2014-02-27 23:22:56 +00:00
return false;
2014-02-27 23:22:56 +00:00
} catch (OpenPgpException e) {
Log.d("gultsch", "error decrypting pgp");
2014-02-27 23:22:56 +00:00
}
if (decrypted != null) {
2014-02-27 23:22:56 +00:00
params[i].setBody(decrypted);
params[i].setEncryption(Message.ENCRYPTION_DECRYPTED);
activity.xmppConnectionService.updateMessage(params[i]);
}
if (activity != null) {
2014-02-27 23:22:56 +00:00
activity.runOnUiThread(new Runnable() {
2014-02-27 23:22:56 +00:00
@Override
public void run() {
messageListAdapter.notifyDataSetChanged();
}
});
}
}
if (activity != null) {
activity.runOnUiThread(new Runnable() {
@Override
public void run() {
activity.updateConversationList();
}
});
}
2014-02-27 23:22:56 +00:00
}
return true;
}
2014-05-01 20:33:49 +00:00
}*/
2014-03-13 20:37:27 +00:00
public void setText(String text) {
this.pastedText = text;
}
2014-01-24 01:04:05 +00:00
}