• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 package com.android.tv.data.api;
2 
3 import android.content.Context;
4 import android.media.tv.TvContentRating;
5 import android.support.annotation.Nullable;
6 import com.google.common.collect.ImmutableList;
7 import java.util.Comparator;
8 import java.util.Objects;
9 
10 /**
11  * Base class for {@link com.android.tv.data.Program} and {@link
12  * com.android.tv.dvr.data.RecordedProgram}.
13  */
14 public interface BaseProgram {
15 
16     /**
17      * Comparator used to compare {@link BaseProgram} according to its season and episodes number.
18      * If a program's season or episode number is null, it will be consider "smaller" than programs
19      * with season or episode numbers.
20      */
21     Comparator<BaseProgram> EPISODE_COMPARATOR = new EpisodeComparator(false);
22     /**
23      * Comparator used to compare {@link BaseProgram} according to its season and episodes number
24      * with season numbers in a reversed order. If a program's season or episode number is null, it
25      * will be consider "smaller" than programs with season or episode numbers.
26      */
27     Comparator<BaseProgram> SEASON_REVERSED_EPISODE_COMPARATOR = new EpisodeComparator(true);
28 
29     String COLUMN_SERIES_ID = "series_id";
30     String COLUMN_STATE = "state";
31 
32     /** Compares two strings represent season numbers or episode numbers of programs. */
numberCompare(String s1, String s2)33     static int numberCompare(String s1, String s2) {
34         if (Objects.equals(s1, s2)) {
35             return 0;
36         } else if (s1 == null) {
37             return -1;
38         } else if (s2 == null) {
39             return 1;
40         } else if (s1.equals(s2)) {
41             return 0;
42         }
43         try {
44             return Integer.compare(Integer.parseInt(s1), Integer.parseInt(s2));
45         } catch (NumberFormatException e) {
46             return s1.compareTo(s2);
47         }
48     }
49 
50     /** Generates the series ID for the other inputs than the tuner TV input. */
generateSeriesId(String packageName, String title)51     static String generateSeriesId(String packageName, String title) {
52         return packageName + "/" + title;
53     }
54 
55     /** Returns ID of the program. */
getId()56     long getId();
57 
58     /** Returns the title of the program. */
getTitle()59     String getTitle();
60 
61     /** Returns the episode title. */
getEpisodeTitle()62     String getEpisodeTitle();
63 
64     /** Returns the displayed title of the program episode. */
65     @Nullable
getEpisodeDisplayTitle(Context context)66     String getEpisodeDisplayTitle(Context context);
67 
68     /**
69      * Returns the content description of the program episode, suitable for being spoken by an
70      * accessibility service.
71      */
getEpisodeContentDescription(Context context)72     String getEpisodeContentDescription(Context context);
73 
74     /** Returns the description of the program. */
getDescription()75     String getDescription();
76 
77     /** Returns the long description of the program. */
getLongDescription()78     String getLongDescription();
79 
80     /** Returns the start time of the program in Milliseconds. */
getStartTimeUtcMillis()81     long getStartTimeUtcMillis();
82 
83     /** Returns the end time of the program in Milliseconds. */
getEndTimeUtcMillis()84     long getEndTimeUtcMillis();
85 
86     /** Returns the duration of the program in Milliseconds. */
getDurationMillis()87     long getDurationMillis();
88 
89     /** Returns the series ID. */
90     @Nullable
getSeriesId()91     String getSeriesId();
92 
93     /** Returns the season number. */
getSeasonNumber()94     String getSeasonNumber();
95 
96     /** Returns the episode number. */
getEpisodeNumber()97     String getEpisodeNumber();
98 
99     /** Returns URI of the program's poster. */
getPosterArtUri()100     String getPosterArtUri();
101 
102     /** Returns URI of the program's thumbnail. */
getThumbnailUri()103     String getThumbnailUri();
104 
105     /** Returns the array of the ID's of the canonical genres. */
getCanonicalGenreIds()106     int[] getCanonicalGenreIds();
107 
108     /** Returns the array of content ratings. */
getContentRatings()109     ImmutableList<TvContentRating> getContentRatings();
110 
111     /** Returns channel's ID of the program. */
getChannelId()112     long getChannelId();
113 
114     /** Returns if the program is valid. */
isValid()115     boolean isValid();
116 
117     /** Checks whether the program is episodic or not. */
isEpisodic()118     boolean isEpisodic();
119 
120     /** Generates the series ID for the other inputs than the tuner TV input. */
121     class EpisodeComparator implements Comparator<BaseProgram> {
122         private final boolean mReversedSeason;
123 
EpisodeComparator(boolean reversedSeason)124         EpisodeComparator(boolean reversedSeason) {
125             mReversedSeason = reversedSeason;
126         }
127 
128         @Override
compare(BaseProgram lhs, BaseProgram rhs)129         public int compare(BaseProgram lhs, BaseProgram rhs) {
130             if (lhs == rhs) {
131                 return 0;
132             }
133             int seasonNumberCompare = numberCompare(lhs.getSeasonNumber(), rhs.getSeasonNumber());
134             if (seasonNumberCompare != 0) {
135                 return mReversedSeason ? -seasonNumberCompare : seasonNumberCompare;
136             } else {
137                 return numberCompare(lhs.getEpisodeNumber(), rhs.getEpisodeNumber());
138             }
139         }
140     }
141 }
142