Search in sources :

Example 1 with IResendMessage

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

the class FragmentChat method onFailedMessageClick.

@Override
public void onFailedMessageClick(View view, final MessageObject messageObject, final int pos) {
    // TODO: 12/28/20 MESSAGE_REFACTOR_NEED_TEST
    final List<MessageObject> failedMessages = mAdapter.getFailedMessages();
    hideKeyboard();
    new ResendMessage(G.fragmentActivity, new IResendMessage() {

        @Override
        public void deleteMessage() {
            if (pos >= 0 && mAdapter.getAdapterItemCount() > pos) {
                mAdapter.remove(pos);
                removeLayoutTimeIfNeed();
            }
        }

        @Override
        public void resendMessage() {
            for (int i = 0; i < failedMessages.size(); i++) {
                if (failedMessages.get(i).id == messageObject.id) {
                    if (failedMessages.get(i).getAttachment() != null) {
                        if (!Uploader.getInstance().isCompressingOrUploading(messageObject.id + "")) {
                            UploadObject fileObject = UploadObject.createForMessage(messageObject, chatType);
                            if (fileObject != null) {
                                Uploader.getInstance().upload(fileObject);
                            }
                        }
                    }
                    break;
                }
            }
            mAdapter.updateMessageStatus(messageObject.id, ProtoGlobal.RoomMessageStatus.SENDING);
            G.handler.postDelayed(new Runnable() {

                @Override
                public void run() {
                    mAdapter.notifyItemChanged(mAdapter.findPositionByMessageId(messageObject.id));
                }
            }, 300);
        }

        @Override
        public void resendAllMessages() {
            for (int i = 0; i < failedMessages.size(); i++) {
                final int j = i;
                G.handler.postDelayed(new Runnable() {

                    @Override
                    public void run() {
                        mAdapter.updateMessageStatus(failedMessages.get(j).id, ProtoGlobal.RoomMessageStatus.SENDING);
                    }
                }, 1000 * i);
            }
        }

        @Override
        public void copyMessage() {
            copyMessageToClipboard(messageObject, false);
        }
    }, messageObject.id, failedMessages);
}
Also used : IResendMessage(net.iGap.observers.interfaces.IResendMessage) UploadObject(net.iGap.module.upload.UploadObject) IResendMessage(net.iGap.observers.interfaces.IResendMessage) ResendMessage(net.iGap.module.ResendMessage) MessageObject(net.iGap.structs.MessageObject)

Aggregations

ResendMessage (net.iGap.module.ResendMessage)1 UploadObject (net.iGap.module.upload.UploadObject)1 IResendMessage (net.iGap.observers.interfaces.IResendMessage)1 MessageObject (net.iGap.structs.MessageObject)1