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
8e272697
Commit
8e272697
authored
Apr 22, 2020
by
Vladislav Bogdashkin
🎣
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
prefetch all estates on settings screen
parent
631c032e
Changes
6
Hide whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
57 additions
and
8 deletions
+57
-8
EstateRepository.kt
...to/visual/roompark/data/data_provider/EstateRepository.kt
+22
-0
IDb.kt
...ava/com/biganto/visual/roompark/data/repository/db/IDb.kt
+2
-0
RequeryRepository.kt
.../roompark/data/repository/db/requrey/RequeryRepository.kt
+6
-0
DealContract.kt
...m/biganto/visual/roompark/domain/contract/DealContract.kt
+5
-0
planTypesUseCase.kt
...ganto/visual/roompark/domain/use_case/planTypesUseCase.kt
+20
-7
ScreenPresenter.kt
.../roompark/presentation/screen/settings/ScreenPresenter.kt
+2
-1
No files found.
app/src/main/java/com/biganto/visual/roompark/data/data_provider/EstateRepository.kt
View file @
8e272697
...
...
@@ -6,6 +6,7 @@ import com.biganto.visual.roompark.data.repository.api.room_park.IRoomParkApi
import
com.biganto.visual.roompark.data.repository.db.IDb
import
com.biganto.visual.roompark.data.repository.db.requrey.model.DealEntity
import
com.biganto.visual.roompark.data.repository.db.requrey.model.EstateEntity
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.data.repository.mapper.fromRawList
import
com.biganto.visual.roompark.domain.contract.DealContract
...
...
@@ -38,6 +39,27 @@ class EstateRepository @Inject constructor(
Timber
.
d
(
"Estate Repository Created $this"
)
}
override
fun
fetchFavorites
(
user
:
UserEntity
):
Observable
<
Iterable
<
EstateEntity
>>
=
api
.
getFavorites
(
user
.
authToken
)
.
doOnError
(
Timber
::
e
)
.
map
{
fromRawList
(
it
,
::
fromRaw
)
}
.
doOnNext
{
it
.
forEach
{
estate
->
estate
.
setFavorite
(
true
)
estate
.
user
=
user
}
}
.
flatMap
(
db
::
upsertEstates
)
.
doOnNext
{
db
.
refreshUser
(
user
)
}
override
fun
fetchDeals
(
user
:
UserEntity
):
Observable
<
List
<
EstateEntity
>>
=
api
.
getDeals
(
TEST_DEAL_TOKEN
)
//api.getDeals(user.authToken)
.
doOnError
(
Timber
::
e
)
.
map
{
List
(
it
.
size
){
index
->
fromRaw
(
it
[
index
],
user
)}
}
.
flatMap
(
db
::
upsertDeals
)
.
map
{
it
.
map
{
deal
->
deal
.
estate
as
EstateEntity
}
}
.
doOnNext
{
db
.
refreshUser
(
user
)
}
private
val
getFavoritesApi
:
Observable
<
List
<
EstateEntity
>>
=
local
.
recentUser
()
.
flatMap
{
...
...
app/src/main/java/com/biganto/visual/roompark/data/repository/db/IDb.kt
View file @
8e272697
...
...
@@ -75,4 +75,6 @@ interface IDb {
fun
refreshUser
(
userEntity
:
UserEntity
):
Observable
<
UserEntity
>
fun
refreshEntities
(
entities
:
List
<
Persistable
>):
Observable
<
Iterable
<
Persistable
>>
fun
refreshEstatesWithTours
():
Completable
fun
upsertEstates
(
entity
:
List
<
EstateEntity
>):
Observable
<
Iterable
<
EstateEntity
>>?
fun
upsertDeals
(
entity
:
List
<
DealEntity
>):
Observable
<
Iterable
<
DealEntity
>>
}
\ No newline at end of file
app/src/main/java/com/biganto/visual/roompark/data/repository/db/requrey/RequeryRepository.kt
View file @
8e272697
...
...
@@ -90,6 +90,12 @@ class RequeryRepository @Inject constructor(
override
fun
<
T
:
List
<
Persistable
>
>
blockingUpsert
(
entity
:
T
)
=
store
.
upsert
(
entity
).
toObservable
().
blockingSubscribe
()
override
fun
upsertDeals
(
entity
:
List
<
DealEntity
>):
Observable
<
Iterable
<
DealEntity
>>
=
store
.
upsert
(
entity
).
toObservable
()
override
fun
upsertEstates
(
entity
:
List
<
EstateEntity
>):
Observable
<
Iterable
<
EstateEntity
>>
=
store
.
upsert
(
entity
).
toObservable
()
override
fun
upsertEstate
(
entity
:
EstateEntity
)
=
store
.
upsert
(
entity
).
toObservable
().
blockingSubscribe
()
...
...
app/src/main/java/com/biganto/visual/roompark/domain/contract/DealContract.kt
View file @
8e272697
package
com.biganto.visual.roompark.domain.contract
import
com.biganto.visual.roompark.data.repository.db.requrey.model.DealEntity
import
com.biganto.visual.roompark.data.repository.db.requrey.model.EstateEntity
import
com.biganto.visual.roompark.data.repository.db.requrey.model.UserEntity
import
com.biganto.visual.roompark.domain.model.DealModel
import
com.biganto.visual.roompark.domain.model.EstateModel
import
io.reactivex.Completable
...
...
@@ -17,4 +20,6 @@ interface DealContract{
fun
getDeals
():
Observable
<
List
<
DealModel
>>
fun
fetchEstate
(
building
:
Int
,
number
:
Int
):
Observable
<
EstateModel
>
fun
setDealRead
(
dealId
:
String
):
Completable
fun
fetchDeals
(
user
:
UserEntity
):
Observable
<
List
<
EstateEntity
>>
fun
fetchFavorites
(
user
:
UserEntity
):
Observable
<
Iterable
<
EstateEntity
>>
}
\ No newline at end of file
app/src/main/java/com/biganto/visual/roompark/domain/use_case/planTypesUseCase.kt
View file @
8e272697
...
...
@@ -2,9 +2,12 @@ package com.biganto.visual.roompark.domain.use_case
import
com.biganto.visual.roompark.data.data_provider.featuresVariants
import
com.biganto.visual.roompark.data.repository.db.requrey.model.EstateEntity
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.DealContract
import
com.biganto.visual.roompark.domain.contract.FlatPlanContract
import
io.reactivex.Observable
import
io.reactivex.rxkotlin.Observables
import
javax.inject.Inject
/**
...
...
@@ -13,20 +16,30 @@ import javax.inject.Inject
class
PlanTypesUseCase
@Inject
constructor
(
private
val
planContract
:
FlatPlanContract
,
private
val
auth
:
AuthContract
private
val
auth
:
AuthContract
,
private
val
dealContract
:
DealContract
)
{
private
fun
fetchUserEstates
(
user
:
UserEntity
):
Observable
<
List
<
EstateEntity
>>
=
Observables
.
zip
(
dealContract
.
fetchDeals
(
user
),
dealContract
.
fetchFavorites
(
user
))
{
t1
,
t2
->
t1
+
t2
}
private
val
fetchAllPlanTypes
=
auth
.
currentUser
()
.
map
{
user
->
val
list
=
user
.
deals
?.
map
{
it
.
estate
as
EstateEntity
}
?.
toMutableList
()
?:
mutableListOf
()
list
.
addAll
(
user
.
estates
?.
map
{
it
as
EstateEntity
}
?:
arrayListOf
())
list
.
flatMap
{
user
->
fetchUserEstates
(
user
)
.
onErrorReturn
{
arrayListOf
()
}
.
map
{
apiList
->
val
list
=
user
.
deals
?.
map
{
it
.
estate
as
EstateEntity
}
?.
toMutableList
()
?:
mutableListOf
()
list
.
addAll
(
user
.
estates
?.
map
{
it
as
EstateEntity
}
?:
arrayListOf
())
(
list
+
apiList
).
distinctBy
{
it
.
id
}
}
}
fun
fetchNotDownloadedPlansSizes
():
Observable
<
Int
>
=
fetchAllPlanTypes
.
flatMapIterable
{
it
}
...
...
app/src/main/java/com/biganto/visual/roompark/presentation/screen/settings/ScreenPresenter.kt
View file @
8e272697
...
...
@@ -18,6 +18,7 @@ import javax.inject.Inject
* Created by Vladislav Bogdashkin on 30.09.2019.
*/
private
const
val
TYPICAL_PLAN_SIZE
=
(
1.2f
*
1024L
*
1024L
).
toLong
()
class
SettingsScreenPresenter
@Inject
constructor
(
private
val
interactor
:
SettingsInteractor
,
...
...
@@ -42,7 +43,7 @@ class SettingsScreenPresenter @Inject constructor(
.
map
{
SettingsScreenViewState
.
OnSizePrefetch
(
it
)
}
val
fetchPlansSize
=
interactor
.
fetchPlanTypesSizes
()
.
map
{
it
*
1024L
*
1024L
}
.
map
{
it
*
TYPICAL_PLAN_SIZE
}
.
map
{
SettingsScreenViewState
.
OnPlanTypesPrefetch
(
it
)
}
val
onDownloadTours
=
intent
(
SettingsScreen
::
downloadAllTours
)
...
...
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