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 100805c commit f2fa113
Show file tree
Hide file tree
Showing 4 changed files with 7 additions and 24 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,8 @@ object CategoryMapper {
categoryId = this.categoryId,
name = this.categoryName,
colorId = this.colorId,
isShare = this.isShared
isShare = this.isShared,
basicCategory = this.baseCategory
)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ data class CategoryModel(
var categoryId: Long = 0,
var name: String = "",
var colorId: Int = 0,
var basicCategory: Boolean = false,
var basicCategory: Boolean = false, // 기본 카테고리는 삭제 불가
var isShare: Boolean = false,
) : Serializable {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,10 @@ class CategoryDetailFragment

// 카테고리 삭제
binding.categoryDeleteBtn.setOnClickListener {
if (viewModel.category.value!!.basicCategory) {
Toast.makeText(requireContext(), "기본 카테고리는 삭제할 수 없습니다.", Toast.LENGTH_SHORT).show()
return@setOnClickListener
}
val dialog = ConfirmDialog(
this@CategoryDetailFragment,
getString(R.string.dialog_category_delete_title),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ import javax.inject.Inject
@HiltViewModel
class CategoryViewModel @Inject constructor(
private val repository: CategoryRepository,
private val getCategoriesUseCase: GetCategoriesUseCase,
) : ViewModel() {
var isEditMode: Boolean = false

Expand All @@ -36,17 +35,6 @@ class CategoryViewModel @Inject constructor(
private val _color = MutableLiveData<CategoryColor?>(null)
val color: LiveData<CategoryColor?> = _color

private val _canDeleteCategory = MutableLiveData<Boolean>(true)
val canDeleteCategory: LiveData<Boolean> = _canDeleteCategory

/** 카테고리 조회 */
fun getCategories() {
viewModelScope.launch {
Log.d("CategoryViewModel", "getCategories")
_categoryList.value = getCategoriesUseCase.invoke()
}
}

/** 카테고리 추가 */
fun addCategory() {
viewModelScope.launch {
Expand Down Expand Up @@ -87,16 +75,6 @@ class CategoryViewModel @Inject constructor(
}
}

fun setDeliable(canDelete: Boolean) {
_canDeleteCategory.value = canDelete
}

fun updateTitle(title: String) {
_category.value = _category.value?.copy(
name = title
)
}

fun updateCategoryColor(color: CategoryColor) {
_color.value = color
_category.value = _category.value?.copy(colorId = color.colorId)
Expand Down

0 comments on commit f2fa113

Please sign in to comment.