use of net.iGap.realm.RealmStickerGroup in project iGap-Android by KianIranian-STDG.
the class StickerRepository method removeStickerGroupFromMyStickers.
public Single<StructIGStickerGroup> removeStickerGroupFromMyStickers(StructIGStickerGroup stickerGroup) {
return removeStickerGroupFromMyStickersApiService(stickerGroup.getGroupId()).doOnComplete(() -> DbManager.getInstance().doRealmTask(realm -> {
RealmStickerGroup realmStickerGroup = realm.where(RealmStickerGroup.class).equalTo("id", stickerGroup.getGroupId()).findFirst();
if (realmStickerGroup != null) {
try {
DbManager.getInstance().doRealmTransaction(asyncRealm -> realmStickerGroup.removeFromRealm());
stickerGroup.setInUserList(false);
} catch (Exception e) {
e.printStackTrace();
}
}
})).andThen((SingleSource<StructIGStickerGroup>) observer -> observer.onSuccess(stickerGroup));
}
use of net.iGap.realm.RealmStickerGroup in project iGap-Android by KianIranian-STDG.
the class StickerRepository method addStickerGroupToMyStickers.
public Single<StructIGStickerGroup> addStickerGroupToMyStickers(StructIGStickerGroup stickerGroup) {
return addStickerGroupToMyStickersApiService(stickerGroup.getGroupId()).doOnComplete(() -> DbManager.getInstance().doRealmTask(realm -> {
RealmStickerGroup realmStickerGroup = realm.where(RealmStickerGroup.class).equalTo("id", stickerGroup.getGroupId()).findFirst();
if (realmStickerGroup == null) {
realm.executeTransactionAsync(asyncRealm -> RealmStickerGroup.put(asyncRealm, stickerGroup));
stickerGroup.setInUserList(true);
}
})).andThen((SingleSource<StructIGStickerGroup>) observer -> observer.onSuccess(stickerGroup));
}
use of net.iGap.realm.RealmStickerGroup in project iGap-Android by KianIranian-STDG.
the class StickerRepository method updateStickers.
private void updateStickers(List<StructIGStickerGroup> stickerGroup) {
DbManager.getInstance().doRealmTask(realm -> {
realm.executeTransactionAsync(asyncRealm -> {
HashSet<String> hashedData = new HashSet<>();
ArrayList<RealmStickerGroup> itemToDelete = new ArrayList<>();
for (StructIGStickerGroup structGroupSticker : stickerGroup) {
hashedData.add(structGroupSticker.getGroupId());
}
RealmResults<RealmStickerGroup> allStickers = asyncRealm.where(RealmStickerGroup.class).findAll();
for (RealmStickerGroup realmStickers : allStickers) {
if (!hashedData.contains(realmStickers.getId())) {
itemToDelete.add(realmStickers);
}
}
for (RealmStickerGroup realmStickers : itemToDelete) {
realmStickers.removeFromRealm();
}
for (StructIGStickerGroup updateStickers : stickerGroup) {
RealmStickerGroup.put(asyncRealm, updateStickers);
}
});
});
}
Aggregations