• 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.content.Context;
21 import android.content.DialogInterface;
22 import android.os.Bundle;
23 import android.support.v17.leanback.app.GuidedStepFragment;
24 import android.view.LayoutInflater;
25 import android.view.View;
26 import android.view.ViewGroup;
27 
28 import com.android.tv.MainActivity;
29 import com.android.tv.R;
30 import com.android.tv.dialog.HalfSizedDialogFragment;
31 import com.android.tv.dvr.ui.DvrConflictFragment.DvrChannelWatchConflictFragment;
32 import com.android.tv.dvr.ui.DvrConflictFragment.DvrProgramConflictFragment;
33 import com.android.tv.guide.ProgramGuide;
34 import com.android.tv.ui.DetailsActivity;
35 
36 public class DvrHalfSizedDialogFragment extends HalfSizedDialogFragment {
37     /** Key for input ID. Type: String. */
38     public static final String KEY_INPUT_ID = "DvrHalfSizedDialogFragment.input_id";
39     /** Key for the program. Type: {@link com.android.tv.data.Program}. */
40     public static final String KEY_PROGRAM = "DvrHalfSizedDialogFragment.program";
41     /** Key for the channel ID. Type: long. */
42     public static final String KEY_CHANNEL_ID = "DvrHalfSizedDialogFragment.channel_id";
43     /** Key for the recording start time in millisecond. Type: long. */
44     public static final String KEY_START_TIME_MS = "DvrHalfSizedDialogFragment.start_time_ms";
45     /** Key for the recording end time in millisecond. Type: long. */
46     public static final String KEY_END_TIME_MS = "DvrHalfSizedDialogFragment.end_time_ms";
47 
48     @Override
onAttach(Context context)49     public void onAttach(Context context) {
50         super.onAttach(context);
51         Activity activity = getActivity();
52         if (activity instanceof MainActivity) {
53             ProgramGuide programGuide =
54                     ((MainActivity) activity).getOverlayManager().getProgramGuide();
55             if (programGuide != null && programGuide.isActive()) {
56                 programGuide.cancelHide();
57             }
58         }
59     }
60 
61     @Override
onDetach()62     public void onDetach() {
63         super.onDetach();
64         Activity activity = getActivity();
65         if (activity instanceof MainActivity) {
66             ProgramGuide programGuide =
67                     ((MainActivity) activity).getOverlayManager().getProgramGuide();
68             if (programGuide != null && programGuide.isActive()) {
69                 programGuide.scheduleHide();
70             }
71         }
72     }
73 
74     public abstract static class DvrGuidedStepDialogFragment extends DvrHalfSizedDialogFragment {
75         private DvrGuidedStepFragment mFragment;
76 
77         @Override
onCreateView( LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState)78         public View onCreateView(
79                 LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
80             View view = super.onCreateView(inflater, container, savedInstanceState);
81             mFragment = onCreateGuidedStepFragment();
82             mFragment.setArguments(getArguments());
83             mFragment.setOnActionClickListener(getOnActionClickListener());
84             GuidedStepFragment.add(
85                     getChildFragmentManager(), mFragment, R.id.halfsized_dialog_host);
86             return view;
87         }
88 
89         @Override
setOnActionClickListener(OnActionClickListener listener)90         public void setOnActionClickListener(OnActionClickListener listener) {
91             super.setOnActionClickListener(listener);
92             if (mFragment != null) {
93                 mFragment.setOnActionClickListener(listener);
94             }
95         }
96 
onCreateGuidedStepFragment()97         protected abstract DvrGuidedStepFragment onCreateGuidedStepFragment();
98     }
99 
100     /** A dialog fragment for {@link DvrScheduleFragment}. */
101     public static class DvrScheduleDialogFragment extends DvrGuidedStepDialogFragment {
102         @Override
onCreateGuidedStepFragment()103         protected DvrGuidedStepFragment onCreateGuidedStepFragment() {
104             return new DvrScheduleFragment();
105         }
106     }
107 
108     /** A dialog fragment for {@link DvrProgramConflictFragment}. */
109     public static class DvrProgramConflictDialogFragment extends DvrGuidedStepDialogFragment {
110         @Override
onCreateGuidedStepFragment()111         protected DvrGuidedStepFragment onCreateGuidedStepFragment() {
112             return new DvrProgramConflictFragment();
113         }
114     }
115 
116     /** A dialog fragment for {@link DvrChannelWatchConflictFragment}. */
117     public static class DvrChannelWatchConflictDialogFragment extends DvrGuidedStepDialogFragment {
118         @Override
onCreateGuidedStepFragment()119         protected DvrGuidedStepFragment onCreateGuidedStepFragment() {
120             return new DvrChannelWatchConflictFragment();
121         }
122     }
123 
124     /** A dialog fragment for {@link DvrChannelRecordDurationOptionFragment}. */
125     public static class DvrChannelRecordDurationOptionDialogFragment
126             extends DvrGuidedStepDialogFragment {
127         @Override
onCreateGuidedStepFragment()128         protected DvrGuidedStepFragment onCreateGuidedStepFragment() {
129             return new DvrChannelRecordDurationOptionFragment();
130         }
131     }
132 
133     /** A dialog fragment for {@link DvrInsufficientSpaceErrorFragment}. */
134     public static class DvrInsufficientSpaceErrorDialogFragment
135             extends DvrGuidedStepDialogFragment {
136         @Override
onCreateGuidedStepFragment()137         protected DvrGuidedStepFragment onCreateGuidedStepFragment() {
138             return new DvrInsufficientSpaceErrorFragment();
139         }
140     }
141 
142     /** A dialog fragment for {@link DvrMissingStorageErrorFragment}. */
143     public static class DvrMissingStorageErrorDialogFragment extends DvrGuidedStepDialogFragment {
144         @Override
onCreateGuidedStepFragment()145         protected DvrGuidedStepFragment onCreateGuidedStepFragment() {
146             return new DvrMissingStorageErrorFragment();
147         }
148     }
149 
150     /** A dialog fragment to show error message when there is no enough free space to record. */
151     public static class DvrNoFreeSpaceErrorDialogFragment extends DvrGuidedStepDialogFragment {
152         @Override
onCreateGuidedStepFragment()153         protected DvrGuidedStepFragment onCreateGuidedStepFragment() {
154             return new DvrGuidedStepFragment.DvrNoFreeSpaceErrorFragment();
155         }
156     }
157 
158     /**
159      * A dialog fragment to show error message when the current storage is too small to support DVR
160      */
161     public static class DvrSmallSizedStorageErrorDialogFragment
162             extends DvrGuidedStepDialogFragment {
163         @Override
onCreateGuidedStepFragment()164         protected DvrGuidedStepFragment onCreateGuidedStepFragment() {
165             return new DvrGuidedStepFragment.DvrSmallSizedStorageErrorFragment();
166         }
167     }
168 
169     /** A dialog fragment for {@link DvrStopRecordingFragment}. */
170     public static class DvrStopRecordingDialogFragment extends DvrGuidedStepDialogFragment {
171         @Override
onCreateGuidedStepFragment()172         protected DvrGuidedStepFragment onCreateGuidedStepFragment() {
173             return new DvrStopRecordingFragment();
174         }
175     }
176 
177     /** A dialog fragment for {@link DvrAlreadyScheduledFragment}. */
178     public static class DvrAlreadyScheduledDialogFragment extends DvrGuidedStepDialogFragment {
179         @Override
onCreateGuidedStepFragment()180         protected DvrGuidedStepFragment onCreateGuidedStepFragment() {
181             return new DvrAlreadyScheduledFragment();
182         }
183     }
184 
185     /** A dialog fragment for {@link DvrAlreadyRecordedFragment}. */
186     public static class DvrAlreadyRecordedDialogFragment extends DvrGuidedStepDialogFragment {
187         @Override
onCreateGuidedStepFragment()188         protected DvrGuidedStepFragment onCreateGuidedStepFragment() {
189             return new DvrAlreadyRecordedFragment();
190         }
191     }
192 
193     /** A dialog fragment for {@link DvrWriteStoragePermissionRationaleFragment}. */
194     public static class DvrWriteStoragePermissionRationaleDialogFragment
195             extends DvrGuidedStepDialogFragment {
196         @Override
onCreateGuidedStepFragment()197         protected DvrWriteStoragePermissionRationaleFragment onCreateGuidedStepFragment() {
198             return new DvrWriteStoragePermissionRationaleFragment();
199         }
200 
201         @Override
onDismiss(DialogInterface dialog)202         public void onDismiss(DialogInterface dialog) {
203             Activity activity = getActivity();
204             if (activity instanceof DetailsActivity) {
205                 activity.requestPermissions(
206                         new String[] {"android.permission.WRITE_EXTERNAL_STORAGE"},
207                         DetailsActivity.REQUEST_DELETE);
208             } else if (activity instanceof DvrSeriesDeletionActivity) {
209                 activity.requestPermissions(
210                         new String[] {"android.permission.WRITE_EXTERNAL_STORAGE"},
211                         DvrSeriesDeletionActivity.REQUEST_DELETE);
212             }
213             super.onDismiss(dialog);
214         }
215     }
216 }
217