Program.java revision 2be00440937254386dae3a1c0c02a7ac76ad92ca
1/*
2 * Copyright (C) 2014 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
17package com.android.tv.data;
18
19import android.content.ContentValues;
20import android.media.tv.TvContentRating;
21import android.media.tv.TvContract;
22
23/**
24 * A convenience class to create and insert program information entries into the database.
25 */
26public final class Program {
27    public static final long INVALID_ID = -1;
28
29    private long mChannelId;
30    private String mTitle;
31    private long mStartTimeUtcMillis;
32    private long mEndTimeUtcMillis;
33    private String mDescription;
34    private String mLongDescription;
35    private String mVideoDefinitionLevel;
36    private String mPosterArtUri;
37    private String mThumbnailUri;
38    private TvContentRating[] mContentRatings;
39
40    private Program() {
41        // Do nothing.
42    }
43
44    public long getChannelId() {
45        return mChannelId;
46    }
47
48    public void setChannelId(long channelId) {
49        mChannelId = channelId;
50    }
51
52    public String getTitle() {
53        return mTitle;
54    }
55
56    public void setTitle(String title) {
57        mTitle = title;
58    }
59
60    public long getStartTimeUtcMillis() {
61        return mStartTimeUtcMillis;
62    }
63
64    public void setStartTimeUtcMillis(long startTimeUtcMillis) {
65        mStartTimeUtcMillis = startTimeUtcMillis;
66    }
67
68    public long getEndTimeUtcMillis() {
69        return mEndTimeUtcMillis;
70    }
71
72    public void setEndTimeUtcMillis(long endTimeUtcMillis) {
73        mEndTimeUtcMillis = endTimeUtcMillis;
74    }
75
76    public String getDescription() {
77        return mDescription;
78    }
79
80    public void setDescription(String description) {
81        mDescription = description;
82    }
83
84    public String getLongDescription() {
85        return mLongDescription;
86    }
87
88    public void setLongDescription(String longDescription) {
89        mLongDescription = longDescription;
90    }
91
92    public String getVideoDefinitionLevel() {
93        return mVideoDefinitionLevel;
94    }
95
96    public void setVideoDefinitionLevel(String videoDefinitionLevel) {
97        mVideoDefinitionLevel = videoDefinitionLevel;
98    }
99
100    public TvContentRating[] getContentRatings() {
101        return mContentRatings;
102    }
103
104    public void setContentRatings(TvContentRating[] contentRatings) {
105        mContentRatings = contentRatings;
106    }
107
108    public String getPosterArtUri() {
109        return mPosterArtUri;
110    }
111
112    public void setPosterArtUri(String posterArtUri) {
113        mPosterArtUri = posterArtUri;
114    }
115
116    public String getThumbnailUri() {
117        return mThumbnailUri;
118    }
119
120    public void setThumbnailUri(String thumbnailUri) {
121        mThumbnailUri = thumbnailUri;
122    }
123
124    public ContentValues toContentValues() {
125        ContentValues values = new ContentValues();
126        values.put(TvContract.Programs.COLUMN_CHANNEL_ID, mChannelId);
127        values.put(TvContract.Programs.COLUMN_TITLE, mTitle);
128        values.put(TvContract.Programs.COLUMN_START_TIME_UTC_MILLIS, mStartTimeUtcMillis);
129        values.put(TvContract.Programs.COLUMN_END_TIME_UTC_MILLIS, mEndTimeUtcMillis);
130        values.put(TvContract.Programs.COLUMN_SHORT_DESCRIPTION, mDescription);
131        values.put(TvContract.Programs.COLUMN_LONG_DESCRIPTION, mLongDescription);
132        values.put(TvContract.Programs.COLUMN_POSTER_ART_URI, mPosterArtUri);
133        values.put(TvContract.Programs.COLUMN_THUMBNAIL_URI, mThumbnailUri);
134        return values;
135    }
136
137    @Override
138    public String toString() {
139        return new StringBuilder()
140                .append("Program{")
141                .append(", channelId=").append(mChannelId)
142                .append(", title=").append(mTitle)
143                .append(", startTimeUtcSec=").append(mStartTimeUtcMillis)
144                .append(", endTimeUtcSec=").append(mEndTimeUtcMillis)
145                .append(", description=").append(mDescription)
146                .append(", longDescription=").append(mLongDescription)
147                .append(", videoDefinitionLevel=").append(mVideoDefinitionLevel)
148                .append(", posterArtUri=").append(mPosterArtUri)
149                .append(", thumbnailUri=").append(mThumbnailUri)
150                .append("}")
151                .toString();
152    }
153
154    public void copyFrom(Program other) {
155        if (this == other) {
156            return;
157        }
158
159        mChannelId = other.mChannelId;
160        mTitle = other.mTitle;
161        mStartTimeUtcMillis = other.mStartTimeUtcMillis;
162        mEndTimeUtcMillis = other.mEndTimeUtcMillis;
163        mDescription = other.mDescription;
164        mLongDescription = other.mLongDescription;
165        mVideoDefinitionLevel = other.mVideoDefinitionLevel;
166        mPosterArtUri = other.mPosterArtUri;
167        mThumbnailUri = other.mThumbnailUri;
168    }
169
170    public static final class Builder {
171        private final Program mProgram;
172
173        public Builder() {
174            mProgram = new Program();
175            // Fill initial data.
176            mProgram.mChannelId = Channel.INVALID_ID;
177            mProgram.mTitle = "title";
178            mProgram.mStartTimeUtcMillis = -1;
179            mProgram.mEndTimeUtcMillis = -1;
180            mProgram.mDescription = "description";
181            mProgram.mLongDescription = "long_description";
182        }
183
184        public Builder(Program other) {
185            mProgram = new Program();
186            mProgram.copyFrom(other);
187        }
188
189        public Builder setChannelId(long channelId) {
190            mProgram.mChannelId = channelId;
191            return this;
192        }
193
194        public Builder setTitle(String title) {
195            mProgram.mTitle = title;
196            return this;
197        }
198
199        public Builder setStartTimeUtcMillis(long startTimeUtcMillis) {
200            mProgram.mStartTimeUtcMillis = startTimeUtcMillis;
201            return this;
202        }
203
204        public Builder setEndTimeUtcMillis(long endTimeUtcMillis) {
205            mProgram.mEndTimeUtcMillis = endTimeUtcMillis;
206            return this;
207        }
208
209        public Builder setDescription(String description) {
210            mProgram.mDescription = description;
211            return this;
212        }
213
214        public Builder setLongDescription(String longDescription) {
215            mProgram.mLongDescription = longDescription;
216            return this;
217        }
218
219        public Builder setVideoDefinitionLevel(String videoDefinitionLevel) {
220            mProgram.mVideoDefinitionLevel = videoDefinitionLevel;
221            return this;
222        }
223
224        public Builder setContentRatings(TvContentRating[] contentRatings) {
225            mProgram.mContentRatings = contentRatings;
226            return this;
227        }
228
229        public Builder setPosterArtUri(String posterArtUri) {
230            mProgram.mPosterArtUri = posterArtUri;
231            return this;
232        }
233
234        public Builder setThumbnailUri(String thumbnailUri) {
235            mProgram.mThumbnailUri = thumbnailUri;
236            return this;
237        }
238
239        public Program build() {
240            return mProgram;
241        }
242    }
243}
244