Search in sources :

Example 1 with MessageProgress

use of net.iGap.messageprogress.MessageProgress in project iGap-Android by KianIranian-STDG.

the class AbstractMessage method onProgressFinish.

public void onProgressFinish(VH holder, AttachmentObject attachment, int messageType) {
    if (attachment == null || !attachment.isFileExistsOnLocal(messageObject)) {
        return;
    }
    if (!(holder instanceof IProgress)) {
        return;
    }
    final MessageProgress _Progress = ((IProgress) holder).getProgress();
    if (_Progress.getTag() == null || !_Progress.getTag().equals(messageObject.id)) {
        return;
    }
    if (Uploader.getInstance().isCompressingOrUploading(messageObject.id + "") || Downloader.getInstance(currentAccount).isDownloading(attachment.cacheId)) {
        return;
    }
    _Progress.setVisibility(View.GONE);
    View thumbnailView = ((IThumbNailItem) holder).getThumbNailImageView();
    thumbnailView.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View view) {
            if (FragmentChat.isInSelectionMode) {
                holder.itemView.performLongClick();
            }
        }
    });
    thumbnailView.setOnLongClickListener(getLongClickPerform(holder));
    _Progress.withDrawable(null, true);
    switch(messageType) {
        case VIDEO_VALUE:
        case VIDEO_TEXT_VALUE:
            ((IProgress) holder).getProgress().setVisibility(View.VISIBLE);
            _Progress.withDrawable(R.drawable.ic_play, true);
            break;
        case AUDIO_VALUE:
        case VOICE_VALUE:
        case AUDIO_TEXT_VALUE:
            break;
        case FILE_VALUE:
        case FILE_TEXT_VALUE:
        case IMAGE_VALUE:
        case IMAGE_TEXT_VALUE:
            thumbnailView.setOnClickListener(new View.OnClickListener() {

                @Override
                public void onClick(View v) {
                    forOnCLick(holder);
                }
            });
            break;
        case GIF_VALUE:
        case GIF_TEXT_VALUE:
            thumbnailView.setOnClickListener(new View.OnClickListener() {

                @Override
                public void onClick(View v) {
                    forOnCLick(holder);
                }
            });
            SharedPreferences sharedPreferences = holder.itemView.getContext().getSharedPreferences(SHP_SETTING.FILE_NAME, MODE_PRIVATE);
            if (sharedPreferences.getInt(SHP_SETTING.KEY_AUTOPLAY_GIFS, SHP_SETTING.Defaults.KEY_AUTOPLAY_GIFS) == 0) {
                ((IProgress) holder).getProgress().setVisibility(View.VISIBLE);
                _Progress.withDrawable(R.mipmap.photogif, true);
            } else {
                ((IProgress) holder).getProgress().setVisibility(View.INVISIBLE);
            }
            break;
    }
}
Also used : SharedPreferences(android.content.SharedPreferences) ImageView(android.widget.ImageView) ReserveSpaceRoundedImageView(net.iGap.module.ReserveSpaceRoundedImageView) ReserveSpaceGifImageView(net.iGap.module.ReserveSpaceGifImageView) View(android.view.View) RecyclerView(androidx.recyclerview.widget.RecyclerView) TextView(android.widget.TextView) AppCompatTextView(androidx.appcompat.widget.AppCompatTextView) MessageProgress(net.iGap.messageprogress.MessageProgress)

Example 2 with MessageProgress

use of net.iGap.messageprogress.MessageProgress in project iGap-Android by KianIranian-STDG.

the class AbstractMessage method forOnCLick.

