Search in sources :

Example 1 with DownloadObject

use of net.iGap.module.downloader.DownloadObject in project iGap-Android by KianIranian-STDG.

the class AdapterChatBackground method onBindViewHolder.

@Override
public void onBindViewHolder(@NotNull RecyclerView.ViewHolder holder, int position) {
    if (holder instanceof ViewHolderImage) {
        if (position == 0) {
            ((ViewHolderImage) holder).messageProgress.setVisibility(View.GONE);
            ((ViewHolderImage) holder).imageView.setImageResource(R.drawable.add_chat_background_setting);
        } else {
            ((ViewHolderImage) holder).messageProgress.setVisibility(View.VISIBLE);
            ((ViewHolderImage) holder).imageView.setImageDrawable(null);
            StructWallpaper wallpaper = mList.get(position - 1);
            String path = "";
            if (wallpaper.getWallpaperType() == FragmentChatBackground.WallpaperType.proto) {
                RealmAttachment pf = wallpaper.getProtoWallpaper().getFile();
                // final String path = G.context.getExternalFilesDir(Environment.DIRECTORY_PICTURES) + "/"  + pf.getCacheId() + "_" + pf.getName();
                path = pf.getLocalFilePath() != null ? pf.getLocalFilePath() : "";
                File file = new File(path);
                if (file.exists()) {
                    G.imageLoader.displayImage(AndroidUtils.suitablePath(path), ((ViewHolderImage) holder).imageView);
                } else {
                    path = pf.getLocalThumbnailPath() != null ? pf.getLocalThumbnailPath() : "";
                    file = new File(path);
                    if (file.exists()) {
                        G.imageLoader.displayImage(AndroidUtils.suitablePath(path), ((ViewHolderImage) holder).imageView);
                    } else {
                        DownloadObject downloadObject = DownloadObject.createForRoomMessage(AttachmentObject.create(pf), ProtoGlobal.RoomMessageType.IMAGE.getNumber());
                        Downloader.getInstance(AccountManager.selectedAccount).download(downloadObject, arg -> {
                            if (arg.status == Status.SUCCESS && arg.data != null) {
                                String filepath = arg.data.getFilePath();
                                String fileToken = arg.data.getToken();
                                if (!(new File(filepath).exists())) {
                                    HelperLog.getInstance().setErrorLog(new Exception("File Dont Exist After Download !!" + filepath));
                                }
                                DbManager.getInstance().doRealmTransaction(realm -> {
                                    for (RealmAvatar realmAvatar1 : realm.where(RealmAvatar.class).equalTo("file.token", fileToken).findAll()) {
                                        realmAvatar1.getFile().setLocalFilePath(filepath);
                                    }
                                });
                                G.runOnUiThread(() -> G.handler.post(() -> {
                                    if (((ViewHolderImage) holder).imageView != null) {
                                        G.imageLoader.displayImage(AndroidUtils.suitablePath(filepath), ((ViewHolderImage) holder).imageView);
                                    }
                                }));
                            }
                        });
                    }
                }
            } else {
                G.imageLoader.displayImage(AndroidUtils.suitablePath(wallpaper.getPath()), ((ViewHolderImage) holder).imageView);
            }
            String bigImagePath;
            bigImagePath = path;
            if (new File(bigImagePath).exists()) {
                ((ViewHolderImage) holder).messageProgress.setVisibility(View.GONE);
            } else {
                ((ViewHolderImage) holder).messageProgress.setVisibility(View.VISIBLE);
                startDownload(position - 1, ((ViewHolderImage) holder).messageProgress);
            }
        }
        holder.itemView.setOnClickListener(v -> {
            if (position == 0) {
                onImageClick.onAddImageClick();
            } else {
                onImageClick.onClick(type, holder.getAdapterPosition() - 1);
            }
        });
    } else if (holder instanceof ViewHolderSolid) {
        ((ViewHolderSolid) holder).cardView.setCardBackgroundColor(Color.parseColor(solidColorList.get(position)));
        holder.itemView.setOnClickListener(v -> onImageClick.onClick(type, holder.getAdapterPosition()));
    }
}
Also used : AttachmentObject(net.iGap.structs.AttachmentObject) AndroidUtils(net.iGap.module.AndroidUtils) AppUtils(net.iGap.module.AppUtils) Environment(android.os.Environment) AppCompatImageView(androidx.appcompat.widget.AppCompatImageView) AccountManager(net.iGap.module.accountManager.AccountManager) ProtoFileDownload(net.iGap.proto.ProtoFileDownload) ChatBackgroundViewModel(net.iGap.viewmodel.ChatBackgroundViewModel) MessageProgress(net.iGap.messageprogress.MessageProgress) G(net.iGap.G) View(android.view.View) RecyclerView(androidx.recyclerview.widget.RecyclerView) CardView(androidx.cardview.widget.CardView) HelperDownloadFile(net.iGap.helper.HelperDownloadFile) Status(net.iGap.module.downloader.Status) LayoutInflater(android.view.LayoutInflater) OnProgress(net.iGap.messageprogress.OnProgress) Downloader(net.iGap.module.downloader.Downloader) ViewGroup(android.view.ViewGroup) File(java.io.File) Color(android.graphics.Color) RealmAvatar(net.iGap.realm.RealmAvatar) HelperLog(net.iGap.helper.HelperLog) List(java.util.List) StructWallpaper(net.iGap.module.StructWallpaper) ProtoGlobal(net.iGap.proto.ProtoGlobal) R(net.iGap.R) NotNull(org.jetbrains.annotations.NotNull) DbManager(net.iGap.module.accountManager.DbManager) FragmentChatBackground(net.iGap.fragments.FragmentChatBackground) DownloadObject(net.iGap.module.downloader.DownloadObject) RealmAttachment(net.iGap.realm.RealmAttachment) StructWallpaper(net.iGap.module.StructWallpaper) DownloadObject(net.iGap.module.downloader.DownloadObject) RealmAttachment(net.iGap.realm.RealmAttachment) HelperDownloadFile(net.iGap.helper.HelperDownloadFile) File(java.io.File) RealmAvatar(net.iGap.realm.RealmAvatar)

