Search in sources :

Example 1 with OnMessageProgressClick

use of net.iGap.messageprogress.OnMessageProgressClick 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 2 with OnMessageProgressClick

use of net.iGap.messageprogress.OnMessageProgressClick 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 3 with OnMessageProgressClick

use of net.iGap.messageprogress.OnMessageProgressClick 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)3 OnMessageProgressClick (net.iGap.messageprogress.OnMessageProgressClick)3 SharedPreferences (android.content.SharedPreferences)1 SpannableString (android.text.SpannableString)1 File (java.io.File)1 HelperDownloadFile (net.iGap.helper.HelperDownloadFile)1 OnProgress (net.iGap.messageprogress.OnProgress)1 ReserveSpaceGifImageView (net.iGap.module.ReserveSpaceGifImageView)1 ReserveSpaceRoundedImageView (net.iGap.module.ReserveSpaceRoundedImageView)1 ProtoGlobal (net.iGap.proto.ProtoGlobal)1