1/*
2 * Copyright (C) 2015 The Android Open Source Project
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except
5 * in compliance with the License. You may obtain a copy of the License at
6 *
7 * http://www.apache.org/licenses/LICENSE-2.0
8 *
9 * Unless required by applicable law or agreed to in writing, software distributed under the License
10 * is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express
11 * or implied. See the License for the specific language governing permissions and limitations under
12 * the License.
13 */
14
15package android.support.v17.leanback.supportleanbackshowcase.app.wizard;
16
17import android.os.Bundle;
18import android.support.annotation.NonNull;
19import android.support.v17.leanback.app.GuidedStepFragment;
20import android.support.v17.leanback.supportleanbackshowcase.R;
21import android.support.v17.leanback.widget.GuidanceStylist;
22import android.support.v17.leanback.widget.GuidedAction;
23
24import java.util.List;
25
26/**
27 * The first screen of the rental wizard. Gives the user the choice between renting the movie in SD
28 * or HD quality.
29 */
30public class WizardExample1stStepFragment extends WizardExampleBaseStepFragment {
31
32    private static final int ACTION_ID_BUY_HD = 1;
33    private static final int ACTION_ID_BUY_SD = ACTION_ID_BUY_HD + 1;
34
35    @NonNull
36    @Override
37    public GuidanceStylist.Guidance onCreateGuidance(Bundle savedInstanceState) {
38        GuidanceStylist.Guidance guidance = new GuidanceStylist.Guidance(mMovie.getTitle(),
39                getString(R.string.wizard_example_choose_rent_options),
40                mMovie.getBreadcrump(), null);
41        return guidance;
42    }
43
44    @Override
45    public void onCreateActions(@NonNull List<GuidedAction> actions, Bundle savedInstanceState) {
46        GuidedAction action = new GuidedAction.Builder(getActivity())
47                .id(ACTION_ID_BUY_HD)
48                .title(R.string.wizard_example_rent_hd)
49                .editable(false)
50                .description(mMovie.getPriceHd() + " " +
51                        getString(R.string.wizard_example_watch_hd))
52                .build();
53        actions.add(action);
54        action = new GuidedAction.Builder(getActivity())
55                .id(ACTION_ID_BUY_SD)
56                .title(getString(R.string.wizard_example_rent_sd))
57                .editable(false)
58                .description(mMovie.getPriceSd() + " " +
59                        getString(R.string.wizard_example_watch_sd))
60                .build();
61        actions.add(action);
62    }
63
64    @Override
65    public void onGuidedActionClicked(GuidedAction action) {
66        boolean rentHd = ACTION_ID_BUY_HD == action.getId();
67        GuidedStepFragment fragment = WizardExample2ndStepFragment.build(rentHd, this);
68        add(getFragmentManager(), fragment);
69    }
70}
71