From 99de618bed6a0669e46bd6c789ba5c9dda26d29f Mon Sep 17 00:00:00 2001 From: Adam Brown Date: Thu, 4 Aug 2022 14:18:03 +0100 Subject: [PATCH 1/4] adding edit text ids so that the content can automatically be restored by the fragment manager --- vector/src/main/res/layout/fragment_ftue_combined_login.xml | 2 ++ vector/src/main/res/layout/fragment_ftue_combined_register.xml | 2 ++ 2 files changed, 4 insertions(+) diff --git a/vector/src/main/res/layout/fragment_ftue_combined_login.xml b/vector/src/main/res/layout/fragment_ftue_combined_login.xml index 9533ab29fc..12943b4dc0 100644 --- a/vector/src/main/res/layout/fragment_ftue_combined_login.xml +++ b/vector/src/main/res/layout/fragment_ftue_combined_login.xml @@ -147,6 +147,7 @@ app:layout_constraintTop_toBottomOf="@id/serverSelectionSpacing"> Date: Thu, 4 Aug 2022 14:25:05 +0100 Subject: [PATCH 2/4] fixing login/account creation errors showing when navigating to another screen - was caused by the lost focus callback being triggered by onPause, fixed by only triggering if the current view is in the resumed state --- .../im/vector/app/core/extensions/TextInputLayout.kt | 9 +++++++-- .../onboarding/ftueauth/FtueAuthCombinedLoginFragment.kt | 4 +++- .../ftueauth/FtueAuthCombinedRegisterFragment.kt | 2 +- 3 files changed, 11 insertions(+), 4 deletions(-) diff --git a/vector/src/main/java/im/vector/app/core/extensions/TextInputLayout.kt b/vector/src/main/java/im/vector/app/core/extensions/TextInputLayout.kt index 4739840f01..f1b5f5ce09 100644 --- a/vector/src/main/java/im/vector/app/core/extensions/TextInputLayout.kt +++ b/vector/src/main/java/im/vector/app/core/extensions/TextInputLayout.kt @@ -78,10 +78,15 @@ fun TextInputLayout.setOnImeDoneListener(action: () -> Unit) { } } -fun TextInputLayout.setOnFocusLostListener(action: () -> Unit) { +/** + * Set a listener for when the input has lost focus, such as moving to the another input field. + * The listener is only called when the view is in a resumed state to avoid triggers when exiting a screen. + */ +fun TextInputLayout.setOnFocusLostListener(lifecycleOwner: LifecycleOwner, action: () -> Unit) { + lifecycleOwner.lifecycle editText().setOnFocusChangeListener { _, hasFocus -> when (hasFocus) { - false -> action() + false -> lifecycleOwner.lifecycleScope.launchWhenResumed { action() } else -> { // do nothing } diff --git a/vector/src/main/java/im/vector/app/features/onboarding/ftueauth/FtueAuthCombinedLoginFragment.kt b/vector/src/main/java/im/vector/app/features/onboarding/ftueauth/FtueAuthCombinedLoginFragment.kt index 58b1edddf8..c2d2346765 100644 --- a/vector/src/main/java/im/vector/app/features/onboarding/ftueauth/FtueAuthCombinedLoginFragment.kt +++ b/vector/src/main/java/im/vector/app/features/onboarding/ftueauth/FtueAuthCombinedLoginFragment.kt @@ -63,7 +63,9 @@ class FtueAuthCombinedLoginFragment @Inject constructor( views.loginRoot.realignPercentagesToParent() views.editServerButton.debouncedClicks { viewModel.handle(OnboardingAction.PostViewEvent(OnboardingViewEvents.EditServerSelection)) } views.loginPasswordInput.setOnImeDoneListener { submit() } - views.loginInput.setOnFocusLostListener { viewModel.handle(OnboardingAction.UserNameEnteredAction.Login(views.loginInput.content())) } + views.loginInput.setOnFocusLostListener(viewLifecycleOwner) { + viewModel.handle(OnboardingAction.UserNameEnteredAction.Login(views.loginInput.content())) + } views.loginForgotPassword.debouncedClicks { viewModel.handle(OnboardingAction.PostViewEvent(OnboardingViewEvents.OnForgetPasswordClicked)) } } diff --git a/vector/src/main/java/im/vector/app/features/onboarding/ftueauth/FtueAuthCombinedRegisterFragment.kt b/vector/src/main/java/im/vector/app/features/onboarding/ftueauth/FtueAuthCombinedRegisterFragment.kt index c69706a17b..8340fb903a 100644 --- a/vector/src/main/java/im/vector/app/features/onboarding/ftueauth/FtueAuthCombinedRegisterFragment.kt +++ b/vector/src/main/java/im/vector/app/features/onboarding/ftueauth/FtueAuthCombinedRegisterFragment.kt @@ -86,7 +86,7 @@ class FtueAuthCombinedRegisterFragment @Inject constructor() : AbstractSSOFtueAu views.createAccountEntryFooter.text = "" } - views.createAccountInput.setOnFocusLostListener { + views.createAccountInput.setOnFocusLostListener(viewLifecycleOwner) { viewModel.handle(OnboardingAction.UserNameEnteredAction.Registration(views.createAccountInput.content())) } } From b6582c41443c2f4960d0554aa1977b5590407ebc Mon Sep 17 00:00:00 2001 From: Adam Brown Date: Thu, 4 Aug 2022 14:29:26 +0100 Subject: [PATCH 3/4] adding changelog entry --- changelog.d/6737.bugfix | 1 + 1 file changed, 1 insertion(+) create mode 100644 changelog.d/6737.bugfix diff --git a/changelog.d/6737.bugfix b/changelog.d/6737.bugfix new file mode 100644 index 0000000000..6568e9ff31 --- /dev/null +++ b/changelog.d/6737.bugfix @@ -0,0 +1 @@ +Fixes onboarding login/account creation errors showing after navigation From b375dd14f781c076482c87fa81ebaa54d70db78c Mon Sep 17 00:00:00 2001 From: Adam Brown Date: Fri, 5 Aug 2022 11:18:53 +0100 Subject: [PATCH 4/4] removing unused line --- .../main/java/im/vector/app/core/extensions/TextInputLayout.kt | 1 - 1 file changed, 1 deletion(-) diff --git a/vector/src/main/java/im/vector/app/core/extensions/TextInputLayout.kt b/vector/src/main/java/im/vector/app/core/extensions/TextInputLayout.kt index f1b5f5ce09..909c343a45 100644 --- a/vector/src/main/java/im/vector/app/core/extensions/TextInputLayout.kt +++ b/vector/src/main/java/im/vector/app/core/extensions/TextInputLayout.kt @@ -83,7 +83,6 @@ fun TextInputLayout.setOnImeDoneListener(action: () -> Unit) { * The listener is only called when the view is in a resumed state to avoid triggers when exiting a screen. */ fun TextInputLayout.setOnFocusLostListener(lifecycleOwner: LifecycleOwner, action: () -> Unit) { - lifecycleOwner.lifecycle editText().setOnFocusChangeListener { _, hasFocus -> when (hasFocus) { false -> lifecycleOwner.lifecycleScope.launchWhenResumed { action() }