Skip to content

Commit

Permalink
fix some retroactive mode errors
Browse files Browse the repository at this point in the history
  • Loading branch information
Razeeman committed Nov 23, 2024
1 parent c807aff commit fb0b989
Show file tree
Hide file tree
Showing 6 changed files with 43 additions and 21 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ object Base {
const val namespace = "com.example.util.simpletimetracker"

// Raise by 2 to account for wear version code.
const val versionCode = 79
const val versionCode = 81
const val versionName = "1.46"
const val minSDK = 21
const val currentSDK = 34
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,9 @@ class AddRunningRecordMediator @Inject constructor(
}
// Show goal count only on timer start, otherwise it would show on change also.
notificationGoalCountInteractor.checkAndShow(typeId)
pomodoroStartInteractor.checkAndStart(typeId)
if (!retroactiveTrackingMode) {
pomodoroStartInteractor.checkAndStart(typeId)
}
}

// Used separately only for changing running activity,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -321,7 +321,6 @@ class AddRunningRecordMediatorTest {
)
}


@Test
fun defaultTag(): Unit = runBlocking {
// Given
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import com.example.util.simpletimetracker.domain.interactor.GetSelectableTagsInt
import com.example.util.simpletimetracker.domain.interactor.NotificationActivitySwitchInteractor
import com.example.util.simpletimetracker.domain.interactor.PrefsInteractor
import com.example.util.simpletimetracker.domain.interactor.RecordInteractor
import com.example.util.simpletimetracker.domain.interactor.RecordTagInteractor
import com.example.util.simpletimetracker.domain.interactor.RecordTypeGoalInteractor
import com.example.util.simpletimetracker.domain.interactor.RecordTypeInteractor
import com.example.util.simpletimetracker.domain.interactor.RunningRecordInteractor
Expand All @@ -19,6 +20,7 @@ import com.example.util.simpletimetracker.feature_notification.R
import com.example.util.simpletimetracker.feature_notification.activitySwitch.manager.NotificationActivitySwitchManager
import com.example.util.simpletimetracker.feature_notification.activitySwitch.manager.NotificationActivitySwitchParams
import com.example.util.simpletimetracker.feature_notification.activitySwitch.manager.NotificationControlsParams
import com.example.util.simpletimetracker.feature_notification.core.NotificationCommonMapper
import com.example.util.simpletimetracker.feature_views.viewData.RecordTypeIcon
import javax.inject.Inject

Expand All @@ -31,12 +33,14 @@ class NotificationActivitySwitchInteractorImpl @Inject constructor(
private val recordTypeInteractor: RecordTypeInteractor,
private val recordTypeGoalInteractor: RecordTypeGoalInteractor,
private val runningRecordInteractor: RunningRecordInteractor,
private val recordTagInteractor: RecordTagInteractor,
private val getCurrentRecordsDurationInteractor: GetCurrentRecordsDurationInteractor,
private val timeMapper: TimeMapper,
private val filterGoalsByDayOfWeekInteractor: FilterGoalsByDayOfWeekInteractor,
private val getSelectableTagsInteractor: GetSelectableTagsInteractor,
private val getNotificationActivitySwitchControlsInteractor: GetNotificationActivitySwitchControlsInteractor,
private val recordInteractor: RecordInteractor,
private val notificationCommonMapper: NotificationCommonMapper,
) : NotificationActivitySwitchInteractor {

override suspend fun updateNotification(
Expand Down Expand Up @@ -82,6 +86,7 @@ class NotificationActivitySwitchInteractorImpl @Inject constructor(
emptyList()
}
val recordTypes = recordTypeInteractor.getAll().associateBy(RecordType::id)
val recordTags = recordTagInteractor.getAll()
val prevRecord = if (retroactiveTrackingModeEnabled) {
// TODO several previous?
recordInteractor.getAllPrev(timeStarted = System.currentTimeMillis())
Expand Down Expand Up @@ -128,9 +133,12 @@ class NotificationActivitySwitchInteractorImpl @Inject constructor(
hint = resourceRepo.getString(R.string.retroactive_tracking_mode_hint)
icon = prevRecordType.icon.let(iconMapper::mapIcon)
color = colorMapper.mapToColorInt(prevRecordType.color, isDarkTheme)
title = resourceRepo.getString(R.string.statistics_detail_last_record) +
" - " +
prevRecordType.name
val namePrefix = resourceRepo.getString(R.string.statistics_detail_last_record)
val fullName = notificationCommonMapper.getNotificationText(
recordType = prevRecordType,
recordTags = recordTags.filter { it.id in prevRecord.tagIds },
)
title = "$namePrefix - $fullName"
subtitle = timeMapper.formatTime(
time = prevRecord.timeEnded,
useMilitaryTime = prefsInteractor.getUseMilitaryTimeFormat(),
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
package com.example.util.simpletimetracker.feature_notification.core

import com.example.util.simpletimetracker.domain.extension.getFullName
import com.example.util.simpletimetracker.domain.model.RecordTag
import com.example.util.simpletimetracker.domain.model.RecordType
import javax.inject.Inject

class NotificationCommonMapper @Inject constructor() {

fun getNotificationText(
recordType: RecordType,
recordTags: List<RecordTag>,
): String {
val tag = recordTags.getFullName()

return if (tag.isEmpty()) {
recordType.name
} else {
"${recordType.name} - $tag"
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ import com.example.util.simpletimetracker.core.mapper.IconMapper
import com.example.util.simpletimetracker.core.mapper.TimeMapper
import com.example.util.simpletimetracker.core.repo.ResourceRepo
import com.example.util.simpletimetracker.domain.extension.getDailyDuration
import com.example.util.simpletimetracker.domain.extension.getFullName
import com.example.util.simpletimetracker.domain.extension.getSessionDuration
import com.example.util.simpletimetracker.domain.extension.hasDailyDuration
import com.example.util.simpletimetracker.domain.extension.value
Expand All @@ -26,6 +25,7 @@ import com.example.util.simpletimetracker.domain.model.RunningRecord
import com.example.util.simpletimetracker.feature_notification.R
import com.example.util.simpletimetracker.feature_notification.activitySwitch.interactor.GetNotificationActivitySwitchControlsInteractor
import com.example.util.simpletimetracker.feature_notification.activitySwitch.manager.NotificationControlsParams
import com.example.util.simpletimetracker.feature_notification.core.NotificationCommonMapper
import com.example.util.simpletimetracker.feature_notification.recordType.manager.NotificationTypeManager
import com.example.util.simpletimetracker.feature_notification.recordType.manager.NotificationTypeParams
import javax.inject.Inject
Expand All @@ -45,6 +45,7 @@ class NotificationTypeInteractorImpl @Inject constructor(
private val filterGoalsByDayOfWeekInteractor: FilterGoalsByDayOfWeekInteractor,
private val getSelectableTagsInteractor: GetSelectableTagsInteractor,
private val getNotificationActivitySwitchControlsInteractor: GetNotificationActivitySwitchControlsInteractor,
private val notificationCommonMapper: NotificationCommonMapper,
) : NotificationTypeInteractor {

// TODO merge with update function?
Expand Down Expand Up @@ -226,7 +227,10 @@ class NotificationTypeInteractorImpl @Inject constructor(
id = recordType.id,
icon = recordType.icon.let(iconMapper::mapIcon),
color = colorMapper.mapToColorInt(recordType.color, isDarkTheme),
text = getNotificationText(recordType, recordTags),
text = notificationCommonMapper.getNotificationText(
recordType = recordType,
recordTags = recordTags,
),
timeStarted = timeMapper.formatTime(
time = runningRecord.timeStarted,
useMilitaryTime = useMilitaryTime,
Expand All @@ -246,19 +250,6 @@ class NotificationTypeInteractorImpl @Inject constructor(
).let(notificationTypeManager::show)
}

private fun getNotificationText(
recordType: RecordType,
recordTags: List<RecordTag>,
): String {
val tag = recordTags.getFullName()

return if (tag.isEmpty()) {
recordType.name
} else {
"${recordType.name} - $tag"
}
}

private fun hide(typeId: Long) {
notificationTypeManager.hide(typeId.toInt())
}
Expand Down

0 comments on commit fb0b989

Please sign in to comment.