Skip to content

Commit 60ae32b

Browse files
authored
Improves the back button behaviour during manual login (#1787)
2 parents 0830041 + 99b44d3 commit 60ae32b

File tree

3 files changed

+20
-5
lines changed

3 files changed

+20
-5
lines changed

RELEASE-NOTES.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
2.38
22
-----
3-
3+
* Fixed back button navigation during manual login to return to the login screen instead of the home screen [#1751](https://github.com/Automattic/simplenote-android/issues/1751)
44

55
2.37
66
-----

Simplenote/src/main/java/com/automattic/simplenote/authentication/NewCredentialsActivity.kt

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -93,8 +93,6 @@ open class NewCredentialsActivity : ThemedAppCompatActivity() {
9393

9494
override fun onBackPressed() {
9595
super.onBackPressed()
96-
this.startActivity(Intent(this, SimplenoteAuthenticationActivity::class.java))
97-
finish()
9896
}
9997

10098
@SuppressLint("RestrictedApi")

Simplenote/src/main/java/com/automattic/simplenote/authentication/SignInFragment.kt

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,12 @@ class SignInFragment: MagicLinkableFragment() {
4444

4545
private var authService: AuthorizationService? = null
4646

47+
private var manualLoginLauncher = registerForActivityResult(ActivityResultContracts.StartActivityForResult()) { result ->
48+
if (result.resultCode == Activity.RESULT_OK) {
49+
activity?.finish()
50+
}
51+
}
52+
4753
private var resultLauncher = registerForActivityResult(ActivityResultContracts.StartActivityForResult()) { result ->
4854

4955
val data = result.data
@@ -118,7 +124,7 @@ class SignInFragment: MagicLinkableFragment() {
118124
}
119125
manualLoginTextView.setOnClickListener {
120126
val email = getEmailEditText()
121-
showLoginWithPassword(activity, email?.text?.toString())
127+
launchManualLogin(email?.text?.toString())
122128
}
123129
return view
124130
}
@@ -133,7 +139,7 @@ class SignInFragment: MagicLinkableFragment() {
133139
hideDialogProgress()
134140
if (state.code == 429) {
135141
val email = getEmailEditText()
136-
showLoginWithPassword(activity, email?.text?.toString())
142+
launchManualLogin(email?.text?.toString())
137143
}
138144
Toast.makeText(context, getString(state.messageRes), Toast.LENGTH_LONG).show()
139145
}
@@ -166,9 +172,20 @@ class SignInFragment: MagicLinkableFragment() {
166172
}
167173
}
168174

175+
private fun launchManualLogin(username: String?) {
176+
val intent = Intent(requireActivity(), NewCredentialsActivity::class.java)
177+
intent.putExtra("EXTRA_IS_LOGIN", true)
178+
if (!username.isNullOrBlank()) {
179+
intent.putExtra(Intent.EXTRA_EMAIL, username)
180+
intent.putExtra(NewCredentialsActivity.PREF_HIDE_EMAIL_FIELD, true)
181+
}
182+
manualLoginLauncher.launch(intent)
183+
}
184+
169185
override fun onDestroy() {
170186
super.onDestroy()
171187
resultLauncher.unregister()
188+
manualLoginLauncher.unregister()
172189
authService?.dispose()
173190
}
174191

0 commit comments

Comments
 (0)