@@ -12,8 +12,7 @@ import com.example.util.simpletimetracker.domain.recordType.model.RecordType
1212import com.example.util.simpletimetracker.domain.statistics.model.RangeLength
1313import com.example.util.simpletimetracker.feature_statistics_detail.R
1414import com.example.util.simpletimetracker.feature_statistics_detail.viewData.StatisticsDetailCardInternalViewData
15- import com.example.util.simpletimetracker.feature_statistics_detail.viewData.StatisticsDetailClickableLongest
16- import com.example.util.simpletimetracker.feature_statistics_detail.viewData.StatisticsDetailClickableShortest
15+ import com.example.util.simpletimetracker.feature_statistics_detail.viewData.StatisticsDetailClickablePopup
1716import com.example.util.simpletimetracker.feature_statistics_detail.viewData.StatisticsDetailClickableTracked
1817import com.example.util.simpletimetracker.feature_statistics_detail.viewData.StatisticsDetailStatsViewData
1918import kotlinx.coroutines.Dispatchers
@@ -81,16 +80,18 @@ class StatisticsDetailStatsInteractor @Inject constructor(
8180 timesTrackedIcon = null ,
8281 shortestRecord = " " ,
8382 compareShortestRecord = " " ,
84- shortestRecordDate = " " ,
83+ shortestRecordDate = null ,
8584 averageRecord = " " ,
8685 compareAverageRecord = " " ,
8786 longestRecord = " " ,
8887 compareLongestRecord = " " ,
89- longestRecordDate = " " ,
88+ longestRecordDate = null ,
9089 firstRecord = " " ,
9190 compareFirstRecord = " " ,
9291 lastRecord = " " ,
9392 compareLastRecord = " " ,
93+ firstRecordClickMessage = null ,
94+ lastRecordClickMessage = null ,
9495 )
9596 }
9697
@@ -114,6 +115,9 @@ class StatisticsDetailStatsInteractor @Inject constructor(
114115 val shortestRecord = records.minByOrNull(RecordBase ::duration)
115116 val longestRecord = records.maxByOrNull(RecordBase ::duration)
116117
118+ val firstRecordData = recordsSorted.firstOrNull()?.timeStarted
119+ val lastRecordData = recordsSorted.lastOrNull()?.timeEnded
120+
117121 val emptyValue by lazy {
118122 resourceRepo.getString(R .string.statistics_detail_empty)
119123 }
@@ -151,9 +155,7 @@ class StatisticsDetailStatsInteractor @Inject constructor(
151155 .orEmpty()
152156 }
153157
154- fun processLengthHint (value : RecordBase ? ): String {
155- value ? : return emptyValue
156-
158+ fun processLengthHint (value : RecordBase ): String {
157159 val result = StringBuilder ()
158160 value.typeIds
159161 .mapNotNull(typesMap::get)
@@ -171,6 +173,30 @@ class StatisticsDetailStatsInteractor @Inject constructor(
171173 return result.toString()
172174 }
173175
176+ fun getTimeSinceMessage (timestamp : Long ): String {
177+ val result = StringBuilder ()
178+ result.append(resourceRepo.getString(R .string.statistics_detail_time_since))
179+ result.append(" \n " )
180+ val interval = System .currentTimeMillis() - timestamp
181+ val timeSince = timeMapper.formatInterval(
182+ interval = interval,
183+ forceSeconds = showSeconds,
184+ durationFormat = durationFormat,
185+ )
186+ val timeSinceInDays = timeMapper.formatInterval(
187+ interval = interval,
188+ forceSeconds = showSeconds,
189+ durationFormat = DurationFormat .DAYS ,
190+ )
191+ result.append(timeSince)
192+ if (timeSince != timeSinceInDays) {
193+ result.append(" \n " )
194+ result.append(" ($timeSinceInDays )" )
195+ }
196+
197+ return result.toString()
198+ }
199+
174200 return mapToStatsViewData(
175201 totalDuration = durations.sum()
176202 .let (::formatInterval),
@@ -187,7 +213,7 @@ class StatisticsDetailStatsInteractor @Inject constructor(
187213 .let (::formatInterval)
188214 .let (::processComparisonString),
189215 shortestRecordDate = shortestRecord
190- .let (::processLengthHint),
216+ ? .let (::processLengthHint),
191217 averageRecord = getAverage(durations)
192218 .let (::formatInterval),
193219 compareAverageRecord = getAverage(compareDurations)
@@ -199,17 +225,21 @@ class StatisticsDetailStatsInteractor @Inject constructor(
199225 .let (::formatInterval)
200226 .let (::processComparisonString),
201227 longestRecordDate = longestRecord
202- .let (::processLengthHint),
203- firstRecord = recordsSorted.firstOrNull()?.timeStarted
228+ ? .let (::processLengthHint),
229+ firstRecord = firstRecordData
204230 .let (::formatDateTimeYear),
205231 compareFirstRecord = compareRecordsSorted.firstOrNull()?.timeStarted
206232 .let (::formatDateTimeYear)
207233 .let (::processComparisonString),
208- lastRecord = recordsSorted.lastOrNull()?.timeEnded
234+ lastRecord = lastRecordData
209235 .let (::formatDateTimeYear),
210236 compareLastRecord = compareRecordsSorted.lastOrNull()?.timeEnded
211237 .let (::formatDateTimeYear)
212238 .let (::processComparisonString),
239+ firstRecordClickMessage = firstRecordData
240+ ?.let (::getTimeSinceMessage),
241+ lastRecordClickMessage = lastRecordData
242+ ?.let (::getTimeSinceMessage),
213243 )
214244 }
215245
@@ -221,16 +251,18 @@ class StatisticsDetailStatsInteractor @Inject constructor(
221251 timesTrackedIcon : StatisticsDetailCardInternalViewData .Icon ? ,
222252 shortestRecord : String ,
223253 compareShortestRecord : String ,
224- shortestRecordDate : String ,
254+ shortestRecordDate : String? ,
225255 averageRecord : String ,
226256 compareAverageRecord : String ,
227257 longestRecord : String ,
228258 compareLongestRecord : String ,
229- longestRecordDate : String ,
259+ longestRecordDate : String? ,
230260 firstRecord : String ,
231261 compareFirstRecord : String ,
232262 lastRecord : String ,
233263 compareLastRecord : String ,
264+ firstRecordClickMessage : String? ,
265+ lastRecordClickMessage : String? ,
234266 ): StatisticsDetailStatsViewData {
235267 return StatisticsDetailStatsViewData (
236268 totalDuration = listOf (
@@ -263,7 +295,7 @@ class StatisticsDetailStatsInteractor @Inject constructor(
263295 valueChange = StatisticsDetailCardInternalViewData .ValueChange .None ,
264296 secondValue = compareShortestRecord,
265297 description = resourceRepo.getString(R .string.statistics_detail_shortest_record),
266- clickable = StatisticsDetailClickableShortest ( shortestRecordDate) ,
298+ clickable = shortestRecordDate?. let { StatisticsDetailClickablePopup (it) } ,
267299 ),
268300 StatisticsDetailCardInternalViewData (
269301 value = averageRecord,
@@ -276,7 +308,7 @@ class StatisticsDetailStatsInteractor @Inject constructor(
276308 valueChange = StatisticsDetailCardInternalViewData .ValueChange .None ,
277309 secondValue = compareLongestRecord,
278310 description = resourceRepo.getString(R .string.statistics_detail_longest_record),
279- clickable = StatisticsDetailClickableLongest ( longestRecordDate) ,
311+ clickable = longestRecordDate?. let { StatisticsDetailClickablePopup (it) } ,
280312 ),
281313 ),
282314 datesTracked = listOf (
@@ -285,12 +317,14 @@ class StatisticsDetailStatsInteractor @Inject constructor(
285317 valueChange = StatisticsDetailCardInternalViewData .ValueChange .None ,
286318 secondValue = compareFirstRecord,
287319 description = resourceRepo.getString(R .string.statistics_detail_first_record),
320+ clickable = firstRecordClickMessage?.let { StatisticsDetailClickablePopup (it) },
288321 ),
289322 StatisticsDetailCardInternalViewData (
290323 value = lastRecord,
291324 valueChange = StatisticsDetailCardInternalViewData .ValueChange .None ,
292325 secondValue = compareLastRecord,
293326 description = resourceRepo.getString(R .string.statistics_detail_last_record),
327+ clickable = lastRecordClickMessage?.let { StatisticsDetailClickablePopup (it) },
294328 ),
295329 ),
296330 )
0 commit comments