From 295c11f0745cec4d0731aa2695c4b74c272fe767 Mon Sep 17 00:00:00 2001 From: dltkd1395 Date: Wed, 13 Dec 2023 16:49:37 +0900 Subject: [PATCH 1/5] =?UTF-8?q?feat(#293):=20strings-mindmap=20=EC=B6=94?= =?UTF-8?q?=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- AOS/app/src/main/res/values/strings-mindmap.xml | 7 +++++++ 1 file changed, 7 insertions(+) create mode 100644 AOS/app/src/main/res/values/strings-mindmap.xml diff --git a/AOS/app/src/main/res/values/strings-mindmap.xml b/AOS/app/src/main/res/values/strings-mindmap.xml new file mode 100644 index 00000000..5feefe1c --- /dev/null +++ b/AOS/app/src/main/res/values/strings-mindmap.xml @@ -0,0 +1,7 @@ + + + add + + 텍스트 입력 + 작성 + \ No newline at end of file From b8d1021adc2611230e0257f51ae42c1ca8354883 Mon Sep 17 00:00:00 2001 From: dltkd1395 Date: Wed, 13 Dec 2023 16:51:00 +0900 Subject: [PATCH 2/5] =?UTF-8?q?feat(#293):=20operationType=20=ED=94=84?= =?UTF-8?q?=EB=A1=9C=ED=8D=BC=ED=8B=B0=20=EC=B6=94=EA=B0=80=20=EB=B0=8F=20?= =?UTF-8?q?updateOperationType=20=ED=95=A8=EC=88=98=20=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../mindsync/ui/mindmap/MindMapViewModel.kt | 283 +++++++++--------- 1 file changed, 146 insertions(+), 137 deletions(-) diff --git a/AOS/app/src/main/java/boostcamp/and07/mindsync/ui/mindmap/MindMapViewModel.kt b/AOS/app/src/main/java/boostcamp/and07/mindsync/ui/mindmap/MindMapViewModel.kt index 7ec4c61b..996b6103 100644 --- a/AOS/app/src/main/java/boostcamp/and07/mindsync/ui/mindmap/MindMapViewModel.kt +++ b/AOS/app/src/main/java/boostcamp/and07/mindsync/ui/mindmap/MindMapViewModel.kt @@ -30,131 +30,149 @@ import javax.inject.Inject @HiltViewModel class MindMapViewModel - @Inject - constructor() : ViewModel() { - private var boardId: String = "" - val crdtTree = CrdtTree(id = IdGenerator.makeRandomNodeId(), tree = Tree()) - private var _selectedNode = MutableStateFlow(null) - val selectedNode: StateFlow = _selectedNode - private val _operation = MutableStateFlow(null) - val operation: StateFlow = _operation - private val mindMapSocketManager = MindMapSocketManager() - private val _socketState = MutableStateFlow(SocketState.DISCONNECT) - val socketState: StateFlow = _socketState - private val _socketEvent = MutableStateFlow(null) - val socketEvent: StateFlow = _socketEvent - - init { - setSocketState() - setSocketEvent() - } +@Inject +constructor() : ViewModel() { + private var boardId: String = "" + val crdtTree = CrdtTree(id = IdGenerator.makeRandomNodeId(), tree = Tree()) + private var _selectedNode = MutableStateFlow(null) + val selectedNode: StateFlow = _selectedNode + private val _operation = MutableStateFlow(null) + val operation: StateFlow = _operation + private val mindMapSocketManager = MindMapSocketManager() + private val _socketState = MutableStateFlow(SocketState.DISCONNECT) + val socketState: StateFlow = _socketState + private val _socketEvent = MutableStateFlow(null) + val socketEvent: StateFlow = _socketEvent + private val _operationType = MutableStateFlow("") + val operationType: StateFlow = _operationType + + init { + setSocketState() + setSocketEvent() + } - fun setBoard( - boardId: String, - boardName: String, - ) { - if (this.boardId != boardId) { - this.boardId = boardId - joinBoard(boardId, boardName) - updateNode(crdtTree.tree.getRootNode().copy(description = boardName)) - } + fun setBoard( + boardId: String, + boardName: String, + ) { + if (this.boardId != boardId) { + this.boardId = boardId + joinBoard(boardId, boardName) + updateNode(crdtTree.tree.getRootNode().copy(description = boardName)) } + } - private fun setSocketState() { - viewModelScope.launch { - mindMapSocketManager.listenState().collectLatest { state -> - _socketState.value = state - } + private fun setSocketState() { + viewModelScope.launch { + mindMapSocketManager.listenState().collectLatest { state -> + _socketState.value = state } } + } + + private fun setSocketEvent() { + viewModelScope.launch { + mindMapSocketManager.listenEvent().collectLatest { event -> + _socketEvent.value = event + when (event.eventType) { + SocketEventType.OPERATION_FROM_SERVER -> { + when (val operation = event.operation) { + is SerializedOperation -> { + applyOperation(operation) + } - private fun setSocketEvent() { - viewModelScope.launch { - mindMapSocketManager.listenEvent().collectLatest { event -> - _socketEvent.value = event - when (event.eventType) { - SocketEventType.OPERATION_FROM_SERVER -> { - when (val operation = event.operation) { - is SerializedOperation -> { - applyOperation(operation) - } - - is SerializedCrdtTree -> { - applyOperation(operation) - } + is SerializedCrdtTree -> { + applyOperation(operation) } } } } } } + } - fun joinBoard( - boardId: String, - boardName: String, - ) { - mindMapSocketManager.joinBoard(boardId, boardName) - } + fun joinBoard( + boardId: String, + boardName: String, + ) { + mindMapSocketManager.joinBoard(boardId, boardName) + } - fun addNode( - parent: Node, - addNode: RectangleNode, - ) { - val addOperation = - crdtTree.generateOperationAdd(addNode.id, parent.id, addNode.description) - crdtTree.applyOperation(addOperation) - _operation.value = addOperation - requestUpdateMindMap(operation = addOperation) - } + fun addNode( + parent: Node, + addNode: RectangleNode, + ) { + val addOperation = + crdtTree.generateOperationAdd(addNode.id, parent.id, addNode.description) + crdtTree.applyOperation(addOperation) + _operation.value = addOperation + requestUpdateMindMap(operation = addOperation) + } - fun removeNode(target: Node) { - _selectedNode.value = null - val removeOperation = crdtTree.generateOperationDelete(target.id) - crdtTree.applyOperation(removeOperation) - _operation.value = removeOperation - requestUpdateMindMap(operation = removeOperation) - } + fun removeNode(target: Node) { + _selectedNode.value = null + val removeOperation = crdtTree.generateOperationDelete(target.id) + crdtTree.applyOperation(removeOperation) + _operation.value = removeOperation + requestUpdateMindMap(operation = removeOperation) + } - fun moveNode( - tree: Tree, - target: Node, - parent: Node, - ) { - this.crdtTree.tree = tree - val moveOperation = crdtTree.generateOperationMove(target.id, parent.id) - crdtTree.applyOperation(moveOperation) - _operation.value = moveOperation - requestUpdateMindMap(operation = moveOperation) - } + fun moveNode( + tree: Tree, + target: Node, + parent: Node, + ) { + this.crdtTree.tree = tree + val moveOperation = crdtTree.generateOperationMove(target.id, parent.id) + crdtTree.applyOperation(moveOperation) + _operation.value = moveOperation + requestUpdateMindMap(operation = moveOperation) + } - fun setSelectedNode(selectNode: Node?) { - _selectedNode.value = selectNode - } + fun setSelectedNode(selectNode: Node?) { + _selectedNode.value = selectNode + } - fun requestUpdateMindMap(operation: Operation) { - val serializedOperation = - when (operation) { - is OperationAdd -> crdtTree.serializeOperationAdd(operation) + fun requestUpdateMindMap(operation: Operation) { + val serializedOperation = + when (operation) { + is OperationAdd -> crdtTree.serializeOperationAdd(operation) - is OperationDelete -> crdtTree.serializeOperationDelete(operation) + is OperationDelete -> crdtTree.serializeOperationDelete(operation) - is OperationMove -> crdtTree.serializeOperationMove(operation) + is OperationMove -> crdtTree.serializeOperationMove(operation) - is OperationUpdate -> crdtTree.serializeOperationUpdate(operation) + is OperationUpdate -> crdtTree.serializeOperationUpdate(operation) + } + mindMapSocketManager.updateMindMap( + serializedOperation = serializedOperation, + boardId = boardId, + ) + } + + fun applyOperation(operation: SerializedOperation) { + val operation = + when (operation.operationType) { + OperationType.ADD.command -> crdtTree.deserializeOperationAdd(operation) + OperationType.DELETE.command -> crdtTree.deserializeOperationDelete(operation) + OperationType.UPDATE.command -> crdtTree.deserializeOperationUpdate(operation) + OperationType.MOVE.command -> crdtTree.deserializeOperationMove(operation) + else -> { + throw IllegalArgumentException(ExceptionMessage.ERROR_MESSAGE_NOT_DEFINED_OPERATION.message) } - mindMapSocketManager.updateMindMap( - serializedOperation = serializedOperation, - boardId = boardId, - ) - } + } + crdtTree.applyOperation(operation) + _operation.value = operation + } - fun applyOperation(operation: SerializedOperation) { + fun applyOperation(operation: SerializedCrdtTree) { + operation.operationLogs?.forEach { operationLog -> val operation = - when (operation.operationType) { - OperationType.ADD.command -> crdtTree.deserializeOperationAdd(operation) - OperationType.DELETE.command -> crdtTree.deserializeOperationDelete(operation) - OperationType.UPDATE.command -> crdtTree.deserializeOperationUpdate(operation) - OperationType.MOVE.command -> crdtTree.deserializeOperationMove(operation) + when (operationLog.operation.operationType) { + OperationType.ADD.command -> crdtTree.deserializeOperationAdd(operationLog.operation) + OperationType.DELETE.command -> crdtTree.deserializeOperationDelete(operationLog.operation) + OperationType.UPDATE.command -> crdtTree.deserializeOperationUpdate(operationLog.operation) + OperationType.MOVE.command -> crdtTree.deserializeOperationMove(operationLog.operation) else -> { throw IllegalArgumentException(ExceptionMessage.ERROR_MESSAGE_NOT_DEFINED_OPERATION.message) } @@ -162,44 +180,35 @@ class MindMapViewModel crdtTree.applyOperation(operation) _operation.value = operation } + } - fun applyOperation(operation: SerializedCrdtTree) { - operation.operationLogs?.forEach { operationLog -> - val operation = - when (operationLog.operation.operationType) { - OperationType.ADD.command -> crdtTree.deserializeOperationAdd(operationLog.operation) - OperationType.DELETE.command -> crdtTree.deserializeOperationDelete(operationLog.operation) - OperationType.UPDATE.command -> crdtTree.deserializeOperationUpdate(operationLog.operation) - OperationType.MOVE.command -> crdtTree.deserializeOperationMove(operationLog.operation) - else -> { - throw IllegalArgumentException(ExceptionMessage.ERROR_MESSAGE_NOT_DEFINED_OPERATION.message) - } - } - crdtTree.applyOperation(operation) - _operation.value = operation - } - } - - fun updateNode(updateNode: Node) { - val updateOperation = - crdtTree.generateOperationUpdate(updateNode.id, updateNode.description) - crdtTree.applyOperation(updateOperation) - _operation.value = updateOperation - requestUpdateMindMap(updateOperation) - } + fun updateNode(updateNode: Node) { + val updateOperation = + crdtTree.generateOperationUpdate(updateNode.id, updateNode.description) + crdtTree.applyOperation(updateOperation) + _operation.value = updateOperation + requestUpdateMindMap(updateOperation) + } - fun update(newTree: Tree) { - crdtTree.tree = newTree - } + fun update(newTree: Tree) { + crdtTree.tree = newTree + } - fun changeRootXY( - windowWidth: Dp, - windowHeight: Dp, - ) { - crdtTree.tree.setRootNode( - crdtTree.tree.getRootNode().copy( - path = crdtTree.tree.getRootNode().path.copy(centerX = windowWidth, centerY = windowHeight), + fun changeRootXY( + windowWidth: Dp, + windowHeight: Dp, + ) { + crdtTree.tree.setRootNode( + crdtTree.tree.getRootNode().copy( + path = crdtTree.tree.getRootNode().path.copy( + centerX = windowWidth, + centerY = windowHeight, ), - ) - } + ), + ) + } + + fun updateOperationType(operationType: String) { + _operationType.value = operationType } +} From d16da32a230589a3019fb12db507d9ec6b06d1c2 Mon Sep 17 00:00:00 2001 From: dltkd1395 Date: Wed, 13 Dec 2023 16:52:15 +0900 Subject: [PATCH 3/5] =?UTF-8?q?design(#293):=20operationType=EC=97=90=20?= =?UTF-8?q?=EB=94=B0=EB=9D=BC=20EditText=EC=9D=98=20=ED=85=8D=EC=8A=A4?= =?UTF-8?q?=ED=8A=B8=20=EC=84=A4=EC=A0=95=20=EB=B3=80=EA=B2=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../res/layout/dialog_edit_description.xml | 82 +++++++++++-------- 1 file changed, 46 insertions(+), 36 deletions(-) diff --git a/AOS/app/src/main/res/layout/dialog_edit_description.xml b/AOS/app/src/main/res/layout/dialog_edit_description.xml index 844cffe6..6682a4f1 100644 --- a/AOS/app/src/main/res/layout/dialog_edit_description.xml +++ b/AOS/app/src/main/res/layout/dialog_edit_description.xml @@ -1,41 +1,51 @@ - + + + + - + - - - \ No newline at end of file + + + + + + + \ No newline at end of file From 0d080f588106eee90d870d732897bbeb3d6301d8 Mon Sep 17 00:00:00 2001 From: dltkd1395 Date: Wed, 13 Dec 2023 16:53:24 +0900 Subject: [PATCH 4/5] =?UTF-8?q?feat(#293):=20binding=20=EC=84=A4=EC=A0=95?= =?UTF-8?q?=20=EB=B0=8F=20operationType=20=EC=97=85=EB=8D=B0=EC=9D=B4?= =?UTF-8?q?=ED=8A=B8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../mindsync/ui/dialog/EditDescriptionDialog.kt | 17 +++++++++++++---- 1 file changed, 13 insertions(+), 4 deletions(-) diff --git a/AOS/app/src/main/java/boostcamp/and07/mindsync/ui/dialog/EditDescriptionDialog.kt b/AOS/app/src/main/java/boostcamp/and07/mindsync/ui/dialog/EditDescriptionDialog.kt index 4eee8e1b..88410a9b 100644 --- a/AOS/app/src/main/java/boostcamp/and07/mindsync/ui/dialog/EditDescriptionDialog.kt +++ b/AOS/app/src/main/java/boostcamp/and07/mindsync/ui/dialog/EditDescriptionDialog.kt @@ -23,7 +23,6 @@ import boostcamp.and07.mindsync.ui.mindmap.MindMapViewModel class EditDescriptionDialog : DialogFragment() { private var _binding: DialogEditDescriptionBinding? = null private val binding get() = _binding!! - private lateinit var editDialogInterface: EditDialogInterface private val mindMapViewModel: MindMapViewModel by navGraphViewModels(R.id.nav_graph) private val args: EditDescriptionDialogArgs by navArgs() @@ -49,8 +48,19 @@ class EditDescriptionDialog : DialogFragment() { savedInstanceState: Bundle?, ) { super.onViewCreated(view, savedInstanceState) + setBinding() setupCancelBtn() setupSubmitBtn() + updateOperationType(args.operation.command) + } + + override fun onStart() { + super.onStart() + resizeDialog() + } + + private fun setBinding() { + binding.vm = mindMapViewModel } private fun setupSubmitBtn() { @@ -83,9 +93,8 @@ class EditDescriptionDialog : DialogFragment() { } } - override fun onStart() { - super.onStart() - resizeDialog() + private fun updateOperationType(operationType: String) { + mindMapViewModel.updateOperationType(operationType) } private fun resizeDialog() { From e1f3f3295fef04e22e85b2b1f231c1ad2e6b35d1 Mon Sep 17 00:00:00 2001 From: dltkd1395 Date: Wed, 13 Dec 2023 17:01:18 +0900 Subject: [PATCH 5/5] =?UTF-8?q?style:=20ktlint=20=EC=A0=81=EC=9A=A9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../mindsync/ui/mindmap/MindMapViewModel.kt | 291 +++++++++--------- 1 file changed, 146 insertions(+), 145 deletions(-) diff --git a/AOS/app/src/main/java/boostcamp/and07/mindsync/ui/mindmap/MindMapViewModel.kt b/AOS/app/src/main/java/boostcamp/and07/mindsync/ui/mindmap/MindMapViewModel.kt index 996b6103..d7927b7e 100644 --- a/AOS/app/src/main/java/boostcamp/and07/mindsync/ui/mindmap/MindMapViewModel.kt +++ b/AOS/app/src/main/java/boostcamp/and07/mindsync/ui/mindmap/MindMapViewModel.kt @@ -30,149 +30,133 @@ import javax.inject.Inject @HiltViewModel class MindMapViewModel -@Inject -constructor() : ViewModel() { - private var boardId: String = "" - val crdtTree = CrdtTree(id = IdGenerator.makeRandomNodeId(), tree = Tree()) - private var _selectedNode = MutableStateFlow(null) - val selectedNode: StateFlow = _selectedNode - private val _operation = MutableStateFlow(null) - val operation: StateFlow = _operation - private val mindMapSocketManager = MindMapSocketManager() - private val _socketState = MutableStateFlow(SocketState.DISCONNECT) - val socketState: StateFlow = _socketState - private val _socketEvent = MutableStateFlow(null) - val socketEvent: StateFlow = _socketEvent - private val _operationType = MutableStateFlow("") - val operationType: StateFlow = _operationType - - init { - setSocketState() - setSocketEvent() - } - - fun setBoard( - boardId: String, - boardName: String, - ) { - if (this.boardId != boardId) { - this.boardId = boardId - joinBoard(boardId, boardName) - updateNode(crdtTree.tree.getRootNode().copy(description = boardName)) + @Inject + constructor() : ViewModel() { + private var boardId: String = "" + val crdtTree = CrdtTree(id = IdGenerator.makeRandomNodeId(), tree = Tree()) + private var _selectedNode = MutableStateFlow(null) + val selectedNode: StateFlow = _selectedNode + private val _operation = MutableStateFlow(null) + val operation: StateFlow = _operation + private val mindMapSocketManager = MindMapSocketManager() + private val _socketState = MutableStateFlow(SocketState.DISCONNECT) + val socketState: StateFlow = _socketState + private val _socketEvent = MutableStateFlow(null) + val socketEvent: StateFlow = _socketEvent + private val _operationType = MutableStateFlow("") + val operationType: StateFlow = _operationType + + init { + setSocketState() + setSocketEvent() } - } - private fun setSocketState() { - viewModelScope.launch { - mindMapSocketManager.listenState().collectLatest { state -> - _socketState.value = state + fun setBoard( + boardId: String, + boardName: String, + ) { + if (this.boardId != boardId) { + this.boardId = boardId + joinBoard(boardId, boardName) + updateNode(crdtTree.tree.getRootNode().copy(description = boardName)) } } - } - private fun setSocketEvent() { - viewModelScope.launch { - mindMapSocketManager.listenEvent().collectLatest { event -> - _socketEvent.value = event - when (event.eventType) { - SocketEventType.OPERATION_FROM_SERVER -> { - when (val operation = event.operation) { - is SerializedOperation -> { - applyOperation(operation) - } + private fun setSocketState() { + viewModelScope.launch { + mindMapSocketManager.listenState().collectLatest { state -> + _socketState.value = state + } + } + } - is SerializedCrdtTree -> { - applyOperation(operation) + private fun setSocketEvent() { + viewModelScope.launch { + mindMapSocketManager.listenEvent().collectLatest { event -> + _socketEvent.value = event + when (event.eventType) { + SocketEventType.OPERATION_FROM_SERVER -> { + when (val operation = event.operation) { + is SerializedOperation -> { + applyOperation(operation) + } + + is SerializedCrdtTree -> { + applyOperation(operation) + } } } } } } } - } - fun joinBoard( - boardId: String, - boardName: String, - ) { - mindMapSocketManager.joinBoard(boardId, boardName) - } - - fun addNode( - parent: Node, - addNode: RectangleNode, - ) { - val addOperation = - crdtTree.generateOperationAdd(addNode.id, parent.id, addNode.description) - crdtTree.applyOperation(addOperation) - _operation.value = addOperation - requestUpdateMindMap(operation = addOperation) - } + fun joinBoard( + boardId: String, + boardName: String, + ) { + mindMapSocketManager.joinBoard(boardId, boardName) + } - fun removeNode(target: Node) { - _selectedNode.value = null - val removeOperation = crdtTree.generateOperationDelete(target.id) - crdtTree.applyOperation(removeOperation) - _operation.value = removeOperation - requestUpdateMindMap(operation = removeOperation) - } + fun addNode( + parent: Node, + addNode: RectangleNode, + ) { + val addOperation = + crdtTree.generateOperationAdd(addNode.id, parent.id, addNode.description) + crdtTree.applyOperation(addOperation) + _operation.value = addOperation + requestUpdateMindMap(operation = addOperation) + } - fun moveNode( - tree: Tree, - target: Node, - parent: Node, - ) { - this.crdtTree.tree = tree - val moveOperation = crdtTree.generateOperationMove(target.id, parent.id) - crdtTree.applyOperation(moveOperation) - _operation.value = moveOperation - requestUpdateMindMap(operation = moveOperation) - } + fun removeNode(target: Node) { + _selectedNode.value = null + val removeOperation = crdtTree.generateOperationDelete(target.id) + crdtTree.applyOperation(removeOperation) + _operation.value = removeOperation + requestUpdateMindMap(operation = removeOperation) + } - fun setSelectedNode(selectNode: Node?) { - _selectedNode.value = selectNode - } + fun moveNode( + tree: Tree, + target: Node, + parent: Node, + ) { + this.crdtTree.tree = tree + val moveOperation = crdtTree.generateOperationMove(target.id, parent.id) + crdtTree.applyOperation(moveOperation) + _operation.value = moveOperation + requestUpdateMindMap(operation = moveOperation) + } - fun requestUpdateMindMap(operation: Operation) { - val serializedOperation = - when (operation) { - is OperationAdd -> crdtTree.serializeOperationAdd(operation) + fun setSelectedNode(selectNode: Node?) { + _selectedNode.value = selectNode + } - is OperationDelete -> crdtTree.serializeOperationDelete(operation) + fun requestUpdateMindMap(operation: Operation) { + val serializedOperation = + when (operation) { + is OperationAdd -> crdtTree.serializeOperationAdd(operation) - is OperationMove -> crdtTree.serializeOperationMove(operation) + is OperationDelete -> crdtTree.serializeOperationDelete(operation) - is OperationUpdate -> crdtTree.serializeOperationUpdate(operation) - } - mindMapSocketManager.updateMindMap( - serializedOperation = serializedOperation, - boardId = boardId, - ) - } + is OperationMove -> crdtTree.serializeOperationMove(operation) - fun applyOperation(operation: SerializedOperation) { - val operation = - when (operation.operationType) { - OperationType.ADD.command -> crdtTree.deserializeOperationAdd(operation) - OperationType.DELETE.command -> crdtTree.deserializeOperationDelete(operation) - OperationType.UPDATE.command -> crdtTree.deserializeOperationUpdate(operation) - OperationType.MOVE.command -> crdtTree.deserializeOperationMove(operation) - else -> { - throw IllegalArgumentException(ExceptionMessage.ERROR_MESSAGE_NOT_DEFINED_OPERATION.message) + is OperationUpdate -> crdtTree.serializeOperationUpdate(operation) } - } - crdtTree.applyOperation(operation) - _operation.value = operation - } + mindMapSocketManager.updateMindMap( + serializedOperation = serializedOperation, + boardId = boardId, + ) + } - fun applyOperation(operation: SerializedCrdtTree) { - operation.operationLogs?.forEach { operationLog -> + fun applyOperation(operation: SerializedOperation) { val operation = - when (operationLog.operation.operationType) { - OperationType.ADD.command -> crdtTree.deserializeOperationAdd(operationLog.operation) - OperationType.DELETE.command -> crdtTree.deserializeOperationDelete(operationLog.operation) - OperationType.UPDATE.command -> crdtTree.deserializeOperationUpdate(operationLog.operation) - OperationType.MOVE.command -> crdtTree.deserializeOperationMove(operationLog.operation) + when (operation.operationType) { + OperationType.ADD.command -> crdtTree.deserializeOperationAdd(operation) + OperationType.DELETE.command -> crdtTree.deserializeOperationDelete(operation) + OperationType.UPDATE.command -> crdtTree.deserializeOperationUpdate(operation) + OperationType.MOVE.command -> crdtTree.deserializeOperationMove(operation) else -> { throw IllegalArgumentException(ExceptionMessage.ERROR_MESSAGE_NOT_DEFINED_OPERATION.message) } @@ -180,35 +164,52 @@ constructor() : ViewModel() { crdtTree.applyOperation(operation) _operation.value = operation } - } - fun updateNode(updateNode: Node) { - val updateOperation = - crdtTree.generateOperationUpdate(updateNode.id, updateNode.description) - crdtTree.applyOperation(updateOperation) - _operation.value = updateOperation - requestUpdateMindMap(updateOperation) - } + fun applyOperation(operation: SerializedCrdtTree) { + operation.operationLogs?.forEach { operationLog -> + val operation = + when (operationLog.operation.operationType) { + OperationType.ADD.command -> crdtTree.deserializeOperationAdd(operationLog.operation) + OperationType.DELETE.command -> crdtTree.deserializeOperationDelete(operationLog.operation) + OperationType.UPDATE.command -> crdtTree.deserializeOperationUpdate(operationLog.operation) + OperationType.MOVE.command -> crdtTree.deserializeOperationMove(operationLog.operation) + else -> { + throw IllegalArgumentException(ExceptionMessage.ERROR_MESSAGE_NOT_DEFINED_OPERATION.message) + } + } + crdtTree.applyOperation(operation) + _operation.value = operation + } + } - fun update(newTree: Tree) { - crdtTree.tree = newTree - } + fun updateNode(updateNode: Node) { + val updateOperation = + crdtTree.generateOperationUpdate(updateNode.id, updateNode.description) + crdtTree.applyOperation(updateOperation) + _operation.value = updateOperation + requestUpdateMindMap(updateOperation) + } - fun changeRootXY( - windowWidth: Dp, - windowHeight: Dp, - ) { - crdtTree.tree.setRootNode( - crdtTree.tree.getRootNode().copy( - path = crdtTree.tree.getRootNode().path.copy( - centerX = windowWidth, - centerY = windowHeight, + fun update(newTree: Tree) { + crdtTree.tree = newTree + } + + fun changeRootXY( + windowWidth: Dp, + windowHeight: Dp, + ) { + crdtTree.tree.setRootNode( + crdtTree.tree.getRootNode().copy( + path = + crdtTree.tree.getRootNode().path.copy( + centerX = windowWidth, + centerY = windowHeight, + ), ), - ), - ) - } + ) + } - fun updateOperationType(operationType: String) { - _operationType.value = operationType + fun updateOperationType(operationType: String) { + _operationType.value = operationType + } } -}