/*
 * 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 android.widget.Toast;

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_Input 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 = "";

    @Override public void onCreate(Bundle savedInstanceState) {

        super.onCreate(savedInstanceState);

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

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

        util.getLinearLayout(act, R.id.llBtn1).setOnClickListener(this);
        util.getLinearLayout(act, R.id.llBtn2).setOnClickListener(this);
    }

    @Override public void onConfigurationChanged(Configuration newConfig) {

        super.onConfigurationChanged(newConfig);
    }

    @Override public void onClick(View v) {

        switch (v.getId()) {
            case R.id.llBtn1:
                String sActivation_Code = util.getEditTextVal(act, R.id.edtsActivation_Code);
                String sPass = util.getEditTextVal(act, R.id.edtPass);

                if ( sActivation_Code.equals("") ) {
                    util.setShowToast(act, util.getString(act, R.string.layout_things_homehub_02) + util.getString(act, R.string.MSG901), Toast.LENGTH_SHORT);
                    return;
                }

                if ( sPass.equals("")  ) {
                    util.setShowToast(act, util.getString(act, R.string.layout_things_homehub_03) + util.getString(act, R.string.MSG901), Toast.LENGTH_SHORT);
                    return;
                }

                if ( sActivation_Code.contains("|*_AC_*|") ) {
                    customDialog.MsgAlert(act,Constants.MSG861, "");
                    return;
                }

                intent = new Intent();
                intent.putExtra(Constants.EXTRA_ACTIVATION_CODE, sActivation_Code);
                intent.putExtra(Constants.EXTRA_PASSWORD, sPass);
                act.setResult(RESULT_OK, intent);
                finish();
                break;
            case R.id.llBtn2:
                onBackPressed();
                break;
            default:
                break;
        }
    }

    @Override public void onBackPressed() {

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

    @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;
        }
    }
}
