aboutsummaryrefslogtreecommitdiffstats
path: root/src/eu/siacs/conversations/ui
diff options
context:
space:
mode:
authoriNPUTmice <daniel@gultsch.de>2014-08-10 15:27:44 +0200
committeriNPUTmice <daniel@gultsch.de>2014-08-10 15:27:44 +0200
commitb35aa3ed0720f195ec341a1188591052909bdf18 (patch)
treea15759ef8c4006c30bcae497baa7841ee792dd3f /src/eu/siacs/conversations/ui
parent6de53791b5db4513f662dabbdfe83db29eb4d666 (diff)
added limited private muc chat feature (messages are now properly marked) - long press on user icon will sent private messages. fixed #259
Diffstat (limited to 'src/eu/siacs/conversations/ui')
-rw-r--r--src/eu/siacs/conversations/ui/ConversationFragment.java44
-rw-r--r--src/eu/siacs/conversations/ui/adapter/MessageAdapter.java55
2 files changed, 92 insertions, 7 deletions
diff --git a/src/eu/siacs/conversations/ui/ConversationFragment.java b/src/eu/siacs/conversations/ui/ConversationFragment.java
index e0733291..fced1e38 100644
--- a/src/eu/siacs/conversations/ui/ConversationFragment.java
+++ b/src/eu/siacs/conversations/ui/ConversationFragment.java
@@ -17,6 +17,7 @@ import eu.siacs.conversations.ui.EditMessage.OnEnterPressed;
import eu.siacs.conversations.ui.XmppActivity.OnPresenceSelected;
import eu.siacs.conversations.ui.adapter.MessageAdapter;
import eu.siacs.conversations.ui.adapter.MessageAdapter.OnContactPictureClicked;
+import eu.siacs.conversations.ui.adapter.MessageAdapter.OnContactPictureLongClicked;
import eu.siacs.conversations.utils.UIHelper;
import android.app.AlertDialog;
import android.app.Fragment;
@@ -160,10 +161,22 @@ public class ConversationFragment extends Fragment {
private void sendMessage() {
- if (mEditMessage.getText().length() < 1)
+ if (mEditMessage.getText().length() < 1) {
+ if (this.conversation.getMode() == Conversation.MODE_MULTI) {
+ conversation.setNextPresence(null);
+ updateChatMsgHint();
+ }
return;
+ }
Message message = new Message(conversation, mEditMessage.getText()
.toString(), conversation.getNextEncryption());
+ if (conversation.getMode() == Conversation.MODE_MULTI) {
+ if (conversation.getNextPresence() != null) {
+ message.setPresence(conversation.getNextPresence());
+ message.setType(Message.TYPE_PRIVATE);
+ conversation.setNextPresence(null);
+ }
+ }
if (conversation.getNextEncryption() == Message.ENCRYPTION_OTR) {
sendOtrMessage(message);
} else if (conversation.getNextEncryption() == Message.ENCRYPTION_PGP) {
@@ -230,7 +243,24 @@ public class ConversationFragment extends Fragment {
@Override
public void onContactPictureClicked(Message message) {
if (message.getConversation().getMode() == Conversation.MODE_MULTI) {
- highlightInConference(message.getCounterpart());
+ if (message.getPresence() != null) {
+ highlightInConference(message.getPresence());
+ } else {
+ highlightInConference(message.getCounterpart());
+ }
+ }
+ }
+ });
+ messageListAdapter.setOnContactPictureLongClicked(new OnContactPictureLongClicked() {
+
+ @Override
+ public void onContactPictureLongClicked(Message message) {
+ if (message.getConversation().getMode() == Conversation.MODE_MULTI) {
+ if (message.getPresence() != null) {
+ privateMessageWith(message.getPresence());
+ } else {
+ privateMessageWith(message.getCounterpart());
+ }
}
}
});
@@ -238,6 +268,12 @@ public class ConversationFragment extends Fragment {
return view;
}
+
+ protected void privateMessageWith(String counterpart) {
+ this.mEditMessage.setHint(getString(R.string.send_private_message_to,counterpart));
+ this.mEditMessage.setText("");
+ this.conversation.setNextPresence(counterpart);
+ }
protected void highlightInConference(String nick) {
String oldString = mEditMessage.getText().toString().trim();
@@ -303,6 +339,9 @@ public class ConversationFragment extends Fragment {
activity.invalidateOptionsMenu();
}
}
+ if (this.conversation.getMode() == Conversation.MODE_MULTI) {
+ conversation.setNextPresence(null);
+ }
}
private void decryptMessage(Message message) {
@@ -406,6 +445,7 @@ public class ConversationFragment extends Fragment {
messagesView.setSelection(size - 1);
}
mEditMessage.setText("");
+ updateChatMsgHint();
}
protected void updateStatusMessages() {
diff --git a/src/eu/siacs/conversations/ui/adapter/MessageAdapter.java b/src/eu/siacs/conversations/ui/adapter/MessageAdapter.java
index a84fc01c..ca475cc9 100644
--- a/src/eu/siacs/conversations/ui/adapter/MessageAdapter.java
+++ b/src/eu/siacs/conversations/ui/adapter/MessageAdapter.java
@@ -14,6 +14,7 @@ import android.content.Context;
import android.content.Intent;
import android.graphics.Bitmap;
import android.graphics.Typeface;
+import android.text.Html;
import android.util.DisplayMetrics;
import android.view.View;
import android.view.ViewGroup;
@@ -40,6 +41,7 @@ public class MessageAdapter extends ArrayAdapter<Message> {
private DisplayMetrics metrics;
private OnContactPictureClicked mOnContactPictureClickedListener;
+ private OnContactPictureLongClicked mOnContactPictureLongClickedListener;
public MessageAdapter(ConversationActivity activity, List<Message> messages) {
super(activity, 0, messages);
@@ -61,6 +63,10 @@ public class MessageAdapter extends ArrayAdapter<Message> {
public void setOnContactPictureClicked(OnContactPictureClicked listener) {
this.mOnContactPictureClickedListener = listener;
}
+
+ public void setOnContactPictureLongClicked(OnContactPictureLongClicked listener) {
+ this.mOnContactPictureLongClickedListener = listener;
+ }
@Override
public int getViewTypeCount() {
@@ -120,7 +126,11 @@ public class MessageAdapter extends ArrayAdapter<Message> {
if (contact != null) {
info = contact.getDisplayName();
} else {
- info = message.getCounterpart();
+ if (message.getPresence() != null) {
+ info = message.getPresence();
+ } else {
+ info = message.getCounterpart();
+ }
}
}
break;
@@ -190,14 +200,33 @@ public class MessageAdapter extends ArrayAdapter<Message> {
viewHolder.messageBody.setTextIsSelectable(false);
}
- private void displayTextMessage(ViewHolder viewHolder, String text) {
+ private void displayTextMessage(ViewHolder viewHolder, Message message) {
if (viewHolder.download_button != null) {
viewHolder.download_button.setVisibility(View.GONE);
}
viewHolder.image.setVisibility(View.GONE);
viewHolder.messageBody.setVisibility(View.VISIBLE);
- if (text != null) {
- viewHolder.messageBody.setText(text.trim());
+ if (message.getBody() != null) {
+ if (message.getType() != Message.TYPE_PRIVATE) {
+ viewHolder.messageBody.setText(message.getBody().trim());
+ } else {
+ StringBuilder builder = new StringBuilder();
+ builder.append(message.getBody().trim());
+ builder.append("&nbsp;<b><i>(");
+ if (message.getStatus() <= Message.STATUS_RECIEVED) {
+ builder.append(activity.getString(R.string.private_message));
+ } else {
+ String to;
+ if (message.getPresence() != null) {
+ to = message.getPresence();
+ } else {
+ to = message.getCounterpart();
+ }
+ builder.append(activity.getString(R.string.private_message_to, to));
+ }
+ builder.append(")</i></b>");
+ viewHolder.messageBody.setText(Html.fromHtml(builder.toString()));
+ }
} else {
viewHolder.messageBody.setText("");
}
@@ -376,6 +405,18 @@ public class MessageAdapter extends ArrayAdapter<Message> {
}
});
+ viewHolder.contact_picture.setOnLongClickListener(new OnLongClickListener() {
+
+ @Override
+ public boolean onLongClick(View v) {
+ if (MessageAdapter.this.mOnContactPictureLongClickedListener != null) {
+ MessageAdapter.this.mOnContactPictureLongClickedListener.onContactPictureLongClicked(item);
+ return true;
+ } else {
+ return false;
+ }
+ }
+ });
}
}
@@ -426,7 +467,7 @@ public class MessageAdapter extends ArrayAdapter<Message> {
} else if (item.getEncryption() == Message.ENCRYPTION_DECRYPTION_FAILED) {
displayDecryptionFailed(viewHolder);
} else {
- displayTextMessage(viewHolder, item.getBody());
+ displayTextMessage(viewHolder, item);
}
}
@@ -474,4 +515,8 @@ public class MessageAdapter extends ArrayAdapter<Message> {
public interface OnContactPictureClicked {
public void onContactPictureClicked(Message message);
}
+
+ public interface OnContactPictureLongClicked {
+ public void onContactPictureLongClicked(Message message);
+ }
}