Skip to content
Snippets Groups Projects
Commit c40a29d1 authored by Taras's avatar Taras
Browse files

Add name and password for start registration

parent 8733fa96
No related branches found
No related tags found
No related merge requests found
......@@ -24,7 +24,7 @@ val dataSourceModule = module {
factory { CreateGroupDataSource() }
single { SignUpDataSource(get()) }
factory { ValidateTokenDataSource(get()) }
factory { SelectSignUpTypeDataSource(get()) }
factory { SelectSignUpTypeDataSource(get(), get()) }
factory { AcceptTermsDataSource(get(), get()) }
factory { ValidateEmailDataSource(get()) }
}
\ No newline at end of file
......@@ -2,6 +2,7 @@ package com.futo.circles.feature.sign_up_type
import android.os.Bundle
import android.view.View
import androidx.core.widget.doAfterTextChanged
import androidx.fragment.app.Fragment
import by.kirich1409.viewbindingdelegate.viewBinding
import com.futo.circles.R
......@@ -20,14 +21,30 @@ class SelectSignUpTypeFragment : Fragment(R.layout.select_sign_up_type_fragment)
override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
super.onViewCreated(view, savedInstanceState)
viewModel.clearSubtitle()
setupViews()
setupObservers()
}
binding.btnToken.setOnClickListener {
startLoading(binding.btnToken)
viewModel.startSignUp()
private fun setupViews() {
with(binding) {
tilUserName.editText?.doAfterTextChanged { setTokenButtonEnabled() }
tilPassword.editText?.doAfterTextChanged { setTokenButtonEnabled() }
btnToken.setOnClickListener {
startLoading(btnToken)
viewModel.startSignUp(
tilUserName.editText?.text?.trim()?.toString() ?: "",
tilPassword.editText?.text?.trim()?.toString() ?: ""
)
}
}
}
private fun setupObservers() {
viewModel.startSignUpEventLiveData.observeResponse(this)
}
private fun setTokenButtonEnabled() {
binding.btnToken.isEnabled = binding.tilUserName.editText?.text?.isNotEmpty() == true &&
binding.tilPassword.editText?.text?.isNotEmpty() == true
}
}
\ No newline at end of file
......@@ -12,9 +12,11 @@ class SelectSignUpTypeViewModel(
val startSignUpEventLiveData = SingleEventLiveData<Response<Unit?>>()
fun startSignUp() {
fun startSignUp(name: String, password: String) {
launchBg {
startSignUpEventLiveData.postValue(dataSource.startNewRegistration())
startSignUpEventLiveData.postValue(
dataSource.startNewRegistration(name, password)
)
}
}
......
package com.futo.circles.feature.sign_up_type.data_source
import android.content.Context
import com.futo.circles.R
import com.futo.circles.extensions.createResult
import com.futo.circles.feature.sign_up.data_source.SignUpDataSource
import com.futo.circles.provider.MatrixInstanceProvider
import org.matrix.android.sdk.api.auth.registration.RegistrationResult
class SelectSignUpTypeDataSource(
private val context: Context,
private val signUpDataSource: SignUpDataSource
) {
......@@ -13,17 +16,20 @@ class SelectSignUpTypeDataSource(
private val registrationWizard by lazy { authService.getRegistrationWizard() }
fun clearSubtitle(){
fun clearSubtitle() {
signUpDataSource.clearSubtitle()
}
suspend fun startNewRegistration() = createResult {
authService.cancelPendingLoginOrRegistration()
(registrationWizard.createAccount(null, null, null)
as? RegistrationResult.FlowResponse)
?.let {
signUpDataSource.startSignUpStages(it.flowResult.missingStages)
}
}
suspend fun startNewRegistration(name: String, password: String) = createResult {
authService.cancelPendingLoginOrRegistration()
(registrationWizard.createAccount(
name, password,
context.getString(R.string.initial_device_name, context.getString(R.string.app_name))
)
as? RegistrationResult.FlowResponse)
?.let {
signUpDataSource.startSignUpStages(it.flowResult.missingStages)
}
}
}
\ No newline at end of file
......@@ -4,14 +4,14 @@
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingHorizontal="36dp"
android:paddingVertical="24dp">
android:paddingVertical="16dp">
<androidx.constraintlayout.widget.Guideline
android:id="@+id/guidelineLogo"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="horizontal"
app:layout_constraintGuide_percent="0.35" />
app:layout_constraintGuide_percent="0.3" />
<com.futo.circles.view.CirclesLogoView
android:id="@+id/ivLogo"
......@@ -22,6 +22,49 @@
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
<com.google.android.material.textfield.TextInputLayout
android:id="@+id/tilUserName"
style="@style/Widget.MaterialComponents.TextInputLayout.OutlinedBox"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginTop="16dp"
android:hint="@string/username"
app:layout_constraintBottom_toTopOf="@id/tilPassword"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@id/guidelineLogo">
<com.google.android.material.textfield.TextInputEditText
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:imeOptions="actionNext"
android:inputType="text"
android:maxLines="1"
android:padding="12dp" />
</com.google.android.material.textfield.TextInputLayout>
<com.google.android.material.textfield.TextInputLayout
android:id="@+id/tilPassword"
style="@style/Widget.MaterialComponents.TextInputLayout.OutlinedBox"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginTop="4dp"
android:hint="@string/password"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@id/tilUserName"
app:passwordToggleEnabled="true">
<com.google.android.material.textfield.TextInputEditText
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:imeOptions="actionDone"
android:inputType="textPassword"
android:padding="8dp" />
</com.google.android.material.textfield.TextInputLayout>
<TextView
android:id="@+id/tvTokenTitle"
......@@ -33,7 +76,7 @@
app:layout_constraintBottom_toTopOf="@id/btnToken"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@id/guidelineLogo"
app:layout_constraintTop_toBottomOf="@id/tilPassword"
app:layout_constraintVertical_bias="0.3"
app:layout_constraintVertical_chainStyle="packed" />
......@@ -42,6 +85,7 @@
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginTop="8dp"
android:enabled="false"
android:text="@string/sign_up_with_token"
app:layout_constraintBottom_toTopOf="@id/tvOr"
app:layout_constraintEnd_toEndOf="parent"
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment