@@ -2,6 +2,7 @@ package com.sunnychung.application.multiplatform.hellohttp.ux
2
2
3
3
import androidx.compose.foundation.VerticalScrollbar
4
4
import androidx.compose.foundation.background
5
+ import androidx.compose.foundation.clickable
5
6
import androidx.compose.foundation.layout.Box
6
7
import androidx.compose.foundation.layout.Column
7
8
import androidx.compose.foundation.layout.ColumnScope
@@ -70,6 +71,8 @@ fun TransportTimelineView(modifier: Modifier = Modifier, protocol: ProtocolVersi
70
71
val density = LocalDensity .current
71
72
val clipboardManager = LocalClipboardManager .current
72
73
74
+ var isRelativeTimeDisplay by remember { mutableStateOf(false ) }
75
+
73
76
log.d { " TransportTimelineView recompose" }
74
77
75
78
val streamDigits = if (protocol?.isHttp2() == true ) {
@@ -205,12 +208,23 @@ fun TransportTimelineView(modifier: Modifier = Modifier, protocol: ProtocolVersi
205
208
// --- for copy button end
206
209
207
210
Column (modifier = modifier) {
208
- Box (modifier = Modifier .fillMaxWidth()) {
211
+ Row (verticalAlignment = Alignment .CenterVertically , modifier = Modifier .fillMaxWidth().padding(horizontal = 8 .dp)) {
212
+ AppCheckbox (
213
+ checked = isRelativeTimeDisplay,
214
+ onCheckedChange = { isRelativeTimeDisplay = it },
215
+ size = 24 .dp,
216
+ modifier = Modifier .padding(end = 4 .dp)
217
+ )
218
+ AppText (
219
+ text = " Relative Time Display" ,
220
+ modifier = Modifier .clickable { isRelativeTimeDisplay = ! isRelativeTimeDisplay },
221
+ )
222
+ Spacer (modifier = Modifier .weight(1f ))
209
223
AppTextButton (
210
224
text = " Copy All" ,
211
- modifier = Modifier .align( Alignment . CenterEnd ). padding(vertical = 4 .dp, horizontal = 8 .dp),
225
+ modifier = Modifier .padding(vertical = 4 .dp),
212
226
) {
213
- val textToCopy = response.describeTransportLayer()
227
+ val textToCopy = response.describeTransportLayer(isRelativeTimeDisplay = isRelativeTimeDisplay )
214
228
clipboardManager.setText(AnnotatedString (textToCopy))
215
229
AppContext .ErrorMessagePromptViewModel .showSuccessMessage(" Copied text" )
216
230
}
@@ -297,6 +311,7 @@ fun TransportTimelineView(modifier: Modifier = Modifier, protocol: ProtocolVersi
297
311
numCharsInALine = numCharsInALine,
298
312
protocol = protocol,
299
313
streamDigits = streamDigits,
314
+ isRelativeTimeDisplay = isRelativeTimeDisplay,
300
315
onMeasureContentWidth = { contentWidthInPx = it },
301
316
onMeasureContentLines = { totalNumLines = it.totalNumLines },
302
317
onPrepareComposable = {},
@@ -328,6 +343,7 @@ fun TransportTimelineView(modifier: Modifier = Modifier, protocol: ProtocolVersi
328
343
numCharsInALine = numCharsInALine,
329
344
protocol = protocol,
330
345
streamDigits = streamDigits,
346
+ isRelativeTimeDisplay = isRelativeTimeDisplay,
331
347
onMeasureContentWidth = { contentWidthInPx = it },
332
348
onMeasureContentLines = { totalNumLines = it.totalNumLines },
333
349
onPrepareComposable = { composables + = it },
@@ -372,6 +388,7 @@ private fun TransportTimelineContentView(
372
388
numCharsInALine : Int ,
373
389
protocol : ProtocolVersion ? ,
374
390
streamDigits : Int ,
391
+ isRelativeTimeDisplay : Boolean ,
375
392
onMeasureContentWidth : (Int ) -> Unit ,
376
393
onMeasureContentLines : (TransportTimelineContentMeasureResult ) -> Unit ,
377
394
onPrepareComposable : (@Composable () -> Unit ) -> Unit ,
@@ -434,6 +451,8 @@ private fun TransportTimelineContentView(
434
451
TimestampColumn (
435
452
createTime = it.instant,
436
453
lastUpdateTime = it.lastUpdateInstant,
454
+ isRelativeTimeDisplay = isRelativeTimeDisplay,
455
+ startInstant = exchange.exchanges.first().instant,
437
456
modifier = Modifier .width(TIMESTAMP_COLUMN_WIDTH_DP )
438
457
.padding(end = 1 .dp)
439
458
)
@@ -545,10 +564,17 @@ fun lazyOrNormalItem(
545
564
}
546
565
547
566
@Composable
548
- fun TimestampColumn (modifier : Modifier = Modifier , createTime : KInstant , lastUpdateTime : KInstant ? ) {
549
- var text = DATE_TIME_FORMAT .format(createTime.atZoneOffset(KZoneOffset .local()))
567
+ fun TimestampColumn (modifier : Modifier = Modifier , createTime : KInstant , lastUpdateTime : KInstant ? , isRelativeTimeDisplay : Boolean , startInstant : KInstant ) {
568
+ var text = DATE_TIME_FORMAT .format(
569
+ createTime.atZoneOffset(KZoneOffset .local()).let { if (isRelativeTimeDisplay) it - startInstant else it }
570
+ )
550
571
if (lastUpdateTime != null && lastUpdateTime != createTime) {
551
- text = " $text ~ ${DATE_TIME_FORMAT .format(lastUpdateTime.atZoneOffset(KZoneOffset .local()))} "
572
+ text = " $text ~ ${
573
+ DATE_TIME_FORMAT .format(
574
+ lastUpdateTime.atZoneOffset(KZoneOffset .local())
575
+ .let { if (isRelativeTimeDisplay) it - startInstant else it }
576
+ )
577
+ } "
552
578
}
553
579
554
580
// sometimes copy button is not working, due to Compose bug:
0 commit comments