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

package com.ntels.onecable.view.mainmore;

import com.ntels.onecable.R;
import com.ntels.onecable.common.AppConfig;
import com.ntels.onecable.common.Constants;
import com.ntels.onecable.common.c_interface.ListInterface;
import com.ntels.onecable.common.c_interface.OnDataSendToReslut;
import com.ntels.onecable.common.http.HttpSend;
import com.ntels.onecable.common.http.Response;
import com.ntels.onecable.common.util.Dlog;
import com.ntels.onecable.common.util.Util;
import com.ntels.onecable.common.widget.CustomActivity;
import com.ntels.onecable.view.dialog.CustomDialog;
import com.ntels.onecable.view.rules.RulesThingsSelect;

import org.json.JSONObject;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.os.Handler;
import android.os.Message;
import android.support.v4.widget.SwipeRefreshLayout;
import android.support.v7.widget.Toolbar;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.Toast;

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

import butterknife.BindView;
import butterknife.ButterKnife;

/**
 * <pre>
 * 1. ClassName :   HomemodeDetail
 * 2. FileName  :   HomemodeDetail.java
 * 3. Package   :   com.ntels.onecable.view.mainmore
 * 4. Date      :   2017-06-29
 * 5. Author    :   aaron
 * 6. Comment   :   Initialize
 * </pre>
 */
public class HomemodeDetail extends CustomActivity implements View.OnClickListener, CustomDialog.OnMsgAlterToResult, ListInterface {

    private static final int MSG_COM_G_MODES_DETAIL = 1;
    private static final int MSG_COM_P_MODES_RULE = 2;
    private static final int MSG_COM_D_MODES_RULE = 3;

    Handler mComHandler = new Handler(new IncomingHandlerCallBack());
    private Util mUtil = new Util();
    private CustomDialog mCustomDialog = new CustomDialog();
    private AppConfig mAppConfig;
    private Intent mIntent;
    private Activity mActivity;
    private SwipeRefreshLayout mSwipeRefreshLayout;
    private Toolbar mToolbar;
    private ArrayList<HashMap<String, Object>> mActions = new ArrayList<>();
    private ArrayList<HashMap<String, Object>> mConditions = new ArrayList<>();
    private ArrayList<HashMap<String, Object>> mTriggers = new ArrayList<>();
    private boolean mLoading = false;
    private int mType = 0;
    private String mModeId = "";
    private String mModeName = "";
    private String mBasicModeCode = "";
    private boolean mIsRuleDeleteAll = false;
    @BindView(R.id.ivHomemodeIcon) ImageView mHomeModeIcon;

    @Override
    protected void onCreate(Bundle savedInstanceState) {

        super.onCreate(savedInstanceState);
        mActivity = HomemodeDetail.this;
        mAppConfig = (AppConfig) mActivity.getApplicationContext();
        mCustomDialog.setOnMsgAlterToResultEvent(this);
        View viewToLoad = LayoutInflater.from(mActivity).inflate(R.layout.homemode_detail, null);

        this.setContentView(viewToLoad);

        ButterKnife.bind(this);

        if (null != getIntent()) {
            mModeId = getIntent().getStringExtra(Constants.EXTRA_MODE_ID);
            mModeName = getIntent().getStringExtra(Constants.EXTRA_MODE_NAME);
            mBasicModeCode = getIntent().getStringExtra(Constants.EXTRA_BASIC_MODE_CODE);
        }

        setToolbar();
        setDisplay();
    }

