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) {
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();

View file

@ -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<Place> places = new ArrayList<>();
@NonNull
public static NearbyParentFragment newInstance() {
@ -957,7 +953,7 @@ public class NearbyParentFragment extends CommonsDaggerSupportFragment
@Override
public void updateListFragment(final List<Place> 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;

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.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) {