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 17package com.android.tv.dvr.ui; 18 19import android.media.tv.TvContract; 20import android.support.annotation.Nullable; 21import android.text.TextUtils; 22 23import com.android.tv.data.BaseProgram; 24import com.android.tv.data.Channel; 25 26/** 27 * A class for details content. 28 */ 29public class DetailsContent { 30 /** Constant for invalid time. */ 31 public static final long INVALID_TIME = -1; 32 33 private CharSequence mTitle; 34 private long mStartTimeUtcMillis; 35 private long mEndTimeUtcMillis; 36 private String mDescription; 37 private String mLogoImageUri; 38 private String mBackgroundImageUri; 39 40 private DetailsContent() { } 41 42 /** 43 * Returns title. 44 */ 45 public CharSequence getTitle() { 46 return mTitle; 47 } 48 49 /** 50 * Returns start time. 51 */ 52 public long getStartTimeUtcMillis() { 53 return mStartTimeUtcMillis; 54 } 55 56 /** 57 * Returns end time. 58 */ 59 public long getEndTimeUtcMillis() { 60 return mEndTimeUtcMillis; 61 } 62 63 /** 64 * Returns description. 65 */ 66 public String getDescription() { 67 return mDescription; 68 } 69 70 /** 71 * Returns Logo image URI as a String. 72 */ 73 public String getLogoImageUri() { 74 return mLogoImageUri; 75 } 76 77 /** 78 * Returns background image URI as a String. 79 */ 80 public String getBackgroundImageUri() { 81 return mBackgroundImageUri; 82 } 83 84 /** 85 * Copies other details content. 86 */ 87 public void copyFrom(DetailsContent other) { 88 if (this == other) { 89 return; 90 } 91 mTitle = other.mTitle; 92 mStartTimeUtcMillis = other.mStartTimeUtcMillis; 93 mEndTimeUtcMillis = other.mEndTimeUtcMillis; 94 mDescription = other.mDescription; 95 mLogoImageUri = other.mLogoImageUri; 96 mBackgroundImageUri = other.mBackgroundImageUri; 97 } 98 99 /** 100 * A class for building details content. 101 */ 102 public static final class Builder { 103 private final DetailsContent mDetailsContent; 104 105 public Builder() { 106 mDetailsContent = new DetailsContent(); 107 mDetailsContent.mStartTimeUtcMillis = INVALID_TIME; 108 mDetailsContent.mEndTimeUtcMillis = INVALID_TIME; 109 } 110 111 /** 112 * Sets title. 113 */ 114 public Builder setTitle(CharSequence title) { 115 mDetailsContent.mTitle = title; 116 return this; 117 } 118 119 /** 120 * Sets start time. 121 */ 122 public Builder setStartTimeUtcMillis(long startTimeUtcMillis) { 123 mDetailsContent.mStartTimeUtcMillis = startTimeUtcMillis; 124 return this; 125 } 126 127 /** 128 * Sets end time. 129 */ 130 public Builder setEndTimeUtcMillis(long endTimeUtcMillis) { 131 mDetailsContent.mEndTimeUtcMillis = endTimeUtcMillis; 132 return this; 133 } 134 135 /** 136 * Sets description. 137 */ 138 public Builder setDescription(String description) { 139 mDetailsContent.mDescription = description; 140 return this; 141 } 142 143 /** 144 * Sets logo image URI as a String. 145 */ 146 public Builder setLogoImageUri(String logoImageUri) { 147 mDetailsContent.mLogoImageUri = logoImageUri; 148 return this; 149 } 150 151 /** 152 * Sets background image URI as a String. 153 */ 154 public Builder setBackgroundImageUri(String backgroundImageUri) { 155 mDetailsContent.mBackgroundImageUri = backgroundImageUri; 156 return this; 157 } 158 159 /** 160 * Sets background image and logo image URI from program and channel. 161 */ 162 public Builder setImageUris(@Nullable BaseProgram program, @Nullable Channel channel) { 163 if (program != null) { 164 return setImageUris(program.getPosterArtUri(), program.getThumbnailUri(), channel); 165 } else { 166 return setImageUris(null, null, channel); 167 } 168 } 169 170 /** 171 * Sets background image and logo image URI and channel is used for fallback images. 172 */ 173 public Builder setImageUris(@Nullable String posterArtUri, 174 @Nullable String thumbnailUri, @Nullable Channel channel) { 175 mDetailsContent.mLogoImageUri = null; 176 mDetailsContent.mBackgroundImageUri = null; 177 if (!TextUtils.isEmpty(posterArtUri) && !TextUtils.isEmpty(thumbnailUri)) { 178 mDetailsContent.mLogoImageUri = posterArtUri; 179 mDetailsContent.mBackgroundImageUri = thumbnailUri; 180 } else if (!TextUtils.isEmpty(posterArtUri)) { 181 // thumbnailUri is empty 182 mDetailsContent.mLogoImageUri = posterArtUri; 183 mDetailsContent.mBackgroundImageUri = posterArtUri; 184 } else if (!TextUtils.isEmpty(thumbnailUri)) { 185 // posterArtUri is empty 186 mDetailsContent.mLogoImageUri = thumbnailUri; 187 mDetailsContent.mBackgroundImageUri = thumbnailUri; 188 } 189 if (TextUtils.isEmpty(mDetailsContent.mLogoImageUri) && channel != null) { 190 String channelLogoUri = TvContract.buildChannelLogoUri(channel.getId()) 191 .toString(); 192 mDetailsContent.mLogoImageUri = channelLogoUri; 193 mDetailsContent.mBackgroundImageUri = channelLogoUri; 194 } 195 return this; 196 } 197 198 /** 199 * Builds details content. 200 */ 201 public DetailsContent build() { 202 DetailsContent detailsContent = new DetailsContent(); 203 detailsContent.copyFrom(mDetailsContent); 204 return detailsContent; 205 } 206 } 207}