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();
}
}
});
}
Aggregations