Search in sources :

Example 11 with MessageProgress

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);
    }
}
Also used : MessageProgress(net.iGap.messageprogress.MessageProgress)

Example 12 with MessageProgress

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 + "");
        }
    }
}
Also used : DownloadObject(net.iGap.module.downloader.DownloadObject) ProtoGlobal(net.iGap.proto.ProtoGlobal) SpannableString(android.text.SpannableString) ProtoFileDownload(net.iGap.proto.ProtoFileDownload) AttachmentObject(net.iGap.structs.AttachmentObject) TextView(android.widget.TextView) AppCompatTextView(androidx.appcompat.widget.AppCompatTextView) MessageProgress(net.iGap.messageprogress.MessageProgress)

Example 13 with MessageProgress

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);
        }
    }
}
Also used : MessageProgress(net.iGap.messageprogress.MessageProgress)

Aggregations

MessageProgress (net.iGap.messageprogress.MessageProgress)13 TextView (android.widget.TextView)5 AppCompatTextView (androidx.appcompat.widget.AppCompatTextView)5 ProtoGlobal (net.iGap.proto.ProtoGlobal)5 SpannableString (android.text.SpannableString)4 View (android.view.View)4 RecyclerView (androidx.recyclerview.widget.RecyclerView)4 SharedPreferences (android.content.SharedPreferences)3 ImageView (android.widget.ImageView)3 OnMessageProgressClick (net.iGap.messageprogress.OnMessageProgressClick)3 ReserveSpaceGifImageView (net.iGap.module.ReserveSpaceGifImageView)3 ReserveSpaceRoundedImageView (net.iGap.module.ReserveSpaceRoundedImageView)3 DownloadObject (net.iGap.module.downloader.DownloadObject)3 ProtoFileDownload (net.iGap.proto.ProtoFileDownload)3 AttachmentObject (net.iGap.structs.AttachmentObject)3 Color (android.graphics.Color)2 ViewGroup (android.view.ViewGroup)2 LinearLayout (android.widget.LinearLayout)2 File (java.io.File)2 HelperDownloadFile (net.iGap.helper.HelperDownloadFile)2