aboutsummaryrefslogtreecommitdiffstats
path: root/src/main/java/de/thedevstack
diff options
context:
space:
mode:
Diffstat (limited to 'src/main/java/de/thedevstack')
-rw-r--r--src/main/java/de/thedevstack/conversationsplus/ui/dialogs/MessageDetailsDialog.java160
1 files changed, 142 insertions, 18 deletions
diff --git a/src/main/java/de/thedevstack/conversationsplus/ui/dialogs/MessageDetailsDialog.java b/src/main/java/de/thedevstack/conversationsplus/ui/dialogs/MessageDetailsDialog.java
index 05830c75..25d522f0 100644
--- a/src/main/java/de/thedevstack/conversationsplus/ui/dialogs/MessageDetailsDialog.java
+++ b/src/main/java/de/thedevstack/conversationsplus/ui/dialogs/MessageDetailsDialog.java
@@ -1,45 +1,56 @@
package de.thedevstack.conversationsplus.ui.dialogs;
import android.app.Activity;
-import android.app.AlertDialog;
import android.text.format.DateFormat;
+import android.util.Log;
import android.view.View;
import android.widget.TextView;
import java.util.Date;
import de.thedevstack.conversationsplus.R;
+import de.thedevstack.conversationsplus.entities.Conversation;
import de.thedevstack.conversationsplus.entities.Message;
import de.thedevstack.conversationsplus.utils.UIHelper;
/**
- * Created by tzur on 29.09.2015.
+ * Fills the contents to the message details dialog.
+ * The view definition is done in R.layout.dialog_message_details.
*/
public class MessageDetailsDialog extends AbstractAlertDialog {
- private AlertDialog.Builder builder;
+ /**
+ * Initializes the Message Details Dialog.
+ * @param context the context of this alert dialog (the parent activity).
+ * @param message the message to be displayed
+ */
public MessageDetailsDialog(Activity context, Message message) {
super(context, R.string.dlg_msg_details_title);
this.createView(context, message);
}
+ /**
+ * Creates the view for the message details alert dialog.
+ * @param context the context of this alert dialog (the parent activity).
+ * @param message the message to be displayed
+ */
protected void createView(Activity context, Message message) {
int viewId = R.layout.dialog_message_details;
View view = context.getLayoutInflater().inflate(viewId, null);
- TextView timeSent = (TextView) view.findViewById(R.id.dlgMsgDetTimeSent);
- timeSent.setText(DateFormat.format("dd.MM.yyyy kk:mm:ss", new Date(message.getMergedTimeSent())));
- TextView sender = (TextView) view.findViewById(R.id.dlgMsgDetSender);
- TextView receipient = (TextView) view.findViewById(R.id.dlgMsgDetReceipient);
- String me = message.getConversation().getAccount().getJid().getResourcepart();
- String other = message.getCounterpart().getResourcepart();
- if (Message.STATUS_RECEIVED == message.getStatus()) {
- sender.setText(other);
- receipient.setText(me);
- } else {
- sender.setText(me);
- receipient.setText(other);
- }
+ displayMessageSentTime(view, message);
+ displaySenderAndReceiver(view, message);
+ displayMessageTypeInfo(view, message);
+ displayMessageStatusInfo(view, message);
+ displayFileInfo(view, message);
+ }
+
+ /**
+ * Publishes file information, if message contains an image to view.
+ * @param view the dialog view
+ * @param message the message to display in dialog
+ */
+ protected void displayFileInfo(View view, Message message) {
if (message.getType() == Message.TYPE_IMAGE || message.getType() == Message.TYPE_FILE || message.getTransferable() != null) {
view.findViewById(R.id.dlgMsgDetFileTable).setVisibility(View.VISIBLE);
if (null != message.getFileParams()) {
@@ -53,7 +64,120 @@ public class MessageDetailsDialog extends AbstractAlertDialog {
this.setView(view);
}
- public void show() {
- this.builder.show();
+ /**
+ * Displays message status info to view.
+ * @param view the dialog view
+ * @param message the message to display in dialog
+ */
+ protected void displayMessageStatusInfo(View view, Message message) {
+ TextView msgStatusTextView = (TextView) view.findViewById(R.id.dlgMsgDetMsgStatus);
+ int msgStatusResId;
+ int msgStatusColorResId;
+ switch (message.getStatus()) {
+ case Message.STATUS_WAITING:
+ msgStatusResId = R.string.dlg_msg_details_msg_status_waiting;
+ msgStatusColorResId = R.color.black87;
+ break;
+ case Message.STATUS_UNSEND:
+ msgStatusResId = R.string.dlg_msg_details_msg_status_unsend;
+ msgStatusColorResId = R.color.black87;
+ break;
+ case Message.STATUS_OFFERED:
+ msgStatusResId = R.string.dlg_msg_details_msg_status_offered;
+ msgStatusColorResId = R.color.black87;
+ break;
+ case Message.STATUS_SEND_FAILED:
+ msgStatusResId = R.string.dlg_msg_details_msg_status_failed;
+ msgStatusColorResId = R.color.red500;
+ break;
+ case Message.STATUS_RECEIVED:
+ msgStatusResId = R.string.dlg_msg_details_msg_status_received;
+ msgStatusColorResId = R.color.black87;
+ break;
+ case Message.STATUS_SEND:
+ case Message.STATUS_SEND_DISPLAYED:
+ case Message.STATUS_SEND_RECEIVED:
+ default:
+ msgStatusResId = R.string.dlg_msg_details_msg_status_sent;
+ msgStatusColorResId = R.color.black87;
+ }
+ msgStatusTextView.setText(msgStatusResId);
+ msgStatusTextView.setTextColor(getContext().getResources().getColor(msgStatusColorResId));
+ }
+
+ /**
+ * Publishes message type information to view.
+ * @param view the dialog view
+ * @param message the message to display in dialog
+ */
+ protected void displayMessageTypeInfo(View view, Message message) {
+ TextView msgTypeTextView = (TextView) view.findViewById(R.id.dlgMsgDetMsgType);
+ int msgTypeResId;
+ switch (message.getType()) {
+ case Message.TYPE_PRIVATE:
+ msgTypeResId = R.string.dlg_msg_details_msg_type_private;
+ break;
+ case Message.TYPE_FILE:
+ msgTypeResId = R.string.dlg_msg_details_msg_type_file;
+ break;
+ case Message.TYPE_IMAGE:
+ msgTypeResId = R.string.dlg_msg_details_msg_type_image;
+ break;
+ case Message.TYPE_STATUS:
+ msgTypeResId = R.string.dlg_msg_details_msg_type_status;
+ break;
+ case Message.TYPE_TEXT:
+ default:
+ msgTypeResId = R.string.dlg_msg_details_msg_type_text;
+ }
+ msgTypeTextView.setText(msgTypeResId);
+ }
+
+ /**
+ * Publishes information about sending and receiving parties to view.
+ * @param view the dialog view
+ * @param message the message to display in dialog
+ */
+ protected void displaySenderAndReceiver(View view, Message message) {
+ Conversation conversation = message.getConversation();
+ // Get own resource name -> What about msg written on other client?
+ String me = conversation.getAccount().getJid().getResourcepart();
+ // Get resource name of chat partner, if available
+ String other = (message.getCounterpart().isBareJid()) ? "" : message.getCounterpart().getResourcepart();
+ Log.d("MesageDialog", "Me: " + me + ", other: " + other);
+ TextView sender = (TextView) view.findViewById(R.id.dlgMsgDetSender);
+ TextView receipient = (TextView) view.findViewById(R.id.dlgMsgDetReceipient);
+
+ if (conversation.getMode() == Conversation.MODE_MULTI) {
+ // Change label of sending and receiving party to MUC terminology
+ TextView senderLabel = (TextView) view.findViewById(R.id.dlgMsgDetLblSender);
+ senderLabel.setText(R.string.dlg_msg_details_sender_nick);
+ TextView receipientLabel = (TextView) view.findViewById(R.id.dlgMsgDetLblReceipient);
+ receipientLabel.setText(R.string.dlg_msg_details_receipient_nick);
+
+ // Get own nick for MUC
+ me = conversation.getMucOptions().getActualNick();
+ }
+ if (Message.STATUS_RECEIVED == message.getStatus()) {
+ // Sender was chat partner, if the status is for my account received
+ sender.setText(other);
+ // Set receipient to myself in case of normal chat or private message in MUC
+ if (conversation.getMode() == Conversation.MODE_SINGLE || Message.TYPE_PRIVATE == message.getType()) {
+ receipient.setText(me);
+ }
+ } else {
+ sender.setText(me);
+ receipient.setText(other);
+ }
+ }
+
+ /**
+ * Publishes information about message sent time to view.
+ * @param view the dialog view
+ * @param message the message to display in dialog
+ */
+ protected void displayMessageSentTime(View view, Message message) {
+ TextView timeSent = (TextView) view.findViewById(R.id.dlgMsgDetTimeSent);
+ timeSent.setText(DateFormat.format("dd.MM.yyyy kk:mm:ss", new Date(message.getMergedTimeSent())));
}
}