@@ -2,7 +2,10 @@ package com.example.util.simpletimetracker.feature_dialogs.recordQuickActions.in
22
33import android.text.SpannableStringBuilder
44import androidx.core.text.bold
5+ import com.example.util.simpletimetracker.core.extension.toViewData
56import com.example.util.simpletimetracker.core.mapper.RecordQuickActionMapper
7+ import com.example.util.simpletimetracker.core.mapper.RecordViewDataMapper
8+ import com.example.util.simpletimetracker.core.mapper.TimeMapper
69import com.example.util.simpletimetracker.core.repo.ResourceRepo
710import com.example.util.simpletimetracker.domain.prefs.interactor.PrefsInteractor
811import com.example.util.simpletimetracker.domain.record.interactor.RecordInteractor
@@ -25,7 +28,9 @@ import com.example.util.simpletimetracker.navigation.params.screen.RecordQuickAc
2528import javax.inject.Inject
2629
2730class RecordQuickActionsViewDataInteractor @Inject constructor(
31+ private val timeMapper : TimeMapper ,
2832 private val resourceRepo : ResourceRepo ,
33+ private val recordViewDataMapper : RecordViewDataMapper ,
2934 private val prefsInteractor : PrefsInteractor ,
3035 private val recordInteractor : RecordInteractor ,
3136 private val runningRecordInteractor : RunningRecordInteractor ,
@@ -41,7 +46,6 @@ class RecordQuickActionsViewDataInteractor @Inject constructor(
4146 is Type .RecordTracked -> recordInteractor.get(params.id)
4247 is Type .RecordUntracked -> null
4348 is Type .RecordRunning -> runningRecordInteractor.get(params.id)
44- null -> null
4549 }
4650 }
4751
@@ -80,6 +84,9 @@ class RecordQuickActionsViewDataInteractor @Inject constructor(
8084 extra : RecordQuickActionsParams ,
8185 ): RecordQuickActionsState {
8286 val isDarkTheme = prefsInteractor.getDarkMode()
87+ val useMilitaryTime = prefsInteractor.getUseMilitaryTimeFormat()
88+ val showSeconds = prefsInteractor.getShowSeconds()
89+ val useProportionalMinutes = prefsInteractor.getUseProportionalMinutes()
8390 val retroactiveTrackingModeEnabled = prefsInteractor.getRetroactiveTrackingMode()
8491 val multiSelectEnabled = recordsContainerMultiselectInteractor.isEnabled
8592 val canContinue = ! retroactiveTrackingModeEnabled
@@ -106,16 +113,22 @@ class RecordQuickActionsViewDataInteractor @Inject constructor(
106113 val buttons = getAllButtons(
107114 allowedButtons = allowedButtons,
108115 ).let (::applyWidth)
109- val hintData = mapHint (
116+ val helpData = mapHelpData (
110117 allowedButtons = allowedButtons,
111118 isDarkTheme = isDarkTheme,
112119 )
113- val multiSelectHint = mapMultiSelectHint()
120+ val hintData = mapHintData(
121+ extra = extra,
122+ record = getRecord(extra),
123+ useMilitaryTime = useMilitaryTime,
124+ showSeconds = showSeconds,
125+ useProportionalMinutes = useProportionalMinutes,
126+ )
114127
115128 return RecordQuickActionsState (
116129 buttons = buttons,
130+ helpData = helpData,
117131 hintData = hintData,
118- multiSelectHint = multiSelectHint,
119132 )
120133 }
121134
@@ -219,7 +232,6 @@ class RecordQuickActionsViewDataInteractor @Inject constructor(
219232 RecordQuickActionsButton .CHANGE_ACTIVITY ,
220233 RecordQuickActionsButton .CHANGE_TAG .takeIf { hasTags },
221234 )
222- null -> emptyList()
223235 }
224236 }
225237
@@ -268,7 +280,7 @@ class RecordQuickActionsViewDataInteractor @Inject constructor(
268280 }
269281 }
270282
271- private fun mapHint (
283+ private fun mapHelpData (
272284 allowedButtons : List <RecordQuickActionsButton >,
273285 isDarkTheme : Boolean ,
274286 ): CharSequence {
@@ -306,25 +318,111 @@ class RecordQuickActionsViewDataInteractor @Inject constructor(
306318 return builder
307319 }
308320
309- private fun mapMultiSelectHint (): String {
321+ private fun mapHintData (
322+ extra : RecordQuickActionsParams ,
323+ record : RecordBase ? ,
324+ useMilitaryTime : Boolean ,
325+ showSeconds : Boolean ,
326+ useProportionalMinutes : Boolean ,
327+ ): RecordQuickActionsState .Hint ? {
310328 return if (recordsContainerMultiselectInteractor.isEnabled) {
311- // Ex. "Selected: 5 Records"
312- val recordsSelectedCount = recordsContainerMultiselectInteractor.selectedRecordIds.size
313- val recordsSelectedString = resourceRepo.getString(
314- R .string.separator_template,
315- recordsSelectedCount,
316- resourceRepo.getQuantityString(
317- R .plurals.statistics_detail_times_tracked,
318- recordsSelectedCount,
329+ mapMultiSelectHint()
330+ } else {
331+ mapSelectedRecordHint(
332+ extra = extra,
333+ record = record,
334+ useMilitaryTime = useMilitaryTime,
335+ showSeconds = showSeconds,
336+ useProportionalMinutes = useProportionalMinutes,
337+ )
338+ }
339+ }
340+
341+ private fun mapSelectedRecordHint (
342+ extra : RecordQuickActionsParams ,
343+ record : RecordBase ? ,
344+ useMilitaryTime : Boolean ,
345+ showSeconds : Boolean ,
346+ useProportionalMinutes : Boolean ,
347+ ): RecordQuickActionsState .Hint .Record ? {
348+ fun formatRecordDuration (timeStarted : Long , timeEnded : Long ): String {
349+ return timeMapper.formatInterval(
350+ interval = recordViewDataMapper.mapDuration(
351+ timeStarted = timeStarted,
352+ timeEnded = timeEnded,
353+ showSeconds = showSeconds,
319354 ),
355+ forceSeconds = showSeconds,
356+ useProportionalMinutes = useProportionalMinutes,
320357 )
321- resourceRepo.getString(
322- R .string.separator_template,
323- resourceRepo.getString(R .string.something_selected),
324- recordsSelectedString,
358+ }
359+
360+ fun formatRunningDuration (timeStarted : Long ): String {
361+ return timeMapper.formatInterval(
362+ interval = System .currentTimeMillis() - timeStarted,
363+ forceSeconds = true ,
364+ useProportionalMinutes = false ,
325365 )
326- } else {
327- " "
328366 }
367+
368+ val timeStarted: Long
369+ val timeEnded: Long?
370+ val duration: String
371+
372+ when (val type = extra.type) {
373+ is Type .RecordTracked -> {
374+ timeStarted = record?.timeStarted ? : return null
375+ timeEnded = record.timeEnded
376+ duration = formatRecordDuration(timeStarted, timeEnded)
377+ }
378+ is Type .RecordUntracked -> {
379+ timeStarted = type.timeStarted
380+ timeEnded = type.timeEnded
381+ duration = formatRecordDuration(timeStarted, timeEnded)
382+ }
383+ is Type .RecordRunning -> {
384+ timeStarted = record?.timeStarted ? : return null
385+ timeEnded = null
386+ duration = formatRunningDuration(timeStarted)
387+ }
388+ }
389+
390+ return RecordQuickActionsState .Hint .Record (
391+ name = extra.preview.name,
392+ iconId = extra.preview.iconId.toViewData(),
393+ color = extra.preview.color,
394+ timeStarted = timeMapper.formatTime(
395+ time = timeStarted,
396+ useMilitaryTime = useMilitaryTime,
397+ showSeconds = showSeconds,
398+ ),
399+ timeEnded = timeEnded?.let {
400+ timeMapper.formatTime(
401+ time = it,
402+ useMilitaryTime = useMilitaryTime,
403+ showSeconds = showSeconds,
404+ )
405+ },
406+ duration = duration,
407+ )
408+ }
409+
410+ private fun mapMultiSelectHint (): RecordQuickActionsState .Hint .MultiSelect {
411+ // Ex. "Selected: 5 Records"
412+ val recordsSelectedCount = recordsContainerMultiselectInteractor.selectedRecordIds.size
413+ val recordsSelectedString = resourceRepo.getString(
414+ R .string.separator_template,
415+ recordsSelectedCount,
416+ resourceRepo.getQuantityString(
417+ R .plurals.statistics_detail_times_tracked,
418+ recordsSelectedCount,
419+ ),
420+ )
421+ val text = resourceRepo.getString(
422+ R .string.separator_template,
423+ resourceRepo.getString(R .string.something_selected),
424+ recordsSelectedString,
425+ )
426+ return RecordQuickActionsState .Hint .MultiSelect (text)
329427 }
330428}
0 commit comments