From 3a972451203f62999ed165c049740cdc8d39a6d5 Mon Sep 17 00:00:00 2001 From: savsch Date: Thu, 19 Dec 2024 23:32:40 +0530 Subject: [PATCH] Fix caching and loading places in Nearby list --- .../fr/free/nrw/commons/nearby/NearbyController.java | 1 - .../commons/nearby/fragments/NearbyParentFragment.java | 8 +------- .../nearby/presenter/NearbyParentFragmentPresenter.kt | 10 +++++----- 3 files changed, 6 insertions(+), 13 deletions(-) diff --git a/app/src/main/java/fr/free/nrw/commons/nearby/NearbyController.java b/app/src/main/java/fr/free/nrw/commons/nearby/NearbyController.java index afec72ee6..cc2442db6 100644 --- a/app/src/main/java/fr/free/nrw/commons/nearby/NearbyController.java +++ b/app/src/main/java/fr/free/nrw/commons/nearby/NearbyController.java @@ -286,7 +286,6 @@ public class NearbyController extends MapController { if (placeList == null) { return baseMarkersList; } - Timber.tag("temptagthree").e("loadAttractionsFromLocationToBaseMarkerOptions called with %d places", placeList.size()); placeList = placeList.subList(0, Math.min(placeList.size(), MAX_RESULTS)); for (Place place : placeList) { BaseMarker baseMarker = new BaseMarker(); 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 8ca73bedb..76301e0a1 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 @@ -325,10 +325,6 @@ public class NearbyParentFragment extends CommonsDaggerSupportFragment * WLM URL */ public static final String WLM_URL = "https://commons.wikimedia.org/wiki/Commons:Mobile_app/Contributing_to_WLM_using_the_app"; - /** - * Saves response of list of places for the first time - */ - private List places = new ArrayList<>(); @NonNull public static NearbyParentFragment newInstance() { @@ -957,7 +953,7 @@ public class NearbyParentFragment extends CommonsDaggerSupportFragment @Override public void updateListFragment(final List placeList) { - places = placeList; + adapter.clear(); adapter.setItems(placeList); binding.bottomSheetNearby.noResultsMessage.setVisibility( placeList.isEmpty() ? View.VISIBLE : View.GONE); @@ -1875,7 +1871,6 @@ public class NearbyParentFragment extends CommonsDaggerSupportFragment */ private void addMarkerToMap(Place place, Boolean isBookMarked) { binding.map.getOverlays().add(convertToMarker(place, isBookMarked)); - Timber.tag("temptag").d("added marker THE OLD WAY"); } public Marker convertToMarker(Place place, Boolean isBookMarked) { @@ -2214,7 +2209,6 @@ public class NearbyParentFragment extends CommonsDaggerSupportFragment */ @Override public void clearAllMarkers() { - Timber.tag("temptagtwo").e("clearallmarkerscalled"); binding.map.getOverlayManager().clear(); binding.map.invalidate(); GeoPoint geoPoint = mapCenter; diff --git a/app/src/main/java/fr/free/nrw/commons/nearby/presenter/NearbyParentFragmentPresenter.kt b/app/src/main/java/fr/free/nrw/commons/nearby/presenter/NearbyParentFragmentPresenter.kt index 98dd5510d..434821a92 100644 --- a/app/src/main/java/fr/free/nrw/commons/nearby/presenter/NearbyParentFragmentPresenter.kt +++ b/app/src/main/java/fr/free/nrw/commons/nearby/presenter/NearbyParentFragmentPresenter.kt @@ -20,6 +20,7 @@ import fr.free.nrw.commons.nearby.contract.NearbyParentFragmentContract import fr.free.nrw.commons.utils.LocationUtils import fr.free.nrw.commons.wikidata.WikidataConstants.PLACE_OBJECT import fr.free.nrw.commons.wikidata.WikidataEditListener.WikidataP18EditListener +import io.reactivex.schedulers.Schedulers import kotlinx.coroutines.Dispatchers import kotlinx.coroutines.Job import kotlinx.coroutines.channels.Channel @@ -27,13 +28,11 @@ import kotlinx.coroutines.delay import kotlinx.coroutines.ensureActive import kotlinx.coroutines.launch import kotlinx.coroutines.withContext -import org.osmdroid.views.overlay.Marker import timber.log.Timber import java.lang.reflect.InvocationHandler import java.lang.reflect.Method import java.lang.reflect.Proxy import java.util.concurrent.CopyOnWriteArrayList -import java.util.concurrent.CopyOnWriteArraySet class NearbyParentFragmentPresenter ( @@ -310,9 +309,10 @@ class NearbyParentFragmentPresenter } ) updatedGroups[index] = finalPlaceGroup - launch { - placesRepository.save(finalPlaceGroup.place) - } + placesRepository + .save(finalPlaceGroup.place) + .subscribeOn(Schedulers.io()) + .subscribe() } // handle any places clicked if (clickedPlacesIndex < clickedPlaces.size) {