|
12 | 12 | import androidx.collection.ArraySet;
|
13 | 13 | import androidx.fragment.app.FragmentActivity;
|
14 | 14 |
|
| 15 | +import com.google.firebase.crashlytics.FirebaseCrashlytics; |
| 16 | + |
15 | 17 | import java.util.ArrayList;
|
| 18 | +import java.util.Arrays; |
16 | 19 | import java.util.Collection;
|
17 | 20 | import java.util.Collections;
|
18 | 21 | import java.util.Comparator;
|
@@ -48,11 +51,16 @@ public MultilangFilterResults(List<StopLocation> results) {
|
48 | 51 |
|
49 | 52 | @Override
|
50 | 53 | protected FilterResults performFiltering(CharSequence constraint) {
|
51 |
| - constraint = constraint.toString().toLowerCase(); |
52 | 54 | List<StopLocation> list = new ArrayList<>();
|
53 |
| - for (StopLocation s : stations) { |
54 |
| - if (stationNameContains(constraint, s)) { |
55 |
| - list.add(s); |
| 55 | + if (constraint == null){ // no filtering |
| 56 | + constraint = ""; // allows using the same sorter a little later |
| 57 | + list.addAll(Arrays.asList(stations)); |
| 58 | + } else { |
| 59 | + constraint = constraint.toString().toLowerCase(); |
| 60 | + for (StopLocation s : stations) { |
| 61 | + if (stationNameContains(constraint, s)) { |
| 62 | + list.add(s); |
| 63 | + } |
56 | 64 | }
|
57 | 65 | }
|
58 | 66 | Collections.sort(list, new AutocompleteSortComparator(constraint));
|
@@ -80,6 +88,10 @@ protected void publishResults(CharSequence constraint, FilterResults results) {
|
80 | 88 | }
|
81 | 89 |
|
82 | 90 | private void updateVisibleStops(List<StopLocation> stops) {
|
| 91 | + if (stops == null){ |
| 92 | + FirebaseCrashlytics.getInstance().recordException(new IllegalArgumentException("Tried to set null in MultilangAutocompleteAdapter!")); |
| 93 | + stops = new ArrayList<>(); // Never allow setting null, even when there are issues with the autocomplete |
| 94 | + } |
83 | 95 | this.visibleStops = stops;
|
84 | 96 | for (DataSetObserver observer : observers) {
|
85 | 97 | observer.onChanged();
|
|
0 commit comments