From 40c2964cddbeb4a75b52f8c7a387833ce268ecf6 Mon Sep 17 00:00:00 2001 From: savsch Date: Tue, 17 Dec 2024 23:49:00 +0530 Subject: [PATCH] reformatting --- .../fragments/NearbyParentFragment.java | 21 ++------ .../nearby/helper/JustExperimenting.kt | 52 +++++++++++-------- 2 files changed, 35 insertions(+), 38 deletions(-) diff --git a/app/src/main/java/fr/free/nrw/commons/nearby/fragments/NearbyParentFragment.java b/app/src/main/java/fr/free/nrw/commons/nearby/fragments/NearbyParentFragment.java index 25f084b58..ce0544a3e 100644 --- a/app/src/main/java/fr/free/nrw/commons/nearby/fragments/NearbyParentFragment.java +++ b/app/src/main/java/fr/free/nrw/commons/nearby/fragments/NearbyParentFragment.java @@ -158,7 +158,7 @@ public class NearbyParentFragment extends CommonsDaggerSupportFragment private JustExperimenting justExperimenting; - public final MapEventsOverlay mapEventsOverlay = new MapEventsOverlay(new MapEventsReceiver() { + public final MapEventsOverlay mapEventsOverlay = new MapEventsOverlay(new MapEventsReceiver() { @Override public boolean singleTapConfirmedHelper(GeoPoint p) { if (clickedMarker != null) { @@ -677,19 +677,6 @@ public class NearbyParentFragment extends CommonsDaggerSupportFragment registerNetworkReceiver(); if (isResumed() && ((MainActivity) getActivity()).activeFragment == ActiveFragment.NEARBY) { if (locationPermissionsHelper.checkLocationPermission(getActivity())) { -// if (lastFocusLocation == null && lastKnownLocation == null) { -// locationPermissionGranted(); -// } else{ -// if (updatedPlacesList != null) { -// if (!updatedPlacesList.isEmpty()) { -// loadPlacesDataAsync(updatedPlacesList, updatedLatLng); -// } else { -// updateMapMarkers(updatedPlacesList, getLastMapFocus(), false); -// } -// }else { -// locationPermissionGranted(); -// } -// } locationPermissionGranted(); } else { startMapWithoutPermission(); @@ -2023,7 +2010,7 @@ public class NearbyParentFragment extends CommonsDaggerSupportFragment */ public void updateMarker(final boolean isBookmarked, final Place place, @Nullable final LatLng currentLatLng) { - if(true) { + if (true) { return; // TODO move this method to new overlay mangement logic } addMarkerToMap(place, isBookmarked); @@ -2132,7 +2119,7 @@ public class NearbyParentFragment extends CommonsDaggerSupportFragment return marker; } - public void replaceMarkerOverlays(final List ms){ + public void replaceMarkerOverlays(final List ms) { clearAllMarkers(); binding.map.getOverlays().addAll(ms); } @@ -2144,7 +2131,7 @@ public class NearbyParentFragment extends CommonsDaggerSupportFragment * locations. */ private void addMarkersToMap(List nearbyBaseMarkers) { - Timber.tag("temptagtwo").e("another n+1 C 2: "+nearbyBaseMarkers.size()); + Timber.tag("temptagtwo").e("another n+1 C 2: " + nearbyBaseMarkers.size()); for(int i = 0; i< nearbyBaseMarkers.size(); i++){ addMarkerToMap(nearbyBaseMarkers.get(i).getPlace(), false); } diff --git a/app/src/main/java/fr/free/nrw/commons/nearby/helper/JustExperimenting.kt b/app/src/main/java/fr/free/nrw/commons/nearby/helper/JustExperimenting.kt index 205c6a060..a143385e9 100644 --- a/app/src/main/java/fr/free/nrw/commons/nearby/helper/JustExperimenting.kt +++ b/app/src/main/java/fr/free/nrw/commons/nearby/helper/JustExperimenting.kt @@ -13,13 +13,9 @@ import kotlinx.coroutines.Job import kotlinx.coroutines.channels.Channel import kotlinx.coroutines.delay import kotlinx.coroutines.ensureActive -import kotlinx.coroutines.flow.MutableStateFlow -import kotlinx.coroutines.flow.asStateFlow -import kotlinx.coroutines.flow.collectLatest import kotlinx.coroutines.launch import kotlinx.coroutines.withContext import org.osmdroid.views.overlay.Marker -import timber.log.Timber import java.util.ArrayList import java.util.concurrent.CopyOnWriteArrayList @@ -41,9 +37,11 @@ class JustExperimenting(frag: NearbyParentFragment) { fun loadNewMarkers(es: ArrayList) = scope.launch { markerBaseDataChannel.send(es) } - suspend fun updateMarkersState(markers: List){ + + suspend fun updateMarkersState(markers: List) { markersStateChannel.send(markers) } + init { scope.launch(Dispatchers.Default) { var pinStateUpdateJob: Job? = null @@ -63,7 +61,7 @@ class JustExperimenting(frag: NearbyParentFragment) { } scope.launch(Dispatchers.Default) { var loadPinDetailsJob: Job? = null - for(markerBaseDataList in markerBaseDataChannel) { + for (markerBaseDataList in markerBaseDataChannel) { loadPinDetailsJob?.cancel() loadPinDetailsJob = launch { loadPinsDetails(frag, markerBaseDataList, this) @@ -71,7 +69,7 @@ class JustExperimenting(frag: NearbyParentFragment) { } } - frag.viewLifecycleOwner.lifecycle.addObserver(object: DefaultLifecycleObserver { + frag.viewLifecycleOwner.lifecycle.addObserver(object : DefaultLifecycleObserver { override fun onDestroy(owner: LifecycleOwner) { performCleanup() } @@ -85,11 +83,9 @@ class JustExperimenting(frag: NearbyParentFragment) { ) { // make sure the grey pins are loaded immediately: skippedCount = skipLimit - updateMarkersState( - markerBaseDataList.map { - frag.convertToMarker(it.place, it.isBookmarked) - } - ) + updateMarkersState(markerBaseDataList.map { + frag.convertToMarker(it.place, it.isBookmarked) + }) // now load the pin details: clickedPlaces.clear() @@ -110,7 +106,7 @@ class JustExperimenting(frag: NearbyParentFragment) { val toUpdateMarkersFrom = currentIndex val placesToFetch = mutableListOf() - while (currentIndex<=endIndex && placesToFetch.size < batchSize) { + while (currentIndex <= endIndex && placesToFetch.size < batchSize) { val existingPlace = markerBaseDataList[currentIndex].place if (existingPlace.name != "") { ++currentIndex @@ -119,7 +115,7 @@ class JustExperimenting(frag: NearbyParentFragment) { val repoPlace = withContext(Dispatchers.IO) { frag.getPlaceFromRepository(existingPlace.entityID) } - if (repoPlace != null && repoPlace.name != ""){ + if (repoPlace != null && repoPlace.name != "") { markerBaseDataList[currentIndex] = MarkerPlaceGroup(markerBaseDataList[currentIndex].isBookmarked, repoPlace) ++currentIndex @@ -138,29 +134,43 @@ class JustExperimenting(frag: NearbyParentFragment) { for (fetchedPlace in fetchedPlaces) { for (index in placesToFetch) { // nesting okay here as batch size is small val existingPlace = markerBaseDataList[index].place - if (existingPlace.siteLinks.wikidataLink == fetchedPlace.siteLinks.wikidataLink){ + if (existingPlace.siteLinks.wikidataLink == + fetchedPlace.siteLinks.wikidataLink + ) { fetchedPlace.location = existingPlace.location fetchedPlace.distance = existingPlace.distance fetchedPlace.isMonument = existingPlace.isMonument - markerBaseDataList[index] = MarkerPlaceGroup(markerBaseDataList[index].isBookmarked, fetchedPlace) + markerBaseDataList[index] = MarkerPlaceGroup( + markerBaseDataList[index].isBookmarked, fetchedPlace + ) frag.savePlaceToDatabase(fetchedPlace) } } } } for (i in toUpdateMarkersFrom..() while (clickedPlacesIndex < clickedPlaces.size) { - clickedPlacesBacklog.put(clickedPlaces[clickedPlacesIndex].location, clickedPlaces[clickedPlacesIndex]) + clickedPlacesBacklog.put( + clickedPlaces[clickedPlacesIndex].location, + clickedPlaces[clickedPlacesIndex] + ) ++clickedPlacesIndex } for (i in currentIndex..endIndex) { if (clickedPlacesBacklog.containsKey(markerBaseDataList[i].place.location)) { - markerBaseDataList[i] = MarkerPlaceGroup(markerBaseDataList[i].isBookmarked, clickedPlacesBacklog[markerBaseDataList[i].place.location]) - updatedMarkers[i] = frag.convertToMarker(markerBaseDataList[i].place, markerBaseDataList[i].isBookmarked) + markerBaseDataList[i] = MarkerPlaceGroup( + markerBaseDataList[i].isBookmarked, + clickedPlacesBacklog[markerBaseDataList[i].place.location] + ) + updatedMarkers[i] = frag.convertToMarker( + markerBaseDataList[i].place, markerBaseDataList[i].isBookmarked + ) } } }