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.list; 18 19 import android.os.Bundle; 20 import androidx.leanback.widget.ClassPresenterSelector; 21 import com.android.tv.R; 22 import com.android.tv.dvr.data.ScheduledRecording; 23 import com.android.tv.dvr.ui.list.SchedulesHeaderRowPresenter.DateHeaderRowPresenter; 24 25 /** A fragment to show the list of schedule recordings. */ 26 public class DvrSchedulesFragment extends BaseDvrSchedulesFragment { 27 @Override onCreate(Bundle savedInstanceState)28 public void onCreate(Bundle savedInstanceState) { 29 super.onCreate(savedInstanceState); 30 if (getRowsAdapter().size() == 0) { 31 showEmptyMessage(R.string.dvr_schedules_empty_state); 32 } 33 } 34 35 @Override onCreateHeaderRowPresenter()36 public SchedulesHeaderRowPresenter onCreateHeaderRowPresenter() { 37 return new DateHeaderRowPresenter(getContext()); 38 } 39 40 @Override onCreateRowPresenter()41 public ScheduleRowPresenter onCreateRowPresenter() { 42 return new ScheduleRowPresenter(getContext()); 43 } 44 45 @Override onCreateRowsAdapter(ClassPresenterSelector presenterSelector)46 public ScheduleRowAdapter onCreateRowsAdapter(ClassPresenterSelector presenterSelector) { 47 return new ScheduleRowAdapter(getContext(), presenterSelector); 48 } 49 50 @Override onScheduledRecordingAdded(ScheduledRecording... scheduledRecordings)51 public void onScheduledRecordingAdded(ScheduledRecording... scheduledRecordings) { 52 super.onScheduledRecordingAdded(scheduledRecordings); 53 if (getRowsAdapter().size() > 0) { 54 hideEmptyMessage(); 55 } 56 } 57 58 @Override onScheduledRecordingRemoved(ScheduledRecording... scheduledRecordings)59 public void onScheduledRecordingRemoved(ScheduledRecording... scheduledRecordings) { 60 super.onScheduledRecordingRemoved(scheduledRecordings); 61 if (getRowsAdapter().size() == 0) { 62 showEmptyMessage(R.string.dvr_schedules_empty_state); 63 } 64 } 65 66 @Override getFirstItemPosition()67 protected int getFirstItemPosition() { 68 Bundle args = getArguments(); 69 ScheduledRecording recording = null; 70 if (args != null) { 71 recording = args.getParcelable(SCHEDULES_KEY_SCHEDULED_RECORDING); 72 } 73 final int selectedPostion = 74 getRowsAdapter().indexOf(getRowsAdapter().findRowByScheduledRecording(recording)); 75 if (selectedPostion != -1) { 76 return selectedPostion; 77 } 78 return super.getFirstItemPosition(); 79 } 80 } 81