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.browse; 18 19import android.content.Context; 20import android.graphics.drawable.Drawable; 21import android.view.View; 22import android.view.ViewGroup; 23 24import com.android.tv.R; 25import com.android.tv.TvApplication; 26import com.android.tv.dvr.data.ScheduledRecording; 27import com.android.tv.dvr.ui.DvrUiHelper; 28import com.android.tv.util.Utils; 29 30import java.util.Collections; 31import java.util.List; 32 33/** 34 * Presents a {@link ScheduledRecording} in the {@link DvrBrowseFragment}. 35 */ 36class FullSchedulesCardPresenter extends DvrItemPresenter<Object> { 37 private final Drawable mIconDrawable; 38 private final String mCardTitleText; 39 40 FullSchedulesCardPresenter(Context context) { 41 super(context); 42 mIconDrawable = mContext.getDrawable(R.drawable.dvr_full_schedule); 43 mCardTitleText = mContext.getString(R.string.dvr_full_schedule_card_view_title); 44 } 45 46 @Override 47 public DvrItemViewHolder onCreateDvrItemViewHolder() { 48 return new DvrItemViewHolder(new RecordingCardView(mContext)); 49 } 50 51 @Override 52 public void onBindDvrItemViewHolder(DvrItemViewHolder vh, Object o) { 53 final RecordingCardView cardView = (RecordingCardView) vh.view; 54 55 cardView.setTitle(mCardTitleText); 56 cardView.setImage(mIconDrawable); 57 List<ScheduledRecording> scheduledRecordings = TvApplication.getSingletons(mContext) 58 .getDvrDataManager().getAvailableScheduledRecordings(); 59 int fullDays = 0; 60 if (!scheduledRecordings.isEmpty()) { 61 fullDays = Utils.computeDateDifference(System.currentTimeMillis(), 62 Collections.max(scheduledRecordings, ScheduledRecording.START_TIME_COMPARATOR) 63 .getStartTimeMs()) + 1; 64 } 65 cardView.setContent(mContext.getResources().getQuantityString( 66 R.plurals.dvr_full_schedule_card_view_content, fullDays, fullDays), null); 67 } 68 69 @Override 70 public void onUnbindViewHolder(ViewHolder vh) { 71 ((RecordingCardView) vh.view).reset(); 72 super.onUnbindViewHolder(vh); 73 } 74 75 @Override 76 protected View.OnClickListener onCreateOnClickListener() { 77 return new View.OnClickListener() { 78 @Override 79 public void onClick(View view) { 80 DvrUiHelper.startSchedulesActivity(mContext, null); 81 } 82 }; 83 } 84}