Skip to content

Commit

Permalink
add retroactive tracking mode support to wear
Browse files Browse the repository at this point in the history
  • Loading branch information
Razeeman committed Oct 26, 2024
1 parent 4626c4a commit 111af50
Show file tree
Hide file tree
Showing 59 changed files with 842 additions and 144 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@ class PrefsRepoImpl @Inject constructor(
)

override var retroactiveTrackingMode: Boolean by prefs.delegate(
KEY_RETROACTIVE_TRACKING_MODE, false
KEY_RETROACTIVE_TRACKING_MODE, false,
)

override var firstDayOfWeek: Int by prefs.delegate(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ class RecordRepoImpl @Inject constructor(
logMessage = "get",
accessCache = { recordCache[id] },
accessSource = { recordDao.get(id)?.let(::mapItem) },
afterSourceAccess = { it?.let { recordCache.put(id, it) } }
afterSourceAccess = { it?.let { recordCache.put(id, it) } },
)

override suspend fun getFromRange(range: Range): List<Record> {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ class RunningRecordRepoImpl @Inject constructor(
logMessage = "has",
accessCache = { cache?.any { it.id == id } },
accessSource = { dao.get(id) != null },
afterSourceAccess = { initializeCache() }
afterSourceAccess = { initializeCache() },
)

override suspend fun add(runningRecord: RunningRecord): Long = mutex.withLockedCache(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ class RemoveRunningRecordMediator @Inject constructor(
// No need to update widgets and notification because it will be done in running record remove.
recordInteractor.addFromRunning(
runningRecord = runningRecord,
timeEnded = recordTimeEnded
timeEnded = recordTimeEnded,
)
}
activityStartedStoppedBroadcastInteractor.onActivityStopped(
Expand All @@ -53,7 +53,7 @@ class RemoveRunningRecordMediator @Inject constructor(
updateExternalViewsInteractor.onRunningRecordRemove(
typeId = typeId,
updateWidgets = updateWidgets,
updateNotificationSwitch = updateNotificationSwitch
updateNotificationSwitch = updateNotificationSwitch,
)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ class ShouldShowRecordDataSelectionInteractor @Inject constructor(
if (needToShowComment(typeId, commentInputAvailable)) {
fields += RecordDataSelectionDialogResult.Field.Comment
}
return RecordDataSelectionDialogResult(fields)
return RecordDataSelectionDialogResult(fields)
}

private suspend fun needToShowTags(typeId: Long): Boolean {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ class UpdateExternalViewsInteractor @Inject constructor(
Update.WidgetSingleTypes.takeIf { getRetroactiveTrackingMode() }
?: Update.WidgetSingleType(typeId),
Update.WidgetUniversal.takeIf { getRetroactiveTrackingMode() },
Update.Wear.takeIf { !fromArchive },
Update.Wear.takeIf { !fromArchive || getRetroactiveTrackingMode() },
Update.NotificationTypes.takeIf { !fromArchive },
Update.NotificationWithControls.takeIf { !fromArchive },
)
Expand Down Expand Up @@ -139,6 +139,7 @@ class UpdateExternalViewsInteractor @Inject constructor(
Update.WidgetSingleTypes.takeIf { getRetroactiveTrackingMode() }
?: Update.WidgetSingleType(typeId),
Update.WidgetUniversal.takeIf { getRetroactiveTrackingMode() },
Update.Wear.takeIf { getRetroactiveTrackingMode() },
)
}

Expand All @@ -154,6 +155,7 @@ class UpdateExternalViewsInteractor @Inject constructor(
Update.WidgetSingleTypes.takeIf { getRetroactiveTrackingMode() }
?: Update.WidgetSingleType(typeId),
Update.WidgetUniversal.takeIf { getRetroactiveTrackingMode() },
Update.Wear.takeIf { getRetroactiveTrackingMode() },
)
}

Expand Down Expand Up @@ -320,7 +322,7 @@ class UpdateExternalViewsInteractor @Inject constructor(
Update.WidgetSingleTypes,
Update.WidgetUniversal,
Update.NotificationWithControls,
Update.Wear
Update.Wear,
)
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,11 @@ import androidx.lifecycle.ViewModel
import androidx.lifecycle.viewModelScope
import com.example.util.simpletimetracker.core.extension.set
import com.example.util.simpletimetracker.core.repo.ResourceRepo
import com.example.util.simpletimetracker.domain.interactor.NotificationActivitySwitchInteractor
import com.example.util.simpletimetracker.domain.interactor.NotificationTypeInteractor
import com.example.util.simpletimetracker.domain.interactor.RecordTagInteractor
import com.example.util.simpletimetracker.domain.interactor.RecordTypeInteractor
import com.example.util.simpletimetracker.domain.interactor.RemoveRecordTagMediator
import com.example.util.simpletimetracker.domain.interactor.RemoveRecordTypeMediator
import com.example.util.simpletimetracker.domain.interactor.UpdateExternalViewsInteractor
import com.example.util.simpletimetracker.domain.interactor.WearInteractor
import com.example.util.simpletimetracker.feature_archive.R
import com.example.util.simpletimetracker.feature_archive.interactor.ArchiveViewDataInteractor
import com.example.util.simpletimetracker.feature_archive.viewData.ArchiveViewData
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ class ChangeRecordCore(
),
createChangeRecordTimeAdjustmentAdapterDelegate(viewModel::onTimeAdjustmentClick),
createChangeRecordButtonAdapterDelegate(viewModel::onItemButtonClick),
createChangeRecordSliderAdapterDelegate(viewModel::onSliderValueChanged)
createChangeRecordSliderAdapterDelegate(viewModel::onSliderValueChanged),
)
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ class ChangeRecordActionsRepeatDelegate @Inject constructor(
comment = params.newComment,
tagIds = params.newCategoryIds,
)
}
},
)
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ import com.example.util.simpletimetracker.core.repo.ResourceRepo
import com.example.util.simpletimetracker.domain.interactor.PrefsInteractor
import com.example.util.simpletimetracker.domain.interactor.RecordTypeInteractor
import com.example.util.simpletimetracker.domain.interactor.UpdateExternalViewsInteractor
import com.example.util.simpletimetracker.domain.interactor.WearInteractor
import com.example.util.simpletimetracker.domain.model.CardOrder
import com.example.util.simpletimetracker.domain.model.RecordType
import com.example.util.simpletimetracker.feature_base_adapter.ViewHolderType
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,8 +52,7 @@ class RunningRecordsViewDataMapper @Inject constructor(
)
}

