mirror of
https://github.com/commons-app/apps-android-commons.git
synced 2025-10-30 14:23:55 +01:00
Add place bookmarking logic, Remove all old code
This commit is contained in:
parent
3a97245120
commit
f19352b451
3 changed files with 46 additions and 38 deletions
|
|
@ -128,5 +128,7 @@ public interface NearbyParentFragmentContract {
|
||||||
void setCheckboxUnknown();
|
void setCheckboxUnknown();
|
||||||
|
|
||||||
void setAdvancedQuery(String query);
|
void setAdvancedQuery(String query);
|
||||||
|
|
||||||
|
void toggleBookmarkedStatus(Place place);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -597,8 +597,7 @@ public class NearbyParentFragment extends CommonsDaggerSupportFragment
|
||||||
return Unit.INSTANCE;
|
return Unit.INSTANCE;
|
||||||
},
|
},
|
||||||
(place, isBookmarked) -> {
|
(place, isBookmarked) -> {
|
||||||
updateMarker(isBookmarked, place, null);
|
presenter.toggleBookmarkedStatus(place);
|
||||||
binding.map.invalidate();
|
|
||||||
return Unit.INSTANCE;
|
return Unit.INSTANCE;
|
||||||
},
|
},
|
||||||
commonPlaceClickActions,
|
commonPlaceClickActions,
|
||||||
|
|
@ -1795,21 +1794,6 @@ public class NearbyParentFragment extends CommonsDaggerSupportFragment
|
||||||
return binding.map == null ? null : getMapFocus();
|
return binding.map == null ? null : getMapFocus();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Sets marker icon according to marker status. Sets title and distance.
|
|
||||||
*
|
|
||||||
* @param isBookmarked true if place is bookmarked
|
|
||||||
* @param place
|
|
||||||
* @param currentLatLng current location
|
|
||||||
*/
|
|
||||||
public void updateMarker(final boolean isBookmarked, final Place place,
|
|
||||||
@Nullable final LatLng currentLatLng) {
|
|
||||||
if (true) {
|
|
||||||
return; // TODO move this method to new overlay mangement logic
|
|
||||||
}
|
|
||||||
addMarkerToMap(place, isBookmarked);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Highlights nearest place when user clicks on home nearby banner
|
* Highlights nearest place when user clicks on home nearby banner
|
||||||
*
|
*
|
||||||
|
|
@ -1863,16 +1847,6 @@ public class NearbyParentFragment extends CommonsDaggerSupportFragment
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Adds a marker representing a place to the map with optional bookmark icon.
|
|
||||||
*
|
|
||||||
* @param place The Place object containing information about the location.
|
|
||||||
* @param isBookMarked A Boolean flag indicating whether the place is bookmarked or not.
|
|
||||||
*/
|
|
||||||
private void addMarkerToMap(Place place, Boolean isBookMarked) {
|
|
||||||
binding.map.getOverlays().add(convertToMarker(place, isBookMarked));
|
|
||||||
}
|
|
||||||
|
|
||||||
public 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());
|
||||||
|
|
@ -2301,21 +2275,14 @@ public class NearbyParentFragment extends CommonsDaggerSupportFragment
|
||||||
@Override
|
@Override
|
||||||
public void onBottomSheetItemClick(@Nullable View view, int position) {
|
public void onBottomSheetItemClick(@Nullable View view, int position) {
|
||||||
BottomSheetItem item = dataList.get(position);
|
BottomSheetItem item = dataList.get(position);
|
||||||
boolean isBookmarked = bookmarkLocationDao.findBookmarkLocation(selectedPlace);
|
|
||||||
switch (item.getImageResourceId()) {
|
switch (item.getImageResourceId()) {
|
||||||
case R.drawable.ic_round_star_border_24px:
|
case R.drawable.ic_round_star_border_24px:
|
||||||
bookmarkLocationDao.updateBookmarkLocation(selectedPlace);
|
presenter.toggleBookmarkedStatus(selectedPlace);
|
||||||
updateBookmarkButtonImage(selectedPlace);
|
updateBookmarkButtonImage(selectedPlace);
|
||||||
isBookmarked = bookmarkLocationDao.findBookmarkLocation(selectedPlace);
|
|
||||||
updateMarker(isBookmarked, selectedPlace, locationManager.getLastLocation());
|
|
||||||
binding.map.invalidate();
|
|
||||||
break;
|
break;
|
||||||
case R.drawable.ic_round_star_filled_24px:
|
case R.drawable.ic_round_star_filled_24px:
|
||||||
bookmarkLocationDao.updateBookmarkLocation(selectedPlace);
|
presenter.toggleBookmarkedStatus(selectedPlace);
|
||||||
updateBookmarkButtonImage(selectedPlace);
|
updateBookmarkButtonImage(selectedPlace);
|
||||||
isBookmarked = bookmarkLocationDao.findBookmarkLocation(selectedPlace);
|
|
||||||
updateMarker(isBookmarked, selectedPlace, locationManager.getLastLocation());
|
|
||||||
binding.map.invalidate();
|
|
||||||
break;
|
break;
|
||||||
case R.drawable.ic_directions_black_24dp:
|
case R.drawable.ic_directions_black_24dp:
|
||||||
Utils.handleGeoCoordinates(this.getContext(), selectedPlace.getLocation());
|
Utils.handleGeoCoordinates(this.getContext(), selectedPlace.getLocation());
|
||||||
|
|
|
||||||
|
|
@ -70,7 +70,9 @@ class NearbyParentFragmentPresenter
|
||||||
val skipDelayMs = 500L
|
val skipDelayMs = 500L
|
||||||
}
|
}
|
||||||
|
|
||||||
suspend fun schedulePlacesUpdate(markerPlaceGroups: List<MarkerPlaceGroup>) =
|
private var bookmarkChangedPlaces = CopyOnWriteArrayList<Place>()
|
||||||
|
|
||||||
|
private suspend fun schedulePlacesUpdate(markerPlaceGroups: List<MarkerPlaceGroup>) =
|
||||||
withContext(Dispatchers.Main) {
|
withContext(Dispatchers.Main) {
|
||||||
if (markerPlaceGroups.isEmpty()) return@withContext
|
if (markerPlaceGroups.isEmpty()) return@withContext
|
||||||
schedulePlacesUpdateJob?.cancel()
|
schedulePlacesUpdateJob?.cancel()
|
||||||
|
|
@ -83,6 +85,19 @@ class NearbyParentFragmentPresenter
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
override fun toggleBookmarkedStatus(place: Place?) {
|
||||||
|
if (place == null) return
|
||||||
|
val nowBookmarked = bookmarkLocationDao.updateBookmarkLocation(place)
|
||||||
|
bookmarkChangedPlaces.add(place)
|
||||||
|
val placeIndex =
|
||||||
|
NearbyController.markerLabelList.indexOfFirst { it.place.location == place.location }
|
||||||
|
NearbyController.markerLabelList[placeIndex] = MarkerPlaceGroup(
|
||||||
|
nowBookmarked,
|
||||||
|
NearbyController.markerLabelList[placeIndex].place
|
||||||
|
)
|
||||||
|
nearbyParentFragmentView.setFilterState()
|
||||||
|
}
|
||||||
|
|
||||||
override fun attachView(view: NearbyParentFragmentContract.View) {
|
override fun attachView(view: NearbyParentFragmentContract.View) {
|
||||||
this.nearbyParentFragmentView = view
|
this.nearbyParentFragmentView = view
|
||||||
}
|
}
|
||||||
|
|
@ -241,8 +256,12 @@ class NearbyParentFragmentPresenter
|
||||||
updatePlaceGroupsToControllerAndRender(nearbyPlaceGroups)
|
updatePlaceGroupsToControllerAndRender(nearbyPlaceGroups)
|
||||||
|
|
||||||
loadPlacesDataAyncJob = scope?.launch(Dispatchers.IO) {
|
loadPlacesDataAyncJob = scope?.launch(Dispatchers.IO) {
|
||||||
clickedPlaces.clear() // clear past clicks
|
// clear past clicks and bookmarkChanged queues
|
||||||
|
clickedPlaces.clear()
|
||||||
|
bookmarkChangedPlaces.clear()
|
||||||
var clickedPlacesIndex = 0
|
var clickedPlacesIndex = 0
|
||||||
|
var bookmarkChangedPlacesIndex = 0
|
||||||
|
|
||||||
val updatedGroups = nearbyPlaceGroups.toMutableList()
|
val updatedGroups = nearbyPlaceGroups.toMutableList()
|
||||||
// first load cached places:
|
// first load cached places:
|
||||||
val indicesToUpdate = mutableListOf<Int>()
|
val indicesToUpdate = mutableListOf<Int>()
|
||||||
|
|
@ -333,6 +352,26 @@ class NearbyParentFragmentPresenter
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
// handle any bookmarks toggled
|
||||||
|
if (bookmarkChangedPlacesIndex < bookmarkChangedPlaces.size) {
|
||||||
|
val bookmarkChangedPlacesBacklog = hashMapOf<LatLng, Place>()
|
||||||
|
while (bookmarkChangedPlacesIndex < bookmarkChangedPlaces.size) {
|
||||||
|
bookmarkChangedPlacesBacklog.put(
|
||||||
|
bookmarkChangedPlaces[bookmarkChangedPlacesIndex].location,
|
||||||
|
bookmarkChangedPlaces[bookmarkChangedPlacesIndex]
|
||||||
|
)
|
||||||
|
++bookmarkChangedPlacesIndex
|
||||||
|
}
|
||||||
|
for ((index, group) in updatedGroups.withIndex()) {
|
||||||
|
if (bookmarkChangedPlacesBacklog.containsKey(group.place.location)) {
|
||||||
|
updatedGroups[index] = MarkerPlaceGroup(
|
||||||
|
bookmarkLocationDao
|
||||||
|
.findBookmarkLocation(updatedGroups[index].place),
|
||||||
|
updatedGroups[index].place
|
||||||
|
)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
schedulePlacesUpdate(updatedGroups)
|
schedulePlacesUpdate(updatedGroups)
|
||||||
if (collectCount++ == totalBatches) {
|
if (collectCount++ == totalBatches) {
|
||||||
break
|
break
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue