Commit 55e0a43e authored by Vladislav Bogdashkin's avatar Vladislav Bogdashkin 🎣

promote getplan method

parent 4a6a88b7
......@@ -112,14 +112,25 @@ class EstateRepository @Inject constructor(
private fun getPlanApi(estateId: Int
, planId:Int
, furniture:Boolean = false
, sizes:Boolean = false
, walls:Boolean = false
, electric:Boolean = false) =
api.getDirectPlan(estateId, planId,furniture,sizes,walls,electric)
, furniture:Boolean? = null
, sizes:Boolean? = null
, walls:Boolean? = null
, electric:Boolean? = null) =
api.getDirectPlan(estateId, planId,
furniture?:false
,sizes?:false
,walls?:false
,electric?:false)
.map{
val sFile = FileModule.getDirectory(file.context
,FileModule.FileDirectory.PlanTypeDir(childName = "planType-$estateId-$planId.html"))
,FileModule.FileDirectory.PlanTypeDir(
estateId = estateId,
planId = planId,
furniture = furniture,
walls = walls,
sizes = sizes,
electric = electric
))
file.saveFileToDisk(sFile,it)
sFile.path
}
......@@ -132,6 +143,25 @@ class EstateRepository @Inject constructor(
arrayListOf(getPlanApi(estateId,planId))
)
override fun getPlan(estateId: Int
,planId:Int
, furniture:Boolean?
, sizes:Boolean?
, walls:Boolean?
, electric:Boolean?): Observable<String> =
Observable.mergeDelayError(
arrayListOf(
getPlanApi(estateId
,planId
, furniture
, sizes
, walls
, electric
)
)
)
// fun getPlanRequestString(estateId: Int
// , planId:Int
// , furniture:Boolean
......
......@@ -85,10 +85,11 @@ class FileModule @Inject constructor(val context: Application) {
, walls:Boolean? = null
, electric:Boolean? = null
) : super(catalog.plus("/plan").plus("/$estateId").plus("/$planId")
.plus("plan_${planId}_${furniture?:"f${furniture.asInt}"}" +
"_${sizes?:"f${sizes.asInt}"}" +
"_${walls?:"f${walls.asInt}"}" +
"_${electric?:"f${electric.asInt}"}")
.plus("/plan${planId}" +
"${sizes?.asInt?.toString()?.map { "_s$it" }?:""}" +
"${furniture?.asInt?.toString()?.map { "_f$it" }?:""}" +
"${walls?.asInt?.toString()?.map { "_w$it" }?:""}" +
"${electric?.asInt?.toString()?.map { "_e$it" }?:""}")
.plus(".html"))
}
......
......@@ -15,4 +15,14 @@ interface DealContract{
fun getEstate(estateId: Int): Observable<EstateModel>
fun getPlanTypes(estateId: Int): Observable<List<PlanPresetModel>>
fun getEmptyPlan(estateId: Int, planId: Int): Observable<String>
fun getPlan(
estateId: Int
, planId: Int
, furniture:Boolean?
, sizes:Boolean?
, walls:Boolean?
, electric:Boolean?): Observable<String>
}
\ No newline at end of file
package com.biganto.visual.roompark.domain.interactor
import com.biganto.visual.roompark.domain.model.PlanPresetModel
import com.biganto.visual.roompark.domain.use_case.EstateUseCase
import javax.inject.Inject
......@@ -18,4 +19,14 @@ class EstateInteractor @Inject constructor(
fun getPlan(estateId: Int,planId:Int) = useCase.getPlan(estateId,planId)
fun getPlan(plan:PlanPresetModel) =
useCase.getPlan(
plan.estateId
,plan.planId
,furniture = plan.features.firstOrNull { it.featureName == "furniture" }?.switchedOn
,sizes = plan.features.firstOrNull { it.featureName == "sizes" }?.switchedOn
,walls = plan.features.firstOrNull { it.featureName == "walls" }?.switchedOn
,electric = plan.features.firstOrNull { it.featureName == "electric" }?.switchedOn
)
}
\ No newline at end of file
......@@ -8,6 +8,8 @@ import com.biganto.visual.roompark.data.repository.db.requrey.model.PlanPreset
* Created by Vladislav Bogdashkin on 23.09.2019.
*/
const val DEFAULT_WALLS_FEATURE_NAME = "walls"
data class DealListModel(val deals:List<DealListModel>)
......@@ -111,8 +113,11 @@ fun fromEntity(entity : PlanPreset) = PlanPresetModel(
planId = entity.planId,
estateId = entity.estateId.id,
title = entity.title,
features = entity.features.toList(),
explication = List(entity.explication.size){ ExplicationModel((entity.explication[it] as ExplicationEntity))}
features = entity.features.asSequence()
.map { FeatureStatus(it, it==DEFAULT_WALLS_FEATURE_NAME) }.toList(),
//default true value for walls (otherwise plan may be empty)
explication = List(entity.explication.size)
{ ExplicationModel((entity.explication[it] as ExplicationEntity))}
)
data class PlanPresetModel(
......@@ -120,7 +125,7 @@ data class PlanPresetModel(
val explication:List<ExplicationModel>,
var estateId:Int,
val title:String,
val features:List<String>
val features:List<FeatureStatus>
)
data class ExplicationModel(
......
......@@ -16,3 +16,5 @@ data class FeatureStatus(
val featureName:String,
val switchedOn: Boolean
)
......@@ -9,16 +9,33 @@ import javax.inject.Inject
class EstateUseCase @Inject constructor(
private val contract: DealContract
){
) {
fun fetchFavorites() = contract.getFavorites()
fun getEstate(estateId:Int) = contract.getEstate(estateId)
fun getEstate(estateId: Int) = contract.getEstate(estateId)
fun getEstatePlanPresets(estateId: Int) =
contract.getPlanTypes(estateId)
fun getPlan(estateId: Int,planId:Int) = contract.getEmptyPlan(estateId,planId)
fun getPlan(estateId: Int, planId: Int) =
contract.getEmptyPlan(estateId, planId)
fun getPlan(
estateId: Int
, planId: Int
, furniture: Boolean?
, sizes: Boolean?
, walls: Boolean?
, electric: Boolean?
) = contract.getPlan(
estateId
, planId
, furniture
, sizes
, walls
, electric
)
}
\ No newline at end of file
......@@ -2,6 +2,7 @@ package com.biganto.visual.roompark.presentation.screen.estate
import com.biganto.visual.roompark.conductor.BigantoBasePresenter
import com.biganto.visual.roompark.domain.interactor.EstateInteractor
import com.biganto.visual.roompark.domain.model.PlanPresetModel
import com.biganto.visual.roompark.util.monades.ExceptionString
import io.reactivex.android.schedulers.AndroidSchedulers
import io.reactivex.schedulers.Schedulers
......@@ -20,6 +21,8 @@ class EstateScreenPresenter @Inject constructor(
)
: BigantoBasePresenter<EstateScreen, EstateScreenViewState>() {
private var planList:List<PlanPresetModel>? = null
override fun defaultErrorViewStateHandler() =
{e: ExceptionString -> EstateScreenViewState.SomeError(e) }
......@@ -30,10 +33,13 @@ class EstateScreenPresenter @Inject constructor(
//.map { EstateScreenViewState.FavoriteEstatesLoaded(it) }
val fetchPlans = interactor.getPlanTypes(estateId)
.doOnNext { planList = it.toList() }
.map { EstateScreenViewState.LoadPlanTypes(it) }
val fetchPlan = intent(EstateScreen::planTypesTabSelected)
.flatMap {planId -> interactor.getPlan(estateId,planId) }
.map { plan ->planList?.first{it.planId == plan} }
.flatMap { interactor.getPlan(it)
}
.map { EstateScreenViewState.LoadPlan(it) }
val state = restoreStateObservable
......
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