    /**
     * 툴바 셋팅.
     */
    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.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_homemode_detail_01, mModeName));
    }

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

        mUtil.getView(mActivity, R.id.llBtn1).setOnClickListener(this);
        mUtil.getView(mActivity, R.id.llBtn2).setOnClickListener(this);
        mUtil.getView(mActivity, R.id.ivFooterAdd).setOnClickListener(this);
        mUtil.getTextView(mActivity, R.id.tvHomemodeText).setText(getString(R.string.layout_homemode_detail_02, mModeName));

        switch (mBasicModeCode) {
            case "MORNING":
                mHomeModeIcon.setImageResource(R.drawable.common_homemode_icon_wakeup_on);
                break;
            case "AWAY":
                mHomeModeIcon.setImageResource(R.drawable.common_homemode_icon_outing_on);
                break;
            case "HOME":
                mHomeModeIcon.setImageResource(R.drawable.common_homemode_icon_homecoming_on);
                break;
            case "NIGHT":
                mHomeModeIcon.setImageResource(R.drawable.common_homemode_icon_sleep_on);
                break;
        }

        mSwipeRefreshLayout = (SwipeRefreshLayout) mActivity.findViewById(R.id.swiperefreshlayout);
        mSwipeRefreshLayout.setColorSchemeResources(android.R.color.holo_red_light, android.R.color.holo_green_light,
                android.R.color.holo_blue_bright, android.R.color.holo_orange_light);
        mSwipeRefreshLayout.setOnRefreshListener(new SwipeRefreshLayout.OnRefreshListener() {
            @Override
            public void onRefresh() {

                if (!mLoading) {
                    mLoading = true;
                    mComHandler.sendMessageDelayed(mComHandler.obtainMessage(MSG_COM_G_MODES_DETAIL), Constants.HANDLER_DELAY_MILLIS);
                }
            }
        });
        setRefresh(true);
        mLoading = true;
        mComHandler.sendMessageDelayed(mComHandler.obtainMessage(MSG_COM_G_MODES_DETAIL), Constants.HANDLER_DELAY_MILLIS);
    }


    /**
     * Actions display.
     */
    @SuppressWarnings("unchecked")
    void setDispActions() {

        Dlog.v("alList_Actions1 = ", mActions.toString());
//        mUtil.getLinearLayout(mActivity, R.id.llAction).setVisibility(View.VISIBLE);
        mUtil.getLinearLayout(mActivity, R.id.llActionBody).removeAllViews();

        if (mActions.size() > 0) {
            for (int row = 0; row < mActions.size(); row++) {
                HashMap<String, Object> tempMap;
                tempMap = mActions.get(row);

                String itemSubTypeCode = mUtil.null2string(tempMap.get(Constants.KEY_ITEM_SUB_TYPE_CODE));

                ArrayList<HashMap<String, Object>> itemSubList;
                if (!mUtil.null2string(tempMap.get(Constants.KEY_ITEM_SUB)).equals("")) {
                    itemSubList = (ArrayList<HashMap<String, Object>>) tempMap.get(Constants.KEY_ITEM_SUB);
                    if (itemSubTypeCode.equals("01")) {
                        for (int row1 = 0; row1 < itemSubList.size(); row1++) {
                            LinearLayout childView = (LinearLayout) View.inflate(
                                    this, R.layout.row_rules_actions_list, null);

                            mUtil.getView(childView, R.id.llRowRoot).setTag(row1);
                            mUtil.getView(childView, R.id.llRowRoot)
                                    .setOnClickListener(new View.OnClickListener() {
                                        int tag = 0;

                                        @Override
                                        public void onClick(View view) {

                                            tag = (int) view.getTag();

                                            for (int row = 0; row < mActions.size(); row++) {
                                                String itemSubTypeCode = mUtil.null2string(
                                                        mActions.get(row).get(Constants.KEY_ITEM_SUB_TYPE_CODE));
                                                if (!mUtil.null2string(
                                                        mActions.get(row).get(Constants.KEY_ITEM_SUB)).equals("")) {
                                                    ArrayList<HashMap<String, Object>> itemSubList =
                                                            (ArrayList<HashMap<String, Object>>)
                                                                    mActions.get(row).get(Constants.KEY_ITEM_SUB);
                                                    if (itemSubTypeCode.equals("01")) {
                                                        String sourceId = mUtil.null2string(
                                                                itemSubList.get(tag).get(Constants.KEY_SOURCE_ID));
                                                        String sourceSubId = mUtil.null2string(
                                                                itemSubList.get(tag).get(Constants.KEY_SOURCE_SUB_ID));
                                                        String availableYn = mUtil.null2string(
                                                                itemSubList.get(tag).get(Constants.KEY_AVAILABLE_YN));

                                                        if (availableYn.equals("N")) {
                                                            mUtil.setShowToast(mActivity, mUtil.getString(mActivity, R.string.MSG900),
                                                                    Toast.LENGTH_SHORT);
                                                            return;
                                                        } else {
                                                            mIntent = new Intent(mActivity, RulesThingsSelect.class);
                                                            mIntent.putExtra(Constants.EXTRA_CALL_TYPE, "2");
                                                            mIntent.putExtra(Constants.EXTRA_TRIGGERS, mTriggers);
                                                            mIntent.putExtra(Constants.EXTRA_ACTIONS, mActions);
                                                            mIntent.putExtra(Constants.EXTRA_CONDITIONS, mConditions);
                                                            mIntent.putExtra(Constants.EXTRA_DEVICE_ID, sourceId);
                                                            mIntent.putExtra(Constants.EXTRA_NODE_ID, sourceSubId);
                                                            mIntent.putExtra(Constants.EXTRA_POSITION, tag);

                                                            mUtil.callActivityForResultNoAnim(mActivity, mIntent,
                                                                    Constants.ACT_RULES_THINGS_SELECT);
                                                        }
                                                        break;
                                                    }
                                                }
                                            }
                                        }
                                    });

                            mUtil.getView(childView, R.id.btnRowDelete).setTag(row1);
                            mUtil.getView(childView, R.id.btnRowDelete)
                                    .setOnClickListener(new View.OnClickListener() {
                                        int tag = 0;

                                        @Override
                                        public void onClick(View view) {

                                            tag = (int) view.getTag();
                                            for (int row = 0; row < mActions.size(); row++) {
                                                String itemSubTypeCode = mUtil.null2string(
                                                        mActions.get(row).get(Constants.KEY_ITEM_SUB_TYPE_CODE));
                                                ArrayList<HashMap<String, Object>> itemSubList;
                                                if (!mUtil.null2string(
                                                        mActions.get(row).get(Constants.KEY_ITEM_SUB)).equals("")) {
                                                    itemSubList = (ArrayList<HashMap<String, Object>>)
                                                            mActions.get(row).get(Constants.KEY_ITEM_SUB);
                                                    if (itemSubTypeCode.equals("01")) {
                                                        itemSubList.remove(tag);
                                                        if (itemSubList.size() == 0) {
                                                            mActions.remove(row);
                                                        }
                                                        break;
                                                    }
                                                }
                                            }
                                            if (mActions.size() <= 0) {
                                                mIsRuleDeleteAll = true;
                                            }
                                            setDispActions();
                                        }
                                    });
                            String sourceName = mUtil.null2string(
                                    itemSubList.get(row1).get(Constants.KEY_SOURCE_NAME));
                            String availableYn = mUtil.null2string(
                                    itemSubList.get(row1).get(Constants.KEY_AVAILABLE_YN));
                            if (availableYn.equals("N")) {
                                mUtil.getTextView(childView, R.id.tvRowTitle)
                                        .setText(mUtil.setSpCenterLine(mActivity, sourceName));
                            } else {
                                mUtil.getTextView(childView, R.id.tvRowTitle).setText(sourceName);
                            }
                            String sourceSubName = mUtil.null2string(
                                    itemSubList.get(row1).get(Constants.KEY_SOURCE_SUB_NAME));
                            mUtil.getTextView(childView, R.id.tvRowBody).setText(sourceSubName);
                            mUtil.getTextView(childView, R.id.tvRowState).setVisibility(View.VISIBLE);
                            String conditionTypeCode = mUtil.null2string(
                                    itemSubList.get(row1).get(Constants.KEY_CONDITION_TYPE_CODE));
                            String conditionTypeCodeName = mUtil.null2string(
                                    itemSubList.get(row1).get(Constants.KEY_CONDITION_TYPE_CODE_NAME));
                            String cmdclsValue = mUtil.null2string(
                                    itemSubList.get(row1).get(Constants.KEY_CMDCLS_VALUE));
                            String cmdclsValueMsg = mUtil.null2string(
                                    itemSubList.get(row1).get(Constants.KEY_CMDCLS_VALUE_MSG));
                            String unit = mUtil.null2string(
                                    itemSubList.get(row1).get(Constants.KEY_UNIT));
                            mUtil.getTextView(childView, R.id.tvRowState)
                                    .setText((cmdclsValueMsg.equals("") ? cmdclsValue : cmdclsValueMsg) + unit + (
                                            conditionTypeCode.equals("01") ? "" : conditionTypeCodeName));
                            String imageFileName = mUtil.null2string(
                                    itemSubList.get(row1).get(Constants.KEY_IMAGE_FILE_NAME));
                            mUtil.setImage(mActivity, imageFileName, mUtil.getImageView(childView, R.id.ivRowIcon));
                            mUtil.getLinearLayout(mActivity, R.id.llActionBody).addView(childView);
                        }
                    }
                }
            }
        }
    }


    /**
     * mSwipeRefreshLayout enable/disable.
     *
     * @param isEnable true or false
     */
    private void setRefresh(boolean isEnable) {

        if (isEnable) {
            mSwipeRefreshLayout.setEnabled(true);
        } else {
            mSwipeRefreshLayout.setEnabled(false);
        }
    }

    @Override
    public void onClick(View view) {

        switch (view.getId()) {
            case R.id.llBtn1:
                if (mIsRuleDeleteAll) {
                    // 기존에 설정되있던 규칙들을 모두 삭제 시 모드 규칙 삭제 API 수행
                    mComHandler.sendMessage(mComHandler.obtainMessage(MSG_COM_D_MODES_RULE));
                } else if (mActions.size() > 0) {
                    // 모드 규칙 등록 및 수정 API 수행
                    mComHandler.sendMessage(mComHandler.obtainMessage(MSG_COM_P_MODES_RULE));
                } else {
                    // 아무 변화 없을 시
                    onBackPressed();
                }
                break;
            case R.id.llBtn2:
                onBackPressed();
                break;
            case R.id.ivFooterAdd:
                mIntent = new Intent(mActivity, RulesThingsSelect.class);
                mIntent.putExtra(Constants.EXTRA_CALL_TYPE, "4");
                mIntent.putExtra(Constants.EXTRA_ACTIONS, mActions);
                mUtil.callActivityForResultNoAnim(mActivity, mIntent, Constants.ACT_RULES_THINGS_SELECT);
                break;
            default:
                break;
        }
    }

    /**
     * 홈모드 상세 조회(해당 홈모드에 걸린 규칙 상세 조회) 요청.
     */
    private void sendGetModesDetail() {

        try {
            HttpSend httpSend;

            httpSend = new HttpSend(mActivity);

            httpSend.setOnDataSendToReslutEvent(new OnDataSendToReslut() {
                @Override
                public void resultResponse(Response result) {

                    resultGetModesDetail(result);
                }
            });
            httpSend.getModesDetail(mModeId);
        } catch (Exception ex) {
            ex.printStackTrace();
        }
    }

    /**
     * 홈모드 상세 조회(해당 홈모드에 걸린 규칙 상세 조회) 요청 결과.
     *
     * @param result 결과 data
     */
    private void resultGetModesDetail(Response result) {

        try {
            if (result.getStatusCode() == 200) {
                ArrayList<HashMap<String, Object>> alList = mUtil.jsonToArrayListMap(result.getContent());
                if (alList.size() > 0) {
                    HashMap<String, Object> hmTempActions = new HashMap<String, Object>();
                    ArrayList<HashMap<String, Object>> itemSubList = new ArrayList<HashMap<String, Object>>();
                    for (int row = 0; row < alList.size(); row++) {
                        HashMap<String, Object> tempMap;
                        tempMap = alList.get(row);
                        //액션이 아예 없는 경우
                        itemSubList.add(tempMap);
                    }
                    hmTempActions.put(Constants.KEY_ITEM_NAME, mUtil.getString(mActivity, R.string.layout_rules_detail_03));
                    hmTempActions.put(Constants.KEY_ITEM_SUB_TYPE_CODE, "01");
                    hmTempActions.put(Constants.KEY_ITEM_SUB, itemSubList);
                    mActions.add(hmTempActions);
                }
                setDispActions();
            } else {
                JSONObject joResult = new JSONObject(result.getContent());
                Dlog.v(joResult.toString());
//                String errorCode = mUtil.null2string(joResult.get(Constants.KEY_ERR_CODE));
                String resultCode = mUtil.null2string(joResult.get(Constants.KEY_RESULT_CODE));
//                String errorMsg = mUtil.null2string(joResult.get(Constants.KEY_ERR_MSG));
                String resultMsg = mUtil.null2string(joResult.get(Constants.KEY_RESULT_MSG));

                switch (resultCode) {
                    case "401":
                        mCustomDialog.msgAlert(mActivity, Constants.MSG998, resultMsg);
                        break;
                    case "401-106":
                        mCustomDialog.msgAlert(mActivity, Constants.MSG997, resultMsg);
                        break;
                    default:
                        mCustomDialog.msgAlert(mActivity, Constants.MSG000, resultMsg);
                        break;
                }
            }
        } catch (Exception ex) {
            ex.printStackTrace();
            mCustomDialog.msgAlert(mActivity, Constants.MSG807);
        }
        mLoading = false;
        mSwipeRefreshLayout.setRefreshing(false);
    }

    /**
     * 모드의 규칙 등록/수정 요청.
     */
    private void sendPostModeRule() {

        try {
            HttpSend httpSend;

            httpSend = new HttpSend(mActivity);

            httpSend.setOnDataSendToReslutEvent(new OnDataSendToReslut() {
                @Override
                public void resultResponse(Response result) {

                    resultPostModeRule(result);
                }
            });

            HashMap<String, Object> hmTemp;
            Dlog.v("actions = " + mActions.size());
            hmTemp = mActions.get(0);

            Dlog.v(mUtil.MapToJson(hmTemp));

            httpSend.postModeRule(mModeId, mUtil.MapToJson(hmTemp));
        } catch (Exception ex) {
            ex.printStackTrace();
        }
    }

    /**
     * {@link #sendPostModeRule()} 요청 결과.
     *
     * @param response 결과 data
     */
    private void resultPostModeRule(Response response) {

        try {
            if (response.getStatusCode() == 200) {
//                JSONObject joResult = new JSONObject(response.getContent());

//                String homegrpRuleId = mUtil.null2string(joResult.get(Constants.KEY_HOMEGRP_RULE_ID));
                mIntent = new Intent();
//                intent.putExtra(Constants.EXTRA_MODE_DEL_YN, modeDelYn);
//                intent.putExtra(Constants.EXTRA_HOMEGRP_RULE_ID, homegrpRuleId);
                mActivity.setResult(RESULT_OK, mIntent);
                finish();
            } else {
                JSONObject joResult = new JSONObject(response.getContent());
                Dlog.v(joResult.toString());
//                String errorCode = mUtil.null2string(joResult.get(Constants.KEY_ERR_CODE));
                String resultCode = mUtil.null2string(joResult.get(Constants.KEY_RESULT_CODE));
//                String errorMsg = mUtil.null2string(joResult.get(Constants.KEY_ERR_MSG));
                String resultMsg = mUtil.null2string(joResult.get(Constants.KEY_RESULT_MSG));

                if (resultCode.equals("401")) {
                    mCustomDialog.msgAlert(mActivity, Constants.MSG998, resultMsg);
                } else if (resultCode.equals("401-106")) {
                    mCustomDialog.msgAlert(mActivity, Constants.MSG997, resultMsg);
                } else {
                    mCustomDialog.msgAlert(mActivity, Constants.MSG000, resultMsg);
                }
            }
        } catch (Exception ex) {
            ex.printStackTrace();
            mCustomDialog.msgAlert(mActivity, Constants.MSG807);
        }
    }

    /**
     * 홈그룹 모드의 규칙 삭제 요청.
     */
    private void sendDeleteModeRule() {

        try {
            HttpSend httpSend;

            httpSend = new HttpSend(mActivity);

            httpSend.setOnDataSendToReslutEvent(new OnDataSendToReslut() {
                @Override
                public void resultResponse(Response result) {

                    resultDeleteModeRule(result);
                }
            });

            httpSend.deleteModeRule(mModeId);
        } catch (Exception ex) {
            ex.printStackTrace();
        }
    }

    /**
     * {@link #sendDeleteModeRule()} 요청 결과.
     *
     * @param response 결과 data
     */
    private void resultDeleteModeRule(Response response) {

        try {
            if (response.getStatusCode() == 200) {
                mIntent = new Intent();
                mActivity.setResult(RESULT_OK, mIntent);
                finish();
            } else {
                JSONObject joResult = new JSONObject(response.getContent());
                Dlog.v(joResult.toString());
//                String errorCode = mUtil.null2string(joResult.get(Constants.KEY_ERR_CODE));
                String resultCode = mUtil.null2string(joResult.get(Constants.KEY_RESULT_CODE));
//                String errorMsg = mUtil.null2string(joResult.get(Constants.KEY_ERR_MSG));
                String resultMsg = mUtil.null2string(joResult.get(Constants.KEY_RESULT_MSG));

                if (resultCode.equals("401")) {
                    mCustomDialog.msgAlert(mActivity, Constants.MSG998, resultMsg);
                } else if (resultCode.equals("401-106")) {
                    mCustomDialog.msgAlert(mActivity, Constants.MSG997, resultMsg);
                } else {
                    mCustomDialog.msgAlert(mActivity, Constants.MSG000, resultMsg);
                }
            }
        } catch (Exception ex) {
            ex.printStackTrace();
            mCustomDialog.msgAlert(mActivity, Constants.MSG807);
        }
    }

    @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) {
                    mComHandler.sendMessageDelayed(mComHandler.obtainMessage(mType), Constants.HANDLER_DELAY_MILLIS);
                } else {
                    mActivity.onBackPressed();
                }
                break;
            default:
                break;
        }
    }

    @Override
    public void onBackPressed() {

        mIntent = new Intent();
        mActivity.setResult(RESULT_CANCELED, mIntent);
        finish();
    }

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

        super.onActivityResult(requestCode, resultCode, data);
        if (resultCode == RESULT_OK) {
            switch (requestCode) {
                case Constants.ACT_RULES_THINGS_SELECT:
                    mActions = (ArrayList<HashMap<String, Object>>) data.getSerializableExtra(Constants.EXTRA_ACTIONS);
                    mIsRuleDeleteAll = false;
                    setDispActions();
                    break;
                default:
                    break;
            }
        } else {
            if (mAppConfig.getGoErr()) {
                mActivity.setResult(RESULT_CANCELED, new Intent());
                finish();
            }
        }
    }

    @Override
    public void onListReload() {
    }

    @Override
    public void onLogout() {
    }

    @Override
    public void onCallAction(int callType, int position) {

        if (callType == 0) {

        }
    }

    class IncomingHandlerCallBack implements Handler.Callback {

        @Override
        public boolean handleMessage(Message msg) {

            mType = msg.what;
            switch (msg.what) {
                case MSG_COM_G_MODES_DETAIL:
                    sendGetModesDetail();
                    break;
                case MSG_COM_P_MODES_RULE:
                    sendPostModeRule();
                    break;
                case MSG_COM_D_MODES_RULE:
                    sendDeleteModeRule();
                    break;

                default:
                    break;
            }
            return true;
        }
    }
}