Search in sources :

Example 1 with StructWallpaper

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

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

the class ChatBackgroundViewModel method fillList.

private void fillList(boolean getInfoFromServer) {
    if (wList == null)
        wList = new ArrayList<>();
    wList.clear();
    DbManager.getInstance().doRealmTask(realm -> {
        RealmWallpaper realmWallpaper = realm.where(RealmWallpaper.class).equalTo("type", ProtoInfoWallpaper.InfoWallpaper.Type.CHAT_BACKGROUND_VALUE).findFirst();
        if (realmWallpaper != null) {
            Log.wtf(this.getClass().getName(), "realmWallpaper != null");
            if (realmWallpaper.getLocalList() != null) {
                Log.wtf(this.getClass().getName(), "realmWallpaper.getLocalList() != null");
                for (String localPath : realmWallpaper.getLocalList()) {
                    if (new File(localPath).exists()) {
                        StructWallpaper _swl = new StructWallpaper();
                        _swl.setWallpaperType(FragmentChatBackground.WallpaperType.local);
                        _swl.setPath(localPath);
                        wList.add(_swl);
                        loadChatBackgroundImage.postValue(wList);
                    }
                }
            }
            if (realmWallpaper.getWallPaperList() != null) {
                Log.wtf(this.getClass().getName(), "realmWallpaper.getWallPaperList() != null");
                for (RealmWallpaperProto wallpaper : realmWallpaper.getWallPaperList()) {
                    StructWallpaper _swp = new StructWallpaper();
                    _swp.setWallpaperType(FragmentChatBackground.WallpaperType.proto);
                    _swp.setProtoWallpaper(realm.copyFromRealm(wallpaper));
                    wList.add(_swp);
                    loadChatBackgroundImage.postValue(wList);
                }
            } else if (getInfoFromServer) {
                Log.wtf(this.getClass().getName(), "getInfoFromServer");
                long time = realmWallpaper.getLastTimeGetList();
                if (time > 0) {
                    if (time + (2 * 60 * 60 * 1000) < TimeUtils.currentLocalTime()) {
                        getImageListFromServer();
                    }
                } else {
                    getImageListFromServer();
                }
            }
        } else {
            Log.wtf(this.getClass().getName(), "realmWallpaper == null");
            if (getInfoFromServer) {
                getImageListFromServer();
            }
        }
    });
}
Also used : StructWallpaper(net.iGap.module.StructWallpaper) RealmWallpaperProto(net.iGap.realm.RealmWallpaperProto) RealmWallpaper(net.iGap.realm.RealmWallpaper) ArrayList(java.util.ArrayList) File(java.io.File) HelperSaveFile(net.iGap.helper.HelperSaveFile)

Aggregations

File (java.io.File)2 StructWallpaper (net.iGap.module.StructWallpaper)2 Color (android.graphics.Color)1 Environment (android.os.Environment)1 LayoutInflater (android.view.LayoutInflater)1 View (android.view.View)1 ViewGroup (android.view.ViewGroup)1 AppCompatImageView (androidx.appcompat.widget.AppCompatImageView)1 CardView (androidx.cardview.widget.CardView)1 RecyclerView (androidx.recyclerview.widget.RecyclerView)1 ArrayList (java.util.ArrayList)1 List (java.util.List)1 G (net.iGap.G)1 R (net.iGap.R)1 FragmentChatBackground (net.iGap.fragments.FragmentChatBackground)1 HelperDownloadFile (net.iGap.helper.HelperDownloadFile)1 HelperLog (net.iGap.helper.HelperLog)1 HelperSaveFile (net.iGap.helper.HelperSaveFile)1 MessageProgress (net.iGap.messageprogress.MessageProgress)1 OnProgress (net.iGap.messageprogress.OnProgress)1