Skip to content

Commit

Permalink
Merge branch 'fix-geouri'
Browse files Browse the repository at this point in the history
  • Loading branch information
westnordost committed Jan 20, 2025
2 parents 83c405a + 17c9603 commit 05b8ace
Show file tree
Hide file tree
Showing 5 changed files with 26 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -171,6 +171,7 @@ class MainActivity :

private lateinit var binding: ActivityMainBinding

// for freezing the map while sidebar is open
private var wasFollowingPosition: Boolean? = null
private var wasNavigationMode: Boolean? = null

Expand Down Expand Up @@ -202,6 +203,10 @@ class MainActivity :
enableEdgeToEdge()
super.onCreate(savedInstanceState)

if (savedInstanceState == null) {
handleIntent(intent)
}

LocalBroadcastManager.getInstance(this).registerReceiver(
requestLocationPermissionResultReceiver,
IntentFilter(LocationRequestFragment.REQUEST_LOCATION_PERMISSION_RESULT)
Expand Down Expand Up @@ -261,6 +266,8 @@ class MainActivity :
observe(viewModel.geoUri) { geoUri ->
if (geoUri != null) {
mapFragment?.setInitialCameraPosition(geoUri)
viewModel.isFollowingPosition.value = mapFragment?.isFollowingPosition ?: false
viewModel.isNavigationMode.value = mapFragment?.isNavigationMode ?: false
}
}
}
Expand All @@ -279,6 +286,10 @@ class MainActivity :

override fun onNewIntent(intent: Intent) {
super.onNewIntent(intent)
handleIntent(intent)
}

private fun handleIntent(intent: Intent) {
if (intent.action != Intent.ACTION_VIEW) return
val data = intent.data?.toString() ?: return
viewModel.setUri(data)
Expand All @@ -296,9 +307,6 @@ class MainActivity :
mapDataWithEditsSource.removeListener(this)
locationAvailabilityReceiver.removeListener(::updateLocationAvailability)

wasFollowingPosition = mapFragment?.isFollowingPosition
wasNavigationMode = mapFragment?.isNavigationMode

locationManager.removeUpdates()
}

Expand Down Expand Up @@ -606,7 +614,7 @@ class MainActivity :
mapFragment?.startPositionTracking()
questAutoSyncer.startPositionTracking()

setIsFollowingPosition(wasFollowingPosition ?: true)
mapFragment?.centerCurrentPositionIfFollowing()
locationManager.getCurrentLocation()
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -105,8 +105,6 @@ class MainViewModelImpl(
val zoom = if (geo.zoom == null || geo.zoom < 14) 18.0 else geo.zoom
val pos = LatLon(geo.latitude, geo.longitude)

isFollowingPosition.value = false
isNavigationMode.value = false
geoUri.value = CameraPosition(pos, 0.0, 0.0, zoom)
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import androidx.compose.material.MaterialTheme
import androidx.compose.runtime.Composable
import androidx.compose.runtime.LaunchedEffect
import androidx.compose.runtime.getValue
import androidx.compose.runtime.mutableIntStateOf
import androidx.compose.runtime.mutableStateOf

Check failure on line 12 in app/src/main/java/de/westnordost/streetcomplete/screens/main/controls/LocationStateButton.kt

View workflow job for this annotation

GitHub Actions / Kotlin

Unused import
import androidx.compose.runtime.remember
import androidx.compose.runtime.setValue
Expand Down Expand Up @@ -44,7 +45,9 @@ fun LocationStateButton(
isFollowing: Boolean = false,
enabled: Boolean = true
) {
var iconResource by remember(state) { mutableStateOf(getIcon(state, isNavigationMode)) }
var iconResource by remember(state, isNavigationMode) {
mutableIntStateOf(getIcon(state, isNavigationMode))
}

MapButton(
onClick = onClick,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -563,6 +563,15 @@ class MainMapFragment : MapFragment(), ShowsGeometryMarkers {

//region Save and restore state

override fun setInitialCameraPosition(camera: CameraPosition) {
super.setInitialCameraPosition(camera)
isFollowingPosition = false
isNavigationMode = false
if (map == null) {
saveMapState()
}
}

private fun restoreMapState() {
isFollowingPosition = prefs.mapIsFollowing
isNavigationMode = prefs.mapIsNavigationMode
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -221,7 +221,7 @@ open class MapFragment : Fragment(R.layout.fragment_map) {
map?.updateCamera(duration, requireContext().contentResolver, builder)
}

fun setInitialCameraPosition(camera: CameraPosition) {
open fun setInitialCameraPosition(camera: CameraPosition) {
if (map != null) {
map?.camera = camera
} else {
Expand Down

0 comments on commit 05b8ace

Please sign in to comment.