Skip to content

Commit

Permalink
[feat] #23 feat : 음식입력 갯수 제한 설정
Browse files Browse the repository at this point in the history
  • Loading branch information
plashdof committed Oct 4, 2024
1 parent 32f07f5 commit 00457da
Showing 1 changed file with 8 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ class FoodRecordDetailFragment :
private val viewModel: FoodRecordDetailViewModel by viewModels()

private var editTextId = -1
private var count = 0

override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
super.onViewCreated(view, savedInstanceState)
Expand All @@ -40,7 +41,11 @@ class FoodRecordDetailFragment :
viewModel.event.collect {
when (it) {
is FoodRecordDetailEvent.NavigateBack -> findNavController().navigateUp()
is FoodRecordDetailEvent.AddEditFood -> addEditFood()
is FoodRecordDetailEvent.AddEditFood -> {
if (count == 3) showToastMessage("음식입력은 최대 3개입니다")
else addEditFood()
}

is FoodRecordDetailEvent.CompleteEditFood -> {
RecordFormData.sideDishes = it.list
findNavController().navigateUp()
Expand All @@ -59,6 +64,7 @@ class FoodRecordDetailFragment :
val newPadding = resources.getDimensionPixelSize(R.dimen.edit_detail_padding)
val oldPadding = resources.getDimensionPixelSize(R.dimen.edit_detail_focus_padding)

count++
editTextId++
viewModel.createFoodItem(editTextId)

Expand Down Expand Up @@ -88,6 +94,7 @@ class FoodRecordDetailFragment :
}

deleteBtn.setOnClickListener {
count--
binding.layoutEditFood.removeView(newEditFood)
viewModel.deleteFoodItem(editTextId)
}
Expand Down

0 comments on commit 00457da

Please sign in to comment.