Search in sources :

Example 1 with ReserveSpaceGifImageView

use of net.iGap.module.ReserveSpaceGifImageView 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)

Aggregations

SpannableString (android.text.SpannableString)1 File (java.io.File)1 HelperDownloadFile (net.iGap.helper.HelperDownloadFile)1 MessageProgress (net.iGap.messageprogress.MessageProgress)1 OnMessageProgressClick (net.iGap.messageprogress.OnMessageProgressClick)1 OnProgress (net.iGap.messageprogress.OnProgress)1 ReserveSpaceGifImageView (net.iGap.module.ReserveSpaceGifImageView)1 ReserveSpaceRoundedImageView (net.iGap.module.ReserveSpaceRoundedImageView)1