Search in sources :

Example 31 with RequestListener

use of com.lingtuan.firefly.listener.RequestListener in project SmartMesh_Android by SmartMeshFoundation.

the class ContactAddAdapter method requestAgree.

/**
 * Agree to add buddy
 */
private void requestAgree(final Holder h, final ChatMsg msg) {
    if (msg.isOffLineMsg()) {
        if (listener != null) {
            boolean successed = listener.addFriendConfim(msg.getUserId());
            if (successed) {
                FinalUserDataBase.getInstance().updateChatEventAgree(msg.getUserId(), true, msg.getType());
                UserBaseVo vo = new UserBaseVo();
                vo.setFriendLog(1);
                vo.setThumb(msg.getUserImage());
                vo.setLocalId(msg.getUserId());
                vo.setUsername(msg.getUsername());
                vo.setGender(msg.getGender() + "");
                vo.setOffLine(true);
                FinalUserDataBase.getInstance().saveFriendUserBase(vo);
                msg.setAgree(true);
                notifyDataSetChanged();
            } else {
                h.agreeBtn.setEnabled(true);
                if (Utils.isConnectNet(mContext)) {
                    NetRequestImpl.getInstance().addFriendAgree(msg.getUserId(), new RequestListener() {

                        @Override
                        public void start() {
                        }

                        @Override
                        public void success(JSONObject response) {
                            try {
                                MyToast.showToast(mContext, response.optString("msg"));
                                FinalUserDataBase.getInstance().updateChatEventAgree(msg.getUserId(), true, msg.getType());
                                msg.setAgree(true);
                                Constants.isRefresh = true;
                                notifyDataSetChanged();
                            } catch (Exception e) {
                                e.printStackTrace();
                            }
                        }

                        @Override
                        public void error(int errorCode, String errorMsg) {
                            try {
                                if (1211122 == errorCode) {
                                    FinalUserDataBase.getInstance().updateChatEventAgree(msg.getUserId(), true, msg.getType());
                                    msg.setAgree(true);
                                } else {
                                    MyToast.showToast(mContext, errorMsg);
                                }
                            } catch (Exception e) {
                                e.printStackTrace();
                            }
                            notifyDataSetChanged();
                        }
                    });
                }
            }
        }
    } else {
        NetRequestImpl.getInstance().addFriendAgree(msg.getUserId(), new RequestListener() {

            @Override
            public void start() {
            }

            @Override
            public void success(JSONObject response) {
                try {
                    MyToast.showToast(mContext, response.optString("msg"));
                    FinalUserDataBase.getInstance().updateChatEventAgree(msg.getUserId(), true, msg.getType());
                    msg.setAgree(true);
                    Constants.isRefresh = true;
                    notifyDataSetChanged();
                } catch (Exception e) {
                    e.printStackTrace();
                }
            }

            @Override
            public void error(int errorCode, String errorMsg) {
                try {
                    if (1211121 == errorCode) {
                        FinalUserDataBase.getInstance().updateChatEventAgree(msg.getUserId(), true, msg.getType());
                        msg.setAgree(true);
                    } else {
                        MyToast.showToast(mContext, errorMsg);
                    }
                } catch (Exception e) {
                    e.printStackTrace();
                }
                notifyDataSetChanged();
            }
        });
    }
}
Also used : RequestListener(com.lingtuan.firefly.listener.RequestListener) JSONObject(org.json.JSONObject) UserBaseVo(com.lingtuan.firefly.vo.UserBaseVo)

Example 32 with RequestListener

use of com.lingtuan.firefly.listener.RequestListener in project SmartMesh_Android by SmartMeshFoundation.

the class MainMessageFragmentUI method createDiscussionGroups.

/**
 * create a group chat
 * @ param touids member id
 * @ param member group members
 */
private void createDiscussionGroups(String touids, final List<UserBaseVo> member) {
    showDialog();
    NetRequestImpl.getInstance().createDiscussionGroups(touids, new RequestListener() {

        @Override
        public void start() {
        }

        @Override
        public void success(JSONObject response) {
            showToast(response.optString("msg"));
            dismissDialog();
            Utils.gotoGroupChat(getActivity(), false, null, response.optString("cid"), member);
        }

        @Override
        public void error(int errorCode, String errorMsg) {
            dismissDialog();
            showToast(errorMsg);
        }
    });
}
Also used : RequestListener(com.lingtuan.firefly.listener.RequestListener) JSONObject(org.json.JSONObject) SuppressLint(android.annotation.SuppressLint)

Aggregations

RequestListener (com.lingtuan.firefly.listener.RequestListener)32 JSONObject (org.json.JSONObject)32 SuppressLint (android.annotation.SuppressLint)7 Intent (android.content.Intent)6 JSONArray (org.json.JSONArray)5 UserBaseVo (com.lingtuan.firefly.vo.UserBaseVo)4 UserInfoVo (com.lingtuan.firefly.vo.UserInfoVo)4 JSONException (org.json.JSONException)4 TokenVo (com.lingtuan.firefly.wallet.vo.TokenVo)3 Handler (android.os.Handler)2 RegistUI (com.lingtuan.firefly.login.RegistUI)2 ActivityNotFoundException (android.content.ActivityNotFoundException)1 Bundle (android.os.Bundle)1 NewContactVO (com.lingtuan.firefly.contact.vo.NewContactVO)1 ContactItemComparator (com.lingtuan.firefly.custom.contact.ContactItemComparator)1 ChatMsg (com.lingtuan.firefly.vo.ChatMsg)1