Commit ad925ad9 authored by Vladislav Bogdashkin's avatar Vladislav Bogdashkin 🎣

resolve localized exception message as Either

parent 8617efc6
......@@ -125,14 +125,12 @@ 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?, apiMessage:String?)
: CustomApiException(code,messageStringId,apiMessage)
}
//as an agreement error message should be correct for user (and localized, if needed) on server-side
......
......@@ -69,12 +69,13 @@ class AuthScreenController :
override fun render(viewState: AuthScreenViewState) {
super.render(viewState)
Timber.d("Render state $viewState")
when(viewState){
when(viewState as BaseState){
is AuthScreenViewState.Idle -> render(viewState)
is AuthScreenViewState.Authorization -> render(viewState)
is AuthScreenViewState.SignedIn -> render(viewState)
is AuthScreenViewState.SignInError -> render(viewState)
is AuthScreenViewState.SomeError -> render(viewState)
is BaseState.HandleError -> render(viewState)
}
}
......@@ -95,14 +96,12 @@ class AuthScreenController :
}
private fun render(viewState: AuthScreenViewState.SignInError){
viewState.exception.stringId?.let { snackbar.showSnackBar(it) }
viewState.exception.message?.let { snackbar.showSnackBar(it, Snackbar.LENGTH_LONG) }
viewState.exception.selectHandler(snackbar::showSnackBar,snackbar::showSnackBar)
signInButton.isEnabled=true
}
private fun render(viewState: AuthScreenViewState.SomeError){
viewState.exception.stringId?.let { snackbar.showSnackBar(it) }
viewState.exception.message?.let { snackbar.showSnackBar(it, Snackbar.LENGTH_LONG) }
viewState.exception.selectHandler(snackbar::showSnackBar,snackbar::showSnackBar)
}
......
......@@ -7,7 +7,6 @@ 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()
......
......@@ -10,10 +10,21 @@ import com.biganto.visual.roompark.domain.custom_exception.CustomApiException
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 var stringId: Int?, var message: String?) {
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,
......@@ -21,8 +32,8 @@ data class ExceptionString(@StringRes var stringId: Int?, var message: String?)
)
init {
assert(stringId!=null && message!=null) { "both values cannot be non-null" }
assert(stringId==null && message==null) { "both values cannot be null" }
assert(stringId==null && message==null) { "both values cannot be null!" }
errorMessage = if (stringId!=null) Either.Left(stringId) else Either.Right(message!!)
}
}
\ No newline at end of file
}
......@@ -80,10 +80,11 @@ interface ISnackBarProvider{
fun bindRootView(rootView : View?)
val isRootBounded : Boolean
val snackBar : Snackbar?
fun showSnackBar(@StringRes stringId: Int)
fun showSnackBar(erorrMessage: Any?)
fun showSnackBar(message: String)
fun showSnackBar(message: String, length: Int)
fun showSnackBar(message: String, type: SnackBarMessageType, length: Int)
fun showSnackBar(@StringRes stringId: Int)
}
enum class SnackBarMessageType{
......
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