Skip to content

Commit

Permalink
Merge pull request #311 from boostcampwm2023/AOS-develop
Browse files Browse the repository at this point in the history
์•ˆ๋“œ๋กœ์ด๋“œ 1.0.0 ๋ฒ„๊ทธ ํ•ด๊ฒฐ
  • Loading branch information
yang1318 authored Dec 14, 2023
2 parents 292c904 + 129f911 commit 446c5b1
Show file tree
Hide file tree
Showing 7 changed files with 90 additions and 103 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
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)
Expand All @@ -49,9 +52,9 @@ class EditDescriptionDialog : DialogFragment() {
) {
super.onViewCreated(view, savedInstanceState)
setBinding()
setViewModel()
setupCancelBtn()
setupSubmitBtn()
updateOperationType(args.operation.command)
}

override fun onStart() {
Expand All @@ -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()
}
}
Expand All @@ -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

Expand Down
Original file line number Diff line number Diff line change
@@ -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<String> = _description
var submitListener: ((String) -> (Unit))? = null

fun setDescription(text: String) {
_description.value = text
}

fun onDescriptionChanged(inputDescription: CharSequence) {
_description.value = inputDescription.toString()
}
}

This file was deleted.

This file was deleted.

Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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()
Expand All @@ -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)
}
}
}
}
Expand Down Expand Up @@ -104,11 +92,30 @@ class MindMapFragment :
operationType: OperationType,
selectedNode: Node,
) {
findNavController().navigate(
MindMapFragmentDirections.actionMindMapFragmentToEditDescriptionDialog(
operationType,
selectedNode,
),
val description = if (operationType == OperationType.ADD) "" else selectedNode.description
val editDescriptionDialog = EditDescriptionDialog()
editDescriptionDialog.setDescription(description)
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",
)
}

Expand Down Expand Up @@ -156,11 +163,4 @@ class MindMapFragment :
) {
mindMapViewModel.moveNode(tree, target, parent)
}

override fun onDestroyView() {
super.onDestroyView()
if (isBack) {
mindMapViewModel.clearTree()
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,6 @@ class MindMapViewModel
val socketState: StateFlow<SocketState> = _socketState
private val _socketEvent = MutableStateFlow<SocketEvent?>(null)
val socketEvent: StateFlow<SocketEvent?> = _socketEvent
private val _operationType = MutableStateFlow("")
val operationType: StateFlow<String> = _operationType

init {
setSocketState()
Expand Down Expand Up @@ -218,18 +216,4 @@ class MindMapViewModel
),
)
}

fun updateOperationType(operationType: String) {
_operationType.value = operationType
}

fun clearTree() {
boardId = ""
crdtTree =
CrdtTree(
id = "",
tree = Tree(),
)
_selectedNode.value = null
}
}
19 changes: 11 additions & 8 deletions AOS/app/src/main/res/layout/dialog_edit_description.xml
Original file line number Diff line number Diff line change
Expand Up @@ -3,47 +3,50 @@
xmlns:app="http://schemas.android.com/apk/res-auto">

<data>

<variable
name="vm"
type="boostcamp.and07.mindsync.ui.mindmap.MindMapViewModel" />
type="boostcamp.and07.mindsync.ui.dialog.EditDescriptionViewModel" />
</data>

<androidx.constraintlayout.widget.ConstraintLayout
android:layout_width="300dp"
android:layout_height="300dp"
android:background="@drawable/bg_round_dialog"
android:padding="10dp"
android:layout_height="300dp">

android:padding="10dp">

<EditText
android:id="@+id/et_node_description"
android:layout_width="0dp"
android:layout_height="0dp"
android:fontFamily="@font/pretendard_regular"
android:hint="@string/mindmap_input_text"
android:text="@{vm.operationType.equals(@string/mindmap_add) ? @string/mindmap_text_empty : vm.selectedNode.description}"
android:onTextChanged="@{(p0, p1, p2, p3) -> vm.onDescriptionChanged(p0)}"
android:text="@{vm.description}"
android:textAlignment="center"
android:fontFamily="@font/pretendard_regular"
app:layout_constraintBottom_toTopOf="@id/btn_submit"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />

<com.google.android.material.button.MaterialButton
android:id="@+id/btn_cancel"
style="@style/Typography.Body02.Medium"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/cancel_message"
android:textColor="@color/white"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toStartOf="@id/btn_submit"
android:fontFamily="@font/pretendard_medium"
app:layout_constraintStart_toStartOf="parent" />

<com.google.android.material.button.MaterialButton
android:id="@+id/btn_submit"
style="@style/Typography.Body02.Medium"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/mindmap_write"
android:fontFamily="@font/pretendard_medium"
android:textColor="@color/white"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toEndOf="@id/btn_cancel" />
Expand Down

0 comments on commit 446c5b1

Please sign in to comment.