summaryrefslogtreecommitdiff
path: root/docs/superpowers/plans/2026-04-04-instrument-sheet-visual-redesign.md
blob: e1a086b22a86c644817c7d289b3d90803f94a2fa (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
1260
1261
1262
1263
1264
1265
1266
1267
1268
1269
1270
1271
1272
1273
1274
1275
1276
1277
1278
1279
1280
1281
1282
1283
1284
1285
1286
1287
1288
1289
1290
1291
1292
1293
1294
1295
1296
1297
1298
1299
1300
1301
1302
1303
1304
1305
1306
1307
1308
1309
1310
1311
1312
1313
1314
1315
1316
1317
1318
1319
1320
1321
1322
1323
1324
1325
1326
1327
1328
1329
1330
1331
1332
1333
1334
1335
1336
1337
1338
1339
1340
1341
1342
1343
1344
1345
1346
1347
1348
1349
1350
1351
1352
1353
1354
1355
1356
1357
1358
1359
1360
1361
1362
1363
1364
1365
1366
1367
1368
1369
1370
1371
1372
1373
1374
1375
1376
1377
1378
1379
1380
1381
1382
1383
1384
1385
1386
1387
1388
1389
1390
1391
1392
1393
1394
1395
1396
1397
1398
1399
1400
1401
1402
1403
1404
1405
1406
1407
# Instrument Sheet Visual Redesign — Implementation Plan

> **For agentic workers:** REQUIRED SUB-SKILL: Use superpowers:subagent-driven-development (recommended) or superpowers:executing-plans to implement this plan task-by-task. Steps use checkbox (`- [ ]`) syntax for tracking.

**Goal:** Redesign the instrument bottom sheet with an animated wave divider, direction arrows, imperial units, updated typography, and touch-event containment.

**Architecture:** Two new custom Views (`DirectionArrowView`, `WaveView`) are wired through an expanded `InstrumentHandler`. The layout is fully restructured; `MainActivity` is updated to pass numeric bearings and feet-converted heights. No new dependencies required.

**Tech Stack:** Kotlin, Android View system, `Canvas`/`Paint`, `ValueAnimator`, Material3, ConstraintLayout, GridLayout

---

## File Map

| File | Action | Responsibility |
|---|---|---|
| `layout_instruments_sheet.xml` | Rewrite | Cell structure, WaveView, forecast layout, touch containment |
| `DirectionArrowView.kt` | Create | Draws rotating chevron arrow in a circle |
| `WaveView.kt` | Create | Animated swell + wind wave canvas |
| `InstrumentHandler.kt` | Rewrite | Drives all text, arrows, and wave view |
| `MainActivity.kt` | Modify | Remove report buttons, convert units, wire new views |
| `themes.xml` | Modify | Typography styles: weight 300, unit label, forecast styles |
| `dimens.xml` | Modify | Updated font sizes |
| `InstrumentHandlerTest.kt` | Create | Unit tests for formatting/conversion helpers |

---

### Task 1: Remove Report Buttons and Fix Touch-Through

**Files:**
- Modify: `android-app/app/src/main/res/layout/layout_instruments_sheet.xml`
- Modify: `android-app/app/src/main/kotlin/org/terst/nav/MainActivity.kt`

- [ ] **Step 1.1: Remove the three report views from the layout**

In `layout_instruments_sheet.xml`, delete the entire `reports_divider` View, `label_reports` TextView, and `reports_row` LinearLayout (lines 199–248). Also add `android:clickable="true"` and `android:focusable="true"` to the root `ConstraintLayout` to prevent touch-through to the map.

The root element should look like:
```xml
<androidx.constraintlayout.widget.ConstraintLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:padding="16dp"
    android:background="?attr/colorSurface"
    android:clickable="true"
    android:focusable="true">
```

- [ ] **Step 1.2: Remove button click listeners from MainActivity**

In `MainActivity.kt`, delete lines 95–101:
```kotlin
// DELETE THESE:
findViewById<MaterialButton>(R.id.btn_nav_pretrip).setOnClickListener {
    showReport(org.terst.nav.tripreport.PreTripReportFragment())
}

findViewById<MaterialButton>(R.id.btn_nav_tripreport).setOnClickListener {
    showReport(org.terst.nav.tripreport.TripReportFragment())
}
```

Also remove the `MaterialButton` import if it becomes unused after this change.

- [ ] **Step 1.3: Build and verify no compile errors**

```bash
cd android-app && ./gradlew assembleDebug 2>&1 | tail -20
```
Expected: `BUILD SUCCESSFUL`

- [ ] **Step 1.4: Commit**

```bash
git add android-app/app/src/main/res/layout/layout_instruments_sheet.xml \
        android-app/app/src/main/kotlin/org/terst/nav/MainActivity.kt
git commit -m "feat(ui): remove report section from instrument sheet, fix touch-through"
```

---

### Task 2: Update Typography Styles

**Files:**
- Modify: `android-app/app/src/main/res/values/themes.xml`
- Modify: `android-app/app/src/main/res/values/dimens.xml`

- [ ] **Step 2.1: Update dimens.xml**

Replace the contents of `dimens.xml` with:
```xml
<?xml version="1.0" encoding="utf-8"?>
<resources>
    <dimen name="text_size_instrument_primary">26sp</dimen>
    <dimen name="text_size_instrument_label">10sp</dimen>
    <dimen name="text_size_instrument_unit">10sp</dimen>
    <dimen name="text_size_forecast_value">22sp</dimen>
    <dimen name="text_size_forecast_label">10sp</dimen>
    <dimen name="text_size_forecast_bearing">12sp</dimen>
    <dimen name="instrument_margin">8dp</dimen>
    <dimen name="instrument_padding">4dp</dimen>
</resources>
```

- [ ] **Step 2.2: Update and add styles in themes.xml**

Replace the instrument styles block (lines 41–70) with:
```xml
<!-- Instrument Display Styles -->
<style name="InstrumentLabel" parent="android:Widget.TextView">
    <item name="android:layout_width">wrap_content</item>
    <item name="android:layout_height">wrap_content</item>
    <item name="android:textColor">@color/instrument_text_secondary</item>
    <item name="android:textSize">@dimen/text_size_instrument_label</item>
    <item name="android:textAllCaps">true</item>
    <item name="android:letterSpacing">0.12</item>
    <item name="android:textStyle">normal</item>
    <item name="android:fontFamily">sans-serif-light</item>
</style>

<style name="InstrumentPrimaryValue" parent="android:Widget.TextView">
    <item name="android:layout_width">wrap_content</item>
    <item name="android:layout_height">wrap_content</item>
    <item name="android:textColor">@color/instrument_text_normal</item>
    <item name="android:textSize">@dimen/text_size_instrument_primary</item>
    <item name="android:textStyle">normal</item>
    <item name="android:fontFamily">sans-serif-light</item>
    <item name="android:includeFontPadding">false</item>
</style>

<style name="InstrumentUnit" parent="android:Widget.TextView">
    <item name="android:layout_width">wrap_content</item>
    <item name="android:layout_height">wrap_content</item>
    <item name="android:textColor">#79747E</item>
    <item name="android:textSize">@dimen/text_size_instrument_unit</item>
    <item name="android:textStyle">normal</item>
    <item name="android:layout_marginStart">2dp</item>
    <item name="android:layout_marginBottom">3dp</item>
</style>

<style name="ForecastLabel" parent="android:Widget.TextView">
    <item name="android:layout_width">wrap_content</item>
    <item name="android:layout_height">wrap_content</item>
    <item name="android:textColor">#5B9EC2</item>
    <item name="android:textSize">@dimen/text_size_forecast_label</item>
    <item name="android:textAllCaps">true</item>
    <item name="android:letterSpacing">0.12</item>
    <item name="android:textStyle">normal</item>
    <item name="android:fontFamily">sans-serif-light</item>
</style>

<style name="ForecastValue" parent="android:Widget.TextView">
    <item name="android:layout_width">wrap_content</item>
    <item name="android:layout_height">wrap_content</item>
    <item name="android:textColor">#CAE8FF</item>
    <item name="android:textSize">@dimen/text_size_forecast_value</item>
    <item name="android:textStyle">normal</item>
    <item name="android:fontFamily">sans-serif-light</item>
    <item name="android:includeFontPadding">false</item>
</style>

<style name="ForecastUnit" parent="android:Widget.TextView">
    <item name="android:layout_width">wrap_content</item>
    <item name="android:layout_height">wrap_content</item>
    <item name="android:textColor">#3B6785</item>
    <item name="android:textSize">@dimen/text_size_forecast_label</item>
    <item name="android:textStyle">normal</item>
    <item name="android:layout_marginStart">2dp</item>
    <item name="android:layout_marginBottom">2dp</item>
</style>

<style name="ForecastBearing" parent="android:Widget.TextView">
    <item name="android:layout_width">wrap_content</item>
    <item name="android:layout_height">wrap_content</item>
    <item name="android:textColor">#6FC3E8</item>
    <item name="android:textSize">@dimen/text_size_forecast_bearing</item>
    <item name="android:textStyle">normal</item>
    <item name="android:layout_marginStart">4dp</item>
</style>

<style name="ForecastPeriod" parent="android:Widget.TextView">
    <item name="android:layout_width">wrap_content</item>
    <item name="android:layout_height">wrap_content</item>
    <item name="android:textColor">#4A7FA0</item>
    <item name="android:textSize">@dimen/text_size_forecast_bearing</item>
    <item name="android:textStyle">normal</item>
    <item name="android:layout_marginStart">4dp</item>
</style>

<style name="InstrumentCard" parent="Widget.Material3.CardView.Elevated">
    <item name="cardBackgroundColor">@color/instrument_card_background</item>
    <item name="cardCornerRadius">12dp</item>
    <item name="cardElevation">2dp</item>
</style>
```

- [ ] **Step 2.3: Build**

```bash
cd android-app && ./gradlew assembleDebug 2>&1 | tail -20
```
Expected: `BUILD SUCCESSFUL`

- [ ] **Step 2.4: Commit**

```bash
git add android-app/app/src/main/res/values/themes.xml \
        android-app/app/src/main/res/values/dimens.xml
git commit -m "feat(ui): update instrument sheet typography — weight 300, unit labels, forecast styles"
```

---

### Task 3: Create DirectionArrowView

**Files:**
- Create: `android-app/app/src/main/kotlin/org/terst/nav/ui/DirectionArrowView.kt`
- Create: `android-app/app/src/test/kotlin/org/terst/nav/ui/DirectionArrowViewTest.kt`

- [ ] **Step 3.1: Write the failing test**

Create `android-app/app/src/test/kotlin/org/terst/nav/ui/DirectionArrowViewTest.kt`:
```kotlin
package org.terst.nav.ui

import org.junit.Assert.assertEquals
import org.junit.Test

class DirectionArrowViewTest {

    @Test
    fun `bearing is normalised — values over 360 wrap`() {
        assertEquals(10f, normalizeBearing(370f), 0.001f)
    }

    @Test
    fun `bearing is normalised — negative values wrap`() {
        assertEquals(350f, normalizeBearing(-10f), 0.001f)
    }

    @Test
    fun `bearing is normalised — exactly 360 becomes 0`() {
        assertEquals(0f, normalizeBearing(360f), 0.001f)
    }
}

// Top-level helper extracted from DirectionArrowView for testability
fun normalizeBearing(deg: Float): Float = ((deg % 360f) + 360f) % 360f
```

- [ ] **Step 3.2: Run test to verify it fails**

```bash
cd android-app && ./gradlew test --tests "org.terst.nav.ui.DirectionArrowViewTest" 2>&1 | tail -20
```
Expected: FAIL — `normalizeBearing` does not exist yet.

- [ ] **Step 3.3: Create DirectionArrowView.kt**

Create `android-app/app/src/main/kotlin/org/terst/nav/ui/DirectionArrowView.kt`:
```kotlin
package org.terst.nav.ui

import android.content.Context
import android.graphics.Canvas
import android.graphics.Color
import android.graphics.Paint
import android.graphics.Path
import android.util.AttributeSet
import android.view.View

/** Normalises a bearing in degrees to [0, 360). */
fun normalizeBearing(deg: Float): Float = ((deg % 360f) + 360f) % 360f

/**
 * A small circular direction indicator. Draws a notched chevron arrow
 * pointing in [bearing] degrees (0 = north/up, clockwise).
 *
 * Two pre-defined palettes:
 *  - [ArrowStyle.SKY]   — grey, for the instrument section
 *  - [ArrowStyle.OCEAN] — blue, for the forecast section
 */
class DirectionArrowView @JvmOverloads constructor(
    context: Context,
    attrs: AttributeSet? = null,
    defStyleAttr: Int = 0
) : View(context, attrs, defStyleAttr) {

    enum class ArrowStyle { SKY, OCEAN }

    var bearing: Float = 0f
        set(value) { field = normalizeBearing(value); invalidate() }

    var arrowStyle: ArrowStyle = ArrowStyle.SKY
        set(value) {
            field = value
            circlePaint.color = circleColor()
            arrowPaint.color  = arrowColor()
            invalidate()
        }

    private val circlePaint = Paint(Paint.ANTI_ALIAS_FLAG).apply {
        style       = Paint.Style.STROKE
        strokeWidth = 1.5f
        color       = circleColor()
    }

    private val arrowPaint = Paint(Paint.ANTI_ALIAS_FLAG).apply {
        style = Paint.Style.FILL
        color = arrowColor()
    }

    private val arrowPath = Path()

    private fun circleColor() = when (arrowStyle) {
        ArrowStyle.SKY   -> Color.parseColor("#3A3640")
        ArrowStyle.OCEAN -> Color.parseColor("#1E4A6E")
    }

    private fun arrowColor() = when (arrowStyle) {
        ArrowStyle.SKY   -> Color.parseColor("#9A94A0")
        ArrowStyle.OCEAN -> Color.parseColor("#6FC3E8")
    }

    override fun onDraw(canvas: Canvas) {
        val cx = width  / 2f
        val cy = height / 2f
        val r  = (minOf(width, height) / 2f) - circlePaint.strokeWidth

        // Circle outline
        canvas.drawCircle(cx, cy, r, circlePaint)

        // Notched chevron: tip at top in unrotated space
        val tipY   = cy - r * 0.72f
        val baseY  = cy + r * 0.50f
        val notchY = cy + r * 0.22f
        val halfW  = r * 0.42f

        arrowPath.reset()
        arrowPath.moveTo(cx, tipY)
        arrowPath.lineTo(cx - halfW, baseY)
        arrowPath.lineTo(cx, notchY)
        arrowPath.lineTo(cx + halfW, baseY)
        arrowPath.close()

        canvas.save()
        canvas.rotate(bearing, cx, cy)
        canvas.drawPath(arrowPath, arrowPaint)
        canvas.restore()
    }
}
```

- [ ] **Step 3.4: Run test to verify it passes**

```bash
cd android-app && ./gradlew test --tests "org.terst.nav.ui.DirectionArrowViewTest" 2>&1 | tail -20
```
Expected: `BUILD SUCCESSFUL` and 3 tests passing.

- [ ] **Step 3.5: Commit**

```bash
git add android-app/app/src/main/kotlin/org/terst/nav/ui/DirectionArrowView.kt \
        android-app/app/src/test/kotlin/org/terst/nav/ui/DirectionArrowViewTest.kt
git commit -m "feat(ui): add DirectionArrowView — rotating chevron compass indicator"
```

---

### Task 4: Create WaveView

**Files:**
- Create: `android-app/app/src/main/kotlin/org/terst/nav/ui/WaveView.kt`

WaveView is a canvas-drawn View; its correctness is verified visually. No pure-logic unit tests apply here.

- [ ] **Step 4.1: Create WaveView.kt**

Create `android-app/app/src/main/kotlin/org/terst/nav/ui/WaveView.kt`:
```kotlin
package org.terst.nav.ui

import android.content.Context
import android.graphics.Canvas
import android.graphics.Color
import android.graphics.LinearGradient
import android.graphics.Paint
import android.graphics.Path
import android.graphics.Shader
import android.os.SystemClock
import android.util.AttributeSet
import android.view.View
import kotlin.math.sin

/**
 * Draws an animated ocean-horizon scene used as the divider between the
 * instrument section and the forecast section.
 *
 * The primary wave is driven by swell height and period; a secondary
 * high-frequency wave represents wind chop. Whitecaps appear at wind-wave
 * crests. The view self-animates via [postInvalidateOnAnimation].
 *
 * Set [swellHeightFt], [swellPeriodSec], and [windWaveHeightFt] to update
 * the wave state when new forecast data arrives.
 */
class WaveView @JvmOverloads constructor(
    context: Context,
    attrs: AttributeSet? = null,
    defStyleAttr: Int = 0
) : View(context, attrs, defStyleAttr) {

    var swellHeightFt: Float = 3f
        set(value) { field = value.coerceAtLeast(0f); invalidate() }

    var swellPeriodSec: Float = 10f
        set(value) { field = value.coerceAtLeast(1f); invalidate() }

    var windWaveHeightFt: Float = 1.5f
        set(value) { field = value.coerceAtLeast(0f); invalidate() }

    private var startTimeMs = -1L

    private val wavePath = Path()

    private val skyPaint   = Paint()
    private val seaPaint   = Paint()

    private val shimmerPaint = Paint(Paint.ANTI_ALIAS_FLAG).apply {
        style       = Paint.Style.STROKE
        strokeWidth = 1.5f
        color       = Color.argb(77, 111, 195, 232)
    }

    private val whitecapPaint = Paint(Paint.ANTI_ALIAS_FLAG).apply {
        style       = Paint.Style.STROKE
        strokeWidth = 1.5f
        strokeCap   = Paint.Cap.ROUND
        color       = Color.argb(128, 255, 255, 255)
    }

    override fun onAttachedToWindow() {
        super.onAttachedToWindow()
        startTimeMs = SystemClock.elapsedRealtime()
        postInvalidateOnAnimation()
    }

    override fun onSizeChanged(w: Int, h: Int, oldw: Int, oldh: Int) {
        skyPaint.shader = LinearGradient(
            0f, 0f, 0f, h * 0.6f,
            Color.parseColor("#1C1B1F"),
            Color.parseColor("#162433"),
            Shader.TileMode.CLAMP
        )
        seaPaint.shader = LinearGradient(
            0f, h * 0.4f, 0f, h.toFloat(),
            Color.parseColor("#0B3050"),
            Color.parseColor("#0D2137"),
            Shader.TileMode.CLAMP
        )
    }

    override fun onDraw(canvas: Canvas) {
        if (startTimeMs < 0) startTimeMs = SystemClock.elapsedRealtime()
        val t = (SystemClock.elapsedRealtime() - startTimeMs) / 1000.0  // seconds

        val w = width.toFloat()
        val h = height.toFloat()

        // Amplitudes scale with wave data, capped relative to view height
        val swellAmp  = (h * (swellHeightFt / 28f)).coerceIn(h * 0.04f, h * 0.22f)
        val windAmp   = (h * (windWaveHeightFt / 28f)).coerceIn(h * 0.02f, h * 0.10f)
        val swellWlen = w * (swellPeriodSec / 14f)
        val windWlen  = swellWlen * 0.35f
        val midY      = h * 0.52f

        fun waveY(x: Float): Float =
            (midY
                + sin((x / swellWlen) * TWO_PI - t * 0.8) * swellAmp
                + sin((x / windWlen)  * TWO_PI - t * 1.8 + 1.2) * windAmp).toFloat()

        // ── Sky fill ──────────────────────────────────────────────────
        wavePath.reset()
        wavePath.moveTo(0f, 0f)
        wavePath.lineTo(0f, waveY(0f))
        var x = 2f
        while (x <= w) { wavePath.lineTo(x, waveY(x)); x += 2f }
        wavePath.lineTo(w, 0f)
        wavePath.close()
        canvas.drawPath(wavePath, skyPaint)

        // ── Sea fill ──────────────────────────────────────────────────
        wavePath.reset()
        wavePath.moveTo(0f, h)
        wavePath.lineTo(0f, waveY(0f))
        x = 2f
        while (x <= w) { wavePath.lineTo(x, waveY(x)); x += 2f }
        wavePath.lineTo(w, h)
        wavePath.close()
        canvas.drawPath(wavePath, seaPaint)

        // ── Shimmer line ──────────────────────────────────────────────
        wavePath.reset()
        wavePath.moveTo(0f, waveY(0f))
        x = 2f
        while (x <= w) { wavePath.lineTo(x, waveY(x)); x += 2f }
        canvas.drawPath(wavePath, shimmerPaint)

        // ── Whitecaps at wind-wave crests ─────────────────────────────
        val capPath = Path()
        x = windWlen * 0.5f
        while (x <= w) {
            val wv = sin((x / windWlen) * TWO_PI - t * 1.8 + 1.2) * windAmp
            val wn = sin(((x + 3) / windWlen) * TWO_PI - t * 1.8 + 1.2) * windAmp
            if (wv > windAmp * 0.55 && wv >= wn) {
                val y = waveY(x)
                capPath.reset()
                capPath.moveTo(x - 7f, y + 1f)
                capPath.quadTo(x, y - 2.5f, x + 8f, y + 1f)
                canvas.drawPath(capPath, whitecapPaint)
            }
            x += windWlen * 0.9f
        }

        postInvalidateOnAnimation()
    }

    companion object {
        private const val TWO_PI = Math.PI * 2.0
    }
}
```

- [ ] **Step 4.2: Build**

```bash
cd android-app && ./gradlew assembleDebug 2>&1 | tail -20
```
Expected: `BUILD SUCCESSFUL`

- [ ] **Step 4.3: Commit**

```bash
git add android-app/app/src/main/kotlin/org/terst/nav/ui/WaveView.kt
git commit -m "feat(ui): add WaveView — animated swell/wind-wave canvas divider"
```

---

### Task 5: Restructure layout_instruments_sheet.xml

**Files:**
- Rewrite: `android-app/app/src/main/res/layout/layout_instruments_sheet.xml`

This is a full rewrite. The outer ConstraintLayout chains remain; the inner cell structure changes to use `DirectionArrowView` inline, and the forecast section is restructured.

- [ ] **Step 5.1: Replace the layout file**

Write the complete new `layout_instruments_sheet.xml`:
```xml
<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:paddingStart="16dp"
    android:paddingEnd="16dp"
    android:paddingBottom="16dp"
    android:background="?attr/colorSurface"
    android:clickable="true"
    android:focusable="true">

    <!-- Drag handle -->
    <View
        android:id="@+id/drag_handle"
        android:layout_width="36dp"
        android:layout_height="4dp"
        android:layout_marginTop="12dp"
        android:background="@color/md_theme_outline"
        app:layout_constraintTop_toTopOf="parent"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintEnd_toEndOf="parent" />

    <!--
        3×2 grid: AWS/HDG/BSP top row, TWS/COG/SOG bottom row.
        Cells with direction: AWS, TWS (kts + unit + arrow inline)
                              HDG, COG (°-in-value + arrow inline)
        Cells without: BSP, SOG (kts + unit, no arrow)
    -->
    <androidx.gridlayout.widget.GridLayout
        android:id="@+id/instrument_grid"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_marginTop="12dp"
        app:columnCount="3"
        app:rowCount="2"
        app:layout_constraintTop_toBottomOf="@id/drag_handle"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintEnd_toEndOf="parent">

        <!-- AWS -->
        <LinearLayout
            android:layout_width="0dp"
            android:layout_height="wrap_content"
            app:layout_columnWeight="1"
            android:orientation="vertical"
            android:gravity="center"
            android:padding="8dp">
            <TextView style="@style/InstrumentLabel" android:text="AWS" />
            <LinearLayout
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_gravity="center_horizontal"
                android:orientation="horizontal"
                android:gravity="center_vertical">
                <TextView
                    android:id="@+id/value_aws"
                    style="@style/InstrumentPrimaryValue"
                    tools:text="18.2" />
                <TextView style="@style/InstrumentUnit" android:text="kts" />
                <org.terst.nav.ui.DirectionArrowView
                    android:id="@+id/arrow_aws"
                    android:layout_width="14dp"
                    android:layout_height="14dp"
                    android:layout_marginStart="3dp"
                    android:layout_marginBottom="3dp"
                    android:layout_gravity="bottom" />
            </LinearLayout>
        </LinearLayout>

        <!-- HDG: ° is part of the value string -->
        <LinearLayout
            android:layout_width="0dp"
            android:layout_height="wrap_content"
            app:layout_columnWeight="1"
            android:orientation="vertical"
            android:gravity="center"
            android:padding="8dp">
            <TextView style="@style/InstrumentLabel" android:text="HDG" />
            <LinearLayout
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_gravity="center_horizontal"
                android:orientation="horizontal"
                android:gravity="center_vertical">
                <TextView
                    android:id="@+id/value_hdg"
                    style="@style/InstrumentPrimaryValue"
                    tools:text="247°" />
                <org.terst.nav.ui.DirectionArrowView
                    android:id="@+id/arrow_hdg"
                    android:layout_width="14dp"
                    android:layout_height="14dp"
                    android:layout_marginStart="3dp"
                    android:layout_marginBottom="3dp"
                    android:layout_gravity="bottom" />
            </LinearLayout>
        </LinearLayout>

        <!-- BSP: no direction -->
        <LinearLayout
            android:layout_width="0dp"
            android:layout_height="wrap_content"
            app:layout_columnWeight="1"
            android:orientation="vertical"
            android:gravity="center"
            android:padding="8dp">
            <TextView style="@style/InstrumentLabel" android:text="BSP" />
            <LinearLayout
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_gravity="center_horizontal"
                android:orientation="horizontal"
                android:gravity="baseline">
                <TextView
                    android:id="@+id/value_bsp"
                    style="@style/InstrumentPrimaryValue"
                    tools:text="6.8" />
                <TextView style="@style/InstrumentUnit" android:text="kts" />
            </LinearLayout>
        </LinearLayout>

        <!-- TWS -->
        <LinearLayout
            android:layout_width="0dp"
            android:layout_height="wrap_content"
            app:layout_columnWeight="1"
            android:orientation="vertical"
            android:gravity="center"
            android:padding="8dp">
            <TextView style="@style/InstrumentLabel" android:text="TWS" />
            <LinearLayout
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_gravity="center_horizontal"
                android:orientation="horizontal"
                android:gravity="center_vertical">
                <TextView
                    android:id="@+id/value_tws"
                    style="@style/InstrumentPrimaryValue"
                    tools:text="15.5" />
                <TextView style="@style/InstrumentUnit" android:text="kts" />
                <org.terst.nav.ui.DirectionArrowView
                    android:id="@+id/arrow_tws"
                    android:layout_width="14dp"
                    android:layout_height="14dp"
                    android:layout_marginStart="3dp"
                    android:layout_marginBottom="3dp"
                    android:layout_gravity="bottom" />
            </LinearLayout>
        </LinearLayout>

        <!-- COG: ° is part of the value string -->
        <LinearLayout
            android:layout_width="0dp"
            android:layout_height="wrap_content"
            app:layout_columnWeight="1"
            android:orientation="vertical"
            android:gravity="center"
            android:padding="8dp">
            <TextView style="@style/InstrumentLabel" android:text="COG" />
            <LinearLayout
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_gravity="center_horizontal"
                android:orientation="horizontal"
                android:gravity="center_vertical">
                <TextView
                    android:id="@+id/value_cog"
                    style="@style/InstrumentPrimaryValue"
                    tools:text="253°" />
                <org.terst.nav.ui.DirectionArrowView
                    android:id="@+id/arrow_cog"
                    android:layout_width="14dp"
                    android:layout_height="14dp"
                    android:layout_marginStart="3dp"
                    android:layout_marginBottom="3dp"
                    android:layout_gravity="bottom" />
            </LinearLayout>
        </LinearLayout>

        <!-- SOG: no direction -->
        <LinearLayout
            android:layout_width="0dp"
            android:layout_height="wrap_content"
            app:layout_columnWeight="1"
            android:orientation="vertical"
            android:gravity="center"
            android:padding="8dp">
            <TextView style="@style/InstrumentLabel" android:text="SOG" />
            <LinearLayout
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_gravity="center_horizontal"
                android:orientation="horizontal"
                android:gravity="baseline">
                <TextView
                    android:id="@+id/value_sog"
                    style="@style/InstrumentPrimaryValue"
                    tools:text="7.1" />
                <TextView style="@style/InstrumentUnit" android:text="kts" />
            </LinearLayout>
        </LinearLayout>

    </androidx.gridlayout.widget.GridLayout>

    <!-- Depth + Baro side by side -->
    <LinearLayout
        android:id="@+id/expanded_instruments"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:orientation="horizontal"
        android:layout_marginTop="4dp"
        app:layout_constraintTop_toBottomOf="@id/instrument_grid"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintEnd_toEndOf="parent">

        <LinearLayout
            android:layout_width="0dp"
            android:layout_height="wrap_content"
            android:layout_weight="1"
            android:orientation="vertical"
            android:gravity="center"
            android:padding="8dp">
            <TextView style="@style/InstrumentLabel" android:text="Depth" />
            <LinearLayout
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_gravity="center_horizontal"
                android:orientation="horizontal"
                android:gravity="baseline">
                <TextView
                    android:id="@+id/value_depth"
                    style="@style/InstrumentPrimaryValue"
                    tools:text="42.0" />
                <TextView style="@style/InstrumentUnit" android:text="ft" />
            </LinearLayout>
        </LinearLayout>

        <View
            android:layout_width="1dp"
            android:layout_height="match_parent"
            android:background="#2B2930" />

        <LinearLayout
            android:layout_width="0dp"
            android:layout_height="wrap_content"
            android:layout_weight="1"
            android:orientation="vertical"
            android:gravity="center"
            android:padding="8dp">
            <TextView style="@style/InstrumentLabel" android:text="Baro" />
            <LinearLayout
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_gravity="center_horizontal"
                android:orientation="horizontal"
                android:gravity="baseline">
                <TextView
                    android:id="@+id/value_baro"
                    style="@style/InstrumentPrimaryValue"
                    tools:text="1013" />
                <TextView style="@style/InstrumentUnit" android:text="hPa" />
            </LinearLayout>
        </LinearLayout>

    </LinearLayout>

    <!-- Animated wave divider -->
    <org.terst.nav.ui.WaveView
        android:id="@+id/wave_divider"
        android:layout_width="match_parent"
        android:layout_height="72dp"
        android:layout_marginStart="-16dp"
        android:layout_marginEnd="-16dp"
        app:layout_constraintTop_toBottomOf="@id/expanded_instruments"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintEnd_toEndOf="parent" />

    <!-- Forecast section (ocean) -->
    <LinearLayout
        android:id="@+id/forecast_row"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:orientation="horizontal"
        android:background="#0D2137"
        android:paddingTop="14dp"
        android:paddingBottom="20dp"
        android:layout_marginStart="-16dp"
        android:layout_marginEnd="-16dp"
        app:layout_constraintTop_toBottomOf="@id/wave_divider"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintBottom_toBottomOf="parent">

        <!-- Current -->
        <LinearLayout
            android:layout_width="0dp"
            android:layout_height="wrap_content"
            android:layout_weight="1"
            android:orientation="vertical"
            android:gravity="center"
            android:padding="4dp">
            <TextView style="@style/ForecastLabel" android:text="Current" />
            <LinearLayout
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_gravity="center_horizontal"
                android:orientation="horizontal"
                android:gravity="baseline">
                <TextView
                    android:id="@+id/value_curr_spd"
                    style="@style/ForecastValue"
                    tools:text="0.8" />
                <TextView style="@style/ForecastUnit" android:text="kts" />
            </LinearLayout>
            <LinearLayout
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_gravity="center_horizontal"
                android:orientation="horizontal"
                android:gravity="center_vertical"
                android:layout_marginTop="4dp">
                <org.terst.nav.ui.DirectionArrowView
                    android:id="@+id/arrow_curr"
                    android:layout_width="14dp"
                    android:layout_height="14dp" />
                <TextView
                    android:id="@+id/bearing_curr"
                    style="@style/ForecastBearing"
                    tools:text="185°" />
            </LinearLayout>
        </LinearLayout>

        <!-- Waves -->
        <LinearLayout
            android:layout_width="0dp"
            android:layout_height="wrap_content"
            android:layout_weight="1"
            android:orientation="vertical"
            android:gravity="center"
            android:padding="4dp">
            <TextView style="@style/ForecastLabel" android:text="Waves" />
            <LinearLayout
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_gravity="center_horizontal"
                android:orientation="horizontal"
                android:gravity="baseline">
                <TextView
                    android:id="@+id/value_wave_ht"
                    style="@style/ForecastValue"
                    tools:text="3.5" />
                <TextView style="@style/ForecastUnit" android:text="ft" />
            </LinearLayout>
            <LinearLayout
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_gravity="center_horizontal"
                android:orientation="horizontal"
                android:gravity="center_vertical"
                android:layout_marginTop="4dp">
                <org.terst.nav.ui.DirectionArrowView
                    android:id="@+id/arrow_waves"
                    android:layout_width="14dp"
                    android:layout_height="14dp" />
                <TextView
                    android:id="@+id/bearing_waves"
                    style="@style/ForecastBearing"
                    tools:text="275°" />
            </LinearLayout>
        </LinearLayout>

        <!-- Swell -->
        <LinearLayout
            android:layout_width="0dp"
            android:layout_height="wrap_content"
            android:layout_weight="1"
            android:orientation="vertical"
            android:gravity="center"
            android:padding="4dp">
            <TextView style="@style/ForecastLabel" android:text="Swell" />
            <LinearLayout
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_gravity="center_horizontal"
                android:orientation="horizontal"
                android:gravity="baseline">
                <TextView
                    android:id="@+id/value_swell_ht"
                    style="@style/ForecastValue"
                    tools:text="5.2" />
                <TextView style="@style/ForecastUnit" android:text="ft" />
            </LinearLayout>
            <LinearLayout
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_gravity="center_horizontal"
                android:orientation="horizontal"
                android:gravity="center_vertical"
                android:layout_marginTop="4dp">
                <org.terst.nav.ui.DirectionArrowView
                    android:id="@+id/arrow_swell"
                    android:layout_width="14dp"
                    android:layout_height="14dp" />
                <TextView
                    android:id="@+id/bearing_swell"
                    style="@style/ForecastBearing"
                    tools:text="260°" />
                <TextView
                    android:id="@+id/value_swell_per"
                    style="@style/ForecastPeriod"
                    tools:text="· 14s" />
            </LinearLayout>
        </LinearLayout>

    </LinearLayout>

</androidx.constraintlayout.widget.ConstraintLayout>
```

- [ ] **Step 5.2: Build**

```bash
cd android-app && ./gradlew assembleDebug 2>&1 | tail -30
```
Expected: `BUILD SUCCESSFUL`. Expect resource ID errors for the old IDs that `InstrumentHandler` still references (`value_curr_dir`, `value_wave_dir`) — those are fixed in Task 6.

- [ ] **Step 5.3: Commit**

```bash
git add android-app/app/src/main/res/layout/layout_instruments_sheet.xml
git commit -m "feat(ui): restructure instrument sheet layout — inline arrows, WaveView, ocean forecast section"
```

---

### Task 6: Refactor InstrumentHandler

**Files:**
- Rewrite: `android-app/app/src/main/kotlin/org/terst/nav/ui/InstrumentHandler.kt`
- Create: `android-app/app/src/test/kotlin/org/terst/nav/ui/InstrumentHandlerTest.kt`

- [ ] **Step 6.1: Write failing tests for formatting helpers**

Create `android-app/app/src/test/kotlin/org/terst/nav/ui/InstrumentHandlerTest.kt`:
```kotlin
package org.terst.nav.ui

import org.junit.Assert.assertEquals
import org.junit.Test
import java.util.Locale

class InstrumentHandlerTest {

    @Test
    fun `metresToFeet converts correctly`() {
        assertEquals(3.28f, metresToFeet(1.0).toFloat(), 0.01f)
    }

    @Test
    fun `metresToFeet zero returns zero`() {
        assertEquals(0f, metresToFeet(0.0).toFloat(), 0.001f)
    }

    @Test
    fun `formatFt formats to one decimal`() {
        val result = formatFt(3.28084, Locale.US)
        assertEquals("3.3", result)
    }

    @Test
    fun `formatBearing appends degree symbol`() {
        assertEquals("275°", formatBearing(275.0, Locale.US))
    }

    @Test
    fun `formatBearing rounds to zero decimals`() {
        assertEquals("123°", formatBearing(123.4, Locale.US))
    }

    @Test
    fun `formatPeriod appends s`() {
        assertEquals("· 14s", formatPeriod(14.0, Locale.US))
    }
}
```

- [ ] **Step 6.2: Run tests to verify they fail**

```bash
cd android-app && ./gradlew test --tests "org.terst.nav.ui.InstrumentHandlerTest" 2>&1 | tail -20
```
Expected: FAIL — helpers not defined yet.

- [ ] **Step 6.3: Rewrite InstrumentHandler.kt**

Replace the entire contents of `InstrumentHandler.kt`:
```kotlin
package org.terst.nav.ui

import android.widget.TextView
import java.util.Locale

// ── Pure formatting helpers (top-level for testability) ──────────────────────

private const val M_TO_FT = 3.28084

/** Converts metres to feet. */
fun metresToFeet(metres: Double): Double = metres * M_TO_FT

/** Formats a feet value to one decimal place. */
fun formatFt(ft: Double, locale: Locale = Locale.getDefault()): String =
    "%.1f".format(locale, ft)

/** Formats a bearing to zero decimal places with a degree symbol. */
fun formatBearing(deg: Double, locale: Locale = Locale.getDefault()): String =
    "%.0f°".format(locale, deg)

/** Formats a swell period with leading dot separator. */
fun formatPeriod(sec: Double, locale: Locale = Locale.getDefault()): String =
    "· %.0fs".format(locale, sec)

// ── InstrumentHandler ────────────────────────────────────────────────────────

/**
 * Drives all text fields, direction arrows, and the wave view in the
 * instrument bottom sheet.
 *
 * All [DirectionArrowView] instances in the forecast section are initialised
 * with [DirectionArrowView.ArrowStyle.OCEAN] style automatically.
 *
 * Units contract:
 *  - Speed values: formatted strings in knots, already formatted by caller
 *  - Height values: caller passes raw metres; this class converts to feet
 *  - Bearing values: raw degrees as [Float], rotated into arrows and formatted
 *    into bearing TextViews by this class
 */
class InstrumentHandler(
    // ── Instrument section TextViews ─────────────────────────────────
    private val valueAws:   TextView,
    private val valueTws:   TextView,
    private val valueHdg:   TextView,
    private val valueCog:   TextView,
    private val valueBsp:   TextView,
    private val valueSog:   TextView,
    private val valueDepth: TextView,
    private val valueBaro:  TextView,
    // ── Instrument section DirectionArrowViews ───────────────────────
    private val arrowAws: DirectionArrowView,
    private val arrowTws: DirectionArrowView,
    private val arrowHdg: DirectionArrowView,
    private val arrowCog: DirectionArrowView,
    // ── Forecast section TextViews ───────────────────────────────────
    private val valueCurrSpd: TextView,
    private val valueWaveHt:  TextView,
    private val valueSwellHt: TextView,
    private val valueSwellPer: TextView,
    // ── Forecast section DirectionArrowViews ─────────────────────────
    private val arrowCurr:  DirectionArrowView,
    private val arrowWaves: DirectionArrowView,
    private val arrowSwell: DirectionArrowView,
    // ── Forecast section bearing TextViews ───────────────────────────
    private val bearingCurr:  TextView,
    private val bearingWaves: TextView,
    private val bearingSwell: TextView,
    // ── Wave view ────────────────────────────────────────────────────
    private val waveView: WaveView
) {
    init {
        arrowCurr.arrowStyle  = DirectionArrowView.ArrowStyle.OCEAN
        arrowWaves.arrowStyle = DirectionArrowView.ArrowStyle.OCEAN
        arrowSwell.arrowStyle = DirectionArrowView.ArrowStyle.OCEAN
    }

    /**
     * Updates instrument-section text and arrows.
     * Null arguments leave the current value unchanged.
     *
     * Heights should already be formatted strings (caller's responsibility
     * for baro/depth). Bearings are raw degrees; pass null to leave arrow
     * position unchanged.
     *
     * [depthM] is raw metres — converted to feet internally.
     */
    fun updateDisplay(
        aws: String?    = null, awsBearingDeg: Float?  = null,
        tws: String?    = null, twsBearingDeg: Float?  = null,
        hdg: String?    = null, hdgBearingDeg: Float?  = null,
        cog: String?    = null, cogBearingDeg: Float?  = null,
        bsp: String?    = null,
        sog: String?    = null,
        depthM: Double? = null,
        baro: String?   = null
    ) {
        aws?.let { valueAws.text = it }
        tws?.let { valueTws.text = it }
        hdg?.let { valueHdg.text = it }
        cog?.let { valueCog.text = it }
        bsp?.let { valueBsp.text = it }
        sog?.let { valueSog.text = it }
        baro?.let { valueBaro.text = it }
        depthM?.let { valueDepth.text = formatFt(metresToFeet(it)) }

        awsBearingDeg?.let { arrowAws.bearing = it }
        twsBearingDeg?.let { arrowTws.bearing = it }
        hdgBearingDeg?.let { arrowHdg.bearing = it }
        cogBearingDeg?.let { arrowCog.bearing = it }
    }

    /**
     * Updates the forecast section.
     *
     * [waveHeightM] and [swellHeightM] are raw metres — converted to feet
     * internally. Speed strings are pre-formatted by the caller. Bearings
     * are raw degrees.
     */
    fun updateConditions(
        currSpd: String?        = null,
        currDirDeg: Float?      = null,
        waveHeightM: Double?    = null,
        waveDirDeg: Float?      = null,
        swellHeightM: Double?   = null,
        swellDirDeg: Float?     = null,
        swellPeriodS: Double?   = null
    ) {
        currSpd?.let { valueCurrSpd.text = it }
        currDirDeg?.let {
            arrowCurr.bearing = it
            bearingCurr.text  = formatBearing(it.toDouble())
        }
        waveHeightM?.let { valueWaveHt.text = formatFt(metresToFeet(it)) }
        waveDirDeg?.let {
            arrowWaves.bearing = it
            bearingWaves.text  = formatBearing(it.toDouble())
        }
        swellHeightM?.let { valueSwellHt.text = formatFt(metresToFeet(it)) }
        swellDirDeg?.let {
            arrowSwell.bearing = it
            bearingSwell.text  = formatBearing(it.toDouble())
        }
        swellPeriodS?.let { valueSwellPer.text = formatPeriod(it) }
    }

    /**
     * Updates the WaveView with current sea state data.
     * All inputs in feet. Call whenever new marine forecast data arrives.
     */
    fun updateWaveState(
        swellHeightFt: Float,
        swellPeriodSec: Float,
        windWaveHeightFt: Float
    ) {
        waveView.swellHeightFt   = swellHeightFt
        waveView.swellPeriodSec  = swellPeriodSec
        waveView.windWaveHeightFt = windWaveHeightFt
    }
}
```

- [ ] **Step 6.4: Run tests to verify they pass**

```bash
cd android-app && ./gradlew test --tests "org.terst.nav.ui.InstrumentHandlerTest" 2>&1 | tail -20
```
Expected: `BUILD SUCCESSFUL`, 6 tests passing.

- [ ] **Step 6.5: Build (will fail until MainActivity is updated)**

```bash
cd android-app && ./gradlew assembleDebug 2>&1 | grep -E "error:|BUILD" | head -20
```
Expected: compile errors in `MainActivity.kt` referencing old `InstrumentHandler` constructor and old `updateConditions` signature. That is expected — fixed in Task 7.

- [ ] **Step 6.6: Commit**

```bash
git add android-app/app/src/main/kotlin/org/terst/nav/ui/InstrumentHandler.kt \
        android-app/app/src/test/kotlin/org/terst/nav/ui/InstrumentHandlerTest.kt
git commit -m "feat(ui): refactor InstrumentHandler — direction arrows, WaveView, feet conversion"
```

---

### Task 7: Update MainActivity — Wire New Views and Fix Units

**Files:**
- Modify: `android-app/app/src/main/kotlin/org/terst/nav/MainActivity.kt`

- [ ] **Step 7.1: Update setupHandlers() to wire all new view references**

Replace the `setupHandlers()` function in `MainActivity.kt`:
```kotlin
private fun setupHandlers() {
    instrumentHandler = InstrumentHandler(
        // Instrument TextViews
        valueAws   = findViewById(R.id.value_aws),
        valueTws   = findViewById(R.id.value_tws),
        valueHdg   = findViewById(R.id.value_hdg),
        valueCog   = findViewById(R.id.value_cog),
        valueBsp   = findViewById(R.id.value_bsp),
        valueSog   = findViewById(R.id.value_sog),
        valueDepth = findViewById(R.id.value_depth),
        valueBaro  = findViewById(R.id.value_baro),
        // Instrument arrows
        arrowAws   = findViewById(R.id.arrow_aws),
        arrowTws   = findViewById(R.id.arrow_tws),
        arrowHdg   = findViewById(R.id.arrow_hdg),
        arrowCog   = findViewById(R.id.arrow_cog),
        // Forecast TextViews
        valueCurrSpd  = findViewById(R.id.value_curr_spd),
        valueWaveHt   = findViewById(R.id.value_wave_ht),
        valueSwellHt  = findViewById(R.id.value_swell_ht),
        valueSwellPer = findViewById(R.id.value_swell_per),
        // Forecast arrows
        arrowCurr  = findViewById(R.id.arrow_curr),
        arrowWaves = findViewById(R.id.arrow_waves),
        arrowSwell = findViewById(R.id.arrow_swell),
        // Forecast bearings
        bearingCurr  = findViewById(R.id.bearing_curr),
        bearingWaves = findViewById(R.id.bearing_waves),
        bearingSwell = findViewById(R.id.bearing_swell),
        // Wave view
        waveView = findViewById(R.id.wave_divider)
    )
    instrumentHandler?.updateDisplay(
        aws = "—", tws = "—", hdg = "—",
        cog = "—", bsp = "—", sog = "—",
        baro = "—"
    )
    instrumentHandler?.updateConditions(
        currSpd = "—"
    )
}
```

- [ ] **Step 7.2: Update observeDataSources() — GPS collector**

In `observeDataSources()`, update the GPS collector to pass bearings as floats and format COG with `°` embedded in the value. Replace the `locationFlow` collector block:
```kotlin
lifecycleScope.launch {
    LocationService.locationFlow.collect { gpsData ->
        mapHandler?.centerOnLocation(gpsData.latitude, gpsData.longitude)
        mapHandler?.updateUserPosition(gpsData.latitude, gpsData.longitude, gpsData.cog.toFloat())
        viewModel.addGpsPoint(gpsData.latitude, gpsData.longitude, gpsData.sog, gpsData.cog)
        instrumentHandler?.updateDisplay(
            sog = "%.1f".format(Locale.getDefault(), gpsData.sog),
            cog = "%.0f°".format(Locale.getDefault(), gpsData.cog),
            cogBearingDeg = gpsData.cog.toFloat()
        )
        if (!conditionsLoaded) {
            conditionsLoaded = true
            viewModel.loadConditions(gpsData.latitude, gpsData.longitude)
        }
    }
}
```

- [ ] **Step 7.3: Update observeDataSources() — marine conditions collector**

Replace the `viewModel.marineConditions` collector block:
```kotlin
lifecycleScope.launch {
    viewModel.marineConditions.collect { c ->
        if (c == null) return@collect
        instrumentHandler?.updateDisplay(
            tws = c.windSpeedKt?.let { "%.1f".format(Locale.getDefault(), it) },
            twsBearingDeg = c.windDirDeg?.toFloat()
        )
        instrumentHandler?.updateConditions(
            currSpd      = c.currentSpeedKt?.let { "%.1f".format(Locale.getDefault(), it) } ?: "—",
            currDirDeg   = c.currentDirDeg?.toFloat(),
            waveHeightM  = c.waveHeightM,
            waveDirDeg   = c.waveDirDeg?.toFloat(),
            swellHeightM = c.swellHeightM,
            swellDirDeg  = c.swellDirDeg?.toFloat(),
            swellPeriodS = c.swellPeriodS
        )
        // Drive wave animation with forecast data (convert M→ft here)
        val swellHtFt  = c.swellHeightM?.let { (it * 3.28084f).toFloat() } ?: 3f
        val windHtFt   = c.waveHeightM?.let  { (it * 3.28084f).toFloat() } ?: 1.5f
        val swellPeriod = c.swellPeriodS?.toFloat() ?: 10f
        instrumentHandler?.updateWaveState(swellHtFt, swellPeriod, windHtFt)
    }
}
```

- [ ] **Step 7.4: Wire depth display from NMEA flow**

Add a new collector inside `observeDataSources()` (after the barometer collector):
```kotlin
lifecycleScope.launch {
    LocationService.nmeaDepthDataFlow.collect { depthData ->
        instrumentHandler?.updateDisplay(depthM = depthData.depthMeters)
    }
}
```

- [ ] **Step 7.5: Build — expect clean compile**

```bash
cd android-app && ./gradlew assembleDebug 2>&1 | tail -20
```
Expected: `BUILD SUCCESSFUL` with no errors.

- [ ] **Step 7.6: Run all unit tests**

```bash
cd android-app && ./gradlew test 2>&1 | tail -30
```
Expected: All tests pass. Verify `InstrumentHandlerTest` (6 tests) and `DirectionArrowViewTest` (3 tests) are listed.

- [ ] **Step 7.7: Commit**

```bash
git add android-app/app/src/main/kotlin/org/terst/nav/MainActivity.kt
git commit -m "feat(ui): wire redesigned instrument sheet — direction arrows, wave state, depth display, feet units"
```

---

## Self-Review Checklist

| Spec requirement | Task |
|---|---|
| Wave divider — swell sine + wind noise + whitecaps | Task 4 (WaveView) |
| Wave divider — sky gradient above, ocean below | Task 4 (WaveView.onSizeChanged) |
| Wave divider data-driven (height, period) | Task 6 updateWaveState + Task 7 |
| Direction arrows inline with numeric values | Task 5 layout + Task 6 InstrumentHandler |
| Mini arrows in forecast section, ocean-tinted | Task 6 InstrumentHandler.init |
| `°` as part of HDG/COG value, not unit label | Task 5 layout (no unit TextView for these), Task 7 COG format |
| AWS/TWS direction arrows driven from forecast | Task 7 (twsBearingDeg from windDirDeg) |
| Forecast cell layout: value / [arrow] bearing | Task 5 layout |
| Swell period on direction line | Task 5 layout (value_swell_per in dir row) |
| Depth in feet | Task 6 (metresToFeet in updateDisplay) |
| Wave/swell heights in feet | Task 6 (metresToFeet in updateConditions) |
| Remove reports section | Task 1 |
| Prevent map touch-through | Task 1 (clickable/focusable on root) |
| Depth now actually displayed (was unconnected) | Task 7 Step 7.4 |
| "Waves" label (not "Wave") | Task 5 layout |
| "Current" label (not "Curr") | Task 5 layout |
| No "FORECAST" section header | Task 5 layout (absent) |