Commit 9e6c70f1 authored by Vladislav Bogdashkin's avatar Vladislav Bogdashkin 🎣

rxJavaPlugins errorHandler listener - need to be override due not all error...

rxJavaPlugins errorHandler listener - need to be override due not all error cases allowed to be resolved by  default rxJava behaviour
parent 836d57ab
......@@ -6,7 +6,11 @@ import com.biganto.visual.roompark.di.dagger.AppComponent
import com.biganto.visual.roompark.di.dagger.DaggerAppComponent
import dagger.android.AndroidInjector
import dagger.android.DaggerApplication
import io.reactivex.exceptions.UndeliverableException
import io.reactivex.plugins.RxJavaPlugins
import kotlinx.io.IOException
import timber.log.Timber
import java.net.SocketException
/**
* Created by Vladislav Bogdashkin on 03.09.2019.
......@@ -33,7 +37,41 @@ class RoomParkApplication : DaggerApplication() {
if (BuildConfig.DEBUG) Timber.plant(Timber.DebugTree())
else Timber.plant(CrashlyticsTree())
RxJavaPlugins.setErrorHandler { e ->
when (e) {
is UndeliverableException -> {
}
// fine, irrelevant network problem or API that throws on cancellation
is IOException -> return@setErrorHandler
is SocketException -> return@setErrorHandler
// fine, some blocking code was interrupted by a dispose call
is InterruptedException ->
return@setErrorHandler
// that's likely a bug in the application
is NullPointerException -> {
Thread.currentThread().uncaughtExceptionHandler
.uncaughtException(Thread.currentThread(), e)
return@setErrorHandler
}
is IllegalArgumentException -> {
Thread.currentThread().uncaughtExceptionHandler
.uncaughtException(Thread.currentThread(), e)
return@setErrorHandler
}
// that's a bug in RxJava or in a custom operator
is IllegalStateException -> {
Thread.currentThread().uncaughtExceptionHandler
.uncaughtException(Thread.currentThread(), e)
return@setErrorHandler
}
}
Timber.w(e, "Undeliverable exception received, not sure what to do")
}
}
}
......
......@@ -59,7 +59,8 @@ class ArticlesScreenController :
override fun feedSubscription(): Observable<Boolean> =
toolBar.headerToolbar.findViewById<SwitchMaterial>(R.id.switch1)
.checkedChanges()
.filter { Timber.d("silentCheck: $silentCheck")
.skip(1) //skip init switcher check state
.filter {
if (!silentCheck) return@filter !silentCheck
else silentCheck = false
silentCheck
......@@ -69,11 +70,6 @@ class ArticlesScreenController :
.observeOn(AndroidSchedulers.mainThread())
private var silentCheck = false
set(value) {
Timber.d("silent value: old: $field new $value")
field = value
}
override fun injectDependencies() {
......@@ -179,11 +175,9 @@ class ArticlesScreenController :
if (sw.isChecked != viewState.subState)
{
silentCheck = true
sw.isChecked = viewState.subState
}
sw.isChecked = viewState.subState
if (viewState.subState)
showError(ExceptionString(R.string.unsubscribe_error_message,null))
else showError(ExceptionString(R.string.subscribe_error_message,null))
......
......@@ -39,10 +39,16 @@ class ArticlesScreenPresenter @Inject constructor(
val onSubChecked = intent(ArticlesScreen::feedSubscription)
// .skip(1)
.filter { restoreModel.sub!=null }
.filter { restoreModel.sub != null }
.flatMap { newState ->
interactor.switchSubscription(restoreModel.sub!!,newState)
.andThen(Observable.just<ArticlesScreenViewState>(ArticlesScreenViewState.SubscriptionStatus(newState)))
interactor.switchSubscription(restoreModel.sub!!, newState)
.andThen(
Observable.just<ArticlesScreenViewState>(
ArticlesScreenViewState.SubscriptionStatus(
newState
)
)
)
.onErrorReturn { ArticlesScreenViewState.SubscriptionError(!newState) }
}
......@@ -72,31 +78,20 @@ class ArticlesScreenPresenter @Inject constructor(
.startWith(Observable.just<ArticlesScreenViewState>(ArticlesScreenViewState.Idle()))
val state =
Observable.mergeDelayError(
arrayListOf(
restoreStateObservable,
prefetchCards,
getNewArticlesPage,
fetchSubscription,
onSubChecked)
val state = Observable.mergeDelayError(
arrayListOf(
restoreStateObservable,
prefetchCards,
getNewArticlesPage,
fetchSubscription,
onSubChecked
)
.doOnError { Timber.e(it) }
.onErrorReturn(::parseError)
// .mergeWith(prefetchCards)
// .mergeWith(getNewArticlesPage)
// .mergeWith(fetchSubscription)
// .mergeWith(onSubChecked)
// val safeState = Observable.mergeDelayError {
//
// }
)
.doOnError { Timber.e(it) }
.onErrorReturn(::parseError)
.subscribeOn(Schedulers.io())
.observeOn(AndroidSchedulers.mainThread())
subscribeViewState(state.cast(ArticlesScreenViewState::class.java), ArticlesScreen::render)
}
}
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment