diff options
author | Daniel Gultsch <daniel.gultsch@rwth-aachen.de> | 2014-02-16 19:30:22 +0100 |
---|---|---|
committer | Daniel Gultsch <daniel.gultsch@rwth-aachen.de> | 2014-02-16 19:30:22 +0100 |
commit | 0392e6b2dc4c9bc4063fce5c1b4817c3c6460426 (patch) | |
tree | 7481ced5fb1895e251d78c6b4ec023e8f1dde808 /src/de/gultsch/chat/ui/ConversationFragment.java | |
parent | 9c7cacdbddf6ba1a34fd56b71718ba4e44e20efa (diff) |
made presences chooser. raw draft. just kinda works
Diffstat (limited to 'src/de/gultsch/chat/ui/ConversationFragment.java')
-rw-r--r-- | src/de/gultsch/chat/ui/ConversationFragment.java | 106 |
1 files changed, 66 insertions, 40 deletions
diff --git a/src/de/gultsch/chat/ui/ConversationFragment.java b/src/de/gultsch/chat/ui/ConversationFragment.java index 1f125ab0..9620c16a 100644 --- a/src/de/gultsch/chat/ui/ConversationFragment.java +++ b/src/de/gultsch/chat/ui/ConversationFragment.java @@ -54,49 +54,12 @@ public class ConversationFragment extends Fragment { final XmppConnectionService xmppService = activity.xmppConnectionService; if (chatMsg.getText().length() < 1) return; - final Message message = new Message(conversation, chatMsg.getText() + Message message = new Message(conversation, chatMsg.getText() .toString(), conversation.nextMessageEncryption); if (conversation.nextMessageEncryption == Message.ENCRYPTION_OTR) { - if (conversation.hasValidOtrSession()) { - activity.xmppConnectionService.sendMessage( - conversation.getAccount(), message, null); - chatMsg.setText(""); - } else { - Hashtable<String, Integer> presences = conversation - .getContact().getPresences(); - if (presences.size() == 0) { - 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); - xmppService.sendMessage( - conversation.getAccount(), - message, null); - chatMsg.setText(""); - } - }); - builder.setNegativeButton("Cancel", null); - builder.create().show(); - } else if (presences.size() == 1) { - xmppService.sendMessage(conversation.getAccount(), - message, - (String) presences.keySet().toArray()[0]); - chatMsg.setText(""); - } - } + sendOtrMessage(message); } else { - xmppService.sendMessage(conversation.getAccount(), message, - null); - chatMsg.setText(""); + sendPlainTextMessage(message); } } }; @@ -334,4 +297,67 @@ public class ConversationFragment extends Fragment { fingerprintWarning.setVisibility(View.GONE); } } + + protected void sendPlainTextMessage(Message message) { + ConversationActivity activity = (ConversationActivity) getActivity(); + activity.xmppConnectionService.sendMessage(conversation.getAccount(), message, + null); + chatMsg.setText(""); + } + + protected void sendOtrMessage(final Message message) { + ConversationActivity activity = (ConversationActivity) getActivity(); + final XmppConnectionService xmppService = activity.xmppConnectionService; + if (conversation.hasValidOtrSession()) { + activity.xmppConnectionService.sendMessage( + conversation.getAccount(), message, null); + chatMsg.setText(""); + } else { + Hashtable<String, Integer> presences = conversation + .getContact().getPresences(); + if (presences.size() == 0) { + 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); + xmppService.sendMessage( + conversation.getAccount(), + message, null); + chatMsg.setText(""); + } + }); + builder.setNegativeButton("Cancel", null); + builder.create().show(); + } else if (presences.size() == 1) { + xmppService.sendMessage(conversation.getAccount(), + message, + (String) presences.keySet().toArray()[0]); + 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); + builder.setItems(presencesArray, new DialogInterface.OnClickListener() { + + @Override + public void onClick(DialogInterface dialog, int which) { + xmppService.sendMessage(conversation.getAccount(), message, presencesArray[which]); + chatMsg.setText(""); + } + }); + builder.create().show(); + } + } + } } |