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