@@ -4,6 +4,7 @@ import androidx.room.Dao
4
4
import androidx.room.Delete
5
5
import androidx.room.Query
6
6
import androidx.room.Upsert
7
+ import cloud.pablos.overload.ui.tabs.home.getItemsOfDay
7
8
import cloud.pablos.overload.ui.views.extractDate
8
9
import cloud.pablos.overload.ui.views.parseToLocalDateTime
9
10
import kotlinx.coroutines.flow.Flow
@@ -16,9 +17,9 @@ interface ItemDao {
16
17
suspend fun upsertItem (item : Item )
17
18
18
19
/* @Upsert
19
- suspend fun upsertItems(items: List<Item>)*/
20
+ suspend fun upsertItems(items: List<Item>)
20
21
21
- /* @Delete
22
+ @Delete
22
23
suspend fun deleteItem(item: Item)*/
23
24
24
25
@Delete
@@ -55,11 +56,7 @@ fun startOrStopPause(
55
56
) {
56
57
val date = LocalDate .now()
57
58
58
- val itemsForToday =
59
- state.items.filter { item ->
60
- val startTime = parseToLocalDateTime(item.startTime)
61
- extractDate(startTime) == date
62
- }
59
+ val itemsForToday = getItemsOfDay(date, state)
63
60
val isFirstToday = itemsForToday.isEmpty()
64
61
val isOngoingToday = itemsForToday.isNotEmpty() && itemsForToday.last().ongoing
65
62
@@ -73,32 +70,32 @@ fun startOrStopPause(
73
70
if (isOngoingNotToday) {
74
71
onEvent(ItemEvent .SetForgotToStopDialogShown (true ))
75
72
} else if (isFirstToday) {
76
- onEvent(ItemEvent .SetStart (start = LocalDateTime .now().toString()))
77
- onEvent(ItemEvent .SetOngoing (ongoing = true ))
78
- onEvent(ItemEvent .SetPause (pause = false ))
73
+ onEvent(ItemEvent .SetStart (LocalDateTime .now().toString()))
74
+ onEvent(ItemEvent .SetOngoing (true ))
75
+ onEvent(ItemEvent .SetPause (false ))
79
76
onEvent(ItemEvent .SaveItem )
80
77
81
- onEvent(ItemEvent .SetIsOngoing (isOngoing = true ))
78
+ onEvent(ItemEvent .SetIsOngoing (true ))
82
79
} else if (isOngoingToday) {
83
- onEvent(ItemEvent .SetId (id = itemsForToday.last().id))
84
- onEvent(ItemEvent .SetStart (start = itemsForToday.last().startTime))
85
- onEvent(ItemEvent .SetEnd (end = LocalDateTime .now().toString()))
86
- onEvent(ItemEvent .SetOngoing (ongoing = false ))
80
+ onEvent(ItemEvent .SetId (itemsForToday.last().id))
81
+ onEvent(ItemEvent .SetStart (itemsForToday.last().startTime))
82
+ onEvent(ItemEvent .SetEnd (LocalDateTime .now().toString()))
83
+ onEvent(ItemEvent .SetOngoing (false ))
87
84
onEvent(ItemEvent .SaveItem )
88
85
89
- onEvent(ItemEvent .SetIsOngoing (isOngoing = false ))
86
+ onEvent(ItemEvent .SetIsOngoing (false ))
90
87
} else {
91
- onEvent(ItemEvent .SetStart (start = itemsForToday.last().endTime))
92
- onEvent(ItemEvent .SetEnd (end = LocalDateTime .now().toString()))
93
- onEvent(ItemEvent .SetOngoing (ongoing = false ))
94
- onEvent(ItemEvent .SetPause (pause = true ))
88
+ onEvent(ItemEvent .SetStart (itemsForToday.last().endTime))
89
+ onEvent(ItemEvent .SetEnd (LocalDateTime .now().toString()))
90
+ onEvent(ItemEvent .SetOngoing (false ))
91
+ onEvent(ItemEvent .SetPause (true ))
95
92
onEvent(ItemEvent .SaveItem )
96
93
97
- onEvent(ItemEvent .SetStart (start = LocalDateTime .now().toString()))
98
- onEvent(ItemEvent .SetOngoing (ongoing = true ))
99
- onEvent(ItemEvent .SetPause (pause = false ))
94
+ onEvent(ItemEvent .SetStart (LocalDateTime .now().toString()))
95
+ onEvent(ItemEvent .SetOngoing (true ))
96
+ onEvent(ItemEvent .SetPause (false ))
100
97
onEvent(ItemEvent .SaveItem )
101
98
102
- onEvent(ItemEvent .SetIsOngoing (isOngoing = true ))
99
+ onEvent(ItemEvent .SetIsOngoing (true ))
103
100
}
104
101
}
0 commit comments