When the Retrofit Call does not succeed ( for example because no Internet), is called as expected the RXJava Callback onError
, where I have a Snackbar
with a setAction()
Listener indicated with an intuitive String "Retry" where I should pass a command to start again the network call.
I could restart the class where I am inside calling it NameActivity()
, but this look terrible.Which command I can pass inside the Snackbar
listener to restart the below code?
MyViewModel!!.getPost("132")
?.subscribeOn(schedulerProvider!!.io())
?.observeOn(schedulerProvider!!.ui())
?.doOnNext {
run {
spinner.setVisibility(View.VISIBLE)
}
}
?.subscribe(object : FlowableSubscriber<List<Post>> {
override fun onError(t: Throwable?) {
spinner.setVisibility(View.GONE)
spinner.visibility
Snackbar.make(view.findViewById(R.id.linearLayout), "Check Internet Connection!", Snackbar.LENGTH_INDEFINITE)
.setAction("Retry", {})//HERE THE COMMAND SHOULD PASS
.show();
}
override fun onComplete() {
Log.d("TAG", "onComplete: ")
}
override fun onSubscribe(s: Subscription) {
s.request(Long.MAX_VALUE);
}
override fun onNext(posts: List<Post>?) {
spinner.setVisibility(View.GONE)
posts?.let { viewAdapter.setTitleData(it) }
}
})
}