summaryrefslogtreecommitdiffstats
path: root/src/com/android/mail/providers/MessageInfo.java
blob: a0ebc34f86d10f1c865649855a49c36515e2a636 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
/**
 * Copyright (c) 2012, Google Inc.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package com.android.mail.providers;

import android.os.Parcel;
import android.os.Parcelable;

import com.google.common.base.Objects;

public class MessageInfo implements Parcelable {
    public static final String SENDER_LIST_TOKEN_ELIDED = " .. ";

    public boolean loaded;
    public boolean read;
    public boolean starred;
    public String sender;
    public String senderEmail;
    public int priority;

    public MessageInfo() {
    }

    public MessageInfo(boolean isRead, boolean isStarred, String senderString, int p,
            String email, boolean loaded) {
        set(isRead, isStarred, senderString, p, email, loaded);
    }

    private MessageInfo(Parcel in) {
        read = (in.readInt() != 0);
        starred = (in.readInt() != 0);
        sender = in.readString();
        priority = in.readInt();
        senderEmail = in.readString();
        loaded = (in.readInt() != 0);
    }

    @Override
    public int describeContents() {
        return 0;
    }

    @Override
    public void writeToParcel(Parcel dest, int flags) {
        dest.writeInt(read ? 1 : 0);
        dest.writeInt(starred ? 1 : 0);
        dest.writeString(sender);
        dest.writeInt(priority);
        dest.writeString(senderEmail);
        dest.writeInt(loaded ? 1 : 0);
    }

    public void set(boolean isRead, boolean isStarred, String senderString, int p,
            String email, boolean isLoaded) {
        read = isRead;
        starred = isStarred;
        sender = senderString;
        priority = p;
        senderEmail = email;
        loaded = isLoaded;
    }

    public boolean markRead(boolean isRead) {
        if (read != isRead) {
            read = isRead;
            return true;
        }
        return false;
    }

    @Override
    public int hashCode() {
        return Objects.hashCode(loaded, read, starred, sender, senderEmail, priority);
    }

    public static final Creator<MessageInfo> CREATOR = new Creator<MessageInfo>() {

        @Override
        public MessageInfo createFromParcel(Parcel source) {
            return new MessageInfo(source);
        }

        @Override
        public MessageInfo[] newArray(int size) {
            return new MessageInfo[size];
        }

    };

    @Override
    public String toString() {
        final StringBuilder builder = new StringBuilder();
        builder.append("[MessageInfo: read = ");
        builder.append(read);
        builder.append(", sender = ");
        builder.append(sender);
        builder.append(", senderEmail = ");
        builder.append(senderEmail);
        builder.append(", priority = ");
        builder.append(priority);
        builder.append(", loaded = ");
        builder.append(loaded);
        builder.append("]");
        return builder.toString();
    }
}