private void forOnCLick(VH holder) {
    if (FragmentChat.isInSelectionMode) {
        holder.itemView.performLongClick();
        return;
    }
    final MessageProgress progress = ((IProgress) holder).getProgress();
    AppUtils.setProgresColor(progress.progressBar);
    View thumbnail = ((IThumbNailItem) holder).getThumbNailImageView();
    if (Uploader.getInstance().isCompressingOrUploading(messageObject.id + "")) {
        if (messageObject.status == MessageObject.STATUS_FAILED && hasFileSize(attachment.filePath)) {
            if (RequestManager.getInstance(AccountManager.selectedAccount).isUserLogin()) {
                messageClickListener.onFailedMessageClick(progress, messageObject, holder.getAdapterPosition());
            } else {
                HelperError.showSnackMessage(G.context.getString(R.string.there_is_no_connection_to_server), false);
            }
        } else {
            messageClickListener.onUploadOrCompressCancel(progress, messageObject, holder.getAdapterPosition());
        }
    } else if (Downloader.getInstance(currentAccount).isDownloading(attachment.cacheId)) {
        Downloader.getInstance(currentAccount).cancelDownload(attachment.cacheId);
    } else {
        thumbnail.setVisibility(View.VISIBLE);
        if (attachment.isFileExistsOnLocal(messageObject)) {
            int _status = messageObject.forwardedMessage != null ? messageObject.forwardedMessage.status : messageObject.status;
            int _type = messageObject.forwardedMessage != null ? messageObject.forwardedMessage.messageType : messageObject.messageType;
            if (_status == MessageObject.STATUS_FAILED) {
                messageClickListener.onFailedMessageClick(progress, messageObject, holder.getAdapterPosition());
            } else {
                /**
                 * avoid from show GIF in fragment show image
                 */
                if (_type == GIF_VALUE || _type == GIF_TEXT_VALUE) {
                    try {
                        onPlayPauseGIF(holder, attachment.filePath);
                    } catch (ClassCastException e) {
                        FileLog.e(e);
                    }
                } else {
                    messageClickListener.onOpenClick(progress, messageObject, holder.getAdapterPosition());
                }
            }
        } else {
            downLoadFile(holder, 2);
        }
    }
}
Also used : ImageView(android.widget.ImageView) ReserveSpaceRoundedImageView(net.iGap.module.ReserveSpaceRoundedImageView) ReserveSpaceGifImageView(net.iGap.module.ReserveSpaceGifImageView) View(android.view.View) RecyclerView(androidx.recyclerview.widget.RecyclerView) TextView(android.widget.TextView) AppCompatTextView(androidx.appcompat.widget.AppCompatTextView) MessageProgress(net.iGap.messageprogress.MessageProgress)

Example 3 with MessageProgress

use of net.iGap.messageprogress.MessageProgress in project iGap-Android by KianIranian-STDG.

the class AbstractMessage method prepareAttachmentIfNeeded.

