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

package com.ntels.onecable.view.things;

import com.ntels.onecable.R;
import com.ntels.onecable.common.Constants;
import com.ntels.onecable.common.util.Util;
import com.ntels.onecable.common.widget.CustomActionBarActivity;

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

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

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

    /*공통*/
    private Activity mActivity;
    private Util mUtil = new Util();
    private boolean mIsReloadFinish = false;
    private String mDeviceId = "";

    @Override
    public void onCreate(Bundle savedInstanceState) {

        super.onCreate(savedInstanceState);

        mActivity = ThingsDeviceAdd.this;

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

        if (getIntent() != null) {
            mDeviceId = getIntent().getStringExtra(Constants.EXTRA_DEVICE_ID);
        }

        setToolbar();
        setDisp();
    }

    @Override
    public void onClick(View view) {
        Intent intent;
        switch (view.getId()) {
            case R.id.llBtn1:
                onBackPressed();
                break;
            case R.id.llRowDevice1:
                intent = new Intent(mActivity, ThingsDeviceAdd1st.class);
                intent.putExtra(Constants.EXTRA_DEVICE_NAME, mUtil.getString(mActivity, R.string.layout_things_device_add_02));
                intent.putExtra(Constants.EXTRA_COMPANY_NAME, mUtil.getString(mActivity, R.string.layout_things_device_add_03));
                intent.putExtra(Constants.EXTRA_DEVICE_DESC, mUtil.getString(mActivity, R.string.layout_things_device_add_del_01));
                intent.putExtra(Constants.EXTRA_DEVICE_DESC1, mUtil.getString(mActivity, R.string.layout_things_device_add_del_04));
                intent.putExtra(Constants.EXTRA_DEVICE_IMAGE, R.drawable.img_things_product_addimg_01_smartgasvalve);
                intent.putExtra(Constants.EXTRA_DEVICE_IMAGE1, R.drawable.img_things_product_addimg_01_smartgasvalve_wait);
                intent.putExtra(Constants.EXTRA_DEVICE_ID, mDeviceId);
                mUtil.callActivityForResultNoAnim(mActivity, intent, Constants.ACT_THINGS_DEVICE_ADD_01);
                break;
            case R.id.llRowDevice2:
                intent = new Intent(mActivity, ThingsDeviceAdd1st.class);
                intent.putExtra(Constants.EXTRA_DEVICE_NAME, mUtil.getString(mActivity, R.string.layout_things_device_add_04));
                intent.putExtra(Constants.EXTRA_COMPANY_NAME, mUtil.getString(mActivity, R.string.layout_things_device_add_05));
                intent.putExtra(Constants.EXTRA_DEVICE_DESC, mUtil.getString(mActivity, R.string.layout_things_device_add_del_02));
                intent.putExtra(Constants.EXTRA_DEVICE_DESC1, mUtil.getString(mActivity, R.string.layout_things_device_add_del_05));
                intent.putExtra(Constants.EXTRA_DEVICE_IMAGE, R.drawable.img_things_product_addimg_02_iotplug);
                intent.putExtra(Constants.EXTRA_DEVICE_IMAGE1, R.drawable.img_things_product_addimg_02_iotplug_wait);
                intent.putExtra(Constants.EXTRA_DEVICE_ID, mDeviceId);
                mUtil.callActivityForResultNoAnim(mActivity, intent, Constants.ACT_THINGS_DEVICE_ADD_01);
                break;
            case R.id.llRowDevice3:
                intent = new Intent(mActivity, ThingsDeviceAdd1st.class);
                intent.putExtra(Constants.EXTRA_DEVICE_NAME, mUtil.getString(mActivity, R.string.layout_things_device_add_06));
                intent.putExtra(Constants.EXTRA_COMPANY_NAME, mUtil.getString(mActivity, R.string.layout_things_device_add_07));
                intent.putExtra(Constants.EXTRA_DEVICE_DESC, mUtil.getString(mActivity, R.string.layout_things_device_add_del_02));
                intent.putExtra(Constants.EXTRA_DEVICE_DESC1, mUtil.getString(mActivity, R.string.layout_things_device_add_del_06));
                intent.putExtra(Constants.EXTRA_DEVICE_IMAGE, R.drawable.img_things_product_addimg_03_smartplug);
                intent.putExtra(Constants.EXTRA_DEVICE_IMAGE1, R.drawable.img_things_product_addimg_03_smartplug_wait);
                intent.putExtra(Constants.EXTRA_DEVICE_ID, mDeviceId);
                mUtil.callActivityForResultNoAnim(mActivity, intent, Constants.ACT_THINGS_DEVICE_ADD_01);
                break;
            case R.id.llRowDevice4:
                intent = new Intent(mActivity, ThingsDeviceAdd1st.class);
                intent.putExtra(Constants.EXTRA_DEVICE_NAME, mUtil.getString(mActivity, R.string.layout_things_device_add_08));
                intent.putExtra(Constants.EXTRA_COMPANY_NAME, mUtil.getString(mActivity, R.string.layout_things_device_add_09));
                intent.putExtra(Constants.EXTRA_DEVICE_DESC, mUtil.getString(mActivity, R.string.layout_things_device_add_del_03));
                intent.putExtra(Constants.EXTRA_DEVICE_DESC1, mUtil.getString(mActivity, R.string.layout_things_device_add_del_07));
                intent.putExtra(Constants.EXTRA_DEVICE_IMAGE, R.drawable.img_things_product_addimg_04_mutisensor_motion);
                intent.putExtra(Constants.EXTRA_DEVICE_IMAGE1, R.drawable.img_things_product_addimg_04_mutisensor_motion_wait);
                intent.putExtra(Constants.EXTRA_DEVICE_ID, mDeviceId);
                mUtil.callActivityForResultNoAnim(mActivity, intent, Constants.ACT_THINGS_DEVICE_ADD_01);
                break;
            case R.id.llRowDevice5:
                intent = new Intent(mActivity, ThingsDeviceAdd1st.class);
                intent.putExtra(Constants.EXTRA_DEVICE_NAME, mUtil.getString(mActivity, R.string.layout_things_device_add_10));
                intent.putExtra(Constants.EXTRA_COMPANY_NAME, mUtil.getString(mActivity, R.string.layout_things_device_add_11));
                intent.putExtra(Constants.EXTRA_DEVICE_DESC, mUtil.getString(mActivity, R.string.layout_things_device_add_del_03));
                intent.putExtra(Constants.EXTRA_DEVICE_DESC1, mUtil.getString(mActivity, R.string.layout_things_device_add_del_09));
                intent.putExtra(Constants.EXTRA_DEVICE_IMAGE, R.drawable.img_things_product_addimg_05_shocksensor);
                intent.putExtra(Constants.EXTRA_DEVICE_IMAGE1, R.drawable.img_things_product_addimg_05_shocksensor_wait);
                intent.putExtra(Constants.EXTRA_DEVICE_ID, mDeviceId);
                mUtil.callActivityForResultNoAnim(mActivity, intent, Constants.ACT_THINGS_DEVICE_ADD_01);
                break;
            case R.id.llRowDevice6:
                intent = new Intent(mActivity, ThingsDeviceAdd1st.class);
                intent.putExtra(Constants.EXTRA_DEVICE_NAME, mUtil.getString(mActivity, R.string.layout_things_device_add_12));
                intent.putExtra(Constants.EXTRA_COMPANY_NAME, mUtil.getString(mActivity, R.string.layout_things_device_add_11));
                intent.putExtra(Constants.EXTRA_DEVICE_DESC, mUtil.getString(mActivity, R.string.layout_things_device_add_del_03));
                intent.putExtra(Constants.EXTRA_DEVICE_DESC1, mUtil.getString(mActivity, R.string.layout_things_device_add_del_11));
                intent.putExtra(Constants.EXTRA_DEVICE_IMAGE, R.drawable.img_things_product_addimg_06_mutisensor_door);
                intent.putExtra(Constants.EXTRA_DEVICE_IMAGE1, R.drawable.img_things_product_addimg_06_mutisensor_door_wait);
                intent.putExtra(Constants.EXTRA_DEVICE_ID, mDeviceId);
                mUtil.callActivityForResultNoAnim(mActivity, intent, Constants.ACT_THINGS_DEVICE_ADD_01);
                break;
            case R.id.llRowDevice7:
                intent = new Intent(mActivity, ThingsDeviceAdd1st.class);
                intent.putExtra(Constants.EXTRA_DEVICE_NAME, mUtil.getString(mActivity, R.string.layout_things_device_add_13));
                intent.putExtra(Constants.EXTRA_COMPANY_NAME, mUtil.getString(mActivity, R.string.layout_things_device_add_14));
                intent.putExtra(Constants.EXTRA_DEVICE_DESC, mUtil.getString(mActivity, R.string.layout_things_device_add_del_13));
                intent.putExtra(Constants.EXTRA_DEVICE_DESC1, mUtil.getString(mActivity, R.string.layout_things_device_add_del_14));
                intent.putExtra(Constants.EXTRA_DEVICE_IMAGE, R.drawable.img_things_product_addimg_00_zwave);
                intent.putExtra(Constants.EXTRA_DEVICE_IMAGE1, R.drawable.img_things_product_addimg_00_zwave_wait);
                intent.putExtra(Constants.EXTRA_DEVICE_ID, mDeviceId);
                mUtil.callActivityForResultNoAnim(mActivity, intent, Constants.ACT_THINGS_DEVICE_ADD_01);
                break;
            case R.id.llRowDevice8:
                // Netatmo에서 access_camera permission을 받아야 사용 가능.
                intent = new Intent(mActivity, ThingsDeviceAdd1st.class);
                intent.putExtra(Constants.EXTRA_DEVICE_NAME, mUtil.getString(mActivity, R.string.layout_things_device_add_16));
                intent.putExtra(Constants.EXTRA_COMPANY_NAME, mUtil.getString(mActivity, R.string.layout_things_device_add_17));
                intent.putExtra(Constants.EXTRA_DEVICE_DESC, mUtil.getString(mActivity, R.string.layout_things_device_add_del_16));
                intent.putExtra(Constants.EXTRA_DEVICE_IMAGE, R.drawable.img_things_product_addimg_07_netatmo);
                intent.putExtra(Constants.EXTRA_DEVICE_IMAGE1, R.drawable.img_things_product_addimg_07_netatmo);
                intent.putExtra(Constants.EXTRA_DEVICE_ID, mDeviceId);
                mUtil.callActivityForResultNoAnim(mActivity, intent, Constants.ACT_THINGS_DEVICE_ADD_01);
                break;
            default:
                break;
        }
    }

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

        super.onActivityResult(requestCode, resultCode, data);
        if (resultCode == RESULT_OK) {
            switch (requestCode) {
                case Constants.ACT_THINGS_DEVICE_ADD_01:
                    mActivity.setResult(RESULT_OK, data);
                    finish();
                    break;
                default:
                    break;
            }
        }
    }

    @Override
    public void onBackPressed() {

        Intent intent = new Intent();
        intent.putExtra(Constants.EXTRA_RELOAD_FLAG, mIsReloadFinish);
        this.setResult(RESULT_CANCELED, intent);
        finish();
    }

    /**
     * 툴바 셋팅.
     */
    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.btnToolbarDel).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_things_device_add_01));
    }

    /**
     * UI display.
     */
    private void setDisp() {

        mUtil.getView(mActivity, R.id.llRowDevice1).setOnClickListener(this);
        mUtil.getView(mActivity, R.id.llRowDevice2).setOnClickListener(this);
        mUtil.getView(mActivity, R.id.llRowDevice3).setOnClickListener(this);
        mUtil.getView(mActivity, R.id.llRowDevice4).setOnClickListener(this);
        mUtil.getView(mActivity, R.id.llRowDevice5).setOnClickListener(this);
        mUtil.getView(mActivity, R.id.llRowDevice6).setOnClickListener(this);
        mUtil.getView(mActivity, R.id.llRowDevice7).setOnClickListener(this);
        mUtil.getView(mActivity, R.id.llRowDevice8).setOnClickListener(this);
        mUtil.getView(mActivity, R.id.llBtn1).setOnClickListener(this);
    }

}
