Skip to content

Commit cbf022d

Browse files
Resolves commons-app#5445 highlighting nearest place on clicking home nearby banner (commons-app#5453)
* Highlighted nearest place when user clicks on home nearby banner * Fixed incorrect behaviour of home nearby banner on being clicked * Fixing failure of unit test cases * spacing * indentation --------- Co-authored-by: Nicolas Raoul <nicolas.raoul@gmail.com>
1 parent b7323d0 commit cbf022d

File tree

4 files changed

+89
-1
lines changed

4 files changed

+89
-1
lines changed

app/src/main/java/fr/free/nrw/commons/contributions/ContributionsFragment.java

+7
Original file line numberDiff line numberDiff line change
@@ -463,6 +463,13 @@ public void onResume() {
463463
if (mediaDetailPagerFragment == null && !isUserProfile) {
464464
if (store.getBoolean("displayNearbyCardView", true)) {
465465
checkPermissionsAndShowNearbyCardView();
466+
467+
// Calling nearby card to keep showing it even when user clicks on it and comes back
468+
try {
469+
updateClosestNearbyCardViewInfo();
470+
} catch (Exception e) {
471+
Timber.e(e);
472+
}
466473
if (nearbyNotificationCardView.cardViewVisibilityState == NearbyNotificationCardView.CardViewVisibilityState.READY) {
467474
nearbyNotificationCardView.setVisibility(View.VISIBLE);
468475
}

app/src/main/java/fr/free/nrw/commons/nearby/fragments/NearbyParentFragment.java

+30-1
Original file line numberDiff line numberDiff line change
@@ -279,6 +279,7 @@ public class NearbyParentFragment extends CommonsDaggerSupportFragment
279279
private GeoPoint lastMapFocus;
280280
private NearbyParentFragmentInstanceReadyCallback nearbyParentFragmentInstanceReadyCallback;
281281
private boolean isAdvancedQueryFragmentVisible = false;
282+
private Place nearestPlace;
282283
private ActivityResultLauncher<String[]> inAppCameraLocationPermissionLauncher = registerForActivityResult(
283284
new ActivityResultContracts.RequestMultiplePermissions(),
284285
new ActivityResultCallback<Map<String, Boolean>>() {
@@ -990,7 +991,7 @@ private void addActionToTitle() {
990991
}
991992

992993
/**
993-
* Centers the map in nearby fragment to a given place
994+
* Centers the map in nearby fragment to a given place and updates nearestPlace
994995
*
995996
* @param place is new center of the map
996997
*/
@@ -1000,6 +1001,7 @@ public void centerMapToPlace(@Nullable final Place place) {
10001001
final double cameraShift;
10011002
if (null != place) {
10021003
lastPlaceToCenter = place;
1004+
nearestPlace = place;
10031005
}
10041006

10051007
if (null != lastPlaceToCenter) {
@@ -1626,7 +1628,34 @@ public void updateMarker(final boolean isBookmarked, final Place place,
16261628
addMarkerToMap(place, isBookmarked);
16271629
}
16281630

1631+
/**
1632+
* Highlights nearest place when user clicks on home nearby banner
1633+
*
1634+
* @param nearestPlace nearest place, which has to be highlighted
1635+
*/
1636+
private void highlightNearestPlace(Place nearestPlace) {
1637+
passInfoToSheet(nearestPlace);
1638+
hideBottomSheet();
1639+
bottomSheetDetailsBehavior.setState(BottomSheetBehavior.STATE_COLLAPSED);
1640+
}
1641+
1642+
/**
1643+
* Returns drawable of marker icon for given place
1644+
*
1645+
* @param place where marker is to be added
1646+
* @param isBookmarked true if place is bookmarked
1647+
* @return returns the drawable of marker according to the place information
1648+
*/
16291649
private @DrawableRes int getIconFor(Place place, Boolean isBookmarked) {
1650+
if(nearestPlace!=null) {
1651+
if(place.name.equals(nearestPlace.name)) {
1652+
// Highlight nearest place only when user clicks on the home nearby banner
1653+
highlightNearestPlace(place);
1654+
return (isBookmarked?
1655+
R.drawable.ic_custom_map_marker_purple_bookmarked:
1656+
R.drawable.ic_custom_map_marker_purple);
1657+
}
1658+
}
16301659
if (place.isMonument()) {
16311660
return R.drawable.ic_custom_map_marker_monuments;
16321661
} else if (!place.pic.trim().isEmpty()) {
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
<vector xmlns:android="http://schemas.android.com/apk/res/android"
2+
android:width="@dimen/half_standard_height"
3+
android:height="28dp"
4+
android:viewportWidth="24.0"
5+
android:viewportHeight="28.0">
6+
<path
7+
android:fillAlpha="0.1"
8+
android:fillColor="#000000"
9+
android:pathData="M6.072,22.223a6.031,3.672 0,1 0,12.062 0a6.031,3.672 0,1 0,-12.062 0z"
10+
android:strokeWidth="1" />
11+
<path
12+
android:fillAlpha="1"
13+
android:fillColor="#f84d4d"
14+
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"
15+
android:strokeWidth="1" />
16+
<path
17+
android:fillAlpha="1"
18+
android:fillColor="#BD98F8"
19+
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"
20+
android:strokeAlpha="1"
21+
android:strokeColor="#003b59"
22+
android:strokeWidth="1" />
23+
</vector>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
<vector xmlns:android="http://schemas.android.com/apk/res/android"
2+
android:width="24dp"
3+
android:height="28dp"
4+
android:viewportWidth="24"
5+
android:viewportHeight="28">
6+
<path
7+
android:pathData="M6.072,22.223a6.031,3.672 0,1 0,12.062 0a6.031,3.672 0,1 0,-12.062 0z"
8+
android:strokeAlpha="0.1"
9+
android:strokeWidth="1"
10+
android:fillColor="#000000"
11+
android:fillAlpha="0.1"/>
12+
<path
13+
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"
14+
android:strokeWidth="1"
15+
android:fillColor="#00ff00"/>
16+
<path
17+
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"
18+
android:strokeWidth="1"
19+
android:fillColor="#BD98F8"
20+
android:strokeColor="#003b59"
21+
android:fillAlpha="1"/>
22+
<path
23+
android:pathData="M17.9025,7.0798 L14.1612,6.7552 12.7003,3.3154c-0.2628,-0.6261 -1.1595,-0.6261 -1.4223,0L9.817,6.7629 6.0835,7.0798C5.4032,7.134 5.125,7.9842 5.6429,8.4326l2.8369,2.4581 -0.8503,3.6485c-0.1546,0.6648 0.5643,1.1904 1.1518,0.8348l3.2079,-1.9325 3.2079,1.9402c0.5875,0.3556 1.3064,-0.1701 1.1518,-0.8348L15.4985,10.8907 18.3354,8.4326C18.8533,7.9842 18.5827,7.134 17.9025,7.0798Z"
24+
android:strokeAlpha="1"
25+
android:strokeWidth="1"
26+
android:fillColor="#f84d4d"
27+
android:fillAlpha="1"
28+
android:strokeColor="#003b59"/>
29+
</vector>

0 commit comments

Comments
 (0)