Commit a1c067d4 authored by Vladislav Bogdashkin's avatar Vladislav Bogdashkin 🎣

update to flat functionally as design

parent 3fd8fbd3
......@@ -9,6 +9,7 @@ import io.reactivex.Observable
interface FindFlatScreen : BigantoBaseContract<FindFlatScreenViewState> {
fun getFlat() : Observable<FlatRequestModel>
fun openFlat() : Observable<Int>
}
data class FlatRequestModel(val building:Int,val number:Int)
\ No newline at end of file
......@@ -18,9 +18,11 @@ import com.google.android.material.tabs.TabLayout
import com.google.android.material.textfield.TextInputLayout
import com.jakewharton.rxbinding3.view.clicks
import com.jakewharton.rxbinding3.view.keys
import com.jakewharton.rxbinding3.widget.afterTextChangeEvents
import io.reactivex.Observable
import io.reactivex.android.schedulers.AndroidSchedulers
import timber.log.Timber
import java.util.concurrent.TimeUnit
import javax.inject.Inject
/**
......@@ -34,16 +36,23 @@ class FindFlatScreenController :
, FindFlatScreen {
override fun openFlat(): Observable<Int> =
findFlatButton.clicks()
.map { 1 }
.mergeWith(flatNumberEditor.keys{ it.keyCode == KeyEvent.KEYCODE_ENTER }.map { 1 })
.doOnNext{ flatNumberEditor.hideKeyboard() }
.observeOn(AndroidSchedulers.mainThread())
override fun getFlat(): Observable<FlatRequestModel> =
Observable.merge(
flatNumberEditor.keys { it.keyCode == KeyEvent.KEYCODE_ENTER },findFlatButton.clicks())
.doOnNext { flatNumberEditor.hideKeyboard() }
flatNumberEditor.afterTextChangeEvents()// keys{ it.keyCode == KeyEvent.KEYCODE_ENTER }
.filter { flatNumberInput.editText?.text?.isNotEmpty()?:false }
.map {
FlatRequestModel(
estateTabs[flatTabs.selectedTabPosition].building
, flatNumberInput.editText?.text.toString().toInt()
)
}
.debounce (300,TimeUnit.MILLISECONDS)
.observeOn(AndroidSchedulers.mainThread())
override fun injectDependencies() {
......@@ -107,6 +116,8 @@ class FindFlatScreenController :
is FindFlatScreenViewState.Idle -> render(viewState)
is FindFlatScreenViewState.SomeError -> render(viewState)
is FindFlatScreenViewState.FlatFounded -> render(viewState)
is FindFlatScreenViewState.FlatNotFound -> render(viewState)
is FindFlatScreenViewState.StartFlat -> render(viewState)
}
}
......@@ -117,6 +128,21 @@ class FindFlatScreenController :
}
private fun render(viewState: FindFlatScreenViewState.FlatFounded){
findFlatButton.isEnabled = true
findFlatButton.text = resources?.getString(R.string.flat_ready_to_watch)
}
private fun render(viewState: FindFlatScreenViewState.FlatNotFound){
findFlatButton.isEnabled = false
viewState.exceptionString.selectHandler(
{findFlatButton.text = resources?.getString(it)},
{findFlatButton.text = it}
)
}
private fun render(viewState: FindFlatScreenViewState.StartFlat){
router.pushController(
RouterTransaction.with(EstateScreenController(viewState.esateId))
.pushChangeHandler(FadeChangeHandler())
......
package com.biganto.visual.roompark.presentation.screen.to_flat
import com.biganto.visual.roompark.R
import com.biganto.visual.roompark.conductor.BigantoBasePresenter
import com.biganto.visual.roompark.domain.interactor.FindFlatInteractor
import com.biganto.visual.roompark.util.monades.ExceptionString
......@@ -23,20 +24,40 @@ class FindFlatScreenPresenter @Inject constructor(
{e: ExceptionString -> FindFlatScreenViewState.SomeError(e)}
//estateId
private var recentFlat:Int? =null
override fun vsByCode(code: Int): (ExceptionString) -> FindFlatScreenViewState =
when (code) {
304 -> {message:ExceptionString ->FindFlatScreenViewState.FlatNotFound(message)}
else -> super.vsByCode(code)
}
override fun bindIntents() {
val getFlatIntent = intent(FindFlatScreen::getFlat)
.doOnNext{recentFlat=null}
.doOnNext{Timber.d(" flat is $it")}
.flatMap { request ->
interactor.getFlat(request.building,request.number)
.map<FindFlatScreenViewState> {FindFlatScreenViewState.FlatFounded(it)}
.doOnNext { recentFlat=it }
.map<FindFlatScreenViewState> {FindFlatScreenViewState.FlatFounded()}
.onErrorReturn (::parseError)
}
.startWith(Observable.just(FindFlatScreenViewState.RequstFlatProgress()))
val startFlatIntent = intent(FindFlatScreen::openFlat)
.map {
if (recentFlat != null) {FindFlatScreenViewState.StartFlat(recentFlat as Int)}
else FindFlatScreenViewState.FlatNotFound(
ExceptionString(R.string.flat_not_found,null)
)
}
val state = restoreStateObservable
.mergeWith(getFlatIntent)
.mergeWith(startFlatIntent)
.doOnError { Timber.e(it) }
.subscribeOn(Schedulers.io())
.observeOn(AndroidSchedulers.mainThread())
......
......@@ -11,7 +11,8 @@ import com.biganto.visual.roompark.util.monades.ExceptionString
sealed class FindFlatScreenViewState : BigantoBaseViewState() {
class Idle : FindFlatScreenViewState()
class RequstFlatProgress : FindFlatScreenViewState()
class FlatFounded(val esateId:Int) : FindFlatScreenViewState()
class FlatNotFound : FindFlatScreenViewState()
class FlatFounded : FindFlatScreenViewState()
class FlatNotFound(val exceptionString:ExceptionString) : FindFlatScreenViewState()
class StartFlat(val esateId:Int) : FindFlatScreenViewState()
class SomeError(val exception: ExceptionString) : FindFlatScreenViewState()
}
\ No newline at end of file
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:state_enabled="false" android:color="@color/colorError" />
<item android:color="@color/colorAccent" />
</selector>
\ No newline at end of file
......@@ -45,11 +45,10 @@
<com.google.android.material.button.MaterialButton
android:id="@+id/findFlatButton"
style="@style/AuthButton.Enable"
style="@style/FlatButton.Watch"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginStart="16dp"
android:layout_marginTop="16dp"
android:layout_marginEnd="16dp"
android:text="СМОТРЕТЬ" />
android:layout_marginEnd="16dp"/>
</LinearLayout>
\ No newline at end of file
......@@ -69,6 +69,8 @@
<string name="max_discount">Максимальная скидка с учетом всех акций</string>
<string name="discount_value">%,.1f \%</string>
<string name="discounted_price">Стоимость со скидкой</string>
<string name="flat_not_found">В ЭТОМ ДОМЕ НЕТ КВАРТИРЫ С ТАКИМ НОМЕРОМ</string>
<string name="flat_ready_to_watch">СМОТРЕТЬ</string>
<!--endregion-->
</resources>
......@@ -149,6 +149,16 @@
<item name="hintTextColor">@color/colorNoticeText</item>
</style>
<style name="FlatButton.Watch" parent="Widget.MaterialComponents.Button.OutlinedButton">
<item name="android:text">"СМОТРЕТЬ"</item>
<item name="android:textColor">@color/flat_watch_button_selector</item>
<item name="strokeColor">@color/flat_watch_button_selector</item>
<item name="strokeWidth">4dp</item>
<item name="android:height">64dp</item>
<item name="cornerRadius">0dp</item>
<item name="rippleColor">@color/colorAccentSecondary</item>
<item name="android:textSize">@dimen/accent_header</item>
</style>
<style name="AuthButton.Enable">
<item name="android:text">"ВОЙТИ"</item>
......
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