1 package com.android.tv.data.api;
2 
3 import android.content.Context;
4 import android.os.Parcel;
5 import android.os.Parcelable;
6 import android.support.annotation.Nullable;
7 import android.support.annotation.UiThread;
8 
9 import com.android.tv.util.images.ImageLoader;
10 
11 import java.io.Serializable;
12 import java.util.List;
13 
14 /** A convenience interface to create and insert program information entries into the database. */
15 public interface Program extends BaseProgram, Comparable<Program> {
16 
17     /** Returns {@code true} if the program is valid and {@code false} otherwise. */
isProgramValid(Program program)18     static boolean isProgramValid(Program program) {
19         return program != null && program.isValid();
20     }
21 
isDuplicate(Program p1, Program p2)22     static boolean isDuplicate(Program p1, Program p2) {
23         if (p1 == null || p2 == null) {
24             return false;
25         }
26         return p1.getChannelId() == p2.getChannelId()
27                 && p1.getStartTimeUtcMillis() == p2.getStartTimeUtcMillis()
28                 && p1.getEndTimeUtcMillis() == p2.getEndTimeUtcMillis();
29     }
30 
31     /** True if the start or end times overlap. */
isOverlapping(@ullable Program p1, @Nullable Program p2)32     static boolean isOverlapping(@Nullable Program p1, @Nullable Program p2) {
33         return p1 != null
34                 && p2 != null
35                 && p1.getStartTimeUtcMillis() < p2.getEndTimeUtcMillis()
36                 && p1.getEndTimeUtcMillis() > p2.getStartTimeUtcMillis();
37     }
38 
39     /** True if the channels IDs are the same. */
sameChannel(@ullable Program p1, @Nullable Program p2)40     static boolean sameChannel(@Nullable Program p1, @Nullable Program p2) {
41         return p1 != null && p2 != null && p1.getChannelId() == p2.getChannelId();
42     }
43 
44     /** Returns the package name of this program. */
getPackageName()45     String getPackageName();
46 
47     /** Returns the season title */
getSeasonTitle()48     String getSeasonTitle();
49 
50     /** Gets the localized duration of the program */
getDurationString(Context context)51     String getDurationString(Context context);
52 
getVideoWidth()53     int getVideoWidth();
54 
getVideoHeight()55     int getVideoHeight();
56 
57     /** Returns the list of Critic Scores for this program */
58     @Nullable
getCriticScores()59     List<CriticScore> getCriticScores();
60 
61     /** Returns {@code true} if the recording of this program is prohibited. */
isRecordingProhibited()62     boolean isRecordingProhibited();
63 
64     /** Returns array of canonical genres for this program. This is expected to be called rarely. */
65     @Nullable
getCanonicalGenres()66     String[] getCanonicalGenres();
67 
68     /** Returns if this program has the genre. */
hasGenre(int genreId)69     boolean hasGenre(int genreId);
70 
71     /** Prefetch the program poster art. */
prefetchPosterArt(Context context, int posterArtWidth, int posterArtHeight)72     void prefetchPosterArt(Context context, int posterArtWidth, int posterArtHeight);
73 
74     /**
75      * Loads the program poster art and returns it via {@code callback}.
76      *
77      * <p>Note that it may directly call {@code callback} if the program poster art already is
78      * loaded.
79      *
80      * @return {@code true} if the load is complete and the callback is executed.
81      */
82     @UiThread
loadPosterArt( Context context, int posterArtWidth, int posterArtHeight, ImageLoader.ImageLoaderCallback<?> callback)83     boolean loadPosterArt(
84             Context context,
85             int posterArtWidth,
86             int posterArtHeight,
87             ImageLoader.ImageLoaderCallback<?> callback);
88 
89     /** Returns a {@link Parcelable} representation of this instance. */
toParcelable()90     Parcelable toParcelable();
91 
92     /** Holds one type of critic score and its source. */
93     final class CriticScore implements Serializable, Parcelable {
94         /** The source of the rating. */
95         public final String source;
96         /** The score. */
97         public final String score;
98         /** The url of the logo image */
99         public final String logoUrl;
100 
101         public static final Creator<CriticScore> CREATOR =
102                 new Creator<CriticScore>() {
103                     @Override
104                     public CriticScore createFromParcel(Parcel in) {
105                         String source = in.readString();
106                         String score = in.readString();
107                         String logoUri = in.readString();
108                         return new CriticScore(source, score, logoUri);
109                     }
110 
111                     @Override
112                     public CriticScore[] newArray(int size) {
113                         return new CriticScore[size];
114                     }
115                 };
116 
117         /**
118          * Constructor for this class.
119          *
120          * @param source the source of the rating
121          * @param score the score
122          */
CriticScore(String source, String score, String logoUrl)123         public CriticScore(String source, String score, String logoUrl) {
124             this.source = source;
125             this.score = score;
126             this.logoUrl = logoUrl;
127         }
128 
129         @Override
describeContents()130         public int describeContents() {
131             return 0;
132         }
133 
134         @Override
writeToParcel(Parcel out, int i)135         public void writeToParcel(Parcel out, int i) {
136             out.writeString(source);
137             out.writeString(score);
138             out.writeString(logoUrl);
139         }
140     }
141 }
142