private void prepareAttachmentIfNeeded(final VH holder, final int messageType) {
    /**
     * runs if message has attachment
     */
    NewChatItemHolder mHolder;
    if (holder instanceof NewChatItemHolder)
        mHolder = (NewChatItemHolder) holder;
    else
        return;
    if (attachment != null) {
        if (mHolder instanceof VideoWithTextItem.ViewHolder || mHolder instanceof ImageWithTextItem.ViewHolder) {
            ReserveSpaceRoundedImageView imageViewReservedSpace = (ReserveSpaceRoundedImageView) ((IThumbNailItem) holder).getThumbNailImageView();
            int _with = attachment.width;
            int _hight = attachment.height;
            if (_with == 0) {
                if (attachment.smallThumbnail != null) {
                    _with = attachment.smallThumbnail.width;
                    _hight = attachment.smallThumbnail.height;
                }
            }
            boolean setDefualtImage = false;
            if (messageType == ProtoGlobal.RoomMessageType.IMAGE_VALUE || messageType == IMAGE_TEXT_VALUE) {
                if (attachment.filePath == null && attachment.thumbnailPath == null && _with == 0) {
                    _with = (int) G.context.getResources().getDimension(R.dimen.dp120);
                    _hight = (int) G.context.getResources().getDimension(R.dimen.dp120);
                    setDefualtImage = true;
                }
            } else {
                if (attachment.thumbnailPath == null && _with == 0) {
                    _with = (int) G.context.getResources().getDimension(R.dimen.dp120);
                    _hight = (int) G.context.getResources().getDimension(R.dimen.dp120);
                    setDefualtImage = true;
                }
            }
            int[] dimens = imageViewReservedSpace.reserveSpace(_with, _hight, type);
            if (dimens[0] != 0 && dimens[1] != 0) {
                mHolder.getContentBloke().getLayoutParams().width = dimens[0];
            }
            if (setDefualtImage) {
                imageViewReservedSpace.setImageResource(R.mipmap.difaultimage);
            }
            if (holder instanceof VideoWithTextItem.ViewHolder) {
                ((VideoWithTextItem.ViewHolder) holder).getMoreButton().setOnClickListener(v -> {
                    OnClickRow(((VideoWithTextItem.ViewHolder) holder), v);
                });
            }
            if (holder instanceof ImageWithTextItem.ViewHolder) {
                ((ImageWithTextItem.ViewHolder) holder).getMoreButton().setOnClickListener(v -> {
                    OnClickRow(((ImageWithTextItem.ViewHolder) holder), v);
                });
            }
        } else if (messageType == ProtoGlobal.RoomMessageType.GIF_VALUE || messageType == GIF_TEXT_VALUE) {
            ReserveSpaceGifImageView imageViewReservedSpace = (ReserveSpaceGifImageView) ((IThumbNailItem) holder).getThumbNailImageView();
            int _with = attachment.width;
            int _hight = attachment.height;
            if (_with == 0) {
                _with = (int) G.context.getResources().getDimension(R.dimen.dp200);
            }
            if (_hight == 0) {
                _hight = (int) G.context.getResources().getDimension(R.dimen.dp200);
            }
            int[] dimens = imageViewReservedSpace.reserveSpace(_with, _hight, type);
            mHolder.getContentBloke().getLayoutParams().width = dimens[0];
        }
        String filePath = null;
        if (attachment.filePath != null) {
            filePath = attachment.filePath;
            if (!new File(filePath).exists()) {
                attachment.filePath = filePath = AndroidUtils.getFilePathWithCashId(attachment.cacheId, attachment.name, messageObject.messageType);
            }
        } else if (messageObject.isFileExistWithCacheId(false)) {
            filePath = messageObject.getCacheFile(false);
        }
        if (attachment.isFileExistsOnLocalAndIsImage(messageObject)) {
            onLoadThumbnailFromLocal(holder, getCacheId(messageObject), filePath, LocalFileType.FILE);
        } else if (messageType == ProtoGlobal.RoomMessageType.VOICE_VALUE || messageType == ProtoGlobal.RoomMessageType.AUDIO_VALUE || messageType == AUDIO_TEXT_VALUE) {
            onLoadThumbnailFromLocal(holder, getCacheId(messageObject), filePath, LocalFileType.FILE);
        } else {
            if (attachment.isThumbnailExistsOnLocal(messageObject)) {
                String thumbPath = attachment.thumbnailPath != null ? attachment.thumbnailPath : messageObject.getCacheFile(true);
                onLoadThumbnailFromLocal(holder, getCacheId(messageObject), thumbPath, LocalFileType.THUMBNAIL);
            } else {
                if (messageType != ProtoGlobal.RoomMessageType.CONTACT_VALUE) {
                    if (mHolder instanceof StickerItem.ViewHolder || mHolder instanceof AnimatedStickerItem.ViewHolder) {
                    } else {
                        downLoadThumbnail(holder);
                    }
                }
            }
        }
        if (hasProgress(holder)) {
            final MessageProgress _Progress = ((IProgress) holder).getProgress();
            _Progress.setTag(messageObject.id);
            _Progress.setVisibility(View.GONE);
            if (mHolder instanceof StickerItem.ViewHolder || mHolder instanceof AnimatedStickerItem.ViewHolder)
                return;
            AppUtils.setProgresColor(_Progress.progressBar);
            _Progress.withOnMessageProgress(new OnMessageProgressClick() {

                @Override
                public void onMessageProgressClick(MessageProgress progress) {
                    forOnCLick(holder);
                }
            });
            if (!attachment.isFileExistsOnLocal(messageObject)) {
                if (HelperCheckInternetConnection.currentConnectivityType == null) {
                    checkAutoDownload(holder, holder.itemView.getContext(), HelperCheckInternetConnection.ConnectivityType.WIFI);
                    checkAutoDownload(holder, holder.itemView.getContext(), HelperCheckInternetConnection.ConnectivityType.MOBILE);
                } else {
                    checkAutoDownload(holder, holder.itemView.getContext(), HelperCheckInternetConnection.currentConnectivityType);
                }
            }
            _Progress.withOnProgress(new OnProgress() {

                @Override
                public void onProgressFinished() {
                    onProgressFinish(holder, attachment, messageType);
                }
            });
            prepareProgress(holder);
        }
    }
}
Also used : SpannableString(android.text.SpannableString) OnProgress(net.iGap.messageprogress.OnProgress) ReserveSpaceGifImageView(net.iGap.module.ReserveSpaceGifImageView) OnMessageProgressClick(net.iGap.messageprogress.OnMessageProgressClick) File(java.io.File) HelperDownloadFile(net.iGap.helper.HelperDownloadFile) ReserveSpaceRoundedImageView(net.iGap.module.ReserveSpaceRoundedImageView) MessageProgress(net.iGap.messageprogress.MessageProgress)

Example 4 with MessageProgress

use of net.iGap.messageprogress.MessageProgress in project iGap-Android by KianIranian-STDG.

the class AbstractMessage method checkAutoDownload.

