Skip to content

Commit

Permalink
Fix crash on empty search string
Browse files Browse the repository at this point in the history
  • Loading branch information
Bertware committed Dec 4, 2023
1 parent ed57772 commit 9e3cd5a
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 6 deletions.
4 changes: 2 additions & 2 deletions Hyperrail/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@ apply plugin: 'com.android.application'
apply plugin: 'com.google.gms.google-services'
apply plugin: 'com.google.firebase.crashlytics'

def VERSION_CODE = 58
def VERSION_NAME = '1.3.4'
def VERSION_CODE = 60
def VERSION_NAME = '1.4.1'

android {
compileSdk 34
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,10 @@
import androidx.collection.ArraySet;
import androidx.fragment.app.FragmentActivity;

import com.google.firebase.crashlytics.FirebaseCrashlytics;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collection;
import java.util.Collections;
import java.util.Comparator;
Expand Down Expand Up @@ -48,11 +51,16 @@ public MultilangFilterResults(List<StopLocation> results) {

@Override
protected FilterResults performFiltering(CharSequence constraint) {
constraint = constraint.toString().toLowerCase();
List<StopLocation> list = new ArrayList<>();
for (StopLocation s : stations) {
if (stationNameContains(constraint, s)) {
list.add(s);
if (constraint == null){ // no filtering
constraint = ""; // allows using the same sorter a little later
list.addAll(Arrays.asList(stations));
} else {
constraint = constraint.toString().toLowerCase();
for (StopLocation s : stations) {
if (stationNameContains(constraint, s)) {
list.add(s);
}
}
}
Collections.sort(list, new AutocompleteSortComparator(constraint));
Expand Down Expand Up @@ -80,6 +88,10 @@ protected void publishResults(CharSequence constraint, FilterResults results) {
}

private void updateVisibleStops(List<StopLocation> stops) {
if (stops == null){
FirebaseCrashlytics.getInstance().recordException(new IllegalArgumentException("Tried to set null in MultilangAutocompleteAdapter!"));
stops = new ArrayList<>(); // Never allow setting null, even when there are issues with the autocomplete
}
this.visibleStops = stops;
for (DataSetObserver observer : observers) {
observer.onChanged();
Expand Down

0 comments on commit 9e3cd5a

Please sign in to comment.