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 ...@@ -6,7 +6,11 @@ import com.biganto.visual.roompark.di.dagger.AppComponent
import com.biganto.visual.roompark.di.dagger.DaggerAppComponent import com.biganto.visual.roompark.di.dagger.DaggerAppComponent
import dagger.android.AndroidInjector import dagger.android.AndroidInjector
import dagger.android.DaggerApplication import dagger.android.DaggerApplication
import io.reactivex.exceptions.UndeliverableException
import io.reactivex.plugins.RxJavaPlugins
import kotlinx.io.IOException
import timber.log.Timber import timber.log.Timber
import java.net.SocketException
/** /**
* Created by Vladislav Bogdashkin on 03.09.2019. * Created by Vladislav Bogdashkin on 03.09.2019.
...@@ -33,7 +37,41 @@ class RoomParkApplication : DaggerApplication() { ...@@ -33,7 +37,41 @@ class RoomParkApplication : DaggerApplication() {
if (BuildConfig.DEBUG) Timber.plant(Timber.DebugTree()) if (BuildConfig.DEBUG) Timber.plant(Timber.DebugTree())
else Timber.plant(CrashlyticsTree()) 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 : ...@@ -59,7 +59,8 @@ class ArticlesScreenController :
override fun feedSubscription(): Observable<Boolean> = override fun feedSubscription(): Observable<Boolean> =
toolBar.headerToolbar.findViewById<SwitchMaterial>(R.id.switch1) toolBar.headerToolbar.findViewById<SwitchMaterial>(R.id.switch1)
.checkedChanges() .checkedChanges()
.filter { Timber.d("silentCheck: $silentCheck") .skip(1) //skip init switcher check state
.filter {
if (!silentCheck) return@filter !silentCheck if (!silentCheck) return@filter !silentCheck
else silentCheck = false else silentCheck = false
silentCheck silentCheck
...@@ -69,11 +70,6 @@ class ArticlesScreenController : ...@@ -69,11 +70,6 @@ class ArticlesScreenController :
.observeOn(AndroidSchedulers.mainThread()) .observeOn(AndroidSchedulers.mainThread())
private var silentCheck = false private var silentCheck = false
set(value) {
Timber.d("silent value: old: $field new $value")
field = value
}
override fun injectDependencies() { override fun injectDependencies() {
...@@ -179,11 +175,9 @@ class ArticlesScreenController : ...@@ -179,11 +175,9 @@ class ArticlesScreenController :
if (sw.isChecked != viewState.subState) if (sw.isChecked != viewState.subState)
{ {
silentCheck = true silentCheck = true
sw.isChecked = viewState.subState
} }
sw.isChecked = viewState.subState
if (viewState.subState) if (viewState.subState)
showError(ExceptionString(R.string.unsubscribe_error_message,null)) showError(ExceptionString(R.string.unsubscribe_error_message,null))
else showError(ExceptionString(R.string.subscribe_error_message,null)) else showError(ExceptionString(R.string.subscribe_error_message,null))
......
...@@ -39,10 +39,16 @@ class ArticlesScreenPresenter @Inject constructor( ...@@ -39,10 +39,16 @@ class ArticlesScreenPresenter @Inject constructor(
val onSubChecked = intent(ArticlesScreen::feedSubscription) val onSubChecked = intent(ArticlesScreen::feedSubscription)
// .skip(1) // .skip(1)
.filter { restoreModel.sub!=null } .filter { restoreModel.sub != null }
.flatMap { newState -> .flatMap { newState ->
interactor.switchSubscription(restoreModel.sub!!,newState) interactor.switchSubscription(restoreModel.sub!!, newState)
.andThen(Observable.just<ArticlesScreenViewState>(ArticlesScreenViewState.SubscriptionStatus(newState))) .andThen(
Observable.just<ArticlesScreenViewState>(
ArticlesScreenViewState.SubscriptionStatus(
newState
)
)
)
.onErrorReturn { ArticlesScreenViewState.SubscriptionError(!newState) } .onErrorReturn { ArticlesScreenViewState.SubscriptionError(!newState) }
} }
...@@ -72,31 +78,20 @@ class ArticlesScreenPresenter @Inject constructor( ...@@ -72,31 +78,20 @@ class ArticlesScreenPresenter @Inject constructor(
.startWith(Observable.just<ArticlesScreenViewState>(ArticlesScreenViewState.Idle())) .startWith(Observable.just<ArticlesScreenViewState>(ArticlesScreenViewState.Idle()))
val state = val state = Observable.mergeDelayError(
Observable.mergeDelayError( arrayListOf(
arrayListOf( restoreStateObservable,
restoreStateObservable, prefetchCards,
prefetchCards, getNewArticlesPage,
getNewArticlesPage, fetchSubscription,
fetchSubscription, onSubChecked
onSubChecked)
) )
.doOnError { Timber.e(it) } )
.onErrorReturn(::parseError) .doOnError { Timber.e(it) }
.onErrorReturn(::parseError)
// .mergeWith(prefetchCards)
// .mergeWith(getNewArticlesPage)
// .mergeWith(fetchSubscription)
// .mergeWith(onSubChecked)
// val safeState = Observable.mergeDelayError {
//
// }
.subscribeOn(Schedulers.io()) .subscribeOn(Schedulers.io())
.observeOn(AndroidSchedulers.mainThread()) .observeOn(AndroidSchedulers.mainThread())
subscribeViewState(state.cast(ArticlesScreenViewState::class.java), ArticlesScreen::render) 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