Home | History | Annotate | Download | only in ui
      1 /*
      2  * Copyright (C) 2008 Esmertec AG.
      3  * Copyright (C) 2008 The Android Open Source Project
      4  *
      5  * Licensed under the Apache License, Version 2.0 (the "License");
      6  * you may not use this file except in compliance with the License.
      7  * You may obtain a copy of the License at
      8  *
      9  *      http://www.apache.org/licenses/LICENSE-2.0
     10  *
     11  * Unless required by applicable law or agreed to in writing, software
     12  * distributed under the License is distributed on an "AS IS" BASIS,
     13  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
     14  * See the License for the specific language governing permissions and
     15  * limitations under the License.
     16  */
     17 
     18 package com.android.mms.ui;
     19 
     20 import android.content.Context;
     21 
     22 import com.android.mms.data.ContactList;
     23 import com.android.mms.data.Conversation;
     24 
     25 /**
     26  * A holder class for a conversation header.
     27  */
     28 public class ConversationListItemData {
     29     private Conversation mConversation;
     30     private long mThreadId;
     31     private String mSubject;
     32     private String mDate;
     33     private boolean mHasAttachment;
     34     private boolean mIsRead;
     35     private boolean mHasError;
     36     private boolean mHasDraft;
     37     private int mMessageCount;
     38 
     39     // The recipients in this conversation
     40     private ContactList mRecipients;
     41     private String mRecipientString;
     42 
     43     // the presence icon resource id displayed for the conversation thread.
     44     private int mPresenceResId;
     45 
     46     public ConversationListItemData(Context context, Conversation conv) {
     47         mConversation = conv;
     48         mThreadId = conv.getThreadId();
     49         mPresenceResId = 0;
     50         mSubject = conv.getSnippet();
     51         mDate = MessageUtils.formatTimeStampString(context, conv.getDate());
     52         mIsRead = !conv.hasUnreadMessages();
     53         mHasError = conv.hasError();
     54         mHasDraft = conv.hasDraft();
     55         mMessageCount = conv.getMessageCount();
     56         mHasAttachment = conv.hasAttachment();
     57         updateRecipients();
     58     }
     59 
     60     public void updateRecipients() {
     61         mRecipients = mConversation.getRecipients();
     62         mRecipientString = mRecipients.formatNames(", ");
     63     }
     64 
     65     /**
     66      * @return Returns the ID of the thread.
     67      */
     68     public long getThreadId() {
     69         return mThreadId;
     70     }
     71 
     72     /**
     73      * @return Returns the date.
     74      */
     75     public String getDate() {
     76         return mDate;
     77     }
     78 
     79     /**
     80      * @return Returns the from.  (formatted for display)
     81      */
     82     public String getFrom() {
     83         return mRecipientString;
     84     }
     85 
     86     public ContactList getContacts() {
     87         return mRecipients;
     88     }
     89 
     90     public int getPresenceResourceId() {
     91         return mPresenceResId;
     92     }
     93 
     94     /**
     95      * @return Returns the subject.
     96      */
     97     public String getSubject() {
     98         return mSubject;
     99     }
    100 
    101     /**
    102      * @return Returns the hasAttachment.
    103      */
    104     public boolean hasAttachment() {
    105         return mHasAttachment;
    106     }
    107 
    108     /**
    109      * @return Returns the isRead.
    110      */
    111     public boolean isRead() {
    112         return mIsRead;
    113     }
    114 
    115     /**
    116      * @return Whether the thread has a transmission error.
    117      */
    118     public boolean hasError() {
    119         return mHasError;
    120     }
    121 
    122     /**
    123      * @return Whether the thread has a draft.
    124      */
    125     public boolean hasDraft() {
    126         return mHasDraft;
    127     }
    128 
    129     /**
    130      * @return message count of the thread.
    131      */
    132     public int getMessageCount() {
    133         return mMessageCount;
    134     }
    135 
    136     /*
    137      * (non-Javadoc)
    138      * @see java.lang.Object#toString()
    139      */
    140     @Override
    141     public String toString() {
    142         return "[ConversationHeader from:" + getFrom() + " subject:" + getSubject()
    143         + "]";
    144     }
    145 }
    146