commit 750f32ad23fe8b840ecb91be751c3ba45bb40a8e Author: Fabio Mazza Date: Mon May 11 18:26:24 2026 +0200 Fix stupid icon bug diff --git a/app/src/main/java/it/reyboz/bustorino/fragments/GeneralMapLibreFragment.kt b/app/src/main/java/it/reyboz/bustorino/fragments/GeneralMapLibreFragment.kt index c2425bc..bdca6a9 100644 --- a/app/src/main/java/it/reyboz/bustorino/fragments/GeneralMapLibreFragment.kt +++ b/app/src/main/java/it/reyboz/bustorino/fragments/GeneralMapLibreFragment.kt @@ -229,10 +229,8 @@ abstract class GeneralMapLibreFragment: ScreenBaseFragment(), OnMapReadyCallback protected val deviceLocationStatusListener = FusedNativeLocationProvider.LocationStatusListener { isEnabled -> mapStateViewModel.locationDeviceEnabled.value = isEnabled if(locationEnabledOnDevice && !isEnabled && locationInitialized) { - context?.let{ - Toast.makeText(it,R.string.enable_location_message,Toast.LENGTH_SHORT).show() - } - setMapLocationEnabled(false) + warnLocationNotEnabledOnDevice() + //setMapLocationEnabled(false) } locationEnabledOnDevice = isEnabled } @@ -311,6 +309,12 @@ abstract class GeneralMapLibreFragment: ScreenBaseFragment(), OnMapReadyCallback super.onDestroyView() } + protected fun warnLocationNotEnabledOnDevice(){ + context?.let{ + Toast.makeText(it,R.string.enable_location_message,Toast.LENGTH_SHORT).show() + } + } + protected fun reloadMap(){ /*map?.let { Log.d("GeneralMapFragment", "RELOADING MAP") @@ -337,65 +341,8 @@ abstract class GeneralMapLibreFragment: ScreenBaseFragment(), OnMapReadyCallback fragmentListener = context } else throw RuntimeException("$context must implement CommonFragmentListener") - } - /* - protected fun restoreMapStateFromBundle(bundle: Bundle): Boolean{ - val nullDouble = -10_000.0 - var boundsRestored =false - val latCenter = bundle.getDouble("center_map_lat", nullDouble) - val lonCenter = bundle.getDouble("center_map_lon",nullDouble) - val zoom = bundle.getDouble("map_zoom", nullDouble) - val bearing = bundle.getDouble("map_bearing", nullDouble) - val tilt = bundle.getDouble("map_tilt", nullDouble) - if(lonCenter!=nullDouble &&latCenter!=nullDouble) map?.let { - val center = LatLng(latCenter, lonCenter) - val newPos = CameraPosition.Builder().target(center) - if(zoom>0) newPos.zoom(zoom) - if(bearing!=nullDouble) newPos.bearing(bearing) - if(tilt != nullDouble) newPos.tilt(tilt) - it.cameraPosition=newPos.build() - - Log.d(DEBUG_TAG, "Restored map state from Bundle, center: $center, zoom: $zoom, bearing $bearing, tilt $tilt") - boundsRestored =true - } else{ - Log.d(DEBUG_TAG, "Not restoring map state, center: $latCenter,$lonCenter; zoom: $zoom, bearing: $bearing, tilt $tilt") - } - val mStop = bundle.getBundle("shown_stop")?.let { - Stop.fromBundle(it) - } - mStop?.let { openStopInBottomSheet(it) } - return boundsRestored - } - - protected fun saveMapStateBeforePause(bundle: Bundle){ - map?.let { - val newBbox = it.projection.visibleRegion.latLngBounds - - - val cp = it.cameraPosition - bundle.putDouble("center_map_lat", newBbox.center.latitude) - bundle.putDouble("center_map_lon", newBbox.center.longitude) - it.cameraPosition.zoom.let { z-> bundle.putDouble("map_zoom",z) } - bundle.putDouble("map_bearing",cp.bearing) - bundle.putDouble("map_tilt", cp.tilt) - - val locationComponent = it.locationComponent - bundle.putBoolean(KEY_LOCATION_ENABLED,locationComponent.isLocationComponentEnabled) - bundle.putParcelable("last_location", locationComponent.lastKnownLocation) - } - shownStopInBottomSheet?.let { - bundle.putBundle("shown_stop", it.toBundle()) - } - } - - protected fun saveMapStateInBundle(): Bundle { - val b = Bundle() - saveMapStateBeforePause(b) - return b } - */ - protected fun stopToGeoJsonFeature(s: Stop): Feature{ return Feature.fromGeometry( Point.fromLngLat(s.longitude!!, s.latitude!!), @@ -495,6 +442,9 @@ abstract class GeneralMapLibreFragment: ScreenBaseFragment(), OnMapReadyCallback if(locationComponent.isLocationComponentEnabled !=enabled) locationComponent.isLocationComponentEnabled= enabled changed = true} + Log.d(DEBUG_TAG, "Asked to set location component enabled: $enabled, changed: $changed") + mapStateViewModel.locationUserActive.value = enabled + return changed } @@ -517,15 +467,17 @@ abstract class GeneralMapLibreFragment: ScreenBaseFragment(), OnMapReadyCallback .locationEngine(locationEngine) .build() locationComponent.activateLocationComponent(options) - //locationComponent.cameraMode = CameraMode.TRACKING - //locationComponent.renderMode = RenderMode.COMPASS - locationInitialized = true + if(BuildConfig.DEBUG) Log.d(DEBUG_TAG, "Requesting location updates") locationEngine!!.requestLocationUpdates(LocationEngineRequest.Builder(500).setDisplacement(20.0f).build(), mapLibreLocationCallback, null) - // signal to show user location icon as active - mapStateViewModel.locationUserActive.value = true - setLocationComponentEnabled(true) + + if(!locationEnabledOnDevice){ + warnLocationNotEnabledOnDevice() + }else { + setLocationComponentEnabled(true) + } + locationInitialized = true onMapLocationComponentInitialized() } } @@ -1016,7 +968,11 @@ abstract class GeneralMapLibreFragment: ScreenBaseFragment(), OnMapReadyCallback } else if(deviceHasLocationProvider()) { if(Permissions.bothLocationPermissionsGranted(context)){ - setMapLocationEnabled(true) + if(!locationEnabledOnDevice){ + warnLocationNotEnabledOnDevice() + } else{ + setMapLocationEnabled(true) + } } else{ Log.d(DEBUG_TAG, "Requesting permissions to show location") Permissions.getInstance(context).checkRequestLocationPermissions(requireActivity(), positionRequestResponder) @@ -1034,6 +990,7 @@ abstract class GeneralMapLibreFragment: ScreenBaseFragment(), OnMapReadyCallback */ @SuppressLint("MissingPermission") protected fun setMapLocationEnabled(enabled: Boolean){ + Log.d(DEBUG_TAG, "Setting map location enabled: $enabled") map?.locationComponent?.isLocationComponentEnabled = enabled //map?.cameraPosition = mapStateViewModel.locationUserActive.value = enabled diff --git a/app/src/main/java/it/reyboz/bustorino/fragments/MapLibreFragment.kt b/app/src/main/java/it/reyboz/bustorino/fragments/MapLibreFragment.kt index 93dbae7..4c7821d 100644 --- a/app/src/main/java/it/reyboz/bustorino/fragments/MapLibreFragment.kt +++ b/app/src/main/java/it/reyboz/bustorino/fragments/MapLibreFragment.kt @@ -233,7 +233,8 @@ class MapLibreFragment : GeneralMapLibreFragment() { usingMQTTPositions = useMQTT } - mapStateViewModel.locationUserActive.observe(viewLifecycleOwner){ setLocationIconEnabled(it)} + mapStateViewModel.locationUserActive.observe(viewLifecycleOwner){ + setLocationIconEnabled(it)} mapStateViewModel.followingUserPosition.observe(viewLifecycleOwner){ updateFollowingIcon(it)} Log.d(DEBUG_TAG, "Fragment View Created!")