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
c6514013
Commit
c6514013
authored
Mar 26, 2020
by
Vladislav Bogdashkin
🎣
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
subscriptions fetching and inittializing by default
parent
6ca8c416
Changes
4
Show whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
123 additions
and
14 deletions
+123
-14
SubscriptionRepository.kt
...ual/roompark/data/data_provider/SubscriptionRepository.kt
+24
-7
RequeryRepository.kt
.../roompark/data/repository/db/requrey/RequeryRepository.kt
+1
-0
Subscribtions.kt
.../biganto/visual/roompark/domain/contract/Subscribtions.kt
+12
-0
subscriptionUseCase.kt
...to/visual/roompark/domain/use_case/subscriptionUseCase.kt
+86
-7
No files found.
app/src/main/java/com/biganto/visual/roompark/data/data_provider/SubscriptionRepository.kt
View file @
c6514013
...
@@ -6,6 +6,7 @@ import com.biganto.visual.roompark.data.repository.db.requrey.model.Subscription
...
@@ -6,6 +6,7 @@ import com.biganto.visual.roompark.data.repository.db.requrey.model.Subscription
import
com.biganto.visual.roompark.data.repository.db.requrey.model.UserEntity
import
com.biganto.visual.roompark.data.repository.db.requrey.model.UserEntity
import
com.biganto.visual.roompark.domain.contract.SubscriptionContract
import
com.biganto.visual.roompark.domain.contract.SubscriptionContract
import
io.reactivex.Completable
import
io.reactivex.Completable
import
io.reactivex.Observable
import
javax.inject.Inject
import
javax.inject.Inject
/**
/**
...
@@ -19,14 +20,27 @@ class SubscriptionRepository @Inject constructor(
...
@@ -19,14 +20,27 @@ class SubscriptionRepository @Inject constructor(
private
val
db
:
IDb
private
val
db
:
IDb
):
SubscriptionContract
{
):
SubscriptionContract
{
private
fun
saveSubscribeState
(
override
fun
saveSubscribeState
(
sub
:
SubscriptionEntity
):
Observable
<
SubscriptionEntity
>
{
return
saveSubscribeState
(
sub
.
owner
as
UserEntity
,
sub
.
id
,
sub
.
topic
,
sub
.
number
,
sub
.
state
)
}
override
fun
saveSubscribeState
(
userEntity
:
UserEntity
,
userEntity
:
UserEntity
,
subInnerId
:
Int
,
subInnerId
:
Int
?
,
topic
:
String
,
topic
:
String
,
topic_id
:
String
?,
topic_id
:
String
?,
nuewState
:
Boolean
nuewState
:
Boolean
):
Completable
{
):
Observable
<
SubscriptionEntity
>
{
var
sub
=
userEntity
.
subscriptions
?.
firstOrNull
{
sub
->
sub
.
id
==
subInnerId
}
var
sub
=
subInnerId
?.
let
{
id
->
userEntity
.
subscriptions
?.
firstOrNull
{
sub
->
sub
.
id
==
id
}
}
if
(
sub
==
null
)
{
if
(
sub
==
null
)
{
sub
=
SubscriptionEntity
()
sub
=
SubscriptionEntity
()
sub
.
setOwner
(
userEntity
)
sub
.
setOwner
(
userEntity
)
...
@@ -35,7 +49,7 @@ class SubscriptionRepository @Inject constructor(
...
@@ -35,7 +49,7 @@ class SubscriptionRepository @Inject constructor(
}
}
(
sub
as
SubscriptionEntity
).
setState
(
nuewState
)
(
sub
as
SubscriptionEntity
).
setState
(
nuewState
)
return
db
.
saveSubscription
(
sub
).
ignoreElement
()
return
db
.
saveSubscription
(
sub
).
toObservable
()
}
}
override
fun
subscribeTopic
(
override
fun
subscribeTopic
(
...
@@ -47,7 +61,7 @@ class SubscriptionRepository @Inject constructor(
...
@@ -47,7 +61,7 @@ class SubscriptionRepository @Inject constructor(
):
Completable
=
api
.
subscribeTopic
(
deviceToken
=
deviceToken
,
topicName
=
topic
,
userToken
=
user
.
authToken
)
):
Completable
=
api
.
subscribeTopic
(
deviceToken
=
deviceToken
,
topicName
=
topic
,
userToken
=
user
.
authToken
)
.
switchMapCompletable
{
.
switchMapCompletable
{
if
(
it
.
status
==
SUBSCRIPTION_RESULT_STATUS
){
if
(
it
.
status
==
SUBSCRIPTION_RESULT_STATUS
){
saveSubscribeState
(
user
,
subInnerId
,
topic
,
topic_id
,
true
)
saveSubscribeState
(
user
,
subInnerId
,
topic
,
topic_id
,
true
)
.
ignoreElements
()
}
}
else
error
(
"Error subscription state!"
)
else
error
(
"Error subscription state!"
)
}
}
...
@@ -63,9 +77,12 @@ class SubscriptionRepository @Inject constructor(
...
@@ -63,9 +77,12 @@ class SubscriptionRepository @Inject constructor(
api
.
unSuubscribeTopic
(
deviceToken
=
deviceToken
,
topicName
=
topic
,
userToken
=
user
.
authToken
)
api
.
unSuubscribeTopic
(
deviceToken
=
deviceToken
,
topicName
=
topic
,
userToken
=
user
.
authToken
)
.
switchMapCompletable
{
.
switchMapCompletable
{
if
(
it
.
status
==
SUBSCRIPTION_RESULT_STATUS
){
if
(
it
.
status
==
SUBSCRIPTION_RESULT_STATUS
){
saveSubscribeState
(
user
,
subInnerId
,
topic
,
topic_id
,
false
)
saveSubscribeState
(
user
,
subInnerId
,
topic
,
topic_id
,
false
)
.
ignoreElements
()
}
}
else
error
(
"Error subscription state!"
)
else
error
(
"Error subscription state!"
)
}
}
}
}
\ No newline at end of file
app/src/main/java/com/biganto/visual/roompark/data/repository/db/requrey/RequeryRepository.kt
View file @
c6514013
...
@@ -183,4 +183,5 @@ class RequeryRepository @Inject constructor(
...
@@ -183,4 +183,5 @@ class RequeryRepository @Inject constructor(
store
.
select
(
SubscriptionEntity
::
class
)
store
.
select
(
SubscriptionEntity
::
class
)
.
where
(
SubscriptionEntity
.
ID
.
eq
(
id
))
.
where
(
SubscriptionEntity
.
ID
.
eq
(
id
))
.
get
()
.
get
()
}
}
app/src/main/java/com/biganto/visual/roompark/domain/contract/Subscribtions.kt
View file @
c6514013
package
com.biganto.visual.roompark.domain.contract
package
com.biganto.visual.roompark.domain.contract
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.data.repository.db.requrey.model.UserEntity
import
io.reactivex.Completable
import
io.reactivex.Completable
import
io.reactivex.Observable
/**
/**
* Created by Vladislav Bogdashkin on 24.09.2019.
* Created by Vladislav Bogdashkin on 24.09.2019.
...
@@ -24,4 +26,14 @@ interface SubscriptionContract{
...
@@ -24,4 +26,14 @@ interface SubscriptionContract{
topic
:
String
,
topic
:
String
,
topic_id
:
String
?
topic_id
:
String
?
):
Completable
):
Completable
fun
saveSubscribeState
(
userEntity
:
UserEntity
,
subInnerId
:
Int
?,
topic
:
String
,
topic_id
:
String
?,
nuewState
:
Boolean
):
Observable
<
SubscriptionEntity
>
fun
saveSubscribeState
(
sub
:
SubscriptionEntity
):
Observable
<
SubscriptionEntity
>
}
}
\ No newline at end of file
app/src/main/java/com/biganto/visual/roompark/domain/use_case/subscriptionUseCase.kt
View file @
c6514013
package
com.biganto.visual.roompark.domain.use_case
package
com.biganto.visual.roompark.domain.use_case
//import io.reactivex.Observable
//import io.reactivex.Observable
import
com.biganto.visual.roompark.data.repository.db.requrey.model.SubscriptionEntity
import
com.biganto.visual.roompark.domain.contract.AuthContract
import
com.biganto.visual.roompark.domain.contract.AuthContract
import
com.biganto.visual.roompark.domain.contract.DeviceUtilsContract
import
com.biganto.visual.roompark.domain.contract.DeviceUtilsContract
import
com.biganto.visual.roompark.domain.contract.SubscriptionContract
import
com.biganto.visual.roompark.domain.contract.SubscriptionContract
...
@@ -17,14 +18,92 @@ class SubscriptionUseCase @Inject constructor(
...
@@ -17,14 +18,92 @@ class SubscriptionUseCase @Inject constructor(
private
val
utils
:
DeviceUtilsContract
,
private
val
utils
:
DeviceUtilsContract
,
private
val
auth
:
AuthContract
private
val
auth
:
AuthContract
){
){
fun
subscribeTopic
(
subId
:
Int
,
topic
:
String
,
topicId
:
String
?=
null
)
=
fun
subscribeTopic
(
subId
:
Int
,
topic
:
SubscriptionTopic
)
=
Observables
.
zip
(
auth
.
currentUser
(),
utils
.
getDeviceId
()){
u
,
t
->
Observables
.
zip
(
auth
.
currentUser
(),
utils
.
getDeviceId
()){
user
,
token
->
subscription
.
subscribeTopic
(
u
,
subId
,
t
,
topic
=
topic
,
topic_id
=
topicId
)
subscription
.
subscribeTopic
(
user
,
subId
,
token
,
topic
=
topic
.
topicName
,
topic_id
=
topic
.
topicId
)
}
}
fun
unSubscribeTopic
(
subId
:
Int
,
topic
:
String
,
topicId
:
String
?=
null
)
=
fun
unSubscribeTopic
(
subId
:
Int
,
topic
:
SubscriptionTopic
)
=
Observables
.
zip
(
auth
.
currentUser
(),
utils
.
getDeviceId
()){
u
,
t
->
Observables
.
zip
(
auth
.
currentUser
(),
utils
.
getDeviceId
()){
user
,
token
->
subscription
.
subscribeTopic
(
u
,
subId
,
t
,
topic
=
topic
,
topic_id
=
topicId
)
subscription
.
unSubscribeTopic
(
user
,
subId
,
token
,
topic
=
topic
.
topicName
,
topic_id
=
topic
.
topicId
)
}
}
fun
getSubscriptions
(
topic
:
SubscriptionTopic
)
=
auth
.
currentUser
()
.
map
{
var
sub
=
it
.
subscriptions
?.
firstOrNull
{
it
.
topic
==
topic
.
topicName
&&
it
.
number
==
topic
.
topicId
}
if
(
sub
==
null
)
{
sub
=
SubscriptionEntity
()
sub
.
setOwner
(
it
)
sub
.
setTopic
(
topic
.
topicName
)
sub
.
setNumber
(
topic
.
topicId
)
sub
.
setState
(
false
)
}
subscription
.
saveSubscribeState
(
sub
as
SubscriptionEntity
).
blockingFirst
()
}
// fun getSubscription()
}
sealed
class
SubscriptionTopic
(
val
topicName
:
String
,
val
topicId
:
String
?
=
null
)
{
class
Deals
(
topicName
:
String
=
TOPIC_API_NAME_DEALS
,
dealId
:
String
?)
:
SubscriptionTopic
(
topicName
,
dealId
)
class
Progress_1
(
topicName
:
String
=
TOPIC_API_NAME_PROGRESS_1
)
:
SubscriptionTopic
(
topicName
)
class
Progress_2
(
topicName
:
String
=
TOPIC_API_NAME_PROGRESS_2
)
:
SubscriptionTopic
(
topicName
)
class
Progress_3
(
topicName
:
String
=
TOPIC_API_NAME_PROGRESS_3
)
:
SubscriptionTopic
(
topicName
)
class
Progress_kindergarden
(
topicName
:
String
=
TOPIC_API_NAME_PROGRESS_KINDERGARDEN
)
:
SubscriptionTopic
(
topicName
)
class
Progress_school
(
topicName
:
String
=
TOPIC_API_NAME_PROGRESS_SCHOOL
)
:
SubscriptionTopic
(
topicName
)
class
Progress_landscaping
(
topicName
:
String
=
TOPIC_API_NAME_PROGRESS_LANDSCAPING
)
:
SubscriptionTopic
(
topicName
)
class
News
(
topicName
:
String
=
TOPIC_API_NAME_NEWS
)
:
SubscriptionTopic
(
topicName
)
class
Blog
(
topicName
:
String
=
TOPIC_API_NAME_BLOG
)
:
SubscriptionTopic
(
topicName
)
class
Construction
(
topicName
:
String
=
TOPIC_API_NAME_CONSCTRUCTION
)
:
SubscriptionTopic
(
topicName
)
}
}
private
const
val
TOPIC_API_NAME_DEALS
=
"deals"
private
const
val
TOPIC_API_NAME_PROGRESS_1
=
"progress-1"
private
const
val
TOPIC_API_NAME_PROGRESS_2
=
"progress-2"
private
const
val
TOPIC_API_NAME_PROGRESS_3
=
"progress-3"
private
const
val
TOPIC_API_NAME_PROGRESS_KINDERGARDEN
=
"progress-kindergarden"
private
const
val
TOPIC_API_NAME_PROGRESS_SCHOOL
=
"progress-school"
private
const
val
TOPIC_API_NAME_PROGRESS_LANDSCAPING
=
"progress-landscaping"
private
const
val
TOPIC_API_NAME_NEWS
=
"news"
private
const
val
TOPIC_API_NAME_BLOG
=
"blog"
private
const
val
TOPIC_API_NAME_CONSCTRUCTION
=
"construction-blog"
private
fun
fromEntity
(
sub
:
SubscriptionEntity
):
SubscriptionTopic
{
when
(
sub
.
topic
){
TOPIC_API_NAME_DEALS
->
SubscriptionTopic
.
Deals
(
dealId
=
sub
.
number
)
TOPIC_API_NAME_PROGRESS_1
->
SubscriptionTopic
.
Progress_1
()
TOPIC_API_NAME_PROGRESS_2
->
SubscriptionTopic
.
Progress_2
()
TOPIC_API_NAME_PROGRESS_3
->
SubscriptionTopic
.
Progress_3
()
TOPIC_API_NAME_PROGRESS_KINDERGARDEN
->
SubscriptionTopic
.
Progress_kindergarden
()
TOPIC_API_NAME_PROGRESS_SCHOOL
->
SubscriptionTopic
.
Progress_school
()
TOPIC_API_NAME_PROGRESS_LANDSCAPING
->
SubscriptionTopic
.
Progress_landscaping
()
TOPIC_API_NAME_NEWS
->
SubscriptionTopic
.
News
()
TOPIC_API_NAME_BLOG
->
SubscriptionTopic
.
Blog
()
TOPIC_API_NAME_CONSCTRUCTION
->
SubscriptionTopic
.
Construction
()
}
}
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