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
99e88e1d
Commit
99e88e1d
authored
Mar 27, 2020
by
Vladislav Bogdashkin
🎣
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
subscription api fix
parent
0a690861
Changes
10
Show whitespace changes
Inline
Side-by-side
Showing
10 changed files
with
63 additions
and
34 deletions
+63
-34
AuthRepository.kt
...anto/visual/roompark/data/data_provider/AuthRepository.kt
+2
-0
DeviceUtils.kt
...biganto/visual/roompark/data/data_provider/DeviceUtils.kt
+1
-0
SubscriptionRepository.kt
...ual/roompark/data/data_provider/SubscriptionRepository.kt
+5
-2
IRoomParkMobileApi.kt
...ompark/data/repository/api/retrofit/IRoomParkMobileApi.kt
+8
-6
RetrofitRepository.kt
...ompark/data/repository/api/retrofit/RetrofitRepository.kt
+1
-0
RetrofitModule.kt
...oompark/data/repository/api/retrofit/di/RetrofitModule.kt
+1
-1
RequeryRepository.kt
.../roompark/data/repository/db/requrey/RequeryRepository.kt
+4
-3
articles.kt
...com/biganto/visual/roompark/domain/interactor/articles.kt
+1
-1
subscriptionUseCase.kt
...to/visual/roompark/domain/use_case/subscriptionUseCase.kt
+39
-21
ScreenPresenter.kt
...roompark/presentation/screen/feed_list/ScreenPresenter.kt
+1
-0
No files found.
app/src/main/java/com/biganto/visual/roompark/data/data_provider/AuthRepository.kt
View file @
99e88e1d
...
@@ -54,6 +54,8 @@ class AuthContractModule @Inject constructor(
...
@@ -54,6 +54,8 @@ class AuthContractModule @Inject constructor(
.
flatMap
{
when
(
it
){
.
flatMap
{
when
(
it
){
is
UserState
.
NotAuthenticated
->
throw
CustomApiException
.
NotAuthorizedException
()
is
UserState
.
NotAuthenticated
->
throw
CustomApiException
.
NotAuthorizedException
()
is
UserState
.
Authenticated
->
db
.
fetchUser
(
it
.
uuid
.
toInt
())
is
UserState
.
Authenticated
->
db
.
fetchUser
(
it
.
uuid
.
toInt
())
.
doOnError
{
Timber
.
e
(
it
)
}
.
doOnNext
{
u
->
"got usr:$u"
}
else
->
throw
CustomApiException
.
NotAuthorizedException
()
else
->
throw
CustomApiException
.
NotAuthorizedException
()
}
}
}
}
...
...
app/src/main/java/com/biganto/visual/roompark/data/data_provider/DeviceUtils.kt
View file @
99e88e1d
...
@@ -18,6 +18,7 @@ class DeviceUtilsRepository @Inject constructor(
...
@@ -18,6 +18,7 @@ class DeviceUtilsRepository @Inject constructor(
override
fun
getDeviceId
():
Observable
<
String
>
=
override
fun
getDeviceId
():
Observable
<
String
>
=
Observable
.
create
<
String
>
{
emitter
->
Observable
.
create
<
String
>
{
emitter
->
Timber
.
d
(
"Creat observer"
)
FirebaseInstanceId
.
getInstance
().
instanceId
FirebaseInstanceId
.
getInstance
().
instanceId
.
addOnCompleteListener
(
OnCompleteListener
{
task
->
.
addOnCompleteListener
(
OnCompleteListener
{
task
->
if
(!
task
.
isSuccessful
)
{
if
(!
task
.
isSuccessful
)
{
...
...
app/src/main/java/com/biganto/visual/roompark/data/data_provider/SubscriptionRepository.kt
View file @
99e88e1d
...
@@ -7,6 +7,7 @@ import com.biganto.visual.roompark.data.repository.db.requrey.model.UserEntity
...
@@ -7,6 +7,7 @@ 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
io.reactivex.Observable
import
timber.log.Timber
import
javax.inject.Inject
import
javax.inject.Inject
/**
/**
...
@@ -59,7 +60,8 @@ class SubscriptionRepository @Inject constructor(
...
@@ -59,7 +60,8 @@ class SubscriptionRepository @Inject constructor(
topic
:
String
,
topic
:
String
,
topic_id
:
String
?
topic_id
:
String
?
):
Completable
=
api
.
subscribeTopic
(
deviceToken
=
deviceToken
,
topicName
=
topic
,
userToken
=
user
.
authToken
)
):
Completable
=
api
.
subscribeTopic
(
deviceToken
=
deviceToken
,
topicName
=
topic
,
userToken
=
user
.
authToken
)
.
switchMapCompletable
{
.
doOnNext
{
Timber
.
d
(
"UUUUUUUU $it"
)
}
.
flatMapCompletable
{
if
(
it
.
status
==
SUBSCRIPTION_RESULT_STATUS
){
if
(
it
.
status
==
SUBSCRIPTION_RESULT_STATUS
){
saveSubscribeState
(
user
,
subInnerId
,
topic
,
topic_id
,
true
).
ignoreElements
()
saveSubscribeState
(
user
,
subInnerId
,
topic
,
topic_id
,
true
).
ignoreElements
()
}
}
...
@@ -75,7 +77,8 @@ class SubscriptionRepository @Inject constructor(
...
@@ -75,7 +77,8 @@ class SubscriptionRepository @Inject constructor(
topic_id
:
String
?
topic_id
:
String
?
):
Completable
=
):
Completable
=
api
.
unSuubscribeTopic
(
deviceToken
=
deviceToken
,
topicName
=
topic
,
userToken
=
user
.
authToken
)
api
.
unSuubscribeTopic
(
deviceToken
=
deviceToken
,
topicName
=
topic
,
userToken
=
user
.
authToken
)
.
switchMapCompletable
{
.
doOnNext
{
Timber
.
d
(
"$it"
)
}
.
flatMapCompletable
{
if
(
it
.
status
==
SUBSCRIPTION_RESULT_STATUS
){
if
(
it
.
status
==
SUBSCRIPTION_RESULT_STATUS
){
saveSubscribeState
(
user
,
subInnerId
,
topic
,
topic_id
,
false
).
ignoreElements
()
saveSubscribeState
(
user
,
subInnerId
,
topic
,
topic_id
,
false
).
ignoreElements
()
}
}
...
...
app/src/main/java/com/biganto/visual/roompark/data/repository/api/retrofit/IRoomParkMobileApi.kt
View file @
99e88e1d
...
@@ -141,24 +141,26 @@ interface IRoomParkMobileApi{
...
@@ -141,24 +141,26 @@ interface IRoomParkMobileApi{
@Field
(
PASSWORD_AUTH_PARAM
)
pwd
:
String
@Field
(
PASSWORD_AUTH_PARAM
)
pwd
:
String
):
Observable
<
Response
<
AuthRaw
>>
):
Observable
<
Response
<
AuthRaw
>>
@POST
(
"$API_URL${SUBSCRIBE_METHOD}OD$DELIMITER"
)
@POST
(
"$API_URL${SUBSCRIBE_METHOD}$DELIMITER"
)
@FormUrlEncoded
fun
subscribe
(
fun
subscribe
(
@Query
(
CLIENT_TYPE_PARAM
)
clientType
:
String
=
DEFAULT_CLIENT_TYPE
,
@Query
(
CLIENT_TYPE_PARAM
)
clientType
:
String
=
DEFAULT_CLIENT_TYPE
,
@Query
(
CLIENT_VERSION_PARAM
)
clientVersion
:
String
=
DEFAULT_CLIENT_VERSION
,
@Query
(
CLIENT_VERSION_PARAM
)
clientVersion
:
String
=
DEFAULT_CLIENT_VERSION
,
@Query
(
API_VERSION_PARAM
)
apiVersion
:
String
=
DEFAULT_API_VERSION
,
@Query
(
API_VERSION_PARAM
)
apiVersion
:
String
=
DEFAULT_API_VERSION
,
@Query
(
AUTH_TOKEN
)
token
:
String
,
@Query
(
AUTH_TOKEN
)
token
:
String
,
@
Query
(
DEVICE_TOKEN_SUBSCRIBTION_PARAM
)
deviceToken
:
String
,
@
Field
(
DEVICE_TOKEN_SUBSCRIBTION_PARAM
)
deviceToken
:
String
,
@
Query
(
TOPIC_SUBSCRIBTION_PARAM
)
topic
:
String
@
Field
(
TOPIC_SUBSCRIBTION_PARAM
)
topic
:
String
):
Observable
<
Response
<
StatusResponse
>>
):
Observable
<
Response
<
StatusResponse
>>
@POST
(
"$API_URL${UNSUBSCRIBE_METHOD}OD$DELIMITER"
)
@POST
(
"$API_URL${UNSUBSCRIBE_METHOD}$DELIMITER"
)
@FormUrlEncoded
fun
unsubscribe
(
fun
unsubscribe
(
@Query
(
CLIENT_TYPE_PARAM
)
clientType
:
String
=
DEFAULT_CLIENT_TYPE
,
@Query
(
CLIENT_TYPE_PARAM
)
clientType
:
String
=
DEFAULT_CLIENT_TYPE
,
@Query
(
CLIENT_VERSION_PARAM
)
clientVersion
:
String
=
DEFAULT_CLIENT_VERSION
,
@Query
(
CLIENT_VERSION_PARAM
)
clientVersion
:
String
=
DEFAULT_CLIENT_VERSION
,
@Query
(
API_VERSION_PARAM
)
apiVersion
:
String
=
DEFAULT_API_VERSION
,
@Query
(
API_VERSION_PARAM
)
apiVersion
:
String
=
DEFAULT_API_VERSION
,
@Query
(
AUTH_TOKEN
)
token
:
String
,
@Query
(
AUTH_TOKEN
)
token
:
String
,
@
Query
(
DEVICE_TOKEN_SUBSCRIBTION_PARAM
)
deviceToken
:
String
,
@
Field
(
DEVICE_TOKEN_SUBSCRIBTION_PARAM
)
deviceToken
:
String
,
@
Query
(
TOPIC_SUBSCRIBTION_PARAM
)
topic
:
String
@
Field
(
TOPIC_SUBSCRIBTION_PARAM
)
topic
:
String
):
Observable
<
Response
<
StatusResponse
>>
):
Observable
<
Response
<
StatusResponse
>>
@GET
(
"$API_URL$DEALS_METHOD$DELIMITER"
)
@GET
(
"$API_URL$DEALS_METHOD$DELIMITER"
)
...
...
app/src/main/java/com/biganto/visual/roompark/data/repository/api/retrofit/RetrofitRepository.kt
View file @
99e88e1d
...
@@ -38,6 +38,7 @@ class RetrofitRepository @Inject constructor(retrofit: Retrofit) : IRoomParkApi
...
@@ -38,6 +38,7 @@ class RetrofitRepository @Inject constructor(retrofit: Retrofit) : IRoomParkApi
topicName
:
String
topicName
:
String
):
Observable
<
StatusResponse
>
=
):
Observable
<
StatusResponse
>
=
api
.
subscribe
(
token
=
userToken
,
deviceToken
=
deviceToken
,
topic
=
topicName
)
api
.
subscribe
(
token
=
userToken
,
deviceToken
=
deviceToken
,
topic
=
topicName
)
.
doOnError
{
Timber
.
w
(
" WTFF ???"
)
}
.
compose
(
RetrofitResponseValidation
())
.
compose
(
RetrofitResponseValidation
())
override
fun
unSuubscribeTopic
(
override
fun
unSuubscribeTopic
(
...
...
app/src/main/java/com/biganto/visual/roompark/data/repository/api/retrofit/di/RetrofitModule.kt
View file @
99e88e1d
...
@@ -34,7 +34,7 @@ private const val TIMEOUT_SECONDS=120L
...
@@ -34,7 +34,7 @@ private const val TIMEOUT_SECONDS=120L
private
const
val
WRITE_SECONDS
=
120L
private
const
val
WRITE_SECONDS
=
120L
private
const
val
READ_SECONDS
=
120L
private
const
val
READ_SECONDS
=
120L
val
INTERCEPT_LOG_LEVEL
=
HttpLoggingInterceptor
.
Level
.
NONE
val
INTERCEPT_LOG_LEVEL
=
HttpLoggingInterceptor
.
Level
.
BODY
@Module
@Module
class
RetrofitModule
{
class
RetrofitModule
{
...
...
app/src/main/java/com/biganto/visual/roompark/data/repository/db/requrey/RequeryRepository.kt
View file @
99e88e1d
...
@@ -31,8 +31,8 @@ class DbModule{
...
@@ -31,8 +31,8 @@ class DbModule{
Timber
.
d
(
"Kotlin store creating.."
)
Timber
.
d
(
"Kotlin store creating.."
)
val
source
=
DatabaseSource
(
context
,
Models
.
DEFAULT
,
"BigantoPerfect"
,
DATABASE_VERSION
)
val
source
=
DatabaseSource
(
context
,
Models
.
DEFAULT
,
"BigantoPerfect"
,
DATABASE_VERSION
)
//
source.setLoggingEnabled(true)
source
.
setLoggingEnabled
(
true
)
//
source.setWriteAheadLoggingEnabled(true)
source
.
setWriteAheadLoggingEnabled
(
true
)
source
.
setTableCreationMode
(
TableCreationMode
.
DROP_CREATE
)
source
.
setTableCreationMode
(
TableCreationMode
.
DROP_CREATE
)
val
store
=
KotlinEntityDataStore
<
Persistable
>(
source
.
configuration
)
val
store
=
KotlinEntityDataStore
<
Persistable
>(
source
.
configuration
)
Timber
.
d
(
"Kotlin store %s"
,
source
)
Timber
.
d
(
"Kotlin store %s"
,
source
)
...
@@ -51,7 +51,8 @@ class RequeryRepository @Inject constructor(
...
@@ -51,7 +51,8 @@ class RequeryRepository @Inject constructor(
override
fun
upsertUser
(
entity
:
UserEntity
):
Observable
<
UserEntity
>
=
override
fun
upsertUser
(
entity
:
UserEntity
):
Observable
<
UserEntity
>
=
store
.
upsert
(
entity
).
toObservable
()
store
.
upsert
(
entity
).
toObservable
()
override
fun
<
T
:
Persistable
>
upsert
(
entity
:
T
)
=
store
.
upsert
(
entity
)
override
fun
<
T
:
Persistable
>
upsert
(
entity
:
T
):
Single
<
T
>
=
store
.
upsert
(
entity
)
override
fun
<
T
:
List
<
Persistable
>
>
upsert
(
entity
:
T
):
Single
<
Iterable
<
Persistable
>>
=
override
fun
<
T
:
List
<
Persistable
>
>
upsert
(
entity
:
T
):
Single
<
Iterable
<
Persistable
>>
=
store
.
upsert
(
entity
)
store
.
upsert
(
entity
)
...
...
app/src/main/java/com/biganto/visual/roompark/domain/interactor/articles.kt
View file @
99e88e1d
...
@@ -29,7 +29,7 @@ class ArticlesInteractor @Inject constructor(
...
@@ -29,7 +29,7 @@ class ArticlesInteractor @Inject constructor(
when
(
newState
){
when
(
newState
){
true
->
subUc
.
subscribeTopic
(
model
.
id
,
model
.
topic
)
true
->
subUc
.
subscribeTopic
(
model
.
id
,
model
.
topic
)
false
->
subUc
.
unSubscribeTopic
(
model
.
id
,
model
.
topic
)
false
->
subUc
.
unSubscribeTopic
(
model
.
id
,
model
.
topic
)
}
.
ignoreElements
()
}
private
fun
feedSubType
(
feed
:
String
)
=
private
fun
feedSubType
(
feed
:
String
)
=
when
(
feed
){
when
(
feed
){
...
...
app/src/main/java/com/biganto/visual/roompark/domain/use_case/subscriptionUseCase.kt
View file @
99e88e1d
...
@@ -2,14 +2,17 @@ package com.biganto.visual.roompark.domain.use_case
...
@@ -2,14 +2,17 @@ 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.data.repository.db.requrey.model.SubscriptionEntity
import
com.biganto.visual.roompark.data.repository.db.requrey.model.UserEntity
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.SubscriptionModel
import
com.biganto.visual.roompark.domain.model.SubscriptionTopic
import
com.biganto.visual.roompark.domain.model.SubscriptionTopic
import
com.biganto.visual.roompark.domain.model.fromEntity
import
com.biganto.visual.roompark.domain.model.fromEntity
import
io.reactivex.Completable
import
io.reactivex.Observable
import
io.reactivex.Observable
import
io.reactivex.rxkotlin.Observables
import
io.reactivex.functions.BiFunction
import
io.reactivex.schedulers.Schedulers
import
timber.log.Timber
import
timber.log.Timber
import
javax.inject.Inject
import
javax.inject.Inject
//import io.reactivex.rxkotlin
//import io.reactivex.rxkotlin
...
@@ -23,26 +26,36 @@ class SubscriptionUseCase @Inject constructor(
...
@@ -23,26 +26,36 @@ 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
:
SubscriptionTopic
)
=
fun
subscribeTopic
(
subId
:
Int
,
topic
:
SubscriptionTopic
):
Completable
=
Observables
.
zip
(
auth
.
currentUser
(),
utils
.
getDeviceId
())
{
user
,
token
->
Observable
.
zip
(
auth
.
currentUser
(),
utils
.
getDeviceId
()
,
BiFunction
<
UserEntity
,
String
,
SubscribeRequestModel
>
{
user
,
token
->
SubscribeRequestModel
(
user
,
token
)
})
.
flatMapCompletable
{
subscription
.
subscribeTopic
(
subscription
.
subscribeTopic
(
user
it
.
user
,
subId
,
subId
,
t
oken
,
it
.
deviceT
oken
,
topic
=
topic
.
topicName
,
,
topic
=
topic
.
topicName
,
topic_id
=
topic
.
topicId
topic_id
=
topic
.
topicId
)
).
subscribeOn
(
Schedulers
.
io
()
)
}
}
fun
unSubscribeTopic
(
subId
:
Int
,
topic
:
SubscriptionTopic
)
=
Observables
.
zip
(
auth
.
currentUser
(),
utils
.
getDeviceId
())
{
user
,
token
->
fun
unSubscribeTopic
(
subId
:
Int
,
topic
:
SubscriptionTopic
):
Completable
=
Observable
.
zip
(
auth
.
currentUser
(),
utils
.
getDeviceId
()
,
BiFunction
<
UserEntity
,
String
,
SubscribeRequestModel
>
{
user
,
token
->
SubscribeRequestModel
(
user
,
token
)
})
.
flatMapCompletable
{
subscription
.
unSubscribeTopic
(
subscription
.
unSubscribeTopic
(
user
it
.
user
,
subId
,
subId
,
t
oken
,
it
.
deviceT
oken
,
topic
=
topic
.
topicName
,
,
topic
=
topic
.
topicName
,
topic_id
=
topic
.
topicId
topic_id
=
topic
.
topicId
)
).
subscribeOn
(
Schedulers
.
io
()
)
}
}
fun
getSubscriptions
(
topic
:
SubscriptionTopic
):
Observable
<
SubscriptionModel
>
=
fun
getSubscriptions
(
topic
:
SubscriptionTopic
):
Observable
<
SubscriptionModel
>
=
...
@@ -65,6 +78,11 @@ class SubscriptionUseCase @Inject constructor(
...
@@ -65,6 +78,11 @@ class SubscriptionUseCase @Inject constructor(
}
}
private
data class
SubscribeRequestModel
(
val
user
:
UserEntity
,
val
deviceToken
:
String
)
app/src/main/java/com/biganto/visual/roompark/presentation/screen/feed_list/ScreenPresenter.kt
View file @
99e88e1d
...
@@ -38,6 +38,7 @@ class ArticlesScreenPresenter @Inject constructor(
...
@@ -38,6 +38,7 @@ class ArticlesScreenPresenter @Inject constructor(
Timber
.
d
(
"feedId : $feedId"
)
Timber
.
d
(
"feedId : $feedId"
)
val
onSubChecked
=
intent
(
ArticlesScreen
::
feedSubscription
)
val
onSubChecked
=
intent
(
ArticlesScreen
::
feedSubscription
)
.
skip
(
1
)
.
filter
{
restoreModel
.
sub
!=
null
}
.
filter
{
restoreModel
.
sub
!=
null
}
.
flatMap
{
newState
->
.
flatMap
{
newState
->
interactor
.
switchSubscription
(
restoreModel
.
sub
!!
,
newState
)
interactor
.
switchSubscription
(
restoreModel
.
sub
!!
,
newState
)
...
...
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