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
import
com.hannesdorfmann.mosby3.mvp.MvpView
import
com.jakewharton.rxrelay2.PublishRelay
import
io.reactivex.Observable
import
timber.log.Timber
/**
* Created by Vladislav Bogdashkin on 30.09.2019.
...
...
@@ -27,16 +28,20 @@ abstract class BigantoBasePresenter<V : MvpView, VS>
open
fun
vsByCode
(
code
:
Int
)
=
defaultErrorViewStateHandler
()
open
fun
vsByThrowable
(
t
:
Throwable
)
=
defaultErrorViewStateHandler
()
open
fun
parseError
(
t
:
Throwable
):
VS
=
open
fun
parseError
(
t
:
Throwable
)
:
VS
=
when
(
t
)
{
is
CustomApiException
->
parseError
(
t
)
is
NoNetworkException
->
parseError
(
t
)
else
->
parseError
(
t
)
is
CustomApiException
->
{
Timber
.
d
(
"CustomApiException ${t.messageStringId} / ${t.customMessage}"
)
parse
(
t
)
}
private
fun
parseError
(
e
:
CustomApiException
)
=
onCodeReturn
(
e
)
private
fun
parseError
(
e
:
NoNetworkException
)
=
onNoNetwork
(
e
)
private
fun
parseError
(
e
:
Exception
)
=
onRandomError
(
e
)
is
NoNetworkException
->
parse
(
t
)
else
->
parse
(
t
)
}
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
=
vsByThrowable
(
t
).
invoke
(
...
...
@@ -48,7 +53,11 @@ abstract class BigantoBasePresenter<V : MvpView, VS>
ExceptionString
(
R
.
string
.
no_network_error
,
null
)
)
private
fun
onCodeReturn
(
e
:
CustomApiException
):
VS
=
vsByCode
(
e
.
code
).
invoke
(
ExceptionString
(
e
))
private
fun
onCodeReturn
(
e
:
CustomApiException
):
VS
{
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
import
com.biganto.visual.roompark.data.repository.api.retrofit.raw.*
import
io.reactivex.Observable
import
retrofit2.Response
import
retrofit2.http.GET
import
retrofit2.http.POST
import
retrofit2.http.Query
import
retrofit2.http.*
/**
...
...
@@ -133,12 +131,13 @@ interface IRoomParkMobileApi{
@POST
(
"$API_URL$AUTH_METHOD$DELIMITER"
)
@FormUrlEncoded
fun
authoriz
(
@Query
(
CLIENT_TYPE_PARAM
)
clientType
:
String
=
DEFAULT_CLIENT_TYPE
,
@Query
(
CLIENT_VERSION_PARAM
)
clientVersion
:
String
=
DEFAULT_CLIENT_VERSION
,
@Query
(
API_VERSION_PARAM
)
apiVersion
:
String
=
DEFAULT_API_VERSION
,
@
Query
(
EMAIL_AUTH_PARAM
)
email
:
String
,
@
Query
(
PASSWORD_AUTH_PARAM
)
pwd
:
String
@
Field
(
EMAIL_AUTH_PARAM
)
email
:
String
,
@
Field
(
PASSWORD_AUTH_PARAM
)
pwd
:
String
):
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
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
com.google.gson.*
import
timber.log.Timber
import
java.lang.reflect.Type
...
...
@@ -23,9 +18,9 @@ class CustomExceptionDeserializer<T> : JsonDeserializer<T> {
//region valid case
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
)
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
...
...
@@ -35,10 +30,10 @@ class CustomExceptionDeserializer<T> : JsonDeserializer<T> {
Timber
.
w
(
"api errorlist: $errorList"
)
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
)
}
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
)
}
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
import
com.google.android.material.textfield.TextInputLayout
import
com.jakewharton.rxbinding3.view.clicks
import
io.reactivex.Observable
import
io.reactivex.android.schedulers.AndroidSchedulers
import
timber.log.Timber
import
javax.inject.Inject
...
...
@@ -31,25 +32,21 @@ class AuthScreenController :
@BindView
(
R
.
id
.
password_text_input
)
lateinit
var
pwdInput
:
TextInputLayout
@BindView
(
R
.
id
.
sign_in_button
)
lateinit
var
signInButton
:
MaterialButton
override
fun
tryAuth
():
Observable
<
AuthInputModel
>
=
signInButton
.
clicks
()
.
doOnNext
{
signInButton
.
hideKeyboard
()}
.
map
<
AuthInputModel
>{
AuthInputModel
(
loginInput
.
editText
?.
text
?.
toString
()
?:
""
,
pwdInput
.
editText
?.
text
?.
toString
()
?:
""
)
}
.
observeOn
(
AndroidSchedulers
.
mainThread
())
override
fun
injectDependencies
()
{
getComponent
()
}
@Inject
override
lateinit
var
injectedPresenter
:
AuthScreenPresenter
// @Inject
// lateinit var snacky:ISnackBarProvider
...
...
@@ -63,8 +60,6 @@ class AuthScreenController :
// @Inject
// lateinit var ac: RoomParkMainActivity
override
fun
render
(
viewState
:
AuthScreenViewState
)
{
super
.
render
(
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(
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"
)
}
.
map
{
it
}
.
map
{
AuthScreenViewState
.
SignedIn
()
}
.
map
<
AuthScreenViewState
>
{
AuthScreenViewState
.
SignedIn
()
}
.
onErrorReturn
{
parseError
(
it
)
}
}
// .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> {
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
){
...
...
@@ -27,13 +27,16 @@ data class ExceptionString(@StringRes private val stringId: Int?, private val m
}
constructor
(
e
:
CustomApiException
)
:
this
(
if
(
e
.
m
essage
!=
null
)
null
else
e
.
messageStringId
,
if
(
e
.
messageStringId
!=
null
)
null
else
e
.
m
essage
if
(
e
.
customM
essage
!=
null
)
null
else
e
.
messageStringId
,
e
.
customM
essage
)
init
{
assert
(
stringId
==
null
&&
message
==
null
)
{
"both values cannot be null!"
}
errorMessage
=
if
(
stringId
!=
null
)
Either
.
Left
(
stringId
)
else
Either
.
Right
(
message
!!
)
}
val
errorMessage
:
Either
<
Int
,
String
>
=
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