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
ac3cacd0
Commit
ac3cacd0
authored
Mar 26, 2020
by
Vladislav Bogdashkin
🎣
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
subscription model
parent
c6514013
Changes
4
Show whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
111 additions
and
76 deletions
+111
-76
article.kt
.../com/biganto/visual/roompark/domain/interactor/article.kt
+1
-0
articles.kt
...com/biganto/visual/roompark/domain/interactor/articles.kt
+15
-1
subscription.kt
.../com/biganto/visual/roompark/domain/model/subscription.kt
+62
-0
subscriptionUseCase.kt
...to/visual/roompark/domain/use_case/subscriptionUseCase.kt
+33
-75
No files found.
app/src/main/java/com/biganto/visual/roompark/domain/interactor/article.kt
View file @
ac3cacd0
...
@@ -2,6 +2,7 @@ package com.biganto.visual.roompark.domain.interactor
...
@@ -2,6 +2,7 @@ package com.biganto.visual.roompark.domain.interactor
import
com.biganto.visual.roompark.domain.model.ArticleModel
import
com.biganto.visual.roompark.domain.model.ArticleModel
import
com.biganto.visual.roompark.domain.use_case.FeedUseCase
import
com.biganto.visual.roompark.domain.use_case.FeedUseCase
import
com.biganto.visual.roompark.domain.use_case.SubscriptionUseCase
import
io.reactivex.Observable
import
io.reactivex.Observable
import
java.util.*
import
java.util.*
import
javax.inject.Inject
import
javax.inject.Inject
...
...
app/src/main/java/com/biganto/visual/roompark/domain/interactor/articles.kt
View file @
ac3cacd0
package
com.biganto.visual.roompark.domain.interactor
package
com.biganto.visual.roompark.domain.interactor
import
com.biganto.visual.roompark.domain.use_case.FeedUseCase
import
com.biganto.visual.roompark.domain.use_case.FeedUseCase
import
com.biganto.visual.roompark.domain.use_case.SubscriptionTopic
import
com.biganto.visual.roompark.domain.use_case.SubscriptionUseCase
import
javax.inject.Inject
import
javax.inject.Inject
/**
/**
...
@@ -8,7 +10,8 @@ import javax.inject.Inject
...
@@ -8,7 +10,8 @@ import javax.inject.Inject
*/
*/
class
ArticlesInteractor
@Inject
constructor
(
class
ArticlesInteractor
@Inject
constructor
(
private
val
uc
:
FeedUseCase
private
val
uc
:
FeedUseCase
,
private
val
subUc
:
SubscriptionUseCase
)
{
)
{
fun
fetchArticles
(
feed
:
String
)
=
fun
fetchArticles
(
feed
:
String
)
=
...
@@ -17,6 +20,17 @@ class ArticlesInteractor @Inject constructor(
...
@@ -17,6 +20,17 @@ class ArticlesInteractor @Inject constructor(
fun
fetchArticlesPage
(
feed
:
String
,
pageSize
:
Int
,
current
:
Int
)
=
fun
fetchArticlesPage
(
feed
:
String
,
pageSize
:
Int
,
current
:
Int
)
=
uc
.
fetchArticlesPage
(
feed
,
pageSize
,
current
)
uc
.
fetchArticlesPage
(
feed
,
pageSize
,
current
)
fun
getSubscriptions
(
feed
:
String
)
=
subUc
.
getSubscriptions
(
feedSubType
(
feed
))
private
fun
feedSubType
(
feed
:
String
)
=
when
(
feed
){
"news"
->
SubscriptionTopic
.
News
()
"blog"
->
SubscriptionTopic
.
Blog
()
"construction-blog"
->
SubscriptionTopic
.
Construction
()
else
->
error
(
"Unknown feed type"
)
}
}
}
...
...
app/src/main/java/com/biganto/visual/roompark/domain/model/subscription.kt
0 → 100644
View file @
ac3cacd0
package
com.biganto.visual.roompark.domain.model
import
com.biganto.visual.roompark.data.repository.db.requrey.model.SubscriptionEntity
/**
* Created by Vladislav Bogdashkin on 26.03.2020.
*/
data class
SubscriptionModel
(
val
topic
:
SubscriptionTopic
,
val
id
:
Int
,
val
state
:
Boolean
)
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
topicFromEntity
(
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
()
else
->
error
(
"Unknown subscription type!"
)
}
fun
fromEntity
(
sub
:
SubscriptionEntity
):
SubscriptionModel
=
SubscriptionModel
(
topicFromEntity
(
sub
),
sub
.
id
,
sub
.
state
)
app/src/main/java/com/biganto/visual/roompark/domain/use_case/subscriptionUseCase.kt
View file @
ac3cacd0
...
@@ -5,6 +5,10 @@ import com.biganto.visual.roompark.data.repository.db.requrey.model.Subscription
...
@@ -5,6 +5,10 @@ import com.biganto.visual.roompark.data.repository.db.requrey.model.Subscription
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
import
com.biganto.visual.roompark.domain.model.SubscriptionModel
import
com.biganto.visual.roompark.domain.model.SubscriptionTopic
import
com.biganto.visual.roompark.domain.model.fromEntity
import
io.reactivex.Observable
import
io.reactivex.rxkotlin.Observables
import
io.reactivex.rxkotlin.Observables
import
javax.inject.Inject
import
javax.inject.Inject
//import io.reactivex.rxkotlin
//import io.reactivex.rxkotlin
...
@@ -17,31 +21,34 @@ class SubscriptionUseCase @Inject constructor(
...
@@ -17,31 +21,34 @@ class SubscriptionUseCase @Inject constructor(
private
val
subscription
:
SubscriptionContract
,
private
val
subscription
:
SubscriptionContract
,
private
val
utils
:
DeviceUtilsContract
,
private
val
utils
:
DeviceUtilsContract
,
private
val
auth
:
AuthContract
private
val
auth
:
AuthContract
){
)
{
fun
subscribeTopic
(
subId
:
Int
,
topic
:
SubscriptionTopic
)
=
fun
subscribeTopic
(
subId
:
Int
,
topic
:
SubscriptionTopic
)
=
Observables
.
zip
(
auth
.
currentUser
(),
utils
.
getDeviceId
())
{
user
,
token
->
Observables
.
zip
(
auth
.
currentUser
(),
utils
.
getDeviceId
())
{
user
,
token
->
subscription
.
subscribeTopic
(
subscription
.
subscribeTopic
(
user
user
,
subId
,
subId
,
token
,
token
,
topic
=
topic
.
topicName
,
,
topic
=
topic
.
topicName
,
topic_id
=
topic
.
topicId
topic_id
=
topic
.
topicId
)
)
}
}
fun
unSubscribeTopic
(
subId
:
Int
,
topic
:
SubscriptionTopic
)
=
fun
unSubscribeTopic
(
subId
:
Int
,
topic
:
SubscriptionTopic
)
=
Observables
.
zip
(
auth
.
currentUser
(),
utils
.
getDeviceId
()){
user
,
token
->
Observables
.
zip
(
auth
.
currentUser
(),
utils
.
getDeviceId
())
{
user
,
token
->
subscription
.
unSubscribeTopic
(
user
subscription
.
unSubscribeTopic
(
,
subId
user
,
token
,
subId
,
topic
=
topic
.
topicName
,
,
token
topic_id
=
topic
.
topicId
)
,
topic
=
topic
.
topicName
,
topic_id
=
topic
.
topicId
)
}
}
fun
getSubscriptions
(
topic
:
SubscriptionTopic
)
=
auth
.
currentUser
()
fun
getSubscriptions
(
topic
:
SubscriptionTopic
):
Observable
<
SubscriptionModel
>
=
auth
.
currentUser
()
.
map
{
.
map
{
var
sub
=
it
.
subscriptions
var
sub
=
it
.
subscriptions
?.
firstOrNull
{
it
.
topic
==
topic
.
topicName
&&
it
.
number
==
topic
.
topicId
}
?.
firstOrNull
{
it
.
topic
==
topic
.
topicName
&&
it
.
number
==
topic
.
topicId
}
if
(
sub
==
null
)
{
if
(
sub
==
null
)
{
sub
=
SubscriptionEntity
()
sub
=
SubscriptionEntity
()
sub
.
setOwner
(
it
)
sub
.
setOwner
(
it
)
...
@@ -51,59 +58,10 @@ class SubscriptionUseCase @Inject constructor(
...
@@ -51,59 +58,10 @@ class SubscriptionUseCase @Inject constructor(
}
}
subscription
.
saveSubscribeState
(
sub
as
SubscriptionEntity
).
blockingFirst
()
subscription
.
saveSubscribeState
(
sub
as
SubscriptionEntity
).
blockingFirst
()
}
}
.
map
(
::
fromEntity
)
// 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