Search in sources :

Example 1 with UploadObject

use of net.iGap.module.upload.UploadObject in project iGap-Android by KianIranian-STDG.

the class UploadService method sendVoice.

private void sendVoice(final String savedPath, final Long mRoomId) {
    ProtoGlobal.Room.Type chatType = RealmRoom.detectType(mRoomId);
    RealmRoomMessage roomMessage = RealmRoomMessage.makeVoiceMessage(mRoomId, chatType, savedPath, "");
    new Thread(() -> {
        DbManager.getInstance().doRealmTransaction(realm1 -> {
            realm1.copyToRealmOrUpdate(roomMessage);
            RealmRoom.setLastMessageWithRoomMessage(realm1, mRoomId, roomMessage);
        });
    }).start();
    UploadObject fileObject = UploadObject.createForMessage(roomMessage, chatType);
    if (fileObject != null)
        Uploader.getInstance().upload(fileObject);
}
Also used : Nullable(androidx.annotation.Nullable) Service(android.app.Service) UploadObject(net.iGap.module.upload.UploadObject) ProtoGlobal(net.iGap.proto.ProtoGlobal) Intent(android.content.Intent) RealmRoom(net.iGap.realm.RealmRoom) RealmRoomMessage(net.iGap.realm.RealmRoomMessage) DbManager(net.iGap.module.accountManager.DbManager) IBinder(android.os.IBinder) Uploader(net.iGap.module.upload.Uploader) UploadObject(net.iGap.module.upload.UploadObject) RealmRoomMessage(net.iGap.realm.RealmRoomMessage) RealmRoom(net.iGap.realm.RealmRoom)

Example 2 with UploadObject

use of net.iGap.module.upload.UploadObject in project iGap-Android by KianIranian-STDG.

the class ResendMessage method resend.

private void resend(final boolean all) {
    if (!RequestManager.getInstance(AccountManager.selectedAccount).isUserLogin()) {
        return;
    }
    DbManager.getInstance().doRealmTask(realm -> {
        realm.executeTransactionAsync(new Realm.Transaction() {

            @Override
            public void execute(Realm realm) {
                for (MessageObject message : mMessages) {
                    if (all) {
                        RealmRoomMessage.setStatus(realm, message.id, ProtoGlobal.RoomMessageStatus.SENDING);
                    } else {
                        if (message.id == mSelectedMessageID) {
                            RealmRoomMessage.setStatus(realm, message.id, ProtoGlobal.RoomMessageStatus.SENDING);
                            break;
                        }
                    }
                }
            }
        }, () -> {
            if (all) {
                mListener.resendAllMessages();
            } else {
                mListener.resendMessage();
            }
            for (int i = 0; i < mMessages.size(); i++) {
                final int j = i;
                if (all) {
                    if (FragmentChat.allowResendMessage(mMessages.get(j).id)) {
                        G.handler.postDelayed(new Runnable() {

                            @Override
                            public void run() {
                                DbManager.getInstance().doRealmTask(realm1 -> {
                                    RealmRoomMessage roomMessage = realm1.where(RealmRoomMessage.class).equalTo("messageId", mMessages.get(j).id).findFirst();
                                    MessageObject resendMessageObject = MessageObject.create(roomMessage);
                                    if (resendMessageObject != null) {
                                        RealmRoom realmRoom = realm1.where(RealmRoom.class).equalTo("id", resendMessageObject.roomId).findFirst();
                                        if (realmRoom != null) {
                                            if (resendMessageObject.attachment == null) {
                                                ProtoGlobal.Room.Type roomType = realmRoom.getType();
                                                ChatSendMessageUtil.getInstance(AccountManager.selectedAccount).build(roomType, resendMessageObject.roomId, resendMessageObject);
                                            } else {
                                                if (resendMessageObject.additional != null && resendMessageObject.additional.type == 4) {
                                                    ChatSendMessageUtil.getInstance(AccountManager.selectedAccount).build(realmRoom.getType(), resendMessageObject.roomId, resendMessageObject);
                                                } else {
                                                    RealmRoomMessage message = realm.copyFromRealm(roomMessage);
                                                    UploadObject fileObject = UploadObject.createForMessage(message, realmRoom.getType());
                                                    if (fileObject != null) {
                                                        Uploader.getInstance().upload(fileObject);
                                                    }
                                                }
                                            }
                                        }
                                    }
                                });
                            }
                        }, 1000 * j);
                    }
                } else {
                    if (mMessages.get(j).id == mSelectedMessageID) {
                        if (FragmentChat.allowResendMessage(mSelectedMessageID)) {
                            RealmRoomMessage roomMessage = realm.where(RealmRoomMessage.class).equalTo("messageId", mMessages.get(j).id).findFirst();
                            MessageObject resendMessageObject = MessageObject.create(roomMessage);
                            if (resendMessageObject != null) {
                                RealmRoom realmRoom = realm.where(RealmRoom.class).equalTo("id", resendMessageObject.roomId).findFirst();
                                if (realmRoom != null) {
                                    ProtoGlobal.Room.Type roomType = realmRoom.getType();
                                    if (resendMessageObject.attachment == null) {
                                        ChatSendMessageUtil.getInstance(AccountManager.selectedAccount).build(roomType, resendMessageObject.roomId, resendMessageObject);
                                    } else {
                                        if (resendMessageObject.additional != null && resendMessageObject.additional.type == 4) {
                                            ChatSendMessageUtil.getInstance(AccountManager.selectedAccount).build(realmRoom.getType(), resendMessageObject.roomId, resendMessageObject);
                                        } else {
                                            RealmRoomMessage message = realm.copyFromRealm(roomMessage);
                                            UploadObject fileObject = UploadObject.createForMessage(message, realmRoom.getType());
                                            if (fileObject != null) {
                                                Uploader.getInstance().upload(fileObject);
                                            }
                                        }
                                    }
                                }
                            }
                            break;
                        }
                    }
                }
            }
        });
    });
}
Also used : Context(android.content.Context) Realm(io.realm.Realm) MessageObject(net.iGap.structs.MessageObject) AccountManager(net.iGap.module.accountManager.AccountManager) UploadObject(net.iGap.module.upload.UploadObject) RealmRoom(net.iGap.realm.RealmRoom) IResendMessage(net.iGap.observers.interfaces.IResendMessage) RequestManager(net.iGap.network.RequestManager) Uploader(net.iGap.module.upload.Uploader) G(net.iGap.G) List(java.util.List) FragmentChat(net.iGap.fragments.FragmentChat) ProtoGlobal(net.iGap.proto.ProtoGlobal) MessageDataStorage(net.iGap.controllers.MessageDataStorage) RealmRoomMessage(net.iGap.realm.RealmRoomMessage) Activity(android.app.Activity) DbManager(net.iGap.module.accountManager.DbManager) ProtoGlobal(net.iGap.proto.ProtoGlobal) UploadObject(net.iGap.module.upload.UploadObject) RealmRoomMessage(net.iGap.realm.RealmRoomMessage) RealmRoom(net.iGap.realm.RealmRoom) Realm(io.realm.Realm) MessageObject(net.iGap.structs.MessageObject) RealmRoom(net.iGap.realm.RealmRoom)

