temporary fixes part three

This commit is contained in:
savsch 2024-12-17 21:16:43 +05:30
parent e2dd4ba0a8
commit 422ba8dcfa
2 changed files with 54 additions and 64 deletions

View file

@ -95,7 +95,6 @@ import fr.free.nrw.commons.nearby.PlacesRepository;
import fr.free.nrw.commons.nearby.WikidataFeedback;
import fr.free.nrw.commons.nearby.contract.NearbyParentFragmentContract;
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.model.BottomSheetItem;
import fr.free.nrw.commons.nearby.presenter.NearbyParentFragmentPresenter;
@ -244,7 +243,7 @@ public class NearbyParentFragment extends CommonsDaggerSupportFragment
private Runnable searchRunnable;
private static final long SCROLL_DELAY = 800; // Delay for debounce of onscroll, in milliseconds.
private List<Place> updatedPlacesList;
// private List<Place> updatedPlacesList;
private LatLng updatedLatLng;
private boolean searchable;
@ -1376,13 +1375,8 @@ public class NearbyParentFragment extends CommonsDaggerSupportFragment
? getTextBetweenParentheses(
updatedPlace.getLongDescription()) : updatedPlace.getLongDescription());
marker.showInfoWindow();
for (int i = 0; i < updatedPlacesList.size(); i++) {
Place pl = updatedPlacesList.get(i);
if (pl.location == updatedPlace.location) {
updatedPlacesList.set(i, updatedPlace);
savePlaceToDatabase(place);
}
}
justExperimenting.handlePlaceClicked(updatedPlace);
savePlaceToDatabase(place);
Drawable icon = ContextCompat.getDrawable(getContext(),
getIconFor(updatedPlace, isBookMarked));
marker.setIcon(icon);
@ -1492,7 +1486,7 @@ public class NearbyParentFragment extends CommonsDaggerSupportFragment
int batchSize = 3;
updatedLatLng = curLatLng;
updatedPlacesList = new ArrayList<>(placeList);
// updatedPlacesList = new ArrayList<>(placeList);
// Sorts the places by distance to ensure the nearest pins are ready for the user as soon
// as possible.
@ -1501,7 +1495,7 @@ public class NearbyParentFragment extends CommonsDaggerSupportFragment
Comparator.comparingDouble(place -> place.getDistanceInDouble(getMapFocus())));
}
stopQuery = false;
processBatchesSequentially(places, batchSize, updatedPlacesList, curLatLng, 0);
// processBatchesSequentially(places, batchSize, updatedPlacesList, curLatLng, 0);
}
/**
@ -1978,7 +1972,7 @@ public class NearbyParentFragment extends CommonsDaggerSupportFragment
}
if (shouldUpdateMarker) {
Experiment e = new Experiment(place, markerPlaceGroup.getIsBookmarked());
MarkerPlaceGroup e = new MarkerPlaceGroup(markerPlaceGroup.getIsBookmarked(), place);
// updateMarker(markerPlaceGroup.getIsBookmarked(), place,
// NearbyController.currentLocation);
es.add(e);
@ -2081,43 +2075,8 @@ public class NearbyParentFragment extends CommonsDaggerSupportFragment
* @param isBookMarked A Boolean flag indicating whether the place is bookmarked or not.
*/
private void addMarkerToMap(Place place, Boolean isBookMarked) {
Drawable icon = ContextCompat.getDrawable(getContext(), getIconFor(place, isBookMarked));
GeoPoint point = new GeoPoint(place.location.getLatitude(), place.location.getLongitude());
Marker marker = new Marker(binding.map);
marker.setPosition(point);
marker.setIcon(icon);
if (!Objects.equals(place.name, "")) {
marker.setTitle(place.name);
marker.setSnippet(
containsParentheses(place.getLongDescription())
? getTextBetweenParentheses(
place.getLongDescription()) : place.getLongDescription());
}
marker.setTextLabelFontSize(40);
marker.setAnchor(Marker.ANCHOR_CENTER, Marker.ANCHOR_TOP);
marker.setOnMarkerClickListener((marker1, mapView) -> {
if (clickedMarker != null) {
clickedMarker.closeInfoWindow();
}
clickedMarker = marker1;
binding.bottomSheetDetails.dataCircularProgress.setVisibility(View.VISIBLE);
binding.bottomSheetDetails.icon.setVisibility(View.GONE);
binding.bottomSheetDetails.wikiDataLl.setVisibility(View.GONE);
if (Objects.equals(place.name, "")) {
getPlaceData(place.getWikiDataEntityId(), place, marker1, isBookMarked);
} else {
marker.showInfoWindow();
binding.bottomSheetDetails.dataCircularProgress.setVisibility(View.GONE);
binding.bottomSheetDetails.icon.setVisibility(View.VISIBLE);
binding.bottomSheetDetails.wikiDataLl.setVisibility(View.VISIBLE);
passInfoToSheet(place);
hideBottomSheet();
}
bottomSheetDetailsBehavior.setState(BottomSheetBehavior.STATE_COLLAPSED);
return true;
});
binding.map.getOverlays().add(marker);
Timber.tag("temptag").d("added marker");
binding.map.getOverlays().add(convertToMarker(place, isBookMarked));
Timber.tag("temptag").d("added marker THE OLD WAY");
}
public Marker convertToMarker(Place place, Boolean isBookMarked) {

View file

@ -1,8 +1,12 @@
package fr.free.nrw.commons.nearby.helper
import androidx.lifecycle.DefaultLifecycleObserver
import androidx.lifecycle.LifecycleOwner
import androidx.lifecycle.lifecycleScope
import fr.free.nrw.commons.nearby.MarkerPlaceGroup
import fr.free.nrw.commons.nearby.Place
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
@ -13,17 +17,22 @@ import kotlinx.coroutines.launch
import org.osmdroid.views.overlay.Marker
import timber.log.Timber
import java.util.ArrayList
import java.util.concurrent.CopyOnWriteArraySet
class JustExperimenting(frag: NearbyParentFragment) {
private val scope = frag.lifecycleScope
private val scope = frag.viewLifecycleOwner.lifecycleScope
private var skippedCount = 0;
private val skipLimit = 2;
private val skipDelayMs = 1000L;
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);
private var markersState = MutableStateFlow(emptyList<Marker>())
private val markerBaseDataChannel = Channel<ArrayList<MarkerPlaceGroup>>(Channel.CONFLATED)
private val clickedPlaces = CopyOnWriteArraySet<Place>()
fun handlePlaceClicked(place: Place) {
clickedPlaces.add(place)
}
fun loadNewMarkers(es: ArrayList<MarkerPlaceGroup>) = scope.launch {
markerBaseDataChannel.send(es)
@ -32,17 +41,20 @@ class JustExperimenting(frag: NearbyParentFragment) {
markersState.value = markers
}
init {
scope.launch {
scope.launch(Dispatchers.Default) {
markersState.collectLatest {
if(skippedCount++<skipLimit){
delay(skipDelayMs);
if (it.isEmpty()) {
return@collectLatest
}
skippedCount = 0;
if (skippedCount++ < skipLimit) {
delay(skipDelayMs)
}
skippedCount = 0
Timber.tag("temptagtwo").d("here: ${it.size}")
frag.replaceMarkerOverlays(it);
frag.replaceMarkerOverlays(it)
}
}
scope.launch {
scope.launch(Dispatchers.Default) {
var loadPinDetailsJob: Job? = null
for(markerBaseDataList in markerBaseDataChannel) {
loadPinDetailsJob?.cancel()
@ -57,21 +69,40 @@ class JustExperimenting(frag: NearbyParentFragment) {
)
// now load the pin details:
clickedPlaces.clear()
var clickedPlacesIndex = 0
markerBaseDataList.sortBy {
it.place.getDistanceInDouble(frag.mapFocus)
}
val updatedMarkers = ArrayList<Marker>(markerBaseDataList.size)
markerBaseDataList.forEach {
updatedMarkers.add(frag.convertToMarker(it.place, it.isBookmarked))
}
val batchSize = 3
for (i in markerBaseDataList.indices step batchSize) {
var currentIndex = 0
val endIndex = markerBaseDataList.lastIndex
while (currentIndex <= endIndex) {
ensureActive()
// TODO
val placesToProcess = HashMap<Int, Place>()
// while(currentIndex<=endIndex && )
++currentIndex // remove this, added just for testing
}
}
}
}
frag.viewLifecycleOwner.lifecycle.addObserver(object: DefaultLifecycleObserver {
override fun onDestroy(owner: LifecycleOwner) {
performCleanup()
}
})
}
private fun performCleanup() {
markerBaseDataChannel.close()
}
// private val mapEventsOverlay = frag.mapEventsOverlay
// fun getBaseOverlays(view: MapView): List<Overlay> = listOf(