• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2018 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.os.Bundle;
21 import android.support.v17.leanback.widget.GuidanceStylist;
22 import android.support.v17.leanback.widget.GuidedAction;
23 import com.android.tv.TvSingletons;
24 import com.android.tv.data.Program;
25 import com.android.tv.dvr.data.ScheduledRecording;
26 import com.android.tv.util.Utils;
27 import java.util.List;
28 
29 /**
30  * A fragment which shows the formation of a program.
31  */
32 public class DvrFutureProgramInfoFragment extends DvrGuidedStepFragment {
33     private static final long ACTION_ID_VIEW_SCHEDULE = 1;
34     private ScheduledRecording mScheduledRecording;
35     private Program mProgram;
36 
37     @Override
onCreateGuidance(Bundle savedInstanceState)38     public GuidanceStylist.Guidance onCreateGuidance(Bundle savedInstanceState) {
39         long startTime = mProgram.getStartTimeUtcMillis();
40         // TODO(b/71717923): use R.string when the strings are finalized
41         StringBuilder description = new StringBuilder()
42                 .append("This program will start at ")
43                 .append(Utils.getDurationString(getContext(), startTime, startTime, false));
44         if (mScheduledRecording != null) {
45             description.append("\nThis program has been scheduled for recording.");
46         }
47         return new GuidanceStylist.Guidance(
48                 mProgram.getTitle(), description.toString(), null, null);
49     }
50 
51     @Override
onCreateActions(List<GuidedAction> actions, Bundle savedInstanceState)52     public void onCreateActions(List<GuidedAction> actions, Bundle savedInstanceState) {
53         Activity activity = getActivity();
54         mProgram = getArguments().getParcelable(DvrHalfSizedDialogFragment.KEY_PROGRAM);
55         mScheduledRecording =
56                 TvSingletons.getSingletons(getContext())
57                         .getDvrDataManager()
58                         .getScheduledRecordingForProgramId(mProgram.getId());
59         actions.add(
60                 new GuidedAction.Builder(activity)
61                         .id(GuidedAction.ACTION_ID_OK)
62                         .title(android.R.string.ok)
63                         .build());
64         if (mScheduledRecording != null) {
65             actions.add(
66                     new GuidedAction.Builder(activity)
67                             .id(ACTION_ID_VIEW_SCHEDULE)
68                             .title("View schedules")
69                             .build());
70         }
71 
72     }
73 
74     @Override
onTrackedGuidedActionClicked(GuidedAction action)75     public void onTrackedGuidedActionClicked(GuidedAction action) {
76         if (action.getId() == ACTION_ID_VIEW_SCHEDULE) {
77             DvrUiHelper.startSchedulesActivity(getContext(), mScheduledRecording);
78             return;
79         }
80         dismissDialog();
81     }
82 
83     @Override
getTrackerPrefix()84     public String getTrackerPrefix() {
85         return "DvrFutureProgramInfoFragment";
86     }
87 }
88