Skip to content
This repository has been archived by the owner on Feb 20, 2023. It is now read-only.

Commit

Permalink
For #7854 - Update the views only if the bookmark node has changed
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
Juan Goncalves authored and kglazko committed May 18, 2020
1 parent 2a5c585 commit ee62297
Showing 1 changed file with 5 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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 ->
Expand Down

0 comments on commit ee62297

Please sign in to comment.