summaryrefslogtreecommitdiff
path: root/android-app/app/src/main/kotlin/org/terst/nav/MainActivity.kt
diff options
context:
space:
mode:
Diffstat (limited to 'android-app/app/src/main/kotlin/org/terst/nav/MainActivity.kt')
-rw-r--r--android-app/app/src/main/kotlin/org/terst/nav/MainActivity.kt19
1 files changed, 8 insertions, 11 deletions
diff --git a/android-app/app/src/main/kotlin/org/terst/nav/MainActivity.kt b/android-app/app/src/main/kotlin/org/terst/nav/MainActivity.kt
index f887a43..f9d4dbd 100644
--- a/android-app/app/src/main/kotlin/org/terst/nav/MainActivity.kt
+++ b/android-app/app/src/main/kotlin/org/terst/nav/MainActivity.kt
@@ -22,7 +22,10 @@ import com.google.android.material.bottomsheet.BottomSheetBehavior
import com.google.android.material.floatingactionbutton.FloatingActionButton
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.delay
+import kotlinx.coroutines.flow.MutableStateFlow
+import kotlinx.coroutines.flow.combine
import kotlinx.coroutines.flow.distinctUntilChanged
+import kotlinx.coroutines.flow.filterNotNull
import kotlinx.coroutines.flow.firstOrNull
import kotlinx.coroutines.launch
import kotlinx.coroutines.withContext
@@ -45,7 +48,7 @@ class MainActivity : AppCompatActivity(), SafetyFragment.SafetyListener {
private var instrumentHandler: InstrumentHandler? = null
private var mapHandler: MapHandler? = null
private var anchorWatchHandler: AnchorWatchHandler? = null
- private var loadedStyle: Style? = null
+ private val loadedStyleFlow = MutableStateFlow<Style?>(null)
private lateinit var bottomSheetBehavior: BottomSheetBehavior<View>
private lateinit var fragmentContainer: FrameLayout
@@ -147,17 +150,13 @@ class MainActivity : AppCompatActivity(), SafetyFragment.SafetyListener {
private fun hideOverlays() {
fragmentContainer.visibility = View.GONE
- // Clear backstack if needed
}
override fun onActivateMob() {
lifecycleScope.launch {
LocationService.locationFlow.firstOrNull()?.let { gpsData ->
val mediaPlayer = MediaPlayer.create(this@MainActivity, R.raw.mob_alarm)
- // In a real redesign, we'd show a specialized MOB fragment
- // For now, keep existing handler logic but maybe toggle visibility
mobHandler?.activateMob(gpsData.latitude, gpsData.longitude, mediaPlayer)
- // Ensure MOB UI is visible - we might need to add it back to activity_main if removed
}
}
}
@@ -167,7 +166,6 @@ class MainActivity : AppCompatActivity(), SafetyFragment.SafetyListener {
}
private fun setupHandlers() {
- // ... (Keep existing handler initialization, just update view IDs as needed)
instrumentHandler = InstrumentHandler(
valueAws = findViewById(R.id.value_aws),
valueTws = findViewById(R.id.value_tws),
@@ -243,7 +241,7 @@ class MainActivity : AppCompatActivity(), SafetyFragment.SafetyListener {
.withLayer(RasterLayer("openseamap-layer", "openseamap-source"))
maplibreMap.setStyle(style) { style ->
- loadedStyle = style
+ loadedStyleFlow.value = style
val anchorBitmap = rasterizeDrawable(R.drawable.ic_anchor)
val arrowBitmap = rasterizeDrawable(R.drawable.ic_tidal_arrow)
mapHandler?.setupLayers(style, anchorBitmap, arrowBitmap)
@@ -265,10 +263,9 @@ class MainActivity : AppCompatActivity(), SafetyFragment.SafetyListener {
}
}
lifecycleScope.launch {
- viewModel.trackPoints.collect { points ->
- val style = loadedStyle ?: return@collect
- mapHandler?.updateTrackLayer(style, points)
- }
+ loadedStyleFlow.filterNotNull()
+ .combine(viewModel.trackPoints) { style, points -> style to points }
+ .collect { (style, points) -> mapHandler?.updateTrackLayer(style, points) }
}
}