made presences chooser. raw draft. just kinda works

This commit is contained in:
Daniel Gultsch 2014-02-16 19:30:22 +01:00
parent 9c7cacdbdd
commit 0392e6b2dc
3 changed files with 67 additions and 48 deletions

View file

@ -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);

View file

@ -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 {

View file

@ -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();
}
}
}
}