diff --git a/app/src/main/java/it/reyboz/bustorino/backend/mato/MQTTMatoClient.kt b/app/src/main/java/it/reyboz/bustorino/backend/mato/MQTTMatoClient.kt --- a/app/src/main/java/it/reyboz/bustorino/backend/mato/MQTTMatoClient.kt +++ b/app/src/main/java/it/reyboz/bustorino/backend/mato/MQTTMatoClient.kt @@ -375,13 +375,20 @@ val currentTimeStamp = makeUnixTimestamp() var c = 0 positionsLock.withLock{ - for ((k, manyp) in currentPositions.entries) { - for ((t, p) in manyp.entries) { + for ((k, posByVeh) in currentPositions) { + /*for (t in posByVeh.keys.toList()) { // iterate over snapshot to avoid modification error + val p = posByVeh[t] ?: continue if (currentTimeStamp - p.timestamp > timeMins * 60) { - manyp.remove(t) + posByVeh.remove(t) c += 1 } } + */ + c+=posByVeh.entries.removeIf{ el -> + currentTimeStamp - el.value.timestamp > timeMins * 60 + }.let { + if(it) 1 else 0 + } } } Log.d(DEBUG_TAG, "Removed $c positions older than $timeMins minutes") diff --git a/app/src/main/java/it/reyboz/bustorino/fragments/GeneralMapLibreFragment.kt b/app/src/main/java/it/reyboz/bustorino/fragments/GeneralMapLibreFragment.kt --- a/app/src/main/java/it/reyboz/bustorino/fragments/GeneralMapLibreFragment.kt +++ b/app/src/main/java/it/reyboz/bustorino/fragments/GeneralMapLibreFragment.kt @@ -67,6 +67,7 @@ } override fun onResume() { + mapView.onResume() super.onResume() val newMapStyle = PreferencesHolder.getMapLibreStyleFile(requireContext()) Log.d(DEBUG_TAG, "onResume newMapStyle: $newMapStyle, lastMapStyle: $lastMapStyle") @@ -77,8 +78,19 @@ @Deprecated("Deprecated in Java") override fun onLowMemory() { - super.onLowMemory() mapView.onLowMemory() + super.onLowMemory() + } + + override fun onStart() { + super.onStart() + mapView.onStart() + } + + override fun onDestroy() { + mapView.onDestroy() + Log.d(DEBUG_TAG, "Destroyed mapView Fragment!!") + super.onDestroy() } diff --git a/app/src/main/java/it/reyboz/bustorino/fragments/LinesDetailFragment.kt b/app/src/main/java/it/reyboz/bustorino/fragments/LinesDetailFragment.kt --- a/app/src/main/java/it/reyboz/bustorino/fragments/LinesDetailFragment.kt +++ b/app/src/main/java/it/reyboz/bustorino/fragments/LinesDetailFragment.kt @@ -1456,7 +1456,6 @@ override fun onResume() { super.onResume() Log.d(DEBUG_TAG, "Resetting paused from onResume") - mapView.onResume() pausedFragment = false val keySourcePositions = getString(R.string.pref_positions_source) @@ -1505,16 +1504,6 @@ } - override fun onStart() { - super.onStart() - mapView.onStart() - } - - override fun onDestroy() { - super.onDestroy() - mapView.onDestroy() - } - override fun onStop() { super.onStop() mapView.onStop() diff --git a/app/src/main/java/it/reyboz/bustorino/fragments/MapLibreFragment.kt b/app/src/main/java/it/reyboz/bustorino/fragments/MapLibreFragment.kt --- a/app/src/main/java/it/reyboz/bustorino/fragments/MapLibreFragment.kt +++ b/app/src/main/java/it/reyboz/bustorino/fragments/MapLibreFragment.kt @@ -616,8 +616,6 @@ override fun onStart() { super.onStart() - mapView.onStart() - //restore state from viewModel stopsViewModel.savedState?.let { restoreMapStateFromBundle(it) @@ -628,7 +626,7 @@ override fun onResume() { super.onResume() - mapView.onResume() + //mapView.onResume() handled in GeneralMapLibreFragment //val keySourcePositions = getString(R.string.pref_positions_source) if(showBusLayer) { @@ -686,12 +684,6 @@ } - override fun onDestroy() { - super.onDestroy() - mapView.onDestroy() - Log.d(DEBUG_TAG, "Destroyed map Fragment!!") - } - override fun onMapDestroy() { mapStyle.removeLayer(STOPS_LAYER_ID) mapStyle.removeSource(STOPS_SOURCE_ID) @@ -700,7 +692,7 @@ mapStyle.removeSource(BUSES_SOURCE_ID) - map?.locationComponent?.isLocationComponentEnabled = false + //map?.locationComponent?.isLocationComponentEnabled = false } override fun getBaseViewForSnackBar(): View? { return mapView