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