diff options
Diffstat (limited to 'src/eu/siacs/conversations/ui')
-rw-r--r-- | src/eu/siacs/conversations/ui/ConversationActivity.java | 134 | ||||
-rw-r--r-- | src/eu/siacs/conversations/ui/ConversationFragment.java | 13 |
2 files changed, 51 insertions, 96 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 diff --git a/src/eu/siacs/conversations/ui/ConversationFragment.java b/src/eu/siacs/conversations/ui/ConversationFragment.java index 8d936781a..5d7e9f94d 100644 --- a/src/eu/siacs/conversations/ui/ConversationFragment.java +++ b/src/eu/siacs/conversations/ui/ConversationFragment.java @@ -784,7 +784,7 @@ public class ConversationFragment extends Fragment { protected void sendPlainTextMessage(Message message) { ConversationActivity activity = (ConversationActivity) getActivity(); - activity.xmppConnectionService.sendMessage(message, null); + activity.xmppConnectionService.sendMessage(message); messageSent(); } @@ -828,7 +828,7 @@ public class ConversationFragment extends Fragment { conversation .setNextEncryption(Message.ENCRYPTION_NONE); message.setEncryption(Message.ENCRYPTION_NONE); - xmppService.sendMessage(message, null); + xmppService.sendMessage(message); messageSent(); } }); @@ -854,7 +854,7 @@ public class ConversationFragment extends Fragment { conversation .setNextEncryption(Message.ENCRYPTION_NONE); message.setEncryption(Message.ENCRYPTION_NONE); - xmppService.sendMessage(message, null); + xmppService.sendMessage(message); messageSent(); } }); @@ -886,7 +886,7 @@ public class ConversationFragment extends Fragment { ConversationActivity activity = (ConversationActivity) getActivity(); final XmppConnectionService xmppService = activity.xmppConnectionService; if (conversation.hasValidOtrSession()) { - activity.xmppConnectionService.sendMessage(message, null); + activity.xmppConnectionService.sendMessage(message); messageSent(); } else { activity.selectPresence(message.getConversation(), @@ -896,7 +896,8 @@ public class ConversationFragment extends Fragment { public void onPresenceSelected(boolean success, String presence) { if (success) { - xmppService.sendMessage(message, presence); + message.setPresence(presence); + xmppService.sendMessage(message); messageSent(); } } @@ -904,7 +905,7 @@ public class ConversationFragment extends Fragment { @Override public void onSendPlainTextInstead() { message.setEncryption(Message.ENCRYPTION_NONE); - xmppService.sendMessage(message, null); + xmppService.sendMessage(message); messageSent(); } }, "otr"); |