Skip to content

Commit b963d3c

Browse files
committed
feat : 알람 저장 정보 수정 및 저장 로직 변경
1 parent 3e452a9 commit b963d3c

File tree

5 files changed

+28
-21
lines changed

5 files changed

+28
-21
lines changed

data/src/main/java/com/stop/data/local/model/Alarm.kt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,13 @@ package com.stop.data.local.model
22

33
import com.squareup.moshi.JsonClass
44
import com.stop.data.model.alarm.AlarmRepositoryItem
5+
import com.stop.domain.model.route.tmap.custom.Route
56

67
@JsonClass(generateAdapter = true)
78
data class Alarm(
89
val startPosition: String,
910
val endPosition: String,
10-
val routes: List<String>,
11+
val routes: List<Route>,
1112
val lastTime: String, // 막차 시간 -> 23:30:15 시분초
1213
val alarmTime: Int, // 10분 전 알람 설정 -> 10
1314
val alarmCode: Int, // 알람을 식별하기 위한 알람 ID

data/src/main/java/com/stop/data/model/alarm/AlarmRepositoryItem.kt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,12 @@ package com.stop.data.model.alarm
22

33
import com.stop.data.local.model.Alarm
44
import com.stop.domain.model.alarm.AlarmUseCaseItem
5+
import com.stop.domain.model.route.tmap.custom.Route
56

67
data class AlarmRepositoryItem(
78
val startPosition: String,
89
val endPosition: String,
9-
val routes: List<String>,
10+
val routes: List<Route>,
1011
val lastTime: String, // 막차 시간 -> 23:30:15 시분초
1112
val alarmTime: Int, // 10분 전 알람 설정 -> 10
1213
val alarmCode: Int, // 알람을 식별하기 위한 알람 ID

domain/src/main/java/com/stop/domain/model/alarm/AlarmUseCaseItem.kt

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,11 @@
11
package com.stop.domain.model.alarm
22

3+
import com.stop.domain.model.route.tmap.custom.Route
4+
35
data class AlarmUseCaseItem(
46
val startPosition: String,
57
val endPosition: String,
6-
val routes: List<String>,
8+
val routes: List<Route>,
79
val lastTime: String, // 막차 시간 -> 23:30:15 시분초
810
val alarmTime: Int, // 10분 전 알람 설정 -> 10
911
val alarmCode: Int, // 알람을 식별하기 위한 알람 ID

presentation/src/main/java/com/stop/ui/alarmsetting/AlarmSettingFragment.kt

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ import com.stop.AlarmFunctions
1515
import com.stop.AlarmWorker
1616
import com.stop.R
1717
import com.stop.databinding.FragmentAlarmSettingBinding
18+
import com.stop.domain.model.alarm.AlarmUseCaseItem
1819
import com.stop.ui.route.ClickRouteViewModel
1920
import dagger.hilt.android.AndroidEntryPoint
2021
import java.util.concurrent.TimeUnit
@@ -66,8 +67,6 @@ class AlarmSettingFragment : Fragment() {
6667

6768
private fun initView() {
6869
with(binding) {
69-
textViewWalk.text = getString(R.string.last_transport_walking_time, 10)
70-
7170
numberPickerAlarmTime.minValue = 0
7271
numberPickerAlarmTime.maxValue = 60
7372

@@ -89,7 +88,16 @@ class AlarmSettingFragment : Fragment() {
8988
}
9089

9190
fun setAlarmRegisterListener() {
92-
alarmSettingViewModel.saveAlarm()
91+
val alarmUseCaseItem = AlarmUseCaseItem(
92+
startPosition = clickRouteViewModel.clickRoute?.routes?.first()?.start?.name ?: "출발지 없음",
93+
endPosition = clickRouteViewModel.clickRoute?.routes?.last()?.end?.name ?: "도착지 없음",
94+
routes = clickRouteViewModel.clickRoute?.routes ?: emptyList(),
95+
lastTime = clickRouteViewModel.lastTime,
96+
0,
97+
ALARM_CODE,
98+
true
99+
)
100+
alarmSettingViewModel.saveAlarm(alarmUseCaseItem)
93101
makeAlarm()
94102
//makeAlarmWorker()
95103
binding.root.findNavController().navigate(R.id.action_alarmSetting_to_mapFragment)
@@ -116,4 +124,9 @@ class AlarmSettingFragment : Fragment() {
116124
_binding = null
117125
super.onDestroyView()
118126
}
127+
128+
companion object {
129+
const val ALARM_CODE = 123
130+
}
131+
119132
}

presentation/src/main/java/com/stop/ui/alarmsetting/AlarmSettingViewModel.kt

Lines changed: 5 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -24,29 +24,19 @@ class AlarmSettingViewModel @Inject constructor(
2424
var alarmMethod = true
2525

2626
private val _alarmItem = MutableStateFlow<AlarmUseCaseItem?>(null)
27-
val alarmItem : StateFlow<AlarmUseCaseItem?> = _alarmItem
27+
val alarmItem: StateFlow<AlarmUseCaseItem?> = _alarmItem
2828

2929
private val _isAlarmItemNotNull = MutableStateFlow(false)
30-
val isAlarmItemNotNull : StateFlow<Boolean> = _isAlarmItemNotNull
31-
32-
fun saveAlarm() {
33-
val alarmUseCaseItem = AlarmUseCaseItem(
34-
"쑥고개로 2다길 1",
35-
"현대 아남타워",
36-
listOf("도보", "버스5517", "신림역", "선릉역", "도보"),
37-
"23:30:00",
38-
alarmTime.value ?: 0,
39-
123,
40-
alarmMethod
41-
)
30+
val isAlarmItemNotNull: StateFlow<Boolean> = _isAlarmItemNotNull
4231

32+
fun saveAlarm(alarmUseCaseItem: AlarmUseCaseItem) {
4333
viewModelScope.launch(Dispatchers.IO) {
44-
saveAlarmUseCase.saveAlarm(alarmUseCaseItem)
34+
saveAlarmUseCase.saveAlarm(alarmUseCaseItem.copy(alarmTime = alarmTime.value ?: 0, alarmMethod = alarmMethod))
4535
}
4636
}
4737

4838
fun getAlarm() {
49-
viewModelScope.launch(Dispatchers.IO){
39+
viewModelScope.launch(Dispatchers.IO) {
5040
getAlarmUseCase.getAlarm().collectLatest {
5141
_alarmItem.value = it
5242

0 commit comments

Comments
 (0)