• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2016 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.android.tv.data;
18 
19 import android.content.Context;
20 import android.support.annotation.Nullable;
21 import android.text.TextUtils;
22 
23 import com.android.tv.R;
24 import com.android.tv.data.api.BaseProgram;
25 
26 /** Base class for {@link ProgramImpl} and {@link com.android.tv.dvr.data.RecordedProgram}. */
27 public abstract class BaseProgramImpl implements BaseProgram {
28 
29     @Override
30     @Nullable
getEpisodeDisplayTitle(Context context)31     public String getEpisodeDisplayTitle(Context context) {
32         String episodeNumber = getEpisodeNumber();
33         String episodeTitle = getEpisodeTitle();
34         if (!TextUtils.isEmpty(episodeNumber)) {
35             episodeTitle = episodeTitle == null ? "" : episodeTitle;
36             String seasonNumber = getSeasonNumber();
37             if (TextUtils.isEmpty(seasonNumber) || TextUtils.equals(seasonNumber, "0")) {
38                 // Do not show "S0: ".
39                 return context.getResources()
40                         .getString(
41                                 R.string.display_episode_title_format_no_season_number,
42                                 episodeNumber,
43                                 episodeTitle);
44             } else {
45                 return context.getResources()
46                         .getString(
47                                 R.string.display_episode_title_format,
48                                 seasonNumber,
49                                 episodeNumber,
50                                 episodeTitle);
51             }
52         }
53         return episodeTitle;
54     }
55 
56     @Override
getEpisodeContentDescription(Context context)57     public String getEpisodeContentDescription(Context context) {
58         String episodeNumber = getEpisodeNumber();
59         String episodeTitle = getEpisodeTitle();
60         if (!TextUtils.isEmpty(episodeNumber)) {
61             episodeTitle = episodeTitle == null ? "" : episodeTitle;
62             String seasonNumber = getSeasonNumber();
63             if (TextUtils.isEmpty(seasonNumber) || TextUtils.equals(seasonNumber, "0")) {
64                 // Do not list season if it is empty or 0
65                 return context.getResources()
66                         .getString(
67                                 R.string.content_description_episode_format_no_season_number,
68                                 episodeNumber,
69                                 episodeTitle);
70             } else {
71                 return context.getResources()
72                         .getString(
73                                 R.string.content_description_episode_format,
74                                 seasonNumber,
75                                 episodeNumber,
76                                 episodeTitle);
77             }
78         }
79         return episodeTitle;
80     }
81 
82     @Override
isEpisodic()83     public boolean isEpisodic() {
84         return !TextUtils.isEmpty(getSeriesId());
85     }
86 }
87