use of net.iGap.messageprogress.MessageProgress in project iGap-Android by KianIranian-STDG.
the class AbstractMessage method prepareProgress.
/**
* automatically update progress if layout has one
*
* @param holder VH
*/
public void prepareProgress(final VH holder) {
if (messageObject.isSenderMe()) {
final MessageProgress progressBar = ((IProgress) holder).getProgress();
AppUtils.setProgresColor(progressBar.progressBar);
progressBar.setVisibility(View.VISIBLE);
progressBar.withDrawable(R.drawable.ic_cancel, false);
/**
* update progress when user trying to upload or download also if
* file is compressing do this action for add listener and use later
*/
if (Uploader.getInstance().isCompressingOrUploading(messageObject.id + "") || (messageObject.status == MessageObject.STATUS_SENDING)) {
// (mMessage.status.equals(ProtoGlobal.RoomMessageStatus.SENDING.toString()) this code newly added
hideThumbnailIf(holder);
((IProgress) holder).getProgress().setVisibility(View.VISIBLE);
progressBar.withProgress(Uploader.getInstance().getUploadProgress(messageObject.id + ""));
} else {
checkForDownloading(holder);
}
int _status = messageObject.forwardedMessage != null ? messageObject.forwardedMessage.status : messageObject.status;
if (_status == MessageObject.STATUS_FAILED) {
onFaildUpload(holder);
}
} else {
checkForDownloading(holder);
}
}
use of net.iGap.messageprogress.MessageProgress 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.messageprogress.MessageProgress in project iGap-Android by KianIranian-STDG.
the class AbstractMessage method checkForDownloading.
private void checkForDownloading(VH holder) {
MessageProgress progress = ((IProgress) holder).getProgress();
AppUtils.setProgresColor(progress.progressBar);
if (Downloader.getInstance(currentAccount).isDownloading(messageObject.getAttachment().cacheId)) {
hideThumbnailIf(holder);
downLoadFile(holder, 0);
} else {
if (messageObject.getAttachment().isFileExistsOnLocal(messageObject)) {
if (messageObject.status != MessageObject.STATUS_SENDING && messageObject.status != MessageObject.STATUS_FAILED) {
progress.performProgress();
}
} else {
hideThumbnailIf(holder);
progress.withDrawable(R.drawable.ic_download, true);
progress.setVisibility(View.VISIBLE);
}
}
}
Aggregations