Commit cc82fe5f authored by Vladislav Bogdashkin's avatar Vladislav Bogdashkin 🎣

provide plan sizes to presentation;

fix di invalid name
parent 53a5764f
......@@ -78,7 +78,7 @@ class PlanRepository @Inject constructor(
.subscribeOn(Schedulers.io())
private fun getPlanFile(featuresVariant: PlanFeaturesVariant)
override fun getPlanFile(featuresVariant: PlanFeaturesVariant)
= getPlanFile(
estateId = featuresVariant.estateId,
planId = featuresVariant.planId,
......@@ -88,7 +88,7 @@ class PlanRepository @Inject constructor(
electric = featuresVariant.electric
)
private fun getPlanFile(estateId: Int
fun getPlanFile(estateId: Int
, planId:Int
, furniture:Boolean? = null
, sizes:Boolean? = null
......@@ -136,6 +136,7 @@ class PlanRepository @Inject constructor(
// fun getPlanRequestString(estateId: Int
// , planId:Int
// , furniture:Boolean
......
......@@ -62,7 +62,7 @@ abstract class ContractRepositoryModule {
@Binds
@Singleton
abstract fun provideTourContract(impl: PlanRepository): FlatPlanContract
abstract fun providePlanContract(impl: PlanRepository): FlatPlanContract
}
......
package com.biganto.visual.roompark.domain.contract
import com.biganto.visual.roompark.data.data_provider.PlanFeaturesVariant
import com.biganto.visual.roompark.domain.model.PlanPresetModel
import io.reactivex.Observable
import java.io.File
/**
* Created by Vladislav Bogdashkin on 20.04.2020.
......@@ -18,4 +20,5 @@ interface FlatPlanContract{
, walls:Boolean?
, electric:Boolean?): Observable<String>
fun getPlanFile(featuresVariant: PlanFeaturesVariant): File
}
\ No newline at end of file
......@@ -28,11 +28,14 @@ class SettingsInteractor @Inject constructor(
private val settingsUseCase: SettingsUseCase,
private val activity: BaseRoomParkActivity,
private val subUc: SubscriptionUseCase,
private val toursUc: TourPreviewsUseCase
private val toursUc: TourPreviewsUseCase,
private val planTypes: PlanTypesUseCase
){
fun fetchToursSizes() = toursUc.fetchToursSizes()
fun fetchPlanTypesSizes() = planTypes.fetchNotDownloadedPlansSizes()
private fun startDownloadService() {
val i = Intent(activity, DownloadManagerService::class.java)
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
......
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.domain.contract.AuthContract
import com.biganto.visual.roompark.domain.contract.FlatPlanContract
import io.reactivex.BackpressureStrategy
import io.reactivex.schedulers.Schedulers
import timber.log.Timber
import javax.inject.Inject
/**
......@@ -13,20 +18,33 @@ class PlanTypesUseCase @Inject constructor(
private val auth:AuthContract
){
// fun fetchNotDownloadedPlansSizes() =
// 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
// }
// .flatMapIterable { it }
// .toFlowable(BackpressureStrategy.BUFFER)
// .parallel(4)
// .runOn(Schedulers.io())
// .flatMap { planContract.getPlanTypes(it.id) }
fun fetchNotDownloadedPlansSizes() =
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
}
.flatMapIterable { it }
.toFlowable(BackpressureStrategy.BUFFER)
.parallel(4)
.runOn(Schedulers.io())
.flatMap{
planContract.getPlanTypes(it.id)
.map { plantypes -> plantypes.flatMap{ plan -> plan.featuresVariants} }
.toFlowable(BackpressureStrategy.BUFFER)
}
.sequential()
.toList()
.toObservable()
.map { it.flatten() }
.doOnNext { Timber.d(" plaanzz: $it") }
.map { list ->
list.sumBy{ if (planContract.getPlanFile(it).exists()) 0 else 1 }
}
......
......@@ -155,6 +155,7 @@ class SettingsScreenController :
is SettingsScreenViewState.SomeError -> render(viewState)
is SettingsScreenViewState.SignOut -> render(viewState)
is SettingsScreenViewState.OnCacheDeleting -> render(viewState)
is SettingsScreenViewState.OnPlanTypesPrefetch -> render(viewState)
is SettingsScreenViewState.LoadCachInfo -> render(viewState)
is SettingsScreenViewState.LoadSubscriptions -> render(viewState)
is SettingsScreenViewState.SubscriptionStatus -> render(viewState)
......@@ -179,6 +180,14 @@ class SettingsScreenController :
)
}
private fun render(viewState: SettingsScreenViewState.OnPlanTypesPrefetch) {
flatDownloaderTitle.text =
resources?.getString(
R.string.download_all_plan_types_settings_with_sizes
, viewState.size.bytesToSize()
)
}
private fun render(viewState: SettingsScreenViewState.LoadSubscriptions){
(pushRecycler.adapter as PushListAdapter).setItems(viewState.list)
}
......
......@@ -41,6 +41,10 @@ class SettingsScreenPresenter @Inject constructor(
val fetchToursSize = interactor.fetchToursSizes()
.map { SettingsScreenViewState.OnSizePrefetch(it) }
val fetchPlansSize = interactor.fetchPlanTypesSizes()
.map { it*1024L }
.map { SettingsScreenViewState.OnPlanTypesPrefetch(it) }
val onDownloadTours = intent(SettingsScreen::downloadAllTours)
.flatMap { interactor.startToursDownloading()
.andThen(Observable.just(SettingsScreenViewState.Idle()))
......@@ -116,6 +120,7 @@ class SettingsScreenPresenter @Inject constructor(
val state = Observable.mergeDelayError(
arrayListOf(
restoreStateObservable,
fetchPlansSize,
fetchSettings,
onSignOut,
onClearCache,
......
......@@ -19,6 +19,7 @@ sealed class SettingsScreenViewState : BigantoBaseViewState() {
class SignOut() : SettingsScreenViewState()
class OnCacheDeleting(val progress:Float) : SettingsScreenViewState()
class OnSizePrefetch(val size:Long) : SettingsScreenViewState()
class OnPlanTypesPrefetch(val size:Long) : SettingsScreenViewState()
class LoadSubscriptions(val list:List<TitledSubscriptionModel>) : SettingsScreenViewState()
class LoadCachInfo(val list: List<CachedDataModel>) : SettingsScreenViewState()
class SubscriptionStatus(val subId:Int,val subState: Boolean) : SettingsScreenViewState()
......
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