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
6ca8c416
Commit
6ca8c416
authored
Mar 25, 2020
by
Vladislav Bogdashkin
🎣
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
subscription contract;
import rxKotlin
parent
1fa0544c
Changes
11
Hide whitespace changes
Inline
Side-by-side
Showing
11 changed files
with
138 additions
and
33 deletions
+138
-33
build.gradle
app/build.gradle
+4
-1
AuthRepository.kt
...anto/visual/roompark/data/data_provider/AuthRepository.kt
+10
-0
SubscriptionRepository.kt
...ual/roompark/data/data_provider/SubscriptionRepository.kt
+71
-0
IDb.kt
...ava/com/biganto/visual/roompark/data/repository/db/IDb.kt
+2
-0
RequeryRepository.kt
.../roompark/data/repository/db/requrey/RequeryRepository.kt
+9
-1
Subscription.kt
...roompark/data/repository/db/requrey/model/Subscription.kt
+3
-2
User.kt
.../visual/roompark/data/repository/db/requrey/model/User.kt
+5
-0
AuthContract.kt
...m/biganto/visual/roompark/domain/contract/AuthContract.kt
+2
-0
Subscribtions.kt
.../biganto/visual/roompark/domain/contract/Subscribtions.kt
+15
-10
subscriptionUseCase.kt
...to/visual/roompark/domain/use_case/subscriptionUseCase.kt
+15
-19
dependencies.gradle
dependencies.gradle
+2
-0
No files found.
app/build.gradle
View file @
6ca8c416
...
...
@@ -165,7 +165,10 @@ dependencies {
implementation
"com.google.firebase:firebase-analytics:$fireBaseVersion"
//CrshLytics
implementation
'com.google.firebase:firebase-crashlytics:17.0.0-beta02'
implementation
"com.google.firebase:firebase-crashlytics:$firebaseCrashlyticsVersion"
//RxKotlin
implementation
(
"io.reactivex.rxjava2:rxkotlin:$rxKotlinVersion"
)
//Tests
testImplementation
'junit:junit:4.12'
...
...
app/src/main/java/com/biganto/visual/roompark/data/data_provider/AuthRepository.kt
View file @
6ca8c416
...
...
@@ -4,8 +4,10 @@ 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.db.requrey.model.UserEntity
import
com.biganto.visual.roompark.data.repository.mapper.fromRaw
import
com.biganto.visual.roompark.domain.contract.AuthContract
import
com.biganto.visual.roompark.domain.custom_exception.CustomApiException
import
com.biganto.visual.roompark.domain.model.AuthInfoModel
import
com.biganto.visual.roompark.domain.model.fromEntity
import
io.reactivex.Completable
...
...
@@ -46,4 +48,12 @@ class AuthContractModule @Inject constructor(
else
->
false
}
}
override
fun
currentUser
():
Observable
<
UserEntity
>
=
local
.
recentUser
()
.
flatMap
{
when
(
it
){
is
UserState
.
NotAuthenticated
->
throw
CustomApiException
.
NotAuthorizedException
()
is
UserState
.
Authenticated
->
db
.
fetchUser
(
it
.
uuid
.
toInt
())
else
->
throw
CustomApiException
.
NotAuthorizedException
()
}
}
}
app/src/main/java/com/biganto/visual/roompark/data/data_provider/SubscriptionRepository.kt
0 → 100644
View file @
6ca8c416
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.db.requrey.model.SubscriptionEntity
import
com.biganto.visual.roompark.data.repository.db.requrey.model.UserEntity
import
com.biganto.visual.roompark.domain.contract.SubscriptionContract
import
io.reactivex.Completable
import
javax.inject.Inject
/**
* Created by Vladislav Bogdashkin on 25.03.2020.
*/
private
const
val
SUBSCRIPTION_RESULT_STATUS
=
"OK"
class
SubscriptionRepository
@Inject
constructor
(
private
val
api
:
IRoomParkApi
,
private
val
db
:
IDb
):
SubscriptionContract
{
private
fun
saveSubscribeState
(
userEntity
:
UserEntity
,
subInnerId
:
Int
,
topic
:
String
,
topic_id
:
String
?,
nuewState
:
Boolean
):
Completable
{
var
sub
=
userEntity
.
subscriptions
?.
firstOrNull
{
sub
->
sub
.
id
==
subInnerId
}
if
(
sub
==
null
)
{
sub
=
SubscriptionEntity
()
sub
.
setOwner
(
userEntity
)
sub
.
setTopic
(
topic
)
sub
.
setNumber
(
topic_id
)
}
(
sub
as
SubscriptionEntity
).
setState
(
nuewState
)
return
db
.
saveSubscription
(
sub
).
ignoreElement
()
}
override
fun
subscribeTopic
(
user
:
UserEntity
,
subInnerId
:
Int
,
deviceToken
:
String
,
topic
:
String
,
topic_id
:
String
?
):
Completable
=
api
.
subscribeTopic
(
deviceToken
=
deviceToken
,
topicName
=
topic
,
userToken
=
user
.
authToken
)
.
switchMapCompletable
{
if
(
it
.
status
==
SUBSCRIPTION_RESULT_STATUS
){
saveSubscribeState
(
user
,
subInnerId
,
topic
,
topic_id
,
true
)
}
else
error
(
"Error subscription state!"
)
}
override
fun
unSubscribeTopic
(
user
:
UserEntity
,
subInnerId
:
Int
,
deviceToken
:
String
,
topic
:
String
,
topic_id
:
String
?
):
Completable
=
api
.
unSuubscribeTopic
(
deviceToken
=
deviceToken
,
topicName
=
topic
,
userToken
=
user
.
authToken
)
.
switchMapCompletable
{
if
(
it
.
status
==
SUBSCRIPTION_RESULT_STATUS
){
saveSubscribeState
(
user
,
subInnerId
,
topic
,
topic_id
,
false
)
}
else
error
(
"Error subscription state!"
)
}
}
\ No newline at end of file
app/src/main/java/com/biganto/visual/roompark/data/repository/db/IDb.kt
View file @
6ca8c416
...
...
@@ -34,4 +34,6 @@ interface IDb {
fun
fetchEstateByNumber
(
building
:
Int
,
number
:
String
):
ReactiveResult
<
EstateEntity
>
fun
setArticleReadState
(
id
:
Int
,
state
:
Boolean
):
Completable
fun
setDealReadState
(
id
:
String
,
state
:
Boolean
):
Completable
fun
saveSubscription
(
subscription
:
SubscriptionEntity
):
Single
<
SubscriptionEntity
>
fun
getSubscription
(
id
:
Int
):
ReactiveResult
<
SubscriptionEntity
>
}
\ No newline at end of file
app/src/main/java/com/biganto/visual/roompark/data/repository/db/requrey/RequeryRepository.kt
View file @
6ca8c416
...
...
@@ -147,7 +147,7 @@ class RequeryRepository @Inject constructor(
fun
upsertFeeds
(
entity
:
List
<
FeedEntity
>)
=
store
.
upsert
(
entity
)
override
fun
userObservableResult
(
uuid
:
Int
)
=
override
fun
userObservableResult
(
uuid
:
Int
)
:
Observable
<
ReactiveResult
<
UserEntity
>>
=
store
.
select
(
UserEntity
::
class
)
.
where
(
UserEntity
.
UUID
.
eq
(
uuid
))
.
get
()
...
...
@@ -175,4 +175,12 @@ class RequeryRepository @Inject constructor(
.
get
()
.
single
()
.
ignoreElement
()
override
fun
saveSubscription
(
subscription
:
SubscriptionEntity
)
=
store
.
upsert
(
subscription
)
override
fun
getSubscription
(
id
:
Int
):
ReactiveResult
<
SubscriptionEntity
>
=
store
.
select
(
SubscriptionEntity
::
class
)
.
where
(
SubscriptionEntity
.
ID
.
eq
(
id
))
.
get
()
}
app/src/main/java/com/biganto/visual/roompark/data/repository/db/requrey/model/Subscription.kt
View file @
6ca8c416
...
...
@@ -15,8 +15,9 @@ interface Subscription : Persistable {
@get
:
ForeignKey
(
references
=
User
::
class
,
referencedColumn
=
"uuid"
)
@get
:
ManyToOne
val
owner
:
User
val
deviceToken
:
String
val
topic
:
String
val
number
:
String
@get
:
Nullable
val
number
:
String
?
//estateId or smth same, depends on subscription case
val
state
:
Boolean
}
\ No newline at end of file
app/src/main/java/com/biganto/visual/roompark/data/repository/db/requrey/model/User.kt
View file @
6ca8c416
...
...
@@ -24,5 +24,10 @@ interface User : Persistable {
@get
:
Nullable
@get
:
OneToMany
(
cascade
=
[
CascadeAction
.
DELETE
])
val
deals
:
List
<
Deal
>?
@get
:
Nullable
@get
:
OneToMany
(
cascade
=
[
CascadeAction
.
DELETE
])
val
subscriptions
:
List
<
Subscription
>?
}
app/src/main/java/com/biganto/visual/roompark/domain/contract/AuthContract.kt
View file @
6ca8c416
package
com.biganto.visual.roompark.domain.contract
import
com.biganto.visual.roompark.data.repository.db.requrey.model.UserEntity
import
com.biganto.visual.roompark.domain.model.AuthInfoModel
import
io.reactivex.Completable
import
io.reactivex.Observable
...
...
@@ -12,4 +13,5 @@ interface AuthContract {
fun
signIn
(
email
:
String
,
password
:
String
)
:
Observable
<
AuthInfoModel
>
fun
signOut
()
:
Completable
fun
validateAuthState
():
Observable
<
Boolean
>
fun
currentUser
():
Observable
<
UserEntity
>
}
\ No newline at end of file
app/src/main/java/com/biganto/visual/roompark/domain/contract/Subscribtions.kt
View file @
6ca8c416
package
com.biganto.visual.roompark.domain.contract
import
com.biganto.visual.roompark.data.repository.
api.retrofit.raw.StatusResponse
import
io.reactivex.
Observ
able
import
com.biganto.visual.roompark.data.repository.
db.requrey.model.UserEntity
import
io.reactivex.
Complet
able
/**
* Created by Vladislav Bogdashkin on 24.09.2019.
*/
interface
SubscriptionContract
{
fun
subscribeTopic
(
deviceToken
:
String
,
topic
:
String
,
topic_id
:
String
?
=
null
)
:
Observable
<
StatusResponse
>
user
:
UserEntity
,
subInnerId
:
Int
,
deviceToken
:
String
,
topic
:
String
,
topic_id
:
String
?
):
Completable
fun
unSubscribeTopic
(
deviceToken
:
String
,
topic
:
String
,
topic_id
:
String
?
=
null
)
:
Observable
<
StatusResponse
>
user
:
UserEntity
,
subInnerId
:
Int
,
deviceToken
:
String
,
topic
:
String
,
topic_id
:
String
?
):
Completable
}
\ No newline at end of file
app/src/main/java/com/biganto/visual/roompark/domain/use_case/subscriptionUseCase.kt
View file @
6ca8c416
package
com.biganto.visual.roompark.domain.use_case
//import io.reactivex.Observable
import
com.biganto.visual.roompark.domain.contract.AuthContract
import
com.biganto.visual.roompark.domain.contract.DeviceUtilsContract
import
com.biganto.visual.roompark.domain.contract.SubscriptionContract
import
io.reactivex.rxkotlin.Observables
import
javax.inject.Inject
//import io.reactivex.rxkotlin
/**
* Created by Vladislav Bogdashkin on 01.11.2019.
...
...
@@ -10,25 +14,17 @@ import javax.inject.Inject
class
SubscriptionUseCase
@Inject
constructor
(
private
val
subscription
:
SubscriptionContract
,
private
val
utils
:
DeviceUtilsContract
private
val
utils
:
DeviceUtilsContract
,
private
val
auth
:
AuthContract
){
fun
subscribeTopic
(
topic
:
String
,
topicId
:
String
?=
null
)
=
utils
.
getDeviceId
()
.
flatMap
{
deviceToken
->
subscription
.
subscribeTopic
(
deviceToken
,
topic
,
topicId
)
}
fun
unSubscribeTopic
(
topic
:
String
,
topicId
:
String
?=
null
)
=
utils
.
getDeviceId
()
.
flatMap
{
deviceToken
->
subscription
.
unSubscribeTopic
(
deviceToken
,
topic
,
topicId
)
}
fun
subscribeTopic
(
subId
:
Int
,
topic
:
String
,
topicId
:
String
?=
null
)
=
Observables
.
zip
(
auth
.
currentUser
(),
utils
.
getDeviceId
()){
u
,
t
->
subscription
.
subscribeTopic
(
u
,
subId
,
t
,
topic
=
topic
,
topic_id
=
topicId
)
}
fun
unSubscribeTopic
(
subId
:
Int
,
topic
:
String
,
topicId
:
String
?=
null
)
=
Observables
.
zip
(
auth
.
currentUser
(),
utils
.
getDeviceId
()){
u
,
t
->
subscription
.
subscribeTopic
(
u
,
subId
,
t
,
topic
=
topic
,
topic_id
=
topicId
)
}
}
\ No newline at end of file
dependencies.gradle
View file @
6ca8c416
...
...
@@ -28,4 +28,6 @@ ext {
viewPager2Version
=
"1.0.0"
glideVersion
=
"4.11.0"
fireBaseVersion
=
"17.2.3"
firebaseCrashlyticsVersion
=
"17.0.0-beta02"
rxKotlinVersion
=
"2.4.0"
}
\ No newline at end of file
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