mirror of
https://github.com/commons-app/apps-android-commons.git
synced 2025-10-26 20:33:53 +01:00
* Show bookmarked nearby locations differently (#2059) * added custom bookmark marker * passed value of bookmarkplacelist in tests * update the nearby markers on clicking bookmark buttons
This commit is contained in:
parent
16927057d0
commit
9451b00a15
5 changed files with 125 additions and 6 deletions
|
|
@ -133,7 +133,8 @@ public class NearbyController {
|
|||
public static List<NearbyBaseMarker> loadAttractionsFromLocationToBaseMarkerOptions(
|
||||
LatLng curLatLng,
|
||||
List<Place> placeList,
|
||||
Context context) {
|
||||
Context context,
|
||||
List<Place> bookmarkplacelist) {
|
||||
List<NearbyBaseMarker> baseMarkerOptions = new ArrayList<>();
|
||||
|
||||
if (placeList == null) {
|
||||
|
|
@ -143,6 +144,37 @@ public class NearbyController {
|
|||
placeList = placeList.subList(0, Math.min(placeList.size(), MAX_RESULTS));
|
||||
|
||||
VectorDrawableCompat vectorDrawable = null;
|
||||
try {
|
||||
vectorDrawable = VectorDrawableCompat.create(
|
||||
context.getResources(), R.drawable.ic_custom_bookmark_marker, context.getTheme()
|
||||
);
|
||||
} catch (Resources.NotFoundException e) {
|
||||
// ignore when running tests.
|
||||
}
|
||||
if (vectorDrawable != null) {
|
||||
Bitmap icon = UiUtils.getBitmap(vectorDrawable);
|
||||
|
||||
for (Place place : bookmarkplacelist) {
|
||||
|
||||
String distance = formatDistanceBetween(curLatLng, place.location);
|
||||
place.setDistance(distance);
|
||||
|
||||
NearbyBaseMarker nearbyBaseMarker = new NearbyBaseMarker();
|
||||
nearbyBaseMarker.title(place.name);
|
||||
nearbyBaseMarker.position(
|
||||
new com.mapbox.mapboxsdk.geometry.LatLng(
|
||||
place.location.getLatitude(),
|
||||
place.location.getLongitude()));
|
||||
nearbyBaseMarker.place(place);
|
||||
nearbyBaseMarker.icon(IconFactory.getInstance(context)
|
||||
.fromBitmap(icon));
|
||||
placeList.remove(place);
|
||||
|
||||
baseMarkerOptions.add(nearbyBaseMarker);
|
||||
}
|
||||
}
|
||||
|
||||
vectorDrawable = null;
|
||||
try {
|
||||
vectorDrawable = VectorDrawableCompat.create(
|
||||
context.getResources(), R.drawable.ic_custom_map_marker, context.getTheme()
|
||||
|
|
@ -170,6 +202,7 @@ public class NearbyController {
|
|||
baseMarkerOptions.add(nearbyBaseMarker);
|
||||
}
|
||||
}
|
||||
|
||||
return baseMarkerOptions;
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -4,6 +4,8 @@ import android.animation.ObjectAnimator;
|
|||
import android.animation.TypeEvaluator;
|
||||
import android.animation.ValueAnimator;
|
||||
import android.content.Intent;
|
||||
import android.content.res.Resources;
|
||||
import android.graphics.Bitmap;
|
||||
import android.graphics.Color;
|
||||
import android.net.Uri;
|
||||
import android.os.Bundle;
|
||||
|
|
@ -12,6 +14,7 @@ import android.support.annotation.Nullable;
|
|||
import android.support.design.widget.BottomSheetBehavior;
|
||||
import android.support.design.widget.CoordinatorLayout;
|
||||
import android.support.design.widget.FloatingActionButton;
|
||||
import android.support.graphics.drawable.VectorDrawableCompat;
|
||||
import android.support.v7.app.AlertDialog;
|
||||
import android.view.Gravity;
|
||||
import android.view.KeyEvent;
|
||||
|
|
@ -30,6 +33,7 @@ import com.google.gson.Gson;
|
|||
import com.google.gson.GsonBuilder;
|
||||
import com.google.gson.reflect.TypeToken;
|
||||
import com.mapbox.mapboxsdk.Mapbox;
|
||||
import com.mapbox.mapboxsdk.annotations.BaseMarkerOptions;
|
||||
import com.mapbox.mapboxsdk.annotations.Icon;
|
||||
import com.mapbox.mapboxsdk.annotations.IconFactory;
|
||||
import com.mapbox.mapboxsdk.annotations.Marker;
|
||||
|
|
@ -62,6 +66,7 @@ import fr.free.nrw.commons.kvstore.JsonKvStore;
|
|||
import fr.free.nrw.commons.utils.ImageUtils;
|
||||
import fr.free.nrw.commons.utils.IntentUtils;
|
||||
import fr.free.nrw.commons.utils.LocationUtils;
|
||||
import fr.free.nrw.commons.utils.UiUtils;
|
||||
import fr.free.nrw.commons.utils.UriDeserializer;
|
||||
import fr.free.nrw.commons.utils.ViewUtil;
|
||||
import timber.log.Timber;
|
||||
|
|
@ -69,6 +74,7 @@ import timber.log.Timber;
|
|||
import static fr.free.nrw.commons.contributions.ContributionController.NEARBY_CAMERA_UPLOAD_REQUEST_CODE;
|
||||
import static fr.free.nrw.commons.contributions.ContributionController.NEARBY_GALLERY_UPLOAD_REQUEST_CODE;
|
||||
import static fr.free.nrw.commons.contributions.ContributionController.NEARBY_UPLOAD_IMAGE_LIMIT;
|
||||
import static fr.free.nrw.commons.utils.LengthUtils.formatDistanceBetween;
|
||||
import static fr.free.nrw.commons.wikidata.WikidataConstants.PLACE_OBJECT;
|
||||
|
||||
public class NearbyMapFragment extends DaggerFragment {
|
||||
|
|
@ -77,6 +83,7 @@ public class NearbyMapFragment extends DaggerFragment {
|
|||
private List<NearbyBaseMarker> baseMarkerOptions;
|
||||
private fr.free.nrw.commons.location.LatLng curLatLng;
|
||||
public fr.free.nrw.commons.location.LatLng[] boundaryCoordinates;
|
||||
private List<Place> bookmarkedplaces;
|
||||
|
||||
private View bottomSheetList;
|
||||
private View bottomSheetDetails;
|
||||
|
|
@ -162,7 +169,8 @@ public class NearbyMapFragment extends DaggerFragment {
|
|||
baseMarkerOptions = NearbyController
|
||||
.loadAttractionsFromLocationToBaseMarkerOptions(curLatLng,
|
||||
placeList,
|
||||
getActivity());
|
||||
getActivity(),
|
||||
bookmarkLocationDao.getAllBookmarksLocations());
|
||||
boundaryCoordinates = gson.fromJson(gsonBoundaryCoordinates, gsonBoundaryCoordinatesType);
|
||||
}
|
||||
if (curLatLng != null) {
|
||||
|
|
@ -247,7 +255,8 @@ public class NearbyMapFragment extends DaggerFragment {
|
|||
baseMarkerOptions = NearbyController
|
||||
.loadAttractionsFromLocationToBaseMarkerOptions(curLatLng,
|
||||
placeList,
|
||||
getActivity());
|
||||
getActivity(),
|
||||
bookmarkLocationDao.getAllBookmarksLocations());
|
||||
boundaryCoordinates = gson.fromJson(gsonBoundaryCoordinates, gsonBoundaryCoordinatesType);
|
||||
}
|
||||
mapboxMap.clear();
|
||||
|
|
@ -269,7 +278,8 @@ public class NearbyMapFragment extends DaggerFragment {
|
|||
List<NearbyBaseMarker> customBaseMarkerOptions = NearbyController
|
||||
.loadAttractionsFromLocationToBaseMarkerOptions(curLatLng, // Curlatlang will be used to calculate distances
|
||||
placeList,
|
||||
getActivity());
|
||||
getActivity(),
|
||||
bookmarkLocationDao.getAllBookmarksLocations());
|
||||
mapboxMap.clear();
|
||||
// We are trying to find nearby places around our custom searched area, thus custom parameter is nonnull
|
||||
addNearbyMarkersToMapBoxMap(customBaseMarkerOptions);
|
||||
|
|
@ -825,6 +835,7 @@ public class NearbyMapFragment extends DaggerFragment {
|
|||
boolean isBookmarked = bookmarkLocationDao.updateBookmarkLocation(place);
|
||||
int updatedIcon = isBookmarked ? R.drawable.ic_round_star_filled_24px : R.drawable.ic_round_star_border_24px;
|
||||
bookmarkButtonImage.setImageResource(updatedIcon);
|
||||
updateMarker(isBookmarked, place);
|
||||
});
|
||||
|
||||
wikipediaButton.setEnabled(place.hasWikipediaLink());
|
||||
|
|
@ -937,6 +948,7 @@ public class NearbyMapFragment extends DaggerFragment {
|
|||
if (mapView != null) {
|
||||
mapView.onPause();
|
||||
}
|
||||
bookmarkedplaces = bookmarkLocationDao.getAllBookmarksLocations();
|
||||
super.onPause();
|
||||
}
|
||||
|
||||
|
|
@ -957,6 +969,13 @@ public class NearbyMapFragment extends DaggerFragment {
|
|||
setListeners();
|
||||
transparentView.setClickable(false);
|
||||
transparentView.setAlpha(0);
|
||||
if (bookmarkedplaces != null) {
|
||||
for (Place place : bookmarkedplaces) {
|
||||
if (!bookmarkLocationDao.findBookmarkLocation(place)) {
|
||||
updateMarker(false, place);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
@ -991,4 +1010,43 @@ public class NearbyMapFragment extends DaggerFragment {
|
|||
return latLng;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public void updateMarker(boolean isBookmarked, Place place) {
|
||||
|
||||
VectorDrawableCompat vectorDrawable;
|
||||
if (isBookmarked) {
|
||||
vectorDrawable = VectorDrawableCompat.create(
|
||||
getContext().getResources(), R.drawable.ic_custom_bookmark_marker, getContext().getTheme()
|
||||
);
|
||||
}
|
||||
else {
|
||||
vectorDrawable = VectorDrawableCompat.create(
|
||||
getContext().getResources(), R.drawable.ic_custom_map_marker, getContext().getTheme()
|
||||
);
|
||||
}
|
||||
for(Marker marker: mapboxMap.getMarkers()){
|
||||
if(marker.getTitle()!=null && marker.getTitle().equals(place.getName())){
|
||||
|
||||
Bitmap icon = UiUtils.getBitmap(vectorDrawable);
|
||||
|
||||
String distance = formatDistanceBetween(curLatLng, place.location);
|
||||
place.setDistance(distance);
|
||||
|
||||
NearbyBaseMarker nearbyBaseMarker = new NearbyBaseMarker();
|
||||
nearbyBaseMarker.title(place.name);
|
||||
nearbyBaseMarker.position(
|
||||
new com.mapbox.mapboxsdk.geometry.LatLng(
|
||||
place.location.getLatitude(),
|
||||
place.location.getLongitude()));
|
||||
nearbyBaseMarker.place(place);
|
||||
nearbyBaseMarker.icon(IconFactory.getInstance(getContext())
|
||||
.fromBitmap(icon));
|
||||
marker.setIcon(IconFactory.getInstance(getContext()).fromBitmap(icon));
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -4,6 +4,7 @@ import android.content.Intent;
|
|||
import android.net.Uri;
|
||||
import android.support.transition.TransitionManager;
|
||||
import android.support.v4.app.Fragment;
|
||||
import android.support.v4.app.FragmentManager;
|
||||
import android.support.v7.app.AlertDialog;
|
||||
import android.support.v7.widget.PopupMenu;
|
||||
import android.view.LayoutInflater;
|
||||
|
|
@ -28,6 +29,7 @@ import fr.free.nrw.commons.Utils;
|
|||
import fr.free.nrw.commons.auth.LoginActivity;
|
||||
import fr.free.nrw.commons.bookmarks.locations.BookmarkLocationsDao;
|
||||
import fr.free.nrw.commons.contributions.ContributionController;
|
||||
import fr.free.nrw.commons.contributions.MainActivity;
|
||||
import fr.free.nrw.commons.di.ApplicationlessInjection;
|
||||
import fr.free.nrw.commons.kvstore.BasicKvStore;
|
||||
import fr.free.nrw.commons.kvstore.JsonKvStore;
|
||||
|
|
@ -187,6 +189,9 @@ public class PlaceRenderer extends Renderer<Place> {
|
|||
if (onBookmarkClick != null) {
|
||||
onBookmarkClick.onClick();
|
||||
}
|
||||
else {
|
||||
((NearbyMapFragment)((NearbyFragment)((NearbyListFragment)fragment).getParentFragment()).getChildFragmentManager().findFragmentByTag(NearbyMapFragment.class.getSimpleName())).updateMarker(isBookmarked, place);
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
|
|
|||
23
app/src/main/res/drawable/ic_custom_bookmark_marker.xml
Normal file
23
app/src/main/res/drawable/ic_custom_bookmark_marker.xml
Normal file
|
|
@ -0,0 +1,23 @@
|
|||
<vector xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:width="24dp"
|
||||
android:height="28dp"
|
||||
android:viewportWidth="24.0"
|
||||
android:viewportHeight="28.0">
|
||||
<path
|
||||
android:fillAlpha="0.1"
|
||||
android:fillColor="#000000"
|
||||
android:pathData="M6.072,22.223a6.031,3.672 0,1 0,12.062 0a6.031,3.672 0,1 0,-12.062 0z"
|
||||
android:strokeWidth="1" />
|
||||
<path
|
||||
android:fillAlpha="1"
|
||||
android:fillColor="#000000"
|
||||
android:pathData="M11.575,11.62C10.689,11.462 9.902,10.759 9.625,9.878 9.553,9.65 9.535,9.499 9.538,9.14c0.004,-0.397 0.019,-0.492 0.13,-0.787 0.236,-0.631 0.646,-1.099 1.212,-1.382 0.386,-0.193 0.709,-0.272 1.116,-0.272 0.676,0 1.263,0.247 1.744,0.734 0.355,0.359 0.541,0.682 0.657,1.136 0.327,1.278 -0.442,2.611 -1.723,2.987 -0.282,0.083 -0.817,0.114 -1.099,0.063z"
|
||||
android:strokeWidth="1" />
|
||||
<path
|
||||
android:fillAlpha="1"
|
||||
android:fillColor="#f84d4d"
|
||||
android:pathData="M11.617,21.707C10.518,20.424 9.338,18.864 8.395,17.449 6.524,14.641 5.455,12.305 5.102,10.255 5.014,9.744 5.006,8.628 5.088,8.137 5.348,6.561 6.043,5.221 7.158,4.148 9.148,2.231 12.016,1.668 14.593,2.688c2.043,0.809 3.607,2.581 4.162,4.719 0.174,0.67 0.204,0.933 0.203,1.761 -0.001,0.81 -0.035,1.098 -0.22,1.857 -0.614,2.524 -2.571,5.977 -5.383,9.501 -0.645,0.809 -1.321,1.61 -1.358,1.61 -0.008,0 -0.179,-0.193 -0.381,-0.428zM12.617,11.603c0.783,-0.188 1.457,-0.795 1.738,-1.564 0.516,-1.415 -0.317,-2.962 -1.783,-3.312 -0.216,-0.052 -0.317,-0.059 -0.661,-0.047 -0.354,0.012 -0.441,0.025 -0.682,0.104 -0.673,0.221 -1.205,0.695 -1.506,1.344 -0.176,0.38 -0.218,0.584 -0.217,1.054 0.001,0.324 0.014,0.452 0.064,0.635 0.266,0.97 1.077,1.689 2.079,1.844 0.243,0.038 0.68,0.012 0.968,-0.057z"
|
||||
android:strokeAlpha="1"
|
||||
android:strokeColor="#003b59"
|
||||
android:strokeWidth="1" />
|
||||
</vector>
|
||||
|
|
@ -18,7 +18,7 @@ class NearbyControllerTest {
|
|||
val location = LatLng(0.0, 0.0, 0f)
|
||||
|
||||
val options = loadAttractionsFromLocationToBaseMarkerOptions(
|
||||
location, null, RuntimeEnvironment.application)
|
||||
location, null, RuntimeEnvironment.application, null)
|
||||
|
||||
assertEquals(0, options.size.toLong())
|
||||
}
|
||||
|
|
@ -28,7 +28,7 @@ class NearbyControllerTest {
|
|||
val location = LatLng(0.0, 0.0, 0f)
|
||||
|
||||
val options = loadAttractionsFromLocationToBaseMarkerOptions(
|
||||
location, emptyList(), RuntimeEnvironment.application)
|
||||
location, emptyList(), RuntimeEnvironment.application, emptyList())
|
||||
|
||||
assertEquals(0, options.size.toLong())
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue