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
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
......
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.mvp.MvpView
import com.jakewharton.rxrelay2.PublishRelay
import io.reactivex.Observable
/**
* Created by Vladislav Bogdashkin on 30.09.2019.
*/
abstract class BigantoBasePresenter<V : MvpView, VS>
: MviBasePresenter<V, VS>(){
: MviBasePresenter<V, VS>() {
protected val restoreStateObservable =
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
import android.content.Context
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.util.DateSerializer
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.repository.api.retrofit.util.*
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.NoNetworkException
......@@ -46,6 +43,7 @@ class RetrofitModule{
private fun gsonConverterFactory() = GsonConverterFactory.create(
GsonBuilder()
.registerTypeHierarchyAdapter(Any::class.java,CustomExceptionDeserializer<Any>())
.registerTypeAdapter(genericType<MutableList<ErrorRaw>>(), ErrorsListDeserializer())
.registerTypeAdapter(Date::class.java, DateSerializer())
.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_
@StringRes
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
,messageStringId= CUSTOM_API_ERROR_RESPONSE_CODE_100_MESSAGE_ID)
class TokenSyntaxException() : CustomApiException(CUSTOM_API_ERROR_RESPONSE_CODE_101
......@@ -125,28 +125,17 @@ sealed class CustomApiException(val code:Int,@StringRes val messageStringId: In
,messageStringId= CUSTOM_API_ERROR_RESPONSE_CODE_231_MESSAGE_ID)
class TourByIdNotFoundException() : CustomApiException(
CUSTOM_API_ERROR_RESPONSE_CODE_TOUR_NOT_FOUND
,messageStringId= CUSTOM_API_ERROR_RESPONSE_CODE_TOUR_NOT_FOUND_MESSAGE_ID)
class UnknownCustomApiException(code: Int, @StringRes messageStringId:Int)
: CustomApiException(code,messageStringId)
class UnknownCustomApiException(code: Int, @StringRes messageStringId:Int?, apiMessage:String?)
: CustomApiException(code,messageStringId,apiMessage)
}
fun parseException(err: ErrorRaw):CustomApiException{
return when(err.code){
CUSTOM_API_ERROR_RESPONSE_CODE_100 -> CustomApiException.NotAuthorizedException()
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)
}
}
//as an agreement error message should be correct for user (and localized, if needed) on server-side
fun parseException(err: ErrorRaw) =
CustomApiException.UnknownCustomApiException(err.code, null, err.message)
......@@ -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
......@@ -9,7 +9,6 @@ import com.biganto.visual.roompark.conductor.BigantoBaseController
import com.biganto.visual.roompark.presentation.screen.home.home_routing.HomeBottomNavigationController
import com.bluelinelabs.conductor.RouterTransaction
import com.google.android.material.button.MaterialButton
import com.google.android.material.snackbar.Snackbar
import com.google.android.material.textfield.TextInputLayout
import com.jakewharton.rxbinding3.view.clicks
import io.reactivex.Observable
......@@ -74,7 +73,7 @@ class AuthScreenController :
is AuthScreenViewState.Authorization -> render(viewState)
is AuthScreenViewState.SignedIn -> render(viewState)
is AuthScreenViewState.SignInError -> render(viewState)
is AuthScreenViewState.SomeError -> render(viewState)
}
}
......@@ -94,12 +93,13 @@ class AuthScreenController :
}
private fun render(viewState: AuthScreenViewState.SignInError){
snackbar.showSnackBar(viewState.message, Snackbar.LENGTH_LONG)
// toolBar.hideAll()
showError(viewState.exception)
signInButton.isEnabled=true
// snacky.showSnackBar("lul")
}
private fun render(viewState: AuthScreenViewState.SomeError) =
showError(viewState.exception)
override fun getLayoutId(): Int = R.layout.authentication_screen
......
......@@ -2,6 +2,7 @@ package com.biganto.visual.roompark.presentation.screen.auth
import com.biganto.visual.roompark.conductor.BigantoBasePresenter
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.schedulers.Schedulers
import timber.log.Timber
......@@ -17,23 +18,32 @@ 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 bindIntents() {
val onAuth = intent(AuthScreen::tryAuth)
.flatMap<AuthScreenViewState>{ model ->
.flatMap<AuthScreenViewState> { model ->
interactor.signIn(model.login, model.pwd)
.doOnNext{Timber.d("auth returned $it")}
.doOnNext { Timber.d("auth returned $it") }
.map { it }
.map<AuthScreenViewState> { AuthScreenViewState.SignInError("") }
.map { AuthScreenViewState.SignedIn() }
.map { AuthScreenViewState.SignedIn() }
}
// .startWith(Observable.just(AuthScreenViewState.Authorization()))
val state = restoreStateObservable
.mergeWith(onAuth)
.doOnError{ Timber.e(it)}
.doOnError { Timber.e(it) }
.onErrorReturn(::parseError)
.subscribeOn(Schedulers.single())
.observeOn(AndroidSchedulers.mainThread())
......
package com.biganto.visual.roompark.presentation.screen.auth
import com.biganto.visual.roompark.conductor.BigantoBaseViewState
import com.biganto.visual.roompark.util.monades.ExceptionString
/**
* Created by Vladislav Bogdashkin on 30.09.2019.
*/
sealed class AuthScreenViewState : BigantoBaseViewState() {
class Idle : AuthScreenViewState()
class Authorization : 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 :
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
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
import android.app.Activity
import android.view.View
import androidx.annotation.StringRes
import androidx.core.content.ContextCompat
import com.biganto.visual.roompark.R
import com.biganto.visual.roompark.util.view_utils.snackbar.SnackBarMessageType.*
......@@ -52,6 +53,10 @@ class SnackBarProvider @Inject constructor(val activity: Activity) : ISnackBarPr
this.rootView = rootView
}
override fun showSnackBar(@StringRes stringId: Int) {
showSnackBar(activity.resources.getString(stringId), Snackbar.LENGTH_SHORT)
}
override fun showSnackBar(message: String) {
showSnackBar(message, Snackbar.LENGTH_SHORT)
}
......@@ -75,6 +80,7 @@ interface ISnackBarProvider{
fun bindRootView(rootView : View?)
val isRootBounded : Boolean
val snackBar : Snackbar?
fun showSnackBar(@StringRes stringId: Int)
fun showSnackBar(message: String)
fun showSnackBar(message: String, 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