Skip to content

Commit

Permalink
[FEAT/#48] AlarmSoundBottomSheet ์—ฐ๋™
Browse files Browse the repository at this point in the history
  • Loading branch information
DongChyeon committed Jan 19, 2025
1 parent 179b2ae commit 33bd138
Show file tree
Hide file tree
Showing 4 changed files with 111 additions and 23 deletions.
15 changes: 15 additions & 0 deletions feature/home/src/main/java/com/yapp/alarm/AlarmAddEditContract.kt
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ sealed class AlarmAddEditContract {
val daySelectionState: AlarmDaySelectionState = AlarmDaySelectionState(),
val holidayState: AlarmHolidayState = AlarmHolidayState(),
val snoozeState: AlarmSnoozeState = AlarmSnoozeState(),
val soundState: AlarmSoundState = AlarmSoundState(),
) : UiState

data class AlarmTimeState(
Expand Down Expand Up @@ -39,6 +40,15 @@ sealed class AlarmAddEditContract {
val snoozeCounts: List<String> = listOf("1ํšŒ", "3ํšŒ", "5ํšŒ", "10ํšŒ", "๋ฌดํ•œ"),
)

data class AlarmSoundState(
val isVibrationEnabled: Boolean = true,
val isSoundEnabled: Boolean = true,
val soundVolume: Int = 70,
val soundIndex: Int = 0,
val sounds: List<String> = (1..7).map { "๊ธฐ๋ณธ ์•Œ๋žŒ์Œ $it" },
val isBottomSheetOpen: Boolean = false,
)

sealed class Action {
data object ClickBack : Action()
data object ClickSave : Action()
Expand All @@ -51,6 +61,11 @@ sealed class AlarmAddEditContract {
data object ToggleSnoozeEnabled : Action()
data class UpdateSnoozeInterval(val index: Int) : Action()
data class UpdateSnoozeCount(val index: Int) : Action()
data object ToggleVibrationEnabled : Action()
data object ToggleSoundEnabled : Action()
data class UpdateSoundVolume(val volume: Int) : Action()
data class UpdateSoundIndex(val index: Int) : Action()
data object ToggleSoundSettingBottomSheetOpen : Action()
}

sealed class SideEffect : com.yapp.ui.base.SideEffect {
Expand Down
48 changes: 42 additions & 6 deletions feature/home/src/main/java/com/yapp/alarm/AlarmAddEditScreen.kt
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ import androidx.lifecycle.compose.collectAsStateWithLifecycle
import com.yapp.alarm.component.AlarmCheckItem
import com.yapp.alarm.component.AlarmDayButton
import com.yapp.alarm.component.bottomsheet.AlarmSnoozeBottomSheet
import com.yapp.alarm.component.bottomsheet.AlarmSoundBottomSheet
import com.yapp.common.navigation.OrbitNavigator
import com.yapp.designsystem.theme.OrbitTheme
import com.yapp.ui.component.button.OrbitButton
Expand Down Expand Up @@ -81,7 +82,8 @@ fun AlarmAddEditScreen(
) {
val state = stateProvider()
val snoozeState = state.snoozeState
val bottomSheetState = rememberModalBottomSheetState(skipPartiallyExpanded = true)
val snoozeBottomSheetState = rememberModalBottomSheetState(skipPartiallyExpanded = true)
val soundBottomSheetState = rememberModalBottomSheetState(skipPartiallyExpanded = true)
val scope = rememberCoroutineScope()

Column(
Expand Down Expand Up @@ -132,20 +134,47 @@ fun AlarmAddEditScreen(
onCountSelected = { index -> eventDispatcher(AlarmAddEditContract.Action.UpdateSnoozeCount(index)) },
onComplete = {
scope.launch {
bottomSheetState.hide()
snoozeBottomSheetState.hide()
}.invokeOnCompletion {
eventDispatcher(AlarmAddEditContract.Action.ToggleSnoozeSettingBottomSheetOpen)
}
},
isSheetOpen = snoozeState.isBottomSheetOpen,
onDismiss = {
scope.launch {
bottomSheetState.hide()
snoozeBottomSheetState.hide()
}.invokeOnCompletion {
eventDispatcher(AlarmAddEditContract.Action.ToggleSnoozeSettingBottomSheetOpen)
}
},
)

AlarmSoundBottomSheet(
isVibrationEnabled = state.soundState.isVibrationEnabled,
isSoundEnabled = state.soundState.isSoundEnabled,
soundVolume = state.soundState.soundVolume,
soundIndex = state.soundState.soundIndex,
sounds = state.soundState.sounds,
onVibrationToggle = { eventDispatcher(AlarmAddEditContract.Action.ToggleVibrationEnabled) },
onSoundToggle = { eventDispatcher(AlarmAddEditContract.Action.ToggleSoundEnabled) },
onVolumeChanged = { eventDispatcher(AlarmAddEditContract.Action.UpdateSoundVolume(it)) },
onSoundSelected = { eventDispatcher(AlarmAddEditContract.Action.UpdateSoundIndex(it)) },
onComplete = {
scope.launch {
soundBottomSheetState.hide()
}.invokeOnCompletion {
eventDispatcher(AlarmAddEditContract.Action.ToggleSoundSettingBottomSheetOpen)
}
},
isSheetOpen = state.soundState.isBottomSheetOpen,
onDismiss = {
scope.launch {
soundBottomSheetState.hide()
}.invokeOnCompletion {
eventDispatcher(AlarmAddEditContract.Action.ToggleSoundSettingBottomSheetOpen)
}
},
)
}

@Composable
Expand Down Expand Up @@ -230,9 +259,16 @@ private fun AlarmAddEditSettingsSection(
.background(OrbitTheme.colors.gray_700),
)
AlarmAddEditSettingItem(
label = "์‚ฌ์šด๋“œ",
description = "์ง„๋™, ์•Œ๋ฆผ์Œ1",
onClick = { },
label = stringResource(id = R.string.alarm_add_edit_sound),
description = when {
state.soundState.isSoundEnabled && state.soundState.isVibrationEnabled -> {
"${state.soundState.sounds[state.soundState.soundIndex]}, ${stringResource(id = R.string.alarm_add_edit_vibration)}"
}
state.soundState.isSoundEnabled -> state.soundState.sounds[state.soundState.soundIndex]
state.soundState.isVibrationEnabled -> stringResource(id = R.string.alarm_add_edit_vibration)
else -> stringResource(id = R.string.alarm_add_edit_alarm_selected_option_none)
},
onClick = { processAction(AlarmAddEditContract.Action.ToggleSoundSettingBottomSheetOpen) },
)
}
}
Expand Down
68 changes: 52 additions & 16 deletions feature/home/src/main/java/com/yapp/alarm/AlarmAddEditViewModel.kt
Original file line number Diff line number Diff line change
@@ -1,30 +1,31 @@
package com.yapp.alarm

import androidx.lifecycle.viewModelScope
import com.yapp.ui.base.BaseViewModel
import dagger.hilt.android.lifecycle.HiltViewModel
import kotlinx.coroutines.launch
import javax.inject.Inject

@HiltViewModel
class AlarmAddEditViewModel @Inject constructor() : BaseViewModel<AlarmAddEditContract.State, AlarmAddEditContract.SideEffect>(
initialState = AlarmAddEditContract.State(),
) {
fun processAction(action: AlarmAddEditContract.Action) {
viewModelScope.launch {
when (action) {
is AlarmAddEditContract.Action.ClickBack -> navigateBack()
is AlarmAddEditContract.Action.ClickSave -> saveAlarm()
is AlarmAddEditContract.Action.UpdateAlarmTime -> updateAlarmTime(action.amPm, action.hour, action.minute)
is AlarmAddEditContract.Action.ToggleWeekdaysChecked -> toggleWeekdaysChecked()
is AlarmAddEditContract.Action.ToggleWeekendsChecked -> toggleWeekendsChecked()
is AlarmAddEditContract.Action.ToggleDaySelection -> toggleDaySelection(action.day)
is AlarmAddEditContract.Action.ToggleDisableHolidayChecked -> toggleDisableHolidayChecked()
is AlarmAddEditContract.Action.ToggleSnoozeEnabled -> toggleSnoozeEnabled()
is AlarmAddEditContract.Action.UpdateSnoozeInterval -> updateSnoozeInterval(action.index)
is AlarmAddEditContract.Action.UpdateSnoozeCount -> updateSnoozeCount(action.index)
is AlarmAddEditContract.Action.ToggleSnoozeSettingBottomSheetOpen -> toggleSnoozeSettingBottomSheet()
}
when (action) {
is AlarmAddEditContract.Action.ClickBack -> navigateBack()
is AlarmAddEditContract.Action.ClickSave -> saveAlarm()
is AlarmAddEditContract.Action.UpdateAlarmTime -> updateAlarmTime(action.amPm, action.hour, action.minute)
is AlarmAddEditContract.Action.ToggleWeekdaysChecked -> toggleWeekdaysChecked()
is AlarmAddEditContract.Action.ToggleWeekendsChecked -> toggleWeekendsChecked()
is AlarmAddEditContract.Action.ToggleDaySelection -> toggleDaySelection(action.day)
is AlarmAddEditContract.Action.ToggleDisableHolidayChecked -> toggleDisableHolidayChecked()
is AlarmAddEditContract.Action.ToggleSnoozeEnabled -> toggleSnoozeEnabled()
is AlarmAddEditContract.Action.UpdateSnoozeInterval -> updateSnoozeInterval(action.index)
is AlarmAddEditContract.Action.UpdateSnoozeCount -> updateSnoozeCount(action.index)
is AlarmAddEditContract.Action.ToggleSnoozeSettingBottomSheetOpen -> toggleSnoozeSettingBottomSheet()
is AlarmAddEditContract.Action.ToggleVibrationEnabled -> toggleVibrationEnabled()
is AlarmAddEditContract.Action.ToggleSoundEnabled -> toggleSoundEnabled()
is AlarmAddEditContract.Action.UpdateSoundVolume -> updateSoundVolume(action.volume)
is AlarmAddEditContract.Action.UpdateSoundIndex -> updateSoundIndex(action.index)
is AlarmAddEditContract.Action.ToggleSoundSettingBottomSheetOpen -> toggleSoundSettingBottomSheet()
}
}

Expand Down Expand Up @@ -167,6 +168,41 @@ class AlarmAddEditViewModel @Inject constructor() : BaseViewModel<AlarmAddEditCo
}
}

private fun toggleVibrationEnabled() {
val newSoundState = currentState.soundState.copy(isVibrationEnabled = !currentState.soundState.isVibrationEnabled)
updateState {
copy(soundState = newSoundState)
}
}

private fun toggleSoundEnabled() {
val newSoundState = currentState.soundState.copy(isSoundEnabled = !currentState.soundState.isSoundEnabled)
updateState {
copy(soundState = newSoundState)
}
}

private fun updateSoundVolume(volume: Int) {
val newSoundState = currentState.soundState.copy(soundVolume = volume)
updateState {
copy(soundState = newSoundState)
}
}

private fun updateSoundIndex(index: Int) {
val newSoundState = currentState.soundState.copy(soundIndex = index)
updateState {
copy(soundState = newSoundState)
}
}

private fun toggleSoundSettingBottomSheet() {
val newSoundState = currentState.soundState.copy(isBottomSheetOpen = !currentState.soundState.isBottomSheetOpen)
updateState {
copy(soundState = newSoundState)
}
}

private fun getAlarmMessage(amPm: String, hour: Int, minute: Int, selectedDays: Set<AlarmDay>): String {
val now = java.time.LocalDateTime.now()
val alarmHour = convertTo24HourFormat(amPm, hour)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,6 @@ internal fun AlarmSoundBottomSheet(

@Composable
private fun BottomSheetContent(
modifier: Modifier = Modifier,
isVibrationEnabled: Boolean,
isSoundEnabled: Boolean,
soundVolume: Int,
Expand Down Expand Up @@ -226,6 +225,8 @@ private fun SoundSection(
sounds = sounds,
onSoundSelected = { onSoundSelected(it) },
)
} else {
Spacer(modifier = Modifier.height(20.dp))
}
}
}
Expand Down

0 comments on commit 33bd138

Please sign in to comment.