2
0
mirror of https://github.com/fork-maintainers/iceraven-browser synced 2024-11-19 09:25:34 +00:00

[fenix] For https://github.com/mozilla-mobile/fenix/issues/13157: Filter out folder being edited from 'select folder' dialog

This commit is contained in:
Grisha Kruglov 2020-09-18 16:37:03 -07:00 committed by Grisha Kruglov
parent 412ae60537
commit f79c9733e1
4 changed files with 23 additions and 4 deletions

View File

@ -107,7 +107,12 @@ class EditBookmarkFragment : Fragment(R.layout.fragment_edit_bookmark) {
R.id.bookmarkEditFragment,
EditBookmarkFragmentDirections
.actionBookmarkEditFragmentToBookmarkSelectFolderFragment(
allowCreatingNewFolder = false
allowCreatingNewFolder = false,
// Don't allow moving folders into themselves.
hideFolderGuid = when (bookmarkNode!!.type) {
BookmarkNodeType.FOLDER -> bookmarkNode!!.guid
else -> null
}
)
)
}

View File

@ -24,12 +24,19 @@ import org.mozilla.fenix.library.bookmarks.selectfolder.SelectBookmarkFolderAdap
class SelectBookmarkFolderAdapter(private val sharedViewModel: BookmarksSharedViewModel) :
ListAdapter<BookmarkNodeWithDepth, BookmarkFolderViewHolder>(DiffCallback) {
fun updateData(tree: BookmarkNode?) {
fun updateData(tree: BookmarkNode?, hideFolderGuid: String?) {
val updatedData = tree
?.convertToFolderDepthTree()
?.drop(1)
.orEmpty()
submitList(updatedData)
val filteredData = if (hideFolderGuid != null && updatedData.isNotEmpty()) {
updatedData.filter { it.node.guid != hideFolderGuid }
} else {
updatedData
}
submitList(filteredData)
}
override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): BookmarkFolderViewHolder {

View File

@ -50,6 +50,8 @@ class SelectBookmarkFolderFragment : Fragment() {
super.onResume()
showToolbar(getString(R.string.bookmark_select_folder_fragment_label))
val args: SelectBookmarkFolderFragmentArgs by navArgs()
viewLifecycleOwner.lifecycleScope.launch(Main) {
bookmarkNode = withContext(IO) {
val context = requireContext()
@ -59,7 +61,7 @@ class SelectBookmarkFolderFragment : Fragment() {
}
val adapter = SelectBookmarkFolderAdapter(sharedViewModel)
recylerViewBookmarkFolders.adapter = adapter
adapter.updateData(bookmarkNode)
adapter.updateData(bookmarkNode, args.hideFolderGuid)
}
}

View File

@ -308,6 +308,11 @@
android:name="allowCreatingNewFolder"
android:defaultValue="false"
app:argType="boolean" />
<argument
android:name="hideFolderGuid"
android:defaultValue="@null"
app:nullable="true"
app:argType="string" />
</fragment>
<fragment