Example 3 with UploadObject

use of net.iGap.module.upload.UploadObject in project iGap-Android by KianIranian-STDG.

the class HttpUploader method startUpload.

private void startUpload(UploadObject fileObject, final File completedCompressFile) {
    if (fileObject.fileToken != null && completedCompressFile == null) {
        sendMessage(fileObject);
    } else {
        UploadHttpRequest existedRequest = findExistedRequest(fileObject.key);
        if (existedRequest == null) {
            existedRequest = new UploadHttpRequest(fileObject, new UploadHttpRequest.UploadDelegate() {

                @Override
                public void onUploadProgress(UploadObject fileObject) {
                    FileLog.i("HttpUploader " + fileObject.fileToken + " progress -> " + fileObject.progress);
                    G.runOnUiThread(() -> EventManager.getInstance(AccountManager.selectedAccount).postEvent(EventManager.ON_UPLOAD_PROGRESS, fileObject.key, fileObject.progress, fileObject.fileSize));
                    if (fileObject.onUploadListener != null) {
                        fileObject.onUploadListener.onProgress(String.valueOf(fileObject.messageId), fileObject.progress);
                    }
                }

                @Override
                public void onUploadFinish(UploadObject fileObject) {
                    HelperDataUsage.increaseUploadFiles(fileObject.messageType);
                    HelperDataUsage.progressUpload(fileObject.fileSize, fileObject.messageType);
                    FileLog.i("HttpUploader onUploadFinish " + fileObject.fileToken);
                    UploadHttpRequest req = inProgressUploads.get(fileObject.key);
                    if (req != null) {
                        inProgressUploads.remove(fileObject.key);
                        inProgressCount.decrementAndGet();
                    }
                    if (fileObject.messageObject != null) {
                        if (completedCompressFile != null && completedCompressFile.exists()) {
                            completedCompressFile.delete();
                        }
                        HelperSetAction.sendCancel(fileObject.messageId);
                        DbManager.getInstance().doRealmTransaction(realm -> RealmAttachment.updateToken(fileObject.messageId, fileObject.fileToken));
                        sendMessage(fileObject);
                    }
                    if (fileObject.messageType == ProtoGlobal.RoomMessageType.STORY) {
                        MessageDataStorage.getInstance(AccountManager.selectedAccount).updateStoryFileToken(fileObject.messageId, fileObject.fileToken);
                        if (isMultiUpload || isRoomMultiUpload) {
                            if (MessageDataStorage.getInstance(AccountManager.selectedAccount).getStoryById(AccountManager.getInstance().getCurrentUser().getId(), false).storyObjects.size() == MessageDataStorage.getInstance(AccountManager.selectedAccount).getNotNullTokenStories(AccountManager.getInstance().getCurrentUser().getId(), 0).size()) {
                                List<StoryObject> realmStoryProtos;
                                if (isRoomMultiUpload) {
                                    realmStoryProtos = MessageDataStorage.getInstance(AccountManager.selectedAccount).getStoryByStatus(AccountManager.getInstance().getCurrentUser().getId(), storyRoomIdForUpload, MessageObject.STATUS_SENDING, true, true, new String[] { "createdAt" });
                                } else {
                                    realmStoryProtos = MessageDataStorage.getInstance(AccountManager.selectedAccount).getStoryByStatus(AccountManager.getInstance().getCurrentUser().getId(), 0, MessageObject.STATUS_SENDING, true, false, new String[] { "createdAt" });
                                }
                                if (realmStoryProtos != null && realmStoryProtos.size() > 0) {
                                    List<ProtoStoryUserAddNew.StoryAddRequest> storyObjects = new ArrayList<>();
                                    for (int i = 0; i < realmStoryProtos.size(); i++) {
                                        ProtoStoryUserAddNew.StoryAddRequest.Builder storyAddRequest = ProtoStoryUserAddNew.StoryAddRequest.newBuilder();
                                        storyAddRequest.setToken(realmStoryProtos.get(i).fileToken);
                                        storyAddRequest.setCaption(realmStoryProtos.get(i).caption);
                                        storyObjects.add(storyAddRequest.build());
                                    }
                                    isStoryUploading = false;
                                    if (isRoomMultiUpload) {
                                        MessageController.getInstance(AccountManager.selectedAccount).addMyRoomStory(storyObjects, storyRoomIdForUpload);
                                    } else {
                                        MessageController.getInstance(AccountManager.selectedAccount).addMyStory(storyObjects);
                                    }
                                }
                            }
                        } else {
                            List<StoryObject> realmStoryProtos = MessageDataStorage.getInstance(AccountManager.selectedAccount).getNotNullTokenStories(AccountManager.getInstance().getCurrentUser().getId(), MessageObject.STATUS_SENDING);
                            if (realmStoryProtos != null && realmStoryProtos.size() > 0) {
                                List<ProtoStoryUserAddNew.StoryAddRequest> storyObjects = new ArrayList<>();
                                for (int i = 0; i < realmStoryProtos.size(); i++) {
                                    ProtoStoryUserAddNew.StoryAddRequest.Builder storyAddRequest = ProtoStoryUserAddNew.StoryAddRequest.newBuilder();
                                    storyAddRequest.setToken(realmStoryProtos.get(i).fileToken);
                                    storyAddRequest.setCaption(realmStoryProtos.get(i).caption);
                                    storyObjects.add(storyAddRequest.build());
                                }
                                isStoryUploading = false;
                                if (realmStoryProtos.get(0).isForRoom) {
                                    MessageController.getInstance(AccountManager.selectedAccount).addMyRoomStory(storyObjects, realmStoryProtos.get(0).roomId);
                                } else {
                                    MessageController.getInstance(AccountManager.selectedAccount).addMyStory(storyObjects);
                                }
                            }
                        }
                    }
                    if (fileObject.onUploadListener != null) {
                        fileObject.onUploadListener.onFinish(String.valueOf(fileObject.messageId), fileObject.fileToken);
                    }
                    scheduleNewUpload();
                }

                @Override
                public void onUploadFail(UploadObject fileObject, @Nullable Exception e) {
                    long uploadedBytes = ((fileObject.fileSize / 100) * fileObject.progress);
                    HelperDataUsage.progressUpload(uploadedBytes, fileObject.messageType);
                    FileLog.e("HttpUploader onUploadFail " + fileObject.fileToken, e);
                    UploadHttpRequest req = inProgressUploads.get(fileObject.key);
                    if (req != null) {
                        inProgressUploads.remove(fileObject.key);
                        inProgressCount.decrementAndGet();
                    }
                    scheduleNewUpload();
                    if (inProgressCount.get() == 0)
                        HelperSetAction.sendCancel(fileObject.messageId);
                    makeFailed(fileObject.messageId);
                    if (fileObject.messageType == ProtoGlobal.RoomMessageType.STORY) {
                        MessageDataStorage.getInstance(AccountManager.selectedAccount).updateStorySentStatus(AccountManager.getInstance().getCurrentUser().getId(), false);
                        MessageDataStorage.getInstance(AccountManager.selectedAccount).updateStoryStatus(fileObject.messageId, MessageObject.STATUS_FAILED);
                        G.runOnUiThread(() -> EventManager.getInstance(AccountManager.selectedAccount).postEvent(EventManager.STORY_UPLOADED_FAILED, fileObject.messageId));
                    }
                    if (fileObject.onUploadListener != null) {
                        fileObject.onUploadListener.onError(String.valueOf(fileObject.messageId));
                    }
                }
            });
            uploadQueue.add(existedRequest);
            scheduleNewUpload();
        }
    }
}
Also used : UploadHttpRequest(net.iGap.module.upload.UploadHttpRequest) StoryObject(net.iGap.story.StoryObject) ArrayList(java.util.ArrayList) UploadObject(net.iGap.module.upload.UploadObject) Nullable(androidx.annotation.Nullable)

