Search in sources :

Example 1 with LogWalletBill

use of net.iGap.adapter.items.chat.LogWalletBill in project iGap-Android by KianIranian-STDG.

the class FragmentChat method switchAddItem.

private void switchAddItem(ArrayList<StructMessageInfo> infos, boolean addTop) {
    if (prgWaiting != null && infos.size() > 0) {
        prgWaiting.setVisibility(View.GONE);
    }
    long identifier = SUID.id().get();
    for (StructMessageInfo info : infos) {
        MessageObject messageObject = MessageObject.create(info.realmRoomMessage);
        int messageType;
        if (messageObject.isForwarded()) {
            messageType = messageObject.forwardedMessage.messageType;
        } else {
            messageType = messageObject.messageType;
        }
        if (!messageObject.isTimeOrLogMessage() || (messageType == LOG_VALUE)) {
            int index = 0;
            if (addTop) {
                if (messageObject.needToShow) {
                    for (int i = 0; i < mAdapter.getAdapterItemCount(); i++) {
                        if (mAdapter.getAdapterItem(i) instanceof TimeItem) {
                            // TODO: 12/28/20 MESSAGE_REFACTOR
                            if (!RealmRoomMessage.isTimeDayDifferent(messageObject.getUpdateOrCreateTime(), mAdapter.getAdapterItem(i).messageObject.getUpdateOrCreateTime())) {
                                mAdapter.remove(i);
                            }
                            break;
                        }
                    }
                    mAdapter.add(0, new TimeItem(mAdapter, this).setMessage(makeLayoutTime(messageObject.getUpdateOrCreateTime())).withIdentifier(identifier++));
                    index = 1;
                }
            } else {
                /**
                 * don't allow for add lower messageId to bottom of list
                 */
                if (messageObject.id > biggestMessageId) {
                    if (messageObject.status != MessageObject.STATUS_SENDING) {
                        biggestMessageId = messageObject.id;
                    }
                } else {
                    continue;
                }
                if (lastMessageId == messageObject.id) {
                    continue;
                } else {
                    lastMessageId = messageObject.id;
                }
                if (messageObject.needToShow) {
                    if (mAdapter.getItemCount() > 0) {
                        if (mAdapter.getAdapterItem(mAdapter.getItemCount() - 1).messageObject != null && RealmRoomMessage.isTimeDayDifferent(messageObject.getUpdateOrCreateTime(), mAdapter.getAdapterItem(mAdapter.getItemCount() - 1).messageObject.getUpdateOrCreateTime())) {
                            mAdapter.add(new TimeItem(mAdapter, this).setMessage(makeLayoutTime(messageObject.getUpdateOrCreateTime())).withIdentifier(identifier++));
                        }
                    } else {
                        mAdapter.add(new TimeItem(mAdapter, this).setMessage(makeLayoutTime(messageObject.getUpdateOrCreateTime())).withIdentifier(identifier++));
                    }
                }
            }
            switch(messageType) {
                case TEXT_VALUE:
                case STORY_REPLY_VALUE:
                    if (messageObject.getAdditional() != null && messageObject.getAdditional().type == AdditionalType.CARD_TO_CARD_MESSAGE)
                        if (!addTop) {
                            mAdapter.add(new CardToCardItem(mAdapter, chatType, FragmentChat.this).setMessage(messageObject).withIdentifier(identifier));
                        } else {
                            mAdapter.add(index, new CardToCardItem(mAdapter, chatType, FragmentChat.this).setMessage(messageObject).withIdentifier(identifier));
                        }
                    else {
                        if (!addTop) {
                            mAdapter.add(new TextItem(mAdapter, chatType, this).setMessage(messageObject).withIdentifier(identifier));
                        } else {
                            mAdapter.add(index, new TextItem(mAdapter, chatType, this).setMessage(messageObject).withIdentifier(identifier));
                        }
                    }
                    break;
                case WALLET_VALUE:
                    if (messageObject.wallet.cardToCard != null) {
                        if (!addTop) {
                            mAdapter.add(new LogWalletCardToCard(mAdapter, chatType, this).setMessage(messageObject).withIdentifier(identifier));
                        } else {
                            mAdapter.add(index, new LogWalletCardToCard(mAdapter, chatType, this).setMessage(messageObject).withIdentifier(identifier));
                        }
                    } else if (messageObject.wallet.topupObject != null) {
                        if (!addTop) {
                            mAdapter.add(new LogWalletTopup(mAdapter, chatType, this).setMessage(messageObject).withIdentifier(identifier));
                        } else {
                            mAdapter.add(index, new LogWalletTopup(mAdapter, chatType, this).setMessage(messageObject).withIdentifier(identifier));
                        }
                        ;
                    } else if (messageObject.wallet.billObject != null) {
                        if (!addTop) {
                            mAdapter.add(new LogWalletBill(mAdapter, chatType, this).setMessage(messageObject).withIdentifier(identifier));
                        } else {
                            mAdapter.add(index, new LogWalletBill(mAdapter, chatType, this).setMessage(messageObject).withIdentifier(identifier));
                        }
                    } else {
                        if (!addTop) {
                            mAdapter.add(new LogWallet(mAdapter, chatType, this).setMessage(messageObject).withIdentifier(identifier));
                        } else {
                            mAdapter.add(index, new LogWallet(mAdapter, chatType, this).setMessage(messageObject).withIdentifier(identifier));
                        }
                    }
                    break;
                case IMAGE_VALUE:
                case IMAGE_TEXT_VALUE:
                    if (!addTop) {
                        mAdapter.add(new ImageWithTextItem(mAdapter, chatType, this).setMessage(messageObject).withIdentifier(identifier));
                    } else {
                        mAdapter.add(index, new ImageWithTextItem(mAdapter, chatType, this).setMessage(messageObject).withIdentifier(identifier));
                    }
                    break;
                case VIDEO_VALUE:
                case VIDEO_TEXT_VALUE:
                    if (!addTop) {
                        mAdapter.add(new VideoWithTextItem(mAdapter, chatType, this).setMessage(messageObject).withIdentifier(identifier));
                    } else {
                        mAdapter.add(index, new VideoWithTextItem(mAdapter, chatType, this).setMessage(messageObject).withIdentifier(identifier));
                    }
                    break;
                case LOCATION_VALUE:
                    if (!addTop) {
                        mAdapter.add(new LocationItem(mAdapter, chatType, this, getActivity()).setMessage(messageObject).withIdentifier(identifier));
                    } else {
                        mAdapter.add(index, new LocationItem(mAdapter, chatType, this, getActivity()).setMessage(messageObject).withIdentifier(identifier));
                    }
                    break;
                case FILE_VALUE:
                case FILE_TEXT_VALUE:
                    if (!addTop) {
                        mAdapter.add(new FileItem(mAdapter, chatType, this).setMessage(messageObject).withIdentifier(identifier));
                    } else {
                        mAdapter.add(index, new FileItem(mAdapter, chatType, this).setMessage(messageObject).withIdentifier(identifier));
                    }
                    break;
                case STICKER_VALUE:
                    if (messageObject.getAdditional() != null && messageObject.getAdditional().type == AdditionalType.GIFT_STICKER) {
                    } else if (messageObject.getAttachment() != null && messageObject.getAttachment().name != null && messageObject.getAttachment().isAnimatedSticker()) {
                        if (!addTop) {
                            mAdapter.add(new AnimatedStickerItem(mAdapter, chatType, this).setMessage(messageObject).withIdentifier(identifier));
                        } else {
                            mAdapter.add(index, new AnimatedStickerItem(mAdapter, chatType, this).setMessage(messageObject).withIdentifier(identifier));
                        }
                    } else {
                        if (messageObject.getAttachment() != null) {
                            if (!addTop) {
                                mAdapter.add(new StickerItem(mAdapter, chatType, this).setMessage(messageObject).withIdentifier(identifier));
                            } else {
                                mAdapter.add(index, new StickerItem(mAdapter, chatType, this).setMessage(messageObject).withIdentifier(identifier));
                            }
                        }
                    }
                    break;
                case VOICE_VALUE:
                    if (!addTop) {
                        mAdapter.add(new VoiceItem(mAdapter, chatType, this).setMessage(messageObject).withIdentifier(identifier));
                    } else {
                        mAdapter.add(index, new VoiceItem(mAdapter, chatType, this).setMessage(messageObject).withIdentifier(identifier));
                    }
                    break;
                case AUDIO_VALUE:
                case AUDIO_TEXT_VALUE:
                    if (!addTop) {
                        mAdapter.add(new AudioItem(mAdapter, chatType, this).setMessage(messageObject).withIdentifier(identifier));
                    } else {
                        mAdapter.add(index, new AudioItem(mAdapter, chatType, this).setMessage(messageObject).withIdentifier(identifier));
                    }
                    break;
                case CONTACT_VALUE:
                    if (!addTop) {
                        mAdapter.add(new ContactItem(getActivity(), mAdapter, chatType, this).setMessage(messageObject).withIdentifier(identifier));
                    } else {
                        mAdapter.add(index, new ContactItem(getActivity(), mAdapter, chatType, this).setMessage(messageObject).withIdentifier(identifier));
                    }
                    break;
                case GIF_VALUE:
                case GIF_TEXT_VALUE:
                    if (!addTop) {
                        mAdapter.add(new GifWithTextItem(mAdapter, chatType, this).setMessage(messageObject).withIdentifier(identifier));
                    } else {
                        mAdapter.add(index, new GifWithTextItem(mAdapter, chatType, this).setMessage(messageObject).withIdentifier(identifier));
                    }
                    break;
                case LOG_VALUE:
                    if (messageObject.needToShow) {
                        if (!addTop) {
                            mAdapter.add(new LogItem(mAdapter, this).setMessage(messageObject).withIdentifier(identifier));
                        } else {
                            mAdapter.add(index, new LogItem(mAdapter, this).setMessage(messageObject).withIdentifier(identifier));
                        }
                    }
                    break;
            }
        }
        identifier++;
    }
}
Also used : StickerItem(net.iGap.adapter.items.chat.StickerItem) AnimatedStickerItem(net.iGap.adapter.items.chat.AnimatedStickerItem) RealmStickerItem(net.iGap.realm.RealmStickerItem) GifWithTextItem(net.iGap.adapter.items.chat.GifWithTextItem) ImageWithTextItem(net.iGap.adapter.items.chat.ImageWithTextItem) StructMessageInfo(net.iGap.module.structs.StructMessageInfo) TimeItem(net.iGap.adapter.items.chat.TimeItem) VideoWithTextItem(net.iGap.adapter.items.chat.VideoWithTextItem) TextItem(net.iGap.adapter.items.chat.TextItem) GifWithTextItem(net.iGap.adapter.items.chat.GifWithTextItem) ImageWithTextItem(net.iGap.adapter.items.chat.ImageWithTextItem) LocationItem(net.iGap.adapter.items.chat.LocationItem) IUpdateLogItem(net.iGap.observers.interfaces.IUpdateLogItem) LogItem(net.iGap.adapter.items.chat.LogItem) ContactItem(net.iGap.adapter.items.chat.ContactItem) LogWallet(net.iGap.adapter.items.chat.LogWallet) LogWalletBill(net.iGap.adapter.items.chat.LogWalletBill) AudioItem(net.iGap.adapter.items.chat.AudioItem) SuppressLint(android.annotation.SuppressLint) AnimatedStickerItem(net.iGap.adapter.items.chat.AnimatedStickerItem) VideoWithTextItem(net.iGap.adapter.items.chat.VideoWithTextItem) CardToCardItem(net.iGap.adapter.items.chat.CardToCardItem) FileItem(net.iGap.adapter.items.chat.FileItem) LogWalletTopup(net.iGap.adapter.items.chat.LogWalletTopup) VoiceItem(net.iGap.adapter.items.chat.VoiceItem) LogWalletCardToCard(net.iGap.adapter.items.chat.LogWalletCardToCard) MessageObject(net.iGap.structs.MessageObject)

Aggregations

SuppressLint (android.annotation.SuppressLint)1 AnimatedStickerItem (net.iGap.adapter.items.chat.AnimatedStickerItem)1 AudioItem (net.iGap.adapter.items.chat.AudioItem)1 CardToCardItem (net.iGap.adapter.items.chat.CardToCardItem)1 ContactItem (net.iGap.adapter.items.chat.ContactItem)1 FileItem (net.iGap.adapter.items.chat.FileItem)1 GifWithTextItem (net.iGap.adapter.items.chat.GifWithTextItem)1 ImageWithTextItem (net.iGap.adapter.items.chat.ImageWithTextItem)1 LocationItem (net.iGap.adapter.items.chat.LocationItem)1 LogItem (net.iGap.adapter.items.chat.LogItem)1 LogWallet (net.iGap.adapter.items.chat.LogWallet)1 LogWalletBill (net.iGap.adapter.items.chat.LogWalletBill)1 LogWalletCardToCard (net.iGap.adapter.items.chat.LogWalletCardToCard)1 LogWalletTopup (net.iGap.adapter.items.chat.LogWalletTopup)1 StickerItem (net.iGap.adapter.items.chat.StickerItem)1 TextItem (net.iGap.adapter.items.chat.TextItem)1 TimeItem (net.iGap.adapter.items.chat.TimeItem)1 VideoWithTextItem (net.iGap.adapter.items.chat.VideoWithTextItem)1 VoiceItem (net.iGap.adapter.items.chat.VoiceItem)1 StructMessageInfo (net.iGap.module.structs.StructMessageInfo)1