use of net.iGap.observers.interfaces.OnComplete in project iGap-Android by KianIranian-STDG.
the class AvatarHandler method getAvatarImage.
/**
* check avatar in Realm and download if needed
*/
private void getAvatarImage(BaseParam baseParam, Realm _realm, boolean requestUserInfo) {
RealmAvatar realmAvatar = getLastAvatar(baseParam.avatarOwnerId, _realm);
if (realmAvatar == null && requestUserInfo && RequestManager.getInstance(AccountManager.selectedAccount).isUserLogin()) {
new RequestUserInfo().userInfoWithCallBack(new OnComplete() {
@Override
public void complete(boolean result, String messageOne, String MessageTwo) {
getAvatar(baseParam, false);
}
}, baseParam.avatarOwnerId, "" + baseParam.avatarOwnerId);
}
if (realmAvatar == null && baseParam instanceof ParamWithAvatarType && ((ParamWithAvatarType) baseParam).registeredUser != null) {
insertRegisteredInfoToDB(((ParamWithAvatarType) baseParam).registeredUser, _realm);
realmAvatar = getLastAvatar(baseParam.avatarOwnerId, _realm);
}
if (realmAvatar != null) {
if (baseParam.showMain && realmAvatar.getFile().isFileExistsOnLocal()) {
final String path = realmAvatar.getFile().getLocalFilePath();
notifyAll(path, baseParam.avatarOwnerId, true, realmAvatar.getFile().getId(), realmAvatar.getId());
} else if (realmAvatar.getFile().isThumbnailExistsOnLocal()) {
final String path = realmAvatar.getFile().getLocalThumbnailPath();
notifyAll(path, baseParam.avatarOwnerId, false, realmAvatar.getFile().getId(), realmAvatar.getId());
} else {
DownloadObject object = DownloadObject.createForAvatar(realmAvatar.getFile());
if (object != null) {
Downloader.getInstance(AccountManager.selectedAccount).download(object, 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));
}
final ArrayList<Long> ownerIdList = new ArrayList<>();
final ArrayList<Long> fileIdList = new ArrayList<>();
final ArrayList<Long> avatarIdList = new ArrayList<>();
DbManager.getInstance().doRealmTransaction(realm -> {
for (RealmAvatar realmAvatar1 : realm.where(RealmAvatar.class).equalTo("file.token", fileToken).findAll()) {
realmAvatar1.getFile().setLocalThumbnailPath(filepath);
ownerIdList.add(realmAvatar1.getOwnerId());
fileIdList.add(realmAvatar1.getFile().getId());
avatarIdList.add(realmAvatar1.getId());
}
});
for (int i = 0; i < ownerIdList.size(); i++) {
AvatarHandler.this.notifyAll(filepath, ownerIdList.get(i), false, fileIdList.get(i), avatarIdList.get(i));
}
ownerIdList.clear();
fileIdList.clear();
avatarIdList.clear();
}
});
}
}
} else if (baseParam instanceof ParamWithAvatarType) {
String[] initials = showInitials(baseParam.avatarOwnerId, ((ParamWithAvatarType) baseParam).avatarType);
if (initials == null) {
getAvatarAfterTime(baseParam);
}
}
}
Aggregations