use of forpdateam.ru.forpda.data.realm.ForumUserBd in project ForPDA by RadiationX.
the class ForumUsersCache method getUserById.
public static ForumUser getUserById(int id) {
ForumUser resultUser = null;
Realm realmInstance = Realm.getDefaultInstance();
ForumUserBd realmResult = realmInstance.where(ForumUserBd.class).equalTo("id", id).findFirst();
if (realmResult != null) {
resultUser = new ForumUser(realmResult);
}
realmInstance.close();
return resultUser;
}
use of forpdateam.ru.forpda.data.realm.ForumUserBd in project ForPDA by RadiationX.
the class ForumUsersCache method saveUsers.
public static void saveUsers(List<ForumUser> forumUsers) {
Realm realmInstance = Realm.getDefaultInstance();
realmInstance.executeTransaction(realm -> {
List<ForumUserBd> bdList = new ArrayList<>();
for (ForumUser item : forumUsers) {
bdList.add(new ForumUserBd(item));
}
realm.insertOrUpdate(bdList);
});
realmInstance.close();
}
use of forpdateam.ru.forpda.data.realm.ForumUserBd in project ForPDA by RadiationX.
the class ForumUsersCache method loadUserByNick.
public static ForumUser loadUserByNick(String nick) throws Exception {
ForumUser resultUser = null;
Realm realmInstance = Realm.getDefaultInstance();
ForumUserBd realmResult = realmInstance.where(ForumUserBd.class).equalTo("nick", nick).findFirst();
if (realmResult != null) {
resultUser = new ForumUser(realmResult);
}
realmInstance.close();
if (realmResult != null) {
return resultUser;
}
List<ForumUser> loadedForumUsers = Api.Qms().findUser(nick);
for (ForumUser user : loadedForumUsers) {
if (nick.equals(user.getNick())) {
resultUser = user;
break;
}
}
if (resultUser != null) {
loadedForumUsers.clear();
loadedForumUsers.add(resultUser);
saveUsers(loadedForumUsers);
}
return resultUser;
}
Aggregations