Search in sources :

Example 1 with OnChatEditMessageResponse

use of net.iGap.observers.interfaces.OnChatEditMessageResponse in project iGap-Android by KianIranian-STDG.

the class FragmentChat method initCallbacks.

/**
 * initialize some callbacks that used in this page
 */
public void initCallbacks() {
    getSendMessageUtil().setOnChatSendMessageResponseChatPage(this);
    // G.chatUpdateStatusUtil.setOnChatUpdateStatusResponse(this);
    G.onChatSendMessage = new OnChatSendMessage() {

        @Override
        public void Error(int majorCode, int minorCode, final int waitTime, long messageId) {
            if (majorCode == 234) {
                G.handler.post(new Runnable() {

                    @Override
                    public void run() {
                        try {
                            if (G.fragmentActivity.hasWindowFocus()) {
                                showErrorDialog(waitTime);
                            }
                        } catch (Exception e) {
                        }
                    }
                });
            } else if (majorCode == 233 && minorCode == 1) {
                G.handler.post(new Runnable() {

                    @Override
                    public void run() {
                        if (getContext() != null && mAdapter != null) {
                            mAdapter.removeMessage(messageId);
                        }
                    }
                });
            }
        }
    };
    G.onChatEditMessageResponse = new OnChatEditMessageResponse() {

        @Override
        public void onChatEditMessage(long roomId, final long messageId, long messageVersion, final String message, ProtoResponse.Response response) {
            if (mRoomId == roomId && mAdapter != null) {
                // I'm in the room
                G.handler.post(new Runnable() {

                    @Override
                    public void run() {
                        // update message text in adapter
                        mAdapter.updateMessageText(messageId, message);
                    }
                });
            }
        }

        @Override
        public void onError(int majorCode, int minorCode) {
        }
    };
    onMusicListener = new OnComplete() {

        @Override
        public void complete(boolean result, String messageID, String MessageTwo) {
            if (result) {
                updateShowItemInScreen();
            } else {
                onPlayMusic(messageID);
            }
        }
    };
    iUpdateLogItem = new // TODO: 12/29/20 MESSAGE_REFACTOR_NEED_TEST
    IUpdateLogItem() {

        @Override
        public void onUpdate(byte[] log, long messageId) {
            if (getActivity() == null || getActivity().isFinishing())
                return;
            getActivity().runOnUiThread(new Runnable() {

                @Override
                public void run() {
                    if (mAdapter == null) {
                        return;
                    }
                    for (int i = mAdapter.getAdapterItemCount() - 1; i >= 0; i--) {
                        try {
                            AbstractMessage item = mAdapter.getAdapterItem(i);
                            if (item.messageObject != null && item.messageObject.id == messageId) {
                                // bagi May crash
                                item.messageObject.log.data = log;
                                mAdapter.notifyAdapterItemChanged(i);
                                break;
                            }
                        } catch (Exception e) {
                            e.printStackTrace();
                            HelperLog.getInstance().setErrorLog(e);
                        }
                    }
                }
            });
        }
    };
    /**
     * after get position from gps
     */
    complete = new OnComplete() {

        @Override
        public void complete(boolean result, final String messageOne, String MessageTwo) {
            try {
                if (getActivity() != null) {
                    String[] split = messageOne.split(",");
                    Double latitude = Double.parseDouble(split[0]);
                    Double longitude = Double.parseDouble(split[1]);
                    NewFragmentMap fragment = NewFragmentMap.newInstance(latitude, longitude);
                    new HelperFragment(getActivity().getSupportFragmentManager(), fragment).setReplace(false).load();
                }
            } catch (Exception e) {
                HelperLog.getInstance().setErrorLog(e);
            }
        }
    };
    G.onHelperSetAction = new OnHelperSetAction() {

        @Override
        public void onAction(ProtoGlobal.ClientAction ClientAction) {
            HelperSetAction.setActionFiles(mRoomId, messageId, ClientAction, chatType);
        }
    };
    G.onDeleteChatFinishActivity = new OnDeleteChatFinishActivity() {

        @Override
        public void onFinish() {
            G.handler.post(new Runnable() {

                @Override
                public void run() {
                    // finish();
                    finishChat();
                }
            });
        }
    };
    G.onUpdateUserStatusInChangePage = (peerId, status, lastSeen) -> {
        if (chatType == CHAT) {
            setUserStatus(status, lastSeen);
            new RequestUserInfo().userInfo(peerId);
        }
    };
}
Also used : OnChatEditMessageResponse(net.iGap.observers.interfaces.OnChatEditMessageResponse) OnHelperSetAction(net.iGap.observers.interfaces.OnHelperSetAction) AbstractMessage(net.iGap.adapter.items.chat.AbstractMessage) OnComplete(net.iGap.observers.interfaces.OnComplete) ProtoGlobal(net.iGap.proto.ProtoGlobal) RealmString(net.iGap.realm.RealmString) HelperString(net.iGap.helper.HelperString) OnChatSendMessage(net.iGap.observers.interfaces.OnChatSendMessage) SuppressLint(android.annotation.SuppressLint) IOException(java.io.IOException) JsonSyntaxException(com.google.gson.JsonSyntaxException) OnDeleteChatFinishActivity(net.iGap.observers.interfaces.OnDeleteChatFinishActivity) RequestUserInfo(net.iGap.request.RequestUserInfo) ProtoResponse(net.iGap.proto.ProtoResponse) HelperFragment(net.iGap.helper.HelperFragment)

Aggregations

SuppressLint (android.annotation.SuppressLint)1 JsonSyntaxException (com.google.gson.JsonSyntaxException)1 IOException (java.io.IOException)1 AbstractMessage (net.iGap.adapter.items.chat.AbstractMessage)1 HelperFragment (net.iGap.helper.HelperFragment)1 HelperString (net.iGap.helper.HelperString)1 OnChatEditMessageResponse (net.iGap.observers.interfaces.OnChatEditMessageResponse)1 OnChatSendMessage (net.iGap.observers.interfaces.OnChatSendMessage)1 OnComplete (net.iGap.observers.interfaces.OnComplete)1 OnDeleteChatFinishActivity (net.iGap.observers.interfaces.OnDeleteChatFinishActivity)1 OnHelperSetAction (net.iGap.observers.interfaces.OnHelperSetAction)1 ProtoGlobal (net.iGap.proto.ProtoGlobal)1 ProtoResponse (net.iGap.proto.ProtoResponse)1 RealmString (net.iGap.realm.RealmString)1 RequestUserInfo (net.iGap.request.RequestUserInfo)1