Search in sources :

Example 1 with RealmWallpaper

use of net.iGap.realm.RealmWallpaper in project iGap-Android by KianIranian-STDG.

the class UserProfileViewModel method getProfileWallpaperFromServer.

private void getProfileWallpaperFromServer() {
    G.onGetProfileWallpaper = list -> {
        G.isNeedToCheckProfileWallpaper = false;
        DbManager.getInstance().doRealmTask(realm -> {
            RealmWallpaper realmWallpaper = realm.where(RealmWallpaper.class).equalTo("type", ProtoInfoWallpaper.InfoWallpaper.Type.PROFILE_WALLPAPER_VALUE).findFirst();
            if (realmWallpaper != null) {
                int count = realmWallpaper.getWallPaperList().size();
                assert realmWallpaper.getWallPaperList().get(count - 1) != null;
                if (!realmWallpaper.getWallPaperList().get(count - 1).getFile().getToken().equals(list.get(0).getFile().getToken())) {
                    RealmWallpaper.updateWallpaper(list);
                }
            } else {
                RealmWallpaper.updateField(list, "", ProtoInfoWallpaper.InfoWallpaper.Type.PROFILE_WALLPAPER_VALUE);
            }
            getProfileWallpaper(realm);
        });
    };
    new RequestInfoWallpaper().infoWallpaper(ProtoInfoWallpaper.InfoWallpaper.Type.PROFILE_WALLPAPER);
}
Also used : RequestInfoWallpaper(net.iGap.request.RequestInfoWallpaper) RealmWallpaper(net.iGap.realm.RealmWallpaper)

Example 2 with RealmWallpaper

use of net.iGap.realm.RealmWallpaper in project iGap-Android by KianIranian-STDG.

the class UserProfileViewModel method checkProfileWallpaper.

/**
 * just when user profile downloaded and available in realm load it
 * else send null to mutable live data to set default at fragment
 *
 * @param realm
 */
private void checkProfileWallpaper(Realm realm) {
    try {
        RealmWallpaper realmWallpaper = realm.where(RealmWallpaper.class).equalTo("type", ProtoInfoWallpaper.InfoWallpaper.Type.PROFILE_WALLPAPER_VALUE).findFirst();
        if (realmWallpaper != null) {
            RealmAttachment pf = realmWallpaper.getWallPaperList().get(realmWallpaper.getWallPaperList().size() - 1).getFile();
            String bigImagePath = G.context.getExternalFilesDir(Environment.DIRECTORY_PICTURES).getAbsolutePath() + "/" + pf.getCacheId() + "_" + DownloadObject.extractMime(pf.getName());
            changeUserProfileWallpaperPath.postValue(bigImagePath);
        } else {
            changeUserProfileWallpaperPath.postValue(null);
        }
    } catch (Exception e) {
        changeUserProfileWallpaperPath.postValue(null);
    }
}
Also used : RealmWallpaper(net.iGap.realm.RealmWallpaper) RealmAttachment(net.iGap.realm.RealmAttachment) HelperString(net.iGap.helper.HelperString)

Example 3 with RealmWallpaper

use of net.iGap.realm.RealmWallpaper 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)

Example 4 with RealmWallpaper

use of net.iGap.realm.RealmWallpaper in project iGap-Android by KianIranian-STDG.

the class UserProfileViewModel method getProfileWallpaper.

private void getProfileWallpaper(Realm realm) {
    try {
        RealmWallpaper realmWallpaper = realm.where(RealmWallpaper.class).equalTo("type", ProtoInfoWallpaper.InfoWallpaper.Type.PROFILE_WALLPAPER_VALUE).findFirst();
        if (realmWallpaper != null) {
            if (realmWallpaper.getWallPaperList() != null && realmWallpaper.getWallPaperList().size() > 0) {
                RealmAttachment pf = realmWallpaper.getWallPaperList().get(realmWallpaper.getWallPaperList().size() - 1).getFile();
                String bigImagePath = G.context.getExternalFilesDir(Environment.DIRECTORY_PICTURES).getAbsolutePath() + "/" + pf.getCacheId() + "_" + DownloadObject.extractMime(pf.getName());
                if (!new File(bigImagePath).exists()) {
                    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(db -> {
                                for (RealmAvatar realmAvatar1 : db.where(RealmAvatar.class).equalTo("file.token", fileToken).findAll()) {
                                    realmAvatar1.getFile().setLocalFilePath(filepath);
                                }
                            });
                            changeUserProfileWallpaperPath.postValue(bigImagePath);
                        }
                    });
                } else {
                    changeUserProfileWallpaperPath.postValue(bigImagePath);
                }
            } else {
                getProfileWallpaperFromServer();
            }
        } else {
            getProfileWallpaperFromServer();
        }
    } catch (ArrayIndexOutOfBoundsException e) {
        e.printStackTrace();
    } catch (NullPointerException e2) {
        e2.printStackTrace();
    } catch (Exception e3) {
        e3.printStackTrace();
    }
}
Also used : RealmWallpaper(net.iGap.realm.RealmWallpaper) DownloadObject(net.iGap.module.downloader.DownloadObject) RealmAttachment(net.iGap.realm.RealmAttachment) HelperString(net.iGap.helper.HelperString) HelperDownloadFile(net.iGap.helper.HelperDownloadFile) File(java.io.File) RealmAvatar(net.iGap.realm.RealmAvatar)

Aggregations

RealmWallpaper (net.iGap.realm.RealmWallpaper)4 File (java.io.File)2 HelperString (net.iGap.helper.HelperString)2 RealmAttachment (net.iGap.realm.RealmAttachment)2 ArrayList (java.util.ArrayList)1 HelperDownloadFile (net.iGap.helper.HelperDownloadFile)1 HelperSaveFile (net.iGap.helper.HelperSaveFile)1 StructWallpaper (net.iGap.module.StructWallpaper)1 DownloadObject (net.iGap.module.downloader.DownloadObject)1 RealmAvatar (net.iGap.realm.RealmAvatar)1 RealmWallpaperProto (net.iGap.realm.RealmWallpaperProto)1 RequestInfoWallpaper (net.iGap.request.RequestInfoWallpaper)1