Skip to content

Commit 3e7d777

Browse files
VitalyVPinchukashishkumar468
authored andcommitted
Fixes commons-app#3720: None of the filters work on Nearby list (commons-app#3723)
1 parent 0c13c46 commit 3e7d777

File tree

2 files changed

+111
-56
lines changed

2 files changed

+111
-56
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
package fr.free.nrw.commons.nearby;
2+
3+
4+
import androidx.fragment.app.Fragment;
5+
6+
import com.pedrogomez.renderers.ListAdapteeCollection;
7+
import com.pedrogomez.renderers.RVRendererAdapter;
8+
import com.pedrogomez.renderers.RendererBuilder;
9+
10+
import java.util.Collections;
11+
import java.util.List;
12+
13+
import fr.free.nrw.commons.contributions.ContributionController;
14+
15+
public class NearbyAdapterFactory {
16+
17+
private Fragment fragment;
18+
private ContributionController controller;
19+
20+
public NearbyAdapterFactory(Fragment fragment, ContributionController controller) {
21+
this.fragment = fragment;
22+
this.controller = controller;
23+
}
24+
25+
public RVRendererAdapter<Place> create(List<Place> placeList) {
26+
return create(placeList, null);
27+
}
28+
29+
public RVRendererAdapter<Place> create(
30+
List<Place> placeList,
31+
PlaceRenderer.OnBookmarkClick onBookmarkClick
32+
) {
33+
RendererBuilder<Place> builder = new RendererBuilder<Place>()
34+
.bind(Place.class, new PlaceRenderer(fragment, controller, onBookmarkClick));
35+
ListAdapteeCollection<Place> collection = new ListAdapteeCollection<>(
36+
placeList != null ? placeList : Collections.emptyList());
37+
return new RVRendererAdapter<>(builder, collection);
38+
}
39+
40+
public void updateAdapterData(List<Place> newPlaceList, RVRendererAdapter<Place> rendererAdapter) {
41+
rendererAdapter.notifyDataSetChanged();
42+
rendererAdapter.diffUpdate(newPlaceList);
43+
}
44+
45+
public void clear(RVRendererAdapter<Place> rendererAdapter){
46+
rendererAdapter.clear();
47+
}
48+
49+
public void add(Place place, RVRendererAdapter<Place> rendererAdapter){
50+
rendererAdapter.add(place);
51+
}
52+
53+
public void update(RVRendererAdapter<Place> rendererAdapter){
54+
rendererAdapter.notifyDataSetChanged();
55+
}
56+
57+
}

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

+54-56
Original file line numberDiff line numberDiff line change
@@ -628,6 +628,18 @@ public void updateListFragment(List<Place> placeList) {
628628
adapterFactory.updateAdapterData(placeList, (RVRendererAdapter<Place>) rvNearbyList.getAdapter());
629629
}
630630

