• 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.Intent;
22 import android.os.Bundle;
23 import android.support.v17.leanback.widget.GuidanceStylist.Guidance;
24 import android.support.v17.leanback.widget.GuidedAction;
25 import com.android.tv.R;
26 import com.android.tv.TvSingletons;
27 import com.android.tv.common.SoftPreconditions;
28 import com.android.tv.dvr.ui.browse.DvrBrowseActivity;
29 import java.util.ArrayList;
30 import java.util.List;
31 
32 public class DvrInsufficientSpaceErrorFragment extends DvrGuidedStepFragment {
33     /** Key for the failed scheduled recordings information. */
34     public static final String FAILED_SCHEDULED_RECORDING_INFOS =
35             "failed_scheduled_recording_infos";
36 
37     private static final String TAG = "DvrInsufficientSpaceErrorFragment";
38 
39     private static final int ACTION_VIEW_RECENT_RECORDINGS = 1;
40 
41     private ArrayList<String> mFailedScheduledRecordingInfos;
42 
43     @Override
onAttach(Context context)44     public void onAttach(Context context) {
45         super.onAttach(context);
46         Bundle args = getArguments();
47         if (args != null) {
48             mFailedScheduledRecordingInfos =
49                     args.getStringArrayList(FAILED_SCHEDULED_RECORDING_INFOS);
50         }
51         SoftPreconditions.checkState(
52                 mFailedScheduledRecordingInfos != null && !mFailedScheduledRecordingInfos.isEmpty(),
53                 TAG,
54                 "failed scheduled recording is null");
55     }
56 
57     @Override
onCreateGuidance(Bundle savedInstanceState)58     public Guidance onCreateGuidance(Bundle savedInstanceState) {
59         String title;
60         String description;
61         int failedScheduledRecordingSize = mFailedScheduledRecordingInfos.size();
62         if (failedScheduledRecordingSize == 1) {
63             title =
64                     getString(
65                             R.string.dvr_error_insufficient_space_title_one_recording,
66                             mFailedScheduledRecordingInfos.get(0));
67             description =
68                     getString(
69                             R.string.dvr_error_insufficient_space_description_one_recording,
70                             mFailedScheduledRecordingInfos.get(0));
71         } else if (failedScheduledRecordingSize == 2) {
72             title =
73                     getString(
74                             R.string.dvr_error_insufficient_space_title_two_recordings,
75                             mFailedScheduledRecordingInfos.get(0),
76                             mFailedScheduledRecordingInfos.get(1));
77             description =
78                     getString(
79                             R.string.dvr_error_insufficient_space_description_two_recordings,
80                             mFailedScheduledRecordingInfos.get(0),
81                             mFailedScheduledRecordingInfos.get(1));
82         } else {
83             title =
84                     getString(
85                             R.string.dvr_error_insufficient_space_title_three_or_more_recordings,
86                             mFailedScheduledRecordingInfos.get(0),
87                             mFailedScheduledRecordingInfos.get(1),
88                             mFailedScheduledRecordingInfos.get(2));
89             description =
90                     getString(
91                             R.string
92                                     .dvr_error_insufficient_space_description_three_or_more_recordings,
93                             mFailedScheduledRecordingInfos.get(0),
94                             mFailedScheduledRecordingInfos.get(1),
95                             mFailedScheduledRecordingInfos.get(2));
96         }
97         return new Guidance(title, description, null, null);
98     }
99 
100     @Override
onCreateActions(List<GuidedAction> actions, Bundle savedInstanceState)101     public void onCreateActions(List<GuidedAction> actions, Bundle savedInstanceState) {
102         Activity activity = getActivity();
103         actions.add(
104                 new GuidedAction.Builder(activity).clickAction(GuidedAction.ACTION_ID_OK).build());
105         if (TvSingletons.getSingletons(getContext()).getDvrManager().hasValidItems()) {
106             actions.add(
107                     new GuidedAction.Builder(activity)
108                             .id(ACTION_VIEW_RECENT_RECORDINGS)
109                             .title(
110                                     getResources()
111                                             .getString(
112                                                     R.string
113                                                             .dvr_error_insufficient_space_action_view_recent_recordings))
114                             .build());
115         }
116     }
117 
118     @Override
onTrackedGuidedActionClicked(GuidedAction action)119     public void onTrackedGuidedActionClicked(GuidedAction action) {
120         if (action.getId() == ACTION_VIEW_RECENT_RECORDINGS) {
121             Intent intent = new Intent(getActivity(), DvrBrowseActivity.class);
122             getActivity().startActivity(intent);
123         }
124         dismissDialog();
125     }
126 
127     @Override
getTrackerPrefix()128     public String getTrackerPrefix() {
129         return "DvrInsufficientSpaceErrorFragment";
130     }
131 
132     @Override
getTrackerLabelForGuidedAction(GuidedAction action)133     public String getTrackerLabelForGuidedAction(GuidedAction action) {
134         long actionId = action.getId();
135         if (actionId == ACTION_VIEW_RECENT_RECORDINGS) {
136             return "view-recent";
137         } else {
138             return super.getTrackerLabelForGuidedAction(action);
139         }
140     }
141 }
142