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
3dfee915
Commit
3dfee915
authored
Nov 15, 2019
by
Vladislav Bogdashkin
🎣
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
fix custom exception flow (messagename) and auth method with proper configuration
parent
9678c356
Changes
6
Show whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
44 additions
and
43 deletions
+44
-43
BigantoBasePresenter.kt
...biganto/visual/roompark/conductor/BigantoBasePresenter.kt
+18
-9
IRoomParkMobileApi.kt
...ompark/data/repository/api/retrofit/IRoomParkMobileApi.kt
+4
-5
CustomExceptionDeserializer.kt
...pository/api/retrofit/util/CustomExceptionDeserializer.kt
+5
-10
ScreenController.kt
...ual/roompark/presentation/screen/auth/ScreenController.kt
+3
-8
ScreenPresenter.kt
...sual/roompark/presentation/screen/auth/ScreenPresenter.kt
+4
-4
either.kt
...n/java/com/biganto/visual/roompark/util/monades/either.kt
+10
-7
No files found.
app/src/main/java/com/biganto/visual/roompark/conductor/BigantoBasePresenter.kt
View file @
3dfee915
...
@@ -8,6 +8,7 @@ import com.hannesdorfmann.mosby3.mvi.MviBasePresenter
...
@@ -8,6 +8,7 @@ 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
import
io.reactivex.Observable
import
timber.log.Timber
/**
/**
* Created by Vladislav Bogdashkin on 30.09.2019.
* Created by Vladislav Bogdashkin on 30.09.2019.
...
@@ -27,16 +28,20 @@ abstract class BigantoBasePresenter<V : MvpView, VS>
...
@@ -27,16 +28,20 @@ abstract class BigantoBasePresenter<V : MvpView, VS>
open
fun
vsByCode
(
code
:
Int
)
=
defaultErrorViewStateHandler
()
open
fun
vsByCode
(
code
:
Int
)
=
defaultErrorViewStateHandler
()
open
fun
vsByThrowable
(
t
:
Throwable
)
=
defaultErrorViewStateHandler
()
open
fun
vsByThrowable
(
t
:
Throwable
)
=
defaultErrorViewStateHandler
()
open
fun
parseError
(
t
:
Throwable
):
VS
=
open
fun
parseError
(
t
:
Throwable
)
:
VS
=
when
(
t
)
{
when
(
t
)
{
is
CustomApiException
->
parseError
(
t
)
is
CustomApiException
->
{
is
NoNetworkException
->
parseError
(
t
)
Timber
.
d
(
"CustomApiException ${t.messageStringId} / ${t.customMessage}"
)
else
->
parseError
(
t
)
parse
(
t
)
}
}
private
fun
parseError
(
e
:
CustomApiException
)
=
onCodeReturn
(
e
)
is
NoNetworkException
->
parse
(
t
)
private
fun
parseError
(
e
:
NoNetworkException
)
=
onNoNetwork
(
e
)
else
->
parse
(
t
)
private
fun
parseError
(
e
:
Exception
)
=
onRandomError
(
e
)
}
private
fun
parse
(
e
:
CustomApiException
)
=
onCodeReturn
(
e
)
private
fun
parse
(
e
:
NoNetworkException
)
=
onNoNetwork
(
e
)
private
fun
parse
(
e
:
Throwable
)
=
onRandomError
(
e
)
open
fun
onRandomError
(
t
:
Throwable
):
VS
=
open
fun
onRandomError
(
t
:
Throwable
):
VS
=
vsByThrowable
(
t
).
invoke
(
vsByThrowable
(
t
).
invoke
(
...
@@ -48,7 +53,11 @@ abstract class BigantoBasePresenter<V : MvpView, VS>
...
@@ -48,7 +53,11 @@ abstract class BigantoBasePresenter<V : MvpView, VS>
ExceptionString
(
R
.
string
.
no_network_error
,
null
)
ExceptionString
(
R
.
string
.
no_network_error
,
null
)
)
)
private
fun
onCodeReturn
(
e
:
CustomApiException
):
VS
=
private
fun
onCodeReturn
(
e
:
CustomApiException
):
VS
{
vsByCode
(
e
.
code
).
invoke
(
ExceptionString
(
e
))
Timber
.
d
(
"2 CustomApiException ${e.messageStringId} / ${e.customMessage}"
)
val
errst
=
ExceptionString
(
e
.
messageStringId
,
e
.
customMessage
)
Timber
.
d
(
"ExceptionString ${errst} / ${errst}"
)
return
vsByCode
(
e
.
code
).
invoke
(
errst
)
}
}
}
\ No newline at end of file
app/src/main/java/com/biganto/visual/roompark/data/repository/api/retrofit/IRoomParkMobileApi.kt
View file @
3dfee915
...
@@ -3,9 +3,7 @@ package com.biganto.visual.roompark.data.repository.api.retrofit
...
@@ -3,9 +3,7 @@ package com.biganto.visual.roompark.data.repository.api.retrofit
import
com.biganto.visual.roompark.data.repository.api.retrofit.raw.*
import
com.biganto.visual.roompark.data.repository.api.retrofit.raw.*
import
io.reactivex.Observable
import
io.reactivex.Observable
import
retrofit2.Response
import
retrofit2.Response
import
retrofit2.http.GET
import
retrofit2.http.*
import
retrofit2.http.POST
import
retrofit2.http.Query
/**
/**
...
@@ -133,12 +131,13 @@ interface IRoomParkMobileApi{
...
@@ -133,12 +131,13 @@ interface IRoomParkMobileApi{
@POST
(
"$API_URL$AUTH_METHOD$DELIMITER"
)
@POST
(
"$API_URL$AUTH_METHOD$DELIMITER"
)
@FormUrlEncoded
fun
authoriz
(
fun
authoriz
(
@Query
(
CLIENT_TYPE_PARAM
)
clientType
:
String
=
DEFAULT_CLIENT_TYPE
,
@Query
(
CLIENT_TYPE_PARAM
)
clientType
:
String
=
DEFAULT_CLIENT_TYPE
,
@Query
(
CLIENT_VERSION_PARAM
)
clientVersion
:
String
=
DEFAULT_CLIENT_VERSION
,
@Query
(
CLIENT_VERSION_PARAM
)
clientVersion
:
String
=
DEFAULT_CLIENT_VERSION
,
@Query
(
API_VERSION_PARAM
)
apiVersion
:
String
=
DEFAULT_API_VERSION
,
@Query
(
API_VERSION_PARAM
)
apiVersion
:
String
=
DEFAULT_API_VERSION
,
@
Query
(
EMAIL_AUTH_PARAM
)
email
:
String
,
@
Field
(
EMAIL_AUTH_PARAM
)
email
:
String
,
@
Query
(
PASSWORD_AUTH_PARAM
)
pwd
:
String
@
Field
(
PASSWORD_AUTH_PARAM
)
pwd
:
String
):
Observable
<
Response
<
AuthRaw
>>
):
Observable
<
Response
<
AuthRaw
>>
...
...
app/src/main/java/com/biganto/visual/roompark/data/repository/api/retrofit/util/CustomExceptionDeserializer.kt
View file @
3dfee915
...
@@ -2,12 +2,7 @@ package com.biganto.visual.roompark.data.repository.api.retrofit.util
...
@@ -2,12 +2,7 @@ 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.data.repository.api.retrofit.raw.ErrorRaw
import
com.biganto.visual.roompark.domain.custom_exception.parseException
import
com.biganto.visual.roompark.domain.custom_exception.parseException
import
com.google.gson.Gson
import
com.google.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
timber.log.Timber
import
java.lang.reflect.Type
import
java.lang.reflect.Type
...
@@ -23,9 +18,9 @@ class CustomExceptionDeserializer<T> : JsonDeserializer<T> {
...
@@ -23,9 +18,9 @@ class CustomExceptionDeserializer<T> : JsonDeserializer<T> {
//region valid case
//region valid case
when
(
json
){
when
(
json
){
is
J
SON
Object
->
if
(!
json
.
asJsonObject
.
keySet
().
contains
(
"errors"
))
is
J
son
Object
->
if
(!
json
.
asJsonObject
.
keySet
().
contains
(
"errors"
))
return
Gson
().
newBuilder
().
create
().
fromJson
(
json
,
typeOfT
)
return
Gson
().
newBuilder
().
create
().
fromJson
(
json
,
typeOfT
)
is
J
SON
Array
->
return
Gson
().
newBuilder
().
create
().
fromJson
(
json
,
typeOfT
)
is
J
son
Array
->
return
Gson
().
newBuilder
().
create
().
fromJson
(
json
,
typeOfT
)
}
}
//endregion valid case
//endregion valid case
...
@@ -35,10 +30,10 @@ class CustomExceptionDeserializer<T> : JsonDeserializer<T> {
...
@@ -35,10 +30,10 @@ class CustomExceptionDeserializer<T> : JsonDeserializer<T> {
Timber
.
w
(
"api errorlist: $errorList"
)
Timber
.
w
(
"api errorlist: $errorList"
)
when
(
json
)
{
when
(
json
)
{
is
JSON
Array
->
errorList
.
asJsonArray
.
forEach
{
is
Json
Array
->
errorList
.
asJsonArray
.
forEach
{
vals
.
add
(
ctx
.
deserialize
<
T
>(
it
,
ErrorRaw
::
class
.
java
)
as
ErrorRaw
)
vals
.
add
(
ctx
.
deserialize
<
T
>(
it
,
ErrorRaw
::
class
.
java
)
as
ErrorRaw
)
}
}
is
J
SON
Object
->
json
.
asJsonObject
.
get
(
"errors"
).
asJsonArray
.
forEach
{
is
J
son
Object
->
json
.
asJsonObject
.
get
(
"errors"
).
asJsonArray
.
forEach
{
vals
.
add
(
ctx
.
deserialize
<
T
>(
it
,
ErrorRaw
::
class
.
java
)
as
ErrorRaw
)
vals
.
add
(
ctx
.
deserialize
<
T
>(
it
,
ErrorRaw
::
class
.
java
)
as
ErrorRaw
)
}
}
else
->
throw
RuntimeException
(
"Unexpected JSON type: "
+
json
.
javaClass
)
else
->
throw
RuntimeException
(
"Unexpected JSON type: "
+
json
.
javaClass
)
...
...
app/src/main/java/com/biganto/visual/roompark/presentation/screen/auth/ScreenController.kt
View file @
3dfee915
...
@@ -12,6 +12,7 @@ import com.google.android.material.button.MaterialButton
...
@@ -12,6 +12,7 @@ import com.google.android.material.button.MaterialButton
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
import
io.reactivex.android.schedulers.AndroidSchedulers
import
timber.log.Timber
import
timber.log.Timber
import
javax.inject.Inject
import
javax.inject.Inject
...
@@ -31,25 +32,21 @@ class AuthScreenController :
...
@@ -31,25 +32,21 @@ class AuthScreenController :
@BindView
(
R
.
id
.
password_text_input
)
lateinit
var
pwdInput
:
TextInputLayout
@BindView
(
R
.
id
.
password_text_input
)
lateinit
var
pwdInput
:
TextInputLayout
@BindView
(
R
.
id
.
sign_in_button
)
lateinit
var
signInButton
:
MaterialButton
@BindView
(
R
.
id
.
sign_in_button
)
lateinit
var
signInButton
:
MaterialButton
override
fun
tryAuth
():
Observable
<
AuthInputModel
>
=
override
fun
tryAuth
():
Observable
<
AuthInputModel
>
=
signInButton
.
clicks
()
signInButton
.
clicks
()
.
doOnNext
{
signInButton
.
hideKeyboard
()}
.
map
<
AuthInputModel
>{
AuthInputModel
(
loginInput
.
editText
?.
text
?.
toString
()
?:
""
.
map
<
AuthInputModel
>{
AuthInputModel
(
loginInput
.
editText
?.
text
?.
toString
()
?:
""
,
pwdInput
.
editText
?.
text
?.
toString
()
?:
""
)
,
pwdInput
.
editText
?.
text
?.
toString
()
?:
""
)
}
}
.
observeOn
(
AndroidSchedulers
.
mainThread
())
override
fun
injectDependencies
()
{
override
fun
injectDependencies
()
{
getComponent
()
getComponent
()
}
}
@Inject
@Inject
override
lateinit
var
injectedPresenter
:
AuthScreenPresenter
override
lateinit
var
injectedPresenter
:
AuthScreenPresenter
// @Inject
// @Inject
// lateinit var snacky:ISnackBarProvider
// lateinit var snacky:ISnackBarProvider
...
@@ -63,8 +60,6 @@ class AuthScreenController :
...
@@ -63,8 +60,6 @@ class AuthScreenController :
// @Inject
// @Inject
// lateinit var ac: RoomParkMainActivity
// lateinit var ac: RoomParkMainActivity
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"
)
...
...
app/src/main/java/com/biganto/visual/roompark/presentation/screen/auth/ScreenPresenter.kt
View file @
3dfee915
...
@@ -30,12 +30,12 @@ class AuthScreenPresenter @Inject constructor(
...
@@ -30,12 +30,12 @@ class AuthScreenPresenter @Inject constructor(
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
.
SignedIn
()
}
.
map
{
AuthScreenViewState
.
SignedIn
()
}
.
onErrorReturn
{
parseError
(
it
)
}
}
}
// .startWith(Observable.just(AuthScreenViewState.Authorization()))
// .startWith(Observable.just(AuthScreenViewState.Authorization()))
...
...
app/src/main/java/com/biganto/visual/roompark/util/monades/either.kt
View file @
3dfee915
...
@@ -18,7 +18,7 @@ sealed class Either<out E, out V> {
...
@@ -18,7 +18,7 @@ sealed class Either<out E, out V> {
data class
ExceptionString
(
@StringRes
private
val
stringId
:
Int
?,
private
val
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
)
=
fun
selectHandler
(
a1
:(
Int
)->
Unit
,
a2
:(
String
)->
Unit
)
=
when
(
errorMessage
){
when
(
errorMessage
){
...
@@ -27,13 +27,16 @@ data class ExceptionString(@StringRes private val stringId: Int?, private val m
...
@@ -27,13 +27,16 @@ data class ExceptionString(@StringRes private val stringId: Int?, private val m
}
}
constructor
(
e
:
CustomApiException
)
:
this
(
constructor
(
e
:
CustomApiException
)
:
this
(
if
(
e
.
m
essage
!=
null
)
null
else
e
.
messageStringId
,
if
(
e
.
customM
essage
!=
null
)
null
else
e
.
messageStringId
,
if
(
e
.
messageStringId
!=
null
)
null
else
e
.
m
essage
e
.
customM
essage
)
)
init
{
val
errorMessage
:
Either
<
Int
,
String
>
=
if
(
stringId
!=
null
)
Either
.
Left
(
stringId
)
else
Either
.
Right
(
message
!!
)
assert
(
stringId
==
null
&&
message
==
null
)
{
"both values cannot be null!"
}
errorMessage
=
if
(
stringId
!=
null
)
Either
.
Left
(
stringId
)
else
Either
.
Right
(
message
!!
)
// init {
}
// Timber.d(" messages: $stringId / $message")
// if (stringId==null && message==null) throw error{ "both values cannot be null!" }
// errorMessage = if (stringId!=null) Either.Left(stringId) else Either.Right(message!!)
// }
}
}
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