From 51fef6101abb8452b0909f84bd55b35a70c06eac Mon Sep 17 00:00:00 2001 From: "seona.Yang" <75965560+yang1318@users.noreply.github.com> Date: Fri, 15 Dec 2023 01:00:01 +0900 Subject: [PATCH 1/9] =?UTF-8?q?refactor:=20=EC=82=AC=EC=9A=A9=ED=95=98?= =?UTF-8?q?=EC=A7=80=20=EC=95=8A=EB=8A=94=20interface=20=EC=82=AD=EC=A0=9C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../and07/mindsync/ui/dialog/EditDialogInterface.kt | 5 ----- .../and07/mindsync/ui/dialog/EditNickNameInterface.kt | 5 ----- 2 files changed, 10 deletions(-) delete mode 100644 AOS/app/src/main/java/boostcamp/and07/mindsync/ui/dialog/EditDialogInterface.kt delete mode 100644 AOS/app/src/main/java/boostcamp/and07/mindsync/ui/dialog/EditNickNameInterface.kt diff --git a/AOS/app/src/main/java/boostcamp/and07/mindsync/ui/dialog/EditDialogInterface.kt b/AOS/app/src/main/java/boostcamp/and07/mindsync/ui/dialog/EditDialogInterface.kt deleted file mode 100644 index b576e749..00000000 --- a/AOS/app/src/main/java/boostcamp/and07/mindsync/ui/dialog/EditDialogInterface.kt +++ /dev/null @@ -1,5 +0,0 @@ -package boostcamp.and07.mindsync.ui.dialog - -interface EditDialogInterface { - fun onSubmitClick(description: String) -} diff --git a/AOS/app/src/main/java/boostcamp/and07/mindsync/ui/dialog/EditNickNameInterface.kt b/AOS/app/src/main/java/boostcamp/and07/mindsync/ui/dialog/EditNickNameInterface.kt deleted file mode 100644 index 51373ce4..00000000 --- a/AOS/app/src/main/java/boostcamp/and07/mindsync/ui/dialog/EditNickNameInterface.kt +++ /dev/null @@ -1,5 +0,0 @@ -package boostcamp.and07.mindsync.ui.dialog - -interface EditNickNameInterface { - fun onModifyClick(nickname: String) -} From 5caf23046723e9496e407b954425b6378495c644 Mon Sep 17 00:00:00 2001 From: "seona.Yang" <75965560+yang1318@users.noreply.github.com> Date: Fri, 15 Dec 2023 01:00:54 +0900 Subject: [PATCH 2/9] =?UTF-8?q?feat(#309):=20EditDescriptionViewModel=20?= =?UTF-8?q?=EC=83=9D=EC=84=B1?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../ui/dialog/EditDescriptionViewModel.kt | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) create mode 100644 AOS/app/src/main/java/boostcamp/and07/mindsync/ui/dialog/EditDescriptionViewModel.kt diff --git a/AOS/app/src/main/java/boostcamp/and07/mindsync/ui/dialog/EditDescriptionViewModel.kt b/AOS/app/src/main/java/boostcamp/and07/mindsync/ui/dialog/EditDescriptionViewModel.kt new file mode 100644 index 00000000..3010bffa --- /dev/null +++ b/AOS/app/src/main/java/boostcamp/and07/mindsync/ui/dialog/EditDescriptionViewModel.kt @@ -0,0 +1,19 @@ +package boostcamp.and07.mindsync.ui.dialog + +import androidx.lifecycle.ViewModel +import kotlinx.coroutines.flow.MutableStateFlow +import kotlinx.coroutines.flow.StateFlow + +class EditDescriptionViewModel : ViewModel() { + private val _description = MutableStateFlow("") + val description: StateFlow = _description + var submitListener: ((String) -> (Unit))? = null + + fun setDescription(text: String) { + _description.value = text + } + + fun onDescriptionChanged(inputDescription: CharSequence) { + _description.value = inputDescription.toString() + } +} From 32284f51135ccd4882a48c32246d674f067bab15 Mon Sep 17 00:00:00 2001 From: "seona.Yang" <75965560+yang1318@users.noreply.github.com> Date: Fri, 15 Dec 2023 01:01:09 +0900 Subject: [PATCH 3/9] =?UTF-8?q?refactor(#309):=20FragmentDialog=EC=97=90?= =?UTF-8?q?=20EditDescriptionViewModel=20=EC=A0=81=EC=9A=A9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../ui/dialog/EditDescriptionDialog.kt | 59 ++++++++----------- 1 file changed, 25 insertions(+), 34 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 db9f7ba8..ec6006a0 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 @@ -10,21 +10,24 @@ import android.view.View import android.view.ViewGroup import android.view.WindowManager import androidx.fragment.app.DialogFragment -import androidx.navigation.fragment.navArgs -import androidx.navigation.navGraphViewModels +import androidx.fragment.app.viewModels import boostcamp.and07.mindsync.R -import boostcamp.and07.mindsync.data.crdt.OperationType -import boostcamp.and07.mindsync.data.model.CircleNode -import boostcamp.and07.mindsync.data.model.RectangleNode -import boostcamp.and07.mindsync.data.util.NodeGenerator import boostcamp.and07.mindsync.databinding.DialogEditDescriptionBinding -import boostcamp.and07.mindsync.ui.mindmap.MindMapViewModel -class EditDescriptionDialog : DialogFragment() { +class EditDescriptionDialog() : DialogFragment() { private var _binding: DialogEditDescriptionBinding? = null private val binding get() = _binding!! - private val mindMapViewModel: MindMapViewModel by navGraphViewModels(R.id.nav_graph) - private val args: EditDescriptionDialogArgs by navArgs() + private val editDescriptionViewModel: EditDescriptionViewModel by viewModels() + private var submitListener: ((String) -> (Unit))? = null + private var description: String = "" + + fun setDescription(description: String) { + this.description = description + } + + fun setSubmitListener(submitListener: ((String) -> (Unit))) { + this.submitListener = submitListener + } override fun onCreateDialog(savedInstanceState: Bundle?): Dialog { val dialog = super.onCreateDialog(savedInstanceState) @@ -49,9 +52,9 @@ class EditDescriptionDialog : DialogFragment() { ) { super.onViewCreated(view, savedInstanceState) setBinding() + setViewModel() setupCancelBtn() setupSubmitBtn() - updateOperationType(args.operation.command) } override fun onStart() { @@ -60,29 +63,21 @@ class EditDescriptionDialog : DialogFragment() { } private fun setBinding() { - binding.vm = mindMapViewModel + binding.vm = editDescriptionViewModel + } + + private fun setViewModel() { + submitListener?.let { + editDescriptionViewModel.submitListener = this.submitListener + } + if (description.isNotEmpty()) { + editDescriptionViewModel.setDescription(description) + } } private fun setupSubmitBtn() { binding.btnSubmit.setOnClickListener { - val node = args.node - val description = binding.etNodeDescription.text.toString() - when (args.operation) { - OperationType.ADD -> { - mindMapViewModel.addNode(node, NodeGenerator.makeNode(description, node.id)) - } - - OperationType.UPDATE -> { - val newNode = - when (node) { - is CircleNode -> node.copy(description = description) - is RectangleNode -> node.copy(description = description) - } - mindMapViewModel.updateNode(newNode) - } - - else -> {} - } + editDescriptionViewModel.submitListener?.invoke(editDescriptionViewModel.description.value) dismiss() } } @@ -93,10 +88,6 @@ class EditDescriptionDialog : DialogFragment() { } } - private fun updateOperationType(operationType: String) { - mindMapViewModel.updateOperationType(operationType) - } - private fun resizeDialog() { val params: ViewGroup.LayoutParams? = dialog?.window?.attributes From fd2db63bd7cb9bdf38d2038c1d86e6467e7174e9 Mon Sep 17 00:00:00 2001 From: "seona.Yang" <75965560+yang1318@users.noreply.github.com> Date: Fri, 15 Dec 2023 01:01:46 +0900 Subject: [PATCH 4/9] =?UTF-8?q?refactor(#309):=20EditDescriptionViewModel?= =?UTF-8?q?=EC=9D=84=20=EC=82=AC=EC=9A=A9=ED=95=A8=EC=9C=BC=EB=A1=9C?= =?UTF-8?q?=EC=8D=A8=20=EB=B6=88=ED=95=84=EC=9A=94=ED=95=B4=EC=A7=84=20vie?= =?UTF-8?q?wModel=20=ED=95=A8=EC=88=98=20=EC=A0=9C=EA=B1=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../mindsync/ui/mindmap/MindMapViewModel.kt | 16 ---------------- 1 file changed, 16 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 aa20b35f..d2320c24 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 @@ -43,8 +43,6 @@ class MindMapViewModel val socketState: StateFlow = _socketState private val _socketEvent = MutableStateFlow(null) val socketEvent: StateFlow = _socketEvent - private val _operationType = MutableStateFlow("") - val operationType: StateFlow = _operationType init { setSocketState() @@ -218,18 +216,4 @@ class MindMapViewModel ), ) } - - fun updateOperationType(operationType: String) { - _operationType.value = operationType - } - - fun clearTree() { - boardId = "" - crdtTree = - CrdtTree( - id = "", - tree = Tree(), - ) - _selectedNode.value = null - } } From e5bd27094c8ab579c1552c3a8419804d0003f7df Mon Sep 17 00:00:00 2001 From: "seona.Yang" <75965560+yang1318@users.noreply.github.com> Date: Fri, 15 Dec 2023 01:02:50 +0900 Subject: [PATCH 5/9] =?UTF-8?q?feat(#309):=20dialog=5Fedit=5Fdescription.x?= =?UTF-8?q?ml=EC=97=90=20=EC=83=88=EB=A1=9C=EC=9A=B4=20viewModel=20?= =?UTF-8?q?=EC=A0=81=EC=9A=A9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- AOS/app/src/main/res/layout/dialog_edit_description.xml | 6 +++--- 1 file changed, 3 insertions(+), 3 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 6682a4f1..ce43c208 100644 --- a/AOS/app/src/main/res/layout/dialog_edit_description.xml +++ b/AOS/app/src/main/res/layout/dialog_edit_description.xml @@ -5,7 +5,7 @@ + type="boostcamp.and07.mindsync.ui.dialog.EditDescriptionViewModel" /> - Date: Fri, 15 Dec 2023 01:08:44 +0900 Subject: [PATCH 6/9] =?UTF-8?q?feat(#309):=20EditDescriptionDialog=20?= =?UTF-8?q?=EB=A5=BC=20MindMapFragment=EC=97=90=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/MindMapFragment.kt | 72 +++++++++---------- 1 file changed, 36 insertions(+), 36 deletions(-) diff --git a/AOS/app/src/main/java/boostcamp/and07/mindsync/ui/mindmap/MindMapFragment.kt b/AOS/app/src/main/java/boostcamp/and07/mindsync/ui/mindmap/MindMapFragment.kt index 9be4bc30..b8bd7490 100644 --- a/AOS/app/src/main/java/boostcamp/and07/mindsync/ui/mindmap/MindMapFragment.kt +++ b/AOS/app/src/main/java/boostcamp/and07/mindsync/ui/mindmap/MindMapFragment.kt @@ -1,19 +1,20 @@ package boostcamp.and07.mindsync.ui.mindmap -import android.content.Context -import androidx.activity.OnBackPressedCallback +import androidx.fragment.app.viewModels import androidx.lifecycle.Lifecycle import androidx.lifecycle.lifecycleScope import androidx.lifecycle.repeatOnLifecycle -import androidx.navigation.fragment.findNavController import androidx.navigation.fragment.navArgs -import androidx.navigation.navGraphViewModels import boostcamp.and07.mindsync.R import boostcamp.and07.mindsync.data.crdt.OperationType +import boostcamp.and07.mindsync.data.model.CircleNode import boostcamp.and07.mindsync.data.model.Node +import boostcamp.and07.mindsync.data.model.RectangleNode import boostcamp.and07.mindsync.data.model.Tree +import boostcamp.and07.mindsync.data.util.NodeGenerator import boostcamp.and07.mindsync.databinding.FragmentMindMapBinding import boostcamp.and07.mindsync.ui.base.BaseFragment +import boostcamp.and07.mindsync.ui.dialog.EditDescriptionDialog import boostcamp.and07.mindsync.ui.util.Dp import boostcamp.and07.mindsync.ui.util.Px import boostcamp.and07.mindsync.ui.util.ThrottleDuration @@ -33,24 +34,9 @@ class MindMapFragment : NodeClickListener, TreeUpdateListener, NodeMoveListener { - private val mindMapViewModel: MindMapViewModel by navGraphViewModels(R.id.nav_graph) { - MindMapViewModelFactory() - } + private val mindMapViewModel: MindMapViewModel by viewModels() private lateinit var mindMapContainer: MindMapContainer private val args: MindMapFragmentArgs by navArgs() - private var isBack = false - - override fun onAttach(context: Context) { - super.onAttach(context) - val callback = - object : OnBackPressedCallback(true) { - override fun handleOnBackPressed() { - isBack = true - findNavController().popBackStack() - } - } - requireActivity().onBackPressedDispatcher.addCallback(this, callback) - } override fun initView() { setupRootNode() @@ -64,10 +50,12 @@ class MindMapFragment : private fun collectOperation() { viewLifecycleOwner.lifecycleScope.launch { repeatOnLifecycle(Lifecycle.State.STARTED) { - mindMapViewModel.operation.collectLatest { - mindMapContainer.update(mindMapViewModel.crdtTree.tree) - binding.zoomLayoutMindMapRoot.lineView.updateTree(mindMapContainer.tree) - binding.zoomLayoutMindMapRoot.nodeView.updateTree(mindMapContainer.tree) + mindMapViewModel.operation.collectLatest { operation -> + operation?.let { + mindMapContainer.update(mindMapViewModel.crdtTree.tree) + binding.zoomLayoutMindMapRoot.lineView.updateTree(mindMapContainer.tree) + binding.zoomLayoutMindMapRoot.nodeView.updateTree(mindMapContainer.tree) + } } } } @@ -104,11 +92,30 @@ class MindMapFragment : operationType: OperationType, selectedNode: Node, ) { - findNavController().navigate( - MindMapFragmentDirections.actionMindMapFragmentToEditDescriptionDialog( - operationType, - selectedNode, - ), + val text: String = if (operationType == OperationType.ADD) "" else selectedNode.description + val editDescriptionDialog = EditDescriptionDialog() + editDescriptionDialog.setDescription(text) + editDescriptionDialog.setSubmitListener { description -> + when (operationType) { + OperationType.ADD -> { + mindMapViewModel.addNode(selectedNode, NodeGenerator.makeNode(description, selectedNode.id)) + } + + OperationType.UPDATE -> { + val newNode = + when (selectedNode) { + is CircleNode -> selectedNode.copy(description = description) + is RectangleNode -> selectedNode.copy(description = description) + } + mindMapViewModel.updateNode(newNode) + } + + else -> {} + } + } + editDescriptionDialog.show( + requireActivity().supportFragmentManager, + "EditDescriptionDialog", ) } @@ -156,11 +163,4 @@ class MindMapFragment : ) { mindMapViewModel.moveNode(tree, target, parent) } - - override fun onDestroyView() { - super.onDestroyView() - if (isBack) { - mindMapViewModel.clearTree() - } - } } From 478ee25c3560de7ef470daf6a404ff7f5ae9b555 Mon Sep 17 00:00:00 2001 From: "seona.Yang" <75965560+yang1318@users.noreply.github.com> Date: Fri, 15 Dec 2023 01:29:45 +0900 Subject: [PATCH 7/9] =?UTF-8?q?refactor:=20fontFaily=20=EB=A5=BC=20Typogra?= =?UTF-8?q?phy=20style=EC=9D=84=20=EC=82=AC=EC=9A=A9=ED=95=98=EB=8F=84?= =?UTF-8?q?=EB=A1=9D=20=ED=95=A8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../src/main/res/layout/dialog_edit_description.xml | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 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 ce43c208..0180e079 100644 --- a/AOS/app/src/main/res/layout/dialog_edit_description.xml +++ b/AOS/app/src/main/res/layout/dialog_edit_description.xml @@ -3,6 +3,7 @@ xmlns:app="http://schemas.android.com/apk/res-auto"> + @@ -10,19 +11,19 @@ + android:padding="10dp"> From c8ea29cb53d0ee71d80b46c366ba76e65944f24f Mon Sep 17 00:00:00 2001 From: "seona.Yang" <75965560+yang1318@users.noreply.github.com> Date: Fri, 15 Dec 2023 01:30:04 +0900 Subject: [PATCH 8/9] =?UTF-8?q?refactor:=20=EB=B3=80=EC=88=98=EC=9D=B4?= =?UTF-8?q?=EB=A6=84=20text=EB=A5=BC=20description=20=EC=9C=BC=EB=A1=9C=20?= =?UTF-8?q?=EB=B3=80=EA=B2=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../boostcamp/and07/mindsync/ui/mindmap/MindMapFragment.kt | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/AOS/app/src/main/java/boostcamp/and07/mindsync/ui/mindmap/MindMapFragment.kt b/AOS/app/src/main/java/boostcamp/and07/mindsync/ui/mindmap/MindMapFragment.kt index b8bd7490..8022a300 100644 --- a/AOS/app/src/main/java/boostcamp/and07/mindsync/ui/mindmap/MindMapFragment.kt +++ b/AOS/app/src/main/java/boostcamp/and07/mindsync/ui/mindmap/MindMapFragment.kt @@ -92,9 +92,9 @@ class MindMapFragment : operationType: OperationType, selectedNode: Node, ) { - val text: String = if (operationType == OperationType.ADD) "" else selectedNode.description + val description = if (operationType == OperationType.ADD) "" else selectedNode.description val editDescriptionDialog = EditDescriptionDialog() - editDescriptionDialog.setDescription(text) + editDescriptionDialog.setDescription(description) editDescriptionDialog.setSubmitListener { description -> when (operationType) { OperationType.ADD -> { From a8dbcf5381c4490081b412bcf02cbe91cbfe85ca Mon Sep 17 00:00:00 2001 From: "seona.Yang" <75965560+yang1318@users.noreply.github.com> Date: Fri, 15 Dec 2023 01:30:57 +0900 Subject: [PATCH 9/9] =?UTF-8?q?style:=20=EB=B6=88=ED=95=84=EC=9A=94?= =?UTF-8?q?=ED=95=9C=20=EC=86=8C=EA=B4=84=ED=98=B8=20=EC=A0=9C=EA=B1=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../boostcamp/and07/mindsync/ui/dialog/EditDescriptionDialog.kt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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 ec6006a0..a3690b01 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 @@ -14,7 +14,7 @@ import androidx.fragment.app.viewModels import boostcamp.and07.mindsync.R import boostcamp.and07.mindsync.databinding.DialogEditDescriptionBinding -class EditDescriptionDialog() : DialogFragment() { +class EditDescriptionDialog : DialogFragment() { private var _binding: DialogEditDescriptionBinding? = null private val binding get() = _binding!! private val editDescriptionViewModel: EditDescriptionViewModel by viewModels()