mirror of
				https://github.com/commons-app/apps-android-commons.git
				synced 2025-10-31 06:43:56 +01:00 
			
		
		
		
	temporary fixes part three
This commit is contained in:
		
							parent
							
								
									e2dd4ba0a8
								
							
						
					
					
						commit
						422ba8dcfa
					
				
					 2 changed files with 54 additions and 64 deletions
				
			
		|  | @ -95,7 +95,6 @@ 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; | ||||||
|  | @ -244,7 +243,7 @@ public class NearbyParentFragment extends CommonsDaggerSupportFragment | ||||||
|     private Runnable searchRunnable; |     private Runnable searchRunnable; | ||||||
|     private static final long SCROLL_DELAY = 800; // Delay for debounce of onscroll, in milliseconds. |     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 LatLng updatedLatLng; | ||||||
|     private boolean searchable; |     private boolean searchable; | ||||||
| 
 | 
 | ||||||
|  | @ -1376,13 +1375,8 @@ public class NearbyParentFragment extends CommonsDaggerSupportFragment | ||||||
|                             ? getTextBetweenParentheses( |                             ? getTextBetweenParentheses( | ||||||
|                             updatedPlace.getLongDescription()) : updatedPlace.getLongDescription()); |                             updatedPlace.getLongDescription()) : updatedPlace.getLongDescription()); | ||||||
|                     marker.showInfoWindow(); |                     marker.showInfoWindow(); | ||||||
|                     for (int i = 0; i < updatedPlacesList.size(); i++) { |                     justExperimenting.handlePlaceClicked(updatedPlace); | ||||||
|                         Place pl = updatedPlacesList.get(i); |  | ||||||
|                         if (pl.location == updatedPlace.location) { |  | ||||||
|                             updatedPlacesList.set(i, updatedPlace); |  | ||||||
|                     savePlaceToDatabase(place); |                     savePlaceToDatabase(place); | ||||||
|                         } |  | ||||||
|                     } |  | ||||||
|                     Drawable icon = ContextCompat.getDrawable(getContext(), |                     Drawable icon = ContextCompat.getDrawable(getContext(), | ||||||
|                         getIconFor(updatedPlace, isBookMarked)); |                         getIconFor(updatedPlace, isBookMarked)); | ||||||
|                     marker.setIcon(icon); |                     marker.setIcon(icon); | ||||||
|  | @ -1492,7 +1486,7 @@ public class NearbyParentFragment extends CommonsDaggerSupportFragment | ||||||
|         int batchSize = 3; |         int batchSize = 3; | ||||||
| 
 | 
 | ||||||
