Folder.java revision ff7d02ac1660d0f4bca9fce1f2033a6ea19c94c2
1/******************************************************************************* 2 * Copyright (C) 2012 Google Inc. 3 * Licensed to 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 18package com.android.mail.providers; 19 20import android.database.Cursor; 21import android.os.Parcel; 22import android.os.Parcelable; 23import com.android.mail.utils.LogUtils; 24 25/** 26 * A folder is a collection of conversations, and perhaps other folders. 27 */ 28public class Folder implements Parcelable { 29 // Try to match the order of members with the order of constants in UIProvider. 30 31 /** 32 * The content provider URI that returns this folder for this account. 33 */ 34 public String uri; 35 36 /** 37 * The human visible name for this folder. 38 */ 39 public String name; 40 41 /** 42 * The possible capabilities that this folder supports. 43 */ 44 public int capabilities; 45 46 /** 47 * Whether or not this folder has children folders. 48 */ 49 public boolean hasChildren; 50 51 /** 52 * How often this folder should be synchronized with the server. 53 */ 54 public int syncFrequency; 55 56 /** 57 * How large the synchronization window is: how many days worth of data is retained on the 58 * device. 59 */ 60 public int syncWindow; 61 62 /** 63 * The content provider URI to return the list of conversations in this 64 * folder. 65 */ 66 public String conversationListUri; 67 68 /** 69 * The content provider URI to return the list of child folders of this folder. 70 */ 71 public String childFoldersListUri; 72 73 /** 74 * The number of messages that are unread in this folder. 75 */ 76 public int unreadCount; 77 78 /** 79 * The total number of messages in this folder. 80 */ 81 public int totalCount; 82 83 /** 84 * Used only for debugging. 85 */ 86 private static final String LOG_TAG = new LogUtils().getLogTag(); 87 88 public Folder(Parcel in) { 89 uri = in.readString(); 90 name = in.readString(); 91 capabilities = in.readInt(); 92 // 1 for true, 0 for false. 93 hasChildren = in.readInt() == 1; 94 syncFrequency = in.readInt(); 95 syncWindow = in.readInt(); 96 conversationListUri = in.readString(); 97 childFoldersListUri = in.readString(); 98 unreadCount = in.readInt(); 99 totalCount = in.readInt(); 100 } 101 102 public Folder(Cursor cursor) { 103 uri = cursor.getString(UIProvider.FOLDER_URI_COLUMN); 104 name = cursor.getString(UIProvider.FOLDER_NAME_COLUMN); 105 capabilities = cursor.getInt(UIProvider.FOLDER_CAPABILITIES_COLUMN); 106 // 1 for true, 0 for false. 107 hasChildren = cursor.getInt(UIProvider.FOLDER_HAS_CHILDREN_COLUMN) == 1; 108 syncFrequency = cursor.getInt(UIProvider.FOLDER_SYNC_FREQUENCY_COLUMN); 109 syncWindow = cursor.getInt(UIProvider.FOLDER_SYNC_WINDOW_COLUMN); 110 conversationListUri = cursor.getString(UIProvider.FOLDER_CONVERSATION_LIST_URI_COLUMN); 111 childFoldersListUri = cursor.getString(UIProvider.FOLDER_CHILD_FOLDERS_LIST_COLUMN); 112 unreadCount = cursor.getInt(UIProvider.FOLDER_UNREAD_COUNT_COLUMN); 113 totalCount = cursor.getInt(UIProvider.FOLDER_TOTAL_COUNT_COLUMN); 114 } 115 116 @Override 117 public void writeToParcel(Parcel dest, int flags) { 118 dest.writeString(uri); 119 dest.writeString(name); 120 dest.writeInt(capabilities); 121 // 1 for true, 0 for false. 122 dest.writeInt(hasChildren ? 1 : 0); 123 dest.writeInt(syncFrequency); 124 dest.writeInt(syncWindow); 125 dest.writeString(conversationListUri); 126 dest.writeString(childFoldersListUri); 127 dest.writeInt(unreadCount); 128 dest.writeInt(totalCount); 129 } 130 131 @SuppressWarnings("hiding") 132 public static final Creator<Folder> CREATOR = new Creator<Folder>() { 133 @Override 134 public Folder createFromParcel(Parcel source) { 135 return new Folder(source); 136 } 137 138 @Override 139 public Folder[] newArray(int size) { 140 return new Folder[size]; 141 } 142 }; 143 144 @Override 145 public int describeContents() { 146 // Return a sort of version number for this parcelable folder. Starting with zero. 147 return 0; 148 } 149} 150