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