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