package de.thedevstack.conversationsplus.ui.dialogs; import android.app.Activity; 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; /** * 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); } /** * 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()) { Message.FileParams params = message.getFileParams(); TextView tvFilesize = (TextView) view.findViewById(R.id.dlgMsgDetFileSize); tvFilesize.setText(UIHelper.getHumanReadableFileSize(params.size)); } TextView mimetype = (TextView) view.findViewById(R.id.dlgMsgDetFileMimeType); mimetype.setText(message.getMimeType()); } this.setView(view); } /** * 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()))); } }