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

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


import com.ntels.onecable.admin.R;
import com.ntels.onecable.admin.common.AppConfig;
import com.ntels.onecable.admin.common.Constants;
import com.ntels.onecable.admin.common.util.Dlog;
import com.ntels.onecable.admin.common.util.Util;
import com.ntels.onecable.admin.common.widget.CustomActivity;
import com.ntels.onecable.admin.view.dialog.CustomDialog;

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.ProgressBar;

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

    private static final String TAG = HomehubRegisterSucess.class.getSimpleName();
    ProgressBar mProgressBar;
    /*통신 관련*/
    private int mType = 0;
    /*공통*/
    private Activity mActivity;
    private AppConfig mAppConfig;
    private Intent mIntent;
    private Util mUtil = new Util();
    private CustomDialog mCustomDialog = new CustomDialog();
    private String mSerialNumber = "";


    @Override
    public void onCreate(Bundle savedInstanceState) {

        super.onCreate(savedInstanceState);

        mActivity = HomehubRegisterSucess.this;
        mAppConfig = (AppConfig) mActivity.getApplicationContext();
        mCustomDialog.setOnMsgAlterToResultEvent(this);


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

        Intent intent = getIntent();
        mSerialNumber = intent.getStringExtra(Constants.EXTRA_DEVICE_SERIAL_NUMBER);

        setToolbar();
        setDisp();

    }

    /**
     * UI display.
     */
    private void setDisp() {
//        mUtil.getView(mActivity, R.id.llPageRoot).setVisibility(View.VISIBLE);
        mUtil.getTextView(mActivity, R.id.tvBtn1).setText(mUtil.getString(mActivity, R.string.layout_cancel));
        mUtil.getTextView(mActivity, R.id.tvErrSN).setText(mUtil.getString(mActivity, R.string.layout_install_homehub_register_err_03, mSerialNumber));
        mUtil.getView(mActivity, R.id.llBtn1).setOnClickListener(this);
//        mUtil.getView(mActivity, R.id.btnRetry).setOnClickListener(this);
    }


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

        mUtil.getTextView(toolbar, R.id.tvToolbarTitle1).setText(mUtil.getString(mActivity, R.string.layout_install_homehub_register_err_02));
    }


    @Override
    public void onConfigurationChanged(Configuration newConfig) {

        super.onConfigurationChanged(newConfig);
    }

    @Override
    public void onBackPressed() {
        onBackPressedSucess();
        return;
    }
    @Override
    public void onClick(View view) {

        switch (view.getId()) {
            case R.id.llBtn1:
                onBackPressedSucess();
                break;
            default:
                break;
        }
    }

    @Override
    public void resultCustomDialogResponse(int msgId, int btnResult) {

        switch (msgId) {
//            case Constants.MSG998:
//                mUtil.callApp_Start(mActivity, "LOGOUT");
//                break;
//            case Constants.MSG997:
//                mUtil.callApp_Start(mActivity, "HOME_RELOAD");
//                break;
//            case Constants.MSG807:
//                if (btnResult == 1) {
//                    comHandler.sendMessageDelayed(comHandler.obtainMessage(mType), Constants.HANDLER_DELAY_MILLIS);
//                }
//                break;
            default:
                break;
        }
    }

    private void onBackPressedRetry(){
        mIntent = new Intent();
        mIntent.putExtra(Constants.EXTRA_RETRAY_FLAG, true);
        mActivity.setResult(RESULT_CANCELED, mIntent);
        finish();
    }


    private void onBackPressedFlowEnd(){
        mIntent = new Intent();
        mIntent.putExtra(Constants.EXTRA_FLOW_END_FLAG, true);
        mActivity.setResult(RESULT_CANCELED, mIntent);
        finish();
    }

    private void onBackPressedEnd(){
        mIntent = new Intent();
        mIntent.putExtra(Constants.EXTRA_END_FLAG, true);
        mActivity.setResult(RESULT_CANCELED, mIntent);
        finish();
    }
    private void onBackPressedSucess(){
        mIntent = new Intent();
        mIntent.putExtra(Constants.EXTRA_RELOAD_FLAG, true);
        mActivity.setResult(RESULT_OK, mIntent);
        finish();
    }


    @Override
    public void onResume() {

        super.onResume();

    }

    @Override
    protected void onDestroy() {

        super.onDestroy();
        Dlog.v("onDestroy()");
    }

    @Override
    protected void onPause() {
        super.onPause();
    }

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

        super.onActivityResult(requestCode, resultCode, data);

        if (resultCode == mActivity.RESULT_OK) {
            switch (requestCode) {
                case Constants.ACT_THINGS_NAME_CHANGE:
                    mActivity.setResult(RESULT_OK, data);
                    finish();
                    break;
                default:
                    break;
            }
        } else {
            switch (requestCode) {
                case Constants.ACT_THINGS_NAME_CHANGE:
//                    mActivity.setResult(RESULT_OK, data);
//                    finish();
                    break;
                default:
                    break;
            }
        }
    }


}

