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.app.Activity; 20 import android.app.ProgressDialog; 21 import android.os.Bundle; 22 import android.support.annotation.IntDef; 23 import com.android.tv.R; 24 import com.android.tv.Starter; 25 import com.android.tv.data.Program; 26 import com.android.tv.dvr.data.SeriesRecording; 27 import com.android.tv.dvr.provider.EpisodicProgramLoadTask; 28 import com.android.tv.dvr.recorder.SeriesRecordingScheduler; 29 import com.android.tv.dvr.ui.BigArguments; 30 import java.lang.annotation.Retention; 31 import java.lang.annotation.RetentionPolicy; 32 import java.util.Collections; 33 import java.util.List; 34 35 /** Activity to show the list of recording schedules. */ 36 public class DvrSchedulesActivity extends Activity { 37 /** 38 * The key for the type of the schedules which will be listed in the list. The type of the value 39 * should be {@link ScheduleListType}. 40 */ 41 public static final String KEY_SCHEDULES_TYPE = "schedules_type"; 42 43 @Retention(RetentionPolicy.SOURCE) 44 @IntDef({TYPE_FULL_SCHEDULE, TYPE_SERIES_SCHEDULE}) 45 public @interface ScheduleListType {} 46 /** A type which means the activity will display the full scheduled recordings. */ 47 public static final int TYPE_FULL_SCHEDULE = 0; 48 /** 49 * A type which means the activity will display a scheduled recording list of a series 50 * recording. 51 */ 52 public static final int TYPE_SERIES_SCHEDULE = 1; 53 54 @Override 55 public void onCreate(final Bundle savedInstanceState) { 56 Starter.start(this); 57 // Pass null to prevent automatically re-creating fragments 58 super.onCreate(null); 59 setContentView(R.layout.activity_dvr_schedules); 60 int scheduleType = getIntent().getIntExtra(KEY_SCHEDULES_TYPE, TYPE_FULL_SCHEDULE); 61 if (scheduleType == TYPE_FULL_SCHEDULE) { 62 DvrSchedulesFragment schedulesFragment = new DvrSchedulesFragment(); 63 schedulesFragment.setArguments(getIntent().getExtras()); 64 getFragmentManager() 65 .beginTransaction() 66 .add(R.id.fragment_container, schedulesFragment) 67 .commit(); 68 } else if (scheduleType == TYPE_SERIES_SCHEDULE) { 69 if (BigArguments.getArgument( 70 DvrSeriesSchedulesFragment.SERIES_SCHEDULES_KEY_SERIES_PROGRAMS) 71 != null) { 72 // The programs will be passed to the DvrSeriesSchedulesFragment, so don't need 73 // to reset the BigArguments. 74 showDvrSeriesSchedulesFragment(getIntent().getExtras()); 75 } else { 76 final ProgressDialog dialog = 77 ProgressDialog.show( 78 this, 79 null, 80 getString(R.string.dvr_series_progress_message_reading_programs)); 81 SeriesRecording seriesRecording = 82 getIntent() 83 .getExtras() 84 .getParcelable( 85 DvrSeriesSchedulesFragment 86 .SERIES_SCHEDULES_KEY_SERIES_RECORDING); 87 // To get programs faster, hold the update of the series schedules. 88 SeriesRecordingScheduler.getInstance(this).pauseUpdate(); 89 new EpisodicProgramLoadTask(this, Collections.singletonList(seriesRecording)) { 90 @Override 91 protected void onPostExecute(List<Program> programs) { 92 SeriesRecordingScheduler.getInstance(DvrSchedulesActivity.this) 93 .resumeUpdate(); 94 dialog.dismiss(); 95 Bundle args = getIntent().getExtras(); 96 BigArguments.reset(); 97 BigArguments.setArgument( 98 DvrSeriesSchedulesFragment.SERIES_SCHEDULES_KEY_SERIES_PROGRAMS, 99 programs == null ? Collections.EMPTY_LIST : programs); 100 showDvrSeriesSchedulesFragment(args); 101 } 102 }.setLoadCurrentProgram(true) 103 .setLoadDisallowedProgram(true) 104 .setLoadScheduledEpisode(true) 105 .setIgnoreChannelOption(true) 106 .execute(); 107 } 108 } else { 109 finish(); 110 } 111 } 112 113 private void showDvrSeriesSchedulesFragment(Bundle args) { 114 DvrSeriesSchedulesFragment schedulesFragment = new DvrSeriesSchedulesFragment(); 115 schedulesFragment.setArguments(args); 116 getFragmentManager() 117 .beginTransaction() 118 .add(R.id.fragment_container, schedulesFragment) 119 .commit(); 120 } 121 } 122