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

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

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.c_interface.MainInterface;
import com.ntels.onecable.admin.common.c_interface.OnDataSendToReslut;
import com.ntels.onecable.admin.common.http.HttpSend;
import com.ntels.onecable.admin.common.http.Response;
import com.ntels.onecable.admin.common.util.Dlog;
import com.ntels.onecable.admin.common.util.Util;
import com.ntels.onecable.admin.common.websocket.WebSocketService;
import com.ntels.onecable.admin.view.dialog.CustomDialog;
import com.ntels.onecable.admin.view.dialog.DialogSpinner;

import org.json.JSONException;
import org.json.JSONObject;

import android.app.Activity;
import android.content.Intent;
import android.content.res.Configuration;
import android.os.Bundle;
import android.os.Handler;
import android.os.Message;
import android.support.v4.app.Fragment;
import android.support.v4.widget.SwipeRefreshLayout;
import android.text.Editable;
import android.text.TextWatcher;
import android.view.KeyEvent;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.view.inputmethod.EditorInfo;
import android.widget.TextView;

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

import butterknife.ButterKnife;
import butterknife.OnClick;

import static com.ntels.onecable.admin.R.id.btnCustomerConnect;
import static com.ntels.onecable.admin.R.id.btnMasterInvatation;
import static com.ntels.onecable.admin.common.Constants.EXTRA_ERROR_CODE;

/**
 * <pre>
 * 1. ClassName :   FragmentCustomer
 * 2. FileName  :   FragmentCustomer.java
 * 3. Package   :   com.ntels.onecable.admin.view.mainmore
 * 4. Date      :   2016-12-01
 * 5. Author    :   aaron
 * 6. Comment   :   Initialize
 * </pre>
 */
public class FragmentCustomer extends Fragment implements CustomDialog.OnMsgAlterToResult {

    private static final String TAG = FragmentCustomer.class.getSimpleName();

    private static final int MSG_COM_G_MSOMEMBER = 1;
    private static final int MSG_COM_P_MODE_CHANGE = 2;
    private static final int MSG_COM_P_HOMEGRP_PROFILE_IMAGE = 3;
    ArrayList<HashMap<String, Object>> mModeList = new ArrayList<>();
    Handler mComHandler = new Handler(new IncomingHandlerCallBack());
    private AppConfig mAppConfig;
    private Util mUtil = new Util();
    private CustomDialog mCustomDialog = new CustomDialog();
    private Intent mIntent;
    private Activity mActivity;
    private int mType = 0;
    private boolean loading = false;
    private SwipeRefreshLayout mSwipeRefreshLayout;
    private MainInterface mCallback;
    private String mCtrtGrpId = "";
    private String mCustId = "";
    private int mCustIdPosition = 0;
    private ArrayList<String> mCustIdMemberList = new ArrayList<String>();
    private ArrayList<String> mCustIdValueList = new ArrayList<String>();
    private ArrayList<String> mCustIdDispList = new ArrayList<String>();
    private ArrayList<HashMap<String, Object>> mTotalList = new ArrayList<>();
    //    @BindView(R.id.ivMsoLogo) ImageView mMsoLogo;
    private TextWatcher mTextWatcher = new TextWatcher() {
        @Override
        public void beforeTextChanged(CharSequence charSequence, int i, int i1, int i2) {

        }

        @Override
        public void onTextChanged(CharSequence charSequence, int i, int i1, int i2) {

        }

        @Override
        public void afterTextChanged(Editable editable) {

            String search = mUtil.getEditText(mActivity, R.id.edtSearch).getText().toString();

            if (mUtil.null2string(search).length() > 0) {
                mUtil.getView(mActivity, R.id.btnSearch).setEnabled(true);
            } else {
                mUtil.getView(mActivity, R.id.btnSearch).setEnabled(false);
            }
        }
    };

