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.R; import de.thedevstack.conversationsplus.entities.Conversation; import de.thedevstack.conversationsplus.entities.FileParams; import de.thedevstack.conversationsplus.entities.Message; import de.thedevstack.conversationsplus.utils.UIHelper; import de.thedevstack.conversationsplus.utils.ui.TextViewUtil; /** * 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.isHttpUploaded() || 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()))); } }