private void checkAutoDownload(final VH holder, Context context, HelperCheckInternetConnection.ConnectivityType connectionMode) {
    if (HelperDownloadFile.getInstance().manuallyStoppedDownload.contains(attachment.cacheId)) {
        // for avoid from reDownload in autoDownload state , after that user manually stopped download.
        return;
    }
    SharedPreferences sharedPreferences = context.getSharedPreferences(SHP_SETTING.FILE_NAME, MODE_PRIVATE);
    ProtoGlobal.RoomMessageType messageType;
    if (messageObject.forwardedMessage != null) {
        messageType = ProtoGlobal.RoomMessageType.forNumber(messageObject.forwardedMessage.messageType);
    } else {
        messageType = ProtoGlobal.RoomMessageType.forNumber(messageObject.messageType);
    }
    switch(messageType) {
        case IMAGE:
        case IMAGE_TEXT:
            switch(connectionMode) {
                case MOBILE:
                    setClickListener(sharedPreferences, SHP_SETTING.KEY_AD_DATA_PHOTO, holder);
                    break;
                case WIFI:
                    setClickListener(sharedPreferences, SHP_SETTING.KEY_AD_WIFI_PHOTO, holder);
                    break;
            }
            break;
        case VOICE:
            switch(connectionMode) {
                case MOBILE:
                    setClickListener(sharedPreferences, SHP_SETTING.KEY_AD_DATA_VOICE_MESSAGE, holder);
                    break;
                case WIFI:
                    setClickListener(sharedPreferences, SHP_SETTING.KEY_AD_WIFI_VOICE_MESSAGE, holder);
                    break;
            }
            break;
        case VIDEO:
        case VIDEO_TEXT:
            switch(connectionMode) {
                case MOBILE:
                    setClickListener(sharedPreferences, SHP_SETTING.KEY_AD_DATA_VIDEO, holder);
                    break;
                case WIFI:
                    setClickListener(sharedPreferences, SHP_SETTING.KEY_AD_WIFI_VIDEO, holder);
                    break;
            }
            break;
        case FILE:
        case FILE_TEXT:
            switch(connectionMode) {
                case MOBILE:
                    setClickListener(sharedPreferences, SHP_SETTING.KEY_AD_DATA_FILE, holder);
                    break;
                case WIFI:
                    setClickListener(sharedPreferences, SHP_SETTING.KEY_AD_WIFI_FILE, holder);
                    break;
            }
            break;
        case AUDIO:
        case AUDIO_TEXT:
            switch(connectionMode) {
                case MOBILE:
                    setClickListener(sharedPreferences, SHP_SETTING.KEY_AD_DATA_MUSIC, holder);
                    break;
                case WIFI:
                    setClickListener(sharedPreferences, SHP_SETTING.KEY_AD_WIFI_MUSIC, holder);
                    break;
            }
            break;
        case GIF:
        case GIF_TEXT:
            switch(connectionMode) {
                case MOBILE:
                    setClickListener(sharedPreferences, SHP_SETTING.KEY_AD_DATA_GIF, holder);
                    break;
                case WIFI:
                    setClickListener(sharedPreferences, SHP_SETTING.KEY_AD_WIFI_GIF, holder);
                    break;
            }
            break;
        default:
            MessageProgress _Progress = ((IProgress) holder).getProgress();
            AppUtils.setProgresColor(_Progress.progressBar);
            _Progress.withOnMessageProgress(new OnMessageProgressClick() {

                @Override
                public void onMessageProgressClick(MessageProgress progress) {
                    forOnCLick(holder);
                }
            });
            break;
    }
}
Also used : SharedPreferences(android.content.SharedPreferences) ProtoGlobal(net.iGap.proto.ProtoGlobal) OnMessageProgressClick(net.iGap.messageprogress.OnMessageProgressClick) MessageProgress(net.iGap.messageprogress.MessageProgress)

Example 5 with MessageProgress

use of net.iGap.messageprogress.MessageProgress in project iGap-Android by KianIranian-STDG.

the class AbstractMessage method setClickListener.

private void setClickListener(SharedPreferences sharedPreferences, String key, final VH holder) {
    /**
     * if type was gif auto file start auto download
     */
    if (sharedPreferences.getInt(key, ((key.equals(SHP_SETTING.KEY_AD_DATA_GIF) || key.equals(SHP_SETTING.KEY_AD_WIFI_GIF)) ? 5 : -1)) != -1 || sharedPreferences.getInt(key, ((key.equals(SHP_SETTING.KEY_AD_DATA_VOICE_MESSAGE) || key.equals(SHP_SETTING.KEY_AD_WIFI_VOICE_MESSAGE)) ? 1 : -1)) != -1) {
        autoDownload(holder);
    } else {
        MessageProgress _Progress = ((IProgress) holder).getProgress();
        AppUtils.setProgresColor(_Progress.progressBar);
        _Progress.withOnMessageProgress(new OnMessageProgressClick() {

            @Override
            public void onMessageProgressClick(MessageProgress progress) {
                forOnCLick(holder);
            }
        });
    }
}
Also used : OnMessageProgressClick(net.iGap.messageprogress.OnMessageProgressClick) 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