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