mirror of
https://github.com/commons-app/apps-android-commons.git
synced 2025-10-30 06:13:54 +01:00
Partially replace temporary experimental fixes
This commit is contained in:
parent
44a5d5854f
commit
e3deffcde9
6 changed files with 79 additions and 41 deletions
|
|
@ -20,8 +20,8 @@ import timber.log.Timber;
|
||||||
|
|
||||||
public class NearbyController extends MapController {
|
public class NearbyController extends MapController {
|
||||||
|
|
||||||
private static final int MAX_RESULTS = 1000;
|
|
||||||
private final NearbyPlaces nearbyPlaces;
|
private final NearbyPlaces nearbyPlaces;
|
||||||
|
public static final int MAX_RESULTS = 1000;
|
||||||
public static double currentLocationSearchRadius = 10.0; //in kilometers
|
public static double currentLocationSearchRadius = 10.0; //in kilometers
|
||||||
public static LatLng currentLocation; // Users latest fetched location
|
public static LatLng currentLocation; // Users latest fetched location
|
||||||
public static LatLng latestSearchLocation; // Can be current and camera target on search this area button is used
|
public static LatLng latestSearchLocation; // Can be current and camera target on search this area button is used
|
||||||
|
|
|
||||||
|
|
@ -2,6 +2,7 @@ package fr.free.nrw.commons.nearby.contract;
|
||||||
|
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
import androidx.annotation.Nullable;
|
import androidx.annotation.Nullable;
|
||||||
|
import androidx.lifecycle.LifecycleCoroutineScope;
|
||||||
import fr.free.nrw.commons.BaseMarker;
|
import fr.free.nrw.commons.BaseMarker;
|
||||||
import fr.free.nrw.commons.kvstore.JsonKvStore;
|
import fr.free.nrw.commons.kvstore.JsonKvStore;
|
||||||
import fr.free.nrw.commons.location.LatLng;
|
import fr.free.nrw.commons.location.LatLng;
|
||||||
|
|
|
||||||
|
|
@ -56,6 +56,8 @@ import androidx.appcompat.app.AlertDialog.Builder;
|
||||||
import androidx.constraintlayout.widget.ConstraintLayout;
|
import androidx.constraintlayout.widget.ConstraintLayout;
|
||||||
import androidx.core.content.ContextCompat;
|
import androidx.core.content.ContextCompat;
|
||||||
import androidx.core.content.FileProvider;
|
import androidx.core.content.FileProvider;
|
||||||
|
import androidx.lifecycle.LifecycleOwner;
|
||||||
|
import androidx.lifecycle.LifecycleOwnerKt;
|
||||||
import androidx.recyclerview.widget.DividerItemDecoration;
|
import androidx.recyclerview.widget.DividerItemDecoration;
|
||||||
import androidx.recyclerview.widget.GridLayoutManager;
|
import androidx.recyclerview.widget.GridLayoutManager;
|
||||||
import androidx.recyclerview.widget.LinearLayoutManager;
|
import androidx.recyclerview.widget.LinearLayoutManager;
|
||||||
|
|
@ -156,7 +158,7 @@ public class NearbyParentFragment extends CommonsDaggerSupportFragment
|
||||||
|
|
||||||
FragmentNearbyParentBinding binding;
|
FragmentNearbyParentBinding binding;
|
||||||
|
|
||||||
private JustExperimenting justExperimenting;
|
// private JustExperimenting justExperimenting;
|
||||||
|
|
||||||
public final MapEventsOverlay mapEventsOverlay = new MapEventsOverlay(new MapEventsReceiver() {
|
public final MapEventsOverlay mapEventsOverlay = new MapEventsOverlay(new MapEventsReceiver() {
|
||||||
@Override
|
@Override
|
||||||
|
|
@ -351,7 +353,7 @@ public class NearbyParentFragment extends CommonsDaggerSupportFragment
|
||||||
binding = FragmentNearbyParentBinding.inflate(inflater, container, false);
|
binding = FragmentNearbyParentBinding.inflate(inflater, container, false);
|
||||||
view = binding.getRoot();
|
view = binding.getRoot();
|
||||||
|
|
||||||
justExperimenting = new JustExperimenting(this);
|
// justExperimenting = new JustExperimenting(this);
|
||||||
|
|
||||||
initNetworkBroadCastReceiver();
|
initNetworkBroadCastReceiver();
|
||||||
presenter = new NearbyParentFragmentPresenter(bookmarkLocationDao);
|
presenter = new NearbyParentFragmentPresenter(bookmarkLocationDao);
|
||||||
|
|
@ -1361,7 +1363,7 @@ public class NearbyParentFragment extends CommonsDaggerSupportFragment
|
||||||
? getTextBetweenParentheses(
|
? getTextBetweenParentheses(
|
||||||
updatedPlace.getLongDescription()) : updatedPlace.getLongDescription());
|
updatedPlace.getLongDescription()) : updatedPlace.getLongDescription());
|
||||||
marker.showInfoWindow();
|
marker.showInfoWindow();
|
||||||
justExperimenting.handlePlaceClicked(updatedPlace);
|
// justExperimenting.handlePlaceClicked(updatedPlace);
|
||||||
savePlaceToDatabase(place);
|
savePlaceToDatabase(place);
|
||||||
Drawable icon = ContextCompat.getDrawable(getContext(),
|
Drawable icon = ContextCompat.getDrawable(getContext(),
|
||||||
getIconFor(updatedPlace, isBookMarked));
|
getIconFor(updatedPlace, isBookMarked));
|
||||||
|
|
@ -1502,8 +1504,8 @@ public class NearbyParentFragment extends CommonsDaggerSupportFragment
|
||||||
*/
|
*/
|
||||||
private void updateMapMarkers(final List<Place> nearbyPlaces, final LatLng curLatLng,
|
private void updateMapMarkers(final List<Place> nearbyPlaces, final LatLng curLatLng,
|
||||||
final boolean shouldUpdateSelectedMarker) {
|
final boolean shouldUpdateSelectedMarker) {
|
||||||
presenter.updateMapMarkers(nearbyPlaces, curLatLng, shouldUpdateSelectedMarker);
|
presenter.updateMapMarkers(nearbyPlaces, curLatLng,
|
||||||
setFilterState();
|
LifecycleOwnerKt.getLifecycleScope(getViewLifecycleOwner()));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
@ -1766,8 +1768,10 @@ public class NearbyParentFragment extends CommonsDaggerSupportFragment
|
||||||
final boolean displayExists = false;
|
final boolean displayExists = false;
|
||||||
final boolean displayNeedsPhoto= false;
|
final boolean displayNeedsPhoto= false;
|
||||||
final boolean displayWlm = false;
|
final boolean displayWlm = false;
|
||||||
// Remove the previous markers before updating them
|
if (selectedLabels == null || selectedLabels.size() == 0) {
|
||||||
// clearAllMarkers(); // moved
|
replaceMarkerOverlays(NearbyController.markerLabelList);
|
||||||
|
return;
|
||||||
|
}
|
||||||
ArrayList<MarkerPlaceGroup> es = new ArrayList<>();
|
ArrayList<MarkerPlaceGroup> es = new ArrayList<>();
|
||||||
for (final MarkerPlaceGroup markerPlaceGroup : NearbyController.markerLabelList) {
|
for (final MarkerPlaceGroup markerPlaceGroup : NearbyController.markerLabelList) {
|
||||||
final Place place = markerPlaceGroup.getPlace();
|
final Place place = markerPlaceGroup.getPlace();
|
||||||
|
|
@ -1810,26 +1814,10 @@ public class NearbyParentFragment extends CommonsDaggerSupportFragment
|
||||||
|
|
||||||
if (shouldUpdateMarker) {
|
if (shouldUpdateMarker) {
|
||||||
MarkerPlaceGroup e = new MarkerPlaceGroup(markerPlaceGroup.getIsBookmarked(), place);
|
MarkerPlaceGroup e = new MarkerPlaceGroup(markerPlaceGroup.getIsBookmarked(), place);
|
||||||
// updateMarker(markerPlaceGroup.getIsBookmarked(), place,
|
|
||||||
// NearbyController.currentLocation);
|
|
||||||
es.add(e);
|
es.add(e);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
justExperimenting.loadNewMarkers(es);
|
replaceMarkerOverlays(es);
|
||||||
// Timber.tag("temptagtwo").e("iscowa: "+(binding.map.getOverlays() instanceof CopyOnWriteArrayList<Overlay>));
|
|
||||||
// Timber.tag("temptagtwo").e("additional debug info: "+(Looper.myLooper() == Looper.getMainLooper()));
|
|
||||||
|
|
||||||
//TODO experimentation touncomment
|
|
||||||
// if (selectedLabels == null || selectedLabels.size() == 0) {
|
|
||||||
// ArrayList<BaseMarker> markerArrayList = new ArrayList<>();
|
|
||||||
// for (final MarkerPlaceGroup markerPlaceGroup : NearbyController.markerLabelList) {
|
|
||||||
// BaseMarker nearbyBaseMarker = new BaseMarker();
|
|
||||||
// nearbyBaseMarker.setPlace(markerPlaceGroup.getPlace());
|
|
||||||
// markerArrayList.add(nearbyBaseMarker);
|
|
||||||
// }
|
|
||||||
// addMarkersToMap(markerArrayList);
|
|
||||||
// }
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|
@ -1955,9 +1943,14 @@ public class NearbyParentFragment extends CommonsDaggerSupportFragment
|
||||||
return marker;
|
return marker;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void replaceMarkerOverlays(final List<Marker> ms) {
|
public void replaceMarkerOverlays(final List<MarkerPlaceGroup> markerPlaceGroups) {
|
||||||
|
ArrayList<Marker> newMarkers = new ArrayList<>(markerPlaceGroups.size());
|
||||||
|
for (MarkerPlaceGroup markerPlaceGroup : markerPlaceGroups) {
|
||||||
|
newMarkers.add(
|
||||||
|
convertToMarker(markerPlaceGroup.getPlace(), markerPlaceGroup.getIsBookmarked()));
|
||||||
|
}
|
||||||
clearAllMarkers();
|
clearAllMarkers();
|
||||||
binding.map.getOverlays().addAll(ms);
|
binding.map.getOverlays().addAll(newMarkers);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
||||||
|
|
@ -55,7 +55,7 @@ class JustExperimenting(frag: NearbyParentFragment) {
|
||||||
delay(skipDelayMs)
|
delay(skipDelayMs)
|
||||||
}
|
}
|
||||||
skippedCount = 0
|
skippedCount = 0
|
||||||
frag.replaceMarkerOverlays(markers)
|
// frag.replaceMarkerOverlays(markers)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -3,6 +3,7 @@ package fr.free.nrw.commons.nearby.presenter
|
||||||
import android.location.Location
|
import android.location.Location
|
||||||
import android.view.View
|
import android.view.View
|
||||||
import androidx.annotation.MainThread
|
import androidx.annotation.MainThread
|
||||||
|
import androidx.lifecycle.LifecycleCoroutineScope
|
||||||
import fr.free.nrw.commons.BaseMarker
|
import fr.free.nrw.commons.BaseMarker
|
||||||
import fr.free.nrw.commons.bookmarks.locations.BookmarkLocationsDao
|
import fr.free.nrw.commons.bookmarks.locations.BookmarkLocationsDao
|
||||||
import fr.free.nrw.commons.kvstore.JsonKvStore
|
import fr.free.nrw.commons.kvstore.JsonKvStore
|
||||||
|
|
@ -18,6 +19,11 @@ 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 kotlinx.coroutines.Dispatchers
|
||||||
|
import kotlinx.coroutines.Job
|
||||||
|
import kotlinx.coroutines.delay
|
||||||
|
import kotlinx.coroutines.launch
|
||||||
|
import kotlinx.coroutines.withContext
|
||||||
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
|
||||||
|
|
@ -35,6 +41,25 @@ class NearbyParentFragmentPresenter
|
||||||
|
|
||||||
private var nearbyParentFragmentView: NearbyParentFragmentContract.View = DUMMY
|
private var nearbyParentFragmentView: NearbyParentFragmentContract.View = DUMMY
|
||||||
|
|
||||||
|
private var loadPlacesDataAyncJob: Job? = null
|
||||||
|
private var schedulePlacesUpdateJob: Job? = null
|
||||||
|
private object schedulePlacesUpdateOptions {
|
||||||
|
var skippedCount = 0
|
||||||
|
val skipLimit = 2
|
||||||
|
val skipDelayMs = 1000L
|
||||||
|
}
|
||||||
|
suspend fun schedulePlacesUpdate(markerPlaceGroups: List<MarkerPlaceGroup>) = withContext(Dispatchers.Main) {
|
||||||
|
if (markerPlaceGroups.isEmpty()) return@withContext
|
||||||
|
schedulePlacesUpdateJob?.cancel()
|
||||||
|
schedulePlacesUpdateJob = launch {
|
||||||
|
if (schedulePlacesUpdateOptions.skippedCount++ < schedulePlacesUpdateOptions.skipLimit) {
|
||||||
|
delay(schedulePlacesUpdateOptions.skipDelayMs)
|
||||||
|
}
|
||||||
|
schedulePlacesUpdateOptions.skippedCount = 0
|
||||||
|
updatePlaceGroupsToControllerAndRender(markerPlaceGroups)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
override fun attachView(view: NearbyParentFragmentContract.View) {
|
override fun attachView(view: NearbyParentFragmentContract.View) {
|
||||||
this.nearbyParentFragmentView = view
|
this.nearbyParentFragmentView = view
|
||||||
}
|
}
|
||||||
|
|
@ -111,7 +136,7 @@ class NearbyParentFragmentPresenter
|
||||||
*
|
*
|
||||||
* @param locationChangeType defines if location changed significantly or slightly
|
* @param locationChangeType defines if location changed significantly or slightly
|
||||||
*/
|
*/
|
||||||
override fun updateMapAndList(locationChangeType: LocationChangeType) {
|
override fun updateMapAndList(locationChangeType: LocationChangeType?) {
|
||||||
Timber.d("Presenter updates map and list")
|
Timber.d("Presenter updates map and list")
|
||||||
if (isNearbyLocked) {
|
if (isNearbyLocked) {
|
||||||
Timber.d("Nearby is locked, so updateMapAndList returns")
|
Timber.d("Nearby is locked, so updateMapAndList returns")
|
||||||
|
|
@ -172,21 +197,32 @@ class NearbyParentFragmentPresenter
|
||||||
* @param nearbyPlaces This variable has placeToCenter list information and distances.
|
* @param nearbyPlaces This variable has placeToCenter list information and distances.
|
||||||
*/
|
*/
|
||||||
fun updateMapMarkers(
|
fun updateMapMarkers(
|
||||||
nearbyPlaces: MutableList<Place?>?, currentLatLng: LatLng?,
|
nearbyPlaces: List<Place>?, currentLatLng: LatLng,
|
||||||
shouldTrackPosition: Boolean
|
scope: LifecycleCoroutineScope?
|
||||||
) {
|
) {
|
||||||
|
val nearbyPlaces: MutableList<Place> =
|
||||||
|
nearbyPlaces?.sortedBy { it.getDistanceInDouble(currentLatLng) }
|
||||||
|
?.take(NearbyController.MAX_RESULTS)
|
||||||
|
?.toMutableList()
|
||||||
|
?: return
|
||||||
|
|
||||||
// nearbyParentFragmentView.clearAllMarkers();
|
loadPlacesDataAyncJob?.cancel()
|
||||||
val baseMarkers = NearbyController
|
|
||||||
.loadAttractionsFromLocationToBaseMarkerOptions(
|
|
||||||
currentLatLng, // Curlatlang will be used to calculate distances
|
|
||||||
nearbyPlaces
|
|
||||||
)
|
|
||||||
nearbyParentFragmentView.updateMapMarkers(baseMarkers)
|
|
||||||
lockUnlockNearby(false) // So that new location updates wont come
|
lockUnlockNearby(false) // So that new location updates wont come
|
||||||
nearbyParentFragmentView.setProgressBarVisibility(false)
|
nearbyParentFragmentView.setProgressBarVisibility(false)
|
||||||
nearbyParentFragmentView.updateListFragment(nearbyPlaces)
|
|
||||||
|
|
||||||
|
updatePlaceGroupsToControllerAndRender(nearbyPlaces.map {
|
||||||
|
MarkerPlaceGroup(
|
||||||
|
// currently only the place's location is known, but bookmarks are stored by name
|
||||||
|
false,
|
||||||
|
it
|
||||||
|
)
|
||||||
|
})
|
||||||
|
|
||||||
|
loadPlacesDataAyncJob = scope?.launch(Dispatchers.IO) {
|
||||||
|
withContext(Dispatchers.Main) {
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
@ -219,7 +255,7 @@ class NearbyParentFragmentPresenter
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun filterByMarkerType(
|
override fun filterByMarkerType(
|
||||||
selectedLabels: MutableList<Label?>?, state: Int,
|
selectedLabels: List<Label?>?, state: Int,
|
||||||
filterForPlaceState: Boolean, filterForAllNoneType: Boolean
|
filterForPlaceState: Boolean, filterForAllNoneType: Boolean
|
||||||
) {
|
) {
|
||||||
if (filterForAllNoneType) { // Means we will set labels based on states
|
if (filterForAllNoneType) { // Means we will set labels based on states
|
||||||
|
|
@ -262,6 +298,14 @@ class NearbyParentFragmentPresenter
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@MainThread
|
||||||
|
fun updatePlaceGroupsToControllerAndRender(markerPlaceGroups: List<MarkerPlaceGroup>) {
|
||||||
|
NearbyController.markerLabelList.clear()
|
||||||
|
NearbyController.markerLabelList.addAll(markerPlaceGroups)
|
||||||
|
nearbyParentFragmentView.setFilterState()
|
||||||
|
nearbyParentFragmentView.updateListFragment(markerPlaceGroups.map { it.place })
|
||||||
|
}
|
||||||
|
|
||||||
override fun setCheckboxUnknown() {
|
override fun setCheckboxUnknown() {
|
||||||
nearbyParentFragmentView.setCheckBoxState(CheckBoxTriStates.UNKNOWN)
|
nearbyParentFragmentView.setCheckBoxState(CheckBoxTriStates.UNKNOWN)
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -457,7 +457,7 @@ class NearbyParentFragmentPresenterTest {
|
||||||
nearbyPlacesInfo.placeList = null
|
nearbyPlacesInfo.placeList = null
|
||||||
|
|
||||||
whenever(bookmarkLocationsDao.allBookmarksLocations).thenReturn(Collections.emptyList())
|
whenever(bookmarkLocationsDao.allBookmarksLocations).thenReturn(Collections.emptyList())
|
||||||
nearbyPresenter.updateMapMarkers(nearbyPlacesInfo.placeList, latestLocation, true)
|
nearbyPresenter.updateMapMarkers(nearbyPlacesInfo.placeList, latestLocation, null)
|
||||||
Mockito.verify(nearbyParentFragmentView).updateMapMarkers(any())
|
Mockito.verify(nearbyParentFragmentView).updateMapMarkers(any())
|
||||||
Mockito.verify(nearbyParentFragmentView).setProgressBarVisibility(false)
|
Mockito.verify(nearbyParentFragmentView).setProgressBarVisibility(false)
|
||||||
Mockito.verify(nearbyParentFragmentView).updateListFragment(nearbyPlacesInfo.placeList)
|
Mockito.verify(nearbyParentFragmentView).updateListFragment(nearbyPlacesInfo.placeList)
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue