mirror of
https://gitlab.com/oeffi/oeffi.git
synced 2025-07-07 06:08:51 +00:00
StationsActivity: Fix product filter to take into account the location products field.
This commit is contained in:
parent
d4371cda0f
commit
0ba61b349f
1 changed files with 19 additions and 12 deletions
|
@ -24,6 +24,7 @@ import java.util.Collection;
|
||||||
import java.util.Collections;
|
import java.util.Collections;
|
||||||
import java.util.Comparator;
|
import java.util.Comparator;
|
||||||
import java.util.Date;
|
import java.util.Date;
|
||||||
|
import java.util.EnumSet;
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.HashSet;
|
import java.util.HashSet;
|
||||||
import java.util.Iterator;
|
import java.util.Iterator;
|
||||||
|
@ -235,8 +236,7 @@ public class StationsActivity extends OeffiMainActivity implements StationsAware
|
||||||
if (!removed.isEmpty()) {
|
if (!removed.isEmpty()) {
|
||||||
for (final Iterator<Station> i = stations.iterator(); i.hasNext();) {
|
for (final Iterator<Station> i = stations.iterator(); i.hasNext();) {
|
||||||
final Station station = i.next();
|
final Station station = i.next();
|
||||||
final List<LineDestination> lines = station.getLines();
|
if (!filter(station, products)) {
|
||||||
if (!filter(lines, products)) {
|
|
||||||
i.remove();
|
i.remove();
|
||||||
stationsMap.remove(station.location.id);
|
stationsMap.remove(station.location.id);
|
||||||
}
|
}
|
||||||
|
@ -998,7 +998,7 @@ public class StationsActivity extends OeffiMainActivity implements StationsAware
|
||||||
changed = true;
|
changed = true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else if (filter(freshStation.getLines(), products)) {
|
} else if (filter(freshStation, products)) {
|
||||||
stations.add(freshStation);
|
stations.add(freshStation);
|
||||||
stationsMap.put(freshStation.location.id, freshStation);
|
stationsMap.put(freshStation.location.id, freshStation);
|
||||||
|
|
||||||
|
@ -1043,16 +1043,23 @@ public class StationsActivity extends OeffiMainActivity implements StationsAware
|
||||||
updateGUI();
|
updateGUI();
|
||||||
}
|
}
|
||||||
|
|
||||||
private static boolean filter(final List<LineDestination> lines, final Collection<Product> products) {
|
private static boolean filter(final Station station, final Collection<Product> productFilter) {
|
||||||
if (lines == null)
|
final Set<Product> products = station.location.products;
|
||||||
return true;
|
if (products != null) {
|
||||||
|
final Set<Product> copy = EnumSet.copyOf(products);
|
||||||
|
copy.retainAll(productFilter);
|
||||||
|
return !copy.isEmpty();
|
||||||
|
}
|
||||||
|
|
||||||
for (final LineDestination line : lines) {
|
final List<LineDestination> lines = station.getLines();
|
||||||
final Product product = line.line.product;
|
if (lines != null) {
|
||||||
if (product != null)
|
for (final LineDestination line : lines) {
|
||||||
for (final Product filterProduct : products)
|
final Product product = line.line.product;
|
||||||
if (product == filterProduct)
|
if (product != null)
|
||||||
return true;
|
for (final Product filterProduct : productFilter)
|
||||||
|
if (product == filterProduct)
|
||||||
|
return true;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return false;
|
return false;
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue