aboutsummaryrefslogtreecommitdiffstats
path: root/src/eu/siacs/conversations
diff options
context:
space:
mode:
authorDaniel Gultsch <daniel.gultsch@rwth-aachen.de>2014-04-26 12:40:21 +0200
committerDaniel Gultsch <daniel.gultsch@rwth-aachen.de>2014-04-26 12:40:21 +0200
commitf36f2184698b2c0dc7ace4073ed018cdf3122b5b (patch)
treecd66b99f8685c57e44c63e020f635a9d6d46dacc /src/eu/siacs/conversations
parenta55ddb889efb2645b5d72df23edca5bfdf4b8951 (diff)
unified presence selection for otr and file transfer
Diffstat (limited to 'src/eu/siacs/conversations')
-rw-r--r--src/eu/siacs/conversations/ui/ConversationActivity.java99
-rw-r--r--src/eu/siacs/conversations/ui/ConversationFragment.java64
-rw-r--r--src/eu/siacs/conversations/ui/OnPresenceSelected.java1
3 files changed, 90 insertions, 74 deletions
diff --git a/src/eu/siacs/conversations/ui/ConversationActivity.java b/src/eu/siacs/conversations/ui/ConversationActivity.java
index 220c2461..fc19ecc7 100644
--- a/src/eu/siacs/conversations/ui/ConversationActivity.java
+++ b/src/eu/siacs/conversations/ui/ConversationActivity.java
@@ -332,7 +332,13 @@ public class ConversationActivity extends XmppActivity {
startActivityForResult(chooser, ATTACH_FILE);
}
}
- });
+
+ @Override
+ public void onSendPlainTextInstead() {
+ // TODO Auto-generated method stub
+
+ }
+ },"file");
break;
case R.id.action_add:
startActivity(new Intent(this, ContactsActivity.class));
@@ -589,36 +595,77 @@ public class ConversationActivity extends XmppActivity {
listView.invalidateViews();
}
- public void selectPresence(final Conversation conversation, final OnPresenceSelected listener) {
- Contact contact = conversation.getContact();
- if (contact==null) {
- showAddToRosterDialog(conversation);
- listener.onPresenceSelected(false,null);
+ 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();
+ listener.onPresenceSelected(false, null);
} else {
- Hashtable<String, Integer> presences = contact.getPresences();
- if (presences.size() == 0) {
- listener.onPresenceSelected(false, null);
- } else if (presences.size() == 1) {
- String presence = (String) presences.keySet().toArray()[0];
- conversation.setNextPresence(presence);
- listener.onPresenceSelected(true, presence);
+ Contact contact = conversation.getContact();
+ if (contact==null) {
+ showAddToRosterDialog(conversation);
+ listener.onPresenceSelected(false,null);
} else {
- 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);
- builder.setItems(presencesArray,
- new DialogInterface.OnClickListener() {
-
+ 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) {
- String presence = presencesArray[which];
- conversation.setNextPresence(presence);
- listener.onPresenceSelected(true,presence);
+ public void onClick(DialogInterface dialog, int which) {
+ listener.onSendPlainTextInstead();
}
});
- builder.create().show();
+ } 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 {
+ 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);
+ builder.setItems(presencesArray,
+ new DialogInterface.OnClickListener() {
+
+ @Override
+ public void onClick(DialogInterface dialog,
+ int which) {
+ String presence = presencesArray[which];
+ conversation.setNextPresence(presence);
+ listener.onPresenceSelected(true,presence);
+ }
+ });
+ builder.create().show();
+ }
}
}
}
diff --git a/src/eu/siacs/conversations/ui/ConversationFragment.java b/src/eu/siacs/conversations/ui/ConversationFragment.java
index 5ade8a53..270aa031 100644
--- a/src/eu/siacs/conversations/ui/ConversationFragment.java
+++ b/src/eu/siacs/conversations/ui/ConversationFragment.java
@@ -616,55 +616,23 @@ public class ConversationFragment extends Fragment {
activity.xmppConnectionService.sendMessage(message, null);
chatMsg.setText("");
} else {
- Hashtable<String, Integer> presences;
- if (conversation.getContact() != null) {
- presences = conversation.getContact().getPresences();
- } else {
- presences = null;
- }
- if ((presences == null) || (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(message, null);
- chatMsg.setText("");
- }
- });
- builder.setNegativeButton("Cancel", null);
- builder.create().show();
- } else if (presences.size() == 1) {
- xmppService.sendMessage(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() {
+ 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 onClick(DialogInterface dialog,
- int which) {
- xmppService.sendMessage(message,
- presencesArray[which]);
- chatMsg.setText("");
- }
- });
- builder.create().show();
- }
+ @Override
+ public void onSendPlainTextInstead() {
+ message.setEncryption(Message.ENCRYPTION_NONE);
+ xmppService.sendMessage(message,null);
+ chatMsg.setText("");
+ }
+ },"otr");
}
}
diff --git a/src/eu/siacs/conversations/ui/OnPresenceSelected.java b/src/eu/siacs/conversations/ui/OnPresenceSelected.java
index 7e424b2e..b3a995dc 100644
--- a/src/eu/siacs/conversations/ui/OnPresenceSelected.java
+++ b/src/eu/siacs/conversations/ui/OnPresenceSelected.java
@@ -2,4 +2,5 @@ package eu.siacs.conversations.ui;
public interface OnPresenceSelected {
public void onPresenceSelected(boolean success, String presence);
+ public void onSendPlainTextInstead();
}