summaryrefslogtreecommitdiff
path: root/android-app
diff options
context:
space:
mode:
authorClaude <noreply@anthropic.com>2026-05-26 05:13:48 +0000
committerClaude <noreply@anthropic.com>2026-05-26 05:13:48 +0000
commite34df09b96f4ded3c25c5a14a0332a874205b64a (patch)
treef510434fa59ad8221d2f74cfc986fcc8d12a0433 /android-app
parentd35410c707900075bf4207bab518ead44d43c6e7 (diff)
Add notes to finished tracks, single Nav voice, fix speed coloring
- TrackDetailSheet: + Add note button opens a dialog with text, camera, and gallery. Entry is saved with timestampMs=track.endMs so it lands inside the track's time window and appears automatically in the event log. logEventAdapter.update() refreshes the list after save. - TripReportGenerator: removed NarrativeStyle enum and 4-style branch. generateNarrative() now emits a concise PASSAGE header (date, time range, duration), stats line (nm / avg kt / max kt), optional conditions (seas, temp), and a timestamped deck log. Fragment and layout updated to remove the ChipGroup style picker. - TrackColors: replaced Expression.get("color") — which silently fails for lineColor on LineLayer in MapLibre Android 11.x — with Expression.step(Expression.get("speed"), ...) that maps the numeric "speed" property directly to color literals. "color" string property removed from speedSegments() features. https://claude.ai/code/session_01YUbuZNDAoLea4cf9UGQ9qn
Diffstat (limited to 'android-app')
-rw-r--r--android-app/app/src/main/kotlin/org/terst/nav/track/TrackColors.kt26
-rw-r--r--android-app/app/src/main/kotlin/org/terst/nav/track/TrackDetailSheet.kt143
-rw-r--r--android-app/app/src/main/kotlin/org/terst/nav/tripreport/TripReportFragment.kt20
-rw-r--r--android-app/app/src/main/kotlin/org/terst/nav/tripreport/TripReportGenerator.kt114
-rw-r--r--android-app/app/src/main/kotlin/org/terst/nav/tripreport/TripReportViewModel.kt12
-rw-r--r--android-app/app/src/main/res/layout/dialog_add_track_note.xml69
-rw-r--r--android-app/app/src/main/res/layout/fragment_trip_report.xml62
-rw-r--r--android-app/app/src/main/res/layout/layout_track_detail_sheet.xml35
-rw-r--r--android-app/app/src/test/kotlin/org/terst/nav/tripreport/TripReportGeneratorTest.kt32
9 files changed, 340 insertions, 173 deletions
diff --git a/android-app/app/src/main/kotlin/org/terst/nav/track/TrackColors.kt b/android-app/app/src/main/kotlin/org/terst/nav/track/TrackColors.kt
index 292240a..5e5e85d 100644
--- a/android-app/app/src/main/kotlin/org/terst/nav/track/TrackColors.kt
+++ b/android-app/app/src/main/kotlin/org/terst/nav/track/TrackColors.kt
@@ -5,17 +5,9 @@ import org.maplibre.geojson.Feature
import org.maplibre.geojson.LineString
import org.maplibre.geojson.Point
-private fun speedToHex(speedKt: Double): String = when {
- speedKt >= 13 -> "#F44336" // red
- speedKt >= 10 -> "#FFC107" // amber
- speedKt >= 7 -> "#4CAF50" // green
- speedKt >= 4 -> "#00BCD4" // cyan
- else -> "#2196F3" // blue
-}
-
/**
* Breaks [points] into consecutive 2-point LineString Features.
- * Each feature carries "speed" (knots) and "color" (CSS hex) properties.
+ * Each feature carries a numeric "speed" property (knots) for data-driven coloring.
*/
fun speedSegments(points: List<TrackPoint>): List<Feature> =
(0 until points.size - 1).map { i ->
@@ -27,12 +19,20 @@ fun speedSegments(points: List<TrackPoint>): List<Feature> =
))
).apply {
addNumberProperty("speed", sog)
- addStringProperty("color", speedToHex(sog))
}
}
/**
- * Returns the lineColor expression for speed-colored segments.
- * Reads the pre-computed "color" string property from each feature.
+ * Returns a step expression mapping the "speed" numeric property to a color.
+ * Uses Expression.step() which reads the numeric property directly, avoiding
+ * the silent failure of Expression.get("color") for string properties on LineLayer
+ * in MapLibre Android 11.x.
*/
-fun speedColorExpression(): Expression = Expression.get("color")
+fun speedColorExpression(): Expression = Expression.step(
+ Expression.get("speed"),
+ Expression.literal("#2196F3"), // < 4 kt: blue
+ Expression.stop(4, Expression.literal("#00BCD4")), // 4–7 kt: cyan
+ Expression.stop(7, Expression.literal("#4CAF50")), // 7–10 kt: green
+ Expression.stop(10, Expression.literal("#FFC107")), // 10–13 kt: amber
+ Expression.stop(13, Expression.literal("#F44336")) // 13+ kt: red
+)
diff --git a/android-app/app/src/main/kotlin/org/terst/nav/track/TrackDetailSheet.kt b/android-app/app/src/main/kotlin/org/terst/nav/track/TrackDetailSheet.kt
index 25e7b15..1d92e18 100644
--- a/android-app/app/src/main/kotlin/org/terst/nav/track/TrackDetailSheet.kt
+++ b/android-app/app/src/main/kotlin/org/terst/nav/track/TrackDetailSheet.kt
@@ -1,17 +1,31 @@
package org.terst.nav.track
+import android.app.Activity
+import android.app.AlertDialog
+import android.content.Intent
import android.graphics.BitmapFactory
+import android.net.Uri
import android.os.Bundle
+import android.provider.MediaStore
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
+import android.widget.Button
+import android.widget.EditText
+import android.widget.FrameLayout
import android.widget.ImageView
import android.widget.TextView
+import androidx.activity.result.contract.ActivityResultContracts
+import androidx.core.content.FileProvider
import androidx.fragment.app.Fragment
import androidx.fragment.app.activityViewModels
+import androidx.lifecycle.lifecycleScope
import androidx.recyclerview.widget.DividerItemDecoration
import androidx.recyclerview.widget.LinearLayoutManager
import androidx.recyclerview.widget.RecyclerView
+import kotlinx.coroutines.Dispatchers
+import kotlinx.coroutines.launch
+import kotlinx.coroutines.withContext
import org.maplibre.android.camera.CameraUpdateFactory
import org.maplibre.android.geometry.LatLng
import org.maplibre.android.geometry.LatLngBounds
@@ -28,8 +42,11 @@ import org.maplibre.geojson.LineString
import org.maplibre.geojson.Point
import org.terst.nav.NavApplication
import org.terst.nav.R
+import org.terst.nav.logbook.EntryType
+import org.terst.nav.logbook.LogEntry
import org.terst.nav.ui.MainViewModel
import java.io.File
+import java.io.FileOutputStream
import java.time.Instant
import java.time.ZoneId
import java.time.format.DateTimeFormatter
@@ -53,6 +70,52 @@ class TrackDetailSheet : Fragment() {
private lateinit var trackMapView: MapView
private var trackMap: MapLibreMap? = null
+ // Note-adding state
+ private var pendingNotePhotoPath: String? = null
+ private var noteDialogPhotoFrame: FrameLayout? = null
+ private var noteDialogPhotoView: ImageView? = null
+ private var logEventAdapter: LogEventAdapter? = null
+ private var currentTrack: SavedTrack? = null
+
+ private val noteCameraLauncher = registerForActivityResult(
+ ActivityResultContracts.StartActivityForResult()
+ ) { result ->
+ if (result.resultCode == Activity.RESULT_OK) {
+ val path = pendingNotePhotoPath ?: return@registerForActivityResult
+ val bm = BitmapFactory.decodeFile(path)
+ if (bm != null) noteDialogPhotoView?.setImageBitmap(bm)
+ else noteDialogPhotoView?.setImageURI(Uri.fromFile(File(path)))
+ noteDialogPhotoFrame?.visibility = View.VISIBLE
+ } else {
+ pendingNotePhotoPath?.let { File(it).delete() }
+ pendingNotePhotoPath = null
+ }
+ }
+
+ private val noteGalleryLauncher = registerForActivityResult(
+ ActivityResultContracts.GetContent()
+ ) { uri: Uri? ->
+ if (uri != null) {
+ lifecycleScope.launch {
+ val path = withContext(Dispatchers.IO) {
+ runCatching {
+ val dir = NavApplication.logbookRepository.photoDir
+ val dest = File(dir, "log_${System.currentTimeMillis()}.jpg")
+ requireContext().contentResolver.openInputStream(uri)?.use { inp ->
+ FileOutputStream(dest).use { out -> inp.copyTo(out) }
+ }
+ dest.absolutePath
+ }.getOrNull()
+ }
+ if (path != null) {
+ pendingNotePhotoPath = path
+ noteDialogPhotoView?.setImageURI(Uri.fromFile(File(path)))
+ noteDialogPhotoFrame?.visibility = View.VISIBLE
+ }
+ }
+ }
+ }
+
companion object {
fun newInstance() = TrackDetailSheet()
}
@@ -65,6 +128,7 @@ class TrackDetailSheet : Fragment() {
parentFragmentManager.popBackStack()
return
}
+ currentTrack = track
view.findViewById<View>(R.id.btn_back).setOnClickListener {
parentFragmentManager.popBackStack()
@@ -88,9 +152,14 @@ class TrackDetailSheet : Fragment() {
val rv = view.findViewById<RecyclerView>(R.id.rv_log_entries)
rv.layoutManager = LinearLayoutManager(requireContext())
rv.addItemDecoration(DividerItemDecoration(requireContext(), DividerItemDecoration.VERTICAL))
- rv.adapter = LogEventAdapter(events) { event ->
+ logEventAdapter = LogEventAdapter(events) { event ->
trackMap?.easeCamera(CameraUpdateFactory.newLatLng(LatLng(event.lat, event.lon)), 300)
}
+ rv.adapter = logEventAdapter
+
+ view.findViewById<View>(R.id.btn_add_note).setOnClickListener {
+ showAddNoteDialog(track)
+ }
trackMapView = view.findViewById(R.id.track_map_view)
trackMapView.onCreate(savedInstanceState)
@@ -106,6 +175,67 @@ class TrackDetailSheet : Fragment() {
}
}
+ private fun showAddNoteDialog(track: SavedTrack) {
+ val dialogView = LayoutInflater.from(requireContext())
+ .inflate(R.layout.dialog_add_track_note, null)
+ val etNote = dialogView.findViewById<EditText>(R.id.et_note_text)
+ noteDialogPhotoFrame = dialogView.findViewById(R.id.frame_note_photo)
+ noteDialogPhotoView = dialogView.findViewById(R.id.iv_note_photo)
+ pendingNotePhotoPath = null
+ noteDialogPhotoFrame?.visibility = View.GONE
+
+ dialogView.findViewById<Button>(R.id.btn_note_camera).setOnClickListener {
+ val file = File(NavApplication.logbookRepository.photoDir, "log_${System.currentTimeMillis()}.jpg")
+ pendingNotePhotoPath = file.absolutePath
+ val uri = FileProvider.getUriForFile(
+ requireContext(), "${requireContext().packageName}.fileprovider", file
+ )
+ val intent = Intent(MediaStore.ACTION_IMAGE_CAPTURE).apply {
+ putExtra(MediaStore.EXTRA_OUTPUT, uri)
+ addFlags(Intent.FLAG_GRANT_WRITE_URI_PERMISSION)
+ }
+ noteCameraLauncher.launch(intent)
+ }
+
+ dialogView.findViewById<Button>(R.id.btn_note_gallery).setOnClickListener {
+ noteGalleryLauncher.launch("image/*")
+ }
+
+ dialogView.findViewById<Button>(R.id.btn_note_remove_photo).setOnClickListener {
+ pendingNotePhotoPath?.let { File(it).delete() }
+ pendingNotePhotoPath = null
+ noteDialogPhotoView?.setImageDrawable(null)
+ noteDialogPhotoFrame?.visibility = View.GONE
+ }
+
+ AlertDialog.Builder(requireContext())
+ .setTitle("Add note to track")
+ .setView(dialogView)
+ .setPositiveButton("Save") { _, _ ->
+ val text = etNote.text?.toString()?.trim() ?: ""
+ val path = pendingNotePhotoPath
+ if (text.isBlank() && path == null) return@setPositiveButton
+ val anchor = track.points.lastOrNull()
+ NavApplication.logbookRepository.save(
+ LogEntry(
+ timestampMs = track.endMs,
+ text = text.ifBlank { "(photo only)" },
+ entryType = EntryType.GENERAL,
+ lat = anchor?.lat,
+ lon = anchor?.lon,
+ photoPath = path
+ )
+ )
+ pendingNotePhotoPath = null
+ logEventAdapter?.update(buildLogEvents(track))
+ }
+ .setNegativeButton("Cancel") { _, _ ->
+ pendingNotePhotoPath?.let { File(it).delete() }
+ pendingNotePhotoPath = null
+ }
+ .show()
+ }
+
private fun drawTrack(style: Style, points: List<TrackPoint>) {
if (points.size < 2) return
val source = GeoJsonSource("track-detail-source",
@@ -171,6 +301,8 @@ class TrackDetailSheet : Fragment() {
}
override fun onDestroyView() {
+ noteDialogPhotoFrame = null
+ noteDialogPhotoView = null
if (::trackMapView.isInitialized) trackMapView.onDestroy()
super.onDestroyView()
viewModel.clearSelectedTrack()
@@ -195,7 +327,7 @@ class TrackDetailSheet : Fragment() {
"%.0f° → %.0f° (Δ%.0f°)".format(t.cogBefore, t.cogAfter, abs(delta)))
}
- // Log entries saved during this track's time window
+ // Log entries saved during or associated with this track's time window
val logEntries = NavApplication.logbookRepository.getAll()
.filter { it.timestampMs in track.startMs..track.endMs }
for (entry in logEntries) {
@@ -229,10 +361,15 @@ private val TIME_FMT: DateTimeFormatter =
.withZone(ZoneId.systemDefault())
private class LogEventAdapter(
- private val events: List<LogEvent>,
+ private var events: List<LogEvent>,
private val onTap: (LogEvent) -> Unit
) : RecyclerView.Adapter<LogEventAdapter.VH>() {
+ fun update(newEvents: List<LogEvent>) {
+ events = newEvents
+ notifyDataSetChanged()
+ }
+
inner class VH(view: View) : RecyclerView.ViewHolder(view) {
val tvIcon = view.findViewById<TextView>(R.id.tv_log_icon)
val tvTime = view.findViewById<TextView>(R.id.tv_log_time)
diff --git a/android-app/app/src/main/kotlin/org/terst/nav/tripreport/TripReportFragment.kt b/android-app/app/src/main/kotlin/org/terst/nav/tripreport/TripReportFragment.kt
index e7a425f..632f616 100644
--- a/android-app/app/src/main/kotlin/org/terst/nav/tripreport/TripReportFragment.kt
+++ b/android-app/app/src/main/kotlin/org/terst/nav/tripreport/TripReportFragment.kt
@@ -9,7 +9,6 @@ import android.widget.TextView
import androidx.fragment.app.Fragment
import androidx.lifecycle.lifecycleScope
import com.google.android.material.button.MaterialButton
-import com.google.android.material.chip.ChipGroup
import kotlinx.coroutines.launch
import org.terst.nav.NavApplication
import org.terst.nav.R
@@ -18,14 +17,13 @@ class TripReportFragment : Fragment() {
private val viewModel by lazy {
TripReportViewModel(
- trackRepository = NavApplication.trackRepository,
+ trackRepository = NavApplication.trackRepository,
logbookRepository = NavApplication.logbookRepository
)
}
private lateinit var tvNarrativeContent: TextView
private lateinit var btnRefresh: MaterialButton
- private lateinit var chipGroup: ChipGroup
private lateinit var progress: ProgressBar
override fun onCreateView(
@@ -38,27 +36,15 @@ class TripReportFragment : Fragment() {
super.onViewCreated(view, savedInstanceState)
tvNarrativeContent = view.findViewById(R.id.tv_narrative_content)
- btnRefresh = view.findViewById(R.id.btn_refresh_report)
- chipGroup = view.findViewById(R.id.chip_group_styles)
- progress = view.findViewById(R.id.progress_report)
+ btnRefresh = view.findViewById(R.id.btn_refresh_report)
+ progress = view.findViewById(R.id.progress_report)
btnRefresh.setOnClickListener { viewModel.generateReport() }
- chipGroup.setOnCheckedStateChangeListener { _, checkedIds ->
- val style = when (checkedIds.firstOrNull()) {
- R.id.chip_adventurous -> NarrativeStyle.ADVENTUROUS
- R.id.chip_journal -> NarrativeStyle.JOURNAL
- R.id.chip_pirate -> NarrativeStyle.PIRATE
- else -> NarrativeStyle.PROFESSIONAL
- }
- viewModel.setStyle(style)
- }
-
viewLifecycleOwner.lifecycleScope.launch {
viewModel.state.collect { state -> renderState(state) }
}
- // Initial generation
viewModel.generateReport()
}
diff --git a/android-app/app/src/main/kotlin/org/terst/nav/tripreport/TripReportGenerator.kt b/android-app/app/src/main/kotlin/org/terst/nav/tripreport/TripReportGenerator.kt
index bbf00b1..2c7f77f 100644
--- a/android-app/app/src/main/kotlin/org/terst/nav/tripreport/TripReportGenerator.kt
+++ b/android-app/app/src/main/kotlin/org/terst/nav/tripreport/TripReportGenerator.kt
@@ -2,13 +2,10 @@ package org.terst.nav.tripreport
import org.terst.nav.logbook.LogEntry
import org.terst.nav.track.TrackPoint
-
-enum class NarrativeStyle {
- PROFESSIONAL,
- ADVENTUROUS,
- JOURNAL,
- PIRATE
-}
+import java.time.Instant
+import java.time.ZoneId
+import java.time.format.DateTimeFormatter
+import java.util.Locale
data class TripSummary(
val startTimeMs: Long,
@@ -32,12 +29,12 @@ class TripReportGenerator {
val startTime = points.first().timestampMs
val endTime = points.last().timestampMs
-
+
var totalDist = 0.0
for (i in 0 until points.size - 1) {
totalDist += calculateDistance(points[i].lat, points[i].lon, points[i+1].lat, points[i+1].lon)
}
- val distanceNm = totalDist / 1852.0 // meters to nautical miles
+ val distanceNm = totalDist / 1852.0
val maxSog = points.maxOf { it.sogKnots }
val avgSog = points.map { it.sogKnots }.average()
@@ -48,21 +45,21 @@ class TripReportGenerator {
val maxWave = points.mapNotNull { it.waveHeightM }.maxOrNull()
return TripSummary(
- startTimeMs = startTime,
- endTimeMs = endTime,
- distanceNm = distanceNm,
- maxSogKts = maxSog,
- avgSogKts = avgSog,
- minAirTempC = minTemp,
- maxAirTempC = maxTemp,
- maxWaveHeightM = maxWave,
- logEntries = logEntries.filter { it.timestampMs in startTime..endTime },
- points = points
+ startTimeMs = startTime,
+ endTimeMs = endTime,
+ distanceNm = distanceNm,
+ maxSogKts = maxSog,
+ avgSogKts = avgSog,
+ minAirTempC = minTemp,
+ maxAirTempC = maxTemp,
+ maxWaveHeightM = maxWave,
+ logEntries = logEntries.filter { it.timestampMs in startTime..endTime },
+ points = points
)
}
private fun calculateDistance(lat1: Double, lon1: Double, lat2: Double, lon2: Double): Double {
- val r = 6371e3 // Earth radius in meters
+ val r = 6371e3
val phi1 = Math.toRadians(lat1)
val phi2 = Math.toRadians(lat2)
val deltaPhi = Math.toRadians(lat2 - lat1)
@@ -76,42 +73,51 @@ class TripReportGenerator {
return r * c
}
- fun generateNarrative(summary: TripSummary, style: NarrativeStyle): String {
- val durationHrs = (summary.endTimeMs - summary.startTimeMs) / 3600000.0
- val baseFactualString = "Trip from ${java.util.Date(summary.startTimeMs)} to ${java.util.Date(summary.endTimeMs)}. " +
- "Distance: %.1f nm. Max SOG: %.1f kts. Avg SOG: %.1f kts. ".format(summary.distanceNm, summary.maxSogKts, summary.avgSogKts) +
- (summary.maxWaveHeightM?.let { "Max waves: %.1fm. ".format(it) } ?: "") +
- "Events: ${summary.logEntries.joinToString { it.text }}"
-
- return when (style) {
- NarrativeStyle.PROFESSIONAL -> {
- "VOYAGE SUMMARY\n" +
- "Duration: %.1f hours\n".format(durationHrs) +
- "Total Distance: %.1f NM\n".format(summary.distanceNm) +
- "Vessel Performance: Avg Speed %.1f kts, Max Speed %.1f kts\n".format(summary.avgSogKts, summary.maxSogKts) +
- "Meteorological Data: " + (summary.maxWaveHeightM?.let { "Significant wave height reached %.1fm." .format(it)} ?: "No wave data recorded.") + "\n" +
- "Key Events:\n" + summary.logEntries.joinToString("\n") { "- ${it.text}" }
- }
- NarrativeStyle.ADVENTUROUS -> {
- "WHAT A TRIP! We covered %.1f nautical miles of open water.\n".format(summary.distanceNm) +
- "We hit a top speed of %.1f knots! ".format(summary.maxSogKts) +
- (summary.maxWaveHeightM?.let { "The sea was alive with waves up to %.1fm high! ".format(it) } ?: "") + "\n" +
- "During our journey, we logged some great moments:\n" +
- summary.logEntries.joinToString("\n") { "🔥 ${it.text}" }
- }
- NarrativeStyle.JOURNAL -> {
- "Reflecting on our time at sea. We traveled %.1f miles over %.1f hours.\n".format(summary.distanceNm, durationHrs) +
- "The average pace was steady at %.1f knots. ".format(summary.avgSogKts) +
- "I remember writing down: " + summary.logEntries.firstOrNull()?.text + "... " +
- "It was a meaningful passage."
+ fun generateNarrative(summary: TripSummary): String {
+ val zone = ZoneId.systemDefault()
+ val dateFmt = DateTimeFormatter.ofPattern("dd MMM yyyy", Locale.getDefault()).withZone(zone)
+ val timeFmt = DateTimeFormatter.ofPattern("HHmm", Locale.getDefault()).withZone(zone)
+ val startInst = Instant.ofEpochMilli(summary.startTimeMs)
+ val endInst = Instant.ofEpochMilli(summary.endTimeMs)
+
+ val durationMs = summary.endTimeMs - summary.startTimeMs
+ val durationStr = if (durationMs >= 3_600_000) {
+ val h = durationMs / 3_600_000
+ val m = (durationMs % 3_600_000) / 60_000
+ "${h}h ${m}m"
+ } else {
+ "${durationMs / 60_000}m"
+ }
+
+ val sb = StringBuilder()
+ sb.appendLine("PASSAGE · ${dateFmt.format(startInst).uppercase(Locale.getDefault())}")
+ sb.appendLine("${timeFmt.format(startInst)}–${timeFmt.format(endInst)} · $durationStr")
+ sb.appendLine()
+ sb.appendLine("%.1f nm avg %.1f kt max %.1f kt".format(
+ summary.distanceNm, summary.avgSogKts, summary.maxSogKts))
+
+ val conditions = buildList<String> {
+ summary.maxWaveHeightM?.let { add("seas %.1f m".format(it)) }
+ val minT = summary.minAirTempC
+ val maxT = summary.maxAirTempC
+ if (minT != null && maxT != null) {
+ add(if (minT == maxT) "%.0f°C".format(minT) else "%.0f–%.0f°C".format(minT, maxT))
}
- NarrativeStyle.PIRATE -> {
- "AHOY! We've sailed %.1f leagues (well, nautical miles) across the briney deep!\n".format(summary.distanceNm) +
- "The wind caught our sails and we flew at %.1f knots!\n".format(summary.maxSogKts) +
- "Listen to the tales from the log:\n" +
- summary.logEntries.joinToString("\n") { "🏴‍☠️ ${it.text}" } + "\n" +
- "Arr, it was a fine voyage indeed!"
+ }
+ if (conditions.isNotEmpty()) {
+ sb.appendLine()
+ sb.appendLine(conditions.joinToString(" "))
+ }
+
+ if (summary.logEntries.isNotEmpty()) {
+ sb.appendLine()
+ for (entry in summary.logEntries.sortedBy { it.timestampMs }) {
+ val time = timeFmt.format(Instant.ofEpochMilli(entry.timestampMs))
+ val photoMarker = if (entry.photoPath != null) " [photo]" else ""
+ sb.appendLine("$time ${entry.text}$photoMarker")
}
}
+
+ return sb.toString().trimEnd()
}
}
diff --git a/android-app/app/src/main/kotlin/org/terst/nav/tripreport/TripReportViewModel.kt b/android-app/app/src/main/kotlin/org/terst/nav/tripreport/TripReportViewModel.kt
index 45cbed5..603d769 100644
--- a/android-app/app/src/main/kotlin/org/terst/nav/tripreport/TripReportViewModel.kt
+++ b/android-app/app/src/main/kotlin/org/terst/nav/tripreport/TripReportViewModel.kt
@@ -25,14 +25,6 @@ class TripReportViewModel(
private val _state = MutableStateFlow<TripReportState>(TripReportState.Idle)
val state: StateFlow<TripReportState> = _state.asStateFlow()
- private val _selectedStyle = MutableStateFlow(NarrativeStyle.PROFESSIONAL)
- val selectedStyle: StateFlow<NarrativeStyle> = _selectedStyle.asStateFlow()
-
- fun setStyle(style: NarrativeStyle) {
- _selectedStyle.value = style
- generateReport()
- }
-
fun generateReport() {
viewModelScope.launch {
_state.value = TripReportState.Loading
@@ -43,8 +35,8 @@ class TripReportViewModel(
return@launch
}
val logEntries = logbookRepository.getAll()
- val summary = generator.generateSummary(points, logEntries)
- val narrative = generator.generateNarrative(summary, _selectedStyle.value)
+ val summary = generator.generateSummary(points, logEntries)
+ val narrative = generator.generateNarrative(summary)
_state.value = TripReportState.Success(summary, narrative)
} catch (e: Exception) {
_state.value = TripReportState.Error(e.message ?: "Unknown error generating report")
diff --git a/android-app/app/src/main/res/layout/dialog_add_track_note.xml b/android-app/app/src/main/res/layout/dialog_add_track_note.xml
new file mode 100644
index 0000000..639a27a
--- /dev/null
+++ b/android-app/app/src/main/res/layout/dialog_add_track_note.xml
@@ -0,0 +1,69 @@
+<?xml version="1.0" encoding="utf-8"?>
+<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
+ android:layout_width="match_parent"
+ android:layout_height="wrap_content"
+ android:orientation="vertical"
+ android:padding="16dp">
+
+ <EditText
+ android:id="@+id/et_note_text"
+ android:layout_width="match_parent"
+ android:layout_height="wrap_content"
+ android:hint="Note"
+ android:minLines="3"
+ android:gravity="top|start"
+ android:inputType="textMultiLine"
+ android:padding="8dp" />
+
+ <LinearLayout
+ android:layout_width="match_parent"
+ android:layout_height="wrap_content"
+ android:orientation="horizontal"
+ android:layout_marginTop="12dp">
+
+ <Button
+ android:id="@+id/btn_note_camera"
+ android:layout_width="0dp"
+ android:layout_height="wrap_content"
+ android:layout_weight="1"
+ android:text="Camera"
+ android:layout_marginEnd="4dp" />
+
+ <Button
+ android:id="@+id/btn_note_gallery"
+ android:layout_width="0dp"
+ android:layout_height="wrap_content"
+ android:layout_weight="1"
+ android:text="Gallery"
+ android:layout_marginStart="4dp" />
+
+ </LinearLayout>
+
+ <FrameLayout
+ android:id="@+id/frame_note_photo"
+ android:layout_width="match_parent"
+ android:layout_height="wrap_content"
+ android:layout_marginTop="8dp"
+ android:visibility="gone">
+
+ <ImageView
+ android:id="@+id/iv_note_photo"
+ android:layout_width="match_parent"
+ android:layout_height="120dp"
+ android:scaleType="centerCrop"
+ android:contentDescription="Selected photo" />
+
+ <Button
+ android:id="@+id/btn_note_remove_photo"
+ android:layout_width="wrap_content"
+ android:layout_height="wrap_content"
+ android:layout_gravity="top|end"
+ android:layout_margin="4dp"
+ android:text="✕"
+ android:textSize="10sp"
+ android:paddingHorizontal="6dp"
+ android:paddingVertical="2dp" />
+
+ </FrameLayout>
+
+</LinearLayout>
diff --git a/android-app/app/src/main/res/layout/fragment_trip_report.xml b/android-app/app/src/main/res/layout/fragment_trip_report.xml
index 1ce0bde..7228fa9 100644
--- a/android-app/app/src/main/res/layout/fragment_trip_report.xml
+++ b/android-app/app/src/main/res/layout/fragment_trip_report.xml
@@ -14,61 +14,10 @@
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
- android:text="Trip Narrative"
+ android:text="Trip Report"
android:textSize="24sp"
android:textStyle="bold"
- android:layout_marginBottom="16dp" />
-
- <TextView
- android:layout_width="wrap_content"
- android:layout_height="wrap_content"
- android:text="Choose Narrative Style:"
- android:textSize="14sp"
- android:layout_marginBottom="8dp" />
-
- <HorizontalScrollView
- android:layout_width="match_parent"
- android:layout_height="wrap_content"
- android:layout_marginBottom="24dp">
-
- <com.google.android.material.chip.ChipGroup
- android:id="@+id/chip_group_styles"
- android:layout_width="wrap_content"
- android:layout_height="wrap_content"
- app:singleSelection="true"
- app:selectionRequired="true">
-
- <com.google.android.material.chip.Chip
- android:id="@+id/chip_professional"
- style="@style/Widget.Material3.Chip.Filter"
- android:layout_width="wrap_content"
- android:layout_height="wrap_content"
- android:text="Professional"
- android:checked="true" />
-
- <com.google.android.material.chip.Chip
- android:id="@+id/chip_adventurous"
- style="@style/Widget.Material3.Chip.Filter"
- android:layout_width="wrap_content"
- android:layout_height="wrap_content"
- android:text="Adventurous" />
-
- <com.google.android.material.chip.Chip
- android:id="@+id/chip_journal"
- style="@style/Widget.Material3.Chip.Filter"
- android:layout_width="wrap_content"
- android:layout_height="wrap_content"
- android:text="Journal" />
-
- <com.google.android.material.chip.Chip
- android:id="@+id/chip_pirate"
- style="@style/Widget.Material3.Chip.Filter"
- android:layout_width="wrap_content"
- android:layout_height="wrap_content"
- android:text="Pirate" />
-
- </com.google.android.material.chip.ChipGroup>
- </HorizontalScrollView>
+ android:layout_marginBottom="24dp" />
<com.google.android.material.card.MaterialCardView
android:layout_width="match_parent"
@@ -88,8 +37,9 @@
android:id="@+id/tv_narrative_content"
android:layout_width="match_parent"
android:layout_height="wrap_content"
- android:text="Generate a report to see your story..."
- android:textSize="16sp"
+ android:text="Generate a report to see your passage summary…"
+ android:textSize="15sp"
+ android:fontFamily="monospace"
android:lineSpacingExtra="4dp" />
</LinearLayout>
@@ -100,7 +50,7 @@
android:layout_width="match_parent"
android:layout_height="60dp"
android:layout_marginTop="24dp"
- android:text="REFRESH REPORT" />
+ android:text="GENERATE REPORT" />
<ProgressBar
android:id="@+id/progress_report"
diff --git a/android-app/app/src/main/res/layout/layout_track_detail_sheet.xml b/android-app/app/src/main/res/layout/layout_track_detail_sheet.xml
index 993edf8..4a77a36 100644
--- a/android-app/app/src/main/res/layout/layout_track_detail_sheet.xml
+++ b/android-app/app/src/main/res/layout/layout_track_detail_sheet.xml
@@ -97,17 +97,36 @@
<View android:layout_width="match_parent" android:layout_height="1dp"
android:background="?attr/colorOutlineVariant" android:layout_marginHorizontal="16dp" />
- <TextView
+ <LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
- android:paddingHorizontal="20dp"
+ android:orientation="horizontal"
+ android:gravity="center_vertical"
+ android:paddingStart="20dp"
+ android:paddingEnd="8dp"
android:paddingTop="8dp"
- android:paddingBottom="4dp"
- android:text="Event Log"
- android:textSize="13sp"
- android:textAllCaps="true"
- android:letterSpacing="0.08"
- android:textColor="?attr/colorOnSurfaceVariant" />
+ android:paddingBottom="4dp">
+
+ <TextView
+ android:layout_width="0dp"
+ android:layout_height="wrap_content"
+ android:layout_weight="1"
+ android:text="Event Log"
+ android:textSize="13sp"
+ android:textAllCaps="true"
+ android:letterSpacing="0.08"
+ android:textColor="?attr/colorOnSurfaceVariant" />
+
+ <Button
+ android:id="@+id/btn_add_note"
+ style="?attr/borderlessButtonStyle"
+ android:layout_width="wrap_content"
+ android:layout_height="wrap_content"
+ android:text="+ Add note"
+ android:textSize="12sp"
+ android:paddingHorizontal="8dp" />
+
+ </LinearLayout>
<androidx.recyclerview.widget.RecyclerView
android:id="@+id/rv_log_entries"
diff --git a/android-app/app/src/test/kotlin/org/terst/nav/tripreport/TripReportGeneratorTest.kt b/android-app/app/src/test/kotlin/org/terst/nav/tripreport/TripReportGeneratorTest.kt
index eea3234..8209d1a 100644
--- a/android-app/app/src/test/kotlin/org/terst/nav/tripreport/TripReportGeneratorTest.kt
+++ b/android-app/app/src/test/kotlin/org/terst/nav/tripreport/TripReportGeneratorTest.kt
@@ -14,8 +14,8 @@ class TripReportGeneratorTest {
private fun pt(lat: Double, lon: Double, sog: Double = 5.0, ts: Long) =
TrackPoint(lat = lat, lon = lon, sogKnots = sog, cogDeg = 0.0, timestampMs = ts)
- private fun entry(ts: Long, text: String = "note") = LogEntry(
- timestampMs = ts, text = text, entryType = EntryType.GENERAL
+ private fun entry(ts: Long, text: String = "note", photoPath: String? = null) = LogEntry(
+ timestampMs = ts, text = text, entryType = EntryType.GENERAL, photoPath = photoPath
)
// ── generateSummary ───────────────────────────────────────────────────────
@@ -30,7 +30,6 @@ class TripReportGeneratorTest {
@Test
fun `distance between two points one nm apart`() {
- // 1 nm north along prime meridian ≈ 0.01667° latitude
val points = listOf(pt(0.0, 0.0, ts = 0L), pt(0.016667, 0.0, ts = 60_000L))
val s = gen.generateSummary(points, emptyList())
assertEquals(1.0, s.distanceNm, 0.02)
@@ -70,20 +69,29 @@ class TripReportGeneratorTest {
// ── generateNarrative ─────────────────────────────────────────────────────
@Test
- fun `professional narrative contains distance and speed`() {
+ fun `narrative contains passage header and distance`() {
val points = listOf(pt(0.0, 0.0, sog = 5.0, ts = 0L), pt(0.016667, 0.0, sog = 5.0, ts = 3_600_000L))
val s = gen.generateSummary(points, emptyList())
- val narrative = gen.generateNarrative(s, NarrativeStyle.PROFESSIONAL)
- assertTrue("Expected distance in narrative", narrative.contains("NM") || narrative.contains("nm"))
+ val narrative = gen.generateNarrative(s)
+ assertTrue("Expected PASSAGE header", narrative.contains("PASSAGE"))
+ assertTrue("Expected distance in nm", narrative.contains("nm"))
+ assertTrue("Expected avg speed", narrative.contains("avg"))
+ assertTrue("Expected max speed", narrative.contains("max"))
}
@Test
- fun `all narrative styles produce non-empty output`() {
+ fun `narrative includes log entry text`() {
val points = listOf(pt(0.0, 0.0, ts = 0L), pt(0.016667, 0.0, ts = 3_600_000L))
- val s = gen.generateSummary(points, listOf(entry(1_000L)))
- for (style in NarrativeStyle.values()) {
- val narrative = gen.generateNarrative(s, style)
- assertTrue("Narrative for $style should not be blank", narrative.isNotBlank())
- }
+ val s = gen.generateSummary(points, listOf(entry(1_000L, "hoisted main")))
+ val narrative = gen.generateNarrative(s)
+ assertTrue("Expected log entry in narrative", narrative.contains("hoisted main"))
+ }
+
+ @Test
+ fun `narrative marks photo entries`() {
+ val points = listOf(pt(0.0, 0.0, ts = 0L), pt(0.016667, 0.0, ts = 3_600_000L))
+ val s = gen.generateSummary(points, listOf(entry(1_000L, "crew photo", photoPath = "/some/path.jpg")))
+ val narrative = gen.generateNarrative(s)
+ assertTrue("Expected [photo] marker", narrative.contains("[photo]"))
}
}