Commit 5ee2709b authored by Vladislav Bogdashkin's avatar Vladislav Bogdashkin 🎣

Merge branch 'feature/prefetch_sizes' into develop

parents 140839e0 6c9a5789
...@@ -34,7 +34,9 @@ ...@@ -34,7 +34,9 @@
<activity android:name=".player.BigantoPlayerActivity" android:screenOrientation="fullSensor" <activity android:name=".player.BigantoPlayerActivity" android:screenOrientation="fullSensor"
android:configChanges="mcc|mnc|locale|touchscreen|keyboard|keyboardHidden|navigation|orientation|screenLayout|uiMode|screenSize|smallestScreenSize|fontScale|layoutDirection|density" android:configChanges="mcc|mnc|locale|touchscreen|keyboard|keyboardHidden|navigation|orientation|screenLayout|uiMode|screenSize|smallestScreenSize|fontScale|layoutDirection|density"
android:largeHeap="true" android:largeHeap="true"
android:hardwareAccelerated="true" android:process=":UnityKillsMe"> </activity> android:hardwareAccelerated="true"
android:process=":UnityKillsMe">
</activity>
<service <service
......
...@@ -210,13 +210,9 @@ class EstateRepository @Inject constructor( ...@@ -210,13 +210,9 @@ class EstateRepository @Inject constructor(
.flatMap { user -> .flatMap { user ->
api.getDeals(TEST_DEAL_TOKEN)//api.getDeals(user.authToken) api.getDeals(TEST_DEAL_TOKEN)//api.getDeals(user.authToken)
.doOnError(Timber::e) .doOnError(Timber::e)
.map { fromRawList(it, ::fromRaw) } .map { List(it.size){index -> fromRaw(it[index],user)} }
.doOnNext {
it.forEach { deal ->
deal.user = user
}
}
.doOnNext(db::blockingUpsert) .doOnNext(db::blockingUpsert)
.doOnNext { db.refreshUser(user) }
} }
private val getDealsDb: Observable<List<DealEntity>> = private val getDealsDb: Observable<List<DealEntity>> =
...@@ -233,7 +229,7 @@ class EstateRepository @Inject constructor( ...@@ -233,7 +229,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
) )
) )
......
...@@ -30,11 +30,15 @@ class ToursRepository @Inject constructor( ...@@ -30,11 +30,15 @@ class ToursRepository @Inject constructor(
override fun deleteToursDbInfo(): Completable = override fun deleteToursDbInfo(): Completable =
Completable.merge(arrayListOf( Completable.merge(
arrayListOf(
db.dropTourFileJuncTable(), db.dropTourFileJuncTable(),
db.dropFileTable(), db.dropFileTable(),
db.dropTourTable() db.dropTourTable(),
)) db.refreshEstatesWithTours()
)
)
// .concatWith { }
.doOnComplete { Timber.w("Completed --") } .doOnComplete { Timber.w("Completed --") }
.doOnError { Timber.e(it) } .doOnError { Timber.e(it) }
......
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.joinToString(separator = ","), 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)
...@@ -62,7 +70,7 @@ class BigantoRetrofitRepository @Inject constructor(@Named("bigantoApi") retrof ...@@ -62,7 +70,7 @@ class BigantoRetrofitRepository @Inject constructor(@Named("bigantoApi") retrof
override fun getOfferTours(multiTourIds:List<Int>): Observable<List<TourPreviewRaw>> = override fun getOfferTours(multiTourIds:List<Int>): Observable<List<TourPreviewRaw>> =
api api
.getOfferTours(offerId = multiTourIds) .getOfferTours(offerId = multiTourIds.joinToString(separator = ","))
.compose(RetrofitResponseValidation()) .compose(RetrofitResponseValidation())
.map { it.values.flatten() } .map { it.values.flatten() }
.doOnError { e(it) } .doOnError { e(it) }
...@@ -70,7 +78,7 @@ class BigantoRetrofitRepository @Inject constructor(@Named("bigantoApi") retrof ...@@ -70,7 +78,7 @@ class BigantoRetrofitRepository @Inject constructor(@Named("bigantoApi") retrof
override fun getOfferTours(multiTourId:Int): Observable<List<TourPreviewRaw>> = override fun getOfferTours(multiTourId:Int): Observable<List<TourPreviewRaw>> =
api api
.getOfferTours(offerId = arrayListOf(multiTourId)) .getOfferTours(offerId = multiTourId.toString())
.compose(RetrofitResponseValidation()) .compose(RetrofitResponseValidation())
.map { it[multiTourId.toString()]?.toList()?: error("No tours avaliable")} .map { it[multiTourId.toString()]?.toList()?: error("No tours avaliable")}
.doOnError { e(it) } .doOnError { e(it) }
......
...@@ -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
...@@ -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: 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,
...@@ -145,7 +156,7 @@ interface IBigantoMobileApi { ...@@ -145,7 +156,7 @@ interface IBigantoMobileApi {
@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(LANG_PARAM) languageCode: String = Locale.getDefault().language, @Query(LANG_PARAM) languageCode: String = Locale.getDefault().language,
@Query(OFFER_GET_TOURS_ID) offerId: List<Int> @Query(OFFER_GET_TOURS_ID) offerId: String
): Observable<Response<Map<String,List<TourPreviewRaw>>>> ): Observable<Response<Map<String,List<TourPreviewRaw>>>>
@Streaming @Streaming
......
...@@ -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,
......
...@@ -36,7 +36,7 @@ private const val TIMEOUT_SECONDS=120L ...@@ -36,7 +36,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.BODY val INTERCEPT_LOG_LEVEL = HttpLoggingInterceptor.Level.HEADERS
@Module @Module
class RetrofitModule{ class RetrofitModule{
......
...@@ -73,4 +73,6 @@ interface IDb { ...@@ -73,4 +73,6 @@ 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>>
fun refreshEstatesWithTours(): Completable
} }
\ No newline at end of file
...@@ -17,6 +17,7 @@ import io.reactivex.rxkotlin.toCompletable ...@@ -17,6 +17,7 @@ import io.reactivex.rxkotlin.toCompletable
import io.reactivex.schedulers.Schedulers import io.reactivex.schedulers.Schedulers
import io.requery.Persistable import io.requery.Persistable
import io.requery.android.sqlite.DatabaseSource import io.requery.android.sqlite.DatabaseSource
import io.requery.kotlin.notNull
import io.requery.reactivex.KotlinReactiveEntityStore import io.requery.reactivex.KotlinReactiveEntityStore
import io.requery.reactivex.ReactiveResult import io.requery.reactivex.ReactiveResult
import io.requery.sql.KotlinEntityDataStore import io.requery.sql.KotlinEntityDataStore
...@@ -56,6 +57,19 @@ class RequeryRepository @Inject constructor( ...@@ -56,6 +57,19 @@ 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 refreshEstatesWithTours(): Completable =
store.select(EstateEntity::class)
.where(EstateEntity::multitourId.notNull())
.get()
.observable()
.toList()
.toObservable()
.doOnNext { Timber.d("bgg ${it.size}") }
.flatMapCompletable{ store.refresh(it).ignoreElement()}
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()
......
...@@ -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>?
......
...@@ -113,11 +113,11 @@ fun fromRaw(raw:DealRaw):DealEntity { ...@@ -113,11 +113,11 @@ fun fromRaw(raw:DealRaw):DealEntity {
} }
fun fromRaw(raw:DealRaw,user:UserEntity):DealEntity { fun fromRaw(raw:DealRaw,user:UserEntity):DealEntity =
val entity = fromRaw(raw) fromRaw(raw).apply {
entity.user = user this.user = user
return entity this.estate.user = user
} }
......
...@@ -182,9 +182,7 @@ class DownloadManagerService @Inject constructor( ...@@ -182,9 +182,7 @@ class DownloadManagerService @Inject constructor(
sink.use { sink.use {
while (!stop && { read = source.read(buffer, step.toLong());read }() != -1L) { while (!stop && { read = source.read(buffer, step.toLong());read }() != -1L) {
model.tempDownloadedSize += read model.tempDownloadedSize += read
if ((System.currentTimeMillis() - timer) > READ_SYNC_MILLS || source.exhausted()) { model.fileDownloadedSize += read
timer = System.currentTimeMillis()
model.fileDownloadedSize += model.tempDownloadedSize
if (model.tempOverallFileSize == 0L) if (model.tempOverallFileSize == 0L)
...@@ -193,11 +191,6 @@ class DownloadManagerService @Inject constructor( ...@@ -193,11 +191,6 @@ class DownloadManagerService @Inject constructor(
model.isDownloaded = (source.exhausted() model.isDownloaded = (source.exhausted()
&& (model.fileDownloadedSize == model.tempOverallFileSize && (model.fileDownloadedSize == model.tempOverallFileSize
|| model.tempOverallFileSize == 0L)) || model.tempOverallFileSize == 0L))
model.tempTourTotalDiff = 0
model.tempDownloadedSize = 0
}
} }
} }
...@@ -286,6 +279,7 @@ class DownloadManagerService @Inject constructor( ...@@ -286,6 +279,7 @@ class DownloadManagerService @Inject constructor(
totalSize += file.totalSize totalSize += file.totalSize
entity entity
} }
Timber.w("fffff $downloadedSize $totalSize")
setDownloadInfo( setDownloadInfo(
raw.id.toString() raw.id.toString()
...@@ -343,6 +337,7 @@ class DownloadManagerService @Inject constructor( ...@@ -343,6 +337,7 @@ class DownloadManagerService @Inject constructor(
.observeOn(Schedulers.computation()) .observeOn(Schedulers.computation())
// .doOnNext{Timber.d("7 ${it}")} // .doOnNext{Timber.d("7 ${it}")}
.flatMap { model -> .flatMap { model ->
Timber.d(" model __ ${model}")
setDownloadInfo( setDownloadInfo(
model.tourId model.tourId
, totalSizedDiffSize = model.tempTourTotalDiff , totalSizedDiffSize = model.tempTourTotalDiff
......
...@@ -31,6 +31,8 @@ class SettingsInteractor @Inject constructor( ...@@ -31,6 +31,8 @@ class SettingsInteractor @Inject constructor(
private val toursUc: TourPreviewsUseCase private val toursUc: TourPreviewsUseCase
){ ){
fun fetchToursSizes() = toursUc.fetchToursSizes()
private fun startDownloadService() { private fun startDownloadService() {
val i = Intent(activity, DownloadManagerService::class.java) val i = Intent(activity, DownloadManagerService::class.java)
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) { if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
......
...@@ -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,108 @@ class TourPreviewsUseCase @Inject constructor( ...@@ -171,13 +174,108 @@ 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(): Observable<Long> =
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!!)
}
Timber.d(" targer estates : " +
"${estates.map { it.tours?.size }} " )
Timber.d(" targer toursOffersToLoad : $toursOffersToLoad " )
Pair(estates,toursOffersToLoad)
}
.flatMap { pair ->
if (pair.second.isNotEmpty()) {
val loadedIds = mutableListOf<String>()
return@flatMap Observable.merge(
pair.second.map {
fetchTourOffer(
it, pair.first.first { estete -> estete.multitourId == it }.id
).doOnError { Timber.e(it) }
.doOnNext { tours -> loadedIds.addAll(tours.map{ t -> t.tour_id }) }
}
).takeLast(1)
.doOnNext { db.refreshEntities(pair.first) }
.map { Pair(pair.first,loadedIds )}
}
else return@flatMap Observable.just(Pair(pair.first,null))
}
.doOnNext { Timber.d(" HERER ") }
.flatMap { pair ->
val estates = pair.first
for (estate in estates) {
Timber.d(" targer estates : ${estate.user} " )
}
val r = (estates.first().user as UserEntity).targetResolution
Timber.d(" targer R : $r " )
var knownSize =
estates.flatMap {
it.tours?.map {t -> t as TourPreviewEntity}
?.asIterable()?: arrayListOf()
}.filter{t -> t.overallSize > 0L }
.onEach { Timber.d("it.overallSize - it.downloadedSize " +
"${it.overallSize}/${it.downloadedSize}") }
.sumByLong { it.overallSize - it.downloadedSize }
Timber.d(" targer knownSize : $knownSize " )
val toursToLoadSize =
estates.flatMap {
it.tours?.map {t -> t as TourPreviewEntity}
?.asIterable()?: arrayListOf()
}.filter{t -> t.overallSize < 1L }
Timber.d(" targer toursToLoadSize : $toursToLoadSize " )
val listIds = toursToLoadSize.map { it.id }.toMutableList()
pair.second?.let { listIds.addAll(it)}
Timber.d(" targer estates : ${listIds} " )
if (listIds.isNullOrEmpty()) return@flatMap Observable.just(knownSize)
else return@flatMap api.getTourFilesSizes(
listIds,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()
......
...@@ -150,6 +150,7 @@ class SettingsScreenController : ...@@ -150,6 +150,7 @@ class SettingsScreenController :
is SettingsScreenViewState.LoadSubscriptions -> render(viewState) is SettingsScreenViewState.LoadSubscriptions -> render(viewState)
is SettingsScreenViewState.SubscriptionStatus -> render(viewState) is SettingsScreenViewState.SubscriptionStatus -> render(viewState)
is SettingsScreenViewState.SubscriptionError -> render(viewState) is SettingsScreenViewState.SubscriptionError -> render(viewState)
is SettingsScreenViewState.OnSizePrefetch -> render(viewState)
} }
} }
...@@ -161,6 +162,14 @@ class SettingsScreenController : ...@@ -161,6 +162,14 @@ class SettingsScreenController :
clearCacheButton.setGone(false) clearCacheButton.setGone(false)
} }
private fun render(viewState: SettingsScreenViewState.OnSizePrefetch) {
toursDownloaderTitle.text =
resources?.getString(
R.string.download_all_tours_settings_with_size
, viewState.size.bytesToSize()
)
}
private fun render(viewState: SettingsScreenViewState.LoadSubscriptions){ private fun render(viewState: SettingsScreenViewState.LoadSubscriptions){
(pushRecycler.adapter as PushListAdapter).setItems(viewState.list) (pushRecycler.adapter as PushListAdapter).setItems(viewState.list)
} }
......
...@@ -38,6 +38,9 @@ class SettingsScreenPresenter @Inject constructor( ...@@ -38,6 +38,9 @@ class SettingsScreenPresenter @Inject constructor(
override fun bindIntents() { override fun bindIntents() {
val fetchToursSize = interactor.fetchToursSizes()
.map { SettingsScreenViewState.OnSizePrefetch(it) }
val onDownloadTours = intent(SettingsScreen::downloadAllTours) val onDownloadTours = intent(SettingsScreen::downloadAllTours)
.flatMap { interactor.startToursDownloading() .flatMap { interactor.startToursDownloading()
.andThen(Observable.just(SettingsScreenViewState.Idle())) .andThen(Observable.just(SettingsScreenViewState.Idle()))
...@@ -120,7 +123,8 @@ class SettingsScreenPresenter @Inject constructor( ...@@ -120,7 +123,8 @@ class SettingsScreenPresenter @Inject constructor(
fetchSubscriptions, fetchSubscriptions,
fetchCache, fetchCache,
onSubChecked, onSubChecked,
onDownloadTours onDownloadTours,
fetchToursSize
) )
) )
.doOnError { Timber.e(it) } .doOnError { Timber.e(it) }
......
...@@ -18,6 +18,7 @@ sealed class SettingsScreenViewState : BigantoBaseViewState() { ...@@ -18,6 +18,7 @@ sealed class SettingsScreenViewState : BigantoBaseViewState() {
class SomeError(val exception: ExceptionString) : SettingsScreenViewState() class SomeError(val exception: ExceptionString) : SettingsScreenViewState()
class SignOut() : SettingsScreenViewState() class SignOut() : SettingsScreenViewState()
class OnCacheDeleting(val progress:Float) : SettingsScreenViewState() class OnCacheDeleting(val progress:Float) : SettingsScreenViewState()
class OnSizePrefetch(val size:Long) : SettingsScreenViewState()
class LoadSubscriptions(val list:List<TitledSubscriptionModel>) : SettingsScreenViewState() class LoadSubscriptions(val list:List<TitledSubscriptionModel>) : SettingsScreenViewState()
class LoadCachInfo(val list: List<CachedDataModel>) : SettingsScreenViewState() class LoadCachInfo(val list: List<CachedDataModel>) : SettingsScreenViewState()
class SubscriptionStatus(val subId:Int,val subState: Boolean) : SettingsScreenViewState() class SubscriptionStatus(val subId:Int,val subState: Boolean) : SettingsScreenViewState()
......
...@@ -56,9 +56,7 @@ ...@@ -56,9 +56,7 @@
android:layout_marginEnd="32dp" android:layout_marginEnd="32dp"
android:layout_weight="1" android:layout_weight="1"
android:gravity="start|center_vertical" android:gravity="start|center_vertical"
android:text="Скачать карточки моих android:text="@string/download_all_plan_types_settings_with_sizes" />
квартир из избранного
и сделок (4 MB)" />
<ImageView <ImageView
android:id="@+id/downloadFlatCardsIcon" android:id="@+id/downloadFlatCardsIcon"
...@@ -89,9 +87,7 @@ ...@@ -89,9 +87,7 @@
android:layout_marginEnd="32dp" android:layout_marginEnd="32dp"
android:layout_weight="1" android:layout_weight="1"
android:gravity="start|center_vertical" android:gravity="start|center_vertical"
android:text="Скачать виртуальные туры android:text="@string/download_all_tours_settings_with_size" />
моих квартир из избранного
и сделок (477 MB)" />
<ImageView <ImageView
android:id="@+id/downloadToursIcon" android:id="@+id/downloadToursIcon"
......
...@@ -121,5 +121,7 @@ ...@@ -121,5 +121,7 @@
<string name="game_view_content_description" /> <string name="game_view_content_description" />
<string name="download_all_tours_settings_with_size">Скачать виртуальные туры моих квартир из избранного и сделок (%s)</string>
<string name="download_all_plan_types_settings_with_sizes">Скачать карточки моих квартир из избранного и сделок (%s)</string>
</resources> </resources>
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment