Conversation.java revision 732600e38891db139bae02dc91dd0c5b0987e8e9
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 17package com.android.mail.providers; 18 19import android.database.Cursor; 20import android.net.Uri; 21import android.os.Parcel; 22import android.os.Parcelable; 23 24public class Conversation implements Parcelable { 25 26 public long id; 27 public String subject; 28 public long dateMs; 29 public String snippet; 30 public boolean hasAttachments; 31 public Uri messageListUri; 32 33 @Override 34 public int describeContents() { 35 return 0; 36 } 37 38 @Override 39 public void writeToParcel(Parcel dest, int flags) { 40 dest.writeLong(id); 41 dest.writeString(subject); 42 dest.writeLong(dateMs); 43 dest.writeString(snippet); 44 dest.writeByte(hasAttachments ? (byte) 1 : 0); 45 dest.writeParcelable(messageListUri, flags); 46 } 47 48 private Conversation(Parcel in) { 49 id = in.readLong(); 50 subject = in.readString(); 51 dateMs = in.readLong(); 52 snippet = in.readString(); 53 hasAttachments = (in.readByte() != 0); 54 messageListUri = in.readParcelable(null); 55 } 56 57 @Override 58 public String toString() { 59 return "[conversation id=" + id + "]"; 60 } 61 62 public static final Creator<Conversation> CREATOR = new Creator<Conversation>() { 63 64 @Override 65 public Conversation createFromParcel(Parcel source) { 66 return new Conversation(source); 67 } 68 69 @Override 70 public Conversation[] newArray(int size) { 71 return new Conversation[size]; 72 } 73 74 }; 75 76 public static Conversation from(Cursor cursor) { 77 return new Conversation(cursor); 78 } 79 80 private Conversation(Cursor cursor) { 81 if (cursor != null) { 82 id = cursor.getLong(UIProvider.CONVERSATION_ID_COLUMN); 83 dateMs = cursor.getLong(UIProvider.CONVERSATION_DATE_RECEIVED_MS_COLUMN); 84 subject = cursor.getString(UIProvider.CONVERSATION_SUBJECT_COLUMN); 85 snippet = cursor.getString(UIProvider.CONVERSATION_SNIPPET_COLUMN); 86 hasAttachments = cursor 87 .getInt(UIProvider.CONVERSATION_HAS_ATTACHMENTS_COLUMN) == 1 ? true : false; 88 messageListUri = Uri.parse(cursor 89 .getString(UIProvider.CONVERSATION_MESSAGE_LIST_URI_COLUMN)); 90 } 91 } 92 93} 94