aboutsummaryrefslogtreecommitdiff
path: root/src/com/android/tv/dvr/ui/DvrHalfSizedDialogFragment.java
blob: 2b132db8a6f987a5c30eae8bf943c1ce2af7c7fd (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
/*
 * Copyright (C) 2016 The Android Open Source Project
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package com.android.tv.dvr.ui;

import android.app.Activity;
import android.content.Context;
import android.os.Bundle;
import android.support.v17.leanback.app.GuidedStepFragment;
import android.support.v17.leanback.widget.GuidedAction;
import android.support.v17.leanback.widget.GuidanceStylist.Guidance;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;

import com.android.tv.MainActivity;
import com.android.tv.R;
import com.android.tv.dvr.DvrStorageStatusManager;
import com.android.tv.dvr.ui.DvrConflictFragment.DvrChannelWatchConflictFragment;
import com.android.tv.dvr.ui.DvrConflictFragment.DvrProgramConflictFragment;
import com.android.tv.guide.ProgramGuide;

import java.util.List;

public class DvrHalfSizedDialogFragment extends HalfSizedDialogFragment {
    /**
     * Key for input ID.
     * Type: String.
     */
    public static final String KEY_INPUT_ID = "DvrHalfSizedDialogFragment.input_id";
    /**
     * Key for the program.
     * Type: {@link com.android.tv.data.Program}.
     */
    public static final String KEY_PROGRAM = "DvrHalfSizedDialogFragment.program";
    /**
     * Key for the channel ID.
     * Type: long.
     */
    public static final String KEY_CHANNEL_ID = "DvrHalfSizedDialogFragment.channel_id";
    /**
     * Key for the recording start time in millisecond.
     * Type: long.
     */
    public static final String KEY_START_TIME_MS = "DvrHalfSizedDialogFragment.start_time_ms";
    /**
     * Key for the recording end time in millisecond.
     * Type: long.
     */
    public static final String KEY_END_TIME_MS = "DvrHalfSizedDialogFragment.end_time_ms";

    @Override
    public void onAttach(Context context) {
        super.onAttach(context);
        Activity activity = getActivity();
        if (activity instanceof MainActivity) {
            ProgramGuide programGuide =
                    ((MainActivity) activity).getOverlayManager().getProgramGuide();
            if (programGuide != null && programGuide.isActive()) {
                programGuide.cancelHide();
            }
        }
    }

    @Override
    public void onDetach() {
        super.onDetach();
        Activity activity = getActivity();
        if (activity instanceof MainActivity) {
            ProgramGuide programGuide =
                    ((MainActivity) activity).getOverlayManager().getProgramGuide();
            if (programGuide != null && programGuide.isActive()) {
                programGuide.scheduleHide();
            }
        }
    }

    public abstract static class DvrGuidedStepDialogFragment extends DvrHalfSizedDialogFragment {
        private DvrGuidedStepFragment mFragment;

        @Override
        public View onCreateView(LayoutInflater inflater, ViewGroup container,
                Bundle savedInstanceState) {
            View view = super.onCreateView(inflater, container, savedInstanceState);
            mFragment = onCreateGuidedStepFragment();
            mFragment.setArguments(getArguments());
            mFragment.setOnActionClickListener(getOnActionClickListener());
            GuidedStepFragment.add(getChildFragmentManager(),
                    mFragment, R.id.halfsized_dialog_host);
            return view;
        }

        @Override
        public void setOnActionClickListener(OnActionClickListener listener) {
            super.setOnActionClickListener(listener);
            if (mFragment != null) {
                mFragment.setOnActionClickListener(listener);
            }
        }

        protected abstract DvrGuidedStepFragment onCreateGuidedStepFragment();
    }

    /** A dialog fragment for {@link DvrScheduleFragment}. */
    public static class DvrScheduleDialogFragment extends DvrGuidedStepDialogFragment {
        @Override
        protected DvrGuidedStepFragment onCreateGuidedStepFragment() {
            return new DvrScheduleFragment();
        }
    }

    /** A dialog fragment for {@link DvrProgramConflictFragment}. */
    public static class DvrProgramConflictDialogFragment extends DvrGuidedStepDialogFragment {
        @Override
        protected DvrGuidedStepFragment onCreateGuidedStepFragment() {
            return new DvrProgramConflictFragment();
        }
    }

    /** A dialog fragment for {@link DvrChannelWatchConflictFragment}. */
    public static class DvrChannelWatchConflictDialogFragment extends DvrGuidedStepDialogFragment {
        @Override
        protected DvrGuidedStepFragment onCreateGuidedStepFragment() {
            return new DvrChannelWatchConflictFragment();
        }
    }

    /** A dialog fragment for {@link DvrChannelRecordDurationOptionFragment}. */
    public static class DvrChannelRecordDurationOptionDialogFragment
            extends DvrGuidedStepDialogFragment {
        @Override
        protected DvrGuidedStepFragment onCreateGuidedStepFragment() {
            return new DvrChannelRecordDurationOptionFragment();
        }
    }

    /** A dialog fragment for {@link DvrInsufficientSpaceErrorFragment}. */
    public static class DvrInsufficientSpaceErrorDialogFragment
            extends DvrGuidedStepDialogFragment {
        @Override
        protected DvrGuidedStepFragment onCreateGuidedStepFragment() {
            return new DvrInsufficientSpaceErrorFragment();
        }
    }

    /** A dialog fragment for {@link DvrMissingStorageErrorFragment}. */
    public static class DvrMissingStorageErrorDialogFragment
            extends DvrGuidedStepDialogFragment {
        @Override
        protected DvrGuidedStepFragment onCreateGuidedStepFragment() {
            return new DvrMissingStorageErrorFragment();
        }
    }

    /**
     * A dialog fragment to show error message when the current storage is too small to
     * support DVR
     */
    public static class DvrSmallSizedStorageErrorDialogFragment
            extends DvrGuidedStepDialogFragment {
        @Override
        protected DvrGuidedStepFragment onCreateGuidedStepFragment() {
            return new DvrGuidedStepFragment() {
                @Override
                public Guidance onCreateGuidance(Bundle savedInstanceState) {
                    String title = getResources().getString(
                            R.string.dvr_error_small_sized_storage_title);
                    String description = getResources().getString(
                            R.string.dvr_error_small_sized_storage_description,
                            DvrStorageStatusManager.MIN_STORAGE_SIZE_FOR_DVR_IN_BYTES / 1024
                                    / 1024 / 1024);
                    return new Guidance(title, description, null, null);
                }

                @Override
                public void onCreateActions(List<GuidedAction> actions, Bundle savedInstanceState) {
                    Activity activity = getActivity();
                    actions.add(new GuidedAction.Builder(activity)
                            .id(GuidedAction.ACTION_ID_OK)
                            .title(android.R.string.ok)
                            .build());
                }

                @Override
                public void onGuidedActionClicked(GuidedAction action) {
                    dismissDialog();
                }
            };
        }
    }

    /** A dialog fragment for {@link DvrStopRecordingFragment}. */
    public static class DvrStopRecordingDialogFragment extends DvrGuidedStepDialogFragment {
        @Override
        protected DvrGuidedStepFragment onCreateGuidedStepFragment() {
            return new DvrStopRecordingFragment();
        }
    }

    /** A dialog fragment for {@link DvrAlreadyScheduledFragment}. */
    public static class DvrAlreadyScheduledDialogFragment extends DvrGuidedStepDialogFragment {
        @Override
        protected DvrGuidedStepFragment onCreateGuidedStepFragment() {
            return new DvrAlreadyScheduledFragment();
        }
    }

    /** A dialog fragment for {@link DvrAlreadyRecordedFragment}. */
    public static class DvrAlreadyRecordedDialogFragment extends DvrGuidedStepDialogFragment {
        @Override
        protected DvrGuidedStepFragment onCreateGuidedStepFragment() {
            return new DvrAlreadyRecordedFragment();
        }
    }
}