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