aboutsummaryrefslogtreecommitdiffstats
path: root/src/main/java/de/thedevstack/conversationsplus/ui/adapter/MessageViewHolder.java
diff options
context:
space:
mode:
Diffstat (limited to 'src/main/java/de/thedevstack/conversationsplus/ui/adapter/MessageViewHolder.java')
-rw-r--r--src/main/java/de/thedevstack/conversationsplus/ui/adapter/MessageViewHolder.java97
1 files changed, 97 insertions, 0 deletions
diff --git a/src/main/java/de/thedevstack/conversationsplus/ui/adapter/MessageViewHolder.java b/src/main/java/de/thedevstack/conversationsplus/ui/adapter/MessageViewHolder.java
new file mode 100644
index 00000000..d66d4f01
--- /dev/null
+++ b/src/main/java/de/thedevstack/conversationsplus/ui/adapter/MessageViewHolder.java
@@ -0,0 +1,97 @@
+package de.thedevstack.conversationsplus.ui.adapter;
+
+import android.app.Activity;
+import android.view.View;
+import android.view.ViewGroup;
+import android.widget.Button;
+import android.widget.ImageView;
+import android.widget.LinearLayout;
+import android.widget.TextView;
+
+import de.thedevstack.conversationsplus.R;
+import de.thedevstack.conversationsplus.utils.ui.TextViewUtil;
+import de.thedevstack.conversationsplus.utils.ui.ViewUtil;
+
+/**
+ */
+class MessageViewHolder {
+
+ static final int SENT = 0;
+ static final int RECEIVED = 1;
+ static final int STATUS = 2;
+ static final int ME_COMMAND = 3;
+
+ View view;
+
+ LinearLayout message_box;
+ Button download_button;
+ ImageView image;
+ ImageView indicator;
+ ImageView indicatorReceived;
+ TextView time;
+ TextView messageBody;
+ ImageView contact_picture;
+ TextView status_message;
+ TextView encryption;
+ TextView remoteFileStatus;
+ boolean darkBackground;
+
+ MessageViewHolder(Activity activity, int type, ViewGroup parent) {
+ int viewResId = this.resolveViewId(type, parent);
+ this.view = activity.getLayoutInflater().inflate(viewResId, parent, false);
+ this.initializeViewElements(type);
+ }
+
+ private int resolveViewId(int type, ViewGroup parent) {
+ Integer viewResId = null;
+
+ switch (type) {
+ case SENT:
+ viewResId = R.layout.message_sent;
+ break;
+ case RECEIVED:
+ viewResId = R.layout.message_received;
+ break;
+ case STATUS:
+ viewResId = R.layout.message_status;
+ break;
+ case ME_COMMAND:
+ viewResId = R.layout.message_mecmd;
+ break;
+ }
+
+ return viewResId;
+ }
+
+ private void initializeViewElements(int type) {
+ if (SENT == type
+ || RECEIVED == type
+ || ME_COMMAND == type) {
+ this.message_box = ViewUtil.visible(view, R.id.message_box);
+ this.indicator = (ImageView) view.findViewById(R.id.security_indicator);
+ this.messageBody = (TextView) view.findViewById(R.id.message_body);
+ this.time = (TextView) view.findViewById(R.id.message_time);
+ this.indicatorReceived = (ImageView) view.findViewById(R.id.indicator_received);
+ }
+ if ((SENT == type
+ || RECEIVED == type)) {
+ this.download_button = (Button) view.findViewById(R.id.download_button);
+ this.image = (ImageView) view.findViewById(R.id.message_image);
+ }
+ if (ME_COMMAND == type
+ || (RECEIVED == type)) { // && message.getConversation().getMode() == Conversation.MODE_MULTI --> only muc received msgs
+ this.contact_picture = ViewUtil.visible(view, R.id.message_photo);
+ }
+ if (RECEIVED == type) {
+ this.encryption = (TextView) view.findViewById(R.id.message_encryption);
+ }
+ if (STATUS == type) {
+ this.contact_picture = ViewUtil.visible(view, R.id.message_photo);
+ this.status_message = TextViewUtil.visible(view, R.id.status_message);
+ }
+ if (SENT == type) { // This field is only useful for sent messages -> because of deletion of own files -> maybe a use case for recvd possible
+ this.remoteFileStatus = TextViewUtil.gone(view, R.id.remote_file_status);
+ }
+ view.setTag(this);
+ }
+}