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

promote getplan method

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