use of net.iGap.structs.AttachmentObject in project iGap-Android by KianIranian-STDG.
the class AbstractMessage method downLoadFile.
void downLoadFile(final VH holder, int priority) {
AttachmentObject attachmentObject = messageObject.getAttachment();
if (attachmentObject == null || attachmentObject.cacheId == null) {
return;
}
AttachmentObject attachment = messageObject.forwardedMessage != null ? messageObject.forwardedMessage.attachment : messageObject.attachment;
final MessageProgress progressBar = ((IProgress) holder).getProgress();
AppUtils.setProgresColor(progressBar.progressBar);
final TextView textView = ((IProgress) holder).getProgressTextView();
final String tempValue = ((IProgress) holder).getTempTextView();
long size = attachment.size;
ProtoFileDownload.FileDownload.Selector selector = ProtoFileDownload.FileDownload.Selector.FILE;
boolean _isDownloading = Downloader.getInstance(currentAccount).isDownloading(attachment.cacheId);
final ProtoGlobal.RoomMessageType messageType = ProtoGlobal.RoomMessageType.forNumber(messageObject.forwardedMessage != null ? messageObject.forwardedMessage.messageType : messageObject.messageType);
// TODO: 12/29/20 MESSAGE_REFACTOR
if (attachmentObject.token != null && attachmentObject.token.length() > 0 && attachmentObject.size > 0) {
progressBar.setVisibility(View.VISIBLE);
progressBar.withDrawable(R.drawable.ic_cancel, false);
DownloadObject struct = DownloadObject.createForRoomMessage(messageObject);
if (struct == null)
return;
progressBar.withProgress(1);
Downloader.getInstance(currentAccount).download(struct, selector, priority, arg -> {
if (FragmentChat.canUpdateAfterDownload) {
G.handler.post(() -> {
switch(arg.status) {
case SUCCESS:
attachment.filePath = arg.data.getFilePath();
onProgressFinish(holder, attachment, messageType.getNumber());
loadImageOrThumbnail(messageType);
break;
case LOADING:
if (arg.data == null) {
return;
}
if (progressBar.getTag() != null && progressBar.getTag().equals(messageObject.id)) {
if (messageObject.attachment == null || !messageObject.attachment.isFileExistsOnLocal(messageObject)) {
if (arg.data.getProgress() != 100) {
progressBar.withProgress(arg.data.getProgress());
if (textView != null) {
String percent;
if (G.selectedLanguage.equals("fa")) {
percent = HelperCalander.convertToUnicodeFarsiNumber(String.valueOf(arg.data.getProgress()));
} else {
percent = String.valueOf(arg.data.getProgress());
}
textView.setText(String.format(Locale.US, "%s %s", percent, "%" + " " + "—" + " " + AndroidUtils.humanReadableByteCount(size, true)));
}
} else {
progressBar.withProgress(99);
}
}
if (arg.data.getProgress() == 100) {
int position = mAdapter.getPosition(this);
mAdapter.notifyItemChanged(position);
if (messageType == AUDIO || messageType == AUDIO_TEXT || messageType == VOICE) {
if (messageObject.roomId == MusicPlayer.roomId) {
MusicPlayer.downloadNewItem = true;
}
}
if (textView != null) {
textView.setText(AndroidUtils.humanReadableByteCount(size, true));
}
}
}
break;
case ERROR:
if (progressBar.getTag() != null && progressBar.getTag().equals(messageObject.id)) {
progressBar.withProgress(1);
progressBar.withDrawable(R.drawable.ic_download, true);
}
if (textView != null) {
textView.setText(AndroidUtils.humanReadableByteCount(size, true));
}
}
});
}
});
if (!_isDownloading) {
messageClickListener.onDownloadAllEqualCashId(attachment.cacheId, messageObject.id + "");
}
}
}
use of net.iGap.structs.AttachmentObject in project iGap-Android by KianIranian-STDG.
the class AbstractMessage method downLoadThumbnail.
private void downLoadThumbnail(final VH holder) {
if (attachment == null)
return;
ProtoFileDownload.FileDownload.Selector selector = ProtoFileDownload.FileDownload.Selector.SMALL_THUMBNAIL;
if (attachment.cacheId == null || attachment.cacheId.length() == 0) {
return;
}
final ProtoGlobal.RoomMessageType messageType = ProtoGlobal.RoomMessageType.forNumber(messageObject.forwardedMessage != null ? messageObject.forwardedMessage.messageType : messageObject.messageType);
DownloadObject fileStruct = DownloadObject.createForThumb(attachment, messageType.getNumber(), false);
if (fileStruct != null) {
AttachmentObject attachment = messageObject.forwardedMessage != null ? messageObject.forwardedMessage.attachment : messageObject.attachment;
Downloader.getInstance(currentAccount).download(fileStruct, selector, arg -> {
G.runOnUiThread(() -> {
switch(arg.status) {
case SUCCESS:
if (arg.data != null) {
if (arg.data.getSelector() == ProtoFileDownload.FileDownload.Selector.FILE_VALUE) {
attachment.filePath = arg.data.getFilePath();
} else {
attachment.thumbnailPath = arg.data.getFilePath();
}
}
if (attachment.isFileExistsOnLocalAndIsImage(messageObject) && attachment.filePath != null) {
onLoadThumbnailFromLocal(holder, null, attachment.filePath, LocalFileType.FILE);
} else if (messageType == VOICE || messageType == AUDIO || messageType == AUDIO_TEXT) {
onLoadThumbnailFromLocal(holder, null, attachment.filePath, LocalFileType.FILE);
} else if (messageType.toString().toLowerCase().contains("image") || messageType.toString().toLowerCase().contains("video") || messageType.toString().toLowerCase().contains("gif")) {
if (attachment.isThumbnailExistsOnLocal(messageObject) && attachment.thumbnailPath != null) {
onLoadThumbnailFromLocal(holder, null, attachment.thumbnailPath, LocalFileType.THUMBNAIL);
}
}
break;
case ERROR:
Log.e("TAG", "thumbnailDownloadMessage: " + arg.message);
if (arg.message != null)
FileLog.e(arg.message);
}
});
});
}
}
use of net.iGap.structs.AttachmentObject in project iGap-Android by KianIranian-STDG.
the class AbstractMessage method replyMessageIfNeeded.
@CallSuper
protected void replyMessageIfNeeded(VH holder) {
NewChatItemHolder mHolder;
if (holder instanceof NewChatItemHolder)
mHolder = (NewChatItemHolder) holder;
else
return;
mHolder.getContentBloke().setMinimumWidth(0);
mHolder.getContentBloke().setMinimumHeight(0);
/**
* set replay container visible if message was replayed, otherwise, gone it
*/
View cslr_replay_layout = ((NewChatItemHolder) holder).getContentBloke().findViewById(R.id.cslr_replay_layout);
if (cslr_replay_layout != null) {
mHolder.getContentBloke().removeView(cslr_replay_layout);
}
if ((messageObject.replayToMessage != null && !messageObject.replayToMessage.deleted) || messageObject.storyObject != null) {
final View replayView = ViewMaker.getViewReplay(((NewChatItemHolder) holder).getContext());
final TextView replyFrom = replayView.findViewById(R.id.chslr_txt_replay_from);
final AppCompatTextView replayMessage = replayView.findViewById(R.id.chslr_txt_replay_message);
replayView.setOnClickListener(v -> {
if (FragmentChat.isInSelectionMode) {
holder.itemView.performLongClick();
return;
}
messageClickListener.onReplyClick(messageObject);
});
replayView.setOnLongClickListener(getLongClickPerform(holder));
try {
// TODO: 12/29/20 MESSAGE_REFACTOR
if (messageObject.replayToMessage != null) {
AppUtils.rightFileThumbnailIcon(replayView.findViewById(R.id.chslr_imv_replay_pic), messageObject.replayToMessage.forwardedMessage == null ? messageObject.replayToMessage.messageType : messageObject.replayToMessage.forwardedMessage.messageType, messageObject.replayToMessage.forwardedMessage == null ? messageObject.replayToMessage : messageObject.replayToMessage.forwardedMessage);
} else if (messageObject.storyObject != null) {
// TODO: 8/15/21 must write a new method for this part
AttachmentObject storyAttachment = messageObject.storyObject.attachmentObject;
ImageView view = replayView.findViewById(R.id.chslr_imv_replay_pic);
if (storyAttachment != null) {
if (storyAttachment.isFileExistsOnLocal(messageObject)) {
G.imageLoader.displayImage(AndroidUtils.suitablePath(storyAttachment.filePath), view);
} else if (storyAttachment.isThumbnailExistsOnLocal(messageObject)) {
G.imageLoader.displayImage(AndroidUtils.suitablePath(storyAttachment.thumbnailPath), view);
} else {
view.setVisibility(View.GONE);
}
} else {
view.setVisibility(View.GONE);
}
}
} catch (IllegalStateException e) {
e.printStackTrace();
}
if (type == ProtoGlobal.Room.Type.CHANNEL) {
if (mAdapter.getRealmRoom() != null) {
replyFrom.setText(EmojiManager.getInstance().replaceEmoji(mAdapter.getRealmRoom().getTitle(), replyFrom.getPaint().getFontMetricsInt()));
}
} else {
RealmRegisteredInfo replayToInfo = DbManager.getInstance().doRealmTask(realm -> {
return RealmRegisteredInfo.getRegistrationInfo(realm, (messageObject.replayToMessage != null ? messageObject.replayToMessage.userId : (messageObject.storyObject != null ? messageObject.storyObject.userId : 0)));
});
if (replayToInfo != null) {
if (messageObject.storyObject != null) {
if (messageObject.storyStatus == ProtoGlobal.RoomMessageStory.Status.ACTIVE_VALUE) {
replyFrom.setText(EmojiManager.getInstance().replaceEmoji(replayToInfo.getDisplayName(), replyFrom.getPaint().getFontMetricsInt()) + " \u25CF " + context.getString(R.string.moments_string));
}
} else {
replyFrom.setText(EmojiManager.getInstance().replaceEmoji(replayToInfo.getDisplayName(), replyFrom.getPaint().getFontMetricsInt()));
}
} else if (messageObject.storyObject != null && messageObject.storyStatus != ProtoGlobal.RoomMessageStory.Status.ACTIVE_VALUE) {
replyFrom.setText(R.string.unavailable_moment);
}
}
// TODO: 12/29/20 MESSAGE_REFACTOR
String replayText = null;
if (messageObject.replayToMessage != null) {
replayText = AppUtils.replyTextMessage(messageObject.replayToMessage, holder.itemView.getResources());
} else if (messageObject.storyObject != null) {
if (messageObject.storyStatus == ProtoGlobal.RoomMessageStory.Status.ACTIVE_VALUE) {
replayText = messageObject.storyObject.caption;
ArrayList<Tuple<Integer, Integer>> places = AbstractMessage.getBoldPlaces(replayText);
replayText = AbstractMessage.removeBoldMark(replayText, places);
} else {
replayText = context.getString(R.string.mement_is_no_longer_available);
}
}
replayMessage.setText(EmojiManager.getInstance().replaceEmoji(replayText, replayMessage.getPaint().getFontMetricsInt()));
if (messageObject.isSenderMe() && type != ProtoGlobal.Room.Type.CHANNEL) {
replayView.setBackgroundResource(theme.getSendReplay(replayView.getContext()));
} else {
replayView.setBackgroundResource(theme.getReceivedReplay(replayView.getContext()));
}
replyFrom.setTextColor(theme.getSendReplayUserColor(replyFrom.getContext()));
replayMessage.setTextColor(theme.getSendMessageTextColor(replayMessage.getContext()));
// must call measure!
replyFrom.measure(0, 0);
replayMessage.measure(0, 0);
int maxWith, withMessage, withTitle;
withTitle = replyFrom.getMeasuredWidth();
withMessage = replayMessage.getMeasuredWidth();
maxWith = Math.max(withTitle, withMessage);
maxWith += i_Dp(R.dimen.dp44);
if (replayView.findViewById(R.id.chslr_imv_replay_pic).getVisibility() == View.VISIBLE) {
maxWith += i_Dp(R.dimen.dp52);
}
minWith = maxWith;
mHolder.getContentBloke().setMinimumWidth(Math.min(minWith, G.maxChatBox));
mHolder.getContentBloke().addView(replayView, 0, new LinearLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT));
replayMessage.setLayoutParams(new LinearLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT));
replyFrom.setLayoutParams(new LinearLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT));
}
}
Aggregations