Home | History | Annotate | Download | only in providers
      1 /**
      2  * Copyright (c) 2012, Google Inc.
      3  *
      4  * Licensed under the Apache License, Version 2.0 (the "License");
      5  * you may not use this file except in compliance with the License.
      6  * You may obtain a copy of the License at
      7  *
      8  *     http://www.apache.org/licenses/LICENSE-2.0
      9  *
     10  * Unless required by applicable law or agreed to in writing, software
     11  * distributed under the License is distributed on an "AS IS" BASIS,
     12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
     13  * See the License for the specific language governing permissions and
     14  * limitations under the License.
     15  */
     16 
     17 package com.android.mail.providers;
     18 
     19 import android.os.Parcel;
     20 import android.os.Parcelable;
     21 
     22 import com.google.common.base.Objects;
     23 
     24 public class MessageInfo implements Parcelable {
     25     public static final String SENDER_LIST_TOKEN_ELIDED = " .. ";
     26 
     27     public boolean read;
     28     public boolean starred;
     29     public String sender;
     30     public String senderEmail;
     31     public int priority;
     32 
     33     public MessageInfo() {
     34     }
     35 
     36     public MessageInfo(boolean isRead, boolean isStarred, String senderString, int p,
     37             String email) {
     38         set(isRead, isStarred, senderString, p, email);
     39     }
     40 
     41     private MessageInfo(Parcel in) {
     42         read = (in.readInt() != 0);
     43         starred = (in.readInt() != 0);
     44         sender = in.readString();
     45         priority = in.readInt();
     46         senderEmail = in.readString();
     47     }
     48 
     49     @Override
     50     public int describeContents() {
     51         return 0;
     52     }
     53 
     54     @Override
     55     public void writeToParcel(Parcel dest, int flags) {
     56         dest.writeInt(read ? 1 : 0);
     57         dest.writeInt(starred ? 1 : 0);
     58         dest.writeString(sender);
     59         dest.writeInt(priority);
     60         dest.writeString(senderEmail);
     61     }
     62 
     63     public void set(boolean isRead, boolean isStarred, String senderString, int p, String email) {
     64         read = isRead;
     65         starred = isStarred;
     66         sender = senderString;
     67         priority = p;
     68         senderEmail = email;
     69     }
     70 
     71     public boolean markRead(boolean isRead) {
     72         if (read != isRead) {
     73             read = isRead;
     74             return true;
     75         }
     76         return false;
     77     }
     78 
     79     @Override
     80     public int hashCode() {
     81         return Objects.hashCode(read, starred, sender, senderEmail);
     82     }
     83 
     84     public static final Creator<MessageInfo> CREATOR = new Creator<MessageInfo>() {
     85 
     86         @Override
     87         public MessageInfo createFromParcel(Parcel source) {
     88             return new MessageInfo(source);
     89         }
     90 
     91         @Override
     92         public MessageInfo[] newArray(int size) {
     93             return new MessageInfo[size];
     94         }
     95 
     96     };
     97 
     98     @Override
     99     public String toString() {
    100         final StringBuilder builder = new StringBuilder();
    101         builder.append("[MessageInfo: read = ");
    102         builder.append(read);
    103         builder.append(", sender = ");
    104         builder.append(sender);
    105         builder.append(", senderEmail = ");
    106         builder.append(senderEmail);
    107         builder.append(", priority = ");
    108         builder.append(priority);
    109         builder.append("]");
    110         return builder.toString();
    111     }
    112 }
    113