diff options
Diffstat (limited to 'src/com/android/tv/data/Program.java')
-rw-r--r-- | src/com/android/tv/data/Program.java | 325 |
1 files changed, 184 insertions, 141 deletions
diff --git a/src/com/android/tv/data/Program.java b/src/com/android/tv/data/Program.java index 071c7024..2c64cdbb 100644 --- a/src/com/android/tv/data/Program.java +++ b/src/com/android/tv/data/Program.java @@ -32,59 +32,56 @@ import android.support.annotation.UiThread; import android.support.annotation.VisibleForTesting; import android.text.TextUtils; import android.util.Log; - import com.android.tv.common.BuildConfig; -import com.android.tv.common.CollectionUtils; import com.android.tv.common.TvContentRatingCache; -import com.android.tv.util.ImageLoader; +import com.android.tv.common.util.CollectionUtils; +import com.android.tv.common.util.CommonUtils; +import com.android.tv.data.api.Channel; import com.android.tv.util.Utils; - +import com.android.tv.util.images.ImageLoader; import java.io.Serializable; import java.util.ArrayList; import java.util.Arrays; import java.util.List; import java.util.Objects; -/** - * A convenience class to create and insert program information entries into the database. - */ +/** A convenience class to create and insert program information entries into the database. */ public final class Program extends BaseProgram implements Comparable<Program>, Parcelable { private static final boolean DEBUG = false; private static final boolean DEBUG_DUMP_DESCRIPTION = false; private static final String TAG = "Program"; private static final String[] PROJECTION_BASE = { - // Columns must match what is read in Program.fromCursor() - TvContract.Programs._ID, - TvContract.Programs.COLUMN_PACKAGE_NAME, - TvContract.Programs.COLUMN_CHANNEL_ID, - TvContract.Programs.COLUMN_TITLE, - TvContract.Programs.COLUMN_EPISODE_TITLE, - TvContract.Programs.COLUMN_SHORT_DESCRIPTION, - TvContract.Programs.COLUMN_LONG_DESCRIPTION, - TvContract.Programs.COLUMN_POSTER_ART_URI, - TvContract.Programs.COLUMN_THUMBNAIL_URI, - TvContract.Programs.COLUMN_CANONICAL_GENRE, - TvContract.Programs.COLUMN_CONTENT_RATING, - TvContract.Programs.COLUMN_START_TIME_UTC_MILLIS, - TvContract.Programs.COLUMN_END_TIME_UTC_MILLIS, - TvContract.Programs.COLUMN_VIDEO_WIDTH, - TvContract.Programs.COLUMN_VIDEO_HEIGHT, - TvContract.Programs.COLUMN_INTERNAL_PROVIDER_DATA + // Columns must match what is read in Program.fromCursor() + TvContract.Programs._ID, + TvContract.Programs.COLUMN_PACKAGE_NAME, + TvContract.Programs.COLUMN_CHANNEL_ID, + TvContract.Programs.COLUMN_TITLE, + TvContract.Programs.COLUMN_EPISODE_TITLE, + TvContract.Programs.COLUMN_SHORT_DESCRIPTION, + TvContract.Programs.COLUMN_LONG_DESCRIPTION, + TvContract.Programs.COLUMN_POSTER_ART_URI, + TvContract.Programs.COLUMN_THUMBNAIL_URI, + TvContract.Programs.COLUMN_CANONICAL_GENRE, + TvContract.Programs.COLUMN_CONTENT_RATING, + TvContract.Programs.COLUMN_START_TIME_UTC_MILLIS, + TvContract.Programs.COLUMN_END_TIME_UTC_MILLIS, + TvContract.Programs.COLUMN_VIDEO_WIDTH, + TvContract.Programs.COLUMN_VIDEO_HEIGHT, + TvContract.Programs.COLUMN_INTERNAL_PROVIDER_DATA }; // Columns which is deprecated in NYC @SuppressWarnings("deprecation") private static final String[] PROJECTION_DEPRECATED_IN_NYC = { - TvContract.Programs.COLUMN_SEASON_NUMBER, - TvContract.Programs.COLUMN_EPISODE_NUMBER + TvContract.Programs.COLUMN_SEASON_NUMBER, TvContract.Programs.COLUMN_EPISODE_NUMBER }; private static final String[] PROJECTION_ADDED_IN_NYC = { - TvContract.Programs.COLUMN_SEASON_DISPLAY_NUMBER, - TvContract.Programs.COLUMN_SEASON_TITLE, - TvContract.Programs.COLUMN_EPISODE_DISPLAY_NUMBER, - TvContract.Programs.COLUMN_RECORDING_PROHIBITED + TvContract.Programs.COLUMN_SEASON_DISPLAY_NUMBER, + TvContract.Programs.COLUMN_SEASON_TITLE, + TvContract.Programs.COLUMN_EPISODE_DISPLAY_NUMBER, + TvContract.Programs.COLUMN_RECORDING_PROHIBITED }; public static final String[] PROJECTION = createProjection(); @@ -97,9 +94,7 @@ public final class Program extends BaseProgram implements Comparable<Program>, P : PROJECTION_DEPRECATED_IN_NYC); } - /** - * Returns the column index for {@code column}, -1 if the column doesn't exist. - */ + /** Returns the column index for {@code column}, -1 if the column doesn't exist. */ public static int getColumnIndex(String column) { for (int i = 0; i < PROJECTION.length; ++i) { if (PROJECTION[i].equals(column)) { @@ -135,7 +130,7 @@ public final class Program extends BaseProgram implements Comparable<Program>, P builder.setEndTimeUtcMillis(cursor.getLong(index++)); builder.setVideoWidth((int) cursor.getLong(index++)); builder.setVideoHeight((int) cursor.getLong(index++)); - if (Utils.isInBundledPackageSet(packageName)) { + if (CommonUtils.isInBundledPackageSet(packageName)) { InternalDataUtils.deserializeInternalProviderData(cursor.getBlob(index), builder); } index++; @@ -183,17 +178,18 @@ public final class Program extends BaseProgram implements Comparable<Program>, P return program; } - public static final Parcelable.Creator<Program> CREATOR = new Parcelable.Creator<Program>() { - @Override - public Program createFromParcel(Parcel in) { - return Program.fromParcel(in); - } + public static final Parcelable.Creator<Program> CREATOR = + new Parcelable.Creator<Program>() { + @Override + public Program createFromParcel(Parcel in) { + return Program.fromParcel(in); + } - @Override - public Program[] newArray(int size) { - return new Program[size]; - } - }; + @Override + public Program[] newArray(int size) { + return new Program[size]; + } + }; private long mId; private String mPackageName; @@ -225,9 +221,7 @@ public final class Program extends BaseProgram implements Comparable<Program>, P return mId; } - /** - * Returns the package name of this program. - */ + /** Returns the package name of this program. */ public String getPackageName() { return mPackageName; } @@ -236,18 +230,14 @@ public final class Program extends BaseProgram implements Comparable<Program>, P return mChannelId; } - /** - * Returns {@code true} if this program is valid or {@code false} otherwise. - */ + /** Returns {@code true} if this program is valid or {@code false} otherwise. */ @Override public boolean isValid() { return mChannelId >= 0; } - /** - * Returns {@code true} if the program is valid and {@code false} otherwise. - */ - public static boolean isValid(Program program) { + /** Returns {@code true} if the program is valid and {@code false} otherwise. */ + public static boolean isProgramValid(Program program) { return program != null && program.isValid(); } @@ -256,17 +246,13 @@ public final class Program extends BaseProgram implements Comparable<Program>, P return mTitle; } - /** - * Returns the series ID. - */ + /** Returns the series ID. */ @Override public String getSeriesId() { return mSeriesId; } - /** - * Returns the episode title. - */ + /** Returns the episode title. */ @Override public String getEpisodeTitle() { return mEpisodeTitle; @@ -292,9 +278,7 @@ public final class Program extends BaseProgram implements Comparable<Program>, P return mEndTimeUtcMillis; } - /** - * Returns the program duration. - */ + /** Returns the program duration. */ @Override public long getDurationMillis() { return mEndTimeUtcMillis - mStartTimeUtcMillis; @@ -318,9 +302,7 @@ public final class Program extends BaseProgram implements Comparable<Program>, P return mVideoHeight; } - /** - * Returns the list of Critic Scores for this program - */ + /** Returns the list of Critic Scores for this program */ @Nullable public List<CriticScore> getCriticScores() { return mCriticScores; @@ -342,17 +324,12 @@ public final class Program extends BaseProgram implements Comparable<Program>, P return mThumbnailUri; } - /** - * Returns {@code true} if the recording of this program is prohibited. - */ + /** Returns {@code true} if the recording of this program is prohibited. */ public boolean isRecordingProhibited() { return mRecordingProhibited; } - /** - * Returns array of canonical genres for this program. - * This is expected to be called rarely. - */ + /** Returns array of canonical genres for this program. This is expected to be called rarely. */ @Nullable public String[] getCanonicalGenres() { if (mCanonicalGenreIds == null) { @@ -365,17 +342,13 @@ public final class Program extends BaseProgram implements Comparable<Program>, P return genres; } - /** - * Returns array of canonical genre ID's for this program. - */ + /** Returns array of canonical genre ID's for this program. */ @Override public int[] getCanonicalGenreIds() { return mCanonicalGenreIds; } - /** - * Returns if this program has the genre. - */ + /** Returns if this program has the genre. */ public boolean hasGenre(int genreId) { if (genreId == GenreItems.ID_ALL_CHANNELS) { return true; @@ -393,10 +366,24 @@ public final class Program extends BaseProgram implements Comparable<Program>, P @Override public int hashCode() { // Hash with all the properties because program ID can be invalid for the dummy programs. - return Objects.hash(mChannelId, mStartTimeUtcMillis, mEndTimeUtcMillis, - mTitle, mSeriesId, mEpisodeTitle, mDescription, mLongDescription, mVideoWidth, - mVideoHeight, mPosterArtUri, mThumbnailUri, Arrays.hashCode(mContentRatings), - Arrays.hashCode(mCanonicalGenreIds), mSeasonNumber, mSeasonTitle, mEpisodeNumber, + return Objects.hash( + mChannelId, + mStartTimeUtcMillis, + mEndTimeUtcMillis, + mTitle, + mSeriesId, + mEpisodeTitle, + mDescription, + mLongDescription, + mVideoWidth, + mVideoHeight, + mPosterArtUri, + mThumbnailUri, + Arrays.hashCode(mContentRatings), + Arrays.hashCode(mCanonicalGenreIds), + mSeasonNumber, + mSeasonTitle, + mEpisodeNumber, mRecordingProhibited); } @@ -436,28 +423,47 @@ public final class Program extends BaseProgram implements Comparable<Program>, P @Override public String toString() { StringBuilder builder = new StringBuilder(); - builder.append("Program[").append(mId) - .append("]{channelId=").append(mChannelId) - .append(", packageName=").append(mPackageName) - .append(", title=").append(mTitle) - .append(", seriesId=").append(mSeriesId) - .append(", episodeTitle=").append(mEpisodeTitle) - .append(", seasonNumber=").append(mSeasonNumber) - .append(", seasonTitle=").append(mSeasonTitle) - .append(", episodeNumber=").append(mEpisodeNumber) - .append(", startTimeUtcSec=").append(Utils.toTimeString(mStartTimeUtcMillis)) - .append(", endTimeUtcSec=").append(Utils.toTimeString(mEndTimeUtcMillis)) - .append(", videoWidth=").append(mVideoWidth) - .append(", videoHeight=").append(mVideoHeight) + builder.append("Program[") + .append(mId) + .append("]{channelId=") + .append(mChannelId) + .append(", packageName=") + .append(mPackageName) + .append(", title=") + .append(mTitle) + .append(", seriesId=") + .append(mSeriesId) + .append(", episodeTitle=") + .append(mEpisodeTitle) + .append(", seasonNumber=") + .append(mSeasonNumber) + .append(", seasonTitle=") + .append(mSeasonTitle) + .append(", episodeNumber=") + .append(mEpisodeNumber) + .append(", startTimeUtcSec=") + .append(Utils.toTimeString(mStartTimeUtcMillis)) + .append(", endTimeUtcSec=") + .append(Utils.toTimeString(mEndTimeUtcMillis)) + .append(", videoWidth=") + .append(mVideoWidth) + .append(", videoHeight=") + .append(mVideoHeight) .append(", contentRatings=") .append(TvContentRatingCache.contentRatingsToString(mContentRatings)) - .append(", posterArtUri=").append(mPosterArtUri) - .append(", thumbnailUri=").append(mThumbnailUri) - .append(", canonicalGenres=").append(Arrays.toString(mCanonicalGenreIds)) - .append(", recordingProhibited=").append(mRecordingProhibited); + .append(", posterArtUri=") + .append(mPosterArtUri) + .append(", thumbnailUri=") + .append(mThumbnailUri) + .append(", canonicalGenres=") + .append(Arrays.toString(mCanonicalGenreIds)) + .append(", recordingProhibited=") + .append(mRecordingProhibited); if (DEBUG_DUMP_DESCRIPTION) { - builder.append(", description=").append(mDescription) - .append(", longDescription=").append(mLongDescription); + builder.append(", description=") + .append(mDescription) + .append(", longDescription=") + .append(mLongDescription); } return builder.append("}").toString(); } @@ -471,12 +477,19 @@ public final class Program extends BaseProgram implements Comparable<Program>, P public static ContentValues toContentValues(Program program) { ContentValues values = new ContentValues(); values.put(TvContract.Programs.COLUMN_CHANNEL_ID, program.getChannelId()); + if (!TextUtils.isEmpty(program.getPackageName())) { + values.put(Programs.COLUMN_PACKAGE_NAME, program.getPackageName()); + } putValue(values, TvContract.Programs.COLUMN_TITLE, program.getTitle()); putValue(values, TvContract.Programs.COLUMN_EPISODE_TITLE, program.getEpisodeTitle()); if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) { - putValue(values, TvContract.Programs.COLUMN_SEASON_DISPLAY_NUMBER, + putValue( + values, + TvContract.Programs.COLUMN_SEASON_DISPLAY_NUMBER, program.getSeasonNumber()); - putValue(values, TvContract.Programs.COLUMN_EPISODE_DISPLAY_NUMBER, + putValue( + values, + TvContract.Programs.COLUMN_EPISODE_DISPLAY_NUMBER, program.getEpisodeNumber()); } else { putValue(values, TvContract.Programs.COLUMN_SEASON_NUMBER, program.getSeasonNumber()); @@ -488,17 +501,23 @@ public final class Program extends BaseProgram implements Comparable<Program>, P putValue(values, TvContract.Programs.COLUMN_THUMBNAIL_URI, program.getThumbnailUri()); String[] canonicalGenres = program.getCanonicalGenres(); if (canonicalGenres != null && canonicalGenres.length > 0) { - putValue(values, TvContract.Programs.COLUMN_CANONICAL_GENRE, + putValue( + values, + TvContract.Programs.COLUMN_CANONICAL_GENRE, TvContract.Programs.Genres.encode(canonicalGenres)); } else { putValue(values, TvContract.Programs.COLUMN_CANONICAL_GENRE, ""); } - putValue(values, Programs.COLUMN_CONTENT_RATING, + putValue( + values, + Programs.COLUMN_CONTENT_RATING, TvContentRatingCache.contentRatingsToString(program.getContentRatings())); - values.put(TvContract.Programs.COLUMN_START_TIME_UTC_MILLIS, - program.getStartTimeUtcMillis()); + values.put( + TvContract.Programs.COLUMN_START_TIME_UTC_MILLIS, program.getStartTimeUtcMillis()); values.put(TvContract.Programs.COLUMN_END_TIME_UTC_MILLIS, program.getEndTimeUtcMillis()); - putValue(values, TvContract.Programs.COLUMN_INTERNAL_PROVIDER_DATA, + putValue( + values, + TvContract.Programs.COLUMN_INTERNAL_PROVIDER_DATA, InternalDataUtils.serializeInternalProviderData(program)); return values; } @@ -547,15 +566,11 @@ public final class Program extends BaseProgram implements Comparable<Program>, P mRecordingProhibited = other.mRecordingProhibited; } - /** - * A Builder for the Program class - */ + /** A Builder for the Program class */ public static final class Builder { private final Program mProgram; - /** - * Creates a Builder for this Program class - */ + /** Creates a Builder for this Program class */ public Builder() { mProgram = new Program(); // Fill initial data. @@ -574,8 +589,9 @@ public final class Program extends BaseProgram implements Comparable<Program>, P } /** - * Creates a builder for this Program class - * by setting default values equivalent to another Program + * Creates a builder for this Program class by setting default values equivalent to another + * Program + * * @param other the program to be copied */ @VisibleForTesting @@ -586,6 +602,7 @@ public final class Program extends BaseProgram implements Comparable<Program>, P /** * Sets the ID of this program + * * @param id the ID * @return a reference to this object */ @@ -596,16 +613,18 @@ public final class Program extends BaseProgram implements Comparable<Program>, P /** * Sets the package name for this program + * * @param packageName the package name * @return a reference to this object */ - public Builder setPackageName(String packageName){ + public Builder setPackageName(String packageName) { mProgram.mPackageName = packageName; return this; } /** * Sets the channel ID for this program + * * @param channelId the channel ID * @return a reference to this object */ @@ -616,6 +635,7 @@ public final class Program extends BaseProgram implements Comparable<Program>, P /** * Sets the program title + * * @param title the title * @return a reference to this object */ @@ -626,6 +646,7 @@ public final class Program extends BaseProgram implements Comparable<Program>, P /** * Sets the series ID. + * * @param seriesId the series ID * @return a reference to this object */ @@ -636,6 +657,7 @@ public final class Program extends BaseProgram implements Comparable<Program>, P /** * Sets the episode title if this is a series program + * * @param episodeTitle the episode title * @return a reference to this object */ @@ -646,6 +668,7 @@ public final class Program extends BaseProgram implements Comparable<Program>, P /** * Sets the season number if this is a series program + * * @param seasonNumber the season number * @return a reference to this object */ @@ -654,9 +677,9 @@ public final class Program extends BaseProgram implements Comparable<Program>, P return this; } - /** * Sets the season title if this is a series program + * * @param seasonTitle the season title * @return a reference to this object */ @@ -667,6 +690,7 @@ public final class Program extends BaseProgram implements Comparable<Program>, P /** * Sets the episode number if this is a series program + * * @param episodeNumber the episode number * @return a reference to this object */ @@ -677,6 +701,7 @@ public final class Program extends BaseProgram implements Comparable<Program>, P /** * Sets the start time of this program + * * @param startTimeUtcMillis the start time in UTC milliseconds * @return a reference to this object */ @@ -687,6 +712,7 @@ public final class Program extends BaseProgram implements Comparable<Program>, P /** * Sets the end time of this program + * * @param endTimeUtcMillis the end time in UTC milliseconds * @return a reference to this object */ @@ -697,6 +723,7 @@ public final class Program extends BaseProgram implements Comparable<Program>, P /** * Sets a description + * * @param description the description * @return a reference to this object */ @@ -707,6 +734,7 @@ public final class Program extends BaseProgram implements Comparable<Program>, P /** * Sets a long description + * * @param longDescription the long description * @return a reference to this object */ @@ -717,6 +745,7 @@ public final class Program extends BaseProgram implements Comparable<Program>, P /** * Defines the video width of this program + * * @param width * @return a reference to this object */ @@ -727,6 +756,7 @@ public final class Program extends BaseProgram implements Comparable<Program>, P /** * Defines the video height of this program + * * @param height * @return a reference to this object */ @@ -737,6 +767,7 @@ public final class Program extends BaseProgram implements Comparable<Program>, P /** * Sets the content ratings for this program + * * @param contentRatings the content ratings * @return a reference to this object */ @@ -747,6 +778,7 @@ public final class Program extends BaseProgram implements Comparable<Program>, P /** * Sets the poster art URI + * * @param posterArtUri the poster art URI * @return a reference to this object */ @@ -757,6 +789,7 @@ public final class Program extends BaseProgram implements Comparable<Program>, P /** * Sets the thumbnail URI + * * @param thumbnailUri the thumbnail URI * @return a reference to this object */ @@ -767,6 +800,7 @@ public final class Program extends BaseProgram implements Comparable<Program>, P /** * Sets the canonical genres by id + * * @param genres the genres * @return a reference to this object */ @@ -777,6 +811,7 @@ public final class Program extends BaseProgram implements Comparable<Program>, P /** * Sets the recording prohibited flag + * * @param recordingProhibited recording prohibited flag * @return a reference to this object */ @@ -787,6 +822,7 @@ public final class Program extends BaseProgram implements Comparable<Program>, P /** * Adds a critic score + * * @param criticScore the critic score * @return a reference to this object */ @@ -802,6 +838,7 @@ public final class Program extends BaseProgram implements Comparable<Program>, P /** * Sets the critic scores + * * @param criticScores the critic scores * @return a reference to this objects */ @@ -812,6 +849,7 @@ public final class Program extends BaseProgram implements Comparable<Program>, P /** * Returns a reference to the Program object being constructed + * * @return the Program object constructed */ public Program build() { @@ -831,7 +869,9 @@ public final class Program extends BaseProgram implements Comparable<Program>, P } /** - * Prefetches the program poster art.<p> + * Prefetches the program poster art. + * + * <p> */ public void prefetchPosterArt(Context context, int posterArtWidth, int posterArtHeight) { if (mPosterArtUri == null) { @@ -842,13 +882,17 @@ public final class Program extends BaseProgram implements Comparable<Program>, P /** * Loads the program poster art and returns it via {@code callback}. - * <p> - * Note that it may directly call {@code callback} if the program poster art already is loaded. + * + * <p>Note that it may directly call {@code callback} if the program poster art already is + * loaded. * * @return {@code true} if the load is complete and the callback is executed. */ @UiThread - public boolean loadPosterArt(Context context, int posterArtWidth, int posterArtHeight, + public boolean loadPosterArt( + Context context, + int posterArtWidth, + int posterArtHeight, ImageLoader.ImageLoaderCallback callback) { if (mPosterArtUri == null) { return false; @@ -861,12 +905,18 @@ public final class Program extends BaseProgram implements Comparable<Program>, P if (p1 == null || p2 == null) { return false; } - boolean isDuplicate = p1.getChannelId() == p2.getChannelId() - && p1.getStartTimeUtcMillis() == p2.getStartTimeUtcMillis() - && p1.getEndTimeUtcMillis() == p2.getEndTimeUtcMillis(); + boolean isDuplicate = + p1.getChannelId() == p2.getChannelId() + && p1.getStartTimeUtcMillis() == p2.getStartTimeUtcMillis() + && p1.getEndTimeUtcMillis() == p2.getEndTimeUtcMillis(); if (DEBUG && BuildConfig.ENG && isDuplicate) { - Log.w(TAG, "Duplicate programs detected! - \"" + p1.getTitle() + "\" and \"" - + p2.getTitle() + "\""); + Log.w( + TAG, + "Duplicate programs detected! - \"" + + p1.getTitle() + + "\" and \"" + + p2.getTitle() + + "\""); } return isDuplicate; } @@ -906,21 +956,13 @@ public final class Program extends BaseProgram implements Comparable<Program>, P out.writeByte((byte) (mRecordingProhibited ? 1 : 0)); } - /** - * Holds one type of critic score and its source. - */ + /** Holds one type of critic score and its source. */ public static final class CriticScore implements Serializable, Parcelable { - /** - * The source of the rating. - */ + /** The source of the rating. */ public final String source; - /** - * The score. - */ + /** The score. */ public final String score; - /** - * The url of the logo image - */ + /** The url of the logo image */ public final String logoUrl; public static final Parcelable.Creator<CriticScore> CREATOR = @@ -929,7 +971,7 @@ public final class Program extends BaseProgram implements Comparable<Program>, P public CriticScore createFromParcel(Parcel in) { String source = in.readString(); String score = in.readString(); - String logoUri = in.readString(); + String logoUri = in.readString(); return new CriticScore(source, score, logoUri); } @@ -941,6 +983,7 @@ public final class Program extends BaseProgram implements Comparable<Program>, P /** * Constructor for this class. + * * @param source the source of the rating * @param score the score */ |