Example 2 with DownloadObject

use of net.iGap.module.downloader.DownloadObject in project iGap-Android by KianIranian-STDG.

the class StoryDisplayFragment method updateStory.

private void updateStory() {
    storyDisplayImage.setVisibility(View.VISIBLE);
    storyProgress.setVisibility(View.VISIBLE);
    storyVideoProgress.setVisibility(View.GONE);
    if (stories.get(counter).getTxt() == null || stories.get(counter).getTxt().trim().equals("") || stories.get(counter).getTxt().trim().isEmpty()) {
        captionRootView.setVisibility(View.GONE);
    } else if (stories.get(counter).getTxt() != null) {
        captionRootView.setVisibility(View.VISIBLE);
        if (stories.get(counter).getTxt().length() >= 100) {
            captionRootView.setTextSize(20);
        } else if (stories.get(counter).getTxt().length() >= 17) {
            captionRootView.setTextSize(28);
        } else {
            captionRootView.setTextSize(40);
        }
        captionRootView.setMovementMethod(ScrollingMovementMethod.getInstance());
        captionRootView.setText(stories.get(counter).getTxt());
    }
    storyTime.setText(LastSeenTimeUtil.computeTime(context, stories.get(counter).getUserId(), stories.get(counter).getStoryData() / 1000L, false, false));
    nickName.setText(stories.get(counter).getDisplayName());
    if (stories.get(counter).isRoom()) {
        chatIconTv.setVisibility(View.VISIBLE);
    } else {
        chatIconTv.setVisibility(View.GONE);
    }
    if (stories.get(counter).isVerified()) {
        verifyIconTv.setVisibility(View.VISIBLE);
    } else {
        verifyIconTv.setVisibility(View.GONE);
    }
    replyTo.setText(EmojiManager.getInstance().replaceEmoji(storyUser.getUserName(), replyTo.getPaint().getFontMetricsInt()) + " \u25CF " + context.getString(R.string.moments_string));
    replyCaption.setText(stories.get(counter).getTxt() != null ? stories.get(counter).getTxt() : "Photo");
    AttachmentObject attachmentObject = stories.get(counter).getAttachment();
    String path = attachmentObject.filePath != null ? attachmentObject.filePath : attachmentObject.thumbnailPath;
    if (stories.get(counter).getStoryId() != 0 && !getMessageDataStorage().isStorySeen(stories.get(counter).getStoryId())) {
        AbstractObject req = null;
        IG_RPC.Story_Add_View story_add_view = new IG_RPC.Story_Add_View();
        story_add_view.storyId = String.valueOf(stories.get(counter).getStoryId());
        req = story_add_view;
        getRequestManager().sendRequest(req, (response, error) -> {
            if (error == null) {
                IG_RPC.Res_Story_Add_View res = (IG_RPC.Res_Story_Add_View) response;
                getMessageDataStorage().storySetSeen(res.storyId);
            } else {
                storyVideoProgress.setVisibility(View.GONE);
            }
        });
    }
    if (counter == (stories.size() - 1) && !getMessageDataStorage().isAllStorySeen(storyUser.getRoomId() == 0, storyUser.getRoomId() == 0 ? storyUser.getUserId() : storyUser.getRoomId())) {
        getMessageDataStorage().storySetSeenAll(storyUser.getRoomId() == 0 ? storyUser.getUserId() : storyUser.getRoomId(), true, storyUser.getRoomId() == 0);
        int storyUnSeenCount = getMessageDataStorage().getUnSeenStoryCount();
        if (storyUnSeenCount > 0) {
            G.onUnreadChange.onChange(storyUnSeenCount, true);
        } else {
            G.onUnreadChange.onChange(0, true);
        }
        EventManager.getInstance(AccountManager.selectedAccount).postEvent(EventManager.STORY_ALL_SEEN);
    }
    File file = new File(path != null ? path : "");
    storyDisplayImage.setImageBitmap(null);
    if (file.exists()) {
        loadImage(path);
    } else {
        path = attachmentObject.thumbnailPath != null ? attachmentObject.thumbnailPath : "";
        file = new File(path);
        if (file.exists()) {
            Story story = stories.get(counter);
            if (story.getAttachment().filePath != null && (new File(story.getAttachment().filePath).exists())) {
                return;
            }
            Bitmap bitmap = AndroidUtils.blurImage(BitmapFactory.decodeFile(path));
            storyDisplayImage.setImageBitmap(bitmap);
        } else {
            ProtoFileDownload.FileDownload.Selector selector;
            if (attachmentObject.largeThumbnail != null) {
                selector = ProtoFileDownload.FileDownload.Selector.LARGE_THUMBNAIL;
                path = AndroidUtils.getFilePathWithCashId(attachmentObject.smallThumbnail.cacheId, attachmentObject.name, G.context.getExternalFilesDir(Environment.DIRECTORY_PICTURES).getAbsolutePath(), true);
                if (new File(path).exists()) {
                    Story story = stories.get(counter);
                    if (story.getAttachment().filePath != null && (new File(story.getAttachment().filePath).exists())) {
                        return;
                    }
                    Bitmap bitmap = AndroidUtils.blurImage(BitmapFactory.decodeFile(path));
                    storyDisplayImage.setImageBitmap(bitmap);
                } else {
                    DownloadObject downloadObject = DownloadObject.createForThumb(attachmentObject, ProtoGlobal.RoomMessageType.STORY.getNumber(), false);
                    if (downloadObject != null) {
                        downloadObject.downloadId = stories.get(counter).getStoryId();
                        getDownloader().download(downloadObject, selector, arg -> {
                            if (arg.status == Status.SUCCESS) {
                                if (arg.data != null) {
                                    String filePath = arg.data.getFilePath();
                                    Story story = stories.get(counter);
                                    if (story.getStoryId() == arg.data.getDownloadObject().downloadId) {
                                        if (story.getAttachment().filePath != null && (new File(story.getAttachment().filePath).exists())) {
                                            return;
                                        }
                                        Bitmap bitmap = AndroidUtils.blurImage(BitmapFactory.decodeFile(filePath));
                                        G.runOnUiThread(() -> storyDisplayImage.setImageBitmap(bitmap));
                                    }
                                }
                            }
                        });
                    }
                }
            } else if (attachmentObject.smallThumbnail != null) {
                selector = ProtoFileDownload.FileDownload.Selector.SMALL_THUMBNAIL;
                path = AndroidUtils.getFilePathWithCashId(attachmentObject.smallThumbnail.cacheId, attachmentObject.name, G.context.getExternalFilesDir(Environment.DIRECTORY_PICTURES).getAbsolutePath(), true);
                if (new File(path).exists()) {
                    Story story = stories.get(counter);
                    if (story.getAttachment().filePath != null && (new File(story.getAttachment().filePath).exists())) {
                        return;
                    }
                    Bitmap bitmap = AndroidUtils.blurImage(BitmapFactory.decodeFile(path));
                    storyDisplayImage.setImageBitmap(bitmap);
                } else {
                    DownloadObject downloadObject = DownloadObject.createForThumb(attachmentObject, ProtoGlobal.RoomMessageType.STORY.getNumber(), false);
                    if (downloadObject != null) {
                        downloadObject.downloadId = stories.get(counter).getStoryId();
                        getDownloader().download(downloadObject, selector, arg -> {
                            if (arg.status == Status.SUCCESS) {
                                if (arg.data != null) {
                                    String filePath = arg.data.getFilePath();
                                    Story story = stories.get(counter);
                                    if (story.getStoryId() == arg.data.getDownloadObject().downloadId) {
                                        if (story.getAttachment().filePath != null && (new File(story.getAttachment().filePath).exists())) {
                                            return;
                                        }
                                        Bitmap bitmap = AndroidUtils.blurImage(BitmapFactory.decodeFile(filePath));
                                        G.runOnUiThread(() -> storyDisplayImage.setImageBitmap(bitmap));
                                    }
                                }
                            }
                        });
                    }
                }
            }
        }
        DownloadObject object = DownloadObject.createForStory(attachmentObject, stories.get(counter).getStoryId(), true);
        if (object != null) {
            ProtoFileDownload.FileDownload.Selector imageSelector = ProtoFileDownload.FileDownload.Selector.FILE;
            Downloader.getInstance(AccountManager.selectedAccount).download(object, imageSelector, HttpRequest.PRIORITY.PRIORITY_HIGH, arg -> {
                if (arg.status == Status.SUCCESS && arg.data != null) {
                    String filepath = arg.data.getFilePath();
                    long downloadId = arg.data.getDownloadObject().downloadId;
                    Story story = stories.get(counter);
                    if (downloadId == story.getStoryId()) {
                        story.getAttachment().filePath = filepath;
                        G.runOnUiThread(() -> loadImage(filepath));
                    }
                }
            });
        }
    }
}
Also used : AnticipateInterpolator(android.view.animation.AnticipateInterpolator) Bundle(android.os.Bundle) ProgressBar(android.widget.ProgressBar) NonNull(androidx.annotation.NonNull) ProtoFileDownload(net.iGap.proto.ProtoFileDownload) FrameLayout(android.widget.FrameLayout) ImageView(android.widget.ImageView) LastSeenTimeUtil(net.iGap.module.LastSeenTimeUtil) Drawable(android.graphics.drawable.Drawable) AdditionalType(net.iGap.module.additionalData.AdditionalType) HelperFragment(net.iGap.helper.HelperFragment) HelperCalander(net.iGap.helper.HelperCalander) ScrollingMovementMethod(android.text.method.ScrollingMovementMethod) ChatSendMessageUtil(net.iGap.module.ChatSendMessageUtil) RealmRoom(net.iGap.realm.RealmRoom) BaseFragment(net.iGap.fragments.BaseFragment) Downloader(net.iGap.module.downloader.Downloader) StringRes(androidx.annotation.StringRes) FontIconTextView(net.iGap.module.FontIconTextView) Nullable(androidx.annotation.Nullable) SHP_SETTING(net.iGap.module.SHP_SETTING) LinearLayoutManager(androidx.recyclerview.widget.LinearLayoutManager) EventManager(net.iGap.observers.eventbus.EventManager) AbstractObject(net.iGap.network.AbstractObject) DownloadObject(net.iGap.module.downloader.DownloadObject) SuggestedStickerAdapter(net.iGap.fragments.emoji.SuggestedStickerAdapter) EmojiManager(net.iGap.libs.emojiKeyboard.emoji.EmojiManager) LayerDrawable(android.graphics.drawable.LayerDrawable) AttachmentObject(net.iGap.structs.AttachmentObject) ViewMaker.setTextSize(net.iGap.adapter.items.chat.ViewMaker.setTextSize) Environment(android.os.Environment) AccountManager(net.iGap.module.accountManager.AccountManager) BitmapFactory(android.graphics.BitmapFactory) PlayerView(com.google.android.exoplayer2.ui.PlayerView) ViewUserDialogFragment(net.iGap.story.ViewUserDialogFragment) GradientDrawable(android.graphics.drawable.GradientDrawable) Toast(android.widget.Toast) LayoutCreator(net.iGap.helper.LayoutCreator) AvatarHandler(net.iGap.helper.avatar.AvatarHandler) StickerSettingFragment(net.iGap.fragments.emoji.remove.StickerSettingFragment) MessageObject(net.iGap.structs.MessageObject) TextUtils(android.text.TextUtils) RecyclerListView(net.iGap.module.customView.RecyclerListView) File(java.io.File) Gravity(android.view.Gravity) StructIGSticker(net.iGap.fragments.emoji.struct.StructIGSticker) EventEditText(net.iGap.module.customView.EventEditText) SharedPreferences(android.content.SharedPreferences) TypedValue(android.util.TypedValue) NotifyFrameLayout(net.iGap.libs.emojiKeyboard.NotifyFrameLayout) DbManager(net.iGap.module.accountManager.DbManager) EditText(android.widget.EditText) Rect(android.graphics.Rect) LinearLayout(android.widget.LinearLayout) AppUtils(net.iGap.module.AppUtils) StoryCell(net.iGap.story.storyviews.StoryCell) Animator(android.animation.Animator) Theme(net.iGap.module.Theme) G(net.iGap.G) RealmUserInfo(net.iGap.realm.RealmUserInfo) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) Gson(com.google.gson.Gson) ActivityInfo(android.content.pm.ActivityInfo) View(android.view.View) KeyboardView(net.iGap.libs.emojiKeyboard.KeyboardView) RecyclerView(androidx.recyclerview.widget.RecyclerView) ParamWithAvatarType(net.iGap.helper.avatar.ParamWithAvatarType) Status(net.iGap.module.downloader.Status) ObjectAnimator(android.animation.ObjectAnimator) RealmStory(net.iGap.realm.RealmStory) DisplayMetrics(android.util.DisplayMetrics) ViewGroup(android.view.ViewGroup) Objects(java.util.Objects) List(java.util.List) CompositeDisposable(io.reactivex.disposables.CompositeDisposable) Disposable(io.reactivex.disposables.Disposable) TextView(android.widget.TextView) FragmentSettingAddStickers(net.iGap.fragments.emoji.add.FragmentSettingAddStickers) HttpRequest(net.iGap.module.downloader.HttpRequest) StickerRepository(net.iGap.repository.StickerRepository) Typeface(android.graphics.Typeface) Context(android.content.Context) AndroidUtils(net.iGap.module.AndroidUtils) KeyEvent(android.view.KeyEvent) ResourcesCompat(androidx.core.content.res.ResourcesCompat) TimeUtils(net.iGap.module.TimeUtils) RealmStickerItem(net.iGap.realm.RealmStickerItem) MotionEvent(android.view.MotionEvent) ExpandableTextView(net.iGap.story.ExpandableTextView) MODE_PRIVATE(android.content.Context.MODE_PRIVATE) AnimatorSet(android.animation.AnimatorSet) RealmRoomMessage(net.iGap.realm.RealmRoomMessage) EmojiView(net.iGap.libs.emojiKeyboard.EmojiView) IG_RPC(net.iGap.network.IG_RPC) ImageLoadingView(net.iGap.story.liststories.ImageLoadingView) RealmAdditional(net.iGap.realm.RealmAdditional) InsetDrawable(android.graphics.drawable.InsetDrawable) CircleImageView(net.iGap.module.CircleImageView) Color(android.graphics.Color) Glide(com.bumptech.glide.Glide) Bitmap(android.graphics.Bitmap) ProtoGlobal(net.iGap.proto.ProtoGlobal) R(net.iGap.R) RealmAttachment(net.iGap.realm.RealmAttachment) IG_RPC(net.iGap.network.IG_RPC) DownloadObject(net.iGap.module.downloader.DownloadObject) Bitmap(android.graphics.Bitmap) ProtoFileDownload(net.iGap.proto.ProtoFileDownload) AttachmentObject(net.iGap.structs.AttachmentObject) AbstractObject(net.iGap.network.AbstractObject) File(java.io.File) RealmStory(net.iGap.realm.RealmStory)

