package com.ntels.onecable.admin.view.things;

import com.ntels.onecable.admin.R;
import com.ntels.onecable.admin.common.Constants;
import com.ntels.onecable.admin.common.util.Util;
import com.ntels.onecable.admin.view.dialog.CustomDialog;
import com.tsengvn.typekit.TypekitContextWrapper;

import android.app.Activity;
import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.support.v4.app.FragmentActivity;
import android.support.v4.view.ViewPager;
import android.support.v7.widget.Toolbar;
import android.view.LayoutInflater;
import android.view.View;

/**
 * <pre>
 * 1. ClassName :   ThingsHomehubGuide
 * 2. FileName  :   ThingsHomehubGuide.java
 * 3. Package   :   com.ntels.onecable.admin.view.things
 * 4. Date      :   2016-11-24
 * 5. Author    :   aaron
 * 6. Comment   :   Initialize
 * </pre>
 */
public class ThingsHomehubGuide extends FragmentActivity implements View.OnClickListener,
        CustomDialog.OnMsgAlterToResult {

    private Activity mActivity;
    private Util mUtil = new Util();
    private Toolbar mToolbar;
    private CustomDialog mCustomDialog = new CustomDialog();
    private Intent mIntent;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        mActivity = ThingsHomehubGuide.this;
        mCustomDialog.setOnMsgAlterToResultEvent(this);

        View viewToLoad = LayoutInflater.from(mActivity).inflate(R.layout.things_homehub_guide, null);
        this.setContentView(viewToLoad);

        setToolbar();
        viewInit();

        ViewPager viewPager = (ViewPager) findViewById(R.id.vpHomehubGuide);
        ThingsHomehubGuideAdapter viewPagerAdapter = new ThingsHomehubGuideAdapter(getSupportFragmentManager());
        viewPager.setAdapter(viewPagerAdapter);
    }

    @Override
    protected void attachBaseContext(Context newBase) {

        super.attachBaseContext(TypekitContextWrapper.wrap(newBase));
    }

    @Override
    public void onClick(View view) {
        switch (view.getId()) {
            case R.id.llBtn1:
                mCustomDialog.msgAlert(mActivity, Constants.MSG905);
                break;
            default:
                break;
        }
    }

    @Override
    public void resultCustomDialogResponse(int msgId, int btnResult) {
        switch (msgId) {
            case Constants.MSG905:
                if (btnResult == 1) {
                    setResult(RESULT_CANCELED, mIntent);
                    finish();
                }
                break;
            default:
                break;
        }
    }

    @Override
    public void onBackPressed() {

        mCustomDialog.msgAlert(mActivity, Constants.MSG905);
    }

    @Override
    public void onActivityResult(int requestCode, int resultCode, Intent data) {
        super.onActivityResult(requestCode, resultCode, data);

        mIntent = new Intent();
        if (resultCode == RESULT_OK) {
            switch (requestCode) {
                case Constants.ACT_THINGS_HOMEHUB_REGISTER:
                    mIntent = new Intent();
                    setResult(RESULT_OK, mIntent);
                    finish();
                    break;
                default:
                    break;
            }
        } else {
            switch (requestCode) {
                case Constants.ACT_THINGS_HOMEHUB_REGISTER:
                    setResult(RESULT_CANCELED, mIntent);
                    finish();
                    break;
                default:
                    break;
            }
        }
    }

    /**
     * View initialize.
     */
    private void viewInit() {
        mUtil.getView(mActivity, R.id.llBtn1).setOnClickListener(this);
    }

    /**
     * 툴바 셋팅.
     */
    private void setToolbar() {
        mToolbar = (Toolbar) mActivity.findViewById(R.id.toolbar);
        mUtil.setKeyboardHide(mActivity, mToolbar);
        mUtil.getTextView(mToolbar, R.id.tvToolbarTitle1).setVisibility(View.VISIBLE);
        mUtil.getTextView(mToolbar, R.id.tvToolbarTitle2).setVisibility(View.GONE);
        mUtil.getTextView(mToolbar, R.id.tvToolbarTitleDivider).setVisibility(View.GONE);
        mUtil.getTextView(mToolbar, R.id.tvToolbarTitle3).setVisibility(View.GONE);
        mUtil.getTextView(mToolbar, R.id.tvToolbarTitle4).setVisibility(View.GONE);
        mUtil.getTextView(mToolbar, R.id.btnToolbarClose).setVisibility(View.GONE);
        mUtil.getTextView(mToolbar, R.id.btnToolbarMore).setVisibility(View.GONE);

        mUtil.getTextView(mToolbar, R.id.tvToolbarTitle1).setText(mUtil.getString(mActivity, R.string.layout_install_homehub_register_01));
    }

}
