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