Commit 6180b58b authored by Vladislav Bogdashkin's avatar Vladislav Bogdashkin 🎣

plan type selection

parent 450c1003
......@@ -114,7 +114,7 @@ fun fromEntity(entity : PlanPreset) = PlanPresetModel(
estateId = entity.estateId.id,
title = entity.title,
features = entity.features.asSequence()
.map { FeatureStatus(it, it==DEFAULT_WALLS_FEATURE_NAME) }.toList(),
.map { FeatureModel.fromFeature(it) }.toList(),
//default true value for walls (otherwise plan may be empty)
explication = List(entity.explication.size)
{ ExplicationModel((entity.explication[it] as ExplicationEntity))}
......@@ -125,7 +125,7 @@ data class PlanPresetModel(
val explication:List<ExplicationModel>,
var estateId:Int,
val title:String,
val features:List<FeatureStatus>
val features:List<FeatureModel>
)
data class ExplicationModel(
......
......@@ -8,13 +8,33 @@ data class PlanTypeModel(
val id:Int,
val planTypeId:Int,
val estateId:Int,
val features:List<FeatureStatus>,
val features:List<FeatureModel>,
val uri:String
)
data class FeatureStatus(
sealed class FeatureModel(
val featureName:String,
val featureTitle:String,
val switchedOn: Boolean
)
){
companion object{
fun fromFeature(featureAlias:String):FeatureModel =
when(featureAlias){
"furniture" -> Furniture()
"sizes" -> Sizes()
"electric" -> Electric()
"walls" -> Walls()
else -> error("Unsupported feature type")
}
}
class Furniture:FeatureModel("furniture","Мебель",false)
class Sizes:FeatureModel("sizes","Размеры",false)
class Electric:FeatureModel("electric","Электрика",false)
class Walls:FeatureModel("walls","Перегородки",true)
}
......@@ -3,13 +3,18 @@ package com.biganto.visual.roompark.presentation.screen.estate
import android.net.Uri
import android.os.Bundle
import android.view.View
import android.view.ViewGroup
import android.webkit.WebView
import android.widget.LinearLayout
import androidx.core.os.bundleOf
import butterknife.BindView
import com.biganto.visual.roompark.R
import com.biganto.visual.roompark.base.RoomParkApplication
import com.biganto.visual.roompark.base.RoomParkMainActivity
import com.biganto.visual.roompark.conductor.BigantoBaseController
import com.biganto.visual.roompark.domain.model.FeatureModel
import com.biganto.visual.roompark.domain.model.PlanPresetModel
import com.google.android.material.switchmaterial.SwitchMaterial
import com.google.android.material.tabs.TabLayout
import com.google.android.material.textview.MaterialTextView
import com.jakewharton.rxbinding3.material.selections
......@@ -59,6 +64,35 @@ class EstateScreenController :
lateinit var planWebView: WebView
@BindView(R.id.sizes_switch_container)
lateinit var sizesContainer: LinearLayout
@BindView(R.id.sizes_switch_header)
lateinit var sizesTitle: MaterialTextView
@BindView(R.id.sizes_switcher)
lateinit var sizesSwitcher: ViewGroup
@BindView(R.id.electricity_switch_container)
lateinit var electricContainer: LinearLayout
@BindView(R.id.electricity_switch_header)
lateinit var electricTitle: MaterialTextView
@BindView(R.id.electricity_switcher)
lateinit var electricSwitcher: ViewGroup
@BindView(R.id.furniture_switch_container)
lateinit var furnContainer: LinearLayout
@BindView(R.id.furniture_switch_header)
lateinit var furnTitle: MaterialTextView
@BindView(R.id.furniture_switcher)
lateinit var furnSwitcher: ViewGroup
@BindView(R.id.walls_switch_container)
lateinit var wallsContainer: LinearLayout
@BindView(R.id.walls_switch_header)
lateinit var wallsTitle: MaterialTextView
@BindView(R.id.walls_switcher)
lateinit var wallsSwitcher: ViewGroup
private fun setToolbar(){
toolBar.showAll()
toolBar.appBar.setExpanded(false,false)
......@@ -87,6 +121,7 @@ class EstateScreenController :
is EstateScreenViewState.LoadEstate -> render(viewState)
is EstateScreenViewState.LoadPlanTypes -> render(viewState)
is EstateScreenViewState.LoadPlan -> render(viewState)
is EstateScreenViewState.PlanTypeSelected -> render(viewState)
is EstateScreenViewState.SomeError -> render(viewState)
}
}
......@@ -119,8 +154,51 @@ class EstateScreenController :
Timber.e(e)
}
}
planTypeSelected(viewState.types.first())
}
private fun planTypeSelected(plan:PlanPresetModel){
wallsContainer.visibility = View.GONE
sizesContainer.visibility = View.GONE
electricContainer.visibility = View.GONE
furnContainer.visibility = View.GONE
plan.features.forEach {
when(it){
is FeatureModel.Furniture -> {
furnContainer.visibility = View.VISIBLE
furnTitle.text = it.featureTitle
furnSwitcher.findViewById<SwitchMaterial>(R.id.switch1).isChecked =
it.switchedOn
}
is FeatureModel.Walls ->{
wallsContainer.visibility = View.VISIBLE
wallsTitle.text = it.featureTitle
wallsSwitcher.findViewById<SwitchMaterial>(R.id.switch1).isChecked =
it.switchedOn
}
is FeatureModel.Sizes ->{
sizesContainer.visibility = View.VISIBLE
sizesTitle.text = it.featureTitle
sizesSwitcher.findViewById<SwitchMaterial>(R.id.switch1).isChecked =
it.switchedOn
}
is FeatureModel.Electric ->{
electricContainer.visibility = View.VISIBLE
electricTitle.text = it.featureTitle
electricSwitcher.findViewById<SwitchMaterial>(R.id.switch1).isChecked =
it.switchedOn
}
}
}
}
private fun render(viewState: EstateScreenViewState.PlanTypeSelected) {
planTypeSelected(viewState.item)
}
private fun render(viewState: EstateScreenViewState.LoadPlan) {
planWebView.settings.javaScriptEnabled = true
planWebView.clearCache(true)
......
......@@ -4,6 +4,7 @@ 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.Observable
import io.reactivex.android.schedulers.AndroidSchedulers
import io.reactivex.schedulers.Schedulers
import timber.log.Timber
......@@ -38,9 +39,12 @@ class EstateScreenPresenter @Inject constructor(
val fetchPlan = intent(EstateScreen::planTypesTabSelected)
.map { plan ->planList?.first{it.planId == plan} }
.flatMap { interactor.getPlan(it)
.flatMap{ interactor.getPlan(it)
.map<EstateScreenViewState> {plan -> EstateScreenViewState.LoadPlan(plan) }
.startWith(Observable.just<EstateScreenViewState>(EstateScreenViewState.PlanTypeSelected(it)))
}
.map { EstateScreenViewState.LoadPlan(it) }
val state = restoreStateObservable
.mergeWith(prefetchCards)
......
......@@ -14,6 +14,7 @@ sealed class EstateScreenViewState : BigantoBaseViewState() {
class Idle : EstateScreenViewState()
class LoadEstate(val estate:EstateModel) : EstateScreenViewState()
class LoadPlanTypes(val types:List<PlanPresetModel>) : EstateScreenViewState()
class PlanTypeSelected(val item:PlanPresetModel) : EstateScreenViewState()
class LoadPlan(val planBody:String) : EstateScreenViewState()
class SomeError(val exception: ExceptionString) : EstateScreenViewState()
}
\ No newline at end of file
......@@ -176,7 +176,7 @@
app:layout_constraintTop_toBottomOf="@+id/include8">
<com.google.android.material.textview.MaterialTextView
android:id="@+id/electrecity_switch_header"
android:id="@+id/electricity_switch_header"
style="@style/Default_TextView.Header_Text"
android:layout_width="wrap_content"
android:layout_height="match_parent"
......@@ -185,7 +185,53 @@
android:text="Электрика" />
<include
android:id="@+id/furniture_switcher"
android:id="@+id/electricity_switcher"
layout="@layout/bell_switch_view"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="end|center_vertical"
android:layout_weight="0" />
</LinearLayout>
<include
android:id="@+id/walls_divider"
layout="@layout/horizontal_divider"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginStart="16dp"
android:layout_marginTop="16dp"
android:layout_marginEnd="16dp"
android:orientation="horizontal"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/electricity_switch_container" />
<LinearLayout
android:id="@+id/walls_switch_container"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginStart="16dp"
android:layout_marginTop="16dp"
android:layout_marginEnd="16dp"
android:orientation="horizontal"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/walls_divider">
<com.google.android.material.textview.MaterialTextView
android:id="@+id/walls_switch_header"
style="@style/Default_TextView.Header_Text"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_gravity="start|center_vertical"
android:layout_weight="1"
android:text="Стены" />
<include
android:id="@+id/walls_switcher"
layout="@layout/bell_switch_view"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
......@@ -203,7 +249,7 @@
android:orientation="horizontal"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/electricity_switch_container" />
app:layout_constraintTop_toBottomOf="@+id/walls_switch_container" />
<include
android:id="@+id/switch_flat_content_tab"
......
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