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

update sign in layout

add sign out method impl
parent 423dc854
...@@ -69,5 +69,6 @@ class AuthContractModule @Inject constructor( ...@@ -69,5 +69,6 @@ class AuthContractModule @Inject constructor(
is UserState.Authenticated -> true is UserState.Authenticated -> true
else ->false else ->false
} } } }
} }
...@@ -3,6 +3,7 @@ package com.biganto.visual.roompark.domain.interactor ...@@ -3,6 +3,7 @@ package com.biganto.visual.roompark.domain.interactor
import com.biganto.visual.roompark.domain.model.CachedDataModel import com.biganto.visual.roompark.domain.model.CachedDataModel
import com.biganto.visual.roompark.domain.model.PushSwitchModel import com.biganto.visual.roompark.domain.model.PushSwitchModel
import com.biganto.visual.roompark.domain.model.SettingsModel import com.biganto.visual.roompark.domain.model.SettingsModel
import com.biganto.visual.roompark.domain.use_case.AuthUseCase
import io.reactivex.Observable import io.reactivex.Observable
import javax.inject.Inject import javax.inject.Inject
...@@ -11,10 +12,13 @@ import javax.inject.Inject ...@@ -11,10 +12,13 @@ import javax.inject.Inject
*/ */
class SettingsInteractor @Inject constructor( class SettingsInteractor @Inject constructor(
private val auth: AuthUseCase
){ ){
fun fetchSettings(): Observable<SettingsModel> = Observable.just(sampleSettings) fun fetchSettings(): Observable<SettingsModel> = Observable.just(sampleSettings)
fun signOut() = auth.signOut()
companion object{ companion object{
......
...@@ -13,5 +13,6 @@ class AuthUseCase @Inject constructor( ...@@ -13,5 +13,6 @@ class AuthUseCase @Inject constructor(
fun validateAuth() = authContract.validateAuthState() fun validateAuth() = authContract.validateAuthState()
fun signIn(login:String,pwd:String) = authContract.signIn(login,pwd) fun signIn(login:String,pwd:String) = authContract.signIn(login,pwd)
fun signOut() = authContract.signOut()
} }
\ No newline at end of file
...@@ -33,12 +33,17 @@ class AuthScreenController : ...@@ -33,12 +33,17 @@ class AuthScreenController :
@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> =
Observable.defer {
signInButton.clicks() signInButton.clicks()
.doOnNext{signInButton.hideKeyboard()} .doOnNext { signInButton.hideKeyboard() }
.map<AuthInputModel>{ AuthInputModel(loginInput.editText?.text?.toString()?:"" .map<AuthInputModel> {
,pwdInput.editText?.text?.toString()?:"") AuthInputModel(
loginInput.editText?.text?.toString() ?: ""
, pwdInput.editText?.text?.toString() ?: ""
)
} }
.observeOn(AndroidSchedulers.mainThread()) .observeOn(AndroidSchedulers.mainThread())
}
override fun injectDependencies() { override fun injectDependencies() {
getComponent() getComponent()
...@@ -92,6 +97,24 @@ class AuthScreenController : ...@@ -92,6 +97,24 @@ class AuthScreenController :
signInButton.isEnabled=true signInButton.isEnabled=true
} }
private fun render(viewState: AuthScreenViewState.WrongLogin){
// showError(viewState.exception)
viewState.exception.selectHandler(
{strId -> loginInput.error = resources?.getString(strId)},
{message -> loginInput.error = message}
)
signInButton.isEnabled=true
}
private fun render(viewState: AuthScreenViewState.WrongPassword){
viewState.exception.selectHandler(
{strId -> pwdInput.error = resources?.getString(strId)},
{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)
......
...@@ -24,6 +24,8 @@ class AuthScreenPresenter @Inject constructor( ...@@ -24,6 +24,8 @@ class AuthScreenPresenter @Inject constructor(
override fun vsByCode(code: Int): (ExceptionString) -> AuthScreenViewState = override fun vsByCode(code: Int): (ExceptionString) -> AuthScreenViewState =
when (code) { when (code) {
101 -> {e:ExceptionString -> AuthScreenViewState.SignInError(e)} 101 -> {e:ExceptionString -> AuthScreenViewState.SignInError(e)}
111 -> {e:ExceptionString -> AuthScreenViewState.WrongLogin(e)}
112 -> {e:ExceptionString -> AuthScreenViewState.WrongPassword(e)}
else -> {e:ExceptionString -> AuthScreenViewState.SomeError(e)} else -> {e:ExceptionString -> AuthScreenViewState.SomeError(e)}
} }
...@@ -35,7 +37,7 @@ class AuthScreenPresenter @Inject constructor( ...@@ -35,7 +37,7 @@ class AuthScreenPresenter @Inject constructor(
.doOnNext { Timber.d("auth returned $it") } .doOnNext { Timber.d("auth returned $it") }
.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()))
......
...@@ -13,4 +13,7 @@ sealed class AuthScreenViewState : BigantoBaseViewState() { ...@@ -13,4 +13,7 @@ sealed class AuthScreenViewState : BigantoBaseViewState() {
class SignedIn : AuthScreenViewState() class SignedIn : AuthScreenViewState()
class SignInError(val exception: ExceptionString) : AuthScreenViewState() class SignInError(val exception: ExceptionString) : AuthScreenViewState()
class SomeError(val exception: ExceptionString) : AuthScreenViewState() class SomeError(val exception: ExceptionString) : AuthScreenViewState()
class WrongLogin(val exception: ExceptionString) : AuthScreenViewState()
class WrongPassword(val exception: ExceptionString) : AuthScreenViewState()
} }
\ No newline at end of file
package com.biganto.visual.roompark.presentation.screen.settings package com.biganto.visual.roompark.presentation.screen.settings
import com.biganto.visual.roompark.conductor.BigantoBaseContract import com.biganto.visual.roompark.conductor.BigantoBaseContract
import io.reactivex.Observable
/** /**
* Created by Vladislav Bogdashkin on 30.09.2019. * Created by Vladislav Bogdashkin on 30.09.2019.
*/ */
interface SettingsScreen : BigantoBaseContract<SettingsScreenViewState> { interface SettingsScreen : BigantoBaseContract<SettingsScreenViewState> {
fun signOut(): Observable<Int>
} }
...@@ -11,10 +11,15 @@ import com.biganto.visual.roompark.R ...@@ -11,10 +11,15 @@ import com.biganto.visual.roompark.R
import com.biganto.visual.roompark.base.RoomParkApplication import com.biganto.visual.roompark.base.RoomParkApplication
import com.biganto.visual.roompark.base.RoomParkMainActivity import com.biganto.visual.roompark.base.RoomParkMainActivity
import com.biganto.visual.roompark.conductor.BigantoBaseController import com.biganto.visual.roompark.conductor.BigantoBaseController
import com.biganto.visual.roompark.presentation.screen.auth.AuthScreenController
import com.biganto.visual.roompark.presentation.screen.settings.util.CahcedListAdapter import com.biganto.visual.roompark.presentation.screen.settings.util.CahcedListAdapter
import com.biganto.visual.roompark.presentation.screen.settings.util.PushListAdapter import com.biganto.visual.roompark.presentation.screen.settings.util.PushListAdapter
import com.biganto.visual.roompark.util.extensions.bytesToSize import com.biganto.visual.roompark.util.extensions.bytesToSize
import com.bluelinelabs.conductor.RouterTransaction
import com.google.android.material.textview.MaterialTextView import com.google.android.material.textview.MaterialTextView
import com.jakewharton.rxbinding3.view.clicks
import io.reactivex.Observable
import io.reactivex.android.schedulers.AndroidSchedulers
import timber.log.Timber import timber.log.Timber
import javax.inject.Inject import javax.inject.Inject
...@@ -28,6 +33,11 @@ class SettingsScreenController : ...@@ -28,6 +33,11 @@ class SettingsScreenController :
, SettingsScreenPresenter>() , SettingsScreenPresenter>()
, SettingsScreen { , SettingsScreen {
override fun signOut(): Observable<Int> =
signOutButton.clicks()
.map { 1 }
.observeOn(AndroidSchedulers.mainThread())
override fun injectDependencies() { override fun injectDependencies() {
getComponent() getComponent()
} }
...@@ -57,6 +67,9 @@ class SettingsScreenController : ...@@ -57,6 +67,9 @@ class SettingsScreenController :
@BindView(R.id.downloadFlatCardsIcon) @BindView(R.id.downloadFlatCardsIcon)
lateinit var flatDownloaderButton:ImageView lateinit var flatDownloaderButton:ImageView
@BindView(R.id.signOutButton)
lateinit var signOutButton:MaterialTextView
private fun setToolbar(){ private fun setToolbar(){
toolBar.showAll() toolBar.showAll()
...@@ -94,6 +107,7 @@ class SettingsScreenController : ...@@ -94,6 +107,7 @@ class SettingsScreenController :
is SettingsScreenViewState.Idle -> render(viewState) is SettingsScreenViewState.Idle -> render(viewState)
is SettingsScreenViewState.LoadSettingsList -> render(viewState) is SettingsScreenViewState.LoadSettingsList -> render(viewState)
is SettingsScreenViewState.SomeError -> render(viewState) is SettingsScreenViewState.SomeError -> render(viewState)
is SettingsScreenViewState.SignOut -> render(viewState)
} }
} }
...@@ -104,6 +118,10 @@ class SettingsScreenController : ...@@ -104,6 +118,10 @@ class SettingsScreenController :
} }
private fun render(viewState: SettingsScreenViewState.SignOut){
router.setRoot(RouterTransaction.with(AuthScreenController()))
}
@SuppressLint("SetTextI18n") @SuppressLint("SetTextI18n")
private fun render(viewState: SettingsScreenViewState.LoadSettingsList){ private fun render(viewState: SettingsScreenViewState.LoadSettingsList){
......
...@@ -2,8 +2,10 @@ package com.biganto.visual.roompark.presentation.screen.settings ...@@ -2,8 +2,10 @@ package com.biganto.visual.roompark.presentation.screen.settings
import android.content.Context import android.content.Context
import com.biganto.visual.roompark.base.RoomParkMainActivity import com.biganto.visual.roompark.base.RoomParkMainActivity
import com.biganto.visual.roompark.di.dagger.AppComponent import com.biganto.visual.roompark.data.repository.api.retrofit.di.RetrofitModule
import com.biganto.visual.roompark.di.dagger.PerScreen import com.biganto.visual.roompark.data.repository.db.requrey.DbModule
import com.biganto.visual.roompark.di.dagger.*
import com.biganto.visual.roompark.domain.contract.AuthContract
import dagger.Binds import dagger.Binds
import dagger.BindsInstance import dagger.BindsInstance
import dagger.Component import dagger.Component
...@@ -12,7 +14,8 @@ import dagger.Module ...@@ -12,7 +14,8 @@ import dagger.Module
@PerScreen @PerScreen
@Component( @Component(
modules = [SettingsScreenModule::class], modules = [SettingsScreenModule::class, DataModule::class
, RetrofitModule::class, AppModule::class, DbModule::class],
dependencies = [AppComponent::class]) dependencies = [AppComponent::class])
interface SettingsScreenComponent { interface SettingsScreenComponent {
...@@ -36,4 +39,8 @@ abstract class SettingsScreenModule{ ...@@ -36,4 +39,8 @@ abstract class SettingsScreenModule{
@Binds @Binds
abstract fun provideContext(activity: RoomParkMainActivity): Context abstract fun provideContext(activity: RoomParkMainActivity): Context
@PerScreen
@Binds
abstract fun provideAuth(contract: AuthContractModule): AuthContract
} }
...@@ -26,10 +26,17 @@ class SettingsScreenPresenter @Inject constructor( ...@@ -26,10 +26,17 @@ class SettingsScreenPresenter @Inject constructor(
val fetchSettings = interactor.fetchSettings() val fetchSettings = interactor.fetchSettings()
.map { SettingsScreenViewState.LoadSettingsList(it) } .map { SettingsScreenViewState.LoadSettingsList(it) }
val onSignOut = intent(SettingsScreen::signOut)
.flatMap { interactor.signOut()
.toObservable<SettingsScreenViewState>()
.map { SettingsScreenViewState.SignOut() }}
val state = restoreStateObservable val state = restoreStateObservable
.mergeWith(fetchSettings) .mergeWith(fetchSettings)
.mergeWith(onSignOut)
.doOnError{ Timber.e(it)} .doOnError{ Timber.e(it)}
.subscribeOn(Schedulers.io()) .subscribeOn(Schedulers.io())
.onErrorReturn(::parseError)
.observeOn(AndroidSchedulers.mainThread()) .observeOn(AndroidSchedulers.mainThread())
subscribeViewState(state.cast(SettingsScreenViewState::class.java), SettingsScreen::render) subscribeViewState(state.cast(SettingsScreenViewState::class.java), SettingsScreen::render)
......
...@@ -13,4 +13,5 @@ sealed class SettingsScreenViewState : BigantoBaseViewState() { ...@@ -13,4 +13,5 @@ sealed class SettingsScreenViewState : BigantoBaseViewState() {
class Idle : SettingsScreenViewState() class Idle : SettingsScreenViewState()
class LoadSettingsList(val settings:SettingsModel) : SettingsScreenViewState() class LoadSettingsList(val settings:SettingsModel) : SettingsScreenViewState()
class SomeError(val exception: ExceptionString) : SettingsScreenViewState() class SomeError(val exception: ExceptionString) : SettingsScreenViewState()
class SignOut() : SettingsScreenViewState()
} }
\ No newline at end of file
...@@ -52,13 +52,16 @@ ...@@ -52,13 +52,16 @@
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:nextFocusDown="@id/password_text_input"
app:layout_constraintEnd_toEndOf="parent" app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent" app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/textView3"> app:layout_constraintTop_toBottomOf="@+id/textView3">
<com.google.android.material.textfield.TextInputEditText <com.google.android.material.textfield.TextInputEditText
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="wrap_content" /> android:layout_height="wrap_content"
android:maxLength="64"
android:maxLines="1" />
</com.google.android.material.textfield.TextInputLayout> </com.google.android.material.textfield.TextInputLayout>
<FrameLayout <FrameLayout
...@@ -76,12 +79,15 @@ ...@@ -76,12 +79,15 @@
<com.google.android.material.textfield.TextInputLayout <com.google.android.material.textfield.TextInputLayout
android:id="@+id/password_text_input" android:id="@+id/password_text_input"
style="@style/AuthTextInputLayout.Password" style="@style/AuthTextInputLayout.Password"
android:nextFocusDown="@id/sign_in_button"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="match_parent"> android:layout_height="match_parent">
<com.google.android.material.textfield.TextInputEditText <com.google.android.material.textfield.TextInputEditText
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="wrap_content" /> android:layout_height="wrap_content"
android:maxLength="64"
android:maxLines="1" />
</com.google.android.material.textfield.TextInputLayout> </com.google.android.material.textfield.TextInputLayout>
<LinearLayout <LinearLayout
......
<?xml version="1.0" encoding="utf-8"?> <?xml version="1.0" encoding="utf-8"?>
<androidx.core.widget.NestedScrollView <androidx.core.widget.NestedScrollView xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/nestedScrollContainer" android:id="@+id/nestedScrollContainer"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="wrap_content" android:layout_height="wrap_content"
xmlns:android="http://schemas.android.com/apk/res/android"> xmlns:android="http://schemas.android.com/apk/res/android">
<LinearLayout xmlns:tools="http://schemas.android.com/tools" <LinearLayout
android:orientation="vertical" android:orientation="vertical"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="match_parent"> android:layout_height="match_parent">
...@@ -139,11 +139,11 @@ ...@@ -139,11 +139,11 @@
<com.google.android.material.textview.MaterialTextView <com.google.android.material.textview.MaterialTextView
android:id="@+id/signOutButton"
style="@style/Default_TextView.Cancel_Text" style="@style/Default_TextView.Cancel_Text"
android:text="СМЕНИТЬ АККАУНТ"
android:layout_margin="32dp"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="wrap_content" android:layout_height="wrap_content"
/> android:layout_margin="32dp"
android:text="СМЕНИТЬ АККАУНТ" />
</LinearLayout> </LinearLayout>
</androidx.core.widget.NestedScrollView> </androidx.core.widget.NestedScrollView>
\ 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