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.res.Resources;
     20 import android.os.Bundle;
     21 import android.support.v17.leanback.widget.Action;
     22 import android.support.v17.leanback.widget.OnActionClickedListener;
     23 import android.support.v17.leanback.widget.SparseArrayObjectAdapter;
     24 import com.android.tv.R;
     25 import com.android.tv.TvSingletons;
     26 import com.android.tv.dvr.DvrManager;
     27 import com.android.tv.dvr.ui.DvrUiHelper;
     28 
     29 /** {@link RecordingDetailsFragment} for scheduled recording in DVR. */
     30 public class ScheduledRecordingDetailsFragment extends RecordingDetailsFragment {
     31     private static final int ACTION_VIEW_SCHEDULE = 1;
     32     private static final int ACTION_CANCEL = 2;
     33 
     34     private DvrManager mDvrManager;
     35     private Action mScheduleAction;
     36     private boolean mHideViewSchedule;
     37     private String mFailedMessage;
     38 
     39     @Override
     40     public void onCreate(Bundle savedInstance) {
     41         Bundle args = getArguments();
     42         mDvrManager = TvSingletons.getSingletons(getContext()).getDvrManager();
     43         mHideViewSchedule = args.getBoolean(DvrDetailsActivity.HIDE_VIEW_SCHEDULE);
     44         mFailedMessage = args.getString(DvrDetailsActivity.EXTRA_FAILED_MESSAGE);
     45         super.onCreate(savedInstance);
     46     }
     47 
     48     @Override
     49     public void onResume() {
     50         super.onResume();
     51         if (mScheduleAction != null) {
     52             mScheduleAction.setIcon(getResources().getDrawable(getScheduleIconId()));
     53         }
     54     }
     55 
     56     @Override
     57     protected void onCreateInternal() {
     58         if (mFailedMessage == null) {
     59             super.onCreateInternal();
     60             return;
     61         }
     62         setDetailsOverviewRow(
     63                 DetailsContent.createFromFailedScheduledRecording(
     64                         getContext(), getScheduledRecording(), mFailedMessage));
     65     }
     66 
     67     @Override
     68     protected SparseArrayObjectAdapter onCreateActionsAdapter() {
     69         SparseArrayObjectAdapter adapter =
     70                 new SparseArrayObjectAdapter(new ActionPresenterSelector());
     71         Resources res = getResources();
     72         if (!mHideViewSchedule) {
     73             mScheduleAction =
     74                     new Action(
     75                             ACTION_VIEW_SCHEDULE,
     76                             res.getString(R.string.dvr_detail_view_schedule),
     77                             null,
     78                             res.getDrawable(getScheduleIconId()));
     79             adapter.set(ACTION_VIEW_SCHEDULE, mScheduleAction);
     80         }
     81         adapter.set(
     82                 ACTION_CANCEL,
     83                 new Action(
     84                         ACTION_CANCEL,
     85                         res.getString(R.string.dvr_detail_cancel_recording),
     86                         null,
     87                         res.getDrawable(R.drawable.ic_dvr_cancel_32dp)));
     88         return adapter;
     89     }
     90 
     91     @Override
     92     protected OnActionClickedListener onCreateOnActionClickedListener() {
     93         return new OnActionClickedListener() {
     94             @Override
     95             public void onActionClicked(Action action) {
     96                 long actionId = action.getId();
     97                 if (actionId == ACTION_VIEW_SCHEDULE) {
     98                     DvrUiHelper.startSchedulesActivity(getContext(), getRecording());
     99                 } else if (actionId == ACTION_CANCEL) {
    100                     mDvrManager.removeScheduledRecording(getRecording());
    101                     getActivity().finish();
    102                 }
    103             }
    104         };
    105     }
    106 
    107     private int getScheduleIconId() {
    108         if (mDvrManager.isConflicting(getRecording())) {
    109             return R.drawable.ic_warning_white_32dp;
    110         } else {
    111             return R.drawable.ic_schedule_32dp;
    112         }
    113     }
    114 }
    115