asynchronous - Android Realm Update Asynchronously Using RxJava -
i have query update data in realm table;
for (mygameentrysquad squad : response.body().getsquad()) { subscription = realm.where(realmplayer.class).equalto("id", squad.getplayer().getid()) .findfirstasync() .asobservable() .subscribe(new action1<realmobject>() { @override public void call(realmobject realmobject) { } }); }
i perform query asynchronously display results on ui.
basically, whatever been returned response.body().getsquad() has id matching record in db; , using in equalto method.
based on data received, update 2 columns on each of record matching ids.
however, facing few challenges on this:
- the action1 in subscribe returning realmobject instead of playerobject
- how proceed here
any guidance on appreciated.
thanks
update
if (response.issuccessful()) { //asynchronously update existing players records squad i.e is_selected (mygameentrysquad squad : response.body().getsquad()) { realm.where(realmplayer.class).equalto("id", squad.getplayer().getid()) .findfirstasync() .<realmplayer>asobservable() .filter(realmplayer -> realmplayer.isloaded()) .subscribe(player -> { realm.begintransaction(); if (squad.getplayer().getposition().equals("gk")) { player.setplaygroundposition("gk"); player.setisselected(true); } // pick flex player if (squad.isflex()) { player.setplaygroundposition("flex"); player.setisselected(true); } // pick goalie if (squad.getplayer().getposition().equals("gk")) { player.setplaygroundposition("gk"); player.setisselected(true); } // pick dfs if ((squad.getplayer().getposition().equals("df")) && (!squad.isflex())) { int dfcounter = 1; player.setplaygroundposition(string.format(locale.english, "df%d", dfcounter)); player.setisselected(true); dfcounter++; } // pick mfs if ((squad.getplayer().getposition().equals("mf")) && (!squad.isflex())) { int mfcounter = 1; player.setplaygroundposition(string.format(locale.english, "mf%d", mfcounter)); player.setisselected(true); mfcounter++; } // pick fws if ((squad.getplayer().getposition().equals("fw")) && (!squad.isflex())) { int fwcounter = 1; player.setplaygroundposition(string.format(locale.english, "mf%d", fwcounter)); player.setisselected(true); fwcounter++; } realm.copytorealmorupdate(player); realm.committransaction(); updatefieldplayers(); }); } hideprogressbar(); }
realm.where(realmplayer.class).equalto("id", squad.getplayer().getid()) .findfirstasync() .<realmplayer>asobservable() .subscribe(new action1<realmplayer>() { @override public void call(realmplayer player) { } });
you should that.
btw, it's bad idea in cycle - check in method of realmquery.
Comments
Post a Comment