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

resolve on error auth editText issue

parent 5d067764
...@@ -19,6 +19,7 @@ import com.biganto.visual.roompark.util.monades.ExceptionString ...@@ -19,6 +19,7 @@ import com.biganto.visual.roompark.util.monades.ExceptionString
import com.biganto.visual.roompark.util.view_utils.snackbar.ISnackBarProvider import com.biganto.visual.roompark.util.view_utils.snackbar.ISnackBarProvider
import com.hannesdorfmann.mosby3.mvi.MviBasePresenter import com.hannesdorfmann.mosby3.mvi.MviBasePresenter
import io.reactivex.disposables.CompositeDisposable import io.reactivex.disposables.CompositeDisposable
import timber.log.Timber
/** /**
* Created by Vladislav Bogdashkin on 28.05.2018. * Created by Vladislav Bogdashkin on 28.05.2018.
...@@ -47,7 +48,14 @@ abstract class BigantoBaseController<VS : BigantoBaseViewState,V: BigantoBaseCon ...@@ -47,7 +48,14 @@ abstract class BigantoBaseController<VS : BigantoBaseViewState,V: BigantoBaseCon
lateinit var toolBar: ICollapsingToolBar lateinit var toolBar: ICollapsingToolBar
lateinit var snackbar: ISnackBarProvider lateinit var snackbar: ISnackBarProvider
override fun onAttach(view: View) {
Timber.d("On Attach")
super.onAttach(view)
}
override fun onDetach(view: View) { override fun onDetach(view: View) {
Timber.d("On Detach")
detachDisposable.clear() detachDisposable.clear()
super.onDetach(view) super.onDetach(view)
} }
......
...@@ -12,9 +12,11 @@ import com.bluelinelabs.conductor.RouterTransaction ...@@ -12,9 +12,11 @@ import com.bluelinelabs.conductor.RouterTransaction
import com.google.android.material.button.MaterialButton import com.google.android.material.button.MaterialButton
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.widget.textChanges
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
/** /**
...@@ -26,19 +28,24 @@ class AuthScreenController : ...@@ -26,19 +28,24 @@ class AuthScreenController :
, AuthScreen , AuthScreen
, AuthScreenPresenter>() , AuthScreenPresenter>()
, AuthScreen { , AuthScreen {
override fun onViewBound(v: View) { override fun onViewBound(v: View) {
toolBar.hideAll() toolBar.hideAll()
bottomNavigation.hide() bottomNavigation.hide()
} }
@BindView(R.id.login_text_input) lateinit var loginInput:TextInputLayout @BindView(R.id.login_text_input) lateinit var loginInput:TextInputLayout
@BindView(R.id.password_text_input) lateinit var pwdInput:TextInputLayout @BindView(R.id.password_text_input) lateinit var pwdInput:TextInputLayout
@BindView(R.id.sign_in_button) lateinit var signInButton:MaterialButton @BindView(R.id.sign_in_button) lateinit var signInButton:MaterialButton
override fun tryAuth(): Observable<AuthInputModel> = override fun tryAuth(): Observable<AuthInputModel> =
signInButton.clicks() signInButton.clicks()
.debounce (200L,TimeUnit.MILLISECONDS)
.doOnNext { signInButton.hideKeyboard() } .doOnNext { signInButton.hideKeyboard() }
.map<AuthInputModel> { .map<AuthInputModel> {
AuthInputModel( AuthInputModel(
...@@ -52,6 +59,27 @@ class AuthScreenController : ...@@ -52,6 +59,27 @@ class AuthScreenController :
getComponent() getComponent()
} }
override fun onAttach(view: View) {
super.onAttach(view)
detachDisposable.addAll(
loginInput.editText?.textChanges()
?.doOnNext { Timber.d("loginInput.isErrorEnabled ${loginInput.isErrorEnabled}")}
?.filter { loginInput.isErrorEnabled }
?.subscribe {
Timber.d("got key $it")
loginInput.isErrorEnabled = false
loginInput.error = null
signInButton.isEnabled=true
},
pwdInput.editText?.textChanges()
?.filter { pwdInput.isErrorEnabled }
?.subscribe { pwdInput.isErrorEnabled = false
signInButton.isEnabled=true
}
)
}
@Inject @Inject
lateinit var bottomNavigation: IBottomNavigation lateinit var bottomNavigation: IBottomNavigation
...@@ -114,7 +142,6 @@ class AuthScreenController : ...@@ -114,7 +142,6 @@ class AuthScreenController :
{strId -> loginInput.error = resources?.getString(strId)}, {strId -> loginInput.error = resources?.getString(strId)},
{message -> loginInput.error = message} {message -> loginInput.error = message}
) )
signInButton.isEnabled=true
} }
private fun render(viewState: AuthScreenViewState.WrongPassword){ private fun render(viewState: AuthScreenViewState.WrongPassword){
...@@ -124,10 +151,10 @@ class AuthScreenController : ...@@ -124,10 +151,10 @@ class AuthScreenController :
{strId -> pwdInput.error = resources?.getString(strId)}, {strId -> pwdInput.error = resources?.getString(strId)},
{message -> pwdInput.error = message} {message -> pwdInput.error = message}
) )
signInButton.isEnabled=true
} }
private fun render(viewState: AuthScreenViewState.SomeError) = private fun render(viewState: AuthScreenViewState.SomeError) =
showError(viewState.exception) showError(viewState.exception)
......
...@@ -3,6 +3,7 @@ package com.biganto.visual.roompark.presentation.screen.auth ...@@ -3,6 +3,7 @@ package com.biganto.visual.roompark.presentation.screen.auth
import com.biganto.visual.roompark.conductor.BigantoBasePresenter import com.biganto.visual.roompark.conductor.BigantoBasePresenter
import com.biganto.visual.roompark.domain.interactor.AuthInteractor import com.biganto.visual.roompark.domain.interactor.AuthInteractor
import com.biganto.visual.roompark.util.monades.ExceptionString import com.biganto.visual.roompark.util.monades.ExceptionString
import io.reactivex.Observable
import io.reactivex.android.schedulers.AndroidSchedulers import io.reactivex.android.schedulers.AndroidSchedulers
import io.reactivex.schedulers.Schedulers import io.reactivex.schedulers.Schedulers
import timber.log.Timber import timber.log.Timber
...@@ -18,6 +19,18 @@ class AuthScreenPresenter @Inject constructor( ...@@ -18,6 +19,18 @@ class AuthScreenPresenter @Inject constructor(
) )
: BigantoBasePresenter<AuthScreen, AuthScreenViewState>() { : BigantoBasePresenter<AuthScreen, AuthScreenViewState>() {
override fun attachView(view: AuthScreen) {
super.attachView(view)
Timber.d("on AttachView")
restoreStateObservable.accept(AuthScreenViewState.Idle())
}
override fun detachView() {
super.detachView()
Timber.d("on DetachView")
restoreStateObservable }
override fun defaultErrorViewStateHandler() = override fun defaultErrorViewStateHandler() =
{e:ExceptionString -> AuthScreenViewState.SomeError(e)} {e:ExceptionString -> AuthScreenViewState.SomeError(e)}
...@@ -38,8 +51,9 @@ class AuthScreenPresenter @Inject constructor( ...@@ -38,8 +51,9 @@ class AuthScreenPresenter @Inject constructor(
.map { it } .map { it }
.map<AuthScreenViewState> { AuthScreenViewState.SignedIn() } .map<AuthScreenViewState> { AuthScreenViewState.SignedIn() }
.onErrorReturn{parseError(it)} .onErrorReturn{parseError(it)}
.startWith(Observable.just(AuthScreenViewState.Authorization()))
} }
// .startWith(Observable.just(AuthScreenViewState.Authorization()))
val state = restoreStateObservable val state = restoreStateObservable
......
<?xml version="1.0" encoding="utf-8"?> <?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android"> <selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:state_enabled="false" android:color="@color/colorAccent" /> <item android:state_enabled="false" android:color="@color/colorGray" />
<item android:color="@color/colorGray" />
<item android:color="@color/colorAccent" />
</selector> </selector>
\ No newline at end of file
...@@ -41,6 +41,7 @@ ...@@ -41,6 +41,7 @@
<style name="Auth.ErrorText" parent="TextAppearance.Design.Error"> <style name="Auth.ErrorText" parent="TextAppearance.Design.Error">
<item name="android:textColor">@color/colorError</item> <item name="android:textColor">@color/colorError</item>
<item name="android:textSize">@dimen/lite_notice</item>
</style> </style>
<style name="Auth.EditText" parent="Widget.AppCompat.EditText"> <style name="Auth.EditText" parent="Widget.AppCompat.EditText">
...@@ -151,6 +152,7 @@ ...@@ -151,6 +152,7 @@
<style name="AuthButton.Enable"> <style name="AuthButton.Enable">
<item name="android:text">"ВОЙТИ"</item> <item name="android:text">"ВОЙТИ"</item>
<item name="android:textColor">@color/sign_in_button_selector</item>
<item name="strokeColor">@color/sign_in_button_selector</item> <item name="strokeColor">@color/sign_in_button_selector</item>
</style> </style>
......
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