Commit 02226f64 authored by Vladislav Bogdashkin's avatar Vladislav Bogdashkin 🎣

finish fetching sizes plan types

parent cc82fe5f
......@@ -151,34 +151,38 @@ private fun BitSet.getOrNull(index:Int) =
if (index<0 || index>=this.size()) null
else get(index)
private fun Int.getBit(index: Int): Boolean? {
if (index<0) return null
return Integer.toBinaryString(shr(index)).last()=='1'
}
val PlanPresetModel.featuresVariants : List<PlanFeaturesVariant>
get() {
if (this.features.isNullOrEmpty()) return arrayListOf()
val maxInd = this.features.size
val variants = BitSet(maxInd).apply { for (i in 0 until size()) set(i,false) }
val f = features.indexOfFirst { it is FeatureModel.Furniture }
val s = features.indexOfFirst { it is FeatureModel.Sizes }
val e = features.indexOfFirst { it is FeatureModel.Electric }
val w = features.indexOfFirst { it is FeatureModel.Walls }
val trueBit = BitSet(1).apply { set(0,true) }
var firstRun = true
val resList = mutableListOf<PlanFeaturesVariant>()
var increment = 0
var allTrue: Boolean
do{
if (firstRun) firstRun = false
else variants.and(trueBit)
val v = PlanFeaturesVariant(
estateId,planId,
furniture = variants.getOrNull(f),
sizes = variants.getOrNull(s),
electric = variants.getOrNull(e),
walls = variants.getOrNull(w)
furniture = increment.getBit(f),
sizes = increment.getBit(s),
electric = increment.getBit(e),
walls = increment.getBit(w)
)
allTrue = v.furniture?:true && v.electric?:true && v.sizes?:true && v.walls?:true
resList.add(v)
}while (variants.cardinality() != variants.size())
increment++
}while (!allTrue)
return resList
}
......
......@@ -4,9 +4,6 @@ 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
/**
......@@ -28,26 +25,10 @@ class PlanTypesUseCase @Inject constructor(
list
}
.flatMapIterable { it }
.toFlowable(BackpressureStrategy.BUFFER)
.parallel(4)
.runOn(Schedulers.io())
.flatMap{
.flatMap {
planContract.getPlanTypes(it.id)
.map { plantypes -> plantypes.flatMap{ plan -> plan.featuresVariants} }
.toFlowable(BackpressureStrategy.BUFFER)
.map { plantypes -> plantypes.flatMap { plan -> plan.featuresVariants }}
}
.sequential()
.toList()
.toObservable()
.map { it.flatten() }
.doOnNext { Timber.d(" plaanzz: $it") }
.map { list ->
list.sumBy{ if (planContract.getPlanFile(it).exists()) 0 else 1 }
}
.map { list -> list.sumBy{ if (planContract.getPlanFile(it).exists()) 0 else 1 }}
.scan { t1: Int, t2: Int -> t1+t2}
}
......@@ -136,11 +136,11 @@ class SettingsScreenController :
toursDownloaderTitle.text =
resources
?.getString(R.string.download_all_tours_settings_with_size, "")
?.getString(R.string.download_all_tours_settings_with_size, "-")
flatDownloaderTitle.text =
resources
?.getString(R.string.download_all_plan_types_settings_with_sizes, "")
?.getString(R.string.download_all_plan_types_settings_with_sizes, "-")
setToolbar()
bindRecycler()
......
......@@ -42,7 +42,7 @@ class SettingsScreenPresenter @Inject constructor(
.map { SettingsScreenViewState.OnSizePrefetch(it) }
val fetchPlansSize = interactor.fetchPlanTypesSizes()
.map { it*1024L }
.map { it*1024L*1024L }
.map { SettingsScreenViewState.OnPlanTypesPrefetch(it) }
val onDownloadTours = intent(SettingsScreen::downloadAllTours)
......
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