Skip to content

Commit

Permalink
✨ Feat: 색상 선택 예외 처리
Browse files Browse the repository at this point in the history
- 토스트 메시지 표시

Related to: #346
  • Loading branch information
nahy-512 committed Feb 9, 2025
1 parent caa4530 commit 6a042ed
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -52,10 +52,16 @@ class CategoryDetailFragment

// 저장하기
binding.categoryDetailSaveTv.setOnClickListener {
if (!this@CategoryDetailFragment.viewModel.isValidInput()) {
if (!viewModel.isValidName()) {
Toast.makeText(requireContext(), "카테고리를 입력해주세요", Toast.LENGTH_SHORT).show()
return@setOnClickListener
}

if (!viewModel.isColorSelected()) {
Toast.makeText(requireContext(), "색상을 설정 후 저장해주세요.", Toast.LENGTH_SHORT).show()
return@setOnClickListener
}

// 수정 모드 -> 카테고리 편집
if (viewModel.isEditMode) {
viewModel.editCategory()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ import androidx.lifecycle.ViewModel
import androidx.lifecycle.viewModelScope
import com.mongmong.namo.domain.model.CategoryModel
import com.mongmong.namo.domain.repositories.CategoryRepository
import com.mongmong.namo.domain.usecases.category.GetCategoriesUseCase
import com.mongmong.namo.presentation.enums.CategoryColor
import com.mongmong.namo.presentation.enums.SuccessType
import dagger.hilt.android.lifecycle.HiltViewModel
Expand Down Expand Up @@ -39,9 +38,11 @@ class CategoryViewModel @Inject constructor(
fun addCategory() {
viewModelScope.launch {
Log.d("CategoryViewModel", "addCategory ${_category.value}")
_isComplete.postValue(repository.addCategory(
category = _category.value!!
))
_isComplete.postValue(
repository.addCategory(
category = _category.value!!
)
)
_completeState.value = SuccessType.ADD
}
}
Expand All @@ -50,9 +51,11 @@ class CategoryViewModel @Inject constructor(
fun editCategory() {
viewModelScope.launch {
Log.d("CategoryViewModel", "editCategory ${_category.value}")
_isComplete.postValue(repository.editCategory(
category = _category.value!!
))
_isComplete.postValue(
repository.editCategory(
category = _category.value!!
)
)
_completeState.value = SuccessType.EDIT
}
}
Expand All @@ -61,9 +64,11 @@ class CategoryViewModel @Inject constructor(
fun deleteCategory() {
viewModelScope.launch {
Log.d("CategoryViewModel", "deleteCategory ${_category.value}")
_isComplete.postValue(repository.deleteCategory(
category = _category.value!!
))
_isComplete.postValue(
repository.deleteCategory(
category = _category.value!!
)
)
_completeState.value = SuccessType.DELETE
}
}
Expand All @@ -84,7 +89,11 @@ class CategoryViewModel @Inject constructor(
_category.value!!.isShare = isShare
}

fun isValidInput(): Boolean {
return (!_category.value?.name.isNullOrEmpty()) && (_color.value != null)
fun isValidName(): Boolean {
return _category.value?.name!!.isNotEmpty()
}

fun isColorSelected(): Boolean {
return _color.value != null
}
}

0 comments on commit 6a042ed

Please sign in to comment.