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