diff options
author | iNPUTmice <daniel@gultsch.de> | 2014-06-11 21:53:25 +0200 |
---|---|---|
committer | iNPUTmice <daniel@gultsch.de> | 2014-06-11 21:53:25 +0200 |
commit | bb9045267393b2a7765d7c121b58c5e7043b525e (patch) | |
tree | a6441672710b78e3041ece15b60481257466b9fa /src/eu/siacs/conversations/ui/ConversationActivity.java | |
parent | 95f1a3d57d6f4a35d4579cf93d24a7621f39cf07 (diff) |
groundwork for offline otr messages
Diffstat (limited to 'src/eu/siacs/conversations/ui/ConversationActivity.java')
-rw-r--r-- | src/eu/siacs/conversations/ui/ConversationActivity.java | 134 |
1 files changed, 44 insertions, 90 deletions
diff --git a/src/eu/siacs/conversations/ui/ConversationActivity.java b/src/eu/siacs/conversations/ui/ConversationActivity.java index bded4e6fb..995568903 100644 --- a/src/eu/siacs/conversations/ui/ConversationActivity.java +++ b/src/eu/siacs/conversations/ui/ConversationActivity.java @@ -11,6 +11,7 @@ import eu.siacs.conversations.entities.Account; import eu.siacs.conversations.entities.Contact; import eu.siacs.conversations.entities.Conversation; import eu.siacs.conversations.entities.Message; +import eu.siacs.conversations.entities.Presences; import eu.siacs.conversations.services.ImageProvider; import eu.siacs.conversations.utils.ExceptionHelper; import eu.siacs.conversations.utils.UIHelper; @@ -835,7 +836,7 @@ public class ConversationActivity extends XmppActivity { message.getConversation().getMessages().add(message); xmppConnectionService.databaseBackend .createMessage(message); - xmppConnectionService.sendMessage(message, null); + xmppConnectionService.sendMessage(message); xmppConnectionService.updateUi( message.getConversation(), false); } @@ -868,99 +869,52 @@ public class ConversationActivity extends XmppActivity { public void selectPresence(final Conversation conversation, final OnPresenceSelected listener, String reason) { - Account account = conversation.getAccount(); - if (account.getStatus() != Account.STATUS_ONLINE) { - AlertDialog.Builder builder = new AlertDialog.Builder(this); - builder.setTitle(getString(R.string.not_connected)); - builder.setIconAttribute(android.R.attr.alertDialogIcon); - if ("otr".equals(reason)) { - builder.setMessage(getString(R.string.you_are_offline, - getString(R.string.otr_messages))); - } else if ("file".equals(reason)) { - builder.setMessage(getString(R.string.you_are_offline, - getString(R.string.files))); - } else { - builder.setMessage(getString(R.string.you_are_offline_blank)); - } - builder.setNegativeButton(getString(R.string.cancel), null); - builder.setPositiveButton(getString(R.string.manage_account), - new OnClickListener() { - - @Override - public void onClick(DialogInterface dialog, int which) { - startActivity(new Intent(activity, - ManageAccountActivity.class)); - } - }); - builder.create().show(); + Contact contact = conversation.getContact(); + if (contact == null) { + showAddToRosterDialog(conversation); listener.onPresenceSelected(false, null); } else { - Contact contact = conversation.getContact(); - if (contact == null) { - showAddToRosterDialog(conversation); - listener.onPresenceSelected(false, null); + Presences presences = contact.getPresences(); + if (presences.size() == 0) { + listener.onPresenceSelected(true, null); + } else if (presences.size() == 1) { + String presence = (String) presences.asStringArray()[0]; + conversation.setNextPresence(presence); + listener.onPresenceSelected(true, presence); } else { - Hashtable<String, Integer> presences = contact.getPresences(); - if (presences.size() == 0) { - AlertDialog.Builder builder = new AlertDialog.Builder(this); - builder.setTitle(getString(R.string.contact_offline)); - if ("otr".equals(reason)) { - builder.setMessage(getString(R.string.contact_offline_otr)); - builder.setPositiveButton( - getString(R.string.send_unencrypted), - new OnClickListener() { - - @Override - public void onClick(DialogInterface dialog, - int which) { - listener.onSendPlainTextInstead(); - } - }); - } else if ("file".equals(reason)) { - builder.setMessage(getString(R.string.contact_offline_file)); - } - builder.setIconAttribute(android.R.attr.alertDialogIcon); - builder.setNegativeButton(getString(R.string.cancel), null); - builder.create().show(); - listener.onPresenceSelected(false, null); - } else if (presences.size() == 1) { - String presence = (String) presences.keySet().toArray()[0]; - conversation.setNextPresence(presence); - listener.onPresenceSelected(true, presence); - } else { - final StringBuilder presence = new StringBuilder(); - AlertDialog.Builder builder = new AlertDialog.Builder(this); - builder.setTitle(getString(R.string.choose_presence)); - final String[] presencesArray = new String[presences.size()]; - presences.keySet().toArray(presencesArray); - int preselectedPresence = 0; - for(int i = 0; i < presencesArray.length; ++i) { - if (presencesArray[i].equals(contact.lastseen.presence)) { - preselectedPresence = i; - break; - } + final StringBuilder presence = new StringBuilder(); + AlertDialog.Builder builder = new AlertDialog.Builder(this); + builder.setTitle(getString(R.string.choose_presence)); + final String[] presencesArray = presences.asStringArray(); + int preselectedPresence = 0; + for (int i = 0; i < presencesArray.length; ++i) { + if (presencesArray[i].equals(contact.lastseen.presence)) { + preselectedPresence = i; + break; } - presence.append(presencesArray[preselectedPresence]); - builder.setSingleChoiceItems(presencesArray,preselectedPresence , - new DialogInterface.OnClickListener() { - - @Override - public void onClick(DialogInterface dialog, - int which) { - presence.delete(0, presence.length()); - presence.append(presencesArray[which]); - }}); - builder.setNegativeButton(R.string.cancel, null); - builder.setPositiveButton(R.string.ok, new OnClickListener() { - - @Override - public void onClick(DialogInterface dialog, int which) { - conversation.setNextPresence(presence.toString()); - listener.onPresenceSelected(true, presence.toString()); - } - }); - builder.create().show(); } + presence.append(presencesArray[preselectedPresence]); + builder.setSingleChoiceItems(presencesArray, + preselectedPresence, + new DialogInterface.OnClickListener() { + + @Override + public void onClick(DialogInterface dialog, + int which) { + presence.delete(0, presence.length()); + presence.append(presencesArray[which]); + } + }); + builder.setNegativeButton(R.string.cancel, null); + builder.setPositiveButton(R.string.ok, new OnClickListener() { + + @Override + public void onClick(DialogInterface dialog, int which) { + conversation.setNextPresence(presence.toString()); + listener.onPresenceSelected(true, presence.toString()); + } + }); + builder.create().show(); } } } @@ -1113,7 +1067,7 @@ public class ConversationActivity extends XmppActivity { @Override public void success(Message message) { - xmppConnectionService.sendMessage(message, null); + xmppConnectionService.sendMessage(message); } @Override |