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