1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
|
package de.thedevstack.conversationsplus.ui.dialogs;
import android.app.Activity;
import android.text.format.DateFormat;
import android.view.View;
import android.widget.TextView;
import java.util.Date;
import de.thedevstack.android.logcat.Logging;
import de.thedevstack.conversationsplus.ConversationsPlusColors;
import de.thedevstack.conversationsplus.entities.FileParams;
import de.thedevstack.conversationsplus.utils.ui.TextViewUtil;
import eu.siacs.conversations.R;
import eu.siacs.conversations.entities.Conversation;
import eu.siacs.conversations.entities.Message;
import eu.siacs.conversations.utils.UIHelper;
/**
* Fills the contents to the message details dialog.
* The view definition is done in R.layout.dialog_message_details.
*/
public class MessageDetailsDialog extends AbstractAlertDialog {
/**
* 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);
displayMessageSentTime(view, message);
displaySenderAndReceiver(view, message);
displayMessageTypeInfo(view, message);
displayMessageStatusInfo(view, message);
displayFileInfo(view, message);
this.setView(view);
}
/**
* 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) {
Logging.d("messagedetailsfile", "File is stored in path: " + message.getRelativeFilePath());
view.findViewById(R.id.dlgMsgDetFileTable).setVisibility(View.VISIBLE);
if (null != message.getFileParams()) {
FileParams params = message.getFileParams();
TextViewUtil.setText(view, R.id.dlgMsgDetFileSize, UIHelper.getHumanReadableDetailedFileSize(params.getSize()));
TextViewUtil.setText(view, R.id.dlgMsgDetFileMimeType, params.getMimeType());
TextViewUtil.setText(view, R.id.dlgMsgDetFileOriginalName, params.getOriginalFilename());
}
TextViewUtil.setText(view, R.id.dlgMsgDetFileHttpUploaded, message.isHttpUploaded() ? R.string.cplus_yes : R.string.cplus_no);
}
}
/**
* 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;
switch (message.getStatus()) {
case Message.STATUS_WAITING:
msgStatusResId = R.string.dlg_msg_details_msg_status_waiting;
break;
case Message.STATUS_UNSEND:
msgStatusResId = R.string.dlg_msg_details_msg_status_unsend;
break;
case Message.STATUS_OFFERED:
msgStatusResId = R.string.dlg_msg_details_msg_status_offered;
break;
case Message.STATUS_SEND_FAILED:
msgStatusResId = R.string.dlg_msg_details_msg_status_failed;
msgStatusTextView.setTextColor(ConversationsPlusColors.error());
break;
case Message.STATUS_RECEIVED:
msgStatusResId = R.string.dlg_msg_details_msg_status_received;
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;
}
msgStatusTextView.setText(msgStatusResId);
}
/**
* 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) {
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;
}
TextViewUtil.setText(view, R.id.dlgMsgDetMsgType, 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 = (null == message.getCounterpart() || message.getCounterpart().isBareJid()) ? "" : message.getCounterpart().getResourcepart();
Logging.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
TextViewUtil.setText(view, R.id.dlgMsgDetLblSender, R.string.dlg_msg_details_sender_nick);
TextViewUtil.setText(view, R.id.dlgMsgDetLblReceipient, 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) {
TextViewUtil.setText(view, R.id.dlgMsgDetTimeSent, DateFormat.format("dd.MM.yyyy kk:mm:ss", new Date(message.getTimeSent())));
}
}
|