Example 4 with UploadObject

use of net.iGap.module.upload.UploadObject 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)

Example 5 with UploadObject

use of net.iGap.module.upload.UploadObject in project iGap-Android by KianIranian-STDG.

the class AbstractMessage method bindView.

@Override
@CallSuper
public void bindView(final VH holder, List<Object> payloads) {
    super.bindView(holder, payloads);
    if (messageObject == null) {
        return;
    }
    NewChatItemHolder mHolder;
    if (holder instanceof NewChatItemHolder) {
        mHolder = (NewChatItemHolder) holder;
    } else if (holder instanceof LogItem.ViewHolder || holder instanceof LogWalletCardToCard.ViewHolder || holder instanceof LogWalletBill.ViewHolder || holder instanceof LogWalletTopup.ViewHolder || holder instanceof LogWallet.ViewHolder) {
        messageClickListener.onItemShowingMessageId(messageObject);
        return;
    } else {
        return;
    }
    this.holder = holder;
    if (messageObject.forwardedMessage == null && messageObject.isSenderMe() && attachment != null && messageObject.status == MessageObject.STATUS_SENDING) {
        EventManager.getInstance(currentAccount).addObserver(EventManager.ON_UPLOAD_PROGRESS, this);
        EventManager.getInstance(currentAccount).addObserver(EventManager.ON_UPLOAD_COMPRESS, this);
        if (!Uploader.getInstance().isCompressingOrUploading(messageObject.id + "")) {
            // TODO: 12/29/20 MESSAGE_REFACTOR
            UploadObject fileObject = UploadObject.createForMessage(messageObject, type);
            if (fileObject != null) {
                Uploader.getInstance().upload(fileObject);
            }
        } else {
            MessageProgress messageProgress = ((IProgress) holder).getProgress();
            int progress = Uploader.getInstance().getUploadProgress(messageObject.id + "");
            messageProgress.withProgress(progress);
            receivedEvent(EventManager.ON_UPLOAD_PROGRESS, AccountManager.selectedAccount, String.valueOf(messageObject.id), progress);
        }
    } else {
        EventManager.getInstance(currentAccount).removeObserver(EventManager.ON_UPLOAD_PROGRESS, this);
        EventManager.getInstance(currentAccount).removeObserver(EventManager.ON_UPLOAD_COMPRESS, this);
    }
    if (attachment != null) {
        EventManager.getInstance(currentAccount).addObserver(EventManager.ON_UPLOAD_COMPRESS, this);
        EventManager.getInstance(currentAccount).addObserver(EventManager.ON_UPLOAD_COMPLETED, this);
        EventManager.getInstance(currentAccount).addObserver(EventManager.ON_FILE_DOWNLOAD_COMPLETED, this);
    }
    // TODO: 12/29/20 MESSAGE_REFACTOR
    mHolder.getItemContainer().setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View view) {
            OnClickRow(mHolder, view);
        }
    });
    holder.itemView.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View view) {
            OnClickRow(mHolder, view);
        }
    });
    if (holder instanceof CardToCardItem.ViewHolder) {
        CardToCardItem.ViewHolder cardToCardHolder = (CardToCardItem.ViewHolder) holder;
        cardToCardHolder.getRootView().setMinWidth(G.maxChatBox - i_Dp(R.dimen.dp100));
        cardToCardHolder.getInnerLayout().setMinimumWidth(G.maxChatBox - i_Dp(R.dimen.dp100));
        if (messageObject.forwardedMessage == null && messageObject.additionalData != null && messageObject.additionalType == AdditionalType.CARD_TO_CARD_MESSAGE) {
            CardToCardValue value = new CardToCardValue();
            try {
                JSONArray rootJsonArray = new JSONArray(messageObject.additionalData);
                for (int i = 0; i < rootJsonArray.length(); i++) {
                    JSONArray valuJsonArray = rootJsonArray.getJSONArray(i);
                    for (int j = 0; j < valuJsonArray.length(); j++) {
                        JSONObject rootJsonObject = new JSONObject(valuJsonArray.getJSONObject(i).toString());
                        JSONObject valueObject = rootJsonObject.getJSONObject("value");
                        String cardNumber = valueObject.getString("cardNumber");
                        int amount = valueObject.getInt("amount");
                        long userId = valueObject.getLong("userId");
                        value.setAmount(amount);
                        value.setCardNumber(cardNumber);
                        value.setUserId(userId);
                    }
                }
            } catch (JSONException e) {
                e.printStackTrace();
            }
            cardToCardHolder.setValue(value);
        }
        cardToCardHolder.setOnCardToCard(cardToCard -> {
            CardToCardHelper.NewCallCardToCard(G.currentActivity, cardToCard.getUserId(), cardToCard.getAmount(), cardToCard.getCardNumber());
        });
    }
    if (holder instanceof ChatItemWithTextHolder) {
        ChatItemWithTextHolder withTextHolder = (ChatItemWithTextHolder) holder;
        // withTextHolder.messageView.setHasEmoji(structMessage.hasEmojiInText());
        int maxsize = 0;
        withTextHolder.removeButtonLayout();
        if ((type == ProtoGlobal.Room.Type.CHANNEL) || (type == ProtoGlobal.Room.Type.CHAT) && messageObject.forwardedMessage != null) {
            maxsize = G.maxChatBox - 16;
        }
        if (maxsize > 0)
            withTextHolder.messageView.setMaxWidth(maxsize);
        if (messageObject.hasLink) {
            try {
                BetterLinkMovementMethod.linkify(Linkify.ALL, withTextHolder.messageView).setOnLinkClickListener((tv, url) -> {
                    return FragmentChat.isInSelectionMode;
                }).setOnLinkLongClickListener((tv, url) -> {
                    if (!FragmentChat.isInSelectionMode) {
                        if (HelperUrl.isTextLink(url)) {
                            G.isLinkClicked = true;
                            messageClickListener.onOpenLinkDialog(url);
                        }
                    }
                    return true;
                });
            } catch (AndroidRuntimeException runtimeException) {
                /**
                 *this try-catch added to fixing bug following bug:
                 * this bug happens because the "Android System WebView" started being
                 * installed as its own application from Android 5.0 and greater and this
                 * code happens to be running while "Android System WebView" is being updated.
                 * While its being updated the package doesn't exist so it causes this exception
                 */
                Toast.makeText(context, R.string.please_try_again, Toast.LENGTH_LONG).show();
            }
        } else {
        // remove BetterLinkMovementMethod
        }
        try {
            if (messageObject.forwardedMessage == null && messageObject.additionalData != null && messageObject.additionalType == AdditionalType.UNDER_MESSAGE_BUTTON) {
                HashMap<Integer, JSONArray> buttonList = MakeButtons.parseData(messageObject.additionalData);
                int rowSize = buttonList.size();
                for (int i = 0; i < rowSize; i++) {
                    int columSize = buttonList.get(i).length();
                    LinearLayout childLayout = MakeButtons.createLayout(((ChatItemWithTextHolder) holder).getContext());
                    for (int j = 0; j < columSize; j++) {
                        ButtonEntity buttonEntity = new Gson().fromJson(buttonList.get(i).get(j).toString(), ButtonEntity.class);
                        buttonEntity.setJsonObject(buttonList.get(i).get(j).toString());
                        childLayout = MakeButtons.addButtons(theme, buttonEntity, buttonList.get(i).length(), 1f, childLayout, (view, btnEntity) -> {
                            if (FragmentChat.isInSelectionMode) {
                                holder.itemView.performLongClick();
                                return;
                            }
                            mAdapter.onBotButtonClicked(() -> onBotBtnClick(view, btnEntity));
                        });
                    }
                    withTextHolder.addButtonLayout(childLayout);
                }
            }
        } catch (Exception e) {
            e.printStackTrace();
        }
        ((LinearLayout.LayoutParams) ((LinearLayout) withTextHolder.messageView.getParent()).getLayoutParams()).gravity = AndroidUtils.isTextRtl(messageObject.forwardedMessage != null ? messageObject.forwardedMessage.message : messageObject.message) ? Gravity.RIGHT : Gravity.LEFT;
    }
    /**
     * for return message that start showing to view
     */
    messageClickListener.onItemShowingMessageId(messageObject);
    if (isSelected() || messageObject.isSelected) {
        ((FrameLayout) holder.itemView).setForeground(new ColorDrawable(G.context.getResources().getColor(R.color.colorChatMessageSelectableItemBg)));
    } else {
        ((FrameLayout) holder.itemView).setForeground(new ColorDrawable(Color.TRANSPARENT));
    }
    /**
     * only will be called when message layout is directional-base (e.g. single chat)
     */
    if (directionalBased) {
        if (!messageObject.isSenderMe() || type == ProtoGlobal.Room.Type.CHANNEL) {
            updateLayoutForReceive(holder);
        } else if (messageObject.isSenderMe()) {
            updateLayoutForSend(holder);
        }
    }
    if (!messageObject.isTimeOrLogMessage()) {
        /**
         * check failed state ,because if is failed we want show to user even is in channel
         */
        if (mAdapter.getRealmRoom() != null && mAdapter.getRealmRoom().isValid() && mAdapter.getRealmRoom().getType() == ProtoGlobal.Room.Type.CHANNEL && ProtoGlobal.RoomMessageStatus.FAILED != ProtoGlobal.RoomMessageStatus.valueOf(messageObject.status)) {
            mHolder.getMessageStatusTv().setVisibility(View.GONE);
        } else {
            mHolder.getMessageStatusTv().setVisibility(View.VISIBLE);
            AppUtils.rightMessageStatus(mHolder.getMessageStatusTv(), ProtoGlobal.RoomMessageStatus.forNumber(messageObject.status), ProtoGlobal.RoomMessageType.forNumber(messageObject.forwardedMessage != null ? messageObject.forwardedMessage.messageType : messageObject.messageType), messageObject.isSenderMe());
        }
    }
    if (// TODO: 12/29/20 MESSAGE_REFACTOR
    messageObject.edited)
        if (messageObject.channelExtra != null && messageObject.channelExtra.getSignature() != null && messageObject.forwardedMessage.channelExtra.getSignature().length() > 0)
            mHolder.getSignatureTv().setText(mHolder.getResources().getString(R.string.edited) + " " + messageObject.forwardedMessage.channelExtra.getSignature());
        else {
            mHolder.getSignatureTv().setText(mHolder.getResources().getString(R.string.edited));
        }
    else
        mHolder.getSignatureTv().setText("");
    /**
     * display user avatar only if chat type is GROUP
     */
    View messageSenderAvatar = mHolder.getItemContainer().findViewById(R.id.messageSenderAvatar);
    if (messageSenderAvatar != null) {
        messageSenderAvatar.setVisibility(View.GONE);
    }
    replyMessageIfNeeded(holder);
    forwardMessageIfNeeded(holder);
    View messageSenderName = mHolder.getContentBloke().findViewById(R.id.messageSenderName);
    if (messageSenderName != null) {
        messageSenderName.setVisibility(View.GONE);
    }
    if (type == ProtoGlobal.Room.Type.GROUP) {
        if (!messageObject.isSenderMe()) {
            addSenderNameToGroupIfNeed(mHolder);
            if (messageSenderAvatar == null) {
                messageSenderAvatar = ViewMaker.makeCircleImageView();
                mHolder.getItemContainer().addView(messageSenderAvatar, 0);
            }
            messageSenderAvatar.setVisibility(View.VISIBLE);
            messageSenderAvatar.setOnClickListener(new View.OnClickListener() {

                @Override
                public void onClick(View v) {
                    if (FragmentChat.isInSelectionMode) {
                        holder.itemView.performLongClick();
                        return;
                    }
                    messageClickListener.onSenderAvatarClick(v, messageObject, holder.getAdapterPosition());
                }
            });
            messageSenderAvatar.setOnLongClickListener(getLongClickPerform(holder));
            final ImageView copyMessageSenderAvatar = (ImageView) messageSenderAvatar;
            mAdapter.avatarHandler.getAvatar(new ParamWithAvatarType(copyMessageSenderAvatar, messageObject.userId).avatarType(AvatarHandler.AvatarType.USER));
        }
    } else {
        FrameLayout forwardContainer = mHolder.getItemContainer().findViewById(R.id.messageForwardContainer);
        ContextThemeWrapper wrapper = new ContextThemeWrapper(holder.itemView.getContext(), Theme.getInstance().getTheme(holder.itemView.getContext()));
        if (forwardContainer == null) {
            forwardContainer = new FrameLayout(holder.itemView.getContext());
            forwardContainer.setId(R.id.messageForwardContainer);
            if (mAdapter.getRealmRoom() != null && mAdapter.getRealmRoom().getChatRoom() != null && mAdapter.getRealmRoom().getChatRoom().getPeerId() == AccountManager.getInstance().getCurrentUser().getId()) {
                mHolder.getItemContainer().addView(forwardContainer, 0, LayoutCreator.createFrame(LayoutCreator.WRAP_CONTENT, LayoutCreator.MATCH_PARENT, Gravity.BOTTOM));
            } else {
                mHolder.getItemContainer().addView(forwardContainer, 1, LayoutCreator.createFrame(LayoutCreator.WRAP_CONTENT, LayoutCreator.MATCH_PARENT, Gravity.BOTTOM));
            }
            forwardContainer.addView(mHolder.getChannelForwardIv(), LayoutCreator.createFrame(26, 26, Gravity.BOTTOM, 4, 4, 8, 4));
            forwardContainer.setVisibility(View.GONE);
        }
        if (type == ProtoGlobal.Room.Type.CHANNEL) {
            mHolder.getChannelForwardIv().setImageDrawable(VectorDrawableCompat.create(holder.itemView.getContext().getResources(), R.drawable.ic_channel_forward_light, wrapper.getTheme()));
            forwardContainer.setVisibility(View.VISIBLE);
            mHolder.getChannelForwardIv().setOnClickListener(v -> {
                if (isAllowToForward(messageObject))
                    messageClickListener.onForwardClick(messageObject);
            });
        }
        if (type == ProtoGlobal.Room.Type.CHAT && mAdapter.getRealmRoom().getChatRoom() != null && mAdapter.getRealmRoom().getChatRoom().getPeerId() == AccountManager.getInstance().getCurrentUser().getId() && !messageObject.isGiftSticker()) {
            mHolder.getChannelForwardIv().setImageDrawable(VectorDrawableCompat.create(holder.itemView.getContext().getResources(), R.drawable.ic_cloud_forward, wrapper.getTheme()));
            forwardContainer.setVisibility(View.VISIBLE);
            mHolder.getChannelForwardIv().setOnClickListener(v -> {
                if (isAllowToForward(messageObject))
                    messageClickListener.onForwardFromCloudClick(messageObject);
            });
        }
    }
    /**
     * set message time
     */
    String time = HelperCalander.getClocktime(messageObject.createTime, false);
    if (HelperCalander.isPersianUnicode) {
        mHolder.getMessageTimeTv().setText(HelperCalander.convertToUnicodeFarsiNumber(time));
    } else {
        mHolder.getMessageTimeTv().setText(time);
    }
    prepareAttachmentIfNeeded(holder, messageObject.forwardedMessage != null ? messageObject.forwardedMessage.messageType : messageObject.messageType);
    /**
     * show vote layout for channel otherwise hide layout also get message state for channel
     */
    mHolder.getVoteContainer().setVisibility(View.GONE);
    mHolder.getViewContainer().setVisibility(View.GONE);
    if (!(holder instanceof StickerItem.ViewHolder)) {
        if ((type == ProtoGlobal.Room.Type.CHANNEL)) {
            showSeenContainer(holder);
        }
    }
    // TODO: 12/29/20 MESSAGE_REFACTOR
    if (messageObject.channelExtra != null && messageObject.channelExtra.getSignature() != null && messageObject.channelExtra.getSignature().length() > 0) {
        mHolder.getContentBloke().setMinimumWidth(LayoutCreator.dp(200));
    } else if (messageObject.edited) {
        mHolder.getContentBloke().setMinimumWidth(LayoutCreator.dp(100));
    }
}
Also used : NonNull(androidx.annotation.NonNull) FileLog(net.iGap.helper.FileLog) UploadObject(net.iGap.module.upload.UploadObject) ProtoFileDownload(net.iGap.proto.ProtoFileDownload) IMAGE_VALUE(net.iGap.proto.ProtoGlobal.RoomMessageType.IMAGE_VALUE) FrameLayout(android.widget.FrameLayout) ImageView(android.widget.ImageView) ColorDrawable(android.graphics.drawable.ColorDrawable) Drawable(android.graphics.drawable.Drawable) VectorDrawableCompat(androidx.vectordrawable.graphics.drawable.VectorDrawableCompat) ReserveSpaceRoundedImageView(net.iGap.module.ReserveSpaceRoundedImageView) JSONException(org.json.JSONException) AdditionalType(net.iGap.module.additionalData.AdditionalType) HelperError(net.iGap.helper.HelperError) HelperFragment(net.iGap.helper.HelperFragment) Log(android.util.Log) ArrayMap(androidx.collection.ArrayMap) Realm(io.realm.Realm) HelperCalander(net.iGap.helper.HelperCalander) ChatSendMessageUtil(net.iGap.module.ChatSendMessageUtil) RealmRoom(net.iGap.realm.RealmRoom) Downloader(net.iGap.module.downloader.Downloader) Uploader(net.iGap.module.upload.Uploader) ViewMaker.i_Dp(net.iGap.adapter.items.chat.ViewMaker.i_Dp) Tuple(net.iGap.libs.Tuple) SHP_SETTING(net.iGap.module.SHP_SETTING) G.context(net.iGap.G.context) OnProgressUpdate(net.iGap.observers.interfaces.OnProgressUpdate) ReserveSpaceGifImageView(net.iGap.module.ReserveSpaceGifImageView) EventManager(net.iGap.observers.eventbus.EventManager) DownloadObject(net.iGap.module.downloader.DownloadObject) EmojiManager(net.iGap.libs.emojiKeyboard.emoji.EmojiManager) AttachmentObject(net.iGap.structs.AttachmentObject) HelperUrl(net.iGap.helper.HelperUrl) AbstractItem(com.mikepenz.fastadapter.items.AbstractItem) AccountManager(net.iGap.module.accountManager.AccountManager) ArrayList(java.util.ArrayList) OnMessageProgressClick(net.iGap.messageprogress.OnMessageProgressClick) ButtonActionType(net.iGap.module.additionalData.ButtonActionType) Toast(android.widget.Toast) LayoutCreator(net.iGap.helper.LayoutCreator) IMAGE_TEXT_VALUE(net.iGap.proto.ProtoGlobal.RoomMessageType.IMAGE_TEXT_VALUE) HelperCheckInternetConnection(net.iGap.helper.HelperCheckInternetConnection) AvatarHandler(net.iGap.helper.avatar.AvatarHandler) AUDIO(net.iGap.proto.ProtoGlobal.RoomMessageType.AUDIO) SpannableString(android.text.SpannableString) MessageObject(net.iGap.structs.MessageObject) StyleSpan(android.text.style.StyleSpan) TextUtils(android.text.TextUtils) CallSuper(androidx.annotation.CallSuper) File(java.io.File) ContextThemeWrapper(androidx.appcompat.view.ContextThemeWrapper) CardToCardHelper(net.iGap.helper.CardToCardHelper) Gravity(android.view.Gravity) SharedPreferences(android.content.SharedPreferences) AUDIO_VALUE(net.iGap.proto.ProtoGlobal.RoomMessageType.AUDIO_VALUE) BetterLinkMovementMethod(me.saket.bettermovementmethod.BetterLinkMovementMethod) DbManager(net.iGap.module.accountManager.DbManager) FILE_TEXT_VALUE(net.iGap.proto.ProtoGlobal.RoomMessageType.FILE_TEXT_VALUE) LinearLayout(android.widget.LinearLayout) AppUtils(net.iGap.module.AppUtils) Spannable(android.text.Spannable) Theme(net.iGap.module.Theme) MessageProgress(net.iGap.messageprogress.MessageProgress) GIF_VALUE(net.iGap.proto.ProtoGlobal.RoomMessageType.GIF_VALUE) G(net.iGap.G) LocalFileType(net.iGap.module.enums.LocalFileType) AndroidRuntimeException(android.util.AndroidRuntimeException) RealmUserInfo(net.iGap.realm.RealmUserInfo) JSONObject(org.json.JSONObject) AUDIO_TEXT_VALUE(net.iGap.proto.ProtoGlobal.RoomMessageType.AUDIO_TEXT_VALUE) IMessageItem(net.iGap.observers.interfaces.IMessageItem) Gson(com.google.gson.Gson) Locale(java.util.Locale) View(android.view.View) RecyclerView(androidx.recyclerview.widget.RecyclerView) VIDEO_VALUE(net.iGap.proto.ProtoGlobal.RoomMessageType.VIDEO_VALUE) MessagesAdapter(net.iGap.adapter.MessagesAdapter) FILE_VALUE(net.iGap.proto.ProtoGlobal.RoomMessageType.FILE_VALUE) ParamWithAvatarType(net.iGap.helper.avatar.ParamWithAvatarType) OnProgress(net.iGap.messageprogress.OnProgress) ViewGroup(android.view.ViewGroup) GIF_TEXT_VALUE(net.iGap.proto.ProtoGlobal.RoomMessageType.GIF_TEXT_VALUE) List(java.util.List) TextView(android.widget.TextView) RealmRegisteredInfo(net.iGap.realm.RealmRegisteredInfo) MusicPlayer(net.iGap.module.MusicPlayer) G.isLocationFromBot(net.iGap.G.isLocationFromBot) MaterialDialog(com.afollestad.materialdialogs.MaterialDialog) Typeface(android.graphics.Typeface) AppCompatTextView(androidx.appcompat.widget.AppCompatTextView) Context(android.content.Context) AndroidUtils(net.iGap.module.AndroidUtils) ResourcesCompat(androidx.core.content.res.ResourcesCompat) HelperGetMessageState(net.iGap.helper.HelperGetMessageState) MakeButtons(net.iGap.module.MakeButtons) HashMap(java.util.HashMap) Linkify(android.text.util.Linkify) TimeUtils(net.iGap.module.TimeUtils) AdditionalObject(net.iGap.structs.AdditionalObject) FragmentChat(net.iGap.fragments.FragmentChat) MODE_PRIVATE(android.content.Context.MODE_PRIVATE) RealmRoomMessage(net.iGap.realm.RealmRoomMessage) RealmAdditional(net.iGap.realm.RealmAdditional) HelperDownloadFile(net.iGap.helper.HelperDownloadFile) CardToCardValue(net.iGap.model.CardToCardValue) VOICE(net.iGap.proto.ProtoGlobal.RoomMessageType.VOICE) AUDIO_TEXT(net.iGap.proto.ProtoGlobal.RoomMessageType.AUDIO_TEXT) DialogAction(com.afollestad.materialdialogs.DialogAction) FragmentPaymentBill(net.iGap.fragments.FragmentPaymentBill) RequestManager(net.iGap.network.RequestManager) Color(android.graphics.Color) CountDownTimer(android.os.CountDownTimer) ButtonEntity(net.iGap.module.additionalData.ButtonEntity) ProtoGlobal(net.iGap.proto.ProtoGlobal) VIDEO_TEXT_VALUE(net.iGap.proto.ProtoGlobal.RoomMessageType.VIDEO_TEXT_VALUE) VOICE_VALUE(net.iGap.proto.ProtoGlobal.RoomMessageType.VOICE_VALUE) R(net.iGap.R) JSONArray(org.json.JSONArray) Gson(com.google.gson.Gson) SpannableString(android.text.SpannableString) ParamWithAvatarType(net.iGap.helper.avatar.ParamWithAvatarType) CardToCardValue(net.iGap.model.CardToCardValue) AndroidRuntimeException(android.util.AndroidRuntimeException) UploadObject(net.iGap.module.upload.UploadObject) ImageView(android.widget.ImageView) ReserveSpaceRoundedImageView(net.iGap.module.ReserveSpaceRoundedImageView) ReserveSpaceGifImageView(net.iGap.module.ReserveSpaceGifImageView) JSONArray(org.json.JSONArray) JSONException(org.json.JSONException) ImageView(android.widget.ImageView) ReserveSpaceRoundedImageView(net.iGap.module.ReserveSpaceRoundedImageView) ReserveSpaceGifImageView(net.iGap.module.ReserveSpaceGifImageView) View(android.view.View) RecyclerView(androidx.recyclerview.widget.RecyclerView) TextView(android.widget.TextView) AppCompatTextView(androidx.appcompat.widget.AppCompatTextView) JSONException(org.json.JSONException) AndroidRuntimeException(android.util.AndroidRuntimeException) JSONObject(org.json.JSONObject) ColorDrawable(android.graphics.drawable.ColorDrawable) ContextThemeWrapper(androidx.appcompat.view.ContextThemeWrapper) FrameLayout(android.widget.FrameLayout) ButtonEntity(net.iGap.module.additionalData.ButtonEntity) LinearLayout(android.widget.LinearLayout) MessageProgress(net.iGap.messageprogress.MessageProgress) CallSuper(androidx.annotation.CallSuper)

Aggregations

UploadObject (net.iGap.module.upload.UploadObject)5 MessageObject (net.iGap.structs.MessageObject)3 Context (android.content.Context)2 Nullable (androidx.annotation.Nullable)2 Realm (io.realm.Realm)2 ArrayList (java.util.ArrayList)2 DbManager (net.iGap.module.accountManager.DbManager)2 Uploader (net.iGap.module.upload.Uploader)2 ProtoGlobal (net.iGap.proto.ProtoGlobal)2 RealmRoom (net.iGap.realm.RealmRoom)2 RealmRoomMessage (net.iGap.realm.RealmRoomMessage)2 Activity (android.app.Activity)1 Service (android.app.Service)1 MODE_PRIVATE (android.content.Context.MODE_PRIVATE)1 Intent (android.content.Intent)1 SharedPreferences (android.content.SharedPreferences)1 Color (android.graphics.Color)1 Typeface (android.graphics.Typeface)1 ColorDrawable (android.graphics.drawable.ColorDrawable)1 Drawable (android.graphics.drawable.Drawable)1