Keep position on screen rotation

Signed-off-by: Marcel Hibbe <dev@mhibbe.de>
This commit is contained in:
Marcel Hibbe 2023-03-29 12:25:11 +02:00
parent f323049815
commit 4ab3d78458
No known key found for this signature in database
GPG Key ID: C793F8B59F43CE7B

View File

@ -108,6 +108,10 @@ class LocationPickerActivity :
var moveToCurrentLocation: Boolean = true var moveToCurrentLocation: Boolean = true
var readyToShareLocation: Boolean = false var readyToShareLocation: Boolean = false
private var mapCenterLat: Double = 0.0
private var mapCenterLon: Double = 0.0
var searchItem: MenuItem? = null var searchItem: MenuItem? = null
var searchView: SearchView? = null var searchView: SearchView? = null
@ -115,6 +119,12 @@ class LocationPickerActivity :
super.onCreate(savedInstanceState) super.onCreate(savedInstanceState)
NextcloudTalkApplication.sharedApplication!!.componentApplication.inject(this) NextcloudTalkApplication.sharedApplication!!.componentApplication.inject(this)
if (savedInstanceState != null) {
moveToCurrentLocation = savedInstanceState.getBoolean("moveToCurrentLocation") == true
mapCenterLat = savedInstanceState.getDouble("mapCenterLat")
mapCenterLon = savedInstanceState.getDouble("mapCenterLon")
}
binding = ActivityLocationBinding.inflate(layoutInflater) binding = ActivityLocationBinding.inflate(layoutInflater)
setupActionBar() setupActionBar()
setupSystemColors() setupSystemColors()
@ -153,6 +163,13 @@ class LocationPickerActivity :
} }
} }
override fun onSaveInstanceState(bundle: Bundle) {
super.onSaveInstanceState(bundle)
bundle.putBoolean("moveToCurrentLocation", moveToCurrentLocation)
bundle.putDouble("mapCenterLat", binding.map.mapCenter.latitude)
bundle.putDouble("mapCenterLon", binding.map.mapCenter.longitude)
}
private fun setupActionBar() { private fun setupActionBar() {
setSupportActionBar(binding.locationPickerToolbar) setSupportActionBar(binding.locationPickerToolbar)
binding.locationPickerToolbar.setNavigationOnClickListener { binding.locationPickerToolbar.setNavigationOnClickListener {
@ -273,6 +290,10 @@ class LocationPickerActivity :
mapController.setZoom(ZOOM_LEVEL_DEFAULT) mapController.setZoom(ZOOM_LEVEL_DEFAULT)
} }
if (mapCenterLat != 0.0 && mapCenterLon != 0.0) {
mapController.setCenter(GeoPoint(mapCenterLat, mapCenterLon))
}
val zoomToCurrentPositionOnFirstFix = geocodingResult == null && moveToCurrentLocation val zoomToCurrentPositionOnFirstFix = geocodingResult == null && moveToCurrentLocation
locationOverlay.runOnFirstFix { locationOverlay.runOnFirstFix {
if (locationOverlay.myLocation != null) { if (locationOverlay.myLocation != null) {