1/* 2 * Copyright (C) 2014 The Android Open Source Project 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except 5 * in compliance with the License. You may obtain a copy of the License at 6 * 7 * http://www.apache.org/licenses/LICENSE-2.0 8 * 9 * Unless required by applicable law or agreed to in writing, software distributed under the License 10 * is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express 11 * or implied. See the License for the specific language governing permissions and limitations under 12 * the License. 13 */ 14package com.example.android.leanback; 15 16import android.os.Parcel; 17import android.os.Parcelable; 18 19public class PhotoItem implements Parcelable { 20 private int mId; 21 private String mTitle; 22 private String mContent; 23 private int mImageResourceId; 24 25 public PhotoItem(String title, int imageResourceId) { 26 this(title, null, imageResourceId); 27 } 28 29 public PhotoItem(String title, int imageResourceId, int id) { 30 this(title, imageResourceId); 31 mId = id; 32 } 33 34 public PhotoItem(String title, String content, int imageResourceId) { 35 mTitle = title; 36 mContent = content; 37 mImageResourceId = imageResourceId; 38 // the id was set to -1 if user don't provide this parameter 39 mId = -1; 40 } 41 42 public PhotoItem(String title, String content, int imageResourceId, int id) { 43 this(title, content, imageResourceId); 44 mId = id; 45 } 46 47 public int getImageResourceId() { 48 return mImageResourceId; 49 } 50 51 public String getTitle() { 52 return mTitle; 53 } 54 55 public String getContent() { 56 return mContent; 57 } 58 59 @Override 60 public String toString() { 61 return mTitle; 62 } 63 64 @Override 65 public int describeContents() { 66 return 0; 67 } 68 69 @Override 70 public void writeToParcel(Parcel dest, int flags) { 71 dest.writeString(mTitle); 72 dest.writeInt(mImageResourceId); 73 } 74 75 public static final Parcelable.Creator<PhotoItem> CREATOR 76 = new Parcelable.Creator<PhotoItem>() { 77 @Override 78 public PhotoItem createFromParcel(Parcel in) { 79 return new PhotoItem(in); 80 } 81 82 @Override 83 public PhotoItem[] newArray(int size) { 84 return new PhotoItem[size]; 85 } 86 }; 87 88 public int getId() { 89 return this.mId; 90 } 91 92 private PhotoItem(Parcel in) { 93 mTitle = in.readString(); 94 mImageResourceId = in.readInt(); 95 } 96 97 @Override 98 public boolean equals(Object o) { 99 if (this == o) return true; 100 if (o == null || getClass() != o.getClass()) return false; 101 PhotoItem photoItem = (PhotoItem) o; 102 if (mId != photoItem.mId) return false; 103 if (mImageResourceId != photoItem.mImageResourceId) return false; 104 if (mTitle != null ? !mTitle.equals(photoItem.mTitle) : photoItem.mTitle != null) { 105 return false; 106 } 107 return mContent != null ? mContent.equals(photoItem.mContent) : photoItem.mContent == null; 108 } 109 110 @Override 111 public int hashCode() { 112 int result = mId; 113 result = 31 * result + (mTitle != null ? mTitle.hashCode() : 0); 114 result = 31 * result + (mContent != null ? mContent.hashCode() : 0); 115 result = 31 * result + mImageResourceId; 116 return result; 117 } 118}