Search in sources :

Example 1 with RealmStickerGroup

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));
}
Also used : JsonObject(com.google.gson.JsonObject) SingleSource(io.reactivex.SingleSource) StickerCategoryGroupDataModel(net.iGap.fragments.emoji.apiModels.StickerCategoryGroupDataModel) FileLog(net.iGap.helper.FileLog) Completable(io.reactivex.Completable) AESCrypt(net.iGap.module.AESCrypt) Single(io.reactivex.Single) AndroidSchedulers(io.reactivex.android.schedulers.AndroidSchedulers) StructIGStickerCategory(net.iGap.fragments.emoji.struct.StructIGStickerCategory) RealmStickerItem(net.iGap.realm.RealmStickerItem) G(net.iGap.G) ArrayList(java.util.ArrayList) HashSet(java.util.HashSet) SliderDataModel(net.iGap.fragments.emoji.apiModels.SliderDataModel) Flowable(io.reactivex.Flowable) Gson(com.google.gson.Gson) Schedulers(io.reactivex.schedulers.Schedulers) RsaDataModel(net.iGap.fragments.emoji.apiModels.RsaDataModel) IGSingleObserver(net.iGap.observers.rx.IGSingleObserver) CardStatusDataModel(net.iGap.fragments.emoji.apiModels.CardStatusDataModel) HelperNumerical(net.iGap.helper.HelperNumerical) Ids(net.iGap.fragments.emoji.apiModels.Ids) CompletableObserver(io.reactivex.CompletableObserver) RealmResults(io.realm.RealmResults) StructIGStickerGroup(net.iGap.fragments.emoji.struct.StructIGStickerGroup) StickerApi(net.iGap.api.StickerApi) UserGiftStickersDataModel(net.iGap.fragments.emoji.apiModels.UserGiftStickersDataModel) File(java.io.File) List(java.util.List) CompositeDisposable(io.reactivex.disposables.CompositeDisposable) Disposable(io.reactivex.disposables.Disposable) RetrofitFactory(net.iGap.api.apiService.RetrofitFactory) StructIGSticker(net.iGap.fragments.emoji.struct.StructIGSticker) Sort(io.realm.Sort) Base64(android.util.Base64) CardDetailDataModel(net.iGap.fragments.emoji.apiModels.CardDetailDataModel) IssueDataModel(net.iGap.fragments.emoji.apiModels.IssueDataModel) R(net.iGap.R) RealmStickerGroup(net.iGap.realm.RealmStickerGroup) ResponseCallback(net.iGap.observers.interfaces.ResponseCallback) NotNull(org.jetbrains.annotations.NotNull) DbManager(net.iGap.module.accountManager.DbManager) RealmStickerGroup(net.iGap.realm.RealmStickerGroup) StructIGStickerGroup(net.iGap.fragments.emoji.struct.StructIGStickerGroup)

Example 2 with RealmStickerGroup

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));
}
Also used : JsonObject(com.google.gson.JsonObject) SingleSource(io.reactivex.SingleSource) StickerCategoryGroupDataModel(net.iGap.fragments.emoji.apiModels.StickerCategoryGroupDataModel) FileLog(net.iGap.helper.FileLog) Completable(io.reactivex.Completable) AESCrypt(net.iGap.module.AESCrypt) Single(io.reactivex.Single) AndroidSchedulers(io.reactivex.android.schedulers.AndroidSchedulers) StructIGStickerCategory(net.iGap.fragments.emoji.struct.StructIGStickerCategory) RealmStickerItem(net.iGap.realm.RealmStickerItem) G(net.iGap.G) ArrayList(java.util.ArrayList) HashSet(java.util.HashSet) SliderDataModel(net.iGap.fragments.emoji.apiModels.SliderDataModel) Flowable(io.reactivex.Flowable) Gson(com.google.gson.Gson) Schedulers(io.reactivex.schedulers.Schedulers) RsaDataModel(net.iGap.fragments.emoji.apiModels.RsaDataModel) IGSingleObserver(net.iGap.observers.rx.IGSingleObserver) CardStatusDataModel(net.iGap.fragments.emoji.apiModels.CardStatusDataModel) HelperNumerical(net.iGap.helper.HelperNumerical) Ids(net.iGap.fragments.emoji.apiModels.Ids) CompletableObserver(io.reactivex.CompletableObserver) RealmResults(io.realm.RealmResults) StructIGStickerGroup(net.iGap.fragments.emoji.struct.StructIGStickerGroup) StickerApi(net.iGap.api.StickerApi) UserGiftStickersDataModel(net.iGap.fragments.emoji.apiModels.UserGiftStickersDataModel) File(java.io.File) List(java.util.List) CompositeDisposable(io.reactivex.disposables.CompositeDisposable) Disposable(io.reactivex.disposables.Disposable) RetrofitFactory(net.iGap.api.apiService.RetrofitFactory) StructIGSticker(net.iGap.fragments.emoji.struct.StructIGSticker) Sort(io.realm.Sort) Base64(android.util.Base64) CardDetailDataModel(net.iGap.fragments.emoji.apiModels.CardDetailDataModel) IssueDataModel(net.iGap.fragments.emoji.apiModels.IssueDataModel) R(net.iGap.R) RealmStickerGroup(net.iGap.realm.RealmStickerGroup) ResponseCallback(net.iGap.observers.interfaces.ResponseCallback) NotNull(org.jetbrains.annotations.NotNull) DbManager(net.iGap.module.accountManager.DbManager) RealmStickerGroup(net.iGap.realm.RealmStickerGroup) StructIGStickerGroup(net.iGap.fragments.emoji.struct.StructIGStickerGroup)

Example 3 with RealmStickerGroup

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);
            }
        });
    });
}
Also used : ArrayList(java.util.ArrayList) RealmStickerGroup(net.iGap.realm.RealmStickerGroup) StructIGStickerGroup(net.iGap.fragments.emoji.struct.StructIGStickerGroup) HashSet(java.util.HashSet)

Aggregations

ArrayList (java.util.ArrayList)3 HashSet (java.util.HashSet)3 StructIGStickerGroup (net.iGap.fragments.emoji.struct.StructIGStickerGroup)3 RealmStickerGroup (net.iGap.realm.RealmStickerGroup)3 Base64 (android.util.Base64)2 Gson (com.google.gson.Gson)2 JsonObject (com.google.gson.JsonObject)2 Completable (io.reactivex.Completable)2 CompletableObserver (io.reactivex.CompletableObserver)2 Flowable (io.reactivex.Flowable)2 Single (io.reactivex.Single)2 SingleSource (io.reactivex.SingleSource)2 AndroidSchedulers (io.reactivex.android.schedulers.AndroidSchedulers)2 CompositeDisposable (io.reactivex.disposables.CompositeDisposable)2 Disposable (io.reactivex.disposables.Disposable)2 Schedulers (io.reactivex.schedulers.Schedulers)2 RealmResults (io.realm.RealmResults)2 Sort (io.realm.Sort)2 File (java.io.File)2 List (java.util.List)2