Skip to content

Commit ef6fd9f

Browse files
madhurgupta10maskaravivek
authored andcommitted
1 parent 5dffea4 commit ef6fd9f

File tree

3 files changed

+34
-31
lines changed

3 files changed

+34
-31
lines changed

app/src/main/java/fr/free/nrw/commons/nearby/NearbyMapFragment.java

Lines changed: 30 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -378,8 +378,8 @@ private void initViews() {
378378
directionsButtonText = ((NearbyFragment)getParentFragment()).view.findViewById(R.id.directionsButtonText);
379379
commonsButtonText = ((NearbyFragment)getParentFragment()).view.findViewById(R.id.commonsButtonText);
380380

381-
bookmarkButton = getActivity().findViewById(R.id.bookmarkButton);
382-
bookmarkButtonImage = getActivity().findViewById(R.id.bookmarkButtonImage);
381+
bookmarkButton = ((NearbyFragment)getParentFragment()).view.findViewById(R.id.bookmarkButton);
382+
bookmarkButtonImage = ((NearbyFragment)getParentFragment()).view.findViewById(R.id.bookmarkButtonImage);
383383

384384
searchThisAreaButton = ((NearbyFragment)getParentFragment()).view.findViewById(R.id.search_this_area_button);
385385
searchThisAreaButtonProgressBar = ((NearbyFragment)getParentFragment()).view.findViewById(R.id.search_this_area_button_progress_bar);
@@ -825,32 +825,25 @@ private void addAnchorToSmallFABs(FloatingActionButton floatingActionButton, int
825825
}
826826

827827
/**
828-
* Same botom sheet carries information for all nearby places, so we need to pass information
828+
* Same bottom sheet carries information for all nearby places, so we need to pass information
829829
* (title, description, distance and links) to view on nearby marker click
830830
* @param place Place of clicked nearby marker
831831
*/
832832
private void passInfoToSheet(Place place) {
833833
this.place = place;
834+
updateBookmarkButtonImage(this.place);
834835

835-
int bookmarkIcon;
836-
if (bookmarkLocationDao.findBookmarkLocation(place)) {
837-
bookmarkIcon = R.drawable.ic_round_star_filled_24px;
838-
} else {
839-
bookmarkIcon = R.drawable.ic_round_star_border_24px;
840-
}
841-
bookmarkButtonImage.setImageResource(bookmarkIcon);
842836
bookmarkButton.setOnClickListener(view -> {
843-
boolean isBookmarked = bookmarkLocationDao.updateBookmarkLocation(place);
844-
int updatedIcon = isBookmarked ? R.drawable.ic_round_star_filled_24px : R.drawable.ic_round_star_border_24px;
845-
bookmarkButtonImage.setImageResource(updatedIcon);
846-
updateMarker(isBookmarked, place);
837+
boolean isBookmarked = bookmarkLocationDao.updateBookmarkLocation(this.place);
838+
updateBookmarkButtonImage(this.place);
839+
updateMarker(isBookmarked, this.place);
847840
});
848841

849842
wikipediaButton.setEnabled(place.hasWikipediaLink());
850-
wikipediaButton.setOnClickListener(view -> openWebView(place.siteLinks.getWikipediaLink()));
843+
wikipediaButton.setOnClickListener(view -> openWebView(this.place.siteLinks.getWikipediaLink()));
851844

852845
wikidataButton.setEnabled(place.hasWikidataLink());
853-
wikidataButton.setOnClickListener(view -> openWebView(place.siteLinks.getWikidataLink()));
846+
wikidataButton.setOnClickListener(view -> openWebView(this.place.siteLinks.getWikidataLink()));
854847

855848
directionsButton.setOnClickListener(view -> {
856849
//Open map app at given position
@@ -860,34 +853,44 @@ private void passInfoToSheet(Place place) {
860853
}
861854
});
862855

863-
commonsButton.setEnabled(place.hasCommonsLink());
864-
commonsButton.setOnClickListener(view -> openWebView(place.siteLinks.getCommonsLink()));
856+
commonsButton.setEnabled(this.place.hasCommonsLink());
857+
commonsButton.setOnClickListener(view -> openWebView(this.place.siteLinks.getCommonsLink()));
865858

866-
icon.setImageResource(place.getLabel().getIcon());
859+
icon.setImageResource(this.place.getLabel().getIcon());
867860

868-
title.setText(place.name);
869-
distance.setText(place.distance);
870-
description.setText(place.getLongDescription());
871-
title.setText(place.name.toString());
872-
distance.setText(place.distance.toString());
861+
title.setText(this.place.name);
862+
distance.setText(this.place.distance);
863+
description.setText(this.place.getLongDescription());
873864

874865
fabCamera.setOnClickListener(view -> {
875866
if (fabCamera.isShown()) {
876-
Timber.d("Camera button tapped. Place: %s", place.toString());
867+
Timber.d("Camera button tapped. Place: %s", this.place.toString());
877868
storeSharedPrefs();
878869
controller.initiateCameraPick(getActivity());
879870
}
880871
});
881872

882873
fabGallery.setOnClickListener(view -> {
883874
if (fabGallery.isShown()) {
884-
Timber.d("Gallery button tapped. Place: %s", place.toString());
875+
Timber.d("Gallery button tapped. Place: %s", this.place.toString());
885876
storeSharedPrefs();
886877
controller.initiateGalleryPick(getActivity(), false);
887878
}
888879
});
889880
}
890881

882+
public void updateBookmarkButtonImage(Place place) {
883+
int bookmarkIcon;
884+
if (bookmarkLocationDao.findBookmarkLocation(place)) {
885+
bookmarkIcon = R.drawable.ic_round_star_filled_24px;
886+
} else {
887+
bookmarkIcon = R.drawable.ic_round_star_border_24px;
888+
}
889+
if (bookmarkButtonImage != null) {
890+
bookmarkButtonImage.setImageResource(bookmarkIcon);
891+
}
892+
}
893+
891894
void storeSharedPrefs() {
892895
Timber.d("Store place object %s", place.toString());
893896
directKvStore.putJson(PLACE_OBJECT, place);
@@ -1033,7 +1036,7 @@ public void updateMarker(boolean isBookmarked, Place place) {
10331036
getContext().getResources(), R.drawable.ic_custom_map_marker, getContext().getTheme()
10341037
);
10351038
}
1036-
for(Marker marker: mapboxMap.getMarkers()){
1039+
for(Marker marker: mapboxMap.getMarkers()){
10371040
if(marker.getTitle()!=null && marker.getTitle().equals(place.getName())){
10381041

10391042
Bitmap icon = UiUtils.getBitmap(vectorDrawable);

app/src/main/java/fr/free/nrw/commons/nearby/PlaceRenderer.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -55,9 +55,9 @@ public class PlaceRenderer extends Renderer<Place> {
5555
@BindView(R.id.iconOverflow) LinearLayout iconOverflow;
5656
@BindView(R.id.cameraButtonText) TextView cameraButtonText;
5757
@BindView(R.id.galleryButtonText) TextView galleryButtonText;
58-
@BindView(R.id.bookmarkButton) LinearLayout bookmarkButton;
58+
@BindView(R.id.bookmarkRowButton) LinearLayout bookmarkButton;
5959
@BindView(R.id.bookmarkButtonText) TextView bookmarkButtonText;
60-
@BindView(R.id.bookmarkButtonImage) ImageView bookmarkButtonImage;
60+
@BindView(R.id.bookmarkRowButtonImage) ImageView bookmarkButtonImage;
6161

6262
@BindView(R.id.directionsButtonText) TextView directionsButtonText;
6363
@BindView(R.id.iconOverflowText) TextView iconOverflowText;

app/src/main/res/layout/nearby_row_button.xml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
>
1212

1313
<LinearLayout
14-
android:id="@+id/bookmarkButton"
14+
android:id="@+id/bookmarkRowButton"
1515
android:layout_width="0dp"
1616
android:layout_height="wrap_content"
1717
android:layout_weight="1"
@@ -21,7 +21,7 @@
2121
android:background="@drawable/button_background_selector"
2222
>
2323
<ImageView
24-
android:id="@+id/bookmarkButtonImage"
24+
android:id="@+id/bookmarkRowButtonImage"
2525
android:layout_width="wrap_content"
2626
android:layout_height="wrap_content"
2727
android:layout_gravity="center_horizontal"

0 commit comments

Comments
 (0)