Commit 4b2dcd45 authored by Vladislav Bogdashkin's avatar Vladislav Bogdashkin 🎣

to flat restore model

parent 9c1dc92c
......@@ -9,7 +9,7 @@ import io.reactivex.Observable
interface FindFlatScreen : BigantoBaseContract<FindFlatScreenViewState> {
fun getFlat() : Observable<FlatRequestModel>
fun openFlat() : Observable<Int>
fun openFlat() : Observable<FlatRequestModel>
}
data class FlatRequestModel(val building:Int,val number:Int)
\ No newline at end of file
......@@ -36,11 +36,20 @@ class FindFlatScreenController :
, FindFlatScreenPresenter>()
, FindFlatScreen {
private val flatModel:FlatRequestModel get(){
return FlatRequestModel(
estateTabs[flatTabs.selectedTabPosition].building
, flatNumberInput.editText?.text.toString().toInt()
)
}
override fun openFlat(): Observable<Int> =
override fun openFlat(): Observable<FlatRequestModel> =
findFlatButton.clicks()
.map { 1 }
.mergeWith(flatNumberEditor.keys{ it.keyCode == KeyEvent.KEYCODE_ENTER }.map { 1 })
.map {
flatModel
}
.doOnNext{ flatNumberEditor.hideKeyboard() }
.observeOn(AndroidSchedulers.mainThread())
......@@ -48,12 +57,9 @@ class FindFlatScreenController :
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()
)
flatModel
}
.debounce (300,TimeUnit.MILLISECONDS)
.debounce (120,TimeUnit.MILLISECONDS)
.observeOn(AndroidSchedulers.mainThread())
override fun injectDependencies() {
......@@ -118,6 +124,7 @@ class FindFlatScreenController :
is FindFlatScreenViewState.FlatFounded -> render(viewState)
is FindFlatScreenViewState.FlatNotFound -> render(viewState)
is FindFlatScreenViewState.StartFlat -> render(viewState)
is FindFlatScreenViewState.RestoreView -> render(viewState)
}
}
......@@ -127,6 +134,14 @@ class FindFlatScreenController :
private fun render(viewState: FindFlatScreenViewState.Idle){
}
private fun render(viewState: FindFlatScreenViewState.RestoreView){
val tabIndex = viewState.restore.building-1
Timber.d(":: ${viewState.restore.building} : $tabIndex")
flatTabs.getTabAt(tabIndex)?.select() //zero-based
flatNumberInput.editText?.setText(viewState.restore.number.toString())
}
private fun render(viewState: FindFlatScreenViewState.FlatFounded){
findFlatButton.isEnabled = true
findFlatButton.text = resources?.getString(R.string.flat_ready_to_watch)
......
......@@ -27,6 +27,13 @@ class FindFlatScreenPresenter @Inject constructor(
//estateId
private var recentFlat:Int? =null
private var restoreModel = RestoreModel(-1,-1)
override fun detachView() {
super.detachView()
restoreStateObservable.accept(FindFlatScreenViewState.RestoreView(restoreModel))
}
override fun vsByCode(code: Int): (ExceptionString) -> FindFlatScreenViewState =
when (code) {
304 -> {message:ExceptionString ->FindFlatScreenViewState.FlatNotFound(message)}
......@@ -36,6 +43,7 @@ class FindFlatScreenPresenter @Inject constructor(
override fun bindIntents() {
val getFlatIntent = intent(FindFlatScreen::getFlat)
.doOnNext { restoreModel.building = it.building;restoreModel.number = it.number }
.doOnNext{recentFlat=null}
.doOnNext{Timber.d(" flat is $it")}
.flatMap { request ->
......@@ -47,6 +55,7 @@ class FindFlatScreenPresenter @Inject constructor(
.startWith(Observable.just(FindFlatScreenViewState.RequstFlatProgress()))
val startFlatIntent = intent(FindFlatScreen::openFlat)
.doOnNext { restoreModel.building = it.building;restoreModel.number = it.number }
.map {
if (recentFlat != null) {FindFlatScreenViewState.StartFlat(recentFlat as Int)}
else FindFlatScreenViewState.FlatNotFound(
......@@ -55,6 +64,7 @@ class FindFlatScreenPresenter @Inject constructor(
}
val state = restoreStateObservable
.mergeWith(getFlatIntent)
.mergeWith(startFlatIntent)
......@@ -64,4 +74,7 @@ class FindFlatScreenPresenter @Inject constructor(
subscribeViewState(state.cast(FindFlatScreenViewState::class.java), FindFlatScreen::render)
}
}
\ No newline at end of file
}
data class RestoreModel(
var building:Int,var number:Int)
......@@ -15,4 +15,5 @@ sealed class FindFlatScreenViewState : BigantoBaseViewState() {
class FlatNotFound(val exceptionString:ExceptionString) : FindFlatScreenViewState()
class StartFlat(val esateId:Int) : FindFlatScreenViewState()
class SomeError(val exception: ExceptionString) : FindFlatScreenViewState()
class RestoreView(val restore:RestoreModel) : FindFlatScreenViewState()
}
\ No newline at end of file
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