iex
02/11/2020, 3:51 PMLiveData
with a fixed value (like `Observable`'s just
), without having to use MutableLiveData
?ursus
02/13/2020, 2:44 AMfun resetService(service: Service, usage: Usage): Single<Foo> =
getSubscriber()
.map { it.subscriber }
.flatMap { subscriber ->
Single
.fromCallable {
val credit = usage.credit ?: 0.0
if (subscriber.type == Type.CREDIT && creditAmount < service.resetPrice) {
throw InsufficientCreditException(creditAmount, service.resetPrice)
}
val product = getProduct(cache, service.productId)
val usageManagement = product?.usageManagement ?: error("UsageManagent is null")
val resetProductId = product.resetProductIdOverride ?: usageManagement.resetProductId
tupleOf(usageManagement.action, resetProductId)
}
.doOnSuccess {
store.setProcessingSubscriber(subscriber.id, isProcessing = true)
}
.flatMap { (action, resetProductId) ->
setService(action, resetProductId, null, null, null, null)
}
.doOnErrorOrCancel {
store.setProcessingSubscriber(subscriber.id, isProcessing = false)
}
}
.doOnSuccess { updateManager.enqueueUpdate() }
iex
02/13/2020, 7:26 AMonErrorReturn
on the api observable(s) but this leads to a bit unwieldy chains in particular when there are several calls...Nikola Milovic
02/16/2020, 6:55 PMoverride fun loadDrillTypes(): Observable<ArrayList<DrillsType>> {
val list = ArrayList<DrillsType>()
firebaseFirestore.collection("drilltypes")
.get()
.addOnSuccessListener { documents ->
for (document in documents) {
val doc = document.toObject(DrillsType::class.java)
list.add(doc)
}
}
.addOnFailureListener { exception ->
Log.w("TAG", "Error getting documents: ", exception)
}
return Observable.just(list) // delay(2, TimeUnit.SECONDS)
}
I get an empty ArrayList
compositeDisposable += repository.loadDrillTypes()
.subscribeWith(object : DisposableObserver<ArrayList<DrillsType>>() {
override fun onError(e: Throwable) {
//if some error happens in our data layer our app will not crash, we will
// get error here
}
override fun onNext(data: ArrayList<DrillsType>) {
Log.d("TAG", data.toString())
}
override fun onComplete() {
Log.d("TAG", "COMPLETE")
}
})
}
But if i add the delay(2, seconds) then I get the normal result that I need... I am 100% sure there is a way around this without having it to be delayed. Or is the delay a standard practice?gsala
02/17/2020, 8:24 AMfun connect(bluetoothDevice: BluetoothDevice) : Observable<RxBleConnection>
. The reason this returns an Observable
instead of a Single
is that the life-cycle of the Observable
is tied to the connection. So this observable will only ever emit one item, but it will stay alive without completing so the connection stays alive until we dispose.
I want to wrap this to use coroutines instead.
I'm thinking about having a function like suspend fun connect(bluetoothDevice : BluetoothDevice) : RxBleConnection
,
Any ideas on how to handle the life-cycle of the Observable? If I just use connectObservable.awaitFirst()
it will take the first value, and dispose, which will stop the connection.alexsullivan114
02/18/2020, 2:41 PMshare
and buffer
to get that behavior, but I'd honestly just go the behavior subject route.iex
02/25/2020, 3:33 PMprivate val dealerAction: Single<DealerAction> = carDealersRepo.selectedCarDealer()
.map {
it.toDealerAction()
}
val dealerButtonTitle: LiveData<String> = dealerAction
.map { it.toButtonTitle() }
.toObservable()
.toLiveData()
When I navigate to a new screen, I change carDealersRepo's underlaying data. When I navigate back, I want that this view model re-fetches selectedCarDealer
iex
02/25/2020, 4:03 PMprivate val dealerButtonTrigger: PublishSubject<Unit> = PublishSubject.create()
init {
dealerButtonTrigger.withLatestFrom(dealerAction.toObservable())
.subscribe { (_, action) ->
action.handle()
}
}
Here, when I click (i.e. call dealerButtonTrigger.onNext(Unit)
) after updating the dealer and navigating back, it still gives me the first dealer. Shouldn't it get the updated value?iex
02/25/2020, 4:08 PMflatMap
instead of withLatestFrom
, but curious why withLatestFrom
doesn't. I thought it will get the current value at the point of time I activate the subject.iex
02/26/2020, 7:20 AMdoOnSubscribe
• Now we navigate forwards and back. This causes the observer (fragment/view) to re-subscribe.
• The api calls are not performed again, but doOnSubscribe
is called, making the progress indicator show for a very short moment.
-> How can we show the indicator only when the requests are being performed?Slackbot
02/26/2020, 7:27 AMNikola Milovic
02/26/2020, 9:25 AMval observer = object : DisposableObserver<DrillsType>() {
override fun onError(e: Throwable) {
Log.d("TAG", "error " + e.message)
}
override fun onNext(data: DrillsType) {
//onnext
}
override fun onComplete() {
Log.d("TAG", "COMPLETE")
}
}
remoteDataSource.loadDrillTypes().subscribeWith(observer)
}
It should be disposed when it's all finished. Can I dispose of it in the onComplete perhaps 😂?Nikola Milovic
02/27/2020, 3:17 PMMatsushita Kohei
03/01/2020, 12:12 AMDanil Novoselov
03/03/2020, 5:33 PMRich Lowenberg
03/18/2020, 7:53 PMivano
03/19/2020, 2:36 PMivano
03/20/2020, 12:21 PMursus
03/21/2020, 3:26 PMiex
03/25/2020, 1:55 PMCan't error out
I'd like that e.g. if I map a click button trigger to an api request an the api request fails, it executes again the next time the trigger is activated. Without having to create a new subscription each time.iex
03/27/2020, 2:29 PMSingle
)?
Maybe maintain BehaviorSubject
with the API results from the last fetch, but when / how do I fetch?ursus
04/07/2020, 4:00 PMursus
04/11/2020, 7:32 PMyougin
04/15/2020, 12:13 PMObservable
?
just(1)
.flatMap { just(2).delay(1, SECONDS).startWith(it) }
.subscribe { println(it) }
Just curious if I’m missing on some operator which does the thing.william
04/27/2020, 8:24 PMCompositeDisposable
for my entire application containing similar subscriptions or can i ignore the return value of .subscribe
?ursus
05/03/2020, 9:07 PMio
to computation
for your repository calls after networking?gabrielfv
05/12/2020, 2:12 PM.subscribe()
would make sense, but if the request fails for some reason the app crashes because there is no onError
handling. However, if I give it something so that it feels it has error handlung, like .subscribe({ }, { })
, I'll be passing on indirect reference to the enclosing class, which would prevent it from being garbage collected until the request returned.
Is there some sort of standard way of acting on such scenario?Nikola Milovic
05/14/2020, 11:47 AMException in thread "UI thread @coroutine#1" java.lang.ClassCastException: io.reactivex.Observer$Subclass1 cannot be cast to com.nikolam.basketpro.ui.drills.selection.DrillsSelectionViewModel$fetchDrillTypes$1$disposable$1
at com.nikolam.basketpro.ui.drills.selection.DrillsSelectionViewModel$fetchDrillTypes$1.invokeSuspend(DrillsSelectionViewModel.kt:37)
at kotlin.coroutines.jvm.internal.BaseContinuationImpl.resumeWith(ContinuationImpl.kt:33)
at kotlinx.coroutines.DispatchedTask.run(DispatchedTask.kt:56)
at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:511)
at java.util.concurrent.FutureTask.run(FutureTask.java:266)
at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.access$201(ScheduledThreadPoolExecutor.java:180)
at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.run(ScheduledThreadPoolExecutor.java:293)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624)
at java.lang.Thread.run(Thread.java:748)
I get a passing test with correct data but I also get this error
(code in thread so I dont spam)ursus
05/21/2020, 2:42 AMBehaviorRelay.value
?ursus
05/22/2020, 3:47 PMursus
05/22/2020, 3:47 PMivano
05/23/2020, 6:10 PMursus
05/23/2020, 6:54 PMivano
05/23/2020, 9:06 PM