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
936097b5
Commit
936097b5
authored
Apr 28, 2020
by
Vladislav
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
subs move to titledsubs models;
fetch api and update states
parent
3d63a790
Changes
12
Hide whitespace changes
Inline
Side-by-side
Showing
12 changed files
with
151 additions
and
80 deletions
+151
-80
SubscriptionRepository.kt
...ual/roompark/data/data_provider/SubscriptionRepository.kt
+39
-3
Subscribtions.kt
.../biganto/visual/roompark/domain/contract/Subscribtions.kt
+16
-0
albums.kt
...a/com/biganto/visual/roompark/domain/interactor/albums.kt
+1
-2
articles.kt
...com/biganto/visual/roompark/domain/interactor/articles.kt
+1
-2
deal.kt
...ava/com/biganto/visual/roompark/domain/interactor/deal.kt
+1
-1
settings.kt
...com/biganto/visual/roompark/domain/interactor/settings.kt
+1
-2
subscriptionUseCase.kt
...to/visual/roompark/domain/use_case/subscriptionUseCase.kt
+48
-29
ScreenPresenter.kt
...al/roompark/presentation/screen/albums/ScreenPresenter.kt
+8
-7
ScreenPresenter.kt
...sual/roompark/presentation/screen/deal/ScreenPresenter.kt
+9
-5
ScreenPresenter.kt
...ual/roompark/presentation/screen/deals/ScreenPresenter.kt
+0
-1
ScreenPresenter.kt
...roompark/presentation/screen/feed_list/ScreenPresenter.kt
+8
-7
ScreenPresenter.kt
.../roompark/presentation/screen/settings/ScreenPresenter.kt
+19
-21
No files found.
app/src/main/java/com/biganto/visual/roompark/data/data_provider/SubscriptionRepository.kt
View file @
936097b5
...
...
@@ -6,6 +6,8 @@ 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
com.biganto.visual.roompark.domain.model.SubscriptionModel
import
com.biganto.visual.roompark.domain.model.fromEntity
import
io.reactivex.Completable
import
io.reactivex.Observable
import
timber.log.Timber
...
...
@@ -43,7 +45,7 @@ class SubscriptionRepository @Inject constructor(
val
userSubs
=
userEntity
.
subscriptions
val
sub
=
subInnerId
?.
let
{
id
->
user
Entity
.
subscription
s
?.
firstOrNull
{
sub
->
sub
.
id
==
id
}
as
SubscriptionEntity
?
user
Sub
s
?.
firstOrNull
{
sub
->
sub
.
id
==
id
}
as
SubscriptionEntity
?
}
?:
SubscriptionEntity
()
.
apply
{
setOwner
(
userEntity
)
...
...
@@ -59,7 +61,7 @@ class SubscriptionRepository @Inject constructor(
fun
saveSubscribtions
(
userEntity
:
UserEntity
,
apiSubs
:
List
<
SubscriptionStatusRaw
>
):
Observable
<
SubscriptionEntity
>
{
):
Observable
<
List
<
SubscriptionModel
>>?
{
val
userSubs
=
userEntity
.
subscriptions
val
newSubList
=
mutableListOf
<
SubscriptionEntity
>()
...
...
@@ -77,10 +79,44 @@ class SubscriptionRepository @Inject constructor(
newSubList
.
add
(
cachedSub
)
}
userSubs
?.
let
{
db
.
deleteSubscriptions
(
it
)
}
return
db
.
upsert
(
newSubList
).
map
{
it
as
SubscriptionEntity
}.
toObservable
()
return
db
.
upsert
(
newSubList
)
.
map
{
list
->
list
.
map
{
fromEntity
(
it
as
SubscriptionEntity
)
}}
.
toObservable
()
}
override
fun
subscribeTopicResult
(
user
:
UserEntity
,
subInnerId
:
Int
,
deviceToken
:
String
,
topic
:
String
,
topic_id
:
String
?
):
Observable
<
List
<
SubscriptionModel
>>
=
api
.
subscribeTopic
(
userToken
=
user
.
authToken
,
deviceToken
=
deviceToken
,
topicName
=
topic
,
topicId
=
topic_id
)
.
flatMap
{
saveSubscribtions
(
user
,
it
.
subscriptions
?:
arrayListOf
())
}
override
fun
unSubscribeTopicResult
(
user
:
UserEntity
,
subInnerId
:
Int
,
deviceToken
:
String
,
topic
:
String
,
topic_id
:
String
?
):
Observable
<
List
<
SubscriptionModel
>>
=
api
.
unSuubscribeTopic
(
userToken
=
user
.
authToken
,
deviceToken
=
deviceToken
,
topicName
=
topic
,
topicId
=
topic_id
)
.
flatMap
{
saveSubscribtions
(
user
,
it
.
subscriptions
?:
arrayListOf
())
}
override
fun
subscribeTopic
(
user
:
UserEntity
,
subInnerId
:
Int
,
...
...
app/src/main/java/com/biganto/visual/roompark/domain/contract/Subscribtions.kt
View file @
936097b5
...
...
@@ -2,6 +2,7 @@ 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.domain.model.SubscriptionModel
import
io.reactivex.Completable
import
io.reactivex.Observable
...
...
@@ -36,4 +37,19 @@ interface SubscriptionContract{
):
Observable
<
SubscriptionEntity
>
fun
saveSubscribeState
(
sub
:
SubscriptionEntity
):
Observable
<
SubscriptionEntity
>
fun
subscribeTopicResult
(
user
:
UserEntity
,
subInnerId
:
Int
,
deviceToken
:
String
,
topic
:
String
,
topic_id
:
String
?
):
Observable
<
List
<
SubscriptionModel
>>
fun
unSubscribeTopicResult
(
user
:
UserEntity
,
subInnerId
:
Int
,
deviceToken
:
String
,
topic
:
String
,
topic_id
:
String
?
):
Observable
<
List
<
SubscriptionModel
>>
}
\ No newline at end of file
app/src/main/java/com/biganto/visual/roompark/domain/interactor/albums.kt
View file @
936097b5
...
...
@@ -5,7 +5,6 @@ import com.biganto.visual.roompark.domain.model.SubscriptionModel
import
com.biganto.visual.roompark.domain.model.SubscriptionTopic
import
com.biganto.visual.roompark.domain.use_case.AlbumsUseCase
import
com.biganto.visual.roompark.domain.use_case.SubscriptionUseCase
import
io.reactivex.Completable
import
io.reactivex.Observable
import
java.util.concurrent.TimeUnit
import
javax.inject.Inject
...
...
@@ -41,7 +40,7 @@ class AlbumsInteractor @Inject constructor(
fun
getSubscriptions
(
topic
:
SubscriptionTopic
)
=
subUc
.
getSubscriptions
(
topic
)
fun
switchSubscription
(
model
:
SubscriptionModel
,
newState
:
Boolean
)
:
Completable
=
fun
switchSubscription
(
model
:
SubscriptionModel
,
newState
:
Boolean
)
=
when
(
newState
){
true
->
subUc
.
subscribeTopic
(
model
.
id
,
model
.
topic
)
false
->
subUc
.
unSubscribeTopic
(
model
.
id
,
model
.
topic
)
...
...
app/src/main/java/com/biganto/visual/roompark/domain/interactor/articles.kt
View file @
936097b5
...
...
@@ -4,7 +4,6 @@ import com.biganto.visual.roompark.domain.model.SubscriptionModel
import
com.biganto.visual.roompark.domain.model.SubscriptionTopic
import
com.biganto.visual.roompark.domain.use_case.FeedUseCase
import
com.biganto.visual.roompark.domain.use_case.SubscriptionUseCase
import
io.reactivex.Completable
import
javax.inject.Inject
/**
...
...
@@ -25,7 +24,7 @@ class ArticlesInteractor @Inject constructor(
fun
getSubscriptions
(
feed
:
String
)
=
subUc
.
getSubscriptions
(
feedSubType
(
feed
))
fun
switchSubscription
(
model
:
SubscriptionModel
,
newState
:
Boolean
)
:
Completable
=
fun
switchSubscription
(
model
:
SubscriptionModel
,
newState
:
Boolean
)
=
when
(
newState
){
true
->
subUc
.
subscribeTopic
(
model
.
id
,
model
.
topic
)
false
->
subUc
.
unSubscribeTopic
(
model
.
id
,
model
.
topic
)
...
...
app/src/main/java/com/biganto/visual/roompark/domain/interactor/deal.kt
View file @
936097b5
...
...
@@ -34,7 +34,7 @@ class DealInteractor @Inject constructor(
fun
getSubscriptions
(
dealId
:
String
)
=
subUc
.
getSubscriptions
(
SubscriptionTopic
.
Deals
(
dealId
=
dealId
))
fun
switchSubscription
(
model
:
SubscriptionModel
,
newState
:
Boolean
)
:
Completable
=
fun
switchSubscription
(
model
:
SubscriptionModel
,
newState
:
Boolean
)
=
when
(
newState
){
true
->
subUc
.
subscribeTopic
(
model
.
id
,
model
.
topic
)
false
->
subUc
.
unSubscribeTopic
(
model
.
id
,
model
.
topic
)
...
...
app/src/main/java/com/biganto/visual/roompark/domain/interactor/settings.kt
View file @
936097b5
...
...
@@ -12,7 +12,6 @@ import com.biganto.visual.roompark.domain.model.PushSwitchModel
import
com.biganto.visual.roompark.domain.model.SettingsModel
import
com.biganto.visual.roompark.domain.model.SubscriptionModel
import
com.biganto.visual.roompark.domain.use_case.*
import
io.reactivex.Completable
import
io.reactivex.Observable
import
io.reactivex.schedulers.Schedulers
import
timber.log.Timber
...
...
@@ -85,7 +84,7 @@ class SettingsInteractor @Inject constructor(
fun
getSubscriptions
()
=
subUc
.
getCurrentUserSubscriptions
()
fun
switchSubscription
(
model
:
SubscriptionModel
,
newState
:
Boolean
)
:
Completable
=
fun
switchSubscription
(
model
:
SubscriptionModel
,
newState
:
Boolean
)
=
when
(
newState
){
true
->
subUc
.
subscribeTopic
(
model
.
id
,
model
.
topic
)
false
->
subUc
.
unSubscribeTopic
(
model
.
id
,
model
.
topic
)
...
...
app/src/main/java/com/biganto/visual/roompark/domain/use_case/subscriptionUseCase.kt
View file @
936097b5
...
...
@@ -11,7 +11,6 @@ import com.biganto.visual.roompark.domain.model.SubscriptionModel
import
com.biganto.visual.roompark.domain.model.SubscriptionTopic
import
com.biganto.visual.roompark.domain.model.TitledSubscriptionModel
import
com.biganto.visual.roompark.domain.model.fromEntity
import
io.reactivex.Completable
import
io.reactivex.Observable
import
io.reactivex.functions.BiFunction
import
io.reactivex.schedulers.Schedulers
...
...
@@ -28,54 +27,74 @@ class SubscriptionUseCase @Inject constructor(
private
val
utils
:
DeviceUtilsContract
,
private
val
auth
:
AuthContract
)
{
fun
subscribeTopic
(
subId
:
Int
,
topic
:
SubscriptionTopic
):
Completable
=
fun
subscribeTopic
(
subId
:
Int
,
topic
:
SubscriptionTopic
):
Observable
<
List
<
TitledSubscriptionModel
>>
=
Observable
.
zip
(
auth
.
currentUser
(),
utils
.
getDeviceId
()
,
BiFunction
<
UserEntity
,
String
,
SubscribeRequestModel
>
{
user
,
token
->
SubscribeRequestModel
(
user
,
token
)
})
.
flatMap
Completable
{
subscription
.
subscribeTopic
(
it
.
user
.
flatMap
{
requestModel
->
subscription
.
subscribeTopic
Result
(
requestModel
.
user
,
subId
,
it
.
deviceToken
,
topic
=
topic
.
topicName
,
topic_id
=
topic
.
topicId
).
subscribeOn
(
Schedulers
.
io
())
,
requestModel
.
deviceToken
,
topic
=
topic
.
topicName
,
topic_id
=
topic
.
topicId
)
.
map
{
subs
->
subsToTitle
(
requestModel
.
user
,
subs
)}
.
subscribeOn
(
Schedulers
.
io
())
}
fun
unSubscribeTopic
(
subId
:
Int
,
topic
:
SubscriptionTopic
):
Completable
=
fun
unSubscribeTopic
(
subId
:
Int
,
topic
:
SubscriptionTopic
):
Observable
<
List
<
TitledSubscriptionModel
>>
=
Observable
.
zip
(
auth
.
currentUser
(),
utils
.
getDeviceId
()
,
BiFunction
<
UserEntity
,
String
,
SubscribeRequestModel
>
{
user
,
token
->
SubscribeRequestModel
(
user
,
token
)
})
.
flatMap
Completable
{
subscription
.
unSubscribeTopic
(
it
.
user
.
flatMap
{
requestModel
->
subscription
.
unSubscribeTopic
Result
(
requestModel
.
user
,
subId
,
it
.
deviceToken
,
requestModel
.
deviceToken
,
topic
=
topic
.
topicName
,
topic_id
=
topic
.
topicId
).
subscribeOn
(
Schedulers
.
io
())
)
.
map
{
subs
->
subsToTitle
(
requestModel
.
user
,
subs
)}
.
subscribeOn
(
Schedulers
.
io
())
}
private
fun
subsToTitle
(
user
:
UserEntity
,
subs
:
List
<
SubscriptionModel
>?)
:
List
<
TitledSubscriptionModel
>
{
val
subList
=
subs
?:
user
.
subscriptions
?.
asSequence
()
?.
map
{
it
as
SubscriptionEntity
}
?.
map
(
::
fromEntity
)
?.
toList
()
?:
arrayListOf
()
return
List
(
subList
.
size
){
i
->
subToTitledSub
(
user
.
deals
?.
map
{
it
as
DealEntity
}
?:
arrayListOf
(),
subList
[
i
])
}
}
private
fun
subToTitledSub
(
deals
:
List
<
DealEntity
>,
sub
:
SubscriptionModel
)
:
TitledSubscriptionModel
{
var
title
=
SubscriptionTopic
.
titleByTopic
(
sub
.
topic
)
if
(
sub
.
topic
is
SubscriptionTopic
.
Deals
)
{
val
deal
=
deals
.
firstOrNull
{
d
->
d
.
estateCrmId
==
sub
.
topic
.
topicId
}
if
(
deal
==
null
)
Timber
.
e
(
"Deal not recognized: $sub ; $deals"
)
title
=
"$title № ${deal?.estate?.number}"
}
return
TitledSubscriptionModel
(
title
,
sub
)
}
fun
getCurrentUserSubscriptions
():
Observable
<
List
<
TitledSubscriptionModel
>>
=
auth
.
currentUser
()
.
map
{
user
->
val
subList
=
user
.
subscriptions
?:
arrayListOf
()
val
list
=
List
<
TitledSubscriptionModel
>(
subList
.
size
){
i
->
val
sub
:
SubscriptionModel
=
fromEntity
(
subList
[
i
]
as
SubscriptionEntity
)
var
title
=
SubscriptionTopic
.
titleByTopic
(
sub
.
topic
)
if
(
sub
.
topic
is
SubscriptionTopic
.
Deals
){
val
deal
=
user
.
deals
?.
firstOrNull
{
d
->
d
.
estateCrmId
==
sub
.
topic
.
topicId
}
as
DealEntity
title
=
"$title № ${deal.estate.number}"
}
TitledSubscriptionModel
(
title
,
sub
)
}
list
}
.
map
{
user
->
subsToTitle
(
user
,
null
)}
fun
getSubscriptions
(
topic
:
SubscriptionTopic
):
Observable
<
SubscriptionModel
>
=
...
...
app/src/main/java/com/biganto/visual/roompark/presentation/screen/albums/ScreenPresenter.kt
View file @
936097b5
...
...
@@ -48,13 +48,14 @@ class AlbumsScreenPresenter @Inject constructor(
.
filter
{
restoreModel
.
sub
!=
null
}
.
flatMap
{
newState
->
interactor
.
switchSubscription
(
restoreModel
.
sub
!!
,
newState
)
.
andThen
(
Observable
.
just
<
AlbumsScreenViewState
>(
AlbumsScreenViewState
.
SubscriptionStatus
(
newState
)
)
)
.
map
{
subs
->
val
s
=
subs
.
map
{
it
.
subModel
}.
firstOrNull
{
it
.
id
==
restoreModel
.
sub
?.
id
}
restoreModel
.
sub
=
s
if
(
s
!=
null
)
return
@map
AlbumsScreenViewState
.
SubscriptionStatus
(
s
.
state
)
else
return
@map
AlbumsScreenViewState
.
SubscriptionError
(!
newState
)
}
.
onErrorReturn
{
AlbumsScreenViewState
.
SubscriptionError
(!
newState
)
}
}
...
...
app/src/main/java/com/biganto/visual/roompark/presentation/screen/deal/ScreenPresenter.kt
View file @
936097b5
...
...
@@ -55,14 +55,18 @@ class DealScreenPresenter @Inject constructor(
.
filter
{
restoreModel
.
sub
!=
null
}
.
flatMap
{
newState
->
interactor
.
switchSubscription
(
restoreModel
.
sub
!!
,
newState
)
.
andThen
(
Observable
.
just
<
DealScreenViewState
>(
DealScreenViewState
.
SubscriptionStatus
(
newState
)
)
)
.
map
{
subs
->
val
s
=
subs
.
map
{
it
.
subModel
}.
firstOrNull
{
it
.
id
==
restoreModel
.
sub
?.
id
}
restoreModel
.
sub
=
s
if
(
s
!=
null
)
return
@map
DealScreenViewState
.
SubscriptionStatus
(
s
.
state
)
else
return
@map
DealScreenViewState
.
SubscriptionError
(!
newState
)
}
.
onErrorReturn
{
DealScreenViewState
.
SubscriptionError
(!
newState
)
}
}
val
fetchSubscription
=
fetchDeal
.
flatMap
{
fetchedDealViewState
->
interactor
.
getSubscriptions
(
...
...
app/src/main/java/com/biganto/visual/roompark/presentation/screen/deals/ScreenPresenter.kt
View file @
936097b5
...
...
@@ -39,7 +39,6 @@ class DealsScreenPresenter @Inject constructor(
)
}
}
.
doOnError
{
Timber
.
e
(
" ERORORO "
)
}
}
.
map
<
DealsScreenViewState
>(
DealsScreenViewState
::
DealsLoaded
)
.
onErrorReturn
(
::
parseError
)
...
...
app/src/main/java/com/biganto/visual/roompark/presentation/screen/feed_list/ScreenPresenter.kt
View file @
936097b5
...
...
@@ -43,13 +43,14 @@ class ArticlesScreenPresenter @Inject constructor(
.
filter
{
restoreModel
.
sub
!=
null
}
.
flatMap
{
newState
->
interactor
.
switchSubscription
(
restoreModel
.
sub
!!
,
newState
)
.
andThen
(
Observable
.
just
<
ArticlesScreenViewState
>(
ArticlesScreenViewState
.
SubscriptionStatus
(
newState
)
)
)
.
map
{
subs
->
val
s
=
subs
.
map
{
it
.
subModel
}.
firstOrNull
{
it
.
id
==
restoreModel
.
sub
?.
id
}
restoreModel
.
sub
=
s
if
(
s
!=
null
)
return
@map
ArticlesScreenViewState
.
SubscriptionStatus
(
s
.
state
)
else
return
@map
ArticlesScreenViewState
.
SubscriptionError
(!
newState
)
}
.
onErrorReturn
{
ArticlesScreenViewState
.
SubscriptionError
(!
newState
)
}
}
...
...
app/src/main/java/com/biganto/visual/roompark/presentation/screen/settings/ScreenPresenter.kt
View file @
936097b5
...
...
@@ -67,28 +67,26 @@ class SettingsScreenPresenter @Inject constructor(
val
onSubChecked
=
intent
(
SettingsScreen
::
onSubscription
)
.
flatMap
{
sub
->
interactor
.
switchSubscription
(
sub
,
!
sub
.
state
)
.
andThen
(
Observable
.
just
<
SettingsScreenViewState
>(
SettingsScreenViewState
.
SubscriptionStatus
(
sub
.
id
,
!
sub
.
state
)
.
map
<
SettingsScreenViewState
>
{
restoreModel
.
subs
=
it
.
toMutableList
()
SettingsScreenViewState
.
SubscriptionStatus
(
sub
.
id
,
!
sub
.
state
)
.
doOnNext
{
val
ind
=
restoreModel
.
subs
.
indexOfFirst
{
it
.
subModel
.
id
==
sub
.
id
}
restoreModel
.
subs
[
ind
]
=
TitledSubscriptionModel
(
title
=
restoreModel
.
subs
[
ind
].
title
,
subModel
=
SubscriptionModel
(
topic
=
sub
.
topic
,
id
=
restoreModel
.
subs
[
ind
].
subModel
.
id
,
state
=
!
sub
.
state
)
)
}
)
}
.
doOnNext
{
val
ind
=
restoreModel
.
subs
.
indexOfFirst
{
it
.
subModel
.
id
==
sub
.
id
}
restoreModel
.
subs
[
ind
]
=
TitledSubscriptionModel
(
title
=
restoreModel
.
subs
[
ind
].
title
,
subModel
=
SubscriptionModel
(
topic
=
sub
.
topic
,
id
=
restoreModel
.
subs
[
ind
].
subModel
.
id
,
state
=
!
sub
.
state
)
)
}
.
doOnError
{
Timber
.
e
(
it
)
}
.
onErrorReturn
{
SettingsScreenViewState
.
SubscriptionError
(
sub
.
id
,
sub
.
state
)
}
}
...
...
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