|         updatedLatLng = curLatLng; |         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 |         // Sorts the places by distance to ensure the nearest pins are ready for the user as soon | ||||||
|         // as possible. |         // as possible. | ||||||
|  | @ -1501,7 +1495,7 @@ public class NearbyParentFragment extends CommonsDaggerSupportFragment | ||||||
|                 Comparator.comparingDouble(place -> place.getDistanceInDouble(getMapFocus()))); |                 Comparator.comparingDouble(place -> place.getDistanceInDouble(getMapFocus()))); | ||||||
|         } |         } | ||||||
|         stopQuery = false; |         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) { |             if (shouldUpdateMarker) { | ||||||
|                 Experiment e = new Experiment(place, markerPlaceGroup.getIsBookmarked()); |                 MarkerPlaceGroup e = new MarkerPlaceGroup(markerPlaceGroup.getIsBookmarked(), place); | ||||||
| //                updateMarker(markerPlaceGroup.getIsBookmarked(), place, | //                updateMarker(markerPlaceGroup.getIsBookmarked(), place, | ||||||
| //                    NearbyController.currentLocation); | //                    NearbyController.currentLocation); | ||||||
|                 es.add(e); |                 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. |      * @param isBookMarked A Boolean flag indicating whether the place is bookmarked or not. | ||||||
|      */ |      */ | ||||||
|     private void addMarkerToMap(Place place, Boolean isBookMarked) { |     private void addMarkerToMap(Place place, Boolean isBookMarked) { | ||||||
|         Drawable icon = ContextCompat.getDrawable(getContext(), getIconFor(place, isBookMarked)); |         binding.map.getOverlays().add(convertToMarker(place, isBookMarked)); | ||||||
|         GeoPoint point = new GeoPoint(place.location.getLatitude(), place.location.getLongitude()); |         Timber.tag("temptag").d("added marker THE OLD WAY"); | ||||||
|         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"); |  | ||||||
|     } |     } | ||||||
| 
 | 
 | ||||||
|     public Marker convertToMarker(Place place, Boolean isBookMarked) { |     public Marker convertToMarker(Place place, Boolean isBookMarked) { | ||||||
|  |  | ||||||
|  | @ -1,8 +1,12 @@ | ||||||
| package fr.free.nrw.commons.nearby.helper | package fr.free.nrw.commons.nearby.helper | ||||||
| 
 | 
 | ||||||
|  | import androidx.lifecycle.DefaultLifecycleObserver | ||||||
|  | import androidx.lifecycle.LifecycleOwner | ||||||
| import androidx.lifecycle.lifecycleScope | import androidx.lifecycle.lifecycleScope | ||||||
| import fr.free.nrw.commons.nearby.MarkerPlaceGroup | import fr.free.nrw.commons.nearby.MarkerPlaceGroup | ||||||
|  | import fr.free.nrw.commons.nearby.Place | ||||||
| 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.Job | ||||||
| import kotlinx.coroutines.channels.Channel | import kotlinx.coroutines.channels.Channel | ||||||
| import kotlinx.coroutines.delay | import kotlinx.coroutines.delay | ||||||
|  | @ -13,17 +17,22 @@ 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 | import java.util.ArrayList | ||||||
|  | import java.util.concurrent.CopyOnWriteArraySet | ||||||
| 
 | 
 | ||||||
| class JustExperimenting(frag: NearbyParentFragment) { | class JustExperimenting(frag: NearbyParentFragment) { | ||||||
|     private val scope = frag.lifecycleScope |     private val scope = frag.viewLifecycleOwner.lifecycleScope | ||||||
| 
 | 
 | ||||||
|     private var skippedCount = 0; |     private var skippedCount = 0 | ||||||
|     private val skipLimit = 2; |     private val skipLimit = 2 | ||||||
|     private val skipDelayMs = 1000L; |     private val skipDelayMs = 1000L | ||||||
| 
 | 
 | ||||||
|     private var markersState = MutableStateFlow(emptyList<Marker>()); |     private var markersState = MutableStateFlow(emptyList<Marker>()) | ||||||
|     private val markerBaseDataChannel = Channel<ArrayList<MarkerPlaceGroup>>(Channel.CONFLATED); |     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 { |     fun loadNewMarkers(es: ArrayList<MarkerPlaceGroup>) = scope.launch { | ||||||
|         markerBaseDataChannel.send(es) |         markerBaseDataChannel.send(es) | ||||||
|  | @ -32,17 +41,20 @@ class JustExperimenting(frag: NearbyParentFragment) { | ||||||
|         markersState.value = markers |         markersState.value = markers | ||||||
|     } |     } | ||||||
|     init { |     init { | ||||||
|         scope.launch { |         scope.launch(Dispatchers.Default) { | ||||||
|             markersState.collectLatest { |             markersState.collectLatest { | ||||||
|                 if(skippedCount++<skipLimit){ |                 if (it.isEmpty()) { | ||||||
|                     delay(skipDelayMs); |                     return@collectLatest | ||||||
|                 } |                 } | ||||||
|                 skippedCount = 0; |                 if (skippedCount++ < skipLimit) { | ||||||
|  |                     delay(skipDelayMs) | ||||||
|  |                 } | ||||||
|  |                 skippedCount = 0 | ||||||
|                 Timber.tag("temptagtwo").d("here: ${it.size}") |                 Timber.tag("temptagtwo").d("here: ${it.size}") | ||||||
|                 frag.replaceMarkerOverlays(it); |                 frag.replaceMarkerOverlays(it) | ||||||
|             } |             } | ||||||
|         } |         } | ||||||
|         scope.launch { |         scope.launch(Dispatchers.Default) { | ||||||
|             var loadPinDetailsJob: Job? = null |             var loadPinDetailsJob: Job? = null | ||||||
|             for(markerBaseDataList in markerBaseDataChannel) { |             for(markerBaseDataList in markerBaseDataChannel) { | ||||||
|                 loadPinDetailsJob?.cancel() |                 loadPinDetailsJob?.cancel() | ||||||
|  | @ -57,21 +69,40 @@ class JustExperimenting(frag: NearbyParentFragment) { | ||||||
|                     ) |                     ) | ||||||
| 
 | 
 | ||||||
|                     // now load the pin details: |                     // now load the pin details: | ||||||
|  |                     clickedPlaces.clear() | ||||||
|  |                     var clickedPlacesIndex = 0 | ||||||
|                     markerBaseDataList.sortBy { |                     markerBaseDataList.sortBy { | ||||||
|                         it.place.getDistanceInDouble(frag.mapFocus) |                         it.place.getDistanceInDouble(frag.mapFocus) | ||||||
|                     } |                     } | ||||||
|  |                     val updatedMarkers = ArrayList<Marker>(markerBaseDataList.size) | ||||||
|  |                     markerBaseDataList.forEach { | ||||||
|  |                         updatedMarkers.add(frag.convertToMarker(it.place, it.isBookmarked)) | ||||||
|  |                     } | ||||||
| 
 | 
 | ||||||
|                     val batchSize = 3 |                     val batchSize = 3 | ||||||
| 
 |                     var currentIndex = 0 | ||||||
|                     for (i in markerBaseDataList.indices step batchSize) { |                     val endIndex = markerBaseDataList.lastIndex | ||||||
|  |                     while (currentIndex <= endIndex) { | ||||||
|                         ensureActive() |                         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 | //    private val mapEventsOverlay = frag.mapEventsOverlay | ||||||
| //    fun getBaseOverlays(view: MapView): List<Overlay> = listOf( | //    fun getBaseOverlays(view: MapView): List<Overlay> = listOf( | ||||||
|  |  | ||||||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue
	
	 savsch
						savsch