From b5b32ba6ea9a6ad28b406cac5cf933242484a18a Mon Sep 17 00:00:00 2001 From: Grisha Kruglov Date: Fri, 18 Sep 2020 18:05:52 -0700 Subject: [PATCH] For #11502: Make sure to always process root titles for parent folders during edit This also switches to a simpler bookmarks query API ('getBookmark') which doesn't fetch children. We don't need 'children' for this dialog, and so don't need to do the extra work. --- .../bookmarks/edit/EditBookmarkFragment.kt | 53 +++++++++++-------- 1 file changed, 31 insertions(+), 22 deletions(-) diff --git a/app/src/main/java/org/mozilla/fenix/library/bookmarks/edit/EditBookmarkFragment.kt b/app/src/main/java/org/mozilla/fenix/library/bookmarks/edit/EditBookmarkFragment.kt index 72960d3cf..6ddce9068 100644 --- a/app/src/main/java/org/mozilla/fenix/library/bookmarks/edit/EditBookmarkFragment.kt +++ b/app/src/main/java/org/mozilla/fenix/library/bookmarks/edit/EditBookmarkFragment.kt @@ -71,14 +71,22 @@ class EditBookmarkFragment : Fragment(R.layout.fragment_edit_bookmark) { viewLifecycleOwner.lifecycleScope.launch(Main) { val context = requireContext() val bookmarkNodeBeforeReload = bookmarkNode + val bookmarksStorage = context.components.core.bookmarksStorage - withContext(IO) { - val bookmarksStorage = context.components.core.bookmarksStorage - bookmarkNode = bookmarksStorage.getTree(args.guidToEdit) - bookmarkParent = sharedViewModel.selectedFolder - ?: bookmarkNode?.parentGuid - ?.let { bookmarksStorage.getTree(it) } - ?.let { DesktopFolders(context, showMobileRoot = true).withRootTitle(it) } + bookmarkNode = withContext(IO) { + bookmarksStorage.getBookmark(args.guidToEdit) + } + + bookmarkParent = withContext(IO) { + // Use user-selected parent folder if it's set, or node's current parent otherwise. + if (sharedViewModel.selectedFolder != null) { + sharedViewModel.selectedFolder + } else { + bookmarkNode?.parentGuid?.let { bookmarksStorage.getBookmark(it) } + }?.let { + // No-op for non-root nodes, and copies a node with a friendly title otherwise. + DesktopFolders(context, showMobileRoot = true).withRootTitle(it) + } } when (bookmarkNode?.type) { @@ -101,21 +109,22 @@ class EditBookmarkFragment : Fragment(R.layout.fragment_edit_bookmark) { bookmarkParent?.let { node -> bookmarkParentFolderSelector.text = node.title - bookmarkParentFolderSelector.setOnClickListener { - sharedViewModel.selectedFolder = null - nav( - R.id.bookmarkEditFragment, - EditBookmarkFragmentDirections - .actionBookmarkEditFragmentToBookmarkSelectFolderFragment( - allowCreatingNewFolder = false, - // Don't allow moving folders into themselves. - hideFolderGuid = when (bookmarkNode!!.type) { - BookmarkNodeType.FOLDER -> bookmarkNode!!.guid - else -> null - } - ) - ) - } + } + + bookmarkParentFolderSelector.setOnClickListener { + sharedViewModel.selectedFolder = null + nav( + R.id.bookmarkEditFragment, + EditBookmarkFragmentDirections + .actionBookmarkEditFragmentToBookmarkSelectFolderFragment( + allowCreatingNewFolder = false, + // Don't allow moving folders into themselves. + hideFolderGuid = when (bookmarkNode!!.type) { + BookmarkNodeType.FOLDER -> bookmarkNode!!.guid + else -> null + } + ) + ) } view.bookmarkNameEdit.apply {