mirror of
https://github.com/SchildiChat/SchildiChat-android.git
synced 2025-03-17 19:58:57 +03:00
Login screens: back button management for registration
This commit is contained in:
parent
62d5aba796
commit
0e2237226f
7 changed files with 34 additions and 11 deletions
|
@ -16,10 +16,12 @@
|
|||
|
||||
package im.vector.riotx.features.login
|
||||
|
||||
import android.app.AlertDialog
|
||||
import android.os.Bundle
|
||||
import android.view.View
|
||||
import androidx.annotation.CallSuper
|
||||
import com.airbnb.mvrx.activityViewModel
|
||||
import im.vector.riotx.R
|
||||
import im.vector.riotx.core.platform.OnBackPressed
|
||||
import im.vector.riotx.core.platform.VectorBaseFragment
|
||||
|
||||
|
@ -39,9 +41,24 @@ abstract class AbstractLoginFragment : VectorBaseFragment(), OnBackPressed {
|
|||
}
|
||||
|
||||
override fun onBackPressed(toolbarButton: Boolean): Boolean {
|
||||
resetViewModel()
|
||||
// Do not consume the Back event
|
||||
return false
|
||||
if (loginViewModel.isPasswordSent) {
|
||||
// Ask for confirmation before cancelling the registration
|
||||
AlertDialog.Builder(requireActivity())
|
||||
.setTitle(R.string.login_signup_cancel_confirmation_title)
|
||||
.setMessage(R.string.login_signup_cancel_confirmation_content)
|
||||
.setPositiveButton(R.string.login_signup_cancel_confirmation_yes) { _, _ ->
|
||||
resetViewModel()
|
||||
vectorBaseActivity.onBackPressed()
|
||||
}
|
||||
.setNegativeButton(R.string.login_signup_cancel_confirmation_no, null)
|
||||
.show()
|
||||
|
||||
return true
|
||||
} else {
|
||||
resetViewModel()
|
||||
// Do not consume the Back event
|
||||
return false
|
||||
}
|
||||
}
|
||||
|
||||
// Reset any modification on the loginViewModel by the current fragment
|
||||
|
|
|
@ -127,7 +127,11 @@ class LoginActivity : VectorBaseActivity(), ToolbarConfigurable {
|
|||
handleRegistrationNavigation(loginViewEvents.flowResult)
|
||||
} else {
|
||||
// First ask for login and password
|
||||
addFragmentToBackstack(R.id.loginFragmentContainer, LoginFragment::class.java)
|
||||
// I add a tag to indicate that this fragment is a registration stage.
|
||||
// This way it will be automatically popped in when starting the next registration stage
|
||||
addFragmentToBackstack(R.id.loginFragmentContainer,
|
||||
LoginFragment::class.java,
|
||||
tag = FRAGMENT_REGISTRATION_STAGE_TAG)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -235,7 +239,7 @@ class LoginActivity : VectorBaseActivity(), ToolbarConfigurable {
|
|||
}
|
||||
|
||||
private fun handleRegistrationNavigation(flowResult: FlowResult) {
|
||||
// Complete all mandatory stage first
|
||||
// Complete all mandatory stages first
|
||||
val mandatoryStage = flowResult.missingStages.firstOrNull { it.mandatory }
|
||||
|
||||
if (mandatoryStage != null) {
|
||||
|
|
|
@ -172,11 +172,9 @@ class LoginCaptchaFragment @Inject constructor(private val assetReader: AssetRea
|
|||
return true
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
override fun resetViewModel() {
|
||||
// Nothing to do
|
||||
loginViewModel.handle(LoginAction.ResetLogin)
|
||||
}
|
||||
}
|
||||
|
|
|
@ -129,6 +129,6 @@ class LoginGenericTextInputFormFragment @Inject constructor() : AbstractLoginFra
|
|||
}
|
||||
|
||||
override fun resetViewModel() {
|
||||
// Nothing to do
|
||||
loginViewModel.handle(LoginAction.ResetLogin)
|
||||
}
|
||||
}
|
||||
|
|
|
@ -238,7 +238,7 @@ class LoginWebFragment @Inject constructor(private val assetReader: AssetReader)
|
|||
}
|
||||
|
||||
override fun resetViewModel() {
|
||||
// Nothing to do
|
||||
loginViewModel.handle(LoginAction.ResetLogin)
|
||||
}
|
||||
|
||||
override fun onBackPressed(toolbarButton: Boolean): Boolean {
|
||||
|
|
|
@ -104,6 +104,6 @@ class LoginTermsFragment @Inject constructor(private val policyController: Polic
|
|||
}
|
||||
|
||||
override fun resetViewModel() {
|
||||
// No op
|
||||
loginViewModel.handle(LoginAction.ResetLogin)
|
||||
}
|
||||
}
|
||||
|
|
|
@ -97,6 +97,10 @@
|
|||
<string name="login_signup_password_hint">Password</string>
|
||||
<string name="login_signup_submit">Next</string>
|
||||
<string name="login_signup_error_user_in_use">That username is taken</string>
|
||||
<string name="login_signup_cancel_confirmation_title">Warning</string>
|
||||
<string name="login_signup_cancel_confirmation_content">Your account is not created yet.\n\nStop the registration process?</string>
|
||||
<string name="login_signup_cancel_confirmation_yes">Yes</string>
|
||||
<string name="login_signup_cancel_confirmation_no">No</string>
|
||||
|
||||
<string name="login_a11y_choose_matrix_org">Select matrix.org</string>
|
||||
<string name="login_a11y_choose_modular">Select modular</string>
|
||||
|
|
Loading…
Add table
Reference in a new issue