Fix caching and loading places in Nearby list

This commit is contained in:
savsch 2024-12-19 23:32:40 +05:30
parent c25f79c49a
commit 3a97245120
3 changed files with 6 additions and 13 deletions

View file

@ -286,7 +286,6 @@ public class NearbyController extends MapController {
if (placeList == null) { if (placeList == null) {
return baseMarkersList; return baseMarkersList;
} }
Timber.tag("temptagthree").e("loadAttractionsFromLocationToBaseMarkerOptions called with %d places", placeList.size());
placeList = placeList.subList(0, Math.min(placeList.size(), MAX_RESULTS)); placeList = placeList.subList(0, Math.min(placeList.size(), MAX_RESULTS));
for (Place place : placeList) { for (Place place : placeList) {
BaseMarker baseMarker = new BaseMarker(); BaseMarker baseMarker = new BaseMarker();

View file

@ -325,10 +325,6 @@ public class NearbyParentFragment extends CommonsDaggerSupportFragment
* WLM URL * WLM URL
*/ */
public static final String WLM_URL = "https://commons.wikimedia.org/wiki/Commons:Mobile_app/Contributing_to_WLM_using_the_app"; 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<Place> places = new ArrayList<>();
@NonNull @NonNull
public static NearbyParentFragment newInstance() { public static NearbyParentFragment newInstance() {
@ -957,7 +953,7 @@ public class NearbyParentFragment extends CommonsDaggerSupportFragment
@Override @Override
public void updateListFragment(final List<Place> placeList) { public void updateListFragment(final List<Place> placeList) {
places = placeList; adapter.clear();
adapter.setItems(placeList); adapter.setItems(placeList);
binding.bottomSheetNearby.noResultsMessage.setVisibility( binding.bottomSheetNearby.noResultsMessage.setVisibility(
placeList.isEmpty() ? View.VISIBLE : View.GONE); placeList.isEmpty() ? View.VISIBLE : View.GONE);
@ -1875,7 +1871,6 @@ public class NearbyParentFragment extends CommonsDaggerSupportFragment
*/ */
private void addMarkerToMap(Place place, Boolean isBookMarked) { private void addMarkerToMap(Place place, Boolean isBookMarked) {
binding.map.getOverlays().add(convertToMarker(place, isBookMarked)); binding.map.getOverlays().add(convertToMarker(place, isBookMarked));
Timber.tag("temptag").d("added marker THE OLD WAY");
} }
public Marker convertToMarker(Place place, Boolean isBookMarked) { public Marker convertToMarker(Place place, Boolean isBookMarked) {
@ -2214,7 +2209,6 @@ public class NearbyParentFragment extends CommonsDaggerSupportFragment
*/ */
@Override @Override
public void clearAllMarkers() { public void clearAllMarkers() {
Timber.tag("temptagtwo").e("clearallmarkerscalled");
binding.map.getOverlayManager().clear(); binding.map.getOverlayManager().clear();
binding.map.invalidate(); binding.map.invalidate();
GeoPoint geoPoint = mapCenter; GeoPoint geoPoint = mapCenter;

View file

@ -20,6 +20,7 @@ import fr.free.nrw.commons.nearby.contract.NearbyParentFragmentContract
import fr.free.nrw.commons.utils.LocationUtils import fr.free.nrw.commons.utils.LocationUtils
import fr.free.nrw.commons.wikidata.WikidataConstants.PLACE_OBJECT import fr.free.nrw.commons.wikidata.WikidataConstants.PLACE_OBJECT
import fr.free.nrw.commons.wikidata.WikidataEditListener.WikidataP18EditListener import fr.free.nrw.commons.wikidata.WikidataEditListener.WikidataP18EditListener
import io.reactivex.schedulers.Schedulers
import kotlinx.coroutines.Dispatchers import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.Job import kotlinx.coroutines.Job
import kotlinx.coroutines.channels.Channel import kotlinx.coroutines.channels.Channel
@ -27,13 +28,11 @@ import kotlinx.coroutines.delay
import kotlinx.coroutines.ensureActive import kotlinx.coroutines.ensureActive
import kotlinx.coroutines.launch import kotlinx.coroutines.launch
import kotlinx.coroutines.withContext import kotlinx.coroutines.withContext
import org.osmdroid.views.overlay.Marker
import timber.log.Timber import timber.log.Timber
import java.lang.reflect.InvocationHandler import java.lang.reflect.InvocationHandler
import java.lang.reflect.Method import java.lang.reflect.Method
import java.lang.reflect.Proxy import java.lang.reflect.Proxy
import java.util.concurrent.CopyOnWriteArrayList import java.util.concurrent.CopyOnWriteArrayList
import java.util.concurrent.CopyOnWriteArraySet
class NearbyParentFragmentPresenter class NearbyParentFragmentPresenter
( (
@ -310,9 +309,10 @@ class NearbyParentFragmentPresenter
} }
) )
updatedGroups[index] = finalPlaceGroup updatedGroups[index] = finalPlaceGroup
launch { placesRepository
placesRepository.save(finalPlaceGroup.place) .save(finalPlaceGroup.place)
} .subscribeOn(Schedulers.io())
.subscribe()
} }
// handle any places clicked // handle any places clicked
if (clickedPlacesIndex < clickedPlaces.size) { if (clickedPlacesIndex < clickedPlaces.size) {