From 4f6213a2dd12a4f2ef99952049b1c9f106d34eef Mon Sep 17 00:00:00 2001 From: Grisha Kruglov Date: Fri, 18 Sep 2020 21:17:09 -0700 Subject: [PATCH] [fenix] For https://github.com/mozilla-mobile/fenix/issues/2792: Display bookmark folders at the top of the bookmarks UI --- .../fenix/library/bookmarks/BookmarkAdapter.kt | 18 ++++++++++++++++-- 1 file changed, 16 insertions(+), 2 deletions(-) diff --git a/app/src/main/java/org/mozilla/fenix/library/bookmarks/BookmarkAdapter.kt b/app/src/main/java/org/mozilla/fenix/library/bookmarks/BookmarkAdapter.kt index 2843bc4430..f6f6a368de 100644 --- a/app/src/main/java/org/mozilla/fenix/library/bookmarks/BookmarkAdapter.kt +++ b/app/src/main/java/org/mozilla/fenix/library/bookmarks/BookmarkAdapter.kt @@ -26,16 +26,30 @@ class BookmarkAdapter(private val emptyView: View, private val interactor: Bookm private var isFirstRun = true fun updateData(tree: BookmarkNode?, mode: BookmarkFragmentState.Mode) { + // Display folders above all other bookmarks. + val allNodes = tree?.children.orEmpty() + val folders: MutableList = mutableListOf() + val notFolders: MutableList = mutableListOf() + allNodes.forEach { + if (it.type == BookmarkNodeType.FOLDER) { + folders.add(it) + } else { + notFolders.add(it) + } + } + val newTree = folders + notFolders + val diffUtil = DiffUtil.calculateDiff( BookmarkDiffUtil( this.tree, - tree?.children.orEmpty(), + newTree, this.mode, mode ) ) - this.tree = tree?.children.orEmpty() + this.tree = newTree + isFirstRun = if (isFirstRun) false else { emptyView.isVisible = this.tree.isEmpty() false