/*
 * Copyright (C) 2015 The Android Open Source Project
 *
 * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except
 * in compliance with the License. You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software distributed under the License
 * is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express
 * or implied. See the License for the specific language governing permissions and limitations under
 * the License.
 */

package android.support.v17.leanback.supportleanbackshowcase;

import android.os.Bundle;
import android.os.Handler;
import android.support.annotation.NonNull;
import android.support.v17.leanback.app.GuidedStepFragment;
import android.support.v17.leanback.widget.GuidanceStylist;
import android.support.v17.leanback.widget.GuidedAction;
import android.support.v17.leanback.widget.GuidedActionsStylist;

import java.util.List;

/**
 * TODO: JavaDoc
 */
public class WizardExample3rdStepFragment extends WizardExampleBaseStepFragment {

    private static final int ACTION_ID_PROCESSING = 1;
    private final Handler mFakeHttpHandler = new Handler();

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        getWizardActivity().setStep(3);
    }

    @Override
    public void onStart() {
        super.onStart();

        // Fake Http call by creating some sort of delay.
        mFakeHttpHandler.postDelayed(fakeHttpRequestRunnable, 4000L);
    }

    @Override
    public GuidedActionsStylist onCreateActionsStylist() {
        GuidedActionsStylist stylist = new GuidedActionsStylist() {
            @Override
            public int onProvideItemLayoutId() {
                return R.layout.wizard_progress_action_item;
            }

            @Override
            public int onProvideLayoutId() {
                return R.layout.wizard_progress_action_container;
            }
        };
        return stylist;
    }

    @Override
    public void onStop() {
        super.onStop();

        // Make sure to cancel the execution of the Runnable in case the fragment is stopped.
        mFakeHttpHandler.removeCallbacks(fakeHttpRequestRunnable);
    }

    @NonNull
    @Override
    public GuidanceStylist.Guidance onCreateGuidance(Bundle savedInstanceState) {
        GuidanceStylist.Guidance guidance = new GuidanceStylist.Guidance(mMovie.getTitle(),
                "Just a second...",
                mMovie.getBreadcrump(), null);
        return guidance;
    }

    @Override
    public void onCreateActions(@NonNull List<GuidedAction> actions, Bundle savedInstanceState) {
        GuidedAction action = new GuidedAction.Builder()
                .id(ACTION_ID_PROCESSING)
                .title(getString(R.string.wizard_example_processing))
                .infoOnly(true)
                .build();
        actions.add(action);
    }

    private final Runnable fakeHttpRequestRunnable = new Runnable() {
        @Override
        public void run() {
            GuidedStepFragment fragment = new WizardExample4thStepFragment();
            fragment.setArguments(getArguments());
            add(getFragmentManager(), fragment);
        }
    };

}
