Commit 28a39fa1 authored by Vladislav Bogdashkin's avatar Vladislav Bogdashkin 🎣

add default error handler to all screens

parent 3de637c8
......@@ -15,6 +15,7 @@ import com.biganto.visual.roompark.base.ICollapsingToolBar
import com.biganto.visual.roompark.base.RoomParkMainActivity
import com.biganto.visual.roompark.conductor.mosby.mvi.BigantoMviController
import com.biganto.visual.roompark.di.dagger.ActivityModule
import com.biganto.visual.roompark.util.monades.ExceptionString
import com.biganto.visual.roompark.util.view_utils.snackbar.ISnackBarProvider
import com.hannesdorfmann.mosby3.mvi.MviBasePresenter
import io.reactivex.disposables.CompositeDisposable
......@@ -93,6 +94,9 @@ abstract class BigantoBaseController<VS : BigantoBaseViewState,V: BigantoBaseCon
return super.handleBack()
}
fun showError(e: ExceptionString) =
e.selectHandler(snackbar::showSnackBar,snackbar::showSnackBar)
protected val isTablet
get() = resources?.getBoolean(R.bool.isTablet)?:false
......
......@@ -22,8 +22,10 @@ abstract class BigantoBasePresenter<V : MvpView, VS>
Observable.defer { Observable.just(parseError(t)) }
abstract fun vsByCode(code: Int): (ExceptionString) -> VS
abstract fun vsByThrowable(t: Throwable): (ExceptionString) -> VS
abstract fun defaultErrorViewStateHandler(): (ExceptionString) -> VS
open fun vsByCode(code: Int) = defaultErrorViewStateHandler()
open fun vsByThrowable(t: Throwable) = defaultErrorViewStateHandler()
open fun parseError(t: Throwable): VS =
when (t) {
......
......@@ -2,6 +2,7 @@ package com.biganto.visual.roompark.presentation.screen.article
import com.biganto.visual.roompark.conductor.BigantoBasePresenter
import com.biganto.visual.roompark.domain.interactor.ArticleInteractor
import com.biganto.visual.roompark.util.monades.ExceptionString
import io.reactivex.android.schedulers.AndroidSchedulers
import io.reactivex.schedulers.Schedulers
import timber.log.Timber
......@@ -16,6 +17,8 @@ class ArticleScreenPresenter @Inject constructor(
private val interactor: ArticleInteractor
)
: BigantoBasePresenter<ArticleScreen, ArticleScreenViewState>() {
override fun defaultErrorViewStateHandler()=
{e:ExceptionString -> ArticleScreenViewState.SomeError(e)}
override fun bindIntents() {
......
......@@ -2,6 +2,7 @@ package com.biganto.visual.roompark.presentation.screen.article
import com.biganto.visual.roompark.conductor.BigantoBaseViewState
import com.biganto.visual.roompark.domain.model.ArticleModel
import com.biganto.visual.roompark.util.monades.ExceptionString
/**
* Created by Vladislav Bogdashkin on 30.09.2019.
......@@ -11,4 +12,5 @@ import com.biganto.visual.roompark.domain.model.ArticleModel
sealed class ArticleScreenViewState : BigantoBaseViewState() {
class Idle : ArticleScreenViewState()
class ArticleLoaded(val item: ArticleModel) : ArticleScreenViewState()
class SomeError(val error:ExceptionString ) : ArticleScreenViewState()
}
\ No newline at end of file
......@@ -93,13 +93,12 @@ class AuthScreenController :
}
private fun render(viewState: AuthScreenViewState.SignInError){
viewState.exception.selectHandler(snackbar::showSnackBar,snackbar::showSnackBar)
showError(viewState.exception)
signInButton.isEnabled=true
}
private fun render(viewState: AuthScreenViewState.SomeError){
viewState.exception.selectHandler(snackbar::showSnackBar,snackbar::showSnackBar)
}
private fun render(viewState: AuthScreenViewState.SomeError) =
showError(viewState.exception)
override fun getLayoutId(): Int = R.layout.authentication_screen
......
......@@ -18,15 +18,15 @@ class AuthScreenPresenter @Inject constructor(
)
: BigantoBasePresenter<AuthScreen, AuthScreenViewState>() {
override fun defaultErrorViewStateHandler() =
{e:ExceptionString -> AuthScreenViewState.SomeError(e)}
override fun vsByCode(code: Int): (ExceptionString) -> AuthScreenViewState =
when (code) {
101 -> {e:ExceptionString -> AuthScreenViewState.SignInError(e)}
else -> {e:ExceptionString -> AuthScreenViewState.SomeError(e)}
}
override fun vsByThrowable(t: Throwable): (ExceptionString) -> AuthScreenViewState =
{e:ExceptionString -> AuthScreenViewState.SomeError(e)}
override fun bindIntents() {
val onAuth = intent(AuthScreen::tryAuth)
......
......@@ -69,6 +69,7 @@ class DealsScreenController :
when(viewState){
is DealsScreenViewState.Idle -> render(viewState)
is DealsScreenViewState.DealsLoaded -> render(viewState)
is DealsScreenViewState.SomeError -> render(viewState)
}
}
......@@ -76,12 +77,13 @@ class DealsScreenController :
}
private fun render(viewState: DealsScreenViewState.DealsLoaded){
(favoritesRecyclerView.adapter as DealsListAdapter).addItems(viewState.items)
}
private fun render(viewState: DealsScreenViewState.SomeError) =
showError(viewState.exception)
private fun getComponent() = DaggerDealsScreenComponent.factory()
.create(RoomParkApplication.component,activity as RoomParkMainActivity)
.inject(this)
......
......@@ -2,6 +2,7 @@ package com.biganto.visual.roompark.presentation.screen.deals
import com.biganto.visual.roompark.conductor.BigantoBasePresenter
import com.biganto.visual.roompark.domain.interactor.DealsInteractor
import com.biganto.visual.roompark.util.monades.ExceptionString
import io.reactivex.android.schedulers.AndroidSchedulers
import io.reactivex.schedulers.Schedulers
import timber.log.Timber
......@@ -17,6 +18,8 @@ class DealsScreenPresenter @Inject constructor(
)
: BigantoBasePresenter<DealsScreen, DealsScreenViewState>() {
override fun defaultErrorViewStateHandler() =
{e:ExceptionString -> DealsScreenViewState.SomeError(e)}
override fun bindIntents() {
......
package com.biganto.visual.roompark.presentation.screen.deals
import com.biganto.visual.roompark.conductor.BigantoBaseViewState
import com.biganto.visual.roompark.util.monades.ExceptionString
/**
* Created by Vladislav Bogdashkin on 30.09.2019.
......@@ -10,5 +11,6 @@ import com.biganto.visual.roompark.conductor.BigantoBaseViewState
sealed class DealsScreenViewState : BigantoBaseViewState() {
class Idle : DealsScreenViewState()
class DealsLoaded(val items:List<DealPreviewModel>) : DealsScreenViewState()
class SomeError(val exception: ExceptionString) : DealsScreenViewState()
}
......@@ -70,6 +70,7 @@ class FavoritesScreenController :
when(viewState){
is FavoritesScreenViewState.Idle -> render(viewState)
is FavoritesScreenViewState.FavoriteEstatesLoaded -> render(viewState)
is FavoritesScreenViewState.SomeError -> render(viewState)
}
}
......@@ -77,6 +78,9 @@ class FavoritesScreenController :
}
private fun render(viewState: FavoritesScreenViewState.SomeError) =
showError(viewState.exception)
private fun render(viewState: FavoritesScreenViewState.FavoriteEstatesLoaded) {
(favoritesRecyclerView.adapter as FavoritesListAdapter).addItems(viewState.items)
......
......@@ -2,6 +2,7 @@ package com.biganto.visual.roompark.presentation.screen.favorites
import com.biganto.visual.roompark.conductor.BigantoBasePresenter
import com.biganto.visual.roompark.domain.interactor.FavoritesInteractor
import com.biganto.visual.roompark.util.monades.ExceptionString
import io.reactivex.android.schedulers.AndroidSchedulers
import io.reactivex.schedulers.Schedulers
import timber.log.Timber
......@@ -17,6 +18,8 @@ class FavoritesScreenPresenter @Inject constructor(
)
: BigantoBasePresenter<FavoritesScreen, FavoritesScreenViewState>() {
override fun defaultErrorViewStateHandler() =
{e: ExceptionString -> FavoritesScreenViewState.SomeError(e)}
override fun bindIntents() {
......
......@@ -2,6 +2,7 @@ package com.biganto.visual.roompark.presentation.screen.favorites
import com.biganto.visual.roompark.conductor.BigantoBaseViewState
import com.biganto.visual.roompark.domain.model.EstateModel
import com.biganto.visual.roompark.util.monades.ExceptionString
/**
* Created by Vladislav Bogdashkin on 30.09.2019.
......@@ -11,4 +12,5 @@ import com.biganto.visual.roompark.domain.model.EstateModel
sealed class FavoritesScreenViewState : BigantoBaseViewState() {
class Idle : FavoritesScreenViewState()
class FavoriteEstatesLoaded(val items: List<EstateModel>) : FavoritesScreenViewState()
class SomeError(val exception: ExceptionString) : FavoritesScreenViewState()
}
\ No newline at end of file
......@@ -86,6 +86,7 @@ class ArticlesScreenController :
when(viewState){
is ArticlesScreenViewState.Idle -> render(viewState)
is ArticlesScreenViewState.ArticlesLoaded -> render(viewState)
is ArticlesScreenViewState.SomeError -> render(viewState)
}
}
......@@ -93,6 +94,8 @@ class ArticlesScreenController :
}
private fun render(viewState: ArticlesScreenViewState.SomeError) =
showError(viewState.exception)
private fun render(viewState: ArticlesScreenViewState.ArticlesLoaded) {
(articlesRecyclerView.adapter as ArticlesAdapter).setItems(viewState.items)
......
......@@ -2,6 +2,7 @@ package com.biganto.visual.roompark.presentation.screen.feed_list
import com.biganto.visual.roompark.conductor.BigantoBasePresenter
import com.biganto.visual.roompark.domain.interactor.ArticlesInteractor
import com.biganto.visual.roompark.util.monades.ExceptionString
import io.reactivex.android.schedulers.AndroidSchedulers
import io.reactivex.schedulers.Schedulers
import timber.log.Timber
......@@ -19,6 +20,8 @@ class ArticlesScreenPresenter @Inject constructor(
)
: BigantoBasePresenter<ArticlesScreen, ArticlesScreenViewState>() {
override fun defaultErrorViewStateHandler() =
{e: ExceptionString -> ArticlesScreenViewState.SomeError(e)}
override fun bindIntents() {
Timber.d("feedId : $feedId")
......
......@@ -2,6 +2,7 @@ package com.biganto.visual.roompark.presentation.screen.feed_list
import com.biganto.visual.roompark.conductor.BigantoBaseViewState
import com.biganto.visual.roompark.domain.model.ArticlePreviewModel
import com.biganto.visual.roompark.util.monades.ExceptionString
/**
* Created by Vladislav Bogdashkin on 30.09.2019.
......@@ -11,4 +12,5 @@ import com.biganto.visual.roompark.domain.model.ArticlePreviewModel
sealed class ArticlesScreenViewState : BigantoBaseViewState() {
class Idle : ArticlesScreenViewState()
class ArticlesLoaded(val items: List<ArticlePreviewModel>) : ArticlesScreenViewState()
class SomeError(val exception: ExceptionString) : ArticlesScreenViewState()
}
\ No newline at end of file
......@@ -123,6 +123,7 @@ class FeedsScreenController :
is FeedsScreenViewState.CamsList -> render(viewState)
is FeedsScreenViewState.GetFeedArticlesPreview -> render(viewState)
is FeedsScreenViewState.RestoreView -> render(viewState)
is FeedsScreenViewState.SomeError -> render(viewState)
}
}
......@@ -130,6 +131,9 @@ class FeedsScreenController :
}
private fun render(viewState: FeedsScreenViewState.SomeError) =
showError(viewState.exception)
private fun allFeedName(feedId:Int) = if (feedId==1) "НОВОСТИ" else "БЛОГИ"
@SuppressLint("SetTextI18n")
......
......@@ -2,6 +2,7 @@ package com.biganto.visual.roompark.presentation.screen.feeds
import com.biganto.visual.roompark.conductor.BigantoBasePresenter
import com.biganto.visual.roompark.domain.interactor.FeedsInteractor
import com.biganto.visual.roompark.util.monades.ExceptionString
import io.reactivex.android.schedulers.AndroidSchedulers
import io.reactivex.schedulers.Schedulers
import timber.log.Timber
......@@ -17,6 +18,10 @@ class FeedsScreenPresenter @Inject constructor(
)
: BigantoBasePresenter<FeedsScreen, FeedsScreenViewState>() {
override fun defaultErrorViewStateHandler() =
{e: ExceptionString -> FeedsScreenViewState.SomeError(e)}
private val restoreModel = RestoreModel(
arrayListOf(),
arrayListOf(),
......
......@@ -5,6 +5,7 @@ import com.biganto.visual.roompark.domain.model.AlbumPreviewModel
import com.biganto.visual.roompark.domain.model.ArticlePreviewModel
import com.biganto.visual.roompark.domain.model.FeedModel
import com.biganto.visual.roompark.domain.model.WebCamModel
import com.biganto.visual.roompark.util.monades.ExceptionString
/**
* Created by Vladislav Bogdashkin on 30.09.2019.
......@@ -20,6 +21,8 @@ sealed class FeedsScreenViewState : BigantoBaseViewState() {
class GetFeedArticlesPreview(val items:List<ArticlePreviewModel>) : FeedsScreenViewState()
class RestoreView(val restore:RestoreModel) : FeedsScreenViewState()
class SomeError(val exception: ExceptionString) : FeedsScreenViewState()
}
data class RestoreModel(
......
package com.biganto.visual.roompark.presentation.screen.home
import com.biganto.visual.roompark.conductor.BigantoBasePresenter
import com.biganto.visual.roompark.util.monades.ExceptionString
import javax.inject.Inject
/**
......@@ -13,6 +14,9 @@ class HomeScreenPresenter @Inject constructor(
)
: BigantoBasePresenter<HomeScreen, HomeScreenViewState>() {
override fun defaultErrorViewStateHandler() =
{e: ExceptionString -> HomeScreenViewState.SomeError(e)}
override fun bindIntents() {
val state = restoreStateObservable
subscribeViewState(state.cast(HomeScreenViewState::class.java), HomeScreen::render)
......
package com.biganto.visual.roompark.presentation.screen.home
import com.biganto.visual.roompark.conductor.BigantoBaseViewState
import com.biganto.visual.roompark.util.monades.ExceptionString
/**
* Created by Vladislav Bogdashkin on 30.09.2019.
......@@ -10,4 +11,5 @@ import com.biganto.visual.roompark.conductor.BigantoBaseViewState
sealed class HomeScreenViewState : BigantoBaseViewState() {
class Idle : HomeScreenViewState()
class ToScreen(val message:String) : HomeScreenViewState()
class SomeError(val exception: ExceptionString) : HomeScreenViewState()
}
\ No newline at end of file
......@@ -68,6 +68,7 @@ class HomeBottomNavigationController(@IdRes toPage: Int = R.id.tab_feeds)
when(viewState){
is HomeScreenViewState.Idle -> render(viewState)
is HomeScreenViewState.ToScreen -> render(viewState)
is HomeScreenViewState.SomeError -> render(viewState)
}
}
......@@ -75,6 +76,9 @@ class HomeBottomNavigationController(@IdRes toPage: Int = R.id.tab_feeds)
}
private fun render(viewState: HomeScreenViewState.SomeError) =
showError(viewState.exception)
private fun render(viewState: HomeScreenViewState.ToScreen){
......
......@@ -93,9 +93,13 @@ class SettingsScreenController :
when(viewState){
is SettingsScreenViewState.Idle -> render(viewState)
is SettingsScreenViewState.LoadSettingsList -> render(viewState)
is SettingsScreenViewState.SomeError -> render(viewState)
}
}
private fun render(viewState: SettingsScreenViewState.SomeError) =
showError(viewState.exception)
private fun render(viewState: SettingsScreenViewState.Idle){
}
......
......@@ -2,6 +2,7 @@ package com.biganto.visual.roompark.presentation.screen.settings
import com.biganto.visual.roompark.conductor.BigantoBasePresenter
import com.biganto.visual.roompark.domain.interactor.SettingsInteractor
import com.biganto.visual.roompark.util.monades.ExceptionString
import io.reactivex.android.schedulers.AndroidSchedulers
import io.reactivex.schedulers.Schedulers
import timber.log.Timber
......@@ -17,6 +18,8 @@ class SettingsScreenPresenter @Inject constructor(
)
: BigantoBasePresenter<SettingsScreen, SettingsScreenViewState>() {
override fun defaultErrorViewStateHandler() =
{e: ExceptionString -> SettingsScreenViewState.SomeError(e)}
override fun bindIntents() {
......
......@@ -2,6 +2,7 @@ package com.biganto.visual.roompark.presentation.screen.settings
import com.biganto.visual.roompark.conductor.BigantoBaseViewState
import com.biganto.visual.roompark.domain.model.SettingsModel
import com.biganto.visual.roompark.util.monades.ExceptionString
/**
* Created by Vladislav Bogdashkin on 30.09.2019.
......@@ -11,4 +12,5 @@ import com.biganto.visual.roompark.domain.model.SettingsModel
sealed class SettingsScreenViewState : BigantoBaseViewState() {
class Idle : SettingsScreenViewState()
class LoadSettingsList(val settings:SettingsModel) : SettingsScreenViewState()
class SomeError(val exception: ExceptionString) : SettingsScreenViewState()
}
\ No newline at end of file
......@@ -2,7 +2,6 @@ package com.biganto.visual.roompark.presentation.screen.splash
import android.view.View
import com.biganto.visual.roompark.R
import com.biganto.visual.roompark.base.ICollapsingToolBar
import com.biganto.visual.roompark.base.RoomParkApplication
import com.biganto.visual.roompark.base.RoomParkMainActivity
import com.biganto.visual.roompark.conductor.BigantoBaseController
......@@ -53,6 +52,7 @@ class SplashScreenController :
is SplashScreenViewState.Idle -> render(viewState)
is SplashScreenViewState.ToAuthScreen -> render(viewState)
is SplashScreenViewState.ToHomeScreen -> render(viewState)
is SplashScreenViewState.SomeError -> render(viewState)
}
}
......@@ -60,6 +60,9 @@ class SplashScreenController :
}
private fun render(viewState: SplashScreenViewState.SomeError) =
showError(viewState.exception)
private fun render(viewState: SplashScreenViewState.ToAuthScreen){
router.pushController(RouterTransaction.with(AuthScreenController())
.popChangeHandler(FadeChangeHandler())
......
......@@ -3,6 +3,7 @@ package com.biganto.visual.roompark.presentation.screen.splash
import com.biganto.visual.roompark.base.RoomParkMainActivity
import com.biganto.visual.roompark.conductor.BigantoBasePresenter
import com.biganto.visual.roompark.domain.interactor.SplashInteractor
import com.biganto.visual.roompark.util.monades.ExceptionString
import javax.inject.Inject
/**
......@@ -17,6 +18,9 @@ class SplashScreenPresenter @Inject constructor(
)
: BigantoBasePresenter<SplashScreen, SplashScreenViewState>() {
override fun defaultErrorViewStateHandler() =
{e: ExceptionString -> SplashScreenViewState.SomeError(e)}
override fun bindIntents() {
val state = restoreStateObservable
......
package com.biganto.visual.roompark.presentation.screen.splash
import com.biganto.visual.roompark.conductor.BigantoBaseViewState
import com.biganto.visual.roompark.util.monades.ExceptionString
/**
* Created by Vladislav Bogdashkin on 30.09.2019.
......@@ -11,4 +12,5 @@ sealed class SplashScreenViewState : BigantoBaseViewState() {
class Idle : SplashScreenViewState()
class ToHomeScreen() : SplashScreenViewState()
class ToAuthScreen() : SplashScreenViewState()
class SomeError(val exception: ExceptionString) : SplashScreenViewState()
}
\ No newline at end of file
......@@ -101,9 +101,13 @@ class FindFlatScreenController :
Timber.d("Render state $viewState")
when(viewState){
is FindFlatScreenViewState.Idle -> render(viewState)
is FindFlatScreenViewState.StartTour -> render(viewState)
}
}
private fun render(viewState: FindFlatScreenViewState.SomeError) =
showError(viewState.exception)
private fun render(viewState: FindFlatScreenViewState.Idle){
}
......
......@@ -2,6 +2,7 @@ package com.biganto.visual.roompark.presentation.screen.to_flat
import com.biganto.visual.roompark.conductor.BigantoBasePresenter
import com.biganto.visual.roompark.domain.interactor.FindFlatInteractor
import com.biganto.visual.roompark.util.monades.ExceptionString
import io.reactivex.Observable
import io.reactivex.android.schedulers.AndroidSchedulers
import io.reactivex.schedulers.Schedulers
......@@ -18,6 +19,9 @@ class FindFlatScreenPresenter @Inject constructor(
)
: BigantoBasePresenter<FindFlatScreen, FindFlatScreenViewState>() {
override fun defaultErrorViewStateHandler() =
{e: ExceptionString -> FindFlatScreenViewState.SomeError(e)}
override fun bindIntents() {
......
......@@ -2,6 +2,7 @@ package com.biganto.visual.roompark.presentation.screen.to_flat
import com.biganto.visual.roompark.conductor.BigantoBaseViewState
import com.biganto.visual.roompark.domain.model.TourModel
import com.biganto.visual.roompark.util.monades.ExceptionString
/**
* Created by Vladislav Bogdashkin on 30.09.2019.
......@@ -14,4 +15,5 @@ sealed class FindFlatScreenViewState : BigantoBaseViewState() {
class TourFounded(val items:List<TourModel>) : FindFlatScreenViewState()
class StartTour(val tourId:String) : FindFlatScreenViewState()
class FlatNotFound() : FindFlatScreenViewState()
class SomeError(val exception: ExceptionString) : FindFlatScreenViewState()
}
\ 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