Search in sources :

Example 1 with RealmWallpaperProto

use of net.iGap.realm.RealmWallpaperProto 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)1 ArrayList (java.util.ArrayList)1 HelperSaveFile (net.iGap.helper.HelperSaveFile)1 StructWallpaper (net.iGap.module.StructWallpaper)1 RealmWallpaper (net.iGap.realm.RealmWallpaper)1 RealmWallpaperProto (net.iGap.realm.RealmWallpaperProto)1