Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Room Park Android
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Vladislav Bogdashkin
Room Park Android
Commits
ad925ad9
Commit
ad925ad9
authored
Nov 13, 2019
by
Vladislav Bogdashkin
🎣
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
resolve localized exception message as Either
parent
8617efc6
Changes
5
Show whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
21 additions
and
13 deletions
+21
-13
CustomException.kt
...isual/roompark/domain/custom_exception/CustomException.kt
+0
-2
ScreenController.kt
...ual/roompark/presentation/screen/auth/ScreenController.kt
+4
-5
ScreenViewState.kt
...sual/roompark/presentation/screen/auth/ScreenViewState.kt
+0
-1
either.kt
...n/java/com/biganto/visual/roompark/util/monades/either.kt
+15
-4
SnackBarModule.kt
...isual/roompark/util/view_utils/snackbar/SnackBarModule.kt
+2
-1
No files found.
app/src/main/java/com/biganto/visual/roompark/domain/custom_exception/CustomException.kt
View file @
ad925ad9
...
@@ -125,14 +125,12 @@ sealed class CustomApiException(val code:Int,@StringRes val messageStringId: In
...
@@ -125,14 +125,12 @@ 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
?,
apiMessage
:
String
?)
class
UnknownCustomApiException
(
code
:
Int
,
@StringRes
messageStringId
:
Int
?,
apiMessage
:
String
?)
:
CustomApiException
(
code
,
messageStringId
,
apiMessage
)
:
CustomApiException
(
code
,
messageStringId
,
apiMessage
)
}
}
//as an agreement error message should be correct for user (and localized, if needed) on server-side
//as an agreement error message should be correct for user (and localized, if needed) on server-side
...
...
app/src/main/java/com/biganto/visual/roompark/presentation/screen/auth/ScreenController.kt
View file @
ad925ad9
...
@@ -69,12 +69,13 @@ class AuthScreenController :
...
@@ -69,12 +69,13 @@ class AuthScreenController :
override
fun
render
(
viewState
:
AuthScreenViewState
)
{
override
fun
render
(
viewState
:
AuthScreenViewState
)
{
super
.
render
(
viewState
)
super
.
render
(
viewState
)
Timber
.
d
(
"Render state $viewState"
)
Timber
.
d
(
"Render state $viewState"
)
when
(
viewState
){
when
(
viewState
as
BaseState
){
is
AuthScreenViewState
.
Idle
->
render
(
viewState
)
is
AuthScreenViewState
.
Idle
->
render
(
viewState
)
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
)
is
AuthScreenViewState
.
SomeError
->
render
(
viewState
)
is
BaseState
.
HandleError
->
render
(
viewState
)
}
}
}
}
...
@@ -95,14 +96,12 @@ class AuthScreenController :
...
@@ -95,14 +96,12 @@ class AuthScreenController :
}
}
private
fun
render
(
viewState
:
AuthScreenViewState
.
SignInError
){
private
fun
render
(
viewState
:
AuthScreenViewState
.
SignInError
){
viewState
.
exception
.
stringId
?.
let
{
snackbar
.
showSnackBar
(
it
)
}
viewState
.
exception
.
selectHandler
(
snackbar
::
showSnackBar
,
snackbar
::
showSnackBar
)
viewState
.
exception
.
message
?.
let
{
snackbar
.
showSnackBar
(
it
,
Snackbar
.
LENGTH_LONG
)
}
signInButton
.
isEnabled
=
true
signInButton
.
isEnabled
=
true
}
}
private
fun
render
(
viewState
:
AuthScreenViewState
.
SomeError
){
private
fun
render
(
viewState
:
AuthScreenViewState
.
SomeError
){
viewState
.
exception
.
stringId
?.
let
{
snackbar
.
showSnackBar
(
it
)
}
viewState
.
exception
.
selectHandler
(
snackbar
::
showSnackBar
,
snackbar
::
showSnackBar
)
viewState
.
exception
.
message
?.
let
{
snackbar
.
showSnackBar
(
it
,
Snackbar
.
LENGTH_LONG
)
}
}
}
...
...
app/src/main/java/com/biganto/visual/roompark/presentation/screen/auth/ScreenViewState.kt
View file @
ad925ad9
...
@@ -7,7 +7,6 @@ import com.biganto.visual.roompark.util.monades.ExceptionString
...
@@ -7,7 +7,6 @@ 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
()
...
...
app/src/main/java/com/biganto/visual/roompark/util/monades/either.kt
View file @
ad925ad9
...
@@ -10,10 +10,21 @@ import com.biganto.visual.roompark.domain.custom_exception.CustomApiException
...
@@ -10,10 +10,21 @@ import com.biganto.visual.roompark.domain.custom_exception.CustomApiException
sealed
class
Either
<
out
E
,
out
V
>
{
sealed
class
Either
<
out
E
,
out
V
>
{
data class
Left
<
out
E
>(
val
left
:
E
)
:
Either
<
E
,
Nothing
>()
data class
Left
<
out
E
>(
val
left
:
E
)
:
Either
<
E
,
Nothing
>()
data class
Right
<
out
V
>(
val
right
:
V
)
:
Either
<
Nothing
,
V
>()
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
(
constructor
(
e
:
CustomApiException
)
:
this
(
if
(
e
.
message
!=
null
)
null
else
e
.
messageStringId
,
if
(
e
.
message
!=
null
)
null
else
e
.
messageStringId
,
...
@@ -21,8 +32,8 @@ data class ExceptionString(@StringRes var stringId: Int?, var message: String?)
...
@@ -21,8 +32,8 @@ data class ExceptionString(@StringRes var stringId: Int?, var message: String?)
)
)
init
{
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
!!
)
}
}
}
}
app/src/main/java/com/biganto/visual/roompark/util/view_utils/snackbar/SnackBarModule.kt
View file @
ad925ad9
...
@@ -80,10 +80,11 @@ interface ISnackBarProvider{
...
@@ -80,10 +80,11 @@ 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
(
erorrMessage
:
Any
?)
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
)
fun
showSnackBar
(
@StringRes
stringId
:
Int
)
}
}
enum
class
SnackBarMessageType
{
enum
class
SnackBarMessageType
{
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment