Commit 087eea30 authored by Vladislav Bogdashkin's avatar Vladislav Bogdashkin 🎣

tag cannot be used as store ..

parent 6180b58b
......@@ -126,7 +126,12 @@ data class PlanPresetModel(
var estateId:Int,
val title:String,
val features:List<FeatureModel>
)
){
inline fun <reified T : FeatureModel> switchFeature(value:Boolean){
features.first { it is T}.switchedOn = value
}
}
data class ExplicationModel(
val living: Boolean,
......
......@@ -15,7 +15,7 @@ data class PlanTypeModel(
sealed class FeatureModel(
val featureName:String,
val featureTitle:String,
val switchedOn: Boolean
var switchedOn: Boolean
){
companion object{
fun fromFeature(featureAlias:String):FeatureModel =
......
......@@ -9,5 +9,9 @@ import io.reactivex.Observable
interface EstateScreen : BigantoBaseContract<EstateScreenViewState> {
fun planTypesTabSelected(): Observable<Int>
fun switchSizes(): Observable<Pair<Int,Boolean>>
fun switchWalls(): Observable<Pair<Int,Boolean>>
fun switchFurniture(): Observable<Pair<Int,Boolean>>
fun switchElectric(): Observable<Pair<Int,Boolean>>
}
......@@ -7,6 +7,8 @@ import android.view.ViewGroup
import android.webkit.WebView
import android.widget.LinearLayout
import androidx.core.os.bundleOf
import androidx.core.view.get
import androidx.core.view.isNotEmpty
import butterknife.BindView
import com.biganto.visual.roompark.R
import com.biganto.visual.roompark.base.RoomParkApplication
......@@ -18,6 +20,7 @@ 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
import com.jakewharton.rxbinding3.widget.checkedChanges
import io.reactivex.Observable
import io.reactivex.android.schedulers.AndroidSchedulers
import timber.log.Timber
......@@ -38,6 +41,38 @@ class EstateScreenController :
, EstateScreenPresenter>
, EstateScreen {
private fun ViewGroup.switchMatch() =
this.findViewById<SwitchMaterial>(R.id.switch1)
.checkedChanges()
.filter {planTypesTabLayout.isNotEmpty()}
.filter{planTypesTabLayout.selectedTabPosition>=0}
.doOnNext { Timber.d("tag: ${planTypesTabLayout.getTabAt(0)?.tag}") }
.doOnNext { Timber.d("tag: ${planTypesTabLayout.getTabAt(0)?.customView}") }
.doOnNext { Timber.d("tag: ${planTypesTabLayout.getTabAt(0)?.view}") }
.doOnNext {
Timber.d("tabs tag: ${planTypesTabLayout.getTag(planTypesTabLayout.selectedTabPosition)}")
Timber.d("tabs tag: ${planTypesTabLayout.getTabAt(0)?.customView?.tag}")
}
.doOnNext { Timber.d("tag: ${planTypesTabLayout.selectedTabPosition}") }
.doOnNext { Timber.d("tag: ${planTypesTabLayout[planTypesTabLayout.selectedTabPosition].tag}") }
.map {
Pair(planTypesTabLayout.getTabAt(0)?.customView?.tag as Int,it)
}
override fun switchSizes(): Observable<Pair<Int, Boolean>> =
sizesSwitcher.switchMatch()
override fun switchWalls(): Observable<Pair<Int, Boolean>> =
wallsSwitcher.switchMatch()
override fun switchFurniture(): Observable<Pair<Int, Boolean>> =
furnSwitcher.switchMatch()
override fun switchElectric(): Observable<Pair<Int, Boolean>> =
electricSwitcher.switchMatch()
override fun planTypesTabSelected(): Observable<Int> =
planTypesTabLayout.selections()
......@@ -147,6 +182,8 @@ class EstateScreenController :
val tab = planTypesTabLayout.newTab()
.setCustomView(R.layout.select_text_tab).setTag(it.planId)
Timber.d("tabs tag: ${tab}")
Timber.d("tabs tag: ${tab.tag}")
(tab.customView as MaterialTextView).text = "Вариант $i"
planTypesTabLayout.addTab(tab)
i++
......
......@@ -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.FeatureModel
import com.biganto.visual.roompark.domain.model.PlanPresetModel
import com.biganto.visual.roompark.util.monades.ExceptionString
import io.reactivex.Observable
......@@ -27,6 +28,11 @@ class EstateScreenPresenter @Inject constructor(
override fun defaultErrorViewStateHandler() =
{e: ExceptionString -> EstateScreenViewState.SomeError(e) }
private fun getPlan(plan:PlanPresetModel): Observable<EstateScreenViewState> =
interactor.getPlan(plan)
.map<EstateScreenViewState> {EstateScreenViewState.LoadPlan(it)}
override fun bindIntents() {
val prefetchCards = interactor.getEstate(estateId)
......@@ -44,12 +50,42 @@ class EstateScreenPresenter @Inject constructor(
.startWith(Observable.just<EstateScreenViewState>(EstateScreenViewState.PlanTypeSelected(it)))
}
val switchSizes = intent(EstateScreen::switchSizes)
.map {pair ->
val plan = planList?.first{it.planId == pair.first}
plan?.switchFeature<FeatureModel.Sizes>(pair.second)
plan
}.flatMap(::getPlan)
val switchFurn = intent(EstateScreen::switchFurniture)
.map {pair ->
val plan = planList?.first{it.planId == pair.first}
plan?.switchFeature<FeatureModel.Furniture>(pair.second)
plan
}.flatMap(::getPlan)
val switchWalls = intent(EstateScreen::switchWalls)
.map {pair ->
val plan = planList?.first{it.planId == pair.first}
plan?.switchFeature<FeatureModel.Walls>(pair.second)
plan
}.flatMap(::getPlan)
val switchElectric = intent(EstateScreen::switchElectric)
.map {pair ->
val plan = planList?.first{it.planId == pair.first}
plan?.switchFeature<FeatureModel.Electric>(pair.second)
plan
}.flatMap(::getPlan)
val state = restoreStateObservable
.mergeWith(prefetchCards)
.mergeWith(fetchPlans)
.mergeWith(fetchPlan)
.mergeWith(switchElectric)
.mergeWith(switchFurn)
.mergeWith(switchSizes)
.mergeWith(switchWalls)
.doOnError{ Timber.e(it)}
.subscribeOn(Schedulers.io())
.observeOn(AndroidSchedulers.mainThread())
......
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