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
3214a4f8
Commit
3214a4f8
authored
Apr 16, 2020
by
Vladislav Bogdashkin
🎣
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
fetch size method
parent
140839e0
Changes
9
Show whitespace changes
Inline
Side-by-side
Showing
9 changed files
with
117 additions
and
5 deletions
+117
-5
EstateRepository.kt
...to/visual/roompark/data/data_provider/EstateRepository.kt
+1
-1
BigantoRetrofitRepository.kt
.../data/repository/api/biganto/BigantoRetrofitRepository.kt
+8
-0
IBigantoApi.kt
...isual/roompark/data/repository/api/biganto/IBigantoApi.kt
+5
-0
IBigantoMobileApi.kt
...roompark/data/repository/api/biganto/IBigantoMobileApi.kt
+11
-0
RawData.kt
...isual/roompark/data/repository/api/biganto/raw/RawData.kt
+7
-0
IDb.kt
...ava/com/biganto/visual/roompark/data/repository/db/IDb.kt
+1
-0
RequeryRepository.kt
.../roompark/data/repository/db/requrey/RequeryRepository.kt
+3
-0
Estate.kt
...isual/roompark/data/repository/db/requrey/model/Estate.kt
+1
-0
toures.kt
...ava/com/biganto/visual/roompark/domain/use_case/toures.kt
+80
-4
No files found.
app/src/main/java/com/biganto/visual/roompark/data/data_provider/EstateRepository.kt
View file @
3214a4f8
...
@@ -233,7 +233,7 @@ class EstateRepository @Inject constructor(
...
@@ -233,7 +233,7 @@ class EstateRepository @Inject constructor(
override
fun
getDeals
():
Observable
<
List
<
DealModel
>>
{
override
fun
getDeals
():
Observable
<
List
<
DealModel
>>
{
return
Observable
.
mergeDelayError
(
return
Observable
.
mergeDelayError
(
arrayListOf
(
arrayListOf
(
//
getDealsDb,
getDealsDb
,
getDealsApi
getDealsApi
)
)
)
)
...
...
app/src/main/java/com/biganto/visual/roompark/data/repository/api/biganto/BigantoRetrofitRepository.kt
View file @
3214a4f8
package
com.biganto.visual.roompark.data.repository.api.biganto
package
com.biganto.visual.roompark.data.repository.api.biganto
import
com.biganto.visual.roompark.data.repository.api.biganto.raw.TourFilesDataRaw
import
com.biganto.visual.roompark.data.repository.api.biganto.raw.TourFilesDataRaw
import
com.biganto.visual.roompark.data.repository.api.biganto.raw.TourFilesSimpleDataRaw
import
com.biganto.visual.roompark.data.repository.api.biganto.raw.TourPreviewRaw
import
com.biganto.visual.roompark.data.repository.api.biganto.raw.TourPreviewRaw
import
io.reactivex.*
import
io.reactivex.*
import
io.reactivex.schedulers.Schedulers
import
io.reactivex.schedulers.Schedulers
...
@@ -53,6 +54,13 @@ class BigantoRetrofitRepository @Inject constructor(@Named("bigantoApi") retrof
...
@@ -53,6 +54,13 @@ class BigantoRetrofitRepository @Inject constructor(@Named("bigantoApi") retrof
.
doOnError
{
e
(
it
)
}
.
doOnError
{
e
(
it
)
}
.
subscribeOn
(
Schedulers
.
io
())
.
subscribeOn
(
Schedulers
.
io
())
override
fun
getTourFilesSizes
(
ids
:
List
<
String
>,
resolution
:
String
)
:
Observable
<
List
<
TourFilesSimpleDataRaw
>>
=
api
.
getTourFilesSize
(
ids
=
ids
,
resolution
=
resolution
)
.
compose
(
RetrofitResponseValidation
())
.
doOnError
{
e
(
it
)
}
.
subscribeOn
(
Schedulers
.
io
())
override
fun
downloadFile
(
uri
:
String
,
headers
:
Map
<
String
,
String
>?):
Flowable
<
ResponseBody
>
=
api
override
fun
downloadFile
(
uri
:
String
,
headers
:
Map
<
String
,
String
>?):
Flowable
<
ResponseBody
>
=
api
.
requestFile
(
headers
?:
HashMap
<
String
,
String
>(),
uri
)
.
requestFile
(
headers
?:
HashMap
<
String
,
String
>(),
uri
)
...
...
app/src/main/java/com/biganto/visual/roompark/data/repository/api/biganto/IBigantoApi.kt
View file @
3214a4f8
...
@@ -2,6 +2,7 @@ package com.biganto.visual.roompark.data.repository.api.biganto
...
@@ -2,6 +2,7 @@ package com.biganto.visual.roompark.data.repository.api.biganto
import
com.biganto.visual.roompark.data.repository.api.biganto.raw.AppVersionRaw
import
com.biganto.visual.roompark.data.repository.api.biganto.raw.AppVersionRaw
import
com.biganto.visual.roompark.data.repository.api.biganto.raw.TourFilesDataRaw
import
com.biganto.visual.roompark.data.repository.api.biganto.raw.TourFilesDataRaw
import
com.biganto.visual.roompark.data.repository.api.biganto.raw.TourFilesSimpleDataRaw
import
com.biganto.visual.roompark.data.repository.api.biganto.raw.TourPreviewRaw
import
com.biganto.visual.roompark.data.repository.api.biganto.raw.TourPreviewRaw
import
io.reactivex.Flowable
import
io.reactivex.Flowable
import
io.reactivex.Observable
import
io.reactivex.Observable
...
@@ -26,4 +27,8 @@ interface IBigantoApi {
...
@@ -26,4 +27,8 @@ interface IBigantoApi {
fun
getOfferTours
(
multiTourId
:
Int
):
Observable
<
List
<
TourPreviewRaw
>>
fun
getOfferTours
(
multiTourId
:
Int
):
Observable
<
List
<
TourPreviewRaw
>>
fun
getOfferTours
(
multiTourIds
:
List
<
Int
>):
Observable
<
List
<
TourPreviewRaw
>>
fun
getOfferTours
(
multiTourIds
:
List
<
Int
>):
Observable
<
List
<
TourPreviewRaw
>>
fun
getTourFilesSizes
(
ids
:
List
<
String
>,
resolution
:
String
):
Observable
<
List
<
TourFilesSimpleDataRaw
>>
}
}
\ No newline at end of file
app/src/main/java/com/biganto/visual/roompark/data/repository/api/biganto/IBigantoMobileApi.kt
View file @
3214a4f8
...
@@ -2,6 +2,7 @@ package com.biganto.visual.roompark.data.repository.api.biganto
...
@@ -2,6 +2,7 @@ package com.biganto.visual.roompark.data.repository.api.biganto
import
com.biganto.visual.roompark.data.repository.api.biganto.raw.AppVersionRaw
import
com.biganto.visual.roompark.data.repository.api.biganto.raw.AppVersionRaw
import
com.biganto.visual.roompark.data.repository.api.biganto.raw.TourFilesDataRaw
import
com.biganto.visual.roompark.data.repository.api.biganto.raw.TourFilesDataRaw
import
com.biganto.visual.roompark.data.repository.api.biganto.raw.TourFilesSimpleDataRaw
import
com.biganto.visual.roompark.data.repository.api.biganto.raw.TourPreviewRaw
import
com.biganto.visual.roompark.data.repository.api.biganto.raw.TourPreviewRaw
import
com.google.gson.JsonArray
import
com.google.gson.JsonArray
import
io.reactivex.Flowable
import
io.reactivex.Flowable
...
@@ -129,6 +130,16 @@ interface IBigantoMobileApi {
...
@@ -129,6 +130,16 @@ interface IBigantoMobileApi {
@Query
(
GET_TOURS_FILES_RESOLUTION
)
resolution
:
String
@Query
(
GET_TOURS_FILES_RESOLUTION
)
resolution
:
String
):
Observable
<
Response
<
List
<
TourFilesDataRaw
>>>
):
Observable
<
Response
<
List
<
TourFilesDataRaw
>>>
@GET
(
"$API_URL$GET_TOURS_FILES_METHOD$DELIMITER"
)
fun
getTourFilesSize
(
@Query
(
CLIENT_TYPE_PARAM
)
clientType
:
String
=
DEFAULT_CLIENT_TYPE
,
@Query
(
CLIENT_VERSION_PARAM
)
clientVersion
:
String
=
DEFAULT_CLIENT_VERSION
,
@Query
(
API_VERSION_PARAM
)
apiVersion
:
String
=
DEFAULT_API_VERSION
,
@Query
(
LANG_PARAM
)
languageCode
:
String
=
Locale
.
getDefault
().
language
,
@Query
(
GET_TOURS_FILES_ID
)
ids
:
List
<
String
>,
@Query
(
GET_TOURS_FILES_RESOLUTION
)
resolution
:
String
):
Observable
<
Response
<
List
<
TourFilesSimpleDataRaw
>>>
@GET
(
"$API_URL$GET_APP_VERSION$DELIMITER"
)
@GET
(
"$API_URL$GET_APP_VERSION$DELIMITER"
)
fun
getAppVersion
(
fun
getAppVersion
(
@Query
(
CLIENT_TYPE_PARAM
)
clientType
:
String
=
DEFAULT_CLIENT_TYPE
,
@Query
(
CLIENT_TYPE_PARAM
)
clientType
:
String
=
DEFAULT_CLIENT_TYPE
,
...
...
app/src/main/java/com/biganto/visual/roompark/data/repository/api/biganto/raw/RawData.kt
View file @
3214a4f8
...
@@ -82,6 +82,13 @@ data class TourFileRaw(
...
@@ -82,6 +82,13 @@ data class TourFileRaw(
)
)
data class
TourFilesSimpleDataRaw
(
val
id
:
Int
,
val
resolution
:
Int
,
val
total_size
:
Long
,
val
errors
:
List
<
ErrorRaw
>?
)
data class
TourFilesDataRaw
(
data class
TourFilesDataRaw
(
val
files
:
List
<
TourFileRaw
>,
val
files
:
List
<
TourFileRaw
>,
val
id
:
Int
,
val
id
:
Int
,
...
...
app/src/main/java/com/biganto/visual/roompark/data/repository/db/IDb.kt
View file @
3214a4f8
...
@@ -73,4 +73,5 @@ interface IDb {
...
@@ -73,4 +73,5 @@ interface IDb {
fun
dropTourFileJuncTable
():
Completable
fun
dropTourFileJuncTable
():
Completable
fun
dropTourTable
():
Completable
fun
dropTourTable
():
Completable
fun
refreshUser
(
userEntity
:
UserEntity
):
Observable
<
UserEntity
>
fun
refreshUser
(
userEntity
:
UserEntity
):
Observable
<
UserEntity
>
fun
refreshEntities
(
entities
:
List
<
Persistable
>):
Observable
<
Iterable
<
Persistable
>>
}
}
\ No newline at end of file
app/src/main/java/com/biganto/visual/roompark/data/repository/db/requrey/RequeryRepository.kt
View file @
3214a4f8
...
@@ -56,6 +56,9 @@ class RequeryRepository @Inject constructor(
...
@@ -56,6 +56,9 @@ class RequeryRepository @Inject constructor(
override
fun
refreshUser
(
userEntity
:
UserEntity
):
Observable
<
UserEntity
>
=
override
fun
refreshUser
(
userEntity
:
UserEntity
):
Observable
<
UserEntity
>
=
store
.
refresh
(
userEntity
).
toObservable
()
store
.
refresh
(
userEntity
).
toObservable
()
override
fun
refreshEntities
(
entities
:
List
<
Persistable
>):
Observable
<
Iterable
<
Persistable
>>
=
store
.
refresh
(
entities
).
toObservable
()
override
fun
dropTourTable
()
=
store
.
delete
(
TourPreviewEntity
::
class
).
get
().
toCompletable
()
override
fun
dropTourTable
()
=
store
.
delete
(
TourPreviewEntity
::
class
).
get
().
toCompletable
()
override
fun
dropTourFileJuncTable
()
=
store
.
delete
(
TourFileJunctionEntity
::
class
).
get
().
toCompletable
()
override
fun
dropTourFileJuncTable
()
=
store
.
delete
(
TourFileJunctionEntity
::
class
).
get
().
toCompletable
()
...
...
app/src/main/java/com/biganto/visual/roompark/data/repository/db/requrey/model/Estate.kt
View file @
3214a4f8
...
@@ -39,6 +39,7 @@ interface Estate : Persistable {
...
@@ -39,6 +39,7 @@ interface Estate : Persistable {
@get
:
Nullable
@get
:
Nullable
val
multitourId
:
Int
?
val
multitourId
:
Int
?
@get
:
Nullable
@get
:
Nullable
@get
:
OneToMany
(
mappedBy
=
"estate"
)
@get
:
OneToMany
(
mappedBy
=
"estate"
)
val
tours
:
Set
<
TourPreview
>?
val
tours
:
Set
<
TourPreview
>?
...
...
app/src/main/java/com/biganto/visual/roompark/domain/use_case/toures.kt
View file @
3214a4f8
...
@@ -4,7 +4,9 @@ import android.content.res.Resources
...
@@ -4,7 +4,9 @@ import android.content.res.Resources
import
com.biganto.visual.roompark.data.repository.api.biganto.IBigantoApi
import
com.biganto.visual.roompark.data.repository.api.biganto.IBigantoApi
import
com.biganto.visual.roompark.data.repository.api.biganto.raw.TourPreviewRaw
import
com.biganto.visual.roompark.data.repository.api.biganto.raw.TourPreviewRaw
import
com.biganto.visual.roompark.data.repository.db.IDb
import
com.biganto.visual.roompark.data.repository.db.IDb
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.TourContract
import
com.biganto.visual.roompark.domain.custom_exception.CustomApiException
import
com.biganto.visual.roompark.domain.custom_exception.CustomApiException
import
com.biganto.visual.roompark.domain.model.TourModel
import
com.biganto.visual.roompark.domain.model.TourModel
import
com.biganto.visual.roompark.domain.model.fromEntity
import
com.biganto.visual.roompark.domain.model.fromEntity
...
@@ -28,6 +30,7 @@ class TourPreviewsUseCase @Inject constructor(
...
@@ -28,6 +30,7 @@ class TourPreviewsUseCase @Inject constructor(
private
val
api
:
IBigantoApi
private
val
api
:
IBigantoApi
,
private
val
db
:
IDb
,
private
val
db
:
IDb
,
private
val
auth
:
AuthContract
,
private
val
auth
:
AuthContract
,
private
val
tours
:
TourContract
)
{
)
{
fun
getTourById
(
tourId
:
String
):
Observable
<
DownloadTourByIdResult
>
{
fun
getTourById
(
tourId
:
String
):
Observable
<
DownloadTourByIdResult
>
{
...
@@ -171,13 +174,86 @@ class TourPreviewsUseCase @Inject constructor(
...
@@ -171,13 +174,86 @@ class TourPreviewsUseCase @Inject constructor(
return
fromApi
return
fromApi
}
}
private
fun
getUserEstates
(
user
:
UserEntity
)
=
user
.
deals
?.
map
{
it
.
estate
}
?.
plus
(
user
.
estates
?.
asSequence
()
?.
filter
{
it
.
favorite
}
?.
asIterable
()
?:
arrayListOf
()
)
fun
fetchToursSizes
()
=
auth
.
currentUser
()
.
map
(
::
getUserEstates
)
.
map
{
it
.
filter
{
estates
->
estates
.
multitourId
!=
null
}.
toList
()
}
.
map
{
estates
->
val
toursOffersToLoad
=
mutableListOf
<
Int
>()
estates
.
forEach
{
if
(
it
.
tours
.
isNullOrEmpty
())
toursOffersToLoad
.
add
(
it
.
multitourId
!!
)
}
Pair
(
estates
,
toursOffersToLoad
)
}
.
flatMap
{
pair
->
if
(!
pair
.
second
.
isEmpty
())
return
@flatMap
Observable
.
fromIterable
(
pair
.
second
)
.
flatMap
{
fetchTourOffer
(
it
,
pair
.
first
.
first
{
estete
->
estete
.
multitourId
==
it
}.
id
)
}
.
doOnNext
{
db
.
refreshEntities
(
pair
.
first
)
}
.
map
{
pair
.
first
}
else
return
@flatMap
Observable
.
just
(
pair
.
first
)
}
.
flatMap
{
estates
->
val
r
=
(
estates
.
first
().
user
as
UserEntity
).
targetResolution
var
knownSize
=
estates
.
flatMap
{
it
.
tours
?.
map
{
t
->
t
as
TourPreviewEntity
}
?.
asIterable
()
?:
arrayListOf
()
}.
filter
{
t
->
t
.
overallSize
>
0L
}
.
sumByLong
{
it
.
overallSize
-
it
.
downloadedSize
}
val
toursToLoadSize
=
estates
.
flatMap
{
it
.
tours
?.
map
{
t
->
t
as
TourPreviewEntity
}
?.
asIterable
()
?:
arrayListOf
()
}.
filter
{
t
->
t
.
overallSize
<
1L
}
if
(
toursToLoadSize
.
isNullOrEmpty
())
return
@flatMap
Observable
.
just
(
knownSize
)
else
return
@flatMap
api
.
getTourFilesSizes
(
toursToLoadSize
.
map
{
it
.
id
},
r
.
toString
()
)
.
flatMapIterable
{
it
}
.
flatMap
{
rawSize
->
db
.
getTourPreview
(
rawSize
.
id
.
toString
())
.
observable
()
.
map
{
entity
->
knownSize
+=
rawSize
.
total_size
entity
.
apply
{
overallSize
=
rawSize
.
total_size
targetResolution
=
rawSize
.
resolution
}
entity
}
.
doOnNext
{
db
.
upsert
(
it
).
blockingGet
()
}
}.
map
{
knownSize
}
}
.
subscribeOn
(
Schedulers
.
io
())
private
inline
fun
<
T
>
Iterable
<
T
>.
sumByLong
(
selector
:
(
T
)
->
Long
):
Long
{
var
sum
=
0L
for
(
element
in
this
)
{
sum
+=
selector
(
element
)
}
return
sum
}
fun
downloadAllDeelsAndEstates
():
Observable
<
Iterable
<
TourPreviewEntity
>>
=
fun
downloadAllDeelsAndEstates
():
Observable
<
Iterable
<
TourPreviewEntity
>>
=
auth
.
currentUser
()
auth
.
currentUser
()
.
map
{
user
->
.
map
{
user
->
val
estatesList
=
val
estatesList
=
getUserEstates
(
user
)
user
.
deals
?.
map
{
it
.
estate
}
?.
plus
(
user
.
estates
?.
asIterable
()
?:
arrayListOf
()
)
estatesList
estatesList
?.
asSequence
()
?.
asSequence
()
...
...
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