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
5809bb86
Commit
5809bb86
authored
Nov 19, 2019
by
Vladislav Bogdashkin
🎣
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
feed use case
parent
06bbe455
Changes
11
Show whitespace changes
Inline
Side-by-side
Showing
11 changed files
with
180 additions
and
53 deletions
+180
-53
bogdashkin.xml
.idea/dictionaries/bogdashkin.xml
+1
-0
AuthRepository.kt
...anto/visual/roompark/data/data_provider/AuthRepository.kt
+43
-17
FeedsRepository.kt
...nto/visual/roompark/data/data_provider/FeedsRepository.kt
+59
-0
IDb.kt
...ava/com/biganto/visual/roompark/data/repository/db/IDb.kt
+8
-0
RequeryRepository.kt
.../roompark/data/repository/db/requrey/RequeryRepository.kt
+27
-1
raw2entity.kt
...anto/visual/roompark/data/repository/mapper/raw2entity.kt
+14
-0
ContextModule.kt
...va/com/biganto/visual/roompark/di/dagger/ContextModule.kt
+0
-29
FeedsContract.kt
.../biganto/visual/roompark/domain/contract/FeedsContract.kt
+2
-2
feeds.kt
...in/java/com/biganto/visual/roompark/domain/model/feeds.kt
+10
-1
ScreenDI.kt
...anto/visual/roompark/presentation/screen/auth/ScreenDI.kt
+11
-2
ScreenDI.kt
.../visual/roompark/presentation/screen/settings/ScreenDI.kt
+5
-1
No files found.
.idea/dictionaries/bogdashkin.xml
View file @
5809bb86
...
...
@@ -3,6 +3,7 @@
<words>
<w>
Biganto
</w>
<w>
snackbar
</w>
<w>
upsert
</w>
</words>
</dictionary>
</component>
\ No newline at end of file
app/src/main/java/com/biganto/visual/roompark/data/data_provider/AuthRepository.kt
View file @
5809bb86
package
com.biganto.visual.roompark.data.data_provider
import
com.biganto.visual.androidplayer.data.repository.local.ILocalStore
import
com.biganto.visual.roompark.data.local.UserState
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.domain.contract.AuthContract
import
com.biganto.visual.roompark.domain.model.AuthInfoModel
import
com.biganto.visual.roompark.domain.model.fromEntity
import
io.reactivex.Completable
import
io.reactivex.Observable
import
timber.log.Timber
import
javax.inject.Inject
/**
* Created by Vladislav Bogdashkin on 29.10.2019.
*/
//
//class AuthRepository @Inject constructor(
// val roomparkApi:IRoomParkApi
//) : AuthContract{
//
// override fun validateAuthState(): Observable<Boolean> {
// TODO("not implemented") //To change body of created functions use File | Settings | File Templates.
// }
//
// override fun signIn(email: String, password: String): Observable<AuthInfoModel> =
// roomparkApi.authenticate(email,password)
// .map { AuthInfoModel("",2,"","") }
//
// override fun signOut(): Completable {
// TODO("not implemented") //To change body of created functions use File | Settings | File Templates.
// }
//
//}
\ No newline at end of file
class
AuthContractModule
@Inject
constructor
(
private
val
local
:
ILocalStore
,
private
val
api
:
IRoomParkApi
,
private
val
db
:
IDb
):
AuthContract
{
init
{
Timber
.
d
(
"Auth Repository Created"
)
}
override
fun
signOut
():
Completable
=
local
.
setRecentUser
(
null
)
override
fun
signIn
(
email
:
String
,
password
:
String
):
Observable
<
AuthInfoModel
>
=
api
.
authenticate
(
email
,
password
)
.
map
(
::
fromRaw
)
.
flatMap
{
db
.
upsertUser
(
it
)
}
.
doOnNext
{
Timber
.
d
(
"user id: ${it.uuid}"
)}
.
doOnNext
{
local
.
setRecentUser
(
it
.
uuid
.
toString
()).
blockingAwait
()
}
.
map
(
::
fromEntity
)
override
fun
validateAuthState
():
Observable
<
Boolean
>
=
local
.
recentUser
()
.
map
{
when
(
it
){
is
UserState
.
NotAuthenticated
->
false
is
UserState
.
Authenticated
->
true
else
->
false
}
}
}
app/src/main/java/com/biganto/visual/roompark/data/data_provider/FeedsRepository.kt
0 → 100644
View file @
5809bb86
package
com.biganto.visual.roompark.data.data_provider
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.domain.contract.FeedsContract
import
com.biganto.visual.roompark.domain.model.*
import
io.reactivex.Observable
import
io.reactivex.Single
import
io.reactivex.schedulers.Schedulers
import
timber.log.Timber
import
javax.inject.Inject
/**
* Created by Vladislav Bogdashkin on 29.10.2019.
*/
class
FeedsContractModule
@Inject
constructor
(
private
val
api
:
IRoomParkApi
,
private
val
db
:
IDb
):
FeedsContract
{
override
fun
fetchFeeds
():
Single
<
FeedsHeaderModel
>
{
TODO
(
"not implemented"
)
//To change body of created functions use File | Settings | File Templates.
}
override
fun
fetchFeedObservable
(
id
:
Int
):
Observable
<
ArticlesPreviewModel
>
{
TODO
(
"not implemented"
)
//To change body of created functions use File | Settings | File Templates.
}
override
fun
getArticle
(
id
:
Int
):
Single
<
ArticlesPreviewModel
>
{
TODO
(
"not implemented"
)
//To change body of created functions use File | Settings | File Templates.
}
init
{
Timber
.
d
(
"Feeds Repository Created"
)
}
private
fun
fetchFeedsApi
(
token
:
String
)
=
api
.
getFeeds
(
token
)
.
doOnNext
{
Timber
.
d
(
"raw0 $it"
)
}
.
map
(
::
fromRaw
)
.
doOnNext
(
db
::
blockingUpsert
)
.
subscribeOn
(
Schedulers
.
io
())
private
val
fetchFeedsDb
=
db
.
fetchFeeds
()
.
toList
()
.
toObservable
()
.
subscribeOn
(
Schedulers
.
io
())
fun
getZones
(
userToken
:
String
):
Observable
<
List
<
FeedModel
>>
=
Observable
.
mergeDelayError
(
arrayListOf
(
fetchFeedsApi
(
userToken
),
fetchFeedsDb
)
).
map
{
fromEntity
(
it
)
{
ent
->
fromEntity2
(
ent
)}}
}
app/src/main/java/com/biganto/visual/roompark/data/repository/db/IDb.kt
View file @
5809bb86
package
com.biganto.visual.roompark.data.repository.db
import
com.biganto.visual.roompark.data.repository.db.requrey.model.FeedEntity
import
com.biganto.visual.roompark.data.repository.db.requrey.model.UserEntity
import
io.reactivex.Observable
import
io.reactivex.Single
import
io.requery.Persistable
/**
* Created by Vladislav Bogdashkin on 29.10.2019.
*/
interface
IDb
{
fun
upsertUser
(
entity
:
UserEntity
):
Observable
<
UserEntity
>?
fun
<
T
:
Persistable
>
upsert
(
entity
:
T
):
Single
<
T
>
fun
<
T
:
List
<
Persistable
>
>
upsert
(
entity
:
T
):
Single
<
Iterable
<
Persistable
>>
fun
fetchFeeds
():
Observable
<
FeedEntity
>
fun
fetchUser
(
uuid
:
Int
):
Observable
<
UserEntity
>
fun
<
T
:
List
<
Persistable
>
>
blockingUpsert
(
entity
:
T
)
}
\ No newline at end of file
app/src/main/java/com/biganto/visual/roompark/data/repository/db/requrey/RequeryRepository.kt
View file @
5809bb86
...
...
@@ -2,11 +2,14 @@ package com.biganto.visual.roompark.data.repository.db.requrey
import
android.content.Context
import
com.biganto.visual.roompark.data.repository.db.IDb
import
com.biganto.visual.roompark.data.repository.db.requrey.model.FeedEntity
import
com.biganto.visual.roompark.data.repository.db.requrey.model.Models
import
com.biganto.visual.roompark.data.repository.db.requrey.model.UserEntity
import
com.biganto.visual.roompark.di.dagger.DATABASE_VERSION
import
dagger.Module
import
dagger.Provides
import
io.reactivex.Observable
import
io.reactivex.Single
import
io.requery.Persistable
import
io.requery.android.sqlite.DatabaseSource
import
io.requery.reactivex.KotlinReactiveEntityStore
...
...
@@ -40,6 +43,29 @@ class RequeryRepository @Inject constructor(
)
:
IDb
{
override
fun
upsertUser
(
entity
:
UserEntity
)
=
store
.
upsert
(
entity
).
toObservable
()
private
inline
fun
<
reified
T
:
Persistable
>
fetchAll
()
=
store
.
select
(
T
::
class
)
override
fun
upsertUser
(
entity
:
UserEntity
):
Observable
<
UserEntity
>
=
store
.
upsert
(
entity
).
toObservable
()
override
fun
<
T
:
Persistable
>
upsert
(
entity
:
T
)
=
store
.
upsert
(
entity
)
override
fun
<
T
:
List
<
Persistable
>
>
upsert
(
entity
:
T
):
Single
<
Iterable
<
Persistable
>>
=
store
.
upsert
(
entity
)
override
fun
<
T
:
List
<
Persistable
>
>
blockingUpsert
(
entity
:
T
)
=
store
.
upsert
(
entity
).
toObservable
().
blockingSubscribe
()
override
fun
fetchFeeds
():
Observable
<
FeedEntity
>
=
fetchAll
<
FeedEntity
>().
get
().
observable
()
override
fun
fetchUser
(
uuid
:
Int
):
Observable
<
UserEntity
>
=
fetchAll
<
UserEntity
>().
where
(
UserEntity
.
UUID
.
eq
(
uuid
)).
get
().
observable
()
fun
upsertFeeds
(
entity
:
List
<
FeedEntity
>)
=
store
.
upsert
(
entity
)
}
\ No newline at end of file
app/src/main/java/com/biganto/visual/roompark/data/repository/mapper/raw2entity.kt
View file @
5809bb86
...
...
@@ -2,6 +2,8 @@ package com.biganto.visual.roompark.data.repository.mapper
import
android.content.res.Resources
import
com.biganto.visual.roompark.data.repository.api.retrofit.raw.AuthRaw
import
com.biganto.visual.roompark.data.repository.api.retrofit.raw.FeedRaw
import
com.biganto.visual.roompark.data.repository.db.requrey.model.FeedEntity
import
com.biganto.visual.roompark.data.repository.db.requrey.model.UserEntity
import
kotlin.math.max
...
...
@@ -21,4 +23,16 @@ fun fromRaw(raw: AuthRaw) : UserEntity {
return
user
}
fun
fromRaw
(
raw
:
FeedRaw
)
:
FeedEntity
{
val
entity
=
FeedEntity
()
entity
.
setId
(
raw
.
id
)
entity
.
setTitle
(
raw
.
title
)
entity
.
setAlias
(
raw
.
alias
)
return
entity
}
fun
fromRaw
(
raw
:
List
<
FeedRaw
>):
List
<
FeedEntity
>
=
List
(
raw
.
size
)
{
index
->
fromRaw
(
raw
[
index
])
}
val
calcTargetResolution
=
max
(
display
.
widthPixels
,
display
.
heightPixels
)
app/src/main/java/com/biganto/visual/roompark/di/dagger/ContextModule.kt
View file @
5809bb86
...
...
@@ -43,32 +43,3 @@ abstract class AppModule{
}
class
AuthContractModule
@Inject
constructor
(
private
val
local
:
ILocalStore
,
private
val
api
:
IRoomParkApi
,
private
val
db
:
IDb
):
AuthContract
{
init
{
Timber
.
d
(
"Auth Repository Created"
)
}
override
fun
signOut
():
Completable
=
local
.
setRecentUser
(
null
)
override
fun
signIn
(
email
:
String
,
password
:
String
):
Observable
<
AuthInfoModel
>
=
api
.
authenticate
(
email
,
password
)
.
map
(
::
fromRaw
)
.
flatMap
{
db
.
upsertUser
(
it
)
}
.
doOnNext
{
Timber
.
d
(
"user id: ${it.uuid}"
)}
.
doOnNext
{
local
.
setRecentUser
(
it
.
uuid
.
toString
()).
blockingAwait
()
}
.
map
(
::
fromEntity
)
override
fun
validateAuthState
():
Observable
<
Boolean
>
=
local
.
recentUser
()
.
map
{
when
(
it
){
is
UserState
.
NotAuthenticated
->
false
is
UserState
.
Authenticated
->
true
else
->
false
}
}
}
app/src/main/java/com/biganto/visual/roompark/domain/contract/FeedsContract.kt
View file @
5809bb86
...
...
@@ -2,8 +2,8 @@ package com.biganto.visual.roompark.domain.contract
import
com.biganto.visual.roompark.domain.model.ArticlesPreviewModel
import
com.biganto.visual.roompark.domain.model.FeedsHeaderModel
import
io.reactivex.
rxjava3.core.
Observable
import
io.reactivex.
rxjava3.core.
Single
import
io.reactivex.Observable
import
io.reactivex.Single
/**
* Created by Vladislav Bogdashkin on 24.09.2019.
...
...
app/src/main/java/com/biganto/visual/roompark/domain/model/feeds.kt
View file @
5809bb86
package
com.biganto.visual.roompark.domain.model
import
com.biganto.visual.roompark.data.repository.db.requrey.model.FeedEntity
import
java.util.*
/**
...
...
@@ -31,3 +32,11 @@ data class ArticleModel(
val
previewUrl
:
String
,
val
isRead
:
Boolean
)
fun
fromEntity2
(
entity
:
FeedEntity
):
FeedModel
=
FeedModel
(
feedId
=
entity
.
id
,
title
=
entity
.
title
,
alias
=
entity
.
alias
)
fun
<
E
,
M
>
fromEntity
(
raw
:
List
<
E
>,
block
:(
E
)->
M
):
List
<
M
>
=
List
(
raw
.
size
)
{
index
->
block
(
raw
[
index
])
}
app/src/main/java/com/biganto/visual/roompark/presentation/screen/auth/ScreenDI.kt
View file @
5809bb86
...
...
@@ -3,9 +3,13 @@ package com.biganto.visual.roompark.presentation.screen.auth
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
dagger.Binds
import
dagger.BindsInstance
...
...
@@ -15,7 +19,12 @@ import dagger.Module
@PerScreen
@Component
(
modules
=
[
AuthScreenModule
::
class
,
DataModule
::
class
,
RetrofitModule
::
class
,
AppModule
::
class
,
DbModule
::
class
modules
=
[
AuthScreenModule
::
class
,
DataModule
::
class
,
RetrofitModule
::
class
,
AppModule
::
class
,
DbModule
::
class
],
dependencies
=
[
AppComponent
::
class
])
interface
AuthScreenComponent
{
...
...
app/src/main/java/com/biganto/visual/roompark/presentation/screen/settings/ScreenDI.kt
View file @
5809bb86
...
...
@@ -2,9 +2,13 @@ package com.biganto.visual.roompark.presentation.screen.settings
import
android.content.Context
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
dagger.Binds
import
dagger.BindsInstance
...
...
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