Skip to content

Commit 54e77fd

Browse files
committed
- Minor code improvements
1 parent 79730df commit 54e77fd

File tree

3 files changed

+27
-6
lines changed

3 files changed

+27
-6
lines changed

LICENSE

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
MIT License
22

3-
Copyright (c) 2024 kormax
3+
Copyright (c) 2025 kormax
44

55
Permission is hereby granted, free of charge, to any person obtaining a copy
66
of this software and associated documentation files (the "Software"), to deal

app/src/main/java/com/kormax/observemodedemo/MainActivity.kt

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,11 +20,13 @@ import androidx.compose.foundation.layout.Column
2020
import androidx.compose.foundation.layout.IntrinsicSize
2121
import androidx.compose.foundation.layout.PaddingValues
2222
import androidx.compose.foundation.layout.Row
23+
import androidx.compose.foundation.layout.Spacer
2324
import androidx.compose.foundation.layout.fillMaxSize
2425
import androidx.compose.foundation.layout.fillMaxWidth
2526
import androidx.compose.foundation.layout.padding
2627
import androidx.compose.foundation.layout.width
2728
import androidx.compose.foundation.layout.wrapContentHeight
29+
import androidx.compose.foundation.layout.wrapContentWidth
2830
import androidx.compose.foundation.lazy.LazyColumn
2931
import androidx.compose.foundation.shape.RoundedCornerShape
3032
import androidx.compose.material.icons.Icons
@@ -735,16 +737,20 @@ fun PollingEventItem(event: PollingLoopEvent, display: String = "delta") {
735737
start = 10.dp,
736738
end = 10.dp,
737739
)
738-
.fillMaxWidth()
740+
.fillMaxWidth(),
741+
verticalAlignment = Alignment.Top,
739742
) {
740743
Text(text = type, modifier = Modifier.width(32.dp))
741744

742-
Text(text = event.name)
745+
Spacer(modifier = Modifier.width(8.dp))
746+
747+
Text(text = event.name, modifier = Modifier.weight(1f))
748+
743749
if (display != "") {
744750
Text(
745751
textAlign = TextAlign.End,
746752
text = delta,
747-
modifier = Modifier.fillMaxWidth(),
753+
modifier = Modifier.wrapContentWidth(Alignment.End),
748754
)
749755
}
750756
}

app/src/main/java/com/kormax/observemodedemo/Utilities.kt

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ import androidx.compose.runtime.rememberUpdatedState
1818
import androidx.compose.ui.graphics.Color
1919
import androidx.compose.ui.platform.LocalContext
2020
import androidx.core.content.pm.PackageInfoCompat
21+
import kotlinx.parcelize.IgnoredOnParcel
2122
import java.time.Instant
2223
import java.time.Instant.now
2324
import kotlin.experimental.and
@@ -108,6 +109,19 @@ class PollingLoopEvent(
108109
else -> parseOtherFrameTypes(hex)
109110
}
110111
}
112+
113+
@IgnoredOnParcel
114+
val typeName: String by lazy {
115+
return@lazy when (type) {
116+
A -> "A"
117+
B -> "B"
118+
F -> "F"
119+
UNKNOWN -> "U"
120+
ON -> "O"
121+
OFF -> "X"
122+
else -> "U*"
123+
}
124+
}
111125
}
112126

113127
fun parseOtherFrameTypes(data: String): String {
@@ -569,9 +583,9 @@ inline fun <reified T> largestRepeatingSequence(
569583
noinline comparator: (T, T) -> Boolean,
570584
): Array<T> {
571585
val possibilities = mutableListOf<Array<T>>()
572-
for (start in 0 until Math.ceil((arr.size / 2).toDouble()).toInt()) {
586+
for (start in 0 until ceil(arr.size / 2.0).toInt()) {
573587
for (end in start until arr.size) {
574-
val pattern = arr.copyOfRange(start, end)
588+
val pattern = arr.copyOfRange(start, end + 1)
575589
if (arr.containsSubArray(pattern.repeat(2), comparator)) {
576590
possibilities.add(pattern)
577591
}
@@ -673,6 +687,7 @@ fun buildPollingExportPayload(
673687
val frameJson =
674688
JSONObject().apply {
675689
put("timestamp", event.timestamp)
690+
put("type", event.typeName)
676691
put("data", event.data.toHexString())
677692
put("vendorSpecificGain", event.vendorSpecificGain)
678693
event.name.takeIf { it.isNotBlank() }?.let { put("name", it) }

0 commit comments

Comments
 (0)