Commit 9678c356 authored by Vladislav Bogdashkin's avatar Vladislav Bogdashkin 🎣

Merge branch 'feature/resolve_common_issues' into develop

w
parents 5f55c936 28a39fa1
...@@ -15,6 +15,7 @@ import com.biganto.visual.roompark.base.ICollapsingToolBar ...@@ -15,6 +15,7 @@ import com.biganto.visual.roompark.base.ICollapsingToolBar
import com.biganto.visual.roompark.base.RoomParkMainActivity import com.biganto.visual.roompark.base.RoomParkMainActivity
import com.biganto.visual.roompark.conductor.mosby.mvi.BigantoMviController import com.biganto.visual.roompark.conductor.mosby.mvi.BigantoMviController
import com.biganto.visual.roompark.di.dagger.ActivityModule 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.biganto.visual.roompark.util.view_utils.snackbar.ISnackBarProvider
import com.hannesdorfmann.mosby3.mvi.MviBasePresenter import com.hannesdorfmann.mosby3.mvi.MviBasePresenter
import io.reactivex.disposables.CompositeDisposable import io.reactivex.disposables.CompositeDisposable
...@@ -93,6 +94,9 @@ abstract class BigantoBaseController<VS : BigantoBaseViewState,V: BigantoBaseCon ...@@ -93,6 +94,9 @@ abstract class BigantoBaseController<VS : BigantoBaseViewState,V: BigantoBaseCon
return super.handleBack() return super.handleBack()
} }
fun showError(e: ExceptionString) =
e.selectHandler(snackbar::showSnackBar,snackbar::showSnackBar)
protected val isTablet protected val isTablet
get() = resources?.getBoolean(R.bool.isTablet)?:false get() = resources?.getBoolean(R.bool.isTablet)?:false
......
package com.biganto.visual.roompark.conductor package com.biganto.visual.roompark.conductor
import com.biganto.visual.roompark.R
import com.biganto.visual.roompark.data.service.network.NoNetworkException
import com.biganto.visual.roompark.domain.custom_exception.CustomApiException
import com.biganto.visual.roompark.util.monades.ExceptionString
import com.hannesdorfmann.mosby3.mvi.MviBasePresenter import com.hannesdorfmann.mosby3.mvi.MviBasePresenter
import com.hannesdorfmann.mosby3.mvp.MvpView import com.hannesdorfmann.mosby3.mvp.MvpView
import com.jakewharton.rxrelay2.PublishRelay import com.jakewharton.rxrelay2.PublishRelay
import io.reactivex.Observable
/** /**
* Created by Vladislav Bogdashkin on 30.09.2019. * Created by Vladislav Bogdashkin on 30.09.2019.
*/ */
abstract class BigantoBasePresenter<V : MvpView, VS> abstract class BigantoBasePresenter<V : MvpView, VS>
: MviBasePresenter<V, VS>(){ : MviBasePresenter<V, VS>() {
protected val restoreStateObservable = protected val restoreStateObservable =
PublishRelay.create<VS>() PublishRelay.create<VS>()
fun observableParseError(t: Throwable): Observable<VS> =
Observable.defer { Observable.just(parseError(t)) }
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) {
is CustomApiException -> parseError(t)
is NoNetworkException -> parseError(t)
else -> parseError(t)
}
private fun parseError(e: CustomApiException) = onCodeReturn(e)
private fun parseError(e: NoNetworkException) = onNoNetwork(e)
private fun parseError(e: Exception) = onRandomError(e)
open fun onRandomError(t: Throwable): VS =
vsByThrowable(t).invoke(
ExceptionString(R.string.unknown_error, null)
)
open fun onNoNetwork(e: NoNetworkException): VS =
vsByThrowable(e).invoke(
ExceptionString(R.string.no_network_error, null)
)
private fun onCodeReturn(e: CustomApiException): VS =
vsByCode(e.code).invoke(ExceptionString(e))
} }
\ No newline at end of file
...@@ -3,10 +3,7 @@ package com.biganto.visual.roompark.data.repository.api.retrofit.di ...@@ -3,10 +3,7 @@ package com.biganto.visual.roompark.data.repository.api.retrofit.di
import android.content.Context import android.content.Context
import com.biganto.visual.roompark.data.repository.api.retrofit.IRoomParkMobileApi import com.biganto.visual.roompark.data.repository.api.retrofit.IRoomParkMobileApi
import com.biganto.visual.roompark.data.repository.api.retrofit.raw.ErrorRaw import com.biganto.visual.roompark.data.repository.api.retrofit.raw.ErrorRaw
import com.biganto.visual.roompark.data.repository.api.retrofit.util.DateSerializer import com.biganto.visual.roompark.data.repository.api.retrofit.util.*
import com.biganto.visual.roompark.data.repository.api.retrofit.util.ErrorsListDeserializer
import com.biganto.visual.roompark.data.repository.api.retrofit.util.NullOnEmptyConverterFactory
import com.biganto.visual.roompark.data.repository.api.retrofit.util.VersionValidationInterceptor
import com.biganto.visual.roompark.data.service.network.INetworkMonitor import com.biganto.visual.roompark.data.service.network.INetworkMonitor
import com.biganto.visual.roompark.data.service.network.LiveNetworkMonitor import com.biganto.visual.roompark.data.service.network.LiveNetworkMonitor
import com.biganto.visual.roompark.data.service.network.NoNetworkException import com.biganto.visual.roompark.data.service.network.NoNetworkException
...@@ -46,6 +43,7 @@ class RetrofitModule{ ...@@ -46,6 +43,7 @@ class RetrofitModule{
private fun gsonConverterFactory() = GsonConverterFactory.create( private fun gsonConverterFactory() = GsonConverterFactory.create(
GsonBuilder() GsonBuilder()
.registerTypeHierarchyAdapter(Any::class.java,CustomExceptionDeserializer<Any>())
.registerTypeAdapter(genericType<MutableList<ErrorRaw>>(), ErrorsListDeserializer()) .registerTypeAdapter(genericType<MutableList<ErrorRaw>>(), ErrorsListDeserializer())
.registerTypeAdapter(Date::class.java, DateSerializer()) .registerTypeAdapter(Date::class.java, DateSerializer())
.setLenient() .setLenient()
......
package com.biganto.visual.roompark.data.repository.api.retrofit.util
import com.biganto.visual.roompark.data.repository.api.retrofit.raw.ErrorRaw
import com.biganto.visual.roompark.domain.custom_exception.parseException
import com.google.gson.Gson
import com.google.gson.JsonDeserializationContext
import com.google.gson.JsonDeserializer
import com.google.gson.JsonElement
import org.json.JSONArray
import org.json.JSONObject
import timber.log.Timber
import java.lang.reflect.Type
/**
* Created by Vladislav Bogdashkin on 12.11.2019.
*/
class CustomExceptionDeserializer<T> : JsonDeserializer<T> {
override fun deserialize(json: JsonElement, typeOfT: Type, ctx: JsonDeserializationContext): T {
val vals = ArrayList<ErrorRaw>()
//region valid case
when(json){
is JSONObject -> if (!json.asJsonObject.keySet().contains("errors"))
return Gson().newBuilder().create().fromJson(json,typeOfT)
is JSONArray -> return Gson().newBuilder().create().fromJson(json,typeOfT)
}
//endregion valid case
//region parse errorList
val errorList = json.asJsonObject.get("errors")
Timber.w("api errorlist: $errorList")
when(json) {
is JSONArray -> errorList.asJsonArray.forEach{
vals.add(ctx.deserialize<T>(it, ErrorRaw::class.java) as ErrorRaw)
}
is JSONObject -> json.asJsonObject.get("errors").asJsonArray.forEach {
vals.add(ctx.deserialize<T>(it, ErrorRaw::class.java) as ErrorRaw)
}
else -> throw RuntimeException("Unexpected JSON type: " + json.javaClass)
}
if (vals.size==0)
error("unhandled api result : $json")
throw parseException(vals.first()) //-> for now throws only first!
//endregion
}
}
\ No newline at end of file
...@@ -82,7 +82,7 @@ const val CUSTOM_API_ERROR_RESPONSE_CODE_TOUR_NOT_FOUND_MESSAGE_ID=R.string.api_ ...@@ -82,7 +82,7 @@ const val CUSTOM_API_ERROR_RESPONSE_CODE_TOUR_NOT_FOUND_MESSAGE_ID=R.string.api_
@StringRes @StringRes
const val CUSTOM_API_ERROR_DEFAULT_MESSAGE_ID=R.string.api_error_default const val CUSTOM_API_ERROR_DEFAULT_MESSAGE_ID=R.string.api_error_default
sealed class CustomApiException(val code:Int,@StringRes val messageStringId: Int):Exception() { sealed class CustomApiException(val code:Int,@StringRes val messageStringId: Int?, val customMessage:String? = null):Exception() {
class NotAuthorizedException() : CustomApiException(CUSTOM_API_ERROR_RESPONSE_CODE_100 class NotAuthorizedException() : CustomApiException(CUSTOM_API_ERROR_RESPONSE_CODE_100
,messageStringId= CUSTOM_API_ERROR_RESPONSE_CODE_100_MESSAGE_ID) ,messageStringId= CUSTOM_API_ERROR_RESPONSE_CODE_100_MESSAGE_ID)
class TokenSyntaxException() : CustomApiException(CUSTOM_API_ERROR_RESPONSE_CODE_101 class TokenSyntaxException() : CustomApiException(CUSTOM_API_ERROR_RESPONSE_CODE_101
...@@ -125,28 +125,17 @@ sealed class CustomApiException(val code:Int,@StringRes val messageStringId: In ...@@ -125,28 +125,17 @@ sealed class CustomApiException(val code:Int,@StringRes val messageStringId: In
,messageStringId= CUSTOM_API_ERROR_RESPONSE_CODE_231_MESSAGE_ID) ,messageStringId= CUSTOM_API_ERROR_RESPONSE_CODE_231_MESSAGE_ID)
class TourByIdNotFoundException() : CustomApiException( class TourByIdNotFoundException() : CustomApiException(
CUSTOM_API_ERROR_RESPONSE_CODE_TOUR_NOT_FOUND CUSTOM_API_ERROR_RESPONSE_CODE_TOUR_NOT_FOUND
,messageStringId= CUSTOM_API_ERROR_RESPONSE_CODE_TOUR_NOT_FOUND_MESSAGE_ID) ,messageStringId= CUSTOM_API_ERROR_RESPONSE_CODE_TOUR_NOT_FOUND_MESSAGE_ID)
class UnknownCustomApiException(code: Int, @StringRes messageStringId:Int) class UnknownCustomApiException(code: Int, @StringRes messageStringId:Int?, apiMessage:String?)
: CustomApiException(code,messageStringId) : CustomApiException(code,messageStringId,apiMessage)
} }
fun parseException(err: ErrorRaw):CustomApiException{ //as an agreement error message should be correct for user (and localized, if needed) on server-side
return when(err.code){ fun parseException(err: ErrorRaw) =
CUSTOM_API_ERROR_RESPONSE_CODE_100 -> CustomApiException.NotAuthorizedException() CustomApiException.UnknownCustomApiException(err.code, null, err.message)
CUSTOM_API_ERROR_RESPONSE_CODE_101 -> CustomApiException.TokenSyntaxException()
CUSTOM_API_ERROR_RESPONSE_CODE_102 -> CustomApiException.UserWithTokenNotFoundException()
CUSTOM_API_ERROR_RESPONSE_CODE_103 -> CustomApiException.TokenEstimatedException()
CUSTOM_API_ERROR_RESPONSE_CODE_104 -> CustomApiException.UserBannedException()
CUSTOM_API_ERROR_RESPONSE_CODE_111 -> CustomApiException.WrongLoginException()
CUSTOM_API_ERROR_RESPONSE_CODE_112 -> CustomApiException.WrongPasswordException()
else -> CustomApiException.UnknownCustomApiException(err.code, CUSTOM_API_ERROR_DEFAULT_MESSAGE_ID)
}
}
...@@ -2,6 +2,7 @@ package com.biganto.visual.roompark.presentation.screen.article ...@@ -2,6 +2,7 @@ package com.biganto.visual.roompark.presentation.screen.article
import com.biganto.visual.roompark.conductor.BigantoBasePresenter import com.biganto.visual.roompark.conductor.BigantoBasePresenter
import com.biganto.visual.roompark.domain.interactor.ArticleInteractor 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.android.schedulers.AndroidSchedulers
import io.reactivex.schedulers.Schedulers import io.reactivex.schedulers.Schedulers
import timber.log.Timber import timber.log.Timber
...@@ -16,6 +17,8 @@ class ArticleScreenPresenter @Inject constructor( ...@@ -16,6 +17,8 @@ class ArticleScreenPresenter @Inject constructor(
private val interactor: ArticleInteractor private val interactor: ArticleInteractor
) )
: BigantoBasePresenter<ArticleScreen, ArticleScreenViewState>() { : BigantoBasePresenter<ArticleScreen, ArticleScreenViewState>() {
override fun defaultErrorViewStateHandler()=
{e:ExceptionString -> ArticleScreenViewState.SomeError(e)}
override fun bindIntents() { override fun bindIntents() {
......
...@@ -2,6 +2,7 @@ package com.biganto.visual.roompark.presentation.screen.article ...@@ -2,6 +2,7 @@ package com.biganto.visual.roompark.presentation.screen.article
import com.biganto.visual.roompark.conductor.BigantoBaseViewState import com.biganto.visual.roompark.conductor.BigantoBaseViewState
import com.biganto.visual.roompark.domain.model.ArticleModel import com.biganto.visual.roompark.domain.model.ArticleModel
import com.biganto.visual.roompark.util.monades.ExceptionString
/** /**
* Created by Vladislav Bogdashkin on 30.09.2019. * Created by Vladislav Bogdashkin on 30.09.2019.
...@@ -11,4 +12,5 @@ import com.biganto.visual.roompark.domain.model.ArticleModel ...@@ -11,4 +12,5 @@ import com.biganto.visual.roompark.domain.model.ArticleModel
sealed class ArticleScreenViewState : BigantoBaseViewState() { sealed class ArticleScreenViewState : BigantoBaseViewState() {
class Idle : ArticleScreenViewState() class Idle : ArticleScreenViewState()
class ArticleLoaded(val item: ArticleModel) : ArticleScreenViewState() class ArticleLoaded(val item: ArticleModel) : ArticleScreenViewState()
class SomeError(val error:ExceptionString ) : ArticleScreenViewState()
} }
\ No newline at end of file
...@@ -9,7 +9,6 @@ import com.biganto.visual.roompark.conductor.BigantoBaseController ...@@ -9,7 +9,6 @@ import com.biganto.visual.roompark.conductor.BigantoBaseController
import com.biganto.visual.roompark.presentation.screen.home.home_routing.HomeBottomNavigationController import com.biganto.visual.roompark.presentation.screen.home.home_routing.HomeBottomNavigationController
import com.bluelinelabs.conductor.RouterTransaction import com.bluelinelabs.conductor.RouterTransaction
import com.google.android.material.button.MaterialButton import com.google.android.material.button.MaterialButton
import com.google.android.material.snackbar.Snackbar
import com.google.android.material.textfield.TextInputLayout import com.google.android.material.textfield.TextInputLayout
import com.jakewharton.rxbinding3.view.clicks import com.jakewharton.rxbinding3.view.clicks
import io.reactivex.Observable import io.reactivex.Observable
...@@ -74,7 +73,7 @@ class AuthScreenController : ...@@ -74,7 +73,7 @@ class AuthScreenController :
is AuthScreenViewState.Authorization -> render(viewState) is AuthScreenViewState.Authorization -> render(viewState)
is AuthScreenViewState.SignedIn -> render(viewState) is AuthScreenViewState.SignedIn -> render(viewState)
is AuthScreenViewState.SignInError -> render(viewState) is AuthScreenViewState.SignInError -> render(viewState)
is AuthScreenViewState.SomeError -> render(viewState)
} }
} }
...@@ -94,12 +93,13 @@ class AuthScreenController : ...@@ -94,12 +93,13 @@ class AuthScreenController :
} }
private fun render(viewState: AuthScreenViewState.SignInError){ private fun render(viewState: AuthScreenViewState.SignInError){
snackbar.showSnackBar(viewState.message, Snackbar.LENGTH_LONG) showError(viewState.exception)
// toolBar.hideAll()
signInButton.isEnabled=true signInButton.isEnabled=true
// snacky.showSnackBar("lul")
} }
private fun render(viewState: AuthScreenViewState.SomeError) =
showError(viewState.exception)
override fun getLayoutId(): Int = R.layout.authentication_screen override fun getLayoutId(): Int = R.layout.authentication_screen
......
...@@ -2,6 +2,7 @@ package com.biganto.visual.roompark.presentation.screen.auth ...@@ -2,6 +2,7 @@ package com.biganto.visual.roompark.presentation.screen.auth
import com.biganto.visual.roompark.conductor.BigantoBasePresenter import com.biganto.visual.roompark.conductor.BigantoBasePresenter
import com.biganto.visual.roompark.domain.interactor.AuthInteractor import com.biganto.visual.roompark.domain.interactor.AuthInteractor
import com.biganto.visual.roompark.util.monades.ExceptionString
import io.reactivex.android.schedulers.AndroidSchedulers import io.reactivex.android.schedulers.AndroidSchedulers
import io.reactivex.schedulers.Schedulers import io.reactivex.schedulers.Schedulers
import timber.log.Timber import timber.log.Timber
...@@ -17,23 +18,32 @@ class AuthScreenPresenter @Inject constructor( ...@@ -17,23 +18,32 @@ class AuthScreenPresenter @Inject constructor(
) )
: BigantoBasePresenter<AuthScreen, AuthScreenViewState>() { : 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 bindIntents() { override fun bindIntents() {
val onAuth = intent(AuthScreen::tryAuth) val onAuth = intent(AuthScreen::tryAuth)
.flatMap<AuthScreenViewState>{ model -> .flatMap<AuthScreenViewState> { model ->
interactor.signIn(model.login, model.pwd) interactor.signIn(model.login, model.pwd)
.doOnNext{Timber.d("auth returned $it")} .doOnNext { Timber.d("auth returned $it") }
.map { it } .map { it }
.map<AuthScreenViewState> { AuthScreenViewState.SignInError("") }
.map { AuthScreenViewState.SignedIn() } .map { AuthScreenViewState.SignedIn() }
} }
// .startWith(Observable.just(AuthScreenViewState.Authorization())) // .startWith(Observable.just(AuthScreenViewState.Authorization()))
val state = restoreStateObservable val state = restoreStateObservable
.mergeWith(onAuth) .mergeWith(onAuth)
.doOnError{ Timber.e(it)} .doOnError { Timber.e(it) }
.onErrorReturn(::parseError)
.subscribeOn(Schedulers.single()) .subscribeOn(Schedulers.single())
.observeOn(AndroidSchedulers.mainThread()) .observeOn(AndroidSchedulers.mainThread())
......
package com.biganto.visual.roompark.presentation.screen.auth package com.biganto.visual.roompark.presentation.screen.auth
import com.biganto.visual.roompark.conductor.BigantoBaseViewState import com.biganto.visual.roompark.conductor.BigantoBaseViewState
import com.biganto.visual.roompark.util.monades.ExceptionString
/** /**
* Created by Vladislav Bogdashkin on 30.09.2019. * Created by Vladislav Bogdashkin on 30.09.2019.
*/ */
sealed class AuthScreenViewState : BigantoBaseViewState() { sealed class AuthScreenViewState : BigantoBaseViewState() {
class Idle : AuthScreenViewState() class Idle : AuthScreenViewState()
class Authorization : AuthScreenViewState() class Authorization : AuthScreenViewState()
class SignedIn : AuthScreenViewState() class SignedIn : AuthScreenViewState()
class SignInError(val message:String) : AuthScreenViewState() class SignInError(val exception: ExceptionString) : AuthScreenViewState()
class SomeError(val exception: ExceptionString) : AuthScreenViewState()
} }
\ No newline at end of file
...@@ -69,6 +69,7 @@ class DealsScreenController : ...@@ -69,6 +69,7 @@ class DealsScreenController :
when(viewState){ when(viewState){
is DealsScreenViewState.Idle -> render(viewState) is DealsScreenViewState.Idle -> render(viewState)
is DealsScreenViewState.DealsLoaded -> render(viewState) is DealsScreenViewState.DealsLoaded -> render(viewState)
is DealsScreenViewState.SomeError -> render(viewState)
} }
} }
...@@ -76,12 +77,13 @@ class DealsScreenController : ...@@ -76,12 +77,13 @@ class DealsScreenController :
} }
private fun render(viewState: DealsScreenViewState.DealsLoaded){ private fun render(viewState: DealsScreenViewState.DealsLoaded){
(favoritesRecyclerView.adapter as DealsListAdapter).addItems(viewState.items) (favoritesRecyclerView.adapter as DealsListAdapter).addItems(viewState.items)
} }
private fun render(viewState: DealsScreenViewState.SomeError) =
showError(viewState.exception)
private fun getComponent() = DaggerDealsScreenComponent.factory() private fun getComponent() = DaggerDealsScreenComponent.factory()
.create(RoomParkApplication.component,activity as RoomParkMainActivity) .create(RoomParkApplication.component,activity as RoomParkMainActivity)
.inject(this) .inject(this)
......
...@@ -2,6 +2,7 @@ package com.biganto.visual.roompark.presentation.screen.deals ...@@ -2,6 +2,7 @@ package com.biganto.visual.roompark.presentation.screen.deals
import com.biganto.visual.roompark.conductor.BigantoBasePresenter import com.biganto.visual.roompark.conductor.BigantoBasePresenter
import com.biganto.visual.roompark.domain.interactor.DealsInteractor 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.android.schedulers.AndroidSchedulers
import io.reactivex.schedulers.Schedulers import io.reactivex.schedulers.Schedulers
import timber.log.Timber import timber.log.Timber
...@@ -17,6 +18,8 @@ class DealsScreenPresenter @Inject constructor( ...@@ -17,6 +18,8 @@ class DealsScreenPresenter @Inject constructor(
) )
: BigantoBasePresenter<DealsScreen, DealsScreenViewState>() { : BigantoBasePresenter<DealsScreen, DealsScreenViewState>() {
override fun defaultErrorViewStateHandler() =
{e:ExceptionString -> DealsScreenViewState.SomeError(e)}
override fun bindIntents() { override fun bindIntents() {
......
package com.biganto.visual.roompark.presentation.screen.deals package com.biganto.visual.roompark.presentation.screen.deals
import com.biganto.visual.roompark.conductor.BigantoBaseViewState import com.biganto.visual.roompark.conductor.BigantoBaseViewState
import com.biganto.visual.roompark.util.monades.ExceptionString
/** /**
* Created by Vladislav Bogdashkin on 30.09.2019. * Created by Vladislav Bogdashkin on 30.09.2019.
...@@ -10,5 +11,6 @@ import com.biganto.visual.roompark.conductor.BigantoBaseViewState ...@@ -10,5 +11,6 @@ import com.biganto.visual.roompark.conductor.BigantoBaseViewState
sealed class DealsScreenViewState : BigantoBaseViewState() { sealed class DealsScreenViewState : BigantoBaseViewState() {
class Idle : DealsScreenViewState() class Idle : DealsScreenViewState()
class DealsLoaded(val items:List<DealPreviewModel>) : DealsScreenViewState() class DealsLoaded(val items:List<DealPreviewModel>) : DealsScreenViewState()
class SomeError(val exception: ExceptionString) : DealsScreenViewState()
} }
...@@ -70,6 +70,7 @@ class FavoritesScreenController : ...@@ -70,6 +70,7 @@ class FavoritesScreenController :
when(viewState){ when(viewState){
is FavoritesScreenViewState.Idle -> render(viewState) is FavoritesScreenViewState.Idle -> render(viewState)
is FavoritesScreenViewState.FavoriteEstatesLoaded -> render(viewState) is FavoritesScreenViewState.FavoriteEstatesLoaded -> render(viewState)
is FavoritesScreenViewState.SomeError -> render(viewState)
} }
} }
...@@ -77,6 +78,9 @@ class FavoritesScreenController : ...@@ -77,6 +78,9 @@ class FavoritesScreenController :
} }
private fun render(viewState: FavoritesScreenViewState.SomeError) =
showError(viewState.exception)
private fun render(viewState: FavoritesScreenViewState.FavoriteEstatesLoaded) { private fun render(viewState: FavoritesScreenViewState.FavoriteEstatesLoaded) {
(favoritesRecyclerView.adapter as FavoritesListAdapter).addItems(viewState.items) (favoritesRecyclerView.adapter as FavoritesListAdapter).addItems(viewState.items)
......
...@@ -2,6 +2,7 @@ package com.biganto.visual.roompark.presentation.screen.favorites ...@@ -2,6 +2,7 @@ package com.biganto.visual.roompark.presentation.screen.favorites
import com.biganto.visual.roompark.conductor.BigantoBasePresenter import com.biganto.visual.roompark.conductor.BigantoBasePresenter
import com.biganto.visual.roompark.domain.interactor.FavoritesInteractor 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.android.schedulers.AndroidSchedulers
import io.reactivex.schedulers.Schedulers import io.reactivex.schedulers.Schedulers
import timber.log.Timber import timber.log.Timber
...@@ -17,6 +18,8 @@ class FavoritesScreenPresenter @Inject constructor( ...@@ -17,6 +18,8 @@ class FavoritesScreenPresenter @Inject constructor(
) )
: BigantoBasePresenter<FavoritesScreen, FavoritesScreenViewState>() { : BigantoBasePresenter<FavoritesScreen, FavoritesScreenViewState>() {
override fun defaultErrorViewStateHandler() =
{e: ExceptionString -> FavoritesScreenViewState.SomeError(e)}
override fun bindIntents() { override fun bindIntents() {
......
...@@ -2,6 +2,7 @@ package com.biganto.visual.roompark.presentation.screen.favorites ...@@ -2,6 +2,7 @@ package com.biganto.visual.roompark.presentation.screen.favorites
import com.biganto.visual.roompark.conductor.BigantoBaseViewState import com.biganto.visual.roompark.conductor.BigantoBaseViewState
import com.biganto.visual.roompark.domain.model.EstateModel import com.biganto.visual.roompark.domain.model.EstateModel
import com.biganto.visual.roompark.util.monades.ExceptionString
/** /**
* Created by Vladislav Bogdashkin on 30.09.2019. * Created by Vladislav Bogdashkin on 30.09.2019.
...@@ -11,4 +12,5 @@ import com.biganto.visual.roompark.domain.model.EstateModel ...@@ -11,4 +12,5 @@ import com.biganto.visual.roompark.domain.model.EstateModel
sealed class FavoritesScreenViewState : BigantoBaseViewState() { sealed class FavoritesScreenViewState : BigantoBaseViewState() {
class Idle : FavoritesScreenViewState() class Idle : FavoritesScreenViewState()
class FavoriteEstatesLoaded(val items: List<EstateModel>) : 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 : ...@@ -86,6 +86,7 @@ class ArticlesScreenController :
when(viewState){ when(viewState){
is ArticlesScreenViewState.Idle -> render(viewState) is ArticlesScreenViewState.Idle -> render(viewState)
is ArticlesScreenViewState.ArticlesLoaded -> render(viewState) is ArticlesScreenViewState.ArticlesLoaded -> render(viewState)
is ArticlesScreenViewState.SomeError -> render(viewState)
} }
} }
...@@ -93,6 +94,8 @@ class ArticlesScreenController : ...@@ -93,6 +94,8 @@ class ArticlesScreenController :
} }
private fun render(viewState: ArticlesScreenViewState.SomeError) =
showError(viewState.exception)
private fun render(viewState: ArticlesScreenViewState.ArticlesLoaded) { private fun render(viewState: ArticlesScreenViewState.ArticlesLoaded) {
(articlesRecyclerView.adapter as ArticlesAdapter).setItems(viewState.items) (articlesRecyclerView.adapter as ArticlesAdapter).setItems(viewState.items)
......
...@@ -2,6 +2,7 @@ package com.biganto.visual.roompark.presentation.screen.feed_list ...@@ -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.conductor.BigantoBasePresenter
import com.biganto.visual.roompark.domain.interactor.ArticlesInteractor 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.android.schedulers.AndroidSchedulers
import io.reactivex.schedulers.Schedulers import io.reactivex.schedulers.Schedulers
import timber.log.Timber import timber.log.Timber
...@@ -19,6 +20,8 @@ class ArticlesScreenPresenter @Inject constructor( ...@@ -19,6 +20,8 @@ class ArticlesScreenPresenter @Inject constructor(
) )
: BigantoBasePresenter<ArticlesScreen, ArticlesScreenViewState>() { : BigantoBasePresenter<ArticlesScreen, ArticlesScreenViewState>() {
override fun defaultErrorViewStateHandler() =
{e: ExceptionString -> ArticlesScreenViewState.SomeError(e)}
override fun bindIntents() { override fun bindIntents() {
Timber.d("feedId : $feedId") Timber.d("feedId : $feedId")
......
...@@ -2,6 +2,7 @@ package com.biganto.visual.roompark.presentation.screen.feed_list ...@@ -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.conductor.BigantoBaseViewState
import com.biganto.visual.roompark.domain.model.ArticlePreviewModel import com.biganto.visual.roompark.domain.model.ArticlePreviewModel
import com.biganto.visual.roompark.util.monades.ExceptionString
/** /**
* Created by Vladislav Bogdashkin on 30.09.2019. * Created by Vladislav Bogdashkin on 30.09.2019.
...@@ -11,4 +12,5 @@ import com.biganto.visual.roompark.domain.model.ArticlePreviewModel ...@@ -11,4 +12,5 @@ import com.biganto.visual.roompark.domain.model.ArticlePreviewModel
sealed class ArticlesScreenViewState : BigantoBaseViewState() { sealed class ArticlesScreenViewState : BigantoBaseViewState() {
class Idle : ArticlesScreenViewState() class Idle : ArticlesScreenViewState()
class ArticlesLoaded(val items: List<ArticlePreviewModel>) : 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 : ...@@ -123,6 +123,7 @@ class FeedsScreenController :
is FeedsScreenViewState.CamsList -> render(viewState) is FeedsScreenViewState.CamsList -> render(viewState)
is FeedsScreenViewState.GetFeedArticlesPreview -> render(viewState) is FeedsScreenViewState.GetFeedArticlesPreview -> render(viewState)
is FeedsScreenViewState.RestoreView -> render(viewState) is FeedsScreenViewState.RestoreView -> render(viewState)
is FeedsScreenViewState.SomeError -> render(viewState)
} }
} }
...@@ -130,6 +131,9 @@ class FeedsScreenController : ...@@ -130,6 +131,9 @@ class FeedsScreenController :
} }
private fun render(viewState: FeedsScreenViewState.SomeError) =
showError(viewState.exception)
private fun allFeedName(feedId:Int) = if (feedId==1) "НОВОСТИ" else "БЛОГИ" private fun allFeedName(feedId:Int) = if (feedId==1) "НОВОСТИ" else "БЛОГИ"
@SuppressLint("SetTextI18n") @SuppressLint("SetTextI18n")
......
...@@ -2,6 +2,7 @@ package com.biganto.visual.roompark.presentation.screen.feeds ...@@ -2,6 +2,7 @@ package com.biganto.visual.roompark.presentation.screen.feeds
import com.biganto.visual.roompark.conductor.BigantoBasePresenter import com.biganto.visual.roompark.conductor.BigantoBasePresenter
import com.biganto.visual.roompark.domain.interactor.FeedsInteractor 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.android.schedulers.AndroidSchedulers
import io.reactivex.schedulers.Schedulers import io.reactivex.schedulers.Schedulers
import timber.log.Timber import timber.log.Timber
...@@ -17,6 +18,10 @@ class FeedsScreenPresenter @Inject constructor( ...@@ -17,6 +18,10 @@ class FeedsScreenPresenter @Inject constructor(
) )
: BigantoBasePresenter<FeedsScreen, FeedsScreenViewState>() { : BigantoBasePresenter<FeedsScreen, FeedsScreenViewState>() {
override fun defaultErrorViewStateHandler() =
{e: ExceptionString -> FeedsScreenViewState.SomeError(e)}
private val restoreModel = RestoreModel( private val restoreModel = RestoreModel(
arrayListOf(), arrayListOf(),
arrayListOf(), arrayListOf(),
......
...@@ -5,6 +5,7 @@ import com.biganto.visual.roompark.domain.model.AlbumPreviewModel ...@@ -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.ArticlePreviewModel
import com.biganto.visual.roompark.domain.model.FeedModel import com.biganto.visual.roompark.domain.model.FeedModel
import com.biganto.visual.roompark.domain.model.WebCamModel import com.biganto.visual.roompark.domain.model.WebCamModel
import com.biganto.visual.roompark.util.monades.ExceptionString
/** /**
* Created by Vladislav Bogdashkin on 30.09.2019. * Created by Vladislav Bogdashkin on 30.09.2019.
...@@ -20,6 +21,8 @@ sealed class FeedsScreenViewState : BigantoBaseViewState() { ...@@ -20,6 +21,8 @@ sealed class FeedsScreenViewState : BigantoBaseViewState() {
class GetFeedArticlesPreview(val items:List<ArticlePreviewModel>) : FeedsScreenViewState() class GetFeedArticlesPreview(val items:List<ArticlePreviewModel>) : FeedsScreenViewState()
class RestoreView(val restore:RestoreModel) : FeedsScreenViewState() class RestoreView(val restore:RestoreModel) : FeedsScreenViewState()
class SomeError(val exception: ExceptionString) : FeedsScreenViewState()
} }
data class RestoreModel( data class RestoreModel(
......
package com.biganto.visual.roompark.presentation.screen.home package com.biganto.visual.roompark.presentation.screen.home
import com.biganto.visual.roompark.conductor.BigantoBasePresenter import com.biganto.visual.roompark.conductor.BigantoBasePresenter
import com.biganto.visual.roompark.util.monades.ExceptionString
import javax.inject.Inject import javax.inject.Inject
/** /**
...@@ -13,6 +14,9 @@ class HomeScreenPresenter @Inject constructor( ...@@ -13,6 +14,9 @@ class HomeScreenPresenter @Inject constructor(
) )
: BigantoBasePresenter<HomeScreen, HomeScreenViewState>() { : BigantoBasePresenter<HomeScreen, HomeScreenViewState>() {
override fun defaultErrorViewStateHandler() =
{e: ExceptionString -> HomeScreenViewState.SomeError(e)}
override fun bindIntents() { override fun bindIntents() {
val state = restoreStateObservable val state = restoreStateObservable
subscribeViewState(state.cast(HomeScreenViewState::class.java), HomeScreen::render) subscribeViewState(state.cast(HomeScreenViewState::class.java), HomeScreen::render)
......
package com.biganto.visual.roompark.presentation.screen.home package com.biganto.visual.roompark.presentation.screen.home
import com.biganto.visual.roompark.conductor.BigantoBaseViewState import com.biganto.visual.roompark.conductor.BigantoBaseViewState
import com.biganto.visual.roompark.util.monades.ExceptionString
/** /**
* Created by Vladislav Bogdashkin on 30.09.2019. * Created by Vladislav Bogdashkin on 30.09.2019.
...@@ -10,4 +11,5 @@ import com.biganto.visual.roompark.conductor.BigantoBaseViewState ...@@ -10,4 +11,5 @@ import com.biganto.visual.roompark.conductor.BigantoBaseViewState
sealed class HomeScreenViewState : BigantoBaseViewState() { sealed class HomeScreenViewState : BigantoBaseViewState() {
class Idle : HomeScreenViewState() class Idle : HomeScreenViewState()
class ToScreen(val message:String) : 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) ...@@ -68,6 +68,7 @@ class HomeBottomNavigationController(@IdRes toPage: Int = R.id.tab_feeds)
when(viewState){ when(viewState){
is HomeScreenViewState.Idle -> render(viewState) is HomeScreenViewState.Idle -> render(viewState)
is HomeScreenViewState.ToScreen -> 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) ...@@ -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){ private fun render(viewState: HomeScreenViewState.ToScreen){
......
...@@ -93,9 +93,13 @@ class SettingsScreenController : ...@@ -93,9 +93,13 @@ class SettingsScreenController :
when(viewState){ when(viewState){
is SettingsScreenViewState.Idle -> render(viewState) is SettingsScreenViewState.Idle -> render(viewState)
is SettingsScreenViewState.LoadSettingsList -> 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){ private fun render(viewState: SettingsScreenViewState.Idle){
} }
......
...@@ -2,6 +2,7 @@ package com.biganto.visual.roompark.presentation.screen.settings ...@@ -2,6 +2,7 @@ package com.biganto.visual.roompark.presentation.screen.settings
import com.biganto.visual.roompark.conductor.BigantoBasePresenter import com.biganto.visual.roompark.conductor.BigantoBasePresenter
import com.biganto.visual.roompark.domain.interactor.SettingsInteractor 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.android.schedulers.AndroidSchedulers
import io.reactivex.schedulers.Schedulers import io.reactivex.schedulers.Schedulers
import timber.log.Timber import timber.log.Timber
...@@ -17,6 +18,8 @@ class SettingsScreenPresenter @Inject constructor( ...@@ -17,6 +18,8 @@ class SettingsScreenPresenter @Inject constructor(
) )
: BigantoBasePresenter<SettingsScreen, SettingsScreenViewState>() { : BigantoBasePresenter<SettingsScreen, SettingsScreenViewState>() {
override fun defaultErrorViewStateHandler() =
{e: ExceptionString -> SettingsScreenViewState.SomeError(e)}
override fun bindIntents() { override fun bindIntents() {
......
...@@ -2,6 +2,7 @@ package com.biganto.visual.roompark.presentation.screen.settings ...@@ -2,6 +2,7 @@ package com.biganto.visual.roompark.presentation.screen.settings
import com.biganto.visual.roompark.conductor.BigantoBaseViewState import com.biganto.visual.roompark.conductor.BigantoBaseViewState
import com.biganto.visual.roompark.domain.model.SettingsModel import com.biganto.visual.roompark.domain.model.SettingsModel
import com.biganto.visual.roompark.util.monades.ExceptionString
/** /**
* Created by Vladislav Bogdashkin on 30.09.2019. * Created by Vladislav Bogdashkin on 30.09.2019.
...@@ -11,4 +12,5 @@ import com.biganto.visual.roompark.domain.model.SettingsModel ...@@ -11,4 +12,5 @@ import com.biganto.visual.roompark.domain.model.SettingsModel
sealed class SettingsScreenViewState : BigantoBaseViewState() { sealed class SettingsScreenViewState : BigantoBaseViewState() {
class Idle : SettingsScreenViewState() class Idle : SettingsScreenViewState()
class LoadSettingsList(val settings:SettingsModel) : 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 ...@@ -2,7 +2,6 @@ package com.biganto.visual.roompark.presentation.screen.splash
import android.view.View import android.view.View
import com.biganto.visual.roompark.R 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.RoomParkApplication
import com.biganto.visual.roompark.base.RoomParkMainActivity import com.biganto.visual.roompark.base.RoomParkMainActivity
import com.biganto.visual.roompark.conductor.BigantoBaseController import com.biganto.visual.roompark.conductor.BigantoBaseController
...@@ -53,6 +52,7 @@ class SplashScreenController : ...@@ -53,6 +52,7 @@ class SplashScreenController :
is SplashScreenViewState.Idle -> render(viewState) is SplashScreenViewState.Idle -> render(viewState)
is SplashScreenViewState.ToAuthScreen -> render(viewState) is SplashScreenViewState.ToAuthScreen -> render(viewState)
is SplashScreenViewState.ToHomeScreen -> render(viewState) is SplashScreenViewState.ToHomeScreen -> render(viewState)
is SplashScreenViewState.SomeError -> render(viewState)
} }
} }
...@@ -60,6 +60,9 @@ class SplashScreenController : ...@@ -60,6 +60,9 @@ class SplashScreenController :
} }
private fun render(viewState: SplashScreenViewState.SomeError) =
showError(viewState.exception)
private fun render(viewState: SplashScreenViewState.ToAuthScreen){ private fun render(viewState: SplashScreenViewState.ToAuthScreen){
router.pushController(RouterTransaction.with(AuthScreenController()) router.pushController(RouterTransaction.with(AuthScreenController())
.popChangeHandler(FadeChangeHandler()) .popChangeHandler(FadeChangeHandler())
......
...@@ -3,6 +3,7 @@ package com.biganto.visual.roompark.presentation.screen.splash ...@@ -3,6 +3,7 @@ package com.biganto.visual.roompark.presentation.screen.splash
import com.biganto.visual.roompark.base.RoomParkMainActivity import com.biganto.visual.roompark.base.RoomParkMainActivity
import com.biganto.visual.roompark.conductor.BigantoBasePresenter import com.biganto.visual.roompark.conductor.BigantoBasePresenter
import com.biganto.visual.roompark.domain.interactor.SplashInteractor import com.biganto.visual.roompark.domain.interactor.SplashInteractor
import com.biganto.visual.roompark.util.monades.ExceptionString
import javax.inject.Inject import javax.inject.Inject
/** /**
...@@ -17,6 +18,9 @@ class SplashScreenPresenter @Inject constructor( ...@@ -17,6 +18,9 @@ class SplashScreenPresenter @Inject constructor(
) )
: BigantoBasePresenter<SplashScreen, SplashScreenViewState>() { : BigantoBasePresenter<SplashScreen, SplashScreenViewState>() {
override fun defaultErrorViewStateHandler() =
{e: ExceptionString -> SplashScreenViewState.SomeError(e)}
override fun bindIntents() { override fun bindIntents() {
val state = restoreStateObservable val state = restoreStateObservable
......
package com.biganto.visual.roompark.presentation.screen.splash package com.biganto.visual.roompark.presentation.screen.splash
import com.biganto.visual.roompark.conductor.BigantoBaseViewState import com.biganto.visual.roompark.conductor.BigantoBaseViewState
import com.biganto.visual.roompark.util.monades.ExceptionString
/** /**
* Created by Vladislav Bogdashkin on 30.09.2019. * Created by Vladislav Bogdashkin on 30.09.2019.
...@@ -11,4 +12,5 @@ sealed class SplashScreenViewState : BigantoBaseViewState() { ...@@ -11,4 +12,5 @@ sealed class SplashScreenViewState : BigantoBaseViewState() {
class Idle : SplashScreenViewState() class Idle : SplashScreenViewState()
class ToHomeScreen() : SplashScreenViewState() class ToHomeScreen() : SplashScreenViewState()
class ToAuthScreen() : SplashScreenViewState() class ToAuthScreen() : SplashScreenViewState()
class SomeError(val exception: ExceptionString) : SplashScreenViewState()
} }
\ No newline at end of file
...@@ -101,9 +101,13 @@ class FindFlatScreenController : ...@@ -101,9 +101,13 @@ class FindFlatScreenController :
Timber.d("Render state $viewState") Timber.d("Render state $viewState")
when(viewState){ when(viewState){
is FindFlatScreenViewState.Idle -> render(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){ private fun render(viewState: FindFlatScreenViewState.Idle){
} }
......
...@@ -2,6 +2,7 @@ package com.biganto.visual.roompark.presentation.screen.to_flat ...@@ -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.conductor.BigantoBasePresenter
import com.biganto.visual.roompark.domain.interactor.FindFlatInteractor import com.biganto.visual.roompark.domain.interactor.FindFlatInteractor
import com.biganto.visual.roompark.util.monades.ExceptionString
import io.reactivex.Observable import io.reactivex.Observable
import io.reactivex.android.schedulers.AndroidSchedulers import io.reactivex.android.schedulers.AndroidSchedulers
import io.reactivex.schedulers.Schedulers import io.reactivex.schedulers.Schedulers
...@@ -18,6 +19,9 @@ class FindFlatScreenPresenter @Inject constructor( ...@@ -18,6 +19,9 @@ class FindFlatScreenPresenter @Inject constructor(
) )
: BigantoBasePresenter<FindFlatScreen, FindFlatScreenViewState>() { : BigantoBasePresenter<FindFlatScreen, FindFlatScreenViewState>() {
override fun defaultErrorViewStateHandler() =
{e: ExceptionString -> FindFlatScreenViewState.SomeError(e)}
override fun bindIntents() { override fun bindIntents() {
......
...@@ -2,6 +2,7 @@ package com.biganto.visual.roompark.presentation.screen.to_flat ...@@ -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.conductor.BigantoBaseViewState
import com.biganto.visual.roompark.domain.model.TourModel import com.biganto.visual.roompark.domain.model.TourModel
import com.biganto.visual.roompark.util.monades.ExceptionString
/** /**
* Created by Vladislav Bogdashkin on 30.09.2019. * Created by Vladislav Bogdashkin on 30.09.2019.
...@@ -14,4 +15,5 @@ sealed class FindFlatScreenViewState : BigantoBaseViewState() { ...@@ -14,4 +15,5 @@ sealed class FindFlatScreenViewState : BigantoBaseViewState() {
class TourFounded(val items:List<TourModel>) : FindFlatScreenViewState() class TourFounded(val items:List<TourModel>) : FindFlatScreenViewState()
class StartTour(val tourId:String) : FindFlatScreenViewState() class StartTour(val tourId:String) : FindFlatScreenViewState()
class FlatNotFound() : FindFlatScreenViewState() class FlatNotFound() : FindFlatScreenViewState()
class SomeError(val exception: ExceptionString) : FindFlatScreenViewState()
} }
\ No newline at end of file
package com.biganto.visual.roompark.util.monades
import androidx.annotation.StringRes
import com.biganto.visual.roompark.domain.custom_exception.CustomApiException
/**
* Created by Vladislav Bogdashkin on 12.11.2019.
*/
sealed class Either<out E, out V> {
data class Left<out E>(val left: E) : Either<E, Nothing>()
data class Right<out V>(val right: V) : Either<Nothing, V>()
}
data class ExceptionString(@StringRes private val stringId: Int?, private val message: String?) {
val errorMessage : Either<Int,String>
fun selectHandler(a1:(Int)->Unit,a2:(String)->Unit) =
when(errorMessage){
is Either.Left -> a1(errorMessage.left)
is Either.Right -> a2(errorMessage.right)
}
constructor(e:CustomApiException) : this(
if (e.message!=null) null else e.messageStringId,
if (e.messageStringId!=null) null else e.message
)
init {
assert(stringId==null && message==null) { "both values cannot be null!" }
errorMessage = if (stringId!=null) Either.Left(stringId) else Either.Right(message!!)
}
}
...@@ -2,6 +2,7 @@ package com.biganto.visual.roompark.util.view_utils.snackbar ...@@ -2,6 +2,7 @@ package com.biganto.visual.roompark.util.view_utils.snackbar
import android.app.Activity import android.app.Activity
import android.view.View import android.view.View
import androidx.annotation.StringRes
import androidx.core.content.ContextCompat import androidx.core.content.ContextCompat
import com.biganto.visual.roompark.R import com.biganto.visual.roompark.R
import com.biganto.visual.roompark.util.view_utils.snackbar.SnackBarMessageType.* import com.biganto.visual.roompark.util.view_utils.snackbar.SnackBarMessageType.*
...@@ -52,6 +53,10 @@ class SnackBarProvider @Inject constructor(val activity: Activity) : ISnackBarPr ...@@ -52,6 +53,10 @@ class SnackBarProvider @Inject constructor(val activity: Activity) : ISnackBarPr
this.rootView = rootView this.rootView = rootView
} }
override fun showSnackBar(@StringRes stringId: Int) {
showSnackBar(activity.resources.getString(stringId), Snackbar.LENGTH_SHORT)
}
override fun showSnackBar(message: String) { override fun showSnackBar(message: String) {
showSnackBar(message, Snackbar.LENGTH_SHORT) showSnackBar(message, Snackbar.LENGTH_SHORT)
} }
...@@ -75,6 +80,7 @@ interface ISnackBarProvider{ ...@@ -75,6 +80,7 @@ interface ISnackBarProvider{
fun bindRootView(rootView : View?) fun bindRootView(rootView : View?)
val isRootBounded : Boolean val isRootBounded : Boolean
val snackBar : Snackbar? val snackBar : Snackbar?
fun showSnackBar(@StringRes stringId: Int)
fun showSnackBar(message: String) fun showSnackBar(message: String)
fun showSnackBar(message: String, length: Int) fun showSnackBar(message: String, length: Int)
fun showSnackBar(message: String, type: SnackBarMessageType, length: Int) fun showSnackBar(message: String, type: SnackBarMessageType, length: Int)
......
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