package com.ntels.kneet.v3.view.things;

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

import com.ntels.kneet.v3.R;
import com.ntels.kneet.v3.common.Constants;
import com.ntels.kneet.v3.common.util.Util;
import com.ntels.kneet.v3.view.dialog.CustomDialog;

/**
 * 1. ClassName :   Things_Homehub_Guide
 * 2. FileName  :   Things_Homehub_Guide.java
 * 3. Package   :   com.ntels.kneet.v3.view.things
 * 4. Date      :   2016-07-16
 * 5. Author    :   aaron
 * 6. Comment   :   Initialize
 */
public class Things_Homehub_Guide extends FragmentActivity implements View.OnClickListener,
                                                                      CustomDialog.OnMsgAlterToResult {

    private Activity            act;
    private Util                util = new Util();
    private Toolbar             toolbar;
    private CustomDialog        customDialog = new CustomDialog();
    private Intent              intent;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        act = Things_Homehub_Guide.this;
        customDialog.setOnMsgAlterToResultEvent(this);

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

        setToolbar();
        viewInit();

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

    private void viewInit() {
        util.getView(act, R.id.llBtn1).setOnClickListener(this);
    }

    private void setToolbar() {
        toolbar = (Toolbar) act.findViewById(R.id.toolbar);
        util.setKeyboardHide(act, toolbar);
        util.getTextView(toolbar, R.id.tvToolbarTitle1).setVisibility(View.VISIBLE);
        util.getTextView(toolbar, R.id.tvToolbarTitle2).setVisibility(View.GONE);
        util.getTextView(toolbar, R.id.tvToolbarTitleDivider).setVisibility(View.GONE);
        util.getTextView(toolbar, R.id.tvToolbarTitle3).setVisibility(View.GONE);
        util.getTextView(toolbar, R.id.tvToolbarTitle4).setVisibility(View.GONE);
        util.getTextView(toolbar, R.id.btnToolbarDel).setVisibility(View.GONE);
        util.getTextView(toolbar, R.id.btnToolbarClose).setVisibility(View.GONE);
        util.getTextView(toolbar, R.id.btnToolbarMore).setVisibility(View.GONE);

        util.getTextView(toolbar, R.id.tvToolbarTitle1).setText(util.getString(act, R.string.layout_homehub_01));
    }

    /**
     * Called when a view has been clicked.
     *
     * @param v The view that was clicked.
     */
    @Override
    public void onClick(View v) {
        switch (v.getId()) {
            case R.id.llBtn1:
                customDialog.MsgAlert(act, Constants.MSG905);
                break;
        }
    }

    @Override
    public void resultCustomDialogResponse(int iMsgID, int iBtnResult) {
        switch (iMsgID) {
            case Constants.MSG905:
                if ( iBtnResult == 1 ) {
                    setResult(RESULT_CANCELED, intent);
                    finish();
                }
                break;
        }
    }

    @Override
    public void onBackPressed() {

        customDialog.MsgAlert(act, Constants.MSG905);
    }

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

        intent = new Intent();
        if ( resultCode == RESULT_OK ) {
            switch (requestCode) {
                case Constants.ACT_THINGS_HOMEHUB_REGISTER:

                    intent = new Intent();
                    setResult(RESULT_OK, intent);
                    finish();

                    break;
            }
        } else {
            switch (requestCode) {
                case Constants.ACT_THINGS_HOMEHUB_REGISTER:
                    setResult(RESULT_CANCELED, intent);
                    finish();
                    break;
            }
        }
    }
}
