/*
 * Copyright (c) 2015. Ncomz. All Rights Reserved
 */

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

import android.app.Activity;
import android.content.Intent;
import android.content.res.Configuration;
import android.os.Bundle;
import android.support.v7.widget.Toolbar;
import android.view.LayoutInflater;
import android.view.View;

import com.ntels.kneet.v3.common.AppConfig;
import com.ntels.kneet.v3.common.Constants;
import com.ntels.kneet.v3.common.c_interface.Main_Interface;
import com.ntels.kneet.v3.common.util.Util;
import com.ntels.kneet.v3.common.widget.CustomActivity;
import com.ntels.kneet.v3.R;
import com.ntels.kneet.v3.view.dialog.CustomDialog;

import java.util.ArrayList;
import java.util.HashMap;

public class Things_Homehub_Guide_Intro extends CustomActivity implements View.OnClickListener,
                                                                          CustomDialog.OnMsgAlterToResult {

    /*툴바 관련*/
    private Toolbar toolbar;

    /*통신 관련*/
    private ArrayList<HashMap<String, Object>> alTotalList = new ArrayList<HashMap<String, Object>>();
    private int                                iType       = 0;
    //    private static final int                                MSG_COM_P_DEVICES_PARTNER_DEVICE_OWNERSHIP = 1;

    /*공통*/
    private Activity       act;
    private AppConfig      appConfig;
    private Main_Interface mCallback;
    private Intent         intent;
    private Util   util      = new Util();
    private CustomDialog customDialog      = new CustomDialog();
    private String sCallType = "";

    /**
     * <PRE>
     * 1. MethodName: onCreate
     * 2. ClassName :
     * 3. Comment   : onCreate
     * 4. Developer : 최진오
     * 5. Created   : 2015. 10.
     * </PRE>
     */
    @Override public void onCreate(Bundle savedInstanceState) {

        super.onCreate(savedInstanceState);

        act = Things_Homehub_Guide_Intro.this;
        appConfig = (AppConfig) act.getApplicationContext();
        customDialog.setOnMsgAlterToResultEvent(this);

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

        if ( savedInstanceState != null ) {
            // sTitle =
            // savedInstanceState.getString(Constants.EXTRA_SPINNER_TITLE);
            // aList1 =
            // savedInstanceState.getStringArrayList(Constants.EXTRA_SPINNER_LIST1);
            // aList2 =
            // savedInstanceState.getStringArrayList(Constants.EXTRA_SPINNER_LIST2);
            // // 0: 세로 한개 선택, 1: 가로 한개선택
            // iType = savedInstanceState.getInt(Constants.EXTRA_SPINNER_TYPE,
            // 0);
            // sBtn1 =
            // savedInstanceState.getString(Constants.EXTRA_SPINNER_BTN1);
            // sBtn2 =
            // savedInstanceState.getString(Constants.EXTRA_SPINNER_BTN2);
            // iPosition =
            // savedInstanceState.getInt(Constants.EXTRA_SPINNER_POSITION, 0);
        } else {
            Intent intent = getIntent();
            sCallType = intent.getStringExtra(Constants.EXTRA_CALL_TYPE);
        }

        util.getView(act, R.id.llBtn1).setOnClickListener(this);
        util.getView(act, R.id.btnExit).setOnClickListener(this);
        util.getView(act, R.id.llPageRoot).setVisibility(View.VISIBLE);
        setDisp();
    }

    private void setDisp() {

        //        util.getTextView(act, R.id.edtName).setText(appConfig.getNickname());
    }

    @Override public void onConfigurationChanged(Configuration newConfig) {

        super.onConfigurationChanged(newConfig);
    }

    @Override public void onClick(View v) {

        switch (v.getId()) {
            case R.id.llBtn1:
                util.getView(act, R.id.llPageRoot).setVisibility(View.INVISIBLE);
                Intent intent = new Intent(act, Things_Homehub_Guide_01.class);
                util.callActivityForResultNoAnim(act, intent, Constants.ACT_THINGS_HOMEHUB_GUIDE_01);
                break;
            case R.id.btnExit:
                onBackPressed();
                break;
            default:
                break;
        }
    }
    /**
     * <PRE>
     * 1. MethodName: onBackPressed
     * 2. ClassName :
     * 3. Comment   : 뒤로가기 버튼
     * 4. Developer : 최진오
     * 5. Created   : 2015. 10.
     * </PRE>
     */
    @Override public void onBackPressed() {

        intent = new Intent();
        act.setResult(RESULT_CANCELED, intent);
        finish();
        return;
    }

    /**
     * <PRE>
     * 1. MethodName: onResume
     * 2. ClassName :
     * 3. Comment   : onResume
     * 4. Developer : 최진오
     * 5. Created   : 2015. 10.
     * </PRE>
     */
    @Override public void onResume() {

        super.onResume();

        // if (!GreenBilllab.getIntro()) {
        // if (Main.reLoginCheck()) {
        // onBackPressed();
        // }
        // }
    }

    @Override public void resultCustomDialogResponse(int iMsgID, int iBtnResult) {

        switch (iMsgID) {

//            case Constants.MSG998:
//                util.callApp_Start(act, "LOGOUT");
//                break;
//            case Constants.MSG997:
//                util.callApp_Start(act, "HOME_RELOAD");
//                break;
//            case Constants.MSG807:
//                if ( iBtnResult == 1 ) {
//                    //                    ComHandler.sendMessageDelayed(ComHandler.obtainMessage(iType), 10);
//                }
//                break;
            default:
                break;
        }
    }
    @Override public void onActivityResult(int requestCode, int resultCode, Intent data) {

        super.onActivityResult(requestCode, resultCode, data);

        if ( resultCode == act.RESULT_OK ) {
            switch (requestCode) {
                case Constants.ACT_THINGS_HOMEHUB_GUIDE_01:

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

                    break;
            }
        } else {
            switch (requestCode) {
                case Constants.ACT_THINGS_HOMEHUB_GUIDE_01:
                    Boolean bFlow_End_Flag = data.getBooleanExtra(Constants.EXTRA_FLOW_END_FLAG, false);
                    if ( bFlow_End_Flag ) {
                        act.setResult(RESULT_CANCELED, data);
                        finish();
                    } else {
                        util.getView(act, R.id.llPageRoot).setVisibility(View.VISIBLE);
                    }
                    break;
            }
            // if (appConfig.getGoErr()) {
            // act.setResult(act.RESULT_CANCELED, new Intent());
            // finish();
            // }
        }
    }
}
