Home | History | Annotate | Download | only in ui
      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;
     18 
     19 import android.content.Context;
     20 import android.content.Intent;
     21 import android.content.res.Resources;
     22 import android.text.TextUtils;
     23 import android.util.Log;
     24 import android.view.View;
     25 import android.view.View.OnClickListener;
     26 import android.view.ViewGroup;
     27 
     28 import com.android.tv.R;
     29 import com.android.tv.dvr.RecordedProgram;
     30 import com.android.tv.dvr.DvrPlaybackActivity;
     31 import com.android.tv.util.Utils;
     32 
     33 /**
     34  * This class is used to generate Views and bind Objects for related recordings in DVR playback.
     35  */
     36 public class DvrPlaybackCardPresenter extends RecordedProgramPresenter {
     37     private static final String TAG = "DvrPlaybackCardPresenter";
     38     private static final boolean DEBUG = false;
     39 
     40     private final int mRelatedRecordingCardWidth;
     41     private final int mRelatedRecordingCardHeight;
     42 
     43     DvrPlaybackCardPresenter(Context context) {
     44         super(context);
     45         mRelatedRecordingCardWidth =
     46                 context.getResources().getDimensionPixelSize(R.dimen.dvr_related_recordings_width);
     47         mRelatedRecordingCardHeight =
     48                 context.getResources().getDimensionPixelSize(R.dimen.dvr_related_recordings_height);
     49     }
     50 
     51     @Override
     52     public ViewHolder onCreateViewHolder(ViewGroup parent) {
     53         Resources res = parent.getResources();
     54         RecordingCardView view = new RecordingCardView(
     55                 getContext(), mRelatedRecordingCardWidth, mRelatedRecordingCardHeight);
     56         return new ViewHolder(view);
     57     }
     58 
     59     @Override
     60     protected OnClickListener onCreateOnClickListener() {
     61         return new OnClickListener() {
     62             @Override
     63             public void onClick(View v) {
     64                 long programId = ((RecordedProgram) v.getTag()).getId();
     65                 if (DEBUG) Log.d(TAG, "Play Related Recording:" + programId);
     66                 Intent intent = new Intent(getContext(), DvrPlaybackActivity.class);
     67                 intent.putExtra(Utils.EXTRA_KEY_RECORDED_PROGRAM_ID, programId);
     68                 getContext().startActivity(intent);
     69             }
     70         };
     71     }
     72 
     73     @Override
     74     protected String getDescription(RecordedProgram program) {
     75         String description = program.getDescription();
     76         if (TextUtils.isEmpty(description)) {
     77             description =
     78                     getContext().getResources().getString(R.string.dvr_msg_no_program_description);
     79         }
     80         return description;
     81     }
     82 }