631+
public void clearNearbyList() {
632+
adapterFactory.clear((RVRendererAdapter<Place>) rvNearbyList.getAdapter());
633+
}
634+
635+
public void updateNearbyList() {
636+
adapterFactory.update((RVRendererAdapter<Place>) rvNearbyList.getAdapter());
637+
}
638+
639+
public void addPlaceToNearbyList(Place place) {
640+
adapterFactory.add(place, (RVRendererAdapter<Place>) rvNearbyList.getAdapter());
641+
}
642+
631643
@Override
632644
public fr.free.nrw.commons.location.LatLng getLastLocation() {
633645
return lastKnownLocation;
@@ -1082,7 +1094,8 @@ public void updateMapMarkers(List<NearbyBaseMarker> nearbyBaseMarkers, Marker se
10821094

10831095
@Override
10841096
public void filterOutAllMarkers() {
1085-
hideAllMArkers();
1097+
hideAllMarkers();
1098+
updateNearbyList();
10861099
}
10871100

10881101
/**
@@ -1093,6 +1106,7 @@ public void displayAllMarkers() {
10931106
for (MarkerPlaceGroup markerPlaceGroup : NearbyController.markerLabelList) {
10941107
updateMarker(markerPlaceGroup.getIsBookmarked(), markerPlaceGroup.getPlace(), NearbyController.currentLocation);
10951108
}
1109+
updateNearbyList();
10961110
}
10971111

10981112
/**
@@ -1104,65 +1118,46 @@ public void displayAllMarkers() {
11041118
* @param filterForAllNoneType true if we filter places with all none button
11051119
*/
11061120
@Override
1107-
public void filterMarkersByLabels(List<Label> selectedLabels, boolean displayExists,
1108-
boolean displayNeedsPhoto,
1109-
boolean filterForPlaceState,
1110-
boolean filterForAllNoneType) {
1111-
if (selectedLabels.size() == 0 && filterForPlaceState) { // If nothing is selected, display all
1112-
// remove the previous markers before updating them
1113-
hideAllMArkers();
1114-
for (MarkerPlaceGroup markerPlaceGroup : NearbyController.markerLabelList) {
1115-
if (displayExists && displayNeedsPhoto) {
1116-
// Exists and needs photo
1117-
if (markerPlaceGroup.getPlace().destroyed.trim().isEmpty() && markerPlaceGroup.getPlace().pic.trim().isEmpty()) {
1118-
updateMarker(markerPlaceGroup.getIsBookmarked(), markerPlaceGroup.getPlace(), NearbyController.currentLocation);
1119-
}
1120-
} else if (displayExists && !displayNeedsPhoto) {
1121-
// Exists and all included needs and doesn't needs photo
1122-
if (markerPlaceGroup.getPlace().destroyed.trim().isEmpty()) {
1123-
updateMarker(markerPlaceGroup.getIsBookmarked(), markerPlaceGroup.getPlace(), NearbyController.currentLocation);
1124-
}
1125-
} else if (!displayExists && displayNeedsPhoto) {
1126-
// All and only needs photo
1127-
if (markerPlaceGroup.getPlace().pic.trim().isEmpty()) {
1128-
updateMarker(markerPlaceGroup.getIsBookmarked(), markerPlaceGroup.getPlace(), NearbyController.currentLocation);
1129-
}
1130-
} else if (!displayExists && !displayNeedsPhoto) {
1131-
// all
1132-
updateMarker(markerPlaceGroup.getIsBookmarked(), markerPlaceGroup.getPlace(), NearbyController.currentLocation);
1133-
}
1121+
public void filterMarkersByLabels(List<Label> selectedLabels,
1122+
boolean displayExists,
1123+
boolean displayNeedsPhoto,
1124+
boolean filterForPlaceState,
1125+
boolean filterForAllNoneType) {
11341126

1127+
// Remove the previous markers before updating them
1128+
hideAllMarkers();
1129+
1130+
for (MarkerPlaceGroup markerPlaceGroup : NearbyController.markerLabelList) {
1131+
Place place = markerPlaceGroup.getPlace();
1132+
1133+
// When label filter is engaged
1134+
// then compare it against place's label
1135+
if (selectedLabels != null && (selectedLabels.size() != 0 || !filterForPlaceState)
1136+
&& !selectedLabels.contains(place.getLabel())) {
1137+
continue;
11351138
}
1136-
} else {
1137-
// First remove all the markers
1138-
hideAllMArkers();
1139-
for (MarkerPlaceGroup markerPlaceGroup : NearbyController.markerLabelList) {
1140-
for (Label label : selectedLabels) {
1141-
if (markerPlaceGroup.getPlace().getLabel().toString().equals(label.toString())) {
1142-
1143-
if (displayExists && displayNeedsPhoto) {
1144-
// Exists and needs photo
1145-
if (markerPlaceGroup.getPlace().destroyed.trim().isEmpty() && markerPlaceGroup.getPlace().pic.trim().isEmpty()) {
1146-
updateMarker(markerPlaceGroup.getIsBookmarked(), markerPlaceGroup.getPlace(), NearbyController.currentLocation);
1147-
}
1148-
} else if (displayExists && !displayNeedsPhoto) {
1149-
// Exists and all included needs and doesn't needs photo
1150-
if (markerPlaceGroup.getPlace().destroyed.trim().isEmpty()) {
1151-
updateMarker(markerPlaceGroup.getIsBookmarked(), markerPlaceGroup.getPlace(), NearbyController.currentLocation);
1152-
}
1153-
} else if (!displayExists && displayNeedsPhoto) {
1154-
// All and only needs photo
1155-
if (markerPlaceGroup.getPlace().pic.trim().isEmpty()) {
1156-
updateMarker(markerPlaceGroup.getIsBookmarked(), markerPlaceGroup.getPlace(), NearbyController.currentLocation);
1157-
}
1158-
} else if (!displayExists && !displayNeedsPhoto) {
1159-
// all
1160-
updateMarker(markerPlaceGroup.getIsBookmarked(), markerPlaceGroup.getPlace(), NearbyController.currentLocation);
1161-
}
1162-
}
1139+
1140+
if (displayExists && displayNeedsPhoto) {
1141+
// Exists and needs photo
1142+
if (place.destroyed.trim().isEmpty() && place.pic.trim().isEmpty()) {
1143+
updateMarker(markerPlaceGroup.getIsBookmarked(), place, NearbyController.currentLocation);
1144+
}
1145+
} else if (displayExists && !displayNeedsPhoto) {
1146+
// Exists and all included needs and doesn't needs photo
1147+
if (place.destroyed.trim().isEmpty()) {
1148+
updateMarker(markerPlaceGroup.getIsBookmarked(), place, NearbyController.currentLocation);
11631149
}
1150+
} else if (!displayExists && displayNeedsPhoto) {
1151+
// All and only needs photo
1152+
if (place.pic.trim().isEmpty()) {
1153+
updateMarker(markerPlaceGroup.getIsBookmarked(), place, NearbyController.currentLocation);
1154+
}
1155+
} else if (!displayExists && !displayNeedsPhoto) {
1156+
// all
1157+
updateMarker(markerPlaceGroup.getIsBookmarked(), place, NearbyController.currentLocation);
11641158
}
11651159
}
1160+
updateNearbyList();
11661161
}
11671162

11681163
@Override
@@ -1177,6 +1172,8 @@ public fr.free.nrw.commons.location.LatLng getCameraTarget() {
11771172
* @param curLatLng current location
11781173
*/
11791174
public void updateMarker(boolean isBookmarked, Place place, @Nullable fr.free.nrw.commons.location.LatLng curLatLng) {
1175+
addPlaceToNearbyList(place);
1176+
11801177
VectorDrawableCompat vectorDrawable;
11811178
if (isBookmarked) {
11821179
vectorDrawable = VectorDrawableCompat.create(
@@ -1223,7 +1220,7 @@ public void updateMarker(boolean isBookmarked, Place place, @Nullable fr.free.nr
12231220
* but it is transparent more than grey(as the name of the icon might suggest)
12241221
* since grey icon may lead the users to believe that it is disabled or prohibited contribution
12251222
*/
1226-
private void hideAllMArkers() {
1223+
private void hideAllMarkers() {
12271224
VectorDrawableCompat vectorDrawable;
12281225
vectorDrawable = VectorDrawableCompat.create(
12291226
getContext().getResources(), R.drawable.ic_custom_greyed_out_marker, getContext().getTheme());
@@ -1234,6 +1231,7 @@ private void hideAllMArkers() {
12341231
}
12351232
}
12361233
addCurrentLocationMarker(NearbyController.currentLocation);
1234+
clearNearbyList();
12371235
}
12381236

12391237
private void addNearbyMarkersToMapBoxMap(List<NearbyBaseMarker> nearbyBaseMarkers, Marker selectedMarker) {

0 commit comments

Comments
 (0)