mirror of
https://github.com/fork-maintainers/iceraven-browser
synced 2024-11-15 18:12:54 +00:00
Bug 1815628 - Show Saved Login Page after new credentials are added
This commit is contained in:
parent
10b7763333
commit
dd644d74fe
@ -14,6 +14,7 @@ import kotlinx.coroutines.Dispatchers
|
||||
import kotlinx.coroutines.async
|
||||
import kotlinx.coroutines.launch
|
||||
import kotlinx.coroutines.withContext
|
||||
import mozilla.components.concept.storage.EncryptedLogin
|
||||
import mozilla.components.concept.storage.Login
|
||||
import mozilla.components.concept.storage.LoginEntry
|
||||
import mozilla.components.service.sync.logins.InvalidRecordException
|
||||
@ -70,17 +71,22 @@ open class SavedLoginsStorageController(
|
||||
|
||||
fun add(originText: String, usernameText: String, passwordText: String) {
|
||||
var saveLoginJob: Deferred<Unit>? = null
|
||||
var id: String? = null
|
||||
lifecycleScope.launch(ioDispatcher) {
|
||||
saveLoginJob = async {
|
||||
add(loginEntryForAdd(originText, usernameText, passwordText))
|
||||
id = add(loginEntryForAdd(originText, usernameText, passwordText))
|
||||
}
|
||||
saveLoginJob?.await()
|
||||
withContext(Dispatchers.Main) {
|
||||
if (id.isNullOrEmpty()) {
|
||||
navController.popBackStack(R.id.savedLoginsFragment, false)
|
||||
} else {
|
||||
val directions =
|
||||
AddLoginFragmentDirections.actionAddLoginFragmentToSavedLoginsFragment()
|
||||
AddLoginFragmentDirections.actionAddLoginFragmentToLoginDetailFragment(id.toString())
|
||||
navController.navigate(directions)
|
||||
}
|
||||
}
|
||||
}
|
||||
saveLoginJob?.invokeOnCompletion {
|
||||
if (it is CancellationException) {
|
||||
saveLoginJob?.cancel()
|
||||
@ -88,9 +94,10 @@ open class SavedLoginsStorageController(
|
||||
}
|
||||
}
|
||||
|
||||
private suspend fun add(loginEntryToSave: LoginEntry) {
|
||||
private suspend fun add(loginEntryToSave: LoginEntry): String? {
|
||||
var encryptedLogin: EncryptedLogin? = null
|
||||
try {
|
||||
val encryptedLogin = passwordsStorage.add(loginEntryToSave)
|
||||
encryptedLogin = passwordsStorage.add(loginEntryToSave)
|
||||
syncAndUpdateList(passwordsStorage.decryptLogin(encryptedLogin))
|
||||
} catch (loginException: LoginsApiException) {
|
||||
Log.e(
|
||||
@ -99,6 +106,7 @@ open class SavedLoginsStorageController(
|
||||
loginException,
|
||||
)
|
||||
}
|
||||
return encryptedLogin?.guid
|
||||
}
|
||||
|
||||
// Create a [LoginEntry] for the edit login dialog
|
||||
|
@ -353,7 +353,7 @@ class AddLoginFragment : Fragment(R.layout.fragment_add_login), MenuProvider {
|
||||
|
||||
override fun onPause() {
|
||||
redirectToReAuth(
|
||||
listOf(R.id.savedLoginsFragment),
|
||||
listOf(R.id.loginDetailFragment, R.id.savedLoginsFragment),
|
||||
findNavController().currentDestination?.id,
|
||||
R.id.addLoginFragment,
|
||||
)
|
||||
|
@ -14,6 +14,7 @@ import android.view.MenuInflater
|
||||
import android.view.MenuItem
|
||||
import android.view.View
|
||||
import android.view.ViewGroup
|
||||
import androidx.activity.addCallback
|
||||
import androidx.appcompat.app.AlertDialog
|
||||
import androidx.core.view.MenuProvider
|
||||
import androidx.lifecycle.Lifecycle
|
||||
@ -123,6 +124,13 @@ class LoginDetailFragment : SecureFragment(R.layout.fragment_login_detail), Menu
|
||||
)
|
||||
super.onPause()
|
||||
}
|
||||
override fun onCreate(savedInstanceState: Bundle?) {
|
||||
super.onCreate(savedInstanceState)
|
||||
requireActivity().onBackPressedDispatcher.addCallback(this) {
|
||||
val directions = LoginDetailFragmentDirections.actionLoginDetailFragmentToSavedLoginsFragment()
|
||||
findNavController().navigate(directions)
|
||||
}
|
||||
}
|
||||
|
||||
private fun setUpPasswordReveal() {
|
||||
binding.passwordText.inputType =
|
||||
|
@ -474,6 +474,12 @@
|
||||
app:popUpToInclusive="true" />
|
||||
</fragment>
|
||||
|
||||
<action
|
||||
android:id="@+id/action_loginDetailFragment_to_savedLoginsFragment"
|
||||
app:destination="@id/savedLoginsFragment"
|
||||
app:popUpTo="@id/savedLoginsFragment"
|
||||
app:popUpToInclusive="true"/>
|
||||
|
||||
<fragment
|
||||
android:id="@+id/editLoginFragment"
|
||||
android:name="org.mozilla.fenix.settings.logins.fragment.EditLoginFragment"
|
||||
@ -496,10 +502,10 @@
|
||||
android:label="@string/add_login"
|
||||
tools:layout="@layout/fragment_add_login">
|
||||
<action
|
||||
android:id="@+id/action_addLoginFragment_to_savedLoginsFragment"
|
||||
app:destination="@id/savedLoginsFragment"
|
||||
android:id="@+id/action_addLoginFragment_to_loginDetailFragment"
|
||||
app:destination="@id/loginDetailFragment"
|
||||
app:popUpTo="@id/savedLoginsFragment"
|
||||
app:popUpToInclusive="true" />
|
||||
app:popUpToInclusive="false" />
|
||||
</fragment>
|
||||
|
||||
<fragment
|
||||
|
Loading…
Reference in New Issue
Block a user