rx-android

Flatten Observable<Observable<Cursor>> to Observable<Cursor>

无人久伴 提交于 2019-12-10 09:20:37
问题 I've an Observable that returns a single Cursor instance ( Observable<Cursor> ). I'm trying to utilize ContentObservable.fromCursor to obtain every cursor's row in onNext callback. One of the solutions I've figured out is such construction: ContentObservable.fromCursor(cursorObservable.toBlocking().first()) .subscribe(cursor -> { // map to object // add to outer collection }, e -> {}, () -> { // do something with list of objects (outer collection) }); This looks rather like a hack because of

Schedulers.io() not returning to main thread

那年仲夏 提交于 2019-12-10 06:41:34
问题 I'm using RxParse to parse query's async load but when i subscribe my observable using subscribeOn(Schedulers.io()) my onCompleted method is never called on main thread. Instead of this, my onCompleted method is called inside of worker thread pool. If i use observeOn(AndroidSchedulers.mainThread) everything will work as well, but my onNextMethod will be called on main thread too and I don't want it. There is something wrong in my code? Have anything wrong in my code? ParseObservable.find

Executing delete with room (rxjava)

。_饼干妹妹 提交于 2019-12-10 03:31:59
问题 In room the @Delete annotation doesn't emit anything. This is what the dao looks like @Dao public interface UserDao { @Delete void deleteUser(User user); //We can't use Maybe or Single or anything here } This makes it a problem while doing something like userRepository.deleteUser().subscribeOn since we have no emission coming the dao . I use the following code to call deleteUser on a background thread. Observable.just(appDatabase). subscribeOn(SchedulerProvider.getInstance().computation()).

Where to draw the line with reactive programming [closed]

瘦欲@ 提交于 2019-12-10 03:06:05
问题 Closed . This question is opinion-based. It is not currently accepting answers. Want to improve this question? Update the question so it can be answered with facts and citations by editing this post. Closed 3 years ago . I have been using RxJava in my project for about a year now. With time, I grew to love it very much - now I'm thinking maybe too much... Most methods I write now have some form of Rx in it, which is great! (until it's not). I now notice that some methods require a lot of work

How to zip few observables in Kotlin language with RxAndroid

自古美人都是妖i 提交于 2019-12-10 02:28:46
问题 I have some problem. I'm a beginer in RxJava/RxKotlin/RxAndroid, and dont understand some features. For Example: import rus.pifpaf.client.data.catalog.models.Category import rus.pifpaf.client.data.main.MainRepository import rus.pifpaf.client.data.main.models.FrontDataModel import rus.pifpaf.client.data.product.models.Product import rx.Observable import rx.Single import rx.lang.kotlin.observable import java.util.* class MainInteractor { private var repository: MainRepository = MainRepository()

RxAndroid - retry observable on click

纵然是瞬间 提交于 2019-12-09 17:53:43
问题 I'm using rxAndroid and rxKotlin in my Android app to handle network requests asynchronously. Now I would like to retry a failed network request only after click on Snackbar button. My code now: val citiesService = ApiFactory.citiesService citiesService.cities() .subscribeOn(Schedulers.newThread()) // fetch List<String> .flatMap { Observable.from(it) } // convert to sequence of String .flatMap { city -> citiesService.coordinates(city) // fetch DoubleArray .map { City(city, it) } // convert to

RxAndroid button click Observer?

生来就可爱ヽ(ⅴ<●) 提交于 2019-12-09 13:53:16
问题 Hi fellow programmers, I am using RxAndroid to make an interval API call every 3 seconds when a button is pressed. private final CompositeDisposable disposables = new CompositeDisposable(); Observable fetchWeatherInterval = Observable.interval(3, TimeUnit.SECONDS) .map(new Function<Long, String>() { @Override public String apply(Long aLong) throws Exception { return getWeather("http://samples.openweathermap.org/data/2.5/weather?", "London,uk", "b1b15e88fa797225412429c1c50c122a1"); } })

UndeliverableException while calling onError of ObservableEmitter in RXjava2

試著忘記壹切 提交于 2019-12-08 15:58:21
问题 I have a method which creates an emitter like below, there are a problem(maybe it is normal behavior) with calling onError in retrofit callback. I got UndeliverableException when try to call onError. I can solve this by checking subscriber.isDiposed() by I wonder how can call onError coz i need to notify my UI level. Addition 1 --> RxJava2CallAdapterFactoryalready implemented private static Retrofit.Builder builderSwift = new Retrofit.Builder() .baseUrl(URL_SWIFT) .addCallAdapterFactory

How can I selectively observe Android Room database INSERT, DELETE, and UPDATE events?

前提是你 提交于 2019-12-08 11:26:26
问题 I have DAO designed this way. @Dao interface FooDao { @Query("SELECT * FROM foo") LiveData<List<Foo>> stream(); } The above lets me receive INSERT , UPDATE , and DELETE events all at once, which I have no way of knowing whether the data is recently inserted, deleted, or being updated. Goal My goal is to be able to update the database rapidly and have RecyclerView reflect the changes without stuttering or completely freezing. Current situation I have a background service that's updating the

How to merge several objects into a single one after execute the groupBy operation?

家住魔仙堡 提交于 2019-12-08 09:39:01
问题 I have the class below that I've created to illustrate my doubt. After doing the initial transformations on my flowable I have: UserScoreTO{id=1, name='john', score=4} UserScoreTO{id=1, name='john', score=5} UserScoreTO{id=1, name='john', score=1} UserScoreTO{id=2, name='paul', score=4} UserScoreTO{id=2, name='paul', score=2} UserScoreTO{id=3, name='mark', score=1} UserScoreTO{id=3, name='mark', score=7} I want to combine UserScoreTO objects with the same id into a Flowable that emits one