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);
}
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;
}
}
}
}
});
});
}
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();
}
}
}
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);
}
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));
}
}
Aggregations