For #2792: Display bookmark folders at the top of the bookmarks UI
This commit is contained in:
parent
078843675b
commit
b7b3ee5ce6
|
@ -26,16 +26,30 @@ class BookmarkAdapter(private val emptyView: View, private val interactor: Bookm
|
||||||
private var isFirstRun = true
|
private var isFirstRun = true
|
||||||
|
|
||||||
fun updateData(tree: BookmarkNode?, mode: BookmarkFragmentState.Mode) {
|
fun updateData(tree: BookmarkNode?, mode: BookmarkFragmentState.Mode) {
|
||||||
|
// Display folders above all other bookmarks.
|
||||||
|
val allNodes = tree?.children.orEmpty()
|
||||||
|
val folders: MutableList<BookmarkNode> = mutableListOf()
|
||||||
|
val notFolders: MutableList<BookmarkNode> = mutableListOf()
|
||||||
|
allNodes.forEach {
|
||||||
|
if (it.type == BookmarkNodeType.FOLDER) {
|
||||||
|
folders.add(it)
|
||||||
|
} else {
|
||||||
|
notFolders.add(it)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
val newTree = folders + notFolders
|
||||||
|
|
||||||
val diffUtil = DiffUtil.calculateDiff(
|
val diffUtil = DiffUtil.calculateDiff(
|
||||||
BookmarkDiffUtil(
|
BookmarkDiffUtil(
|
||||||
this.tree,
|
this.tree,
|
||||||
tree?.children.orEmpty(),
|
newTree,
|
||||||
this.mode,
|
this.mode,
|
||||||
mode
|
mode
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
|
|
||||||
this.tree = tree?.children.orEmpty()
|
this.tree = newTree
|
||||||
|
|
||||||
isFirstRun = if (isFirstRun) false else {
|
isFirstRun = if (isFirstRun) false else {
|
||||||
emptyView.isVisible = this.tree.isEmpty()
|
emptyView.isVisible = this.tree.isEmpty()
|
||||||
false
|
false
|
||||||
|
|
Loading…
Reference in New Issue
Block a user