    public void recevicedWebSocket(Intent intentReceived) {

        int receivedState = intentReceived.getIntExtra(Constants.EXTRA_RESULT_STATE, WebSocketService.WEBSOCKET_RECEIVED_SUCESS);
        if (receivedState == WebSocketService.WEBSOCKET_RECEIVED_SUCESS) {
            try {
                String result = intentReceived.getStringExtra(Constants.EXTRA_RESULT);
                Dlog.v(result);
                JSONObject jsonObject = new JSONObject(result);
                String messageType = mUtil.null2string(jsonObject.get(Constants.KEY_MESSAGE_TYPE));
                Dlog.i(TAG, "websocket message mType : " + messageType);
                String resultCode = "";
                String resultMsg = "";
                if (jsonObject.has(Constants.KEY_RESULT_CODE)) {
                    resultCode = mUtil.null2string(jsonObject.get(Constants.KEY_RESULT_CODE));
                }
                if (jsonObject.has(Constants.KEY_RESULT_MSG)) {
                    resultMsg = mUtil.null2string(jsonObject.get(Constants.KEY_RESULT_MSG));
                }
//                if (messageType.equals(Constants.WEBSOCKET_TYPE_NODE_COMMAND)) {
//                    resultWsNodeCommand(jsonObject);
//                } else if (messageType.equals(Constants.WEBSOCKET_TYPE_NODE_COMMAND_RESULT)) {
//                    notificationWsNodeCommandResult(jsonObject);
//                } else if (messageType.equals(Constants.WEBSOCKET_TYPE_NODE_CONTENT)) {
//                    notificationWsNodeContent(jsonObject);
//                } else if (messageType.equals(Constants.WEBSOCKET_TYPE_NODE_REGISTER_RESULT)) {
//                    notificationWsNodeRegisterResult(jsonObject);
//                } else if (messageType.equals(Constants.WEBSOCKET_TYPE_NODES_RELOAD)) {
//                    resultWsNodeReload(jsonObject);
//                } else if (messageType.equals(Constants.WEBSOCKET_TYPE_NODE_DELETE_RESULT)) {
//                    notificationWsNodeDelete(jsonObject);
//                } else {
//                    /*final String finalResultMsg = resultMsg;
//                    runOnUiThread(new Runnable() {
//                        @Override
//                        public void run() {
//                            mUtil.setShowToast(mActivity, finalResultMsg, Toast.LENGTH_SHORT);
//                        }
//                    });*/
//                }
            } catch (JSONException ex) {
                ex.printStackTrace();
            }

        } else if (receivedState == WebSocketService.WEBSOCKET_RECEIVED_ERROR) {
//            if (!mUtil.getTopActivityName(mActivity).equals("view.Main")) {
//                return;
//            }
            int errorCode = intentReceived.getIntExtra(EXTRA_ERROR_CODE, WebSocketService.WEBSOCKET_CONNECT_TIMEOUT);
            switch (errorCode) {
                case Constants.WEBSOCKET_ERROR_TIMEOUT:
                    Dlog.i(TAG, "WEBSOCKET_ERROR_TIMEOUT!!!");
//                    for (HashMap<String, Object> hm : mAlTotalList) {
//                        hm.put(Constants.KEY_REQUEST_TIME, "");
//                    }
                    break;
                case Constants.WEBSOCKET_ERROR_NOT_CONNECTED:
                    Dlog.i(TAG, "WEBSOCKET_ERROR_NOT_CONNECTED!!!");
                    mCustomDialog.msgAlert(mActivity, Constants.MSG807);
                    break;
                default:
                    break;
            }
//            setHomeHubStateList();
        }
    }

    @Override
    public void onAttach(Activity activity) {

        super.onAttach(activity);

        try {
            mCallback = (MainInterface) activity;
        } catch (ClassCastException ex) {
            throw new ClassCastException(activity.toString() + " must implement MainInterface");
        }
    }

