Skip to content

Commit a2c98ae

Browse files
committed
Clean up
Improve UI and clean up code
1 parent 5280f84 commit a2c98ae

File tree

4 files changed

+30
-25
lines changed

4 files changed

+30
-25
lines changed

workflow-trace-viewer/src/jvmMain/kotlin/com/squareup/workflow1/traceviewer/App.kt

Lines changed: 13 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -64,8 +64,8 @@ internal fun App(
6464
sandboxState = sandboxState,
6565
) {
6666
// if there is not a file selected and trace mode is live, then don't render anything.
67-
val readyForFileTrace = validateFileMode(traceMode)
68-
val readyForLiveTrace = validateLiveMode(traceMode)
67+
val readyForFileTrace = TraceMode.validateFileMode(traceMode)
68+
val readyForLiveTrace = TraceMode.validateLiveMode(traceMode)
6969

7070
if (readyForFileTrace || readyForLiveTrace) {
7171
active = true
@@ -121,7 +121,7 @@ internal fun App(
121121
if (traceMode is TraceMode.Live) {
122122
if ((traceMode as TraceMode.Live).device == null) {
123123
DisplayDevices(
124-
onDeviceSelected = { selectedDevice ->
124+
onDeviceSelect = { selectedDevice ->
125125
traceMode = TraceMode.Live(selectedDevice)
126126
},
127127
devices = listDevices(),
@@ -161,6 +161,16 @@ internal class SandboxState {
161161
internal sealed interface TraceMode {
162162
data class File(val file: PlatformFile?) : TraceMode
163163
data class Live(val device: String? = null) : TraceMode
164+
165+
companion object {
166+
fun validateLiveMode(traceMode: TraceMode): Boolean {
167+
return traceMode is Live && traceMode.device != null
168+
}
169+
170+
fun validateFileMode(traceMode: TraceMode): Boolean {
171+
return traceMode is File && traceMode.file != null
172+
}
173+
}
164174
}
165175

166176
/**
@@ -172,11 +182,3 @@ internal fun listDevices(): List<String> {
172182
// We drop the header "List of devices attached"
173183
return process.inputStream.bufferedReader().readLines().drop(1).dropLast(1)
174184
}
175-
176-
internal fun validateLiveMode(traceMode: TraceMode): Boolean {
177-
return traceMode is TraceMode.Live && traceMode.device != null
178-
}
179-
180-
internal fun validateFileMode(traceMode: TraceMode): Boolean {
181-
return traceMode is TraceMode.File && traceMode.file != null
182-
}

workflow-trace-viewer/src/jvmMain/kotlin/com/squareup/workflow1/traceviewer/model/NodeUpdate.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,5 +34,5 @@ enum class NodeState(val color: Color) {
3434
STATE_CHANGED(Color(0xFFE57373)), // red
3535
PROPS_CHANGED(Color(0xFFFF8A65)), // orange
3636
CHILDREN_CHANGED(Color(0x802196F3)), // blue
37-
UNCHANGED(Color.Transparent),
37+
UNCHANGED(Color.LightGray.copy(alpha = 0.3f)),
3838
}

workflow-trace-viewer/src/jvmMain/kotlin/com/squareup/workflow1/traceviewer/ui/DisplayDevices.kt

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ import androidx.compose.ui.unit.dp
1818
@OptIn(ExperimentalMaterialApi::class)
1919
@Composable
2020
internal fun DisplayDevices(
21-
onDeviceSelected: (String) -> Unit,
21+
onDeviceSelect: (String) -> Unit,
2222
devices: List<String>,
2323
modifier: Modifier = Modifier,
2424
) {
@@ -29,7 +29,7 @@ internal fun DisplayDevices(
2929
) {
3030
if (devices.isEmpty()) {
3131
Text(
32-
text = "No device available",
32+
text = "No device available. Boot up a new device and restart the visualizer",
3333
modifier = Modifier.align(Alignment.Center)
3434
)
3535
return@Box
@@ -40,8 +40,9 @@ internal fun DisplayDevices(
4040
devices.forEach { device ->
4141
Card(
4242
onClick = {
43+
// Only give back the specific emulator device, i.e. "emulator-5554"
4344
emulatorRegex.find(device)?.value?.let { emulator ->
44-
onDeviceSelected(emulator)
45+
onDeviceSelect(emulator)
4546
}
4647
},
4748
shape = RoundedCornerShape(16.dp),

workflow-trace-viewer/src/jvmMain/kotlin/com/squareup/workflow1/traceviewer/ui/WorkflowTree.kt

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ package com.squareup.workflow1.traceviewer.ui
22

33
import androidx.compose.foundation.background
44
import androidx.compose.foundation.border
5+
import androidx.compose.foundation.clickable
56
import androidx.compose.foundation.layout.Arrangement
67
import androidx.compose.foundation.layout.Box
78
import androidx.compose.foundation.layout.Column
@@ -18,7 +19,6 @@ import androidx.compose.ui.ExperimentalComposeUiApi
1819
import androidx.compose.ui.Modifier
1920
import androidx.compose.ui.graphics.Color
2021
import androidx.compose.ui.input.pointer.PointerEventType
21-
import androidx.compose.ui.input.pointer.isPrimaryPressed
2222
import androidx.compose.ui.input.pointer.isSecondaryPressed
2323
import androidx.compose.ui.input.pointer.onPointerEvent
2424
import androidx.compose.ui.unit.dp
@@ -45,8 +45,10 @@ internal fun DrawTree(
4545
Column(
4646
modifier
4747
.padding(6.dp)
48-
.border(3.dp, Color.Black)
49-
.fillMaxSize(),
48+
.fillMaxSize()
49+
.then(
50+
if (node.children.isNotEmpty()) Modifier.border(3.dp, Color.Black) else Modifier
51+
),
5052
horizontalAlignment = Alignment.CenterHorizontally,
5153
) {
5254
val isAffected = affectedNodes.contains(node)
@@ -93,8 +95,8 @@ internal fun DrawTree(
9395
* Draws the group of unaffected children, which can be open and closed to expand/collapse them.
9496
*
9597
* If an unaffected children also has other children, it cannot be opened since the this group
96-
* treats all nodes as one entity. The onClick for the whole group overrides the onClick for the
97-
* individual nodes.
98+
* treats all nodes as one entity. The right click for the whole group overrides the right click for
99+
* the individual nodes.
98100
*/
99101
@OptIn(ExperimentalComposeUiApi::class)
100102
@Composable
@@ -141,8 +143,7 @@ private fun UnaffectedChildrenGroup(
141143
Column(
142144
modifier = Modifier
143145
.fillMaxWidth()
144-
.padding(6.dp)
145-
.border(3.dp, Color.Black),
146+
.padding(6.dp),
146147
horizontalAlignment = Alignment.CenterHorizontally,
147148
) {
148149
DrawChildrenInGroups(
@@ -279,10 +280,11 @@ private fun DrawNode(
279280
Box(
280281
modifier = Modifier
281282
.background(nodeUpdate.state.color)
283+
.clickable {
284+
onNodeSelect(nodeUpdate)
285+
}
282286
.onPointerEvent(PointerEventType.Press) {
283-
if (it.buttons.isPrimaryPressed) {
284-
onNodeSelect(nodeUpdate)
285-
} else if (it.buttons.isSecondaryPressed) {
287+
if (it.buttons.isSecondaryPressed) {
286288
onExpandToggle(node)
287289
}
288290
}

0 commit comments

Comments
 (0)