mirror of
https://github.com/commons-app/apps-android-commons.git
synced 2025-10-29 22:03:55 +01:00
temporary fixes part two
This commit is contained in:
parent
f541debe8a
commit
e2dd4ba0a8
2 changed files with 124 additions and 101 deletions
|
|
@ -28,7 +28,6 @@ import android.os.Build.VERSION_CODES;
|
||||||
import android.os.Bundle;
|
import android.os.Bundle;
|
||||||
import android.os.Environment;
|
import android.os.Environment;
|
||||||
import android.os.Handler;
|
import android.os.Handler;
|
||||||
import android.os.Looper;
|
|
||||||
import android.preference.PreferenceManager;
|
import android.preference.PreferenceManager;
|
||||||
import android.provider.Settings;
|
import android.provider.Settings;
|
||||||
import android.text.Html;
|
import android.text.Html;
|
||||||
|
|
@ -96,6 +95,7 @@ import fr.free.nrw.commons.nearby.PlacesRepository;
|
||||||
import fr.free.nrw.commons.nearby.WikidataFeedback;
|
import fr.free.nrw.commons.nearby.WikidataFeedback;
|
||||||
import fr.free.nrw.commons.nearby.contract.NearbyParentFragmentContract;
|
import fr.free.nrw.commons.nearby.contract.NearbyParentFragmentContract;
|
||||||
import fr.free.nrw.commons.nearby.fragments.AdvanceQueryFragment.Callback;
|
import fr.free.nrw.commons.nearby.fragments.AdvanceQueryFragment.Callback;
|
||||||
|
import fr.free.nrw.commons.nearby.helper.Experiment;
|
||||||
import fr.free.nrw.commons.nearby.helper.JustExperimenting;
|
import fr.free.nrw.commons.nearby.helper.JustExperimenting;
|
||||||
import fr.free.nrw.commons.nearby.model.BottomSheetItem;
|
import fr.free.nrw.commons.nearby.model.BottomSheetItem;
|
||||||
import fr.free.nrw.commons.nearby.presenter.NearbyParentFragmentPresenter;
|
import fr.free.nrw.commons.nearby.presenter.NearbyParentFragmentPresenter;
|
||||||
|
|
@ -127,7 +127,6 @@ import java.util.List;
|
||||||
import java.util.Locale;
|
import java.util.Locale;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import java.util.Objects;
|
import java.util.Objects;
|
||||||
import java.util.concurrent.CopyOnWriteArrayList;
|
|
||||||
import java.util.concurrent.TimeUnit;
|
import java.util.concurrent.TimeUnit;
|
||||||
import javax.inject.Inject;
|
import javax.inject.Inject;
|
||||||
import javax.inject.Named;
|
import javax.inject.Named;
|
||||||
|
|
@ -160,6 +159,29 @@ public class NearbyParentFragment extends CommonsDaggerSupportFragment
|
||||||
|
|
||||||
private JustExperimenting justExperimenting;
|
private JustExperimenting justExperimenting;
|
||||||
|
|
||||||
|
public final MapEventsOverlay mapEventsOverlay = new MapEventsOverlay(new MapEventsReceiver() {
|
||||||
|
@Override
|
||||||
|
public boolean singleTapConfirmedHelper(GeoPoint p) {
|
||||||
|
if (clickedMarker != null) {
|
||||||
|
clickedMarker.closeInfoWindow();
|
||||||
|
} else {
|
||||||
|
Timber.e("CLICKED MARKER IS NULL");
|
||||||
|
}
|
||||||
|
if (isListBottomSheetExpanded()) {
|
||||||
|
// Back should first hide the bottom sheet if it is expanded
|
||||||
|
hideBottomSheet();
|
||||||
|
} else if (isDetailsBottomSheetVisible()) {
|
||||||
|
hideBottomDetailsSheet();
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean longPressHelper(GeoPoint p) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
@Inject
|
@Inject
|
||||||
LocationServiceManager locationManager;
|
LocationServiceManager locationManager;
|
||||||
@Inject
|
@Inject
|
||||||
|
|
@ -459,28 +481,7 @@ public class NearbyParentFragment extends CommonsDaggerSupportFragment
|
||||||
binding.map.getOverlays().add(scaleBarOverlay);
|
binding.map.getOverlays().add(scaleBarOverlay);
|
||||||
binding.map.getZoomController().setVisibility(Visibility.NEVER);
|
binding.map.getZoomController().setVisibility(Visibility.NEVER);
|
||||||
binding.map.getController().setZoom(ZOOM_LEVEL);
|
binding.map.getController().setZoom(ZOOM_LEVEL);
|
||||||
binding.map.getOverlays().add(new MapEventsOverlay(new MapEventsReceiver() {
|
binding.map.getOverlays().add(mapEventsOverlay);
|
||||||
@Override
|
|
||||||
public boolean singleTapConfirmedHelper(GeoPoint p) {
|
|
||||||
if (clickedMarker != null) {
|
|
||||||
clickedMarker.closeInfoWindow();
|
|
||||||
} else {
|
|
||||||
Timber.e("CLICKED MARKER IS NULL");
|
|
||||||
}
|
|
||||||
if (isListBottomSheetExpanded()) {
|
|
||||||
// Back should first hide the bottom sheet if it is expanded
|
|
||||||
hideBottomSheet();
|
|
||||||
} else if (isDetailsBottomSheetVisible()) {
|
|
||||||
hideBottomDetailsSheet();
|
|
||||||
}
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public boolean longPressHelper(GeoPoint p) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
}));
|
|
||||||
|
|
||||||
binding.map.addMapListener(new MapListener() {
|
binding.map.addMapListener(new MapListener() {
|
||||||
@Override
|
@Override
|
||||||
|
|
@ -677,19 +678,20 @@ public class NearbyParentFragment extends CommonsDaggerSupportFragment
|
||||||
registerNetworkReceiver();
|
registerNetworkReceiver();
|
||||||
if (isResumed() && ((MainActivity) getActivity()).activeFragment == ActiveFragment.NEARBY) {
|
if (isResumed() && ((MainActivity) getActivity()).activeFragment == ActiveFragment.NEARBY) {
|
||||||
if (locationPermissionsHelper.checkLocationPermission(getActivity())) {
|
if (locationPermissionsHelper.checkLocationPermission(getActivity())) {
|
||||||
if (lastFocusLocation == null && lastKnownLocation == null) {
|
// if (lastFocusLocation == null && lastKnownLocation == null) {
|
||||||
locationPermissionGranted();
|
// locationPermissionGranted();
|
||||||
} else{
|
// } else{
|
||||||
if (updatedPlacesList != null) {
|
// if (updatedPlacesList != null) {
|
||||||
if (!updatedPlacesList.isEmpty()) {
|
// if (!updatedPlacesList.isEmpty()) {
|
||||||
loadPlacesDataAsync(updatedPlacesList, updatedLatLng);
|
// loadPlacesDataAsync(updatedPlacesList, updatedLatLng);
|
||||||
} else {
|
// } else {
|
||||||
updateMapMarkers(updatedPlacesList, getLastMapFocus(), false);
|
// updateMapMarkers(updatedPlacesList, getLastMapFocus(), false);
|
||||||
}
|
// }
|
||||||
}else {
|
// }else {
|
||||||
locationPermissionGranted();
|
// locationPermissionGranted();
|
||||||
}
|
// }
|
||||||
}
|
// }
|
||||||
|
locationPermissionGranted();
|
||||||
} else {
|
} else {
|
||||||
startMapWithoutPermission();
|
startMapWithoutPermission();
|
||||||
}
|
}
|
||||||
|
|
@ -1424,7 +1426,7 @@ public class NearbyParentFragment extends CommonsDaggerSupportFragment
|
||||||
lastFocusLocation = searchLatLng;
|
lastFocusLocation = searchLatLng;
|
||||||
lastMapFocus = new GeoPoint(searchLatLng.getLatitude(),
|
lastMapFocus = new GeoPoint(searchLatLng.getLatitude(),
|
||||||
searchLatLng.getLongitude());
|
searchLatLng.getLongitude());
|
||||||
loadPlacesDataAsync(nearbyPlacesInfo.placeList, nearbyPlacesInfo.currentLatLng);
|
// loadPlacesDataAsync(nearbyPlacesInfo.placeList, nearbyPlacesInfo.currentLatLng);
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
throwable -> {
|
throwable -> {
|
||||||
|
|
@ -1469,7 +1471,7 @@ public class NearbyParentFragment extends CommonsDaggerSupportFragment
|
||||||
lastMapFocus = new GeoPoint(searchLatLng.getLatitude(),
|
lastMapFocus = new GeoPoint(searchLatLng.getLatitude(),
|
||||||
searchLatLng.getLongitude());
|
searchLatLng.getLongitude());
|
||||||
stopQuery();
|
stopQuery();
|
||||||
loadPlacesDataAsync(nearbyPlacesInfo.placeList, nearbyPlacesInfo.currentLatLng);
|
// loadPlacesDataAsync(nearbyPlacesInfo.placeList, nearbyPlacesInfo.currentLatLng);
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
throwable -> {
|
throwable -> {
|
||||||
|
|
@ -1935,8 +1937,7 @@ public class NearbyParentFragment extends CommonsDaggerSupportFragment
|
||||||
final boolean displayWlm = false;
|
final boolean displayWlm = false;
|
||||||
// Remove the previous markers before updating them
|
// Remove the previous markers before updating them
|
||||||
// clearAllMarkers(); // moved
|
// clearAllMarkers(); // moved
|
||||||
int debugcount = 0;
|
ArrayList<MarkerPlaceGroup> es = new ArrayList<>();
|
||||||
ArrayList<Experiment> 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();
|
||||||
// When label filter is engaged
|
// When label filter is engaged
|
||||||
|
|
@ -1977,29 +1978,27 @@ public class NearbyParentFragment extends CommonsDaggerSupportFragment
|
||||||
}
|
}
|
||||||
|
|
||||||
if (shouldUpdateMarker) {
|
if (shouldUpdateMarker) {
|
||||||
++debugcount;
|
Experiment e = new Experiment(place, markerPlaceGroup.getIsBookmarked());
|
||||||
Experiment e = new Experiment();
|
|
||||||
e.place = place;
|
|
||||||
e.isBookmarked = markerPlaceGroup.getIsBookmarked();
|
|
||||||
// updateMarker(markerPlaceGroup.getIsBookmarked(), place,
|
// updateMarker(markerPlaceGroup.getIsBookmarked(), place,
|
||||||
// NearbyController.currentLocation);
|
// NearbyController.currentLocation);
|
||||||
es.add(e);
|
es.add(e);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
experimenting(es);
|
justExperimenting.loadNewMarkers(es);
|
||||||
Timber.tag("temptagtwo").e("n+1 C 2: "+debugcount);
|
|
||||||
// Timber.tag("temptagtwo").e("iscowa: "+(binding.map.getOverlays() instanceof CopyOnWriteArrayList<Overlay>));
|
// Timber.tag("temptagtwo").e("iscowa: "+(binding.map.getOverlays() instanceof CopyOnWriteArrayList<Overlay>));
|
||||||
// Timber.tag("temptagtwo").e("additional debug info: "+(Looper.myLooper() == Looper.getMainLooper()));
|
// Timber.tag("temptagtwo").e("additional debug info: "+(Looper.myLooper() == Looper.getMainLooper()));
|
||||||
if (selectedLabels == null || selectedLabels.size() == 0) {
|
|
||||||
ArrayList<BaseMarker> markerArrayList = new ArrayList<>();
|
//TODO experimentation touncomment
|
||||||
for (final MarkerPlaceGroup markerPlaceGroup : NearbyController.markerLabelList) {
|
// if (selectedLabels == null || selectedLabels.size() == 0) {
|
||||||
BaseMarker nearbyBaseMarker = new BaseMarker();
|
// ArrayList<BaseMarker> markerArrayList = new ArrayList<>();
|
||||||
nearbyBaseMarker.setPlace(markerPlaceGroup.getPlace());
|
// for (final MarkerPlaceGroup markerPlaceGroup : NearbyController.markerLabelList) {
|
||||||
markerArrayList.add(nearbyBaseMarker);
|
// BaseMarker nearbyBaseMarker = new BaseMarker();
|
||||||
}
|
// nearbyBaseMarker.setPlace(markerPlaceGroup.getPlace());
|
||||||
//TODO experimentation touncomment
|
// markerArrayList.add(nearbyBaseMarker);
|
||||||
|
// }
|
||||||
// addMarkersToMap(markerArrayList);
|
// addMarkersToMap(markerArrayList);
|
||||||
}
|
// }
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|
@ -2016,6 +2015,9 @@ public class NearbyParentFragment extends CommonsDaggerSupportFragment
|
||||||
*/
|
*/
|
||||||
public void updateMarker(final boolean isBookmarked, final Place place,
|
public void updateMarker(final boolean isBookmarked, final Place place,
|
||||||
@Nullable final LatLng currentLatLng) {
|
@Nullable final LatLng currentLatLng) {
|
||||||
|
if(true) {
|
||||||
|
return; // TODO move this method to new overlay mangement logic
|
||||||
|
}
|
||||||
addMarkerToMap(place, isBookmarked);
|
addMarkerToMap(place, isBookmarked);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -2118,7 +2120,7 @@ public class NearbyParentFragment extends CommonsDaggerSupportFragment
|
||||||
Timber.tag("temptag").d("added marker");
|
Timber.tag("temptag").d("added marker");
|
||||||
}
|
}
|
||||||
|
|
||||||
private Marker convertToMarker(Place place, Boolean isBookMarked) {
|
public Marker convertToMarker(Place place, Boolean isBookMarked) {
|
||||||
Drawable icon = ContextCompat.getDrawable(getContext(), getIconFor(place, isBookMarked));
|
Drawable icon = ContextCompat.getDrawable(getContext(), getIconFor(place, isBookMarked));
|
||||||
GeoPoint point = new GeoPoint(place.location.getLatitude(), place.location.getLongitude());
|
GeoPoint point = new GeoPoint(place.location.getLatitude(), place.location.getLongitude());
|
||||||
Marker marker = new Marker(binding.map);
|
Marker marker = new Marker(binding.map);
|
||||||
|
|
@ -2157,20 +2159,7 @@ public class NearbyParentFragment extends CommonsDaggerSupportFragment
|
||||||
return marker;
|
return marker;
|
||||||
}
|
}
|
||||||
|
|
||||||
private class Experiment {
|
public void replaceMarkerOverlays(final List<Marker> ms){
|
||||||
public Place place;
|
|
||||||
public Boolean isBookmarked;
|
|
||||||
}
|
|
||||||
|
|
||||||
private void experimenting(final List<Experiment> pubs) {
|
|
||||||
// if(System.currentTimeMillis()>1734359981239L) {return;}
|
|
||||||
ArrayList<Marker> ms = new ArrayList<>(pubs.size());
|
|
||||||
for(Experiment e: pubs){
|
|
||||||
ms.add(convertToMarker(e.place,e.isBookmarked));
|
|
||||||
}
|
|
||||||
justExperimenting.updateMarkersState(ms);
|
|
||||||
}
|
|
||||||
public void experimentingPartTwo(final List<Marker> ms){
|
|
||||||
clearAllMarkers();
|
clearAllMarkers();
|
||||||
binding.map.getOverlays().addAll(ms);
|
binding.map.getOverlays().addAll(ms);
|
||||||
}
|
}
|
||||||
|
|
@ -2513,28 +2502,7 @@ public class NearbyParentFragment extends CommonsDaggerSupportFragment
|
||||||
scaleBarOverlay.setBackgroundPaint(barPaint);
|
scaleBarOverlay.setBackgroundPaint(barPaint);
|
||||||
scaleBarOverlay.enableScaleBar();
|
scaleBarOverlay.enableScaleBar();
|
||||||
binding.map.getOverlays().add(scaleBarOverlay);
|
binding.map.getOverlays().add(scaleBarOverlay);
|
||||||
binding.map.getOverlays().add(new MapEventsOverlay(new MapEventsReceiver() {
|
binding.map.getOverlays().add(mapEventsOverlay);
|
||||||
@Override
|
|
||||||
public boolean singleTapConfirmedHelper(GeoPoint p) {
|
|
||||||
if (clickedMarker != null) {
|
|
||||||
clickedMarker.closeInfoWindow();
|
|
||||||
} else {
|
|
||||||
Timber.e("CLICKED MARKER IS NULL");
|
|
||||||
}
|
|
||||||
if (isListBottomSheetExpanded()) {
|
|
||||||
// Back should first hide the bottom sheet if it is expanded
|
|
||||||
hideBottomSheet();
|
|
||||||
} else if (isDetailsBottomSheetVisible()) {
|
|
||||||
hideBottomDetailsSheet();
|
|
||||||
}
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public boolean longPressHelper(GeoPoint p) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
}));
|
|
||||||
binding.map.setMultiTouchControls(true);
|
binding.map.setMultiTouchControls(true);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -1,33 +1,88 @@
|
||||||
package fr.free.nrw.commons.nearby.helper
|
package fr.free.nrw.commons.nearby.helper
|
||||||
|
|
||||||
import androidx.lifecycle.lifecycleScope
|
import androidx.lifecycle.lifecycleScope
|
||||||
import fr.free.nrw.commons.databinding.FragmentNearbyParentBinding
|
import fr.free.nrw.commons.nearby.MarkerPlaceGroup
|
||||||
import fr.free.nrw.commons.nearby.fragments.NearbyParentFragment
|
import fr.free.nrw.commons.nearby.fragments.NearbyParentFragment
|
||||||
import kotlinx.coroutines.Dispatchers
|
import kotlinx.coroutines.Job
|
||||||
|
import kotlinx.coroutines.channels.Channel
|
||||||
import kotlinx.coroutines.delay
|
import kotlinx.coroutines.delay
|
||||||
|
import kotlinx.coroutines.ensureActive
|
||||||
import kotlinx.coroutines.flow.MutableStateFlow
|
import kotlinx.coroutines.flow.MutableStateFlow
|
||||||
import kotlinx.coroutines.flow.collectLatest
|
import kotlinx.coroutines.flow.collectLatest
|
||||||
import kotlinx.coroutines.launch
|
import kotlinx.coroutines.launch
|
||||||
import org.osmdroid.views.overlay.Marker
|
import org.osmdroid.views.overlay.Marker
|
||||||
import timber.log.Timber
|
import timber.log.Timber
|
||||||
|
import java.util.ArrayList
|
||||||
|
|
||||||
class JustExperimenting(frag: NearbyParentFragment) {
|
class JustExperimenting(frag: NearbyParentFragment) {
|
||||||
private var markersState = MutableStateFlow(emptyList<Marker>());
|
private val scope = frag.lifecycleScope
|
||||||
|
|
||||||
private var skippedCount = 0;
|
private var skippedCount = 0;
|
||||||
|
private val skipLimit = 2;
|
||||||
|
private val skipDelayMs = 1000L;
|
||||||
|
|
||||||
|
private var markersState = MutableStateFlow(emptyList<Marker>());
|
||||||
|
private val markerBaseDataChannel = Channel<ArrayList<MarkerPlaceGroup>>(Channel.CONFLATED);
|
||||||
|
|
||||||
|
|
||||||
|
fun loadNewMarkers(es: ArrayList<MarkerPlaceGroup>) = scope.launch {
|
||||||
|
markerBaseDataChannel.send(es)
|
||||||
|
}
|
||||||
fun updateMarkersState(markers: List<Marker>){
|
fun updateMarkersState(markers: List<Marker>){
|
||||||
markersState.value = markers
|
markersState.value = markers
|
||||||
}
|
}
|
||||||
init {
|
init {
|
||||||
frag.lifecycleScope.launch(Dispatchers.Default) {
|
scope.launch {
|
||||||
markersState.collectLatest {
|
markersState.collectLatest {
|
||||||
++skippedCount;
|
if(skippedCount++<skipLimit){
|
||||||
if(skippedCount<5){
|
delay(skipDelayMs);
|
||||||
delay(500);
|
|
||||||
}
|
}
|
||||||
skippedCount = 0;
|
skippedCount = 0;
|
||||||
Timber.tag("temptagtwo").d("here: ${it.size}")
|
Timber.tag("temptagtwo").d("here: ${it.size}")
|
||||||
frag.experimentingPartTwo(it);
|
frag.replaceMarkerOverlays(it);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
scope.launch {
|
||||||
|
var loadPinDetailsJob: Job? = null
|
||||||
|
for(markerBaseDataList in markerBaseDataChannel) {
|
||||||
|
loadPinDetailsJob?.cancel()
|
||||||
|
loadPinDetailsJob = launch {
|
||||||
|
|
||||||
|
// make sure the grey pins are loaded immediately:
|
||||||
|
skippedCount = skipLimit
|
||||||
|
updateMarkersState(
|
||||||
|
markerBaseDataList.map {
|
||||||
|
frag.convertToMarker(it.place, it.isBookmarked)
|
||||||
|
}
|
||||||
|
)
|
||||||
|
|
||||||
|
// now load the pin details:
|
||||||
|
markerBaseDataList.sortBy {
|
||||||
|
it.place.getDistanceInDouble(frag.mapFocus)
|
||||||
|
}
|
||||||
|
|
||||||
|
val batchSize = 3
|
||||||
|
|
||||||
|
for (i in markerBaseDataList.indices step batchSize) {
|
||||||
|
ensureActive()
|
||||||
|
// TODO
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
// private val mapEventsOverlay = frag.mapEventsOverlay
|
||||||
|
// fun getBaseOverlays(view: MapView): List<Overlay> = listOf(
|
||||||
|
// // distance scale
|
||||||
|
// ScaleBarOverlay(view).apply {
|
||||||
|
// setScaleBarOffset(15, 25)
|
||||||
|
// setBackgroundPaint(Paint().apply { setARGB(200, 255, 250, 250) })
|
||||||
|
// enableScaleBar()
|
||||||
|
// },
|
||||||
|
// // map events overlay:
|
||||||
|
// mapEventsOverlay
|
||||||
|
// )
|
||||||
|
|
||||||
}
|
}
|
||||||
Loading…
Add table
Add a link
Reference in a new issue