// Only move in cache, not in tree funonMoveHolder( viewHolder: RecyclerView.ViewHolder, target: RecyclerView.ViewHolder ): Boolean { val srcNode = getItem(viewHolder.adapterPosition) var targetNode = getItem(max(0, target.adapterPosition - 1))
if (targetNode.path.startsWith(srcNode.path) && srcNode.depth < targetNode.depth) { returnfalse }
val targetData = targetNode.requireData() val targetDataParent = targetData.parent val srcData = srcNode.requireData() val srcDataParent = srcData.parent
val targetDataSource = if (targetData is MultipleDataSourceSupport<*>) { targetData as MultipleDataSourceSupport<T> } else { (targetDataParent as MultipleDataSourceSupport<T>) }
val srcDataParentDataSource = srcDataParent as MultipleDataSourceSupport<T>
srcDataParentDataSource.remove(srcData)
targetDataSource.add(srcData)
srcData.parent = if (targetData is MultipleDataSourceSupport<*>) { targetData } else { targetDataParent }
/** * Binder for TreeView and nodes. * * TreeView calls this class to get the generated itemView and bind the node data to the itemView * * @see [TreeView.binder] */ abstractclassTreeViewBinder<T : Any> : DiffUtil.ItemCallback<TreeNode<T>>() {
/** * like [ItemTouchHelper.Callback.clearView] * * Called when the view is released after dragging. * * You can override this method to do some operations on the view, such as set background color, etc. * * And you need to call [AbstractTree.moveNode], otherwise the node will not be moved. * * * @see [ItemTouchHelper.Callback.clearView] */ openfunonMovedView( srcNode: TreeNode<T>, targetNode: TreeNode<T>? = null, holder: RecyclerView.ViewHolder ) { }
/** * like [ItemTouchHelper.Callback.onSelectedChanged] * * Called when the view is selected after dragging. * * You can override this method to do some operations on the view, such as set background color, etc. */ openfunonMoveView( srcHolder: RecyclerView.ViewHolder, srcNode: TreeNode<T>, targetHolder: RecyclerView.ViewHolder? = null, targetNode: TreeNode<T>? = null, ): Boolean { returntrue } }