    @Override
    public void onCreate(Bundle savedInstanceState) {

        super.onCreate(savedInstanceState);
        Dlog.v("onCreate()");
    }

    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container,
                             Bundle savedInstanceState) {
        Dlog.v("onCreateView()");
        View rootView = inflater.inflate(R.layout.fragment_customer, container, false);
        ButterKnife.bind(this, rootView);

        return rootView;
    }

    @Override
    public void onStop() {

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

    @Override
    public void onStart() {

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

    @Override
    public void onActivityCreated(Bundle savedInstanceState) {

        super.onActivityCreated(savedInstanceState);
        Dlog.v("onActivityCreated().");
        Dlog.v(savedInstanceState == null ? "true" : "false");

        mActivity = getActivity();
        String actName = "Customer";
        mAppConfig = (AppConfig) mActivity.getApplicationContext();
        mCustomDialog.setOnMsgAlterToResultEvent(this);

        mUtil.callActGoogleAnalytics(actName);

        displayListView();
    }


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

        mUtil.getEditText(mActivity, R.id.edtSearch).addTextChangedListener(mTextWatcher);
        mUtil.getEditText(mActivity, R.id.edtSearch).setOnEditorActionListener(new TextView.OnEditorActionListener() {
            @Override
            public boolean onEditorAction(TextView v, int actionId, KeyEvent event) {
                switch (actionId) {
                    case EditorInfo.IME_ACTION_SEARCH:
                        mUtil.getView(mActivity, R.id.btnSearch).performClick();
                        break;
                    default:
                        return false;
                }
                return true;
            }
        });


        mUtil.getView(mActivity, R.id.btnSearch).setEnabled(false);

        mUtil.getView(mActivity, R.id.llResult).setVisibility(View.GONE);

    }

    @Override
    public void onConfigurationChanged(Configuration newConfig) {

        super.onConfigurationChanged(newConfig);
    }

    @OnClick({R.id.btnSearch, R.id.btnSelectResultId, R.id.btnMasterInvatation,  R.id.btnCustomerConnect})
    public void onClick(View view) {

        switch (view.getId()) {
            case R.id.btnSearch: {
                mUtil.getView(mActivity, R.id.btnSearch).setEnabled(false);
                mUtil.getView(mActivity, R.id.llResult).setVisibility(View.GONE);
                mUtil.getView(mActivity, R.id.llResultId).setVisibility(View.GONE);
                mUtil.getView(mActivity, R.id.llMasterInvatation).setVisibility(View.GONE);
                mCustId = mUtil.getEditTextVal(mActivity, R.id.edtSearch);
                mComHandler.sendMessageDelayed(mComHandler.obtainMessage(MSG_COM_G_MSOMEMBER), Constants.HANDLER_DELAY_MILLIS);

                break;
            }
            case R.id.btnMasterInvatation: {
                mUtil.getView(mActivity, btnMasterInvatation).setEnabled(false);
                mIntent = new Intent(mActivity, CustomerJoinMaster.class);
                mIntent.putExtra(Constants.KEY_CUST_ID, mCustId);
                mIntent.putExtra(Constants.KEY_CTRT_GRP_ID, mCtrtGrpId);
                mUtil.callActivityForResultNoAnim(mActivity, mIntent, Constants.ACT_CUSTOMER_JOIN_MASTER);
                mUtil.getView(mActivity, btnMasterInvatation).setEnabled(true);
                break;
            }
            case R.id.btnCustomerConnect: {
                mUtil.getView(mActivity, btnCustomerConnect).setEnabled(false);
                mIntent = new Intent(mActivity, CustomerConnection.class);
                mIntent.putExtra(Constants.EXTRA_CALL_TYPE, "0");
                mIntent.putExtra(Constants.KEY_CUST_ID, mCustId);
                mIntent.putExtra(Constants.KEY_CTRT_GRP_ID, mCtrtGrpId);
                mIntent.putExtra(Constants.EXTRA_POSITION, mCustIdPosition);
                mIntent.putExtra(Constants.EXTRA_SPINNER_LIST1, mCustIdDispList);
                mIntent.putExtra(Constants.EXTRA_SPINNER_LIST2, mCustIdValueList);
                mIntent.putExtra(Constants.EXTRA_SPINNER_LIST3, mCustIdMemberList);
                mUtil.callActivityForResultNoAnim(mActivity, mIntent, Constants.ACT_CUSTOMER_CONNECTION);
                mUtil.getView(mActivity, btnCustomerConnect).setEnabled(true);
                break;
            }
            case R.id.btnSelectResultId: {
                if (mCustIdDispList.size() > 0) {
                    // 여기에 선택창 호출
                    Intent intent = new Intent();
                    intent.setClass(mActivity, DialogSpinner.class);
                    intent.putExtra(Constants.EXTRA_SPINNER_LIST1, mCustIdDispList);
                    intent.putExtra(Constants.EXTRA_SPINNER_TITLE, mUtil.getString(mActivity, R.string.layout_customer_07));
                    intent.putExtra(Constants.EXTRA_SPINNER_TYPE, 0);
                    intent.putExtra(Constants.EXTRA_SPINNER_SHOW_TYPE, 1);
                    intent.putExtra(Constants.EXTRA_SPINNER_POSITION, mCustIdPosition);
                    mUtil.callActivityForResult(mActivity, intent, Constants.ACT_SPINNER, Constants.CHANGE_EVENT_BOTTOM_BOTTOM);
                }
                break;
            }
            default:
                break;
        }
    }


    /**
     * 고객번호 조회
     */
    private void sendGetMsoMember() {
        try {
            HttpSend httpSend = new HttpSend(mActivity);
            httpSend.setOnDataSendToReslutEvent(new OnDataSendToReslut() {
                @Override
                public void resultResponse(Response result) {

                    resultGetMsoMember(result);
                }
            });

            //공통 변수 입력
            httpSend.getMsoMember(mCustId);
        } catch (Exception ex) {
            ex.printStackTrace();
        }
    }

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

        try {
            mUtil.getView(mActivity, R.id.btnSearch).setEnabled(true);
            if (response.getStatusCode() == 200) {
                mUtil.getView(mActivity, R.id.llResult).setVisibility(View.VISIBLE);
                mUtil.getTextView(mActivity, R.id.tvResultCustId).setText(mCustId);
                mUtil.getEditText(mActivity, R.id.edtSearch).setText("");
                mTotalList.clear();
                mTotalList = mUtil.jsonToArrayListMap(response.getContent());

                if (mTotalList.size() > 0) {
                    mCustIdDispList.clear();
                    mCustIdValueList.clear();
                    mCustIdPosition = 0;
                    mCtrtGrpId = "";
                    mCustId = "";
                    for (int row = 0; row < mTotalList.size(); row++) {
                        HashMap<String, Object> tempMap;
                        tempMap = this.mTotalList.get(row);
                        if (row == 0) {
                            mCtrtGrpId = mUtil.null2string(tempMap.get(Constants.KEY_CTRT_GRP_ID));
                            mCustId = mUtil.null2string(tempMap.get(Constants.KEY_CUST_ID));
                        }

                        mCustIdValueList.add(mUtil.null2string(tempMap.get(Constants.KEY_PHONE)));
                        mCustIdMemberList.add(mUtil.null2string(tempMap.get(Constants.KEY_MEMBER_ID)));
                        mCustIdDispList.add(mUtil.null2string(tempMap.get(Constants.KEY_MEMBER_ID)) + "("
                                + mUtil.insertHyphenPhone(mUtil.null2string(tempMap.get(Constants.KEY_PHONE))) + ")");
                    }

                    if (mCustIdValueList.get(0).equals("")) {
                        Dlog.v("jino1");
                        // 등록은 되었지만 연결되지 않은 경우.
                        mUtil.getView(mActivity, R.id.tvNoCustIdMsg).setVisibility(View.GONE);
                        mUtil.getView(mActivity, R.id.llResultId).setVisibility(View.VISIBLE);
                        mUtil.getView(mActivity, R.id.llMasterInvatation).setVisibility(View.VISIBLE);
                        mUtil.getView(mActivity, R.id.llCustomerConnect).setVisibility(View.GONE);
                        mUtil.getView(mActivity, R.id.tvSelectResultId).setVisibility(View.VISIBLE);
                        mUtil.getButton(mActivity, R.id.btnSelectResultId).setVisibility(View.GONE);
                        mUtil.getButton(mActivity, R.id.btnSelectResultId).setEnabled(false);
                    } else {
                        Dlog.v("jino2");
                        mUtil.getView(mActivity, R.id.llResultId).setVisibility(View.VISIBLE);
                        mUtil.getView(mActivity, R.id.tvNoCustIdMsg).setVisibility(View.GONE);
                        mUtil.getView(mActivity, R.id.llMasterInvatation).setVisibility(View.GONE);
                        mUtil.getView(mActivity, R.id.llCustomerConnect).setVisibility(View.VISIBLE);
                        if (mTotalList.size() == 1) {
                            Dlog.v("jino3");
                            mUtil.getView(mActivity, R.id.tvSelectResultId).setVisibility(View.VISIBLE);
                            mUtil.getButton(mActivity, R.id.btnSelectResultId).setVisibility(View.GONE);

                            mUtil.getTextView(mActivity, R.id.tvSelectResultId).setText(mCustIdDispList.get(mCustIdPosition));
                            mUtil.getTextView(mActivity, R.id.tvSelectResultId).setSelected(true);
                        } else {
                            Dlog.v("jino4");
                            mUtil.getView(mActivity, R.id.tvSelectResultId).setVisibility(View.GONE);
                            mUtil.getButton(mActivity, R.id.btnSelectResultId).setVisibility(View.VISIBLE);

                            mUtil.getButton(mActivity, R.id.btnSelectResultId).setText(mCustIdDispList.get(mCustIdPosition));
                            mUtil.getButton(mActivity, R.id.btnSelectResultId).setSelected(true);
                            mUtil.getButton(mActivity, R.id.btnSelectResultId).setEnabled(true);
                        }
                    }
                } else {
                    // 등록되지 않은 고객번호 일때 처리
                    mUtil.getView(mActivity, R.id.tvNoCustIdMsg).setVisibility(View.VISIBLE);
                    mUtil.getView(mActivity, R.id.llResultId).setVisibility(View.GONE);
                    mUtil.getView(mActivity, R.id.llMasterInvatation).setVisibility(View.GONE);
                    mUtil.getView(mActivity, R.id.llCustomerConnect).setVisibility(View.GONE);
                    mUtil.getButton(mActivity, R.id.btnSelectResultId).setSelected(false);
                    mUtil.getButton(mActivity, R.id.btnSelectResultId).setEnabled(false);
                }
//                mSwipeRefreshLayout.setRefreshing(false);
            } else {
                JSONObject joResult = new JSONObject(response.getContent());
                Dlog.v(joResult.toString());
                String resultCode = mUtil.null2string(joResult.get(Constants.KEY_RESULT_CODE));
                String resultMsg = mUtil.null2string(joResult.get(Constants.KEY_RESULT_MSG));

                if (resultCode.equals("41")){
                    // 등록되지 않은 고객번호 일때 처리
                    mUtil.getView(mActivity, R.id.llResult).setVisibility(View.VISIBLE);
                    mUtil.getView(mActivity, R.id.tvNoCustIdMsg).setVisibility(View.VISIBLE);
                    mUtil.getView(mActivity, R.id.llResultId).setVisibility(View.GONE);
                    mUtil.getView(mActivity, R.id.llMasterInvatation).setVisibility(View.GONE);
                    mUtil.getView(mActivity, R.id.llCustomerConnect).setVisibility(View.GONE);
                    mUtil.getButton(mActivity, R.id.btnSelectResultId).setSelected(false);
                    mUtil.getButton(mActivity, R.id.btnSelectResultId).setEnabled(false);
                } else {
                    mCustomDialog.msgAlert(mActivity, Constants.MSG000, resultMsg);
                }
            }
        } catch (Exception ex) {
            ex.printStackTrace();
            mCustomDialog.msgAlert(mActivity, Constants.MSG807);
        }
        /*try {
            mUtil.getView(mActivity, R.id.btnReload).setEnabled(true);
        } catch (Exception ex) {
            ex.printStackTrace();
        }*/
    }

    @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 onActivityResult(int requestCode, int resultCode, Intent data) {

        super.onActivityResult(requestCode, resultCode, data);
        if (resultCode == Activity.RESULT_OK) {
            switch (requestCode) {
                case Constants.ACT_SPINNER: {
                    mCustIdPosition = data.getIntExtra(Constants.EXTRA_SPINNER_RESULT, -1);
                    mUtil.getButton(mActivity, R.id.btnSelectResultId).setText(mCustIdDispList.get(mCustIdPosition));
                    break;
                }
                case Constants.ACT_CUSTOMER_JOIN_MASTER:
                    if (data == null) {
                        return;
                    }
                    Boolean isReload = data.getBooleanExtra(Constants.EXTRA_RELOAD_FLAG, false);
                    if (isReload) {
                        mComHandler.sendMessageDelayed(mComHandler.obtainMessage(MSG_COM_G_MSOMEMBER), Constants.HANDLER_DELAY_MILLIS);
                    }
                    break;
                case Constants.ACT_CUSTOMER_CONNECTION:
                    if (data == null) {
                        return;
                    }

                    mCustIdPosition = data.getIntExtra(Constants.EXTRA_POSITION, 0);
                    mUtil.getButton(mActivity, R.id.btnSelectResultId).setText(mCustIdDispList.get(mCustIdPosition));
                    if (mAppConfig.getIsCustomerConn()){
                        if (mCustId != mAppConfig.getCustId()){

                            CustomDialog mCustomDialog = new CustomDialog();
                            mCustomDialog.setOnMsgAlterToResultEvent(new CustomDialog.OnMsgAlterToResult() {
                                @Override
                                public void resultCustomDialogResponse(int iMsgID, int iBtnResult) {
                                    if (iBtnResult == 1) {   // ok 선택 시
                                        mUtil.getView(mActivity, R.id.llResult).setVisibility(View.GONE);
                                        mUtil.getEditText(mActivity, R.id.edtSearch).setText("");
                                        mCallback.setCustomerConnect(mCustId, mCustIdPosition, mCustIdDispList, mCustIdValueList, mCustIdMemberList);
                                    } else if (iBtnResult == 2) {   // cancel 선택 시

                                    }
                                }
                            });
                            mCustomDialog.msgAlert(mActivity, Constants.MSG702, R.string.MSG_TITLE_000);
                        }
                    } else {
                        mUtil.getView(mActivity, R.id.llResult).setVisibility(View.GONE);
                        mUtil.getEditText(mActivity, R.id.edtSearch).setText("");
                        mCallback.setCustomerConnect(mCustId, mCustIdPosition, mCustIdDispList, mCustIdValueList, mCustIdMemberList);
                    }
                    break;
                case Constants.ACT_SETTING:
                    break;
                /*case Constants.ACT_IMAGE_SELECT:
                    fileName = mUtil.null2string(data.getStringExtra(Constants.EXTRA_IMAGE_FILE_NAME));

                    mComHandler.sendMessageDelayed(mComHandler.obtainMessage(
                            MSG_COM_P_HOMEGRP_PROFILE_IMAGE), 10);
                    break;*/
                default:
                    break;
            }
        } else {
            switch (requestCode) {
                case Constants.ACT_HOMEMODE:
                    if (data == null) {
                        return;
                    }
                    Boolean isReload = data.getBooleanExtra(Constants.EXTRA_RELOAD_FLAG, false);
                    if (isReload) {
//                        mComHandler.sendMessageDelayed(mComHandler.obtainMessage(MSG_COM_P_DASHBOARD), Constants.HANDLER_DELAY_MILLIS);
                    }
                    break;
                case Constants.ACT_NOTICE:
                case Constants.ACT_MESSAGE_CENTER:
//                    mComHandler.sendMessageDelayed(mComHandler.obtainMessage(MSG_COM_P_DASHBOARD), Constants.HANDLER_DELAY_MILLIS);
                    break;
                default:
                    break;
            }
        }
    }

    class IncomingHandlerCallBack implements Handler.Callback {

        @Override
        public boolean handleMessage(Message msg) {

            mType = msg.what;
            if (!mAppConfig.getIsLogin()) {
                return true;
            }
            switch (msg.what) {
                case MSG_COM_G_MSOMEMBER:
                    sendGetMsoMember();
                    break;
                case MSG_COM_P_MODE_CHANGE:
//                    sendPutModeChange();
                    break;
                /*case MSG_COM_P_HOMEGRP_PROFILE_IMAGE:
                    sendPostHomegrpProfileImage();
                    break;*/
                default:
                    break;
            }
            return true;
        }
    }
}
