Home | History | Annotate | Download | only in model
      1 /*
      2  * Copyright (C) 2015 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 
     17 package com.example.android.tvleanback.model;
     18 
     19 import android.os.Parcel;
     20 import android.os.Parcelable;
     21 import android.util.Log;
     22 
     23 import java.net.URI;
     24 import java.net.URISyntaxException;
     25 
     26 /*
     27  * Movie class represents video entity with title, description, image thumbs and video url.
     28  */
     29 public class Movie implements Parcelable {
     30     private static final String TAG = "Movie";
     31     static final long serialVersionUID = 727566175075960653L;
     32     private static int sCount = 0;
     33     private String mId;
     34     private String mTitle;
     35     private String mDescription;
     36     private String mBgImageUrl;
     37     private String mCardImageUrl;
     38     private String mVideoUrl;
     39     private String mStudio;
     40     private String mCategory;
     41 
     42     public Movie() {
     43 
     44     }
     45 
     46     public Movie(Parcel in){
     47         String[] data = new String[8];
     48 
     49         in.readStringArray(data);
     50         mId = data[0];
     51         mTitle = data[1];
     52         mDescription = data[2];
     53         mBgImageUrl = data[3];
     54         mCardImageUrl = data[4];
     55         mVideoUrl = data[5];
     56         mStudio = data[6];
     57         mCategory = data[7];
     58     }
     59 
     60     public static String getCount() {
     61         return Integer.toString(sCount);
     62     }
     63 
     64     public static void incrementCount() {
     65         sCount++;
     66     }
     67 
     68     public String getId() {
     69         return mId;
     70     }
     71 
     72     public void setId(String id) {
     73         mId = id;
     74     }
     75 
     76     public String getTitle() {
     77         return mTitle;
     78     }
     79 
     80     public void setTitle(String title) {
     81         mTitle = title;
     82     }
     83 
     84     public String getDescription() {
     85         return mDescription;
     86     }
     87 
     88     public void setDescription(String description) {
     89         mDescription = description;
     90     }
     91 
     92     public String getStudio() {
     93         return mStudio;
     94     }
     95 
     96     public void setStudio(String studio) {
     97         mStudio = studio;
     98     }
     99 
    100     public String getVideoUrl() {
    101         return mVideoUrl;
    102     }
    103 
    104     public void setVideoUrl(String videoUrl) {
    105         mVideoUrl = videoUrl;
    106     }
    107 
    108     public String getBackgroundImageUrl() {
    109         return mBgImageUrl;
    110     }
    111 
    112     public void setBackgroundImageUrl(String bgImageUrl) {
    113         mBgImageUrl = bgImageUrl;
    114     }
    115 
    116     public String getCardImageUrl() {
    117         return mCardImageUrl;
    118     }
    119 
    120     public void setCardImageUrl(String cardImageUrl) {
    121         mCardImageUrl = cardImageUrl;
    122     }
    123 
    124     public String getCategory() {
    125         return mCategory;
    126     }
    127 
    128     public void setCategory(String category) {
    129         mCategory = category;
    130     }
    131 
    132     public URI getBackgroundImageURI() {
    133         try {
    134             return new URI(getBackgroundImageUrl());
    135         } catch (URISyntaxException e) {
    136             return null;
    137         }
    138     }
    139 
    140     public int describeContents() {
    141         return 0;
    142     }
    143 
    144     @Override
    145     public void writeToParcel(Parcel dest, int flags) {
    146         dest.writeStringArray(new String[] {mId,
    147                 mTitle,
    148                 mDescription,
    149                 mBgImageUrl,
    150                 mCardImageUrl,
    151                 mVideoUrl,
    152                 mStudio,
    153                 mCategory});
    154     }
    155 
    156     @Override
    157     public String toString() {
    158         StringBuilder sb = new StringBuilder(200);
    159         sb.append("Movie{");
    160         sb.append("mId=" + mId);
    161         sb.append(", mTitle='" + mTitle + '\'');
    162         sb.append(", mVideoUrl='" + mVideoUrl + '\'');
    163         sb.append(", backgroundImageUrl='" + mBgImageUrl + '\'');
    164         sb.append(", backgroundImageURI='" + getBackgroundImageURI().toString() + '\'');
    165         sb.append(", mCardImageUrl='" + mCardImageUrl + '\'');
    166         sb.append('}');
    167         return sb.toString();
    168     }
    169 
    170     public static final Parcelable.Creator CREATOR = new Parcelable.Creator() {
    171         public Movie createFromParcel(Parcel in) {
    172             return new Movie(in);
    173         }
    174 
    175         public Movie[] newArray(int size) {
    176             return new Movie[size];
    177         }
    178     };
    179 }
    180