Skip to content

Commit 8489aa5

Browse files
committed
change start of day shift presentation
1 parent a6ded26 commit 8489aa5

3 files changed

Lines changed: 24 additions & 22 deletions

File tree

features/feature_settings/src/main/java/com/example/util/simpletimetracker/feature_settings/interactor/SettingsAdditionalViewDataInteractor.kt

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -232,9 +232,14 @@ class SettingsAdditionalViewDataInteractor @Inject constructor(
232232
showSeconds = false,
233233
),
234234
)
235+
val value = if (shift == 0L) {
236+
resourceRepo.getString(R.string.change_record_type_goal_time_disabled)
237+
} else {
238+
timeMapper.formatDuration(shift / 1000)
239+
}
235240

236241
return SettingsStartOfDayViewData(
237-
startOfDayValue = settingsMapper.toStartOfDayText(shift, useMilitaryTime = true),
242+
startOfDayValue = value,
238243
startOfDaySign = settingsMapper.toStartOfDaySign(shift),
239244
hint = hint,
240245
)

features/feature_settings/src/main/java/com/example/util/simpletimetracker/feature_settings/viewModel/SettingsViewModel.kt

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -122,7 +122,6 @@ class SettingsViewModel @Inject constructor(
122122
fun onDateTimeSet(timestamp: Long, tag: String?) {
123123
notificationsDelegate.onDateTimeSet(timestamp, tag)
124124
displayDelegate.onDateTimeSet(timestamp, tag)
125-
additionalDelegate.onDateTimeSet(timestamp, tag)
126125
backupDelegate.onDateTimeSet(timestamp, tag)
127126
}
128127

features/feature_settings/src/main/java/com/example/util/simpletimetracker/feature_settings/viewModel/delegate/SettingsAdditionalViewModelDelegate.kt

Lines changed: 18 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -100,10 +100,6 @@ class SettingsAdditionalViewModelDelegate @Inject constructor(
100100
onDurationDisabledDelegate(tag)
101101
}
102102

103-
fun onDateTimeSet(timestamp: Long, tag: String?) {
104-
onDateTimeSetDelegate(timestamp, tag)
105-
}
106-
107103
fun onTypesSelected(typeIds: List<Long>, tag: String?) {
108104
onTypesSelectedDelegate(typeIds, tag)
109105
}
@@ -139,11 +135,13 @@ class SettingsAdditionalViewModelDelegate @Inject constructor(
139135

140136
private fun onStartOfDayClicked() {
141137
delegateScope.launch {
142-
parent?.openDateTimeDialog(
138+
DurationDialogParams(
143139
tag = SettingsViewModel.START_OF_DAY_DIALOG_TAG,
144-
timestamp = prefsInteractor.getStartOfDayShift(),
145-
useMilitaryTime = true,
146-
)
140+
value = DurationDialogParams.Value.DurationSeconds(
141+
duration = prefsInteractor.getStartOfDayShift() / 1000,
142+
),
143+
showSeconds = false,
144+
).let(router::navigate)
147145
}
148146
}
149147

@@ -296,30 +294,30 @@ class SettingsAdditionalViewModelDelegate @Inject constructor(
296294
}
297295
}
298296

299-
private fun onDurationSetDelegate(tag: String?, duration: Long) {
297+
private fun onDurationSetDelegate(tag: String?, duration: Long) = delegateScope.launch {
300298
when (tag) {
301-
SettingsViewModel.IGNORE_SHORT_RECORDS_DIALOG_TAG -> delegateScope.launch {
299+
SettingsViewModel.IGNORE_SHORT_RECORDS_DIALOG_TAG -> {
302300
prefsInteractor.setIgnoreShortRecordsDuration(duration)
303301
parent?.updateContent()
304302
}
303+
SettingsViewModel.START_OF_DAY_DIALOG_TAG -> {
304+
val wasPositive = prefsInteractor.getStartOfDayShift() >= 0
305+
val newValue = if (wasPositive) duration else duration * -1
306+
prefsInteractor.setStartOfDayShift(newValue * 1000)
307+
externalViewsInteractor.onStartOfDayChange()
308+
parent?.updateContent()
309+
}
305310
}
306311
}
307312

308-
private fun onDurationDisabledDelegate(tag: String?) {
313+
private fun onDurationDisabledDelegate(tag: String?) = delegateScope.launch {
309314
when (tag) {
310-
SettingsViewModel.IGNORE_SHORT_RECORDS_DIALOG_TAG -> delegateScope.launch {
315+
SettingsViewModel.IGNORE_SHORT_RECORDS_DIALOG_TAG -> {
311316
prefsInteractor.setIgnoreShortRecordsDuration(0)
312317
parent?.updateContent()
313318
}
314-
}
315-
}
316-
317-
private fun onDateTimeSetDelegate(timestamp: Long, tag: String?) = delegateScope.launch {
318-
when (tag) {
319319
SettingsViewModel.START_OF_DAY_DIALOG_TAG -> {
320-
val wasPositive = prefsInteractor.getStartOfDayShift() >= 0
321-
val newValue = settingsMapper.toStartOfDayShift(timestamp, wasPositive)
322-
prefsInteractor.setStartOfDayShift(newValue)
320+
prefsInteractor.setStartOfDayShift(0)
323321
externalViewsInteractor.onStartOfDayChange()
324322
parent?.updateContent()
325323
}

0 commit comments

Comments
 (0)