Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
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
2ca86258
Commit
2ca86258
authored
Nov 20, 2019
by
Vladislav Bogdashkin
🎣
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
user session and feeds contract/uc/interactor
parent
4c5a7cc6
Changes
16
Show whitespace changes
Inline
Side-by-side
Showing
16 changed files
with
157 additions
and
20 deletions
+157
-20
BigantoBasePresenter.kt
...biganto/visual/roompark/conductor/BigantoBasePresenter.kt
+2
-7
FeedsRepository.kt
...nto/visual/roompark/data/data_provider/FeedsRepository.kt
+12
-6
ILocalStore.kt
...ava/com/biganto/visual/roompark/data/local/ILocalStore.kt
+1
-0
UserHolder.kt
...java/com/biganto/visual/roompark/data/local/UserHolder.kt
+2
-0
IDb.kt
...ava/com/biganto/visual/roompark/data/repository/db/IDb.kt
+2
-0
RequeryRepository.kt
.../roompark/data/repository/db/requrey/RequeryRepository.kt
+7
-0
UserSession.kt
.../visual/roompark/data/service/user_session/UserSession.kt
+74
-0
FeedsContract.kt
.../biganto/visual/roompark/domain/contract/FeedsContract.kt
+2
-1
CustomException.kt
...isual/roompark/domain/custom_exception/CustomException.kt
+2
-2
feeds.kt
...va/com/biganto/visual/roompark/domain/interactor/feeds.kt
+7
-1
authUseCase.kt
...om/biganto/visual/roompark/domain/use_case/authUseCase.kt
+1
-0
feedUseCase.kt
...om/biganto/visual/roompark/domain/use_case/feedUseCase.kt
+16
-0
ScreenDI.kt
...nto/visual/roompark/presentation/screen/feeds/ScreenDI.kt
+22
-1
ScreenDI.kt
...anto/visual/roompark/presentation/screen/home/ScreenDI.kt
+1
-1
ScreenDI.kt
...to/visual/roompark/presentation/screen/splash/ScreenDI.kt
+5
-1
strings.xml
app/src/main/res/values/strings.xml
+1
-0
No files found.
app/src/main/java/com/biganto/visual/roompark/conductor/BigantoBasePresenter.kt
View file @
2ca86258
...
...
@@ -53,11 +53,6 @@ abstract class BigantoBasePresenter<V : MvpView, VS>
ExceptionString
(
R
.
string
.
no_network_error
,
null
)
)
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
)
}
private
fun
onCodeReturn
(
e
:
CustomApiException
):
VS
=
vsByCode
(
e
.
code
).
invoke
(
ExceptionString
(
e
.
messageStringId
,
e
.
customMessage
))
}
\ No newline at end of file
app/src/main/java/com/biganto/visual/roompark/data/data_provider/FeedsRepository.kt
View file @
2ca86258
package
com.biganto.visual.roompark.data.data_provider
import
com.biganto.visual.androidplayer.data.repository.local.ILocalStore
import
com.biganto.visual.roompark.data.repository.api.IRoomParkApi
import
com.biganto.visual.roompark.data.repository.db.IDb
import
com.biganto.visual.roompark.data.repository.mapper.fromRaw
import
com.biganto.visual.roompark.data.service.user_session.IUserSession
import
com.biganto.visual.roompark.domain.contract.FeedsContract
import
com.biganto.visual.roompark.domain.model.ArticlesPreviewModel
import
com.biganto.visual.roompark.domain.model.FeedModel
import
com.biganto.visual.roompark.domain.model.FeedsHeaderModel
import
com.biganto.visual.roompark.domain.model.fromEntity
import
io.reactivex.Observable
import
io.reactivex.Single
...
...
@@ -18,15 +19,19 @@ import javax.inject.Inject
* Created by Vladislav Bogdashkin on 29.10.2019.
*/
//@Singleton
class
FeedsContractModule
@Inject
constructor
(
private
val
api
:
IRoomParkApi
,
private
val
db
:
IDb
private
val
db
:
IDb
,
private
val
local
:
ILocalStore
,
private
val
session
:
IUserSession
):
FeedsContract
{
override
fun
fetchFeeds
():
Single
<
FeedsHeaderModel
>
{
TODO
(
"not implemented"
)
//To change body of created functions use File | Settings | File Templates.
}
override
fun
fetchFeeds
():
Observable
<
List
<
FeedModel
>>
=
fetchAllFeeds
(
session
.
token
)
override
fun
fetchFeedObservable
(
id
:
Int
):
Observable
<
ArticlesPreviewModel
>
{
TODO
(
"not implemented"
)
//To change body of created functions use File | Settings | File Templates.
...
...
@@ -60,3 +65,4 @@ class FeedsContractModule @Inject constructor(
).
map
{
fromEntity
(
it
,
::
fromEntity
)
}
}
app/src/main/java/com/biganto/visual/roompark/data/local/ILocalStore.kt
View file @
2ca86258
...
...
@@ -12,4 +12,5 @@ interface ILocalStore {
fun
recentUser
():
Observable
<
in
UserState
>
fun
setDownloadListDestinationTourId
(
tourId
:
String
):
Observable
<
String
>?
fun
getDownloadListDestinationTourId
():
Observable
<
String
>?
fun
recentUserObs
():
Observable
<
String
>
}
\ No newline at end of file
app/src/main/java/com/biganto/visual/roompark/data/local/UserHolder.kt
View file @
2ca86258
...
...
@@ -48,6 +48,8 @@ class UserHolder @Inject constructor(val context : Context) : ILocalStore
prefs
.
string
(
SCROLL_LIST_TO_TOUR_KEY
,
""
)
.
observe
()
override
fun
recentUserObs
()
=
userSession
.
observe
()
override
fun
recentUser
():
Observable
<
in
UserState
>
=
userSession
.
observe
()
...
...
app/src/main/java/com/biganto/visual/roompark/data/repository/db/IDb.kt
View file @
2ca86258
...
...
@@ -5,6 +5,7 @@ import com.biganto.visual.roompark.data.repository.db.requrey.model.UserEntity
import
io.reactivex.Observable
import
io.reactivex.Single
import
io.requery.Persistable
import
io.requery.reactivex.ReactiveResult
/**
* Created by Vladislav Bogdashkin on 29.10.2019.
...
...
@@ -16,4 +17,5 @@ interface IDb {
fun
fetchFeeds
():
Observable
<
FeedEntity
>
fun
fetchUser
(
uuid
:
Int
):
Observable
<
UserEntity
>
fun
<
T
:
List
<
Persistable
>
>
blockingUpsert
(
entity
:
T
)
fun
userObservableResult
(
uuid
:
Int
):
Observable
<
ReactiveResult
<
UserEntity
>>?
}
\ No newline at end of file
app/src/main/java/com/biganto/visual/roompark/data/repository/db/requrey/RequeryRepository.kt
View file @
2ca86258
...
...
@@ -68,4 +68,11 @@ class RequeryRepository @Inject constructor(
fun
upsertFeeds
(
entity
:
List
<
FeedEntity
>)
=
store
.
upsert
(
entity
)
override
fun
userObservableResult
(
uuid
:
Int
)
=
store
.
select
(
UserEntity
::
class
)
.
where
(
UserEntity
.
UUID
.
eq
(
uuid
))
.
get
()
.
observableResult
()
}
\ No newline at end of file
app/src/main/java/com/biganto/visual/roompark/data/service/user_session/UserSession.kt
0 → 100644
View file @
2ca86258
package
com.biganto.visual.roompark.data.service.user_session
import
com.biganto.visual.androidplayer.data.repository.local.ILocalStore
import
com.biganto.visual.roompark.R
import
com.biganto.visual.roompark.data.local.UserState
import
com.biganto.visual.roompark.data.repository.db.IDb
import
com.biganto.visual.roompark.domain.custom_exception.CustomApiException
import
timber.log.Timber
import
javax.inject.Inject
/**
* Created by Vladislav Bogdashkin on 19.11.2019.
*/
//@Singleton
class
UserSessionService
@Inject
constructor
(
private
val
local
:
ILocalStore
,
private
val
db
:
IDb
):
IUserSession
{
private
var
_token
:
String
?
=
null
override
val
token
=
_token
?:
throw
CustomApiException
.
UnknownCustomApiException
(-
1
,
R
.
string
.
unauthorized_user_request
)
val
disposable
=
local
.
recentUserObs
()
.
flatMap
{
db
.
fetchUser
(
it
.
toInt
())
}
.
subscribe
{
_token
=
it
.
authToken
}
val
disposable2
=
local
.
recentUserObs
()
.
doOnNext
{
Timber
.
w
(
"got new user $it"
)
}
.
flatMap
{
db
.
userObservableResult
(
it
.
toInt
())
?.
doOnNext
{
Timber
.
w
(
"obs db user $it"
)
}
?.
flatMap
{
reactiveResult
->
reactiveResult
.
observable
()
?.
doOnNext
{
Timber
.
w
(
"flatmapUser db user $it"
)
}
}
}
.
doOnNext
{
Timber
.
w
(
"subscribe user $it"
)
}
.
subscribe
{
_token
=
it
.
authToken
}
fun
currentUser
()
=
local
.
recentUser
().
map
{
when
(
it
){
is
UserState
.
Authenticated
->
it
.
uuid
is
UserState
.
NotAuthenticated
->
CustomApiException
.
UnknownCustomApiException
(-
1
,
R
.
string
.
unauthorized_user_request
)
else
->
CustomApiException
.
UnknownCustomApiException
(-
1
,
R
.
string
.
unauthorized_user_request
)
}
}
fun
getUser
(
uuid
:
Int
)
=
db
.
fetchUser
(
uuid
).
map
{
it
.
authToken
}
}
class
UnauthorizedUser
(
override
var
message
:
String
,
val
userId
:
String
):
Exception
(
message
)
interface
IUserSession
{
val
token
:
String
}
sealed
class
UserSessionState
(){
class
Active
(
uuid
:
String
):
UserSessionState
()
class
Inactive
():
UserSessionState
()
}
\ No newline at end of file
app/src/main/java/com/biganto/visual/roompark/domain/contract/FeedsContract.kt
View file @
2ca86258
package
com.biganto.visual.roompark.domain.contract
import
com.biganto.visual.roompark.domain.model.ArticlesPreviewModel
import
com.biganto.visual.roompark.domain.model.FeedModel
import
com.biganto.visual.roompark.domain.model.FeedsHeaderModel
import
io.reactivex.Observable
import
io.reactivex.Single
...
...
@@ -11,7 +12,7 @@ import io.reactivex.Single
interface
FeedsContract
{
fun
fetchFeeds
():
Single
<
FeedsHeaderModel
>
fun
fetchFeeds
():
Observable
<
List
<
FeedModel
>
>
fun
fetchFeedObservable
(
id
:
Int
):
Observable
<
ArticlesPreviewModel
>
fun
getArticle
(
id
:
Int
):
Single
<
ArticlesPreviewModel
>
}
\ No newline at end of file
app/src/main/java/com/biganto/visual/roompark/domain/custom_exception/CustomException.kt
View file @
2ca86258
...
...
@@ -128,14 +128,14 @@ sealed class CustomApiException(val code:Int,@StringRes val messageStringId: In
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
?)
class
UnknownCustomApiException
(
code
:
Int
,
@StringRes
messageStringId
:
Int
?)
:
CustomApiException
(
code
,
messageStringId
,
apiMessage
)
}
//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
)
CustomApiException
.
UnknownCustomApiException
(
err
.
code
,
null
)
app/src/main/java/com/biganto/visual/roompark/domain/interactor/feeds.kt
View file @
2ca86258
package
com.biganto.visual.roompark.domain.interactor
import
com.biganto.visual.roompark.domain.model.*
import
com.biganto.visual.roompark.domain.use_case.FeedUseCase
import
io.reactivex.Single
import
java.util.*
import
javax.inject.Inject
...
...
@@ -10,9 +11,14 @@ import javax.inject.Inject
*/
class
FeedsInteractor
@Inject
constructor
(
private
val
feedsUseCase
:
FeedUseCase
)
{
fun
fetchTopFeeds
():
Single
<
FeedsHeaderModel
>
=
Single
.
just
(
testFeeds
)
fun
fetchTopFeeds
():
Single
<
FeedsHeaderModel
>
=
feedsUseCase
.
getFeeds
().
map
{
FeedsHeaderModel
(
it
)
}.
single
(
FeedsHeaderModel
(
arrayListOf
()))
//Single.just(testFeeds)
fun
fetchArticles
(
feedId
:
Int
):
Single
<
ArticlesPreviewModel
>
=
Single
.
just
(
when
(
feedId
)
{
...
...
app/src/main/java/com/biganto/visual/roompark/domain/use_case/authUseCase.kt
View file @
2ca86258
...
...
@@ -9,6 +9,7 @@ import javax.inject.Inject
class
AuthUseCase
@Inject
constructor
(
private
val
authContract
:
AuthContract
){
fun
validateAuth
()
=
authContract
.
validateAuthState
()
...
...
app/src/main/java/com/biganto/visual/roompark/domain/use_case/feedUseCase.kt
0 → 100644
View file @
2ca86258
package
com.biganto.visual.roompark.domain.use_case
import
com.biganto.visual.roompark.domain.contract.FeedsContract
import
javax.inject.Inject
/**
* Created by Vladislav Bogdashkin on 24.09.2019.
*/
class
FeedUseCase
@Inject
constructor
(
private
val
contract
:
FeedsContract
){
fun
getFeeds
()
=
contract
.
fetchFeeds
()
}
\ No newline at end of file
app/src/main/java/com/biganto/visual/roompark/presentation/screen/feeds/ScreenDI.kt
View file @
2ca86258
...
...
@@ -2,8 +2,16 @@ package com.biganto.visual.roompark.presentation.screen.feeds
import
android.content.Context
import
com.biganto.visual.roompark.base.RoomParkMainActivity
import
com.biganto.visual.roompark.data.data_provider.FeedsContractModule
import
com.biganto.visual.roompark.data.repository.api.retrofit.di.RetrofitModule
import
com.biganto.visual.roompark.data.repository.db.requrey.DbModule
import
com.biganto.visual.roompark.data.service.user_session.IUserSession
import
com.biganto.visual.roompark.data.service.user_session.UserSessionService
import
com.biganto.visual.roompark.di.dagger.AppComponent
import
com.biganto.visual.roompark.di.dagger.AppModule
import
com.biganto.visual.roompark.di.dagger.DataModule
import
com.biganto.visual.roompark.di.dagger.PerScreen
import
com.biganto.visual.roompark.domain.contract.FeedsContract
import
dagger.Binds
import
dagger.BindsInstance
import
dagger.Component
...
...
@@ -12,7 +20,11 @@ import dagger.Module
@PerScreen
@Component
(
modules
=
[
FeedsScreenModule
::
class
],
modules
=
[
FeedsScreenModule
::
class
,
DataModule
::
class
,
RetrofitModule
::
class
,
AppModule
::
class
,
DbModule
::
class
],
dependencies
=
[
AppComponent
::
class
])
interface
FeedsScreenComponent
{
...
...
@@ -36,4 +48,13 @@ abstract class FeedsScreenModule{
@Binds
abstract
fun
provideContext
(
activity
:
RoomParkMainActivity
):
Context
@PerScreen
@Binds
abstract
fun
provideContract
(
impl
:
FeedsContractModule
):
FeedsContract
@PerScreen
@Binds
abstract
fun
provideSession
(
impl
:
UserSessionService
):
IUserSession
}
app/src/main/java/com/biganto/visual/roompark/presentation/screen/home/ScreenDI.kt
View file @
2ca86258
...
...
@@ -4,8 +4,8 @@ import android.content.Context
import
com.biganto.visual.roompark.base.IBottomNavigation
import
com.biganto.visual.roompark.base.ICollapsingToolBar
import
com.biganto.visual.roompark.base.RoomParkMainActivity
import
com.biganto.visual.roompark.data.data_provider.AuthContractModule
import
com.biganto.visual.roompark.di.dagger.AppComponent
import
com.biganto.visual.roompark.di.dagger.AuthContractModule
import
com.biganto.visual.roompark.di.dagger.PerScreen
import
com.biganto.visual.roompark.domain.contract.AuthContract
import
com.biganto.visual.roompark.presentation.screen.home.home_routing.HomeBottomNavigationController
...
...
app/src/main/java/com/biganto/visual/roompark/presentation/screen/splash/ScreenDI.kt
View file @
2ca86258
...
...
@@ -3,9 +3,13 @@ package com.biganto.visual.roompark.presentation.screen.splash
import
android.content.Context
import
com.biganto.visual.roompark.base.IBottomNavigation
import
com.biganto.visual.roompark.base.RoomParkMainActivity
import
com.biganto.visual.roompark.data.data_provider.AuthContractModule
import
com.biganto.visual.roompark.data.repository.api.retrofit.di.RetrofitModule
import
com.biganto.visual.roompark.data.repository.db.requrey.DbModule
import
com.biganto.visual.roompark.di.dagger.*
import
com.biganto.visual.roompark.di.dagger.AppComponent
import
com.biganto.visual.roompark.di.dagger.AppModule
import
com.biganto.visual.roompark.di.dagger.DataModule
import
com.biganto.visual.roompark.di.dagger.PerScreen
import
com.biganto.visual.roompark.domain.contract.AuthContract
import
com.biganto.visual.roompark.presentation.screen.auth.AuthScreenModule
import
dagger.Binds
...
...
app/src/main/res/values/strings.xml
View file @
2ca86258
...
...
@@ -50,6 +50,7 @@
<string
name=
"auth_data_requirments_failed"
>
Login at least %d symbols
\nPassword at least %d symbols
</string>
<string
name=
"feeds_tab_divider"
>
/
</string>
<string
name=
"unauthorized_user_request"
>
Пользователь не авторизован
</string>
<!--endregion-->
</resources>
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