From 0392e6b2dc4c9bc4063fce5c1b4817c3c6460426 Mon Sep 17 00:00:00 2001 From: Daniel Gultsch Date: Sun, 16 Feb 2014 19:30:22 +0100 Subject: [PATCH] made presences chooser. raw draft. just kinda works --- .../gultsch/chat/entities/Conversation.java | 2 +- .../gultsch/chat/ui/ConversationActivity.java | 7 -- .../gultsch/chat/ui/ConversationFragment.java | 106 +++++++++++------- 3 files changed, 67 insertions(+), 48 deletions(-) diff --git a/src/de/gultsch/chat/entities/Conversation.java b/src/de/gultsch/chat/entities/Conversation.java index 343e83a44..3f83010ce 100644 --- a/src/de/gultsch/chat/entities/Conversation.java +++ b/src/de/gultsch/chat/entities/Conversation.java @@ -106,7 +106,7 @@ public class Conversation extends AbstractEntity { public Message getLatestMessage() { if ((this.messages == null)||(this.messages.size()==0)) { Message message = new Message(this,"",Message.ENCRYPTION_NONE); - message.setTime(0); + message.setTime(getCreated()); return message; } else { return this.messages.get(this.messages.size() - 1); diff --git a/src/de/gultsch/chat/ui/ConversationActivity.java b/src/de/gultsch/chat/ui/ConversationActivity.java index b1464031b..464054ad9 100644 --- a/src/de/gultsch/chat/ui/ConversationActivity.java +++ b/src/de/gultsch/chat/ui/ConversationActivity.java @@ -66,14 +66,7 @@ public class ConversationActivity extends XmppActivity { @Override public void run() { updateConversationList(); - /*for(int i = 0; i < conversationList.size(); ++i) { - if (currentConv == conversationList.get(i)) { - selectedConversation = conversationList.get(i); - break; - } - }*/ if(paneShouldBeOpen) { - selectedConversation = conversationList.get(0); if (conversationList.size() >= 1) { swapConversationFragment(); } else { diff --git a/src/de/gultsch/chat/ui/ConversationFragment.java b/src/de/gultsch/chat/ui/ConversationFragment.java index 1f125ab07..9620c16a7 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 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 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(); + } + } + } }