Skip to content

Commit

Permalink
fix continue action for record with default duration
Browse files Browse the repository at this point in the history
  • Loading branch information
Razeeman committed Nov 9, 2024
1 parent 24e55e5 commit 100ebf8
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ class AddRunningRecordMediator @Inject constructor(
comment: String,
timeStarted: Long? = null,
updateNotificationSwitch: Boolean = true,
checkDefaultDuration: Boolean = true,
) {
val actualTimeStarted = timeStarted ?: System.currentTimeMillis()
val retroactiveTrackingMode = prefsInteractor.getRetroactiveTrackingMode()
Expand Down Expand Up @@ -108,7 +109,7 @@ class AddRunningRecordMediator @Inject constructor(
if (retroactiveTrackingMode) {
addRetroactiveModeInternal(startParams, prevRecord)
} else {
addInternal(startParams)
addInternal(startParams, checkDefaultDuration)
}
// Show goal count only on timer start, otherwise it would show on change also.
notificationGoalCountInteractor.checkAndShow(typeId)
Expand All @@ -125,19 +126,23 @@ class AddRunningRecordMediator @Inject constructor(
tagIds: List<Long>,
) {
addInternal(
StartParams(
params = StartParams(
typeId = typeId,
timeStarted = timeStarted,
comment = comment,
tagIds = tagIds,
updateNotificationSwitch = true,
),
checkDefaultDuration = false,
)
}

private suspend fun addInternal(params: StartParams) {
private suspend fun addInternal(
params: StartParams,
checkDefaultDuration: Boolean,
) {
val type = recordTypeInteractor.get(params.typeId) ?: return
if (type.defaultDuration > 0L) {
if (type.defaultDuration > 0L && checkDefaultDuration) {
addInstantRecord(params, type)
} else {
addRunningRecord(params)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ class RecordActionContinueMediator @Inject constructor(
timeStarted = timeStarted,
comment = comment,
tagIds = tagIds,
checkDefaultDuration = false,
)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -204,15 +204,16 @@ class RecordQuickActionsViewModel @Inject constructor(

private suspend fun loadState(): RecordQuickActionsState {
val retroactiveTrackingModeEnabled = prefsInteractor.getRetroactiveTrackingMode()
val canContinue = !retroactiveTrackingModeEnabled

val buttons = when (extra.type) {
is Type.RecordTracked -> listOfNotNull(
RecordQuickActionsState.Button.Statistics(false),
RecordQuickActionsState.Button.Delete(false),
RecordQuickActionsState.Button.Continue(false)
.takeIf { !retroactiveTrackingModeEnabled },
.takeIf { canContinue },
RecordQuickActionsState.Button.Repeat(false),
RecordQuickActionsState.Button.Duplicate(!retroactiveTrackingModeEnabled),
RecordQuickActionsState.Button.Duplicate(canContinue),
)
is Type.RecordUntracked -> listOf(
RecordQuickActionsState.Button.Statistics(false),
Expand Down

0 comments on commit 100ebf8

Please sign in to comment.