[fenix] For https://github.com/mozilla-mobile/fenix/issues/7854 - Update the views only if the bookmark node has changed

As the bookmark node data is loaded from storage every time the fragment's view is created, when the user navigates to the SelectFolderFragment and returns, the bookmark is loaded once again from storage, replacing the EditText's content (title and URL) which causes the loss of user input.

Validating that the loaded bookmark is different from the one that is already referenced in the fragment avoids unnecessarily replacing the `EditText`s values.
pull/600/head
Juan Goncalves 5 years ago committed by kglazko
parent 0259540eb6
commit e55ee21914

@ -67,6 +67,7 @@ class EditBookmarkFragment : Fragment(R.layout.fragment_edit_bookmark) {
viewLifecycleOwner.lifecycleScope.launch(Main) {
val context = requireContext()
val bookmarkNodeBeforeReload = bookmarkNode
withContext(IO) {
val bookmarksStorage = context.components.core.bookmarksStorage
@ -89,9 +90,10 @@ class EditBookmarkFragment : Fragment(R.layout.fragment_edit_bookmark) {
else -> throw IllegalArgumentException()
}
bookmarkNode?.let { bookmarkNode ->
bookmarkNameEdit.setText(bookmarkNode.title)
bookmarkUrlEdit.setText(bookmarkNode.url)
val currentBookmarkNode = bookmarkNode
if (currentBookmarkNode != null && currentBookmarkNode != bookmarkNodeBeforeReload) {
bookmarkNameEdit.setText(currentBookmarkNode.title)
bookmarkUrlEdit.setText(currentBookmarkNode.url)
}
bookmarkParent?.let { node ->

Loading…
Cancel
Save