1/*
2 * Copyright (C) 2014 The Android Open Source Project
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
17package com.android.mail.providers;
18
19import android.os.Parcel;
20import android.os.Parcelable;
21
22import com.google.common.base.Objects;
23
24public class ParticipantInfo implements Parcelable {
25
26    /** the pretty name of the participant if one exists */
27    public String name;
28
29    /** the email address of the participant if one exists */
30    public String email;
31
32    /** priority of the participant */
33    public int priority;
34
35    /** {@code true} if the participant has read the entire conversation; {@code false} otherwise */
36    public boolean readConversation;
37
38    public ParticipantInfo(String name, String email, int priority, boolean readConversation) {
39        this.name = name;
40        this.email = email;
41        this.priority = priority;
42        this.readConversation = readConversation;
43    }
44
45    public boolean markRead(boolean isRead) {
46        if (readConversation != isRead) {
47            readConversation = isRead;
48            return true;
49        }
50        return false;
51    }
52
53    @Override
54    public int hashCode() {
55        return Objects.hashCode(name, email, priority, readConversation);
56    }
57
58    public static final Creator<ParticipantInfo> CREATOR = new Creator<ParticipantInfo>() {
59        @Override
60        public ParticipantInfo createFromParcel(Parcel parcel) {
61            return new ParticipantInfo(parcel);
62        }
63
64        @Override
65        public ParticipantInfo[] newArray(int size) {
66            return new ParticipantInfo[size];
67        }
68    };
69
70    public ParticipantInfo(Parcel in) {
71        name = in.readString();
72        email = in.readString();
73        priority = in.readInt();
74        readConversation = in.readInt() != 0;
75    }
76
77    @Override
78    public int describeContents() {
79        return 0;
80    }
81
82    @Override
83    public void writeToParcel(Parcel out, int flags) {
84        out.writeString(name);
85        out.writeString(email);
86        out.writeInt(priority);
87        out.writeInt(readConversation ? 1 : 0);
88    }
89
90    @Override
91    public String toString() {
92        return "[ParticipantInfo: readConversation = " + readConversation +
93                ", name = " + name +
94                ", email = " + email +
95                ", priority = " + priority +
96                "]";
97    }
98}