Skip to content

Commit 63018fc

Browse files
VitalyVPinchukmisaochan
authored andcommitted
Add #3723 and #3721 to 2.13 release, fix conflicts
Conflicts were caused by merging #3723 before #3721 , so I just rolled both into one commit.
1 parent 461249f commit 63018fc

File tree

3 files changed

+72
-59
lines changed

3 files changed

+72
-59
lines changed

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

+13
Original file line numberDiff line numberDiff line change
@@ -41,4 +41,17 @@ public void updateAdapterData(List<Place> newPlaceList, RVRendererAdapter<Place>
4141
rendererAdapter.notifyDataSetChanged();
4242
rendererAdapter.diffUpdate(newPlaceList);
4343
}
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+
4457
}

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

+54-58
Original file line numberDiff line numberDiff line change
@@ -624,6 +624,18 @@ public void updateListFragment(List<Place> placeList) {
624624
adapterFactory.updateAdapterData(placeList, (RVRendererAdapter<Place>) rvNearbyList.getAdapter());
625625
}
626626

627+
public void clearNearbyList() {
628+
adapterFactory.clear((RVRendererAdapter<Place>) rvNearbyList.getAdapter());
629+
}
630+
631+
public void updateNearbyList() {
632+
adapterFactory.update((RVRendererAdapter<Place>) rvNearbyList.getAdapter());
633+
}
634+
635+
public void addPlaceToNearbyList(Place place) {
636+
adapterFactory.add(place, (RVRendererAdapter<Place>) rvNearbyList.getAdapter());
637+
}
638+
627639
@Override
628640
public fr.free.nrw.commons.location.LatLng getLastLocation() {
629641
return lastKnownLocation;
@@ -1078,7 +1090,8 @@ public void updateMapMarkers(List<NearbyBaseMarker> nearbyBaseMarkers, Marker se
10781090

10791091
@Override
10801092
public void filterOutAllMarkers() {
1081-
hideAllMArkers();
1093+
hideAllMarkers();
1094+
updateNearbyList();
10821095
}
10831096

10841097
/**
@@ -1089,6 +1102,7 @@ public void displayAllMarkers() {
10891102
for (MarkerPlaceGroup markerPlaceGroup : NearbyController.markerLabelList) {
10901103
updateMarker(markerPlaceGroup.getIsBookmarked(), markerPlaceGroup.getPlace(), NearbyController.currentLocation);
10911104
}
1105+
updateNearbyList();
10921106
}
10931107

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

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

11641159
@Override
@@ -1173,6 +1168,8 @@ public fr.free.nrw.commons.location.LatLng getCameraTarget() {
11731168
* @param curLatLng current location
11741169
*/
11751170
public void updateMarker(boolean isBookmarked, Place place, @Nullable fr.free.nrw.commons.location.LatLng curLatLng) {
1171+
addPlaceToNearbyList(place);
1172+
11761173
VectorDrawableCompat vectorDrawable;
11771174
if (isBookmarked) {
11781175
vectorDrawable = VectorDrawableCompat.create(
@@ -1219,10 +1216,8 @@ public void updateMarker(boolean isBookmarked, Place place, @Nullable fr.free.nr
12191216
* but it is transparent more than grey(as the name of the icon might suggest)
12201217
* since grey icon may lead the users to believe that it is disabled or prohibited contribution
12211218
*/
1219+
12221220
private void hideAllMArkers() {
1223-
if(currentLocationMarker==null){
1224-
return;
1225-
}
12261221
VectorDrawableCompat vectorDrawable;
12271222
vectorDrawable = VectorDrawableCompat.create(
12281223
getContext().getResources(), R.drawable.ic_custom_greyed_out_marker, getContext().getTheme());
@@ -1233,6 +1228,7 @@ private void hideAllMArkers() {
12331228
}
12341229
}
12351230
addCurrentLocationMarker(NearbyController.currentLocation);
1231+
clearNearbyList();
12361232
}
12371233

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

app/src/main/java/fr/free/nrw/commons/nearby/presenter/NearbyParentFragmentPresenter.java

+5-1
Original file line numberDiff line numberDiff line change
@@ -284,7 +284,11 @@ public void filterByMarkerType(List<Label> selectedLabels, int state, boolean fi
284284
nearbyParentFragmentView.setRecyclerViewAdapterItemsGreyedOut();
285285
break;
286286
case CHECKED:
287-
nearbyParentFragmentView.displayAllMarkers();
287+
// Despite showing all labels NearbyFilterState still should be applied
288+
nearbyParentFragmentView.filterMarkersByLabels(selectedLabels,
289+
NearbyFilterState.getInstance().isExistsSelected(),
290+
NearbyFilterState.getInstance().isNeedPhotoSelected(),
291+
filterForPlaceState, false);
288292
nearbyParentFragmentView.setRecyclerViewAdapterAllSelected();
289293
break;
290294
}

0 commit comments

Comments
 (0)