119
119
import java .io .IOException ;
120
120
import java .util .ArrayList ;
121
121
import java .util .Date ;
122
+ import java .util .Iterator ;
122
123
import java .util .List ;
123
124
import java .util .Locale ;
124
125
import java .util .concurrent .TimeUnit ;
@@ -246,6 +247,10 @@ public class NearbyParentFragment extends CommonsDaggerSupportFragment
246
247
* WLM URL
247
248
*/
248
249
public static final String WLM_URL = "https://commons.wikimedia.org/wiki/Commons:Mobile_app/Contributing_to_WLM_using_the_app" ;
250
+ /**
251
+ * Saves response of list of places for the first time
252
+ */
253
+ private List <Place > places ;
249
254
250
255
@ NonNull
251
256
public static NearbyParentFragment newInstance () {
@@ -636,6 +641,8 @@ private void initFilterChips() {
636
641
checkBoxTriStates .setState (CheckBoxTriStates .UNKNOWN );
637
642
NearbyFilterState .setNeedPhotoSelected (isChecked );
638
643
presenter .filterByMarkerType (nearbyFilterSearchRecyclerViewAdapter .selectedLabels , checkBoxTriStates .getState (), true , false );
644
+ updatePlaceList (chipNeedsPhoto .isChecked (),
645
+ chipExists .isChecked (), chipWlm .isChecked ());
639
646
} else {
640
647
chipNeedsPhoto .setChecked (!isChecked );
641
648
}
@@ -647,6 +654,8 @@ private void initFilterChips() {
647
654
checkBoxTriStates .setState (CheckBoxTriStates .UNKNOWN );
648
655
NearbyFilterState .setExistsSelected (isChecked );
649
656
presenter .filterByMarkerType (nearbyFilterSearchRecyclerViewAdapter .selectedLabels , checkBoxTriStates .getState (), true , false );
657
+ updatePlaceList (chipNeedsPhoto .isChecked (),
658
+ chipExists .isChecked (), chipWlm .isChecked ());
650
659
} else {
651
660
chipExists .setChecked (!isChecked );
652
661
}
@@ -658,12 +667,66 @@ private void initFilterChips() {
658
667
checkBoxTriStates .setState (CheckBoxTriStates .UNKNOWN );
659
668
NearbyFilterState .setWlmSelected (isChecked );
660
669
presenter .filterByMarkerType (nearbyFilterSearchRecyclerViewAdapter .selectedLabels , checkBoxTriStates .getState (), true , false );
670
+ updatePlaceList (chipNeedsPhoto .isChecked (),
671
+ chipExists .isChecked (), chipWlm .isChecked ());
661
672
}else {
662
673
chipWlm .setChecked (!isChecked );
663
674
}
664
675
});
665
676
}
666
677
678
+ /**
679
+ * Updates Nearby place list according to available chip states
680
+ *
681
+ * @param needsPhoto is chipNeedsPhoto checked
682
+ * @param exists is chipExists checked
683
+ * @param isWlm is chipWlm checked
684
+ */
685
+ private void updatePlaceList (final boolean needsPhoto , final boolean exists ,
686
+ final boolean isWlm ) {
687
+ final List <Place > updatedPlaces = new ArrayList <>();
688
+
689
+ if (needsPhoto ) {
690
+ for (final Place place :
691
+ places ) {
692
+ if (place .pic .trim ().isEmpty () && !updatedPlaces .contains (place )) {
693
+ updatedPlaces .add (place );
694
+ }
695
+ }
696
+ } else {
697
+ updatedPlaces .addAll (places );
698
+ }
699
+
700
+ if (exists ) {
701
+ for (final Iterator <Place > placeIterator = updatedPlaces .iterator ();
702
+ placeIterator .hasNext ();){
703
+ final Place place = placeIterator .next ();
704
+ if (!place .exists ) {
705
+ placeIterator .remove ();
706
+ }
707
+ }
708
+ }
709
+
710
+ if (!isWlm ) {
711
+ for (final Place place :
712
+ places ) {
713
+ if (place .isMonument () && updatedPlaces .contains (place )) {
714
+ updatedPlaces .remove (place );
715
+ }
716
+ }
717
+ } else {
718
+ for (final Place place :
719
+ places ) {
720
+ if (place .isMonument () && !updatedPlaces .contains (place )) {
721
+ updatedPlaces .add (place );
722
+ }
723
+ }
724
+ }
725
+
726
+ adapter .setItems (updatedPlaces );
727
+ noResultsView .setVisibility (updatedPlaces .isEmpty () ? View .VISIBLE : View .GONE );
728
+ }
729
+
667
730
/**
668
731
* Defines how bottom sheets will act on click
669
732
*/
@@ -785,6 +848,7 @@ public void centerMapToPlace(final Place place) {
785
848
786
849
@ Override
787
850
public void updateListFragment (final List <Place > placeList ) {
851
+ places = placeList ;
788
852
adapter .setItems (placeList );
789
853
noResultsView .setVisibility (placeList .isEmpty () ? View .VISIBLE : View .GONE );
790
854
}
0 commit comments