Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,11 @@ class TimerRepositoryImpl @Inject constructor(

// 커스텀 타이머 삭제
override suspend fun deleteCustomTimer(customTimerId: Long): BaseResult<Unit> {
TODO("Not yet implemented")
return apiCallBuilder(
ioDispatcher = ioDispatcher,
apiCall = { apiService.deleteCustomTimer(customTimerId) },
mapper = { Unit }
)
}

// 커스텀 타이머 이름 수정
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
package com.project200.domain.usecase

import com.project200.domain.model.BaseResult
import com.project200.domain.repository.TimerRepository
import javax.inject.Inject

class DeleteCustomTimerUseCase @Inject constructor(
private val timerRepository: TimerRepository
) {
suspend operator fun invoke(customTimerId: Long): BaseResult<Unit> {
return timerRepository.deleteCustomTimer(customTimerId)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import androidx.lifecycle.repeatOnLifecycle
import androidx.navigation.fragment.findNavController
import androidx.navigation.fragment.navArgs
import androidx.recyclerview.widget.LinearLayoutManager
import com.project200.domain.model.BaseResult
import com.project200.feature.timer.TimerListFragment
import com.project200.feature.timer.utils.TimerFormatter.toFormattedTimeAsLong
import com.project200.presentation.base.BaseAlertDialog
Expand Down Expand Up @@ -145,6 +146,15 @@ class CustomTimerFragment: BindingFragment<FragmentCustomTimerBinding>(R.layout.
binding.baseToolbar.setTitle(title)
}

viewModel.deleteResult.observe(viewLifecycleOwner) { result ->
findNavController().navigateUp()
val messageRes = when(result) {
is BaseResult.Success -> R.string.custom_timer_delete_success
is BaseResult.Error -> R.string.custom_timer_error_delete_failed
}
Toast.makeText(requireContext(), getString(messageRes), Toast.LENGTH_SHORT).show()
}

// 에러 이벤트 처리
viewLifecycleOwner.lifecycleScope.launch {
repeatOnLifecycle(Lifecycle.State.STARTED) {
Expand Down Expand Up @@ -243,7 +253,7 @@ class CustomTimerFragment: BindingFragment<FragmentCustomTimerBinding>(R.layout.
title = getString(R.string.custom_timer_delete_alert),
desc = null,
onConfirmClicked = {
// TODO: 커스텀 타이머 삭제
viewModel.deleteTimer()
}
).show(parentFragmentManager, BaseAlertDialog::class.java.simpleName)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import com.project200.domain.model.Step
import com.project200.domain.manager.TimerManager
import com.project200.domain.model.BaseResult
import com.project200.domain.model.CustomTimer
import com.project200.domain.usecase.DeleteCustomTimerUseCase
import com.project200.domain.usecase.GetCustomTimerUseCase
import dagger.hilt.android.lifecycle.HiltViewModel
import kotlinx.coroutines.flow.MutableSharedFlow
Expand All @@ -19,7 +20,8 @@ import javax.inject.Inject
@HiltViewModel
class CustomTimerViewModel @Inject constructor(
private val timerManager: TimerManager,
private val getCustomTimerUseCase: GetCustomTimerUseCase
private val getCustomTimerUseCase: GetCustomTimerUseCase,
private val deleteCustomTimerUseCase: DeleteCustomTimerUseCase,
): ViewModel() {
// 전체 타이머 시간 (밀리초 단위)
var totalTime: Long = 0L
Expand All @@ -29,8 +31,7 @@ class CustomTimerViewModel @Inject constructor(
var totalStepTime: Long = 0L
private set

var customTimerId: Long? = null
private set
private var customTimerId: Long = -1L

private val _title = MutableLiveData<String>()
val title: LiveData<String> = _title
Expand Down Expand Up @@ -60,6 +61,9 @@ class CustomTimerViewModel @Inject constructor(
private val _errorEvent = MutableSharedFlow<Boolean>()
val errorEvent: SharedFlow<Boolean> = _errorEvent

private val _deleteResult = MutableLiveData<BaseResult<Unit>>()
val deleteResult: LiveData<BaseResult<Unit>> = _deleteResult

init {
setupTimerManager()
resetTimer()
Expand All @@ -83,6 +87,13 @@ class CustomTimerViewModel @Inject constructor(
}
}

fun deleteTimer() {
viewModelScope.launch {
if (customTimerId == -1L) return@launch
_deleteResult.value = deleteCustomTimerUseCase(customTimerId)
}
}

// TimerManager의 콜백을 설정하는 초기화 함수
private fun setupTimerManager() {
timerManager.setOnTickListener { millisUntilFinished ->
Expand Down
2 changes: 2 additions & 0 deletions feature/timer/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
<string name="custom_timer_default">나만의 타이머</string>

<string name="custom_timer_delete_alert">정말 타이머를 삭제할까요?</string>
<string name="custom_timer_delete_success">타이머를 삭제했습니다.</string>
<string name="custom_timer_title_hint">나만의 타이머 이름</string>
<string name="custom_timer_step_hint">Step</string>

Expand All @@ -22,6 +23,7 @@
<string name="error_failed_to_load_list">타이머를 불러오는데 실패했습니다.</string>
<string name="custom_timer_error_create_failed">타이머를 생성하는데 실패했습니다.</string>
<string name="custom_timer_error_edit_failed">타이머를 수정하는데 실패했습니다.</string>
<string name="custom_timer_error_delete_failed">타이머를 삭제하는데 실패했습니다.</string>
<string name="unknown_error">알 수 없는 오류가 발생했습니다.</string>

<string name="edit_simple_timer_error">타이머 수정에 실패했습니다.</string>
Expand Down