Example 3 with DownloadObject

use of net.iGap.module.downloader.DownloadObject in project iGap-Android by KianIranian-STDG.

the class StoryCell method setData.

public void setData(MainStoryObject mainStoryObject, String color, Context context, boolean needDivider, CircleStatus status, ImageLoadingView.Status imageLoadingStatus, IconClicked iconClicked) {
    this.userId = mainStoryObject.userId;
    this.roomId = mainStoryObject.roomId;
    this.isVerified = mainStoryObject.isVerified;
    initView(context, needDivider, status, imageLoadingStatus, iconClicked, mainStoryObject.storyObjects.get(0).createdAt);
    circleImageLoading.setStatus(imageLoadingStatus);
    if (userId == AccountManager.getInstance().getCurrentUser().getId()) {
        topText.setText(context.getString(R.string.my_status));
    } else {
        if (roomId != 0) {
            channelIconTv.setVisibility(VISIBLE);
        }
        if (isVerified) {
            verifyIconTv.setVisibility(VISIBLE);
        }
        topText.setText(mainStoryObject.storyObjects.get(0).displayName != null ? mainStoryObject.storyObjects.get(0).displayName : "");
    }
    String name = HelperImageBackColor.getFirstAlphabetName(mainStoryObject.storyObjects.get(0).displayName != null ? mainStoryObject.storyObjects.get(0).displayName : "");
    if (circleImageLoading.getStatus() == ImageLoadingView.Status.FAILED) {
        bottomText.setText(context.getString(R.string.story_could_not_sent));
        bottomText.setTextColor(Color.RED);
        deleteIcon.setTextColor(Color.RED);
        addIcon.setTextColor(Color.RED);
        addIcon.setText(R.string.icon_error);
    } else if (circleImageLoading.getStatus() == ImageLoadingView.Status.LOADING) {
        bottomText.setText(context.getString(R.string.story_sending));
        deleteIcon.setTextColor(Theme.getInstance().getTitleTextColor(context));
    } else {
        bottomText.setText(LastSeenTimeUtil.computeTime(context, mainStoryObject.userId, mainStoryObject.storyObjects.get(0).createdAt / 1000L, false, false));
    }
    AttachmentObject attachment = mainStoryObject.storyObjects.get(0).attachmentObject;
    if (status == CircleStatus.LOADING_CIRCLE_IMAGE) {
        if (attachment != null && (attachment.thumbnailPath != null || attachment.filePath != null)) {
            try {
                Glide.with(G.context).load(attachment.filePath != null ? attachment.filePath : attachment.thumbnailPath).placeholder(new BitmapDrawable(context.getResources(), HelperImageBackColor.drawAlphabetOnPicture(LayoutCreator.dp(64), name, color))).into(circleImageLoading);
            } catch (Exception e) {
                Glide.with(G.context).load(new BitmapDrawable(context.getResources(), HelperImageBackColor.drawAlphabetOnPicture(LayoutCreator.dp(64), name, color))).into(circleImageLoading);
            }
        } else if (attachment != null) {
            Glide.with(G.context).load(new BitmapDrawable(context.getResources(), HelperImageBackColor.drawAlphabetOnPicture(LayoutCreator.dp(64), name, color))).into(circleImageLoading);
            DownloadObject object = DownloadObject.createForStory(attachment, storyId, true);
            if (object != null) {
                Downloader.getInstance(AccountManager.selectedAccount).download(object, arg -> {
                    if (arg.status == Status.SUCCESS && arg.data != null) {
                        String filepath = arg.data.getFilePath();
                        String downloadedFileToken = arg.data.getToken();
                        if (!(new File(filepath).exists())) {
                            HelperLog.getInstance().setErrorLog(new Exception("File Dont Exist After Download !!" + filepath));
                        }
                        if (arg.data.getDownloadObject().downloadId == storyId) {
                            DbManager.getInstance().doRealmTransaction(realm1 -> {
                                RealmStoryProto realmStoryProto = realm1.where(RealmStoryProto.class).equalTo("isForReply", false).equalTo("storyId", storyId).findFirst();
                                if (realmStoryProto != null) {
                                    realmStoryProto.getFile().setLocalFilePath(filepath);
                                }
                            });
                            G.runOnUiThread(() -> Glide.with(G.context).load(filepath).placeholder(new BitmapDrawable(context.getResources(), HelperImageBackColor.drawAlphabetOnPicture(LayoutCreator.dp(64), name, color))).into(circleImageLoading));
                        }
                    }
                });
            }
        } else {
            Glide.with(G.context).load(new BitmapDrawable(context.getResources(), HelperImageBackColor.drawAlphabetOnPicture(LayoutCreator.dp(64), name, color))).into(circleImageLoading);
        }
    }
}
Also used : LinearLayout(android.widget.LinearLayout) NonNull(androidx.annotation.NonNull) UploadObject(net.iGap.module.upload.UploadObject) FrameLayout(android.widget.FrameLayout) LastSeenTimeUtil(net.iGap.module.LastSeenTimeUtil) Theme(net.iGap.module.Theme) G(net.iGap.G) HttpUploader(net.iGap.helper.upload.ApiBased.HttpUploader) RealmStoryProto(net.iGap.realm.RealmStoryProto) View(android.view.View) Canvas(android.graphics.Canvas) Log(android.util.Log) HelperImageBackColor(net.iGap.helper.HelperImageBackColor) MainStoryObject(net.iGap.story.MainStoryObject) ParamWithAvatarType(net.iGap.helper.avatar.ParamWithAvatarType) HelperCalander(net.iGap.helper.HelperCalander) MessageController(net.iGap.controllers.MessageController) Status(net.iGap.module.downloader.Status) BitmapDrawable(android.graphics.drawable.BitmapDrawable) Downloader(net.iGap.module.downloader.Downloader) RealmStory(net.iGap.realm.RealmStory) Uploader(net.iGap.module.upload.Uploader) HelperLog(net.iGap.helper.HelperLog) FontIconTextView(net.iGap.module.FontIconTextView) List(java.util.List) TextView(android.widget.TextView) ProtoStoryUserAddNew(net.iGap.proto.ProtoStoryUserAddNew) ViewMaker.i_Dp(net.iGap.adapter.items.chat.ViewMaker.i_Dp) Paint(android.graphics.Paint) EventManager(net.iGap.observers.eventbus.EventManager) DownloadObject(net.iGap.module.downloader.DownloadObject) Context(android.content.Context) AttachmentObject(net.iGap.structs.AttachmentObject) ResourcesCompat(androidx.core.content.res.ResourcesCompat) ViewMaker.setTextSize(net.iGap.adapter.items.chat.ViewMaker.setTextSize) AccountManager(net.iGap.module.accountManager.AccountManager) StoryObject(net.iGap.story.StoryObject) ArrayList(java.util.ArrayList) LayoutCreator(net.iGap.helper.LayoutCreator) AvatarHandler(net.iGap.helper.avatar.AvatarHandler) ImageLoadingView(net.iGap.story.liststories.ImageLoadingView) MessageObject(net.iGap.structs.MessageObject) TextUtils(android.text.TextUtils) MaterialDesignTextView(net.iGap.module.MaterialDesignTextView) IconView(net.iGap.messenger.ui.components.IconView) CircleImageView(net.iGap.module.CircleImageView) File(java.io.File) Color(android.graphics.Color) Gravity(android.view.Gravity) Glide(com.bumptech.glide.Glide) TypedValue(android.util.TypedValue) ViewMaker(net.iGap.adapter.items.chat.ViewMaker) ProtoGlobal(net.iGap.proto.ProtoGlobal) MessageDataStorage(net.iGap.controllers.MessageDataStorage) R(net.iGap.R) DbManager(net.iGap.module.accountManager.DbManager) RealmStoryProto(net.iGap.realm.RealmStoryProto) AttachmentObject(net.iGap.structs.AttachmentObject) DownloadObject(net.iGap.module.downloader.DownloadObject) BitmapDrawable(android.graphics.drawable.BitmapDrawable) File(java.io.File)

Example 4 with DownloadObject

use of net.iGap.module.downloader.DownloadObject in project iGap-Android by KianIranian-STDG.

the class FragmentChat method saveSelectedMessageToDownload.

private void saveSelectedMessageToDownload(MessageObject messageObject, int pos) {
    String filename;
    String filepath;
    int messageType;
    if (messageObject.forwardedMessage != null) {
        filename = messageObject.forwardedMessage.getAttachment().name;
        filepath = messageObject.forwardedMessage.getAttachment().filePath != null ? messageObject.forwardedMessage.getAttachment().filePath : AndroidUtils.getFilePathWithCashId(messageObject.forwardedMessage.getAttachment().cacheId, filename, messageObject.forwardedMessage.messageType);
    } else {
        filename = messageObject.getAttachment().name;
        filepath = messageObject.getAttachment().filePath != null ? messageObject.getAttachment().filePath : AndroidUtils.getFilePathWithCashId(messageObject.getAttachment().cacheId, filename, messageObject.messageType);
    }
    if (new File(filepath).exists()) {
        getStoragePermission(filepath, filename);
    } else {
        final int _messageType = messageObject.forwardedMessage != null ? messageObject.forwardedMessage.messageType : messageObject.messageType;
        String cacheId = messageObject.forwardedMessage != null ? messageObject.forwardedMessage.getAttachment().cacheId : messageObject.getAttachment().cacheId;
        final String name = messageObject.forwardedMessage != null ? messageObject.forwardedMessage.getAttachment().name : messageObject.getAttachment().name;
        String fileToken = messageObject.forwardedMessage != null ? messageObject.forwardedMessage.getAttachment().token : messageObject.getAttachment().token;
        String fileUrl = messageObject.forwardedMessage != null ? messageObject.forwardedMessage.getAttachment().publicUrl : messageObject.getAttachment().publicUrl;
        Long size = messageObject.forwardedMessage != null ? messageObject.forwardedMessage.getAttachment().size : messageObject.getAttachment().size;
        if (cacheId == null) {
            return;
        }
        final String _path = AndroidUtils.getFilePathWithCashId(cacheId, name, _messageType);
        // TODO: 1/6/21 MESSAGE_REFACTOR
        DownloadObject fileObject = DownloadObject.createForRoomMessage(messageObject);
        if (fileObject != null) {
            getDownloader().download(fileObject, arg -> {
                if (arg.data != null && arg.data.getProgress() == 100) {
                    if (canUpdateAfterDownload) {
                        G.handler.post(() -> {
                            getStoragePermission(_path, name);
                        });
                    }
                }
            });
        }
        onDownloadAllEqualCashId(cacheId, messageObject.id + "");
        mAdapter.notifyItemChanged(pos);
    }
}
Also used : DownloadObject(net.iGap.module.downloader.DownloadObject) RealmString(net.iGap.realm.RealmString) HelperString(net.iGap.helper.HelperString) HelperSaveFile(net.iGap.helper.HelperSaveFile) File(java.io.File) AttachFile(net.iGap.module.AttachFile) SuppressLint(android.annotation.SuppressLint)

