Skip to content

Commit

Permalink
Merge pull request #130 from TeamHY2/Feature/#98-extend-timer
Browse files Browse the repository at this point in the history
[Fix] 열람실 연장하기 버튼을 눌렀을 때 발생한 문제를 해결한다
  • Loading branch information
librarywon authored Nov 12, 2024
2 parents 9924872 + 6793c29 commit dd45fdf
Show file tree
Hide file tree
Showing 27 changed files with 24 additions and 77 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,12 @@ fun HomeRoute(
homeViewModel.updateStudyRoomExtendDialogVisibility(false)
},
onRightButtonClick = {
homeViewModel.updateStudyRoomExtendDialogVisibility(false)
homeViewModel.run {
updateStudyRoomExtendDialogVisibility(false)
saveStudyDay(true)
updateTimerRunning(true)
updateSelectedTime(LocalDateTime.now().truncatedTo(ChronoUnit.MINUTES))
}
startTimer(
LocalDateTime.now().truncatedTo(ChronoUnit.MINUTES),
homeViewModel,
Expand All @@ -147,7 +152,7 @@ fun HomeRoute(
onRightButtonClick = {
homeViewModel.updateStudyRoomEndDialogVisibility(false)
homeViewModel.updateTimerRunning(false)
homeViewModel.saveStudyDay()
homeViewModel.saveStudyDay(false)
},
onDismiss = {
homeViewModel.updateStudyRoomEndDialogVisibility(false)
Expand All @@ -171,12 +176,6 @@ fun HomeRoute(
},
onStudyRoomExtendClick = {
homeViewModel.updateStudyRoomExtendDialogVisibility(true)
startTimer(
LocalDateTime.now().truncatedTo(ChronoUnit.MINUTES),
homeViewModel,
timerViewModel,
onSendNotification,
)
},
onStudyRoomEndClick = {
homeViewModel.updateStudyRoomEndDialogVisibility(true)
Expand Down Expand Up @@ -221,7 +220,7 @@ private fun startTimer(
},
Timer.TIME_OVER_SECONDS to {
homeViewModel.updateTimerRunning(false)
homeViewModel.saveStudyDay()
homeViewModel.saveStudyDay(false)
},
),
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ class HomeViewModel
}
}

fun saveStudyDay() {
fun saveStudyDay(isExtend: Boolean) {
val currentState = _homeUiState.value
if (currentState is HomeUiState.Success) {
val startDateTime =
Expand All @@ -76,7 +76,7 @@ class HomeViewModel
viewModelScope.launch {
studyDayRepository.saveStudyDay(startDateTime, endDateTime)
.onSuccess {
loadHomeData()
if (!isExtend) loadHomeData()
}.onFailure { throwable ->
_errorFlow.emit(throwable)
}
Expand Down
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added main-presentation/src/main/res/drawable/ic_home.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
13 changes: 0 additions & 13 deletions main-presentation/src/main/res/drawable/ic_home.xml

This file was deleted.

Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
19 changes: 0 additions & 19 deletions main-presentation/src/main/res/drawable/ic_ranking.xml

This file was deleted.

Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
14 changes: 0 additions & 14 deletions main-presentation/src/main/res/drawable/ic_record.xml

This file was deleted.

Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
13 changes: 0 additions & 13 deletions main-presentation/src/main/res/drawable/ic_setting.xml

This file was deleted.

Binary file modified main-presentation/src/main/res/drawable/ic_setting_selected.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import com.teamhy2.hongikyeolgong2.timer.model.Timer
import com.teamhy2.hongikyeolgong2.timer.model.TimerRepository
import com.teamhy2.hongikyeolgong2.timer.prsentation.model.TimerUiModel
import dagger.hilt.android.lifecycle.HiltViewModel
import kotlinx.coroutines.Job
import kotlinx.coroutines.flow.MutableStateFlow
import kotlinx.coroutines.flow.StateFlow
import kotlinx.coroutines.flow.asStateFlow
Expand All @@ -21,6 +22,7 @@ class TimerViewModel
private val timerRepository: TimerRepository,
) : ViewModel() {
private lateinit var timer: Timer
private var timerJob: Job? = null

private val _timerState = MutableStateFlow(TimerUiModel())
val timerState: StateFlow<TimerUiModel> = _timerState.asStateFlow()
Expand All @@ -44,6 +46,7 @@ class TimerViewModel
duration: Duration = durationHour.value,
events: Map<Long, () -> Unit>,
) {
timerJob?.cancel()
timer = Timer(startTime, duration, events)
_timerState.value =
TimerUiModel(
Expand All @@ -58,13 +61,17 @@ class TimerViewModel
}

private fun startTimer() {
viewModelScope.launch {
timer.emitTimerEvents().collect {
_timerState.value =
_timerState.value.copy(
leftTime = timer.formattedLeftTime,
)
timerJob =
viewModelScope.launch {
timer.emitTimerEvents().collect { timeLeft ->
_timerState.value =
_timerState.value.copy(
leftTime = timer.formattedLeftTime,
)
if (timeLeft <= 0) {
timerJob?.cancel()
}
}
}
}
}
}

0 comments on commit dd45fdf

Please sign in to comment.