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

to flat restore model

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