// TODO RETRO check first enter, main, widgets, notifs, wear.
// TODO RETRO add hint about how it works and limitations.
// TODO add hint about how it works and limitations?
fun mapToRetroActiveMode(
typesMap: Map<Long, RecordType>,
recordTags: List<RecordTag>,
Expand All @@ -72,8 +71,8 @@ class RunningRecordsViewDataMapper @Inject constructor(
)
}

val type = prevRecord?.typeId?.let(typesMap::get)
if (prevRecord != null && type != null) {
val prevRecordType = prevRecord?.typeId?.let(typesMap::get)
if (prevRecord != null && prevRecordType != null) {
result += runningRecordViewDataMapper.map(
runningRecord = RunningRecord(
id = UNTRACKED_ITEM_ID,
Expand Down Expand Up @@ -103,7 +102,7 @@ class RunningRecordsViewDataMapper @Inject constructor(
)
result += recordViewDataMapper.map(
record = prevRecord,
recordType = type,
recordType = prevRecordType,
recordTags = recordTags.filter { it.id in prevRecord.tagIds },
isDarkTheme = isDarkTheme,
useMilitaryTime = useMilitaryTime,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,10 @@ import com.example.util.simpletimetracker.core.base.SingleLiveEvent
import com.example.util.simpletimetracker.core.base.ViewModelDelegate
import com.example.util.simpletimetracker.core.extension.set
import com.example.util.simpletimetracker.core.interactor.LanguageInteractor
import com.example.util.simpletimetracker.feature_settings.api.SettingsBlock
import com.example.util.simpletimetracker.domain.interactor.PrefsInteractor
import com.example.util.simpletimetracker.domain.interactor.UpdateExternalViewsInteractor
import com.example.util.simpletimetracker.domain.interactor.WidgetInteractor
import com.example.util.simpletimetracker.domain.model.WidgetType
import com.example.util.simpletimetracker.feature_base_adapter.ViewHolderType
import com.example.util.simpletimetracker.feature_settings.api.SettingsBlock
import com.example.util.simpletimetracker.feature_settings.interactor.SettingsMainViewDataInteractor
import com.example.util.simpletimetracker.feature_settings.mapper.SettingsMapper
import com.example.util.simpletimetracker.navigation.Router
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,16 @@ package com.example.util.simpletimetracker.feature_wear

import com.example.util.simpletimetracker.core.interactor.RecordRepeatInteractor
import com.example.util.simpletimetracker.core.mapper.RecordTagViewDataMapper
import com.example.util.simpletimetracker.domain.extension.orZero
import com.example.util.simpletimetracker.domain.mapper.AppColorMapper
import com.example.util.simpletimetracker.domain.model.AppColor
import com.example.util.simpletimetracker.domain.model.Record
import com.example.util.simpletimetracker.domain.model.RecordTag
import com.example.util.simpletimetracker.domain.model.RecordType
import com.example.util.simpletimetracker.domain.model.RunningRecord
import com.example.util.simpletimetracker.wear_api.WearActivityDTO
import com.example.util.simpletimetracker.wear_api.WearCurrentActivityDTO
import com.example.util.simpletimetracker.wear_api.WearLastRecordDTO
import com.example.util.simpletimetracker.wear_api.WearRecordRepeatResponse
import com.example.util.simpletimetracker.wear_api.WearSettingsDTO
import com.example.util.simpletimetracker.wear_api.WearTagDTO
Expand Down Expand Up @@ -46,6 +49,19 @@ class WearDataLocalMapper @Inject constructor(
)
}

fun map(
record: Record?,
tags: List<WearTagDTO>,
): WearLastRecordDTO {
return WearLastRecordDTO(
isPresent = record != null,
activityId = record?.typeId.orZero(),
startedAt = record?.timeStarted.orZero(),
finishedAt = record?.timeEnded.orZero(),
tags = tags,
)
}

fun map(
recordTag: RecordTag,
types: Map<Long, RecordType>,
Expand All @@ -64,11 +80,13 @@ class WearDataLocalMapper @Inject constructor(
allowMultitasking: Boolean,
recordTagSelectionCloseAfterOne: Boolean,
enableRepeatButton: Boolean,
retroactiveTrackingMode: Boolean,
): WearSettingsDTO {
return WearSettingsDTO(
allowMultitasking = allowMultitasking,
recordTagSelectionCloseAfterOne = recordTagSelectionCloseAfterOne,
enableRepeatButton = enableRepeatButton,
retroactiveTrackingMode = retroactiveTrackingMode,
)
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import com.example.util.simpletimetracker.core.interactor.RecordRepeatInteractor
import com.example.util.simpletimetracker.domain.interactor.AddRunningRecordMediator
import com.example.util.simpletimetracker.domain.interactor.GetSelectableTagsInteractor
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.RecordTypeInteractor
import com.example.util.simpletimetracker.domain.interactor.RemoveRunningRecordMediator
Expand All @@ -21,7 +22,7 @@ import com.example.util.simpletimetracker.domain.model.WidgetType
import com.example.util.simpletimetracker.navigation.Router
import com.example.util.simpletimetracker.wear_api.WearActivityDTO
import com.example.util.simpletimetracker.wear_api.WearCommunicationAPI
import com.example.util.simpletimetracker.wear_api.WearCurrentActivityDTO
import com.example.util.simpletimetracker.wear_api.WearCurrentStateDTO
import com.example.util.simpletimetracker.wear_api.WearRecordRepeatResponse
import com.example.util.simpletimetracker.wear_api.WearSettingsDTO
import com.example.util.simpletimetracker.wear_api.WearShouldShowTagSelectionRequest
Expand All @@ -38,6 +39,7 @@ class WearDataRepo @Inject constructor(
private val recordTagInteractor: RecordTagInteractor,
private val getSelectableTagsInteractor: GetSelectableTagsInteractor,
private val runningRecordInteractor: RunningRecordInteractor,
private val recordInteractor: RecordInteractor,
private val shouldShowRecordDataSelectionInteractor: ShouldShowRecordDataSelectionInteractor,
private val removeRunningRecordMediator: Lazy<RemoveRunningRecordMediator>,
private val addRunningRecordMediator: Lazy<AddRunningRecordMediator>,
Expand All @@ -54,18 +56,31 @@ class WearDataRepo @Inject constructor(
.map(wearDataLocalMapper::map)
}

override suspend fun queryCurrentActivities(): List<WearCurrentActivityDTO> {
return runningRecordInteractor.getAll().map { record ->
val tags = record.tagIds.mapNotNull { tagId ->
override suspend fun queryCurrentActivities(): WearCurrentStateDTO {
suspend fun mapTags(tagIds: List<Long>): List<WearTagDTO> {
return tagIds.mapNotNull { tagId ->
recordTagInteractor.get(tagId)?.let {
wearDataLocalMapper.map(
recordTag = it,
types = emptyMap(), // Color is not needed.
)
}
}
wearDataLocalMapper.map(record, tags)
}

val runningRecords = runningRecordInteractor.getAll().map { record ->
wearDataLocalMapper.map(record, mapTags(record.tagIds))
}
val prevRecord = recordInteractor
.getPrev(timeStarted = System.currentTimeMillis())
.firstOrNull()
.let { record ->
wearDataLocalMapper.map(record, mapTags(record?.tagIds.orEmpty()))
}
return WearCurrentStateDTO(
currentActivities = runningRecords,
lastRecord = prevRecord,
)
}

override suspend fun startActivity(request: WearStartActivityRequest) {
Expand Down Expand Up @@ -115,6 +130,7 @@ class WearDataRepo @Inject constructor(
allowMultitasking = prefsInteractor.getAllowMultitasking(),
recordTagSelectionCloseAfterOne = prefsInteractor.getRecordTagSelectionCloseAfterOne(),
enableRepeatButton = prefsInteractor.getEnableRepeatButton(),
retroactiveTrackingMode = prefsInteractor.getRetroactiveTrackingMode(),
)
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ import javax.inject.Singleton
*/
@Singleton
class WidgetViewsHolder @Inject constructor(
@ApplicationContext private val context: Context
@ApplicationContext private val context: Context,
) {

private var recordTypeView: RecordTypeView? = null
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ class WidgetStatisticsChartProvider : AppWidgetProvider() {

@OptIn(DelicateCoroutinesApi::class)
override fun onDeleted(context: Context?, appWidgetIds: IntArray?) {
GlobalScope.launch( allowDiskRead { Dispatchers.Main }) {
GlobalScope.launch(allowDiskRead { Dispatchers.Main }) {
appWidgetIds?.forEach { prefsInteractor.removeStatisticsWidget(it) }
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ import com.example.util.simpletimetracker.core.interactor.FilterGoalsByDayOfWeek
import com.example.util.simpletimetracker.core.interactor.GetCurrentRecordsDurationInteractor
import com.example.util.simpletimetracker.core.interactor.RecordRepeatInteractor
import com.example.util.simpletimetracker.core.mapper.RecordTypeViewDataMapper
import com.example.util.simpletimetracker.core.repo.ResourceRepo
import com.example.util.simpletimetracker.domain.extension.orZero
import com.example.util.simpletimetracker.domain.interactor.AddRunningRecordMediator
import com.example.util.simpletimetracker.domain.interactor.ChangeSelectedActivityFilterMediator
Expand All @@ -29,7 +28,6 @@ import com.example.util.simpletimetracker.feature_base_adapter.divider.DividerVi
import com.example.util.simpletimetracker.feature_base_adapter.loader.LoaderViewData
import com.example.util.simpletimetracker.feature_base_adapter.recordType.RecordTypeViewData
import com.example.util.simpletimetracker.feature_base_adapter.recordTypeSpecial.RunningRecordTypeSpecialViewData
import com.example.util.simpletimetracker.feature_widget.R
import com.example.util.simpletimetracker.feature_widget.universal.mapper.WidgetUniversalViewDataMapper
import com.example.util.simpletimetracker.navigation.Router
import com.example.util.simpletimetracker.navigation.params.screen.RecordTagSelectionParams
Expand All @@ -42,7 +40,6 @@ import javax.inject.Inject
@HiltViewModel
class WidgetUniversalViewModel @Inject constructor(
private val router: Router,
private val resourceRepo: ResourceRepo,
private val addRunningRecordMediator: AddRunningRecordMediator,
private val removeRunningRecordMediator: RemoveRunningRecordMediator,
private val recordTypeInteractor: RecordTypeInteractor,
Expand Down
6 changes: 6 additions & 0 deletions resources/src/main/res/values-ar/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -297,6 +297,8 @@
<string name="settings_show_notification_with_switch_hide">إخفاء وقت ظهور إشعار المؤقت</string>
<string name="settings_keep_statistics_range">حافظ على نطاق الإحصائيات</string>
<string name="settings_keep_statistics_range_hint">في حال التفعيل، ستفتح الإحصائيات التفصيلية بنفس النطاق الزمني المحدد في الإحصائيات.</string>
<string name="settings_retroactive_tracking_mode">تمكين تتبع الوقت بأثر رجعي</string>
<string name="settings_retroactive_tracking_mode_hint">تتبع الوقت عن طريق تحديد النشاط الذي تم القيام به منذ المرة الأخيرة بدلاً من تحديد النشاط الذي سيتم القيام به من الآن.</string>
<string name="settings_start_of_day">توقيت بداية اليوم</string>
<string name="settings_start_of_day_hint">سيتم تحويل بداية اليوم بمقدار الوقت المحدد ، للأمام أو للخلف حسب العلامة.</string>
<string name="settings_start_of_day_hint_value">يبدأ اليوم في %s</string>
Expand Down Expand Up @@ -504,6 +506,7 @@
<string name="notification_activity_text">هل مازلت تنشط: %s?</string>
<string name="notification_goal_time_description">تم الوصول للهدف</string>
<string name="notification_time_started">بُدء في %s</string>
<string name="notification_time_ended">انتهى عند %s</string>
<string name="notification_record_type_stop">أوقف</string>
<string name="notification_pomodoro_subtitle">البدء: %s (%s)</string>

Expand Down Expand Up @@ -553,6 +556,9 @@
<string name="pomodoro_state_long_break">استراحة طويلة</string>
<string name="pomodoro_settings_periods_until_long_break">الفترات حتى الفاصل الطويل</string>

<!-- Retroactive tracking mode -->
<string name="retroactive_tracking_mode_hint">حدد ما كنت تفعله</string>

<!-- Icon emoji category -->
<string name="emojiGroupSmileys">ابتسامات &amp; مشاعر</string>
<string name="emojiGroupPeople">الناس &amp; الجسد</string>
Expand Down
Loading

0 comments on commit 111af50

Please sign in to comment.