Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public class Notebook implements Parcelable{
- // Constants
- private final String TAG = "Notebook";
- // Data
- private long mLocalId;
- private long mRemoteId;
- private long mUserId;
- private ArrayList<Note> mItems;
- private long mCreateDate;
- private String mTitle;
- public Notebook() {
- mLocalId = -1;
- mRemoteId = -1;
- mUserId = -1;
- mItems = new ArrayList<Note>();
- mCreateDate = AppUtils.now();
- mTitle = "Default notebook";
- }
- public static final Parcelable.Creator CREATOR = new Parcelable.Creator() {
- public Notebook createFromParcel(Parcel in) {
- return new Notebook(in);
- }
- public Notebook[] newArray(int size) {
- return new Notebook[size];
- }
- };
- public long getLocalId(){
- return mLocalId;
- }
- public Notebook setLocalId(long pLocalId){
- mLocalId = pLocalId;
- return this;
- }
- public long getRemoteId(){
- return mRemoteId;
- }
- public Notebook setRemoteId(long pRemoteId){
- mRemoteId = pRemoteId;
- return this;
- }
- public long getUserId(){
- return mUserId;
- }
- public Notebook setUserId(long pUserId){
- mUserId = pUserId;
- return this;
- }
- public long getCreateDate(){
- return mCreateDate;
- }
- public Notebook setCreateDate(long pCreateDate){
- mCreateDate = pCreateDate;
- return this;
- }
- public Notebook addItem(Note pItem){
- mItems.add(pItem);
- return this;
- }
- public Note removeItemAt(int position){
- try{
- return mItems.remove(position);
- }catch (IndexOutOfBoundsException e) {
- e.printStackTrace();
- return null;
- }
- }
- public Note getItem(int position){
- try{
- return mItems.get(position);
- }catch (IndexOutOfBoundsException e) {
- e.printStackTrace();
- return null;
- }
- }
- public int getItemsCount(){
- return mItems.size();
- }
- public String getTitle(){
- return mTitle;
- }
- public Notebook setTitle(String pTitle){
- mTitle = pTitle;
- return this;
- }
- @Override
- public String toString() {
- return Convertor.toString(this) + " total notes: " + getItemsCount();
- }
- public Notebook setItems(ArrayList<Note> pNotes) {
- mItems = pNotes;
- return this;
- }
- @Override
- public int describeContents() {
- return hashCode();
- }
- @Override
- public void writeToParcel(Parcel dest, int flags) {
- Console.debug(TAG, "writing parcel... " + flags, Console.Liviu);
- dest.writeLong(mLocalId);
- dest.writeLong(mRemoteId);
- dest.writeLong(mUserId);
- dest.writeLong(mCreateDate);
- dest.writeString(mTitle);
- }
- public Notebook(Parcel source){
- /*
- * Reconstruct from the Parcel
- */
- Console.debug(TAG, "ParcelData(Parcel source): time to put back parcel data", Console.Liviu);
- mLocalId = source.readLong();
- mRemoteId = source.readLong();
- mUserId = source.readLong();
- mCreateDate = source.readLong();
- mTitle = source.readString();
- mItems = new ArrayList<Note>();
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment