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.Intent;
21 import android.os.Bundle;
22 import android.support.v17.leanback.widget.GuidanceStylist.Guidance;
23 import android.support.v17.leanback.widget.GuidedAction;
24 
25 import com.android.tv.R;
26 import com.android.tv.TvApplication;
27 import com.android.tv.dvr.DvrDataManager;
28 
29 import java.util.List;
30 
31 public class DvrInsufficientSpaceErrorFragment extends DvrGuidedStepFragment {
32     private static final int ACTION_DONE = 1;
33     private static final int ACTION_OPEN_DVR = 2;
34 
35     @Override
onCreateGuidance(Bundle savedInstanceState)36     public Guidance onCreateGuidance(Bundle savedInstanceState) {
37         String title = getResources().getString(R.string.dvr_error_insufficient_space_title);
38         String description = getResources()
39                 .getString(R.string.dvr_error_insufficient_space_description);
40         return new Guidance(title, description, null, null);
41     }
42 
43     @Override
onCreateActions(List<GuidedAction> actions, Bundle savedInstanceState)44     public void onCreateActions(List<GuidedAction> actions, Bundle savedInstanceState) {
45         Activity activity = getActivity();
46         actions.add(new GuidedAction.Builder(activity)
47                 .id(ACTION_DONE)
48                 .title(getResources().getString(R.string.dvr_action_error_done))
49                 .build());
50         DvrDataManager dvrDataManager = TvApplication.getSingletons(getContext())
51                 .getDvrDataManager();
52         if (!(dvrDataManager.getRecordedPrograms().isEmpty()
53                 && dvrDataManager.getStartedRecordings().isEmpty()
54                 && dvrDataManager.getNonStartedScheduledRecordings().isEmpty()
55                 && dvrDataManager.getSeriesRecordings().isEmpty())) {
56                     actions.add(new GuidedAction.Builder(activity)
57                             .id(ACTION_OPEN_DVR)
58                             .title(getResources().getString(R.string.dvr_action_error_open_dvr))
59                             .build());
60         }
61     }
62 
63     @Override
onGuidedActionClicked(GuidedAction action)64     public void onGuidedActionClicked(GuidedAction action) {
65         if (action.getId() == ACTION_OPEN_DVR) {
66             Intent intent = new Intent(getActivity(), DvrActivity.class);
67             getActivity().startActivity(intent);
68         }
69         dismissDialog();
70     }
71 }
72