mirror of
https://github.com/commons-app/apps-android-commons.git
synced 2025-10-26 20:33:53 +01:00
Fix 4511 Update Nearby list according to chip state (#4605)
* Exists and Need Photo list updated * WLM filter added * Minor bug fix nad code convention * Code clean up * Renamed NeedsPhoto and isExists
This commit is contained in:
parent
401f70cf12
commit
6978d00926
1 changed files with 64 additions and 0 deletions
|
|
@ -119,6 +119,7 @@ import io.reactivex.schedulers.Schedulers;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.Date;
|
import java.util.Date;
|
||||||
|
import java.util.Iterator;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Locale;
|
import java.util.Locale;
|
||||||
import java.util.concurrent.TimeUnit;
|
import java.util.concurrent.TimeUnit;
|
||||||
|
|
@ -246,6 +247,10 @@ public class NearbyParentFragment extends CommonsDaggerSupportFragment
|
||||||
* WLM URL
|
* WLM URL
|
||||||
*/
|
*/
|
||||||
public static final String WLM_URL = "https://commons.wikimedia.org/wiki/Commons:Mobile_app/Contributing_to_WLM_using_the_app";
|
public static final String WLM_URL = "https://commons.wikimedia.org/wiki/Commons:Mobile_app/Contributing_to_WLM_using_the_app";
|
||||||
|
/**
|
||||||
|
* Saves response of list of places for the first time
|
||||||
|
*/
|
||||||
|
private List<Place> places;
|
||||||
|
|
||||||
@NonNull
|
@NonNull
|
||||||
public static NearbyParentFragment newInstance() {
|
public static NearbyParentFragment newInstance() {
|
||||||
|
|
@ -636,6 +641,8 @@ public class NearbyParentFragment extends CommonsDaggerSupportFragment
|
||||||
checkBoxTriStates.setState(CheckBoxTriStates.UNKNOWN);
|
checkBoxTriStates.setState(CheckBoxTriStates.UNKNOWN);
|
||||||
NearbyFilterState.setNeedPhotoSelected(isChecked);
|
NearbyFilterState.setNeedPhotoSelected(isChecked);
|
||||||
presenter.filterByMarkerType(nearbyFilterSearchRecyclerViewAdapter.selectedLabels, checkBoxTriStates.getState(), true, false);
|
presenter.filterByMarkerType(nearbyFilterSearchRecyclerViewAdapter.selectedLabels, checkBoxTriStates.getState(), true, false);
|
||||||
|
updatePlaceList(chipNeedsPhoto.isChecked(),
|
||||||
|
chipExists.isChecked(), chipWlm.isChecked());
|
||||||
} else {
|
} else {
|
||||||
chipNeedsPhoto.setChecked(!isChecked);
|
chipNeedsPhoto.setChecked(!isChecked);
|
||||||
}
|
}
|
||||||
|
|
@ -647,6 +654,8 @@ public class NearbyParentFragment extends CommonsDaggerSupportFragment
|
||||||
checkBoxTriStates.setState(CheckBoxTriStates.UNKNOWN);
|
checkBoxTriStates.setState(CheckBoxTriStates.UNKNOWN);
|
||||||
NearbyFilterState.setExistsSelected(isChecked);
|
NearbyFilterState.setExistsSelected(isChecked);
|
||||||
presenter.filterByMarkerType(nearbyFilterSearchRecyclerViewAdapter.selectedLabels, checkBoxTriStates.getState(), true, false);
|
presenter.filterByMarkerType(nearbyFilterSearchRecyclerViewAdapter.selectedLabels, checkBoxTriStates.getState(), true, false);
|
||||||
|
updatePlaceList(chipNeedsPhoto.isChecked(),
|
||||||
|
chipExists.isChecked(), chipWlm.isChecked());
|
||||||
} else {
|
} else {
|
||||||
chipExists.setChecked(!isChecked);
|
chipExists.setChecked(!isChecked);
|
||||||
}
|
}
|
||||||
|
|
@ -658,12 +667,66 @@ public class NearbyParentFragment extends CommonsDaggerSupportFragment
|
||||||
checkBoxTriStates.setState(CheckBoxTriStates.UNKNOWN);
|
checkBoxTriStates.setState(CheckBoxTriStates.UNKNOWN);
|
||||||
NearbyFilterState.setWlmSelected(isChecked);
|
NearbyFilterState.setWlmSelected(isChecked);
|
||||||
presenter.filterByMarkerType(nearbyFilterSearchRecyclerViewAdapter.selectedLabels, checkBoxTriStates.getState(), true, false);
|
presenter.filterByMarkerType(nearbyFilterSearchRecyclerViewAdapter.selectedLabels, checkBoxTriStates.getState(), true, false);
|
||||||
|
updatePlaceList(chipNeedsPhoto.isChecked(),
|
||||||
|
chipExists.isChecked(), chipWlm.isChecked());
|
||||||
}else{
|
}else{
|
||||||
chipWlm.setChecked(!isChecked);
|
chipWlm.setChecked(!isChecked);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Updates Nearby place list according to available chip states
|
||||||
|
*
|
||||||
|
* @param needsPhoto is chipNeedsPhoto checked
|
||||||
|
* @param exists is chipExists checked
|
||||||
|
* @param isWlm is chipWlm checked
|
||||||
|
*/
|
||||||
|
private void updatePlaceList(final boolean needsPhoto, final boolean exists,
|
||||||
|
final boolean isWlm) {
|
||||||
|
final List<Place> updatedPlaces = new ArrayList<>();
|
||||||
|
|
||||||
|
if (needsPhoto) {
|
||||||
|
for (final Place place :
|
||||||
|
places) {
|
||||||
|
if (place.pic.trim().isEmpty() && !updatedPlaces.contains(place)) {
|
||||||
|
updatedPlaces.add(place);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
updatedPlaces.addAll(places);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (exists) {
|
||||||
|
for(final Iterator<Place> placeIterator = updatedPlaces.iterator();
|
||||||
|
placeIterator.hasNext();){
|
||||||
|
final Place place = placeIterator.next();
|
||||||
|
if (!place.exists) {
|
||||||
|
placeIterator.remove();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!isWlm) {
|
||||||
|
for (final Place place :
|
||||||
|
places) {
|
||||||
|
if (place.isMonument() && updatedPlaces.contains(place)) {
|
||||||
|
updatedPlaces.remove(place);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
for (final Place place :
|
||||||
|
places) {
|
||||||
|
if (place.isMonument() && !updatedPlaces.contains(place)) {
|
||||||
|
updatedPlaces.add(place);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
adapter.setItems(updatedPlaces);
|
||||||
|
noResultsView.setVisibility(updatedPlaces.isEmpty() ? View.VISIBLE : View.GONE);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Defines how bottom sheets will act on click
|
* Defines how bottom sheets will act on click
|
||||||
*/
|
*/
|
||||||
|
|
@ -785,6 +848,7 @@ public class NearbyParentFragment extends CommonsDaggerSupportFragment
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void updateListFragment(final List<Place> placeList) {
|
public void updateListFragment(final List<Place> placeList) {
|
||||||
|
places = placeList;
|
||||||
adapter.setItems(placeList);
|
adapter.setItems(placeList);
|
||||||
noResultsView.setVisibility(placeList.isEmpty() ? View.VISIBLE : View.GONE);
|
noResultsView.setVisibility(placeList.isEmpty() ? View.VISIBLE : View.GONE);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue