use of net.iGap.adapter.items.chat.FileItem 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++;
}
}
Aggregations