Example 5 with DownloadObject

use of net.iGap.module.downloader.DownloadObject in project iGap-Android by KianIranian-STDG.

the class FragmentChat method saveSelectedMessageToMusic.

private void saveSelectedMessageToMusic(MessageObject message, int pos) {
    String filename;
    String filepath;
    if (message.forwardedMessage != null) {
        filename = message.forwardedMessage.getAttachment().name;
        filepath = message.forwardedMessage.getAttachment().filePath != null ? message.forwardedMessage.getAttachment().filePath : AndroidUtils.getFilePathWithCashId(message.forwardedMessage.getAttachment().cacheId, filename, message.forwardedMessage.messageType);
    } else {
        filename = message.getAttachment().name;
        filepath = message.getAttachment().filePath != null ? message.getAttachment().filePath : AndroidUtils.getFilePathWithCashId(message.getAttachment().cacheId, message.getAttachment().name, message.messageType);
    }
    if (new File(filepath).exists()) {
        HelperSaveFile.saveFileToDownLoadFolder(filepath, filename, HelperSaveFile.FolderType.music);
    } else {
        final int _messageType = message.forwardedMessage != null ? message.forwardedMessage.messageType : message.messageType;
        String cacheId = message.forwardedMessage != null ? message.forwardedMessage.getAttachment().cacheId : message.getAttachment().cacheId;
        final String name = message.forwardedMessage != null ? message.forwardedMessage.getAttachment().name : message.getAttachment().name;
        String fileToken = message.forwardedMessage != null ? message.forwardedMessage.getAttachment().token : message.getAttachment().token;
        String fileUrl = message.forwardedMessage != null ? message.forwardedMessage.getAttachment().publicUrl : message.getAttachment().publicUrl;
        Long size = message.forwardedMessage != null ? message.forwardedMessage.getAttachment().size : message.getAttachment().size;
        if (cacheId == null) {
            return;
        }
        ProtoFileDownload.FileDownload.Selector selector = ProtoFileDownload.FileDownload.Selector.FILE;
        final String _path = AndroidUtils.getFilePathWithCashId(cacheId, name, _messageType);
        // TODO: 1/6/21 MESSAGE_REFACTOR
        DownloadObject fileObject = DownloadObject.createForRoomMessage(message);
        if (fileObject != null) {
            getDownloader().download(fileObject, selector, arg -> {
                if (canUpdateAfterDownload) {
                    G.handler.post(() -> {
                        if (arg.status == Status.SUCCESS || arg.status == Status.LOADING) {
                            if (arg.data != null && arg.data.getProgress() == 100) {
                                HelperSaveFile.saveFileToDownLoadFolder(_path, name, HelperSaveFile.FolderType.music);
                            }
                        }
                    });
                }
            });
        }
        onDownloadAllEqualCashId(cacheId, message.id + "");
        mAdapter.notifyItemChanged(pos);
    }
}
Also used : ProtoFileDownload(net.iGap.proto.ProtoFileDownload) DownloadObject(net.iGap.module.downloader.DownloadObject) RealmString(net.iGap.realm.RealmString) HelperString(net.iGap.helper.HelperString) HelperSaveFile(net.iGap.helper.HelperSaveFile) File(java.io.File) AttachFile(net.iGap.module.AttachFile) SuppressLint(android.annotation.SuppressLint)

Aggregations

DownloadObject (net.iGap.module.downloader.DownloadObject)14 File (java.io.File)11 ProtoFileDownload (net.iGap.proto.ProtoFileDownload)7 ProtoGlobal (net.iGap.proto.ProtoGlobal)7 AttachmentObject (net.iGap.structs.AttachmentObject)7 G (net.iGap.G)5 AccountManager (net.iGap.module.accountManager.AccountManager)5 DbManager (net.iGap.module.accountManager.DbManager)5 Downloader (net.iGap.module.downloader.Downloader)5 Status (net.iGap.module.downloader.Status)5 SuppressLint (android.annotation.SuppressLint)4 Color (android.graphics.Color)4 View (android.view.View)4 TextView (android.widget.TextView)4 HelperLog (net.iGap.helper.HelperLog)4 Context (android.content.Context)3 TextUtils (android.text.TextUtils)3 TypedValue (android.util.TypedValue)3 Gravity (android.view.Gravity)3 FrameLayout (android.widget.FrameLayout)3