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