mirror of
https://gitlab.com/oeffi/oeffi.git
synced 2025-07-07 21:58:48 +00:00
NetworkContentProvider: Add support for products column.
This commit is contained in:
parent
94b2b827b1
commit
9bdaae5e6f
3 changed files with 45 additions and 14 deletions
|
@ -60,6 +60,7 @@ public final class NetworkContentProvider extends ContentProvider {
|
||||||
public static final String KEY_NAME = "name";
|
public static final String KEY_NAME = "name";
|
||||||
public static final String KEY_LAT = "lat";
|
public static final String KEY_LAT = "lat";
|
||||||
public static final String KEY_LON = "lon";
|
public static final String KEY_LON = "lon";
|
||||||
|
public static final String KEY_PRODUCTS = "products"; // optional!
|
||||||
public static final String KEY_LINES = "lines";
|
public static final String KEY_LINES = "lines";
|
||||||
|
|
||||||
public static final String QUERY_PARAM_Q = "q";
|
public static final String QUERY_PARAM_Q = "q";
|
||||||
|
@ -133,6 +134,7 @@ public final class NetworkContentProvider extends ContentProvider {
|
||||||
final Cursor testCursor = db.query(DATABASE_TABLE, null, null, null, null, null, null, "0");
|
final Cursor testCursor = db.query(DATABASE_TABLE, null, null, null, null, null, null, "0");
|
||||||
final boolean hasLocalId = testCursor.getColumnIndex(NetworkContentProvider.KEY_LOCAL_ID) != -1;
|
final boolean hasLocalId = testCursor.getColumnIndex(NetworkContentProvider.KEY_LOCAL_ID) != -1;
|
||||||
final boolean hasPlace = testCursor.getColumnIndex(NetworkContentProvider.KEY_PLACE) != -1;
|
final boolean hasPlace = testCursor.getColumnIndex(NetworkContentProvider.KEY_PLACE) != -1;
|
||||||
|
final boolean hasProducts = testCursor.getColumnIndex(NetworkContentProvider.KEY_PRODUCTS) != -1;
|
||||||
testCursor.close();
|
testCursor.close();
|
||||||
|
|
||||||
String selection = null;
|
String selection = null;
|
||||||
|
|
|
@ -27,6 +27,7 @@ import java.util.Date;
|
||||||
import java.util.LinkedHashMap;
|
import java.util.LinkedHashMap;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
import java.util.Set;
|
||||||
import java.util.regex.Matcher;
|
import java.util.regex.Matcher;
|
||||||
import java.util.regex.Pattern;
|
import java.util.regex.Pattern;
|
||||||
|
|
||||||
|
@ -407,13 +408,24 @@ public class StationDetailsActivity extends OeffiActivity implements StationsAwa
|
||||||
.getColumnIndexOrThrow(NetworkContentProvider.KEY_LAT);
|
.getColumnIndexOrThrow(NetworkContentProvider.KEY_LAT);
|
||||||
final int lonCol = cursor
|
final int lonCol = cursor
|
||||||
.getColumnIndexOrThrow(NetworkContentProvider.KEY_LON);
|
.getColumnIndexOrThrow(NetworkContentProvider.KEY_LON);
|
||||||
|
final int productsCol = cursor
|
||||||
|
.getColumnIndex(NetworkContentProvider.KEY_PRODUCTS);
|
||||||
final int linesCol = cursor
|
final int linesCol = cursor
|
||||||
.getColumnIndexOrThrow(NetworkContentProvider.KEY_LINES);
|
.getColumnIndexOrThrow(NetworkContentProvider.KEY_LINES);
|
||||||
|
|
||||||
location = new Location(LocationType.STATION, location.id,
|
final Point coord = Point.from1E6(cursor.getInt(latCol),
|
||||||
Point.from1E6(cursor.getInt(latCol), cursor.getInt(lonCol)),
|
cursor.getInt(lonCol));
|
||||||
placeCol != -1 ? cursor.getString(placeCol) : selectedStation.place,
|
final String place = placeCol != -1 ? cursor.getString(placeCol)
|
||||||
cursor.getString(nameCol));
|
: selectedStation.place;
|
||||||
|
final String name = cursor.getString(nameCol);
|
||||||
|
final Set<Product> products;
|
||||||
|
if (productsCol != -1 && !cursor.isNull(productsCol))
|
||||||
|
products = Product
|
||||||
|
.fromCodes(cursor.getString(productsCol).toCharArray());
|
||||||
|
else
|
||||||
|
products = null;
|
||||||
|
location = new Location(LocationType.STATION, location.id, coord, place,
|
||||||
|
name, products);
|
||||||
|
|
||||||
final String[] additionalLinesArray = cursor.getString(linesCol).split(",");
|
final String[] additionalLinesArray = cursor.getString(linesCol).split(",");
|
||||||
additionalLines = new ArrayList<>(additionalLinesArray.length);
|
additionalLines = new ArrayList<>(additionalLinesArray.length);
|
||||||
|
@ -519,12 +531,18 @@ public class StationDetailsActivity extends OeffiActivity implements StationsAwa
|
||||||
final int nameCol = stationCursor.getColumnIndexOrThrow(NetworkContentProvider.KEY_NAME);
|
final int nameCol = stationCursor.getColumnIndexOrThrow(NetworkContentProvider.KEY_NAME);
|
||||||
final int latCol = stationCursor.getColumnIndexOrThrow(NetworkContentProvider.KEY_LAT);
|
final int latCol = stationCursor.getColumnIndexOrThrow(NetworkContentProvider.KEY_LAT);
|
||||||
final int lonCol = stationCursor.getColumnIndexOrThrow(NetworkContentProvider.KEY_LON);
|
final int lonCol = stationCursor.getColumnIndexOrThrow(NetworkContentProvider.KEY_LON);
|
||||||
|
final int productsCol = stationCursor.getColumnIndex(NetworkContentProvider.KEY_PRODUCTS);
|
||||||
final int linesCol = stationCursor.getColumnIndexOrThrow(NetworkContentProvider.KEY_LINES);
|
final int linesCol = stationCursor.getColumnIndexOrThrow(NetworkContentProvider.KEY_LINES);
|
||||||
|
|
||||||
selectedStation = new Location(LocationType.STATION, selectedStation.id,
|
final Point coord = Point.from1E6(stationCursor.getInt(latCol), stationCursor.getInt(lonCol));
|
||||||
Point.from1E6(stationCursor.getInt(latCol), stationCursor.getInt(lonCol)),
|
final String place = placeCol != -1 ? stationCursor.getString(placeCol) : selectedStation.place;
|
||||||
placeCol != -1 ? stationCursor.getString(placeCol) : selectedStation.place,
|
final String name = stationCursor.getString(nameCol);
|
||||||
stationCursor.getString(nameCol));
|
final Set<Product> products;
|
||||||
|
if (productsCol != -1 && !stationCursor.isNull(productsCol))
|
||||||
|
products = Product.fromCodes(stationCursor.getString(productsCol).toCharArray());
|
||||||
|
else
|
||||||
|
products = null;
|
||||||
|
selectedStation = new Location(LocationType.STATION, selectedStation.id, coord, place, name, products);
|
||||||
|
|
||||||
final NetworkProvider networkProvider = NetworkProviderFactory.provider(selectedNetwork);
|
final NetworkProvider networkProvider = NetworkProviderFactory.provider(selectedNetwork);
|
||||||
|
|
||||||
|
|
|
@ -850,6 +850,7 @@ public class StationsActivity extends OeffiMainActivity implements StationsAware
|
||||||
final int nameColumnIndex = cursor.getColumnIndexOrThrow(NetworkContentProvider.KEY_NAME);
|
final int nameColumnIndex = cursor.getColumnIndexOrThrow(NetworkContentProvider.KEY_NAME);
|
||||||
final int latColumnIndex = cursor.getColumnIndexOrThrow(NetworkContentProvider.KEY_LAT);
|
final int latColumnIndex = cursor.getColumnIndexOrThrow(NetworkContentProvider.KEY_LAT);
|
||||||
final int lonColumnIndex = cursor.getColumnIndexOrThrow(NetworkContentProvider.KEY_LON);
|
final int lonColumnIndex = cursor.getColumnIndexOrThrow(NetworkContentProvider.KEY_LON);
|
||||||
|
final int productsColumnIndex = cursor.getColumnIndex(NetworkContentProvider.KEY_PRODUCTS);
|
||||||
final int linesColumnIndex = cursor.getColumnIndexOrThrow(NetworkContentProvider.KEY_LINES);
|
final int linesColumnIndex = cursor.getColumnIndexOrThrow(NetworkContentProvider.KEY_LINES);
|
||||||
|
|
||||||
final List<Station> freshStations = new ArrayList<>(cursor.getCount());
|
final List<Station> freshStations = new ArrayList<>(cursor.getCount());
|
||||||
|
@ -876,14 +877,18 @@ public class StationsActivity extends OeffiMainActivity implements StationsAware
|
||||||
: cursor.getString(nativeIdColumnIndex);
|
: cursor.getString(nativeIdColumnIndex);
|
||||||
final String place = placeColumnIndex != -1 ? cursor.getString(placeColumnIndex) : null;
|
final String place = placeColumnIndex != -1 ? cursor.getString(placeColumnIndex) : null;
|
||||||
final String name = cursor.getString(nameColumnIndex);
|
final String name = cursor.getString(nameColumnIndex);
|
||||||
final Point p = Point.from1E6(cursor.getInt(latColumnIndex),
|
final Point coord = Point.from1E6(cursor.getInt(latColumnIndex),
|
||||||
cursor.getInt(lonColumnIndex));
|
cursor.getInt(lonColumnIndex));
|
||||||
final Station station = new Station(network,
|
final Set<Product> products;
|
||||||
new de.schildbach.pte.dto.Location(LocationType.STATION, id, p, place, name),
|
if (productsColumnIndex != -1 && !cursor.isNull(productsColumnIndex))
|
||||||
lineDestinations);
|
products = Product.fromCodes(cursor.getString(productsColumnIndex).toCharArray());
|
||||||
|
else
|
||||||
|
products = null;
|
||||||
|
final Station station = new Station(network, new de.schildbach.pte.dto.Location(
|
||||||
|
LocationType.STATION, id, coord, place, name, products), lineDestinations);
|
||||||
if (deviceLocation != null) {
|
if (deviceLocation != null) {
|
||||||
android.location.Location.distanceBetween(referenceLocation.getLatAsDouble(),
|
android.location.Location.distanceBetween(referenceLocation.getLatAsDouble(),
|
||||||
referenceLocation.getLonAsDouble(), p.getLatAsDouble(), p.getLonAsDouble(),
|
referenceLocation.getLonAsDouble(), coord.getLatAsDouble(), coord.getLonAsDouble(),
|
||||||
distanceBetweenResults);
|
distanceBetweenResults);
|
||||||
station.setDistanceAndBearing(distanceBetweenResults[0], distanceBetweenResults[1]);
|
station.setDistanceAndBearing(distanceBetweenResults[0], distanceBetweenResults[1]);
|
||||||
}
|
}
|
||||||
|
@ -1606,6 +1611,7 @@ public class StationsActivity extends OeffiMainActivity implements StationsAware
|
||||||
final int nameColumnIndex = cursor.getColumnIndexOrThrow(NetworkContentProvider.KEY_NAME);
|
final int nameColumnIndex = cursor.getColumnIndexOrThrow(NetworkContentProvider.KEY_NAME);
|
||||||
final int latColumnIndex = cursor.getColumnIndexOrThrow(NetworkContentProvider.KEY_LAT);
|
final int latColumnIndex = cursor.getColumnIndexOrThrow(NetworkContentProvider.KEY_LAT);
|
||||||
final int lonColumnIndex = cursor.getColumnIndexOrThrow(NetworkContentProvider.KEY_LON);
|
final int lonColumnIndex = cursor.getColumnIndexOrThrow(NetworkContentProvider.KEY_LON);
|
||||||
|
final int productsColumnIndex = cursor.getColumnIndex(NetworkContentProvider.KEY_PRODUCTS);
|
||||||
final int linesColumnIndex = cursor.getColumnIndexOrThrow(NetworkContentProvider.KEY_LINES);
|
final int linesColumnIndex = cursor.getColumnIndexOrThrow(NetworkContentProvider.KEY_LINES);
|
||||||
|
|
||||||
while (cursor.moveToNext()) {
|
while (cursor.moveToNext()) {
|
||||||
|
@ -1619,6 +1625,11 @@ public class StationsActivity extends OeffiMainActivity implements StationsAware
|
||||||
final int lat = cursor.getInt(latColumnIndex);
|
final int lat = cursor.getInt(latColumnIndex);
|
||||||
final int lon = cursor.getInt(lonColumnIndex);
|
final int lon = cursor.getInt(lonColumnIndex);
|
||||||
final Point coord = Point.from1E6(lat, lon);
|
final Point coord = Point.from1E6(lat, lon);
|
||||||
|
final Set<Product> products;
|
||||||
|
if (productsColumnIndex != -1 && !cursor.isNull(productsColumnIndex))
|
||||||
|
products = Product.fromCodes(cursor.getString(productsColumnIndex).toCharArray());
|
||||||
|
else
|
||||||
|
products = null;
|
||||||
final List<LineDestination> lineDestinations = new LinkedList<>();
|
final List<LineDestination> lineDestinations = new LinkedList<>();
|
||||||
for (final String lineStr : cursor.getString(linesColumnIndex).split(",")) {
|
for (final String lineStr : cursor.getString(linesColumnIndex).split(",")) {
|
||||||
if (!lineStr.isEmpty()) {
|
if (!lineStr.isEmpty()) {
|
||||||
|
@ -1629,7 +1640,7 @@ public class StationsActivity extends OeffiMainActivity implements StationsAware
|
||||||
.add(new LineDestination(new Line(null, null, product, label, style), null));
|
.add(new LineDestination(new Line(null, null, product, label, style), null));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
final Location location = new Location(LocationType.STATION, id, coord, place, name);
|
final Location location = new Location(LocationType.STATION, id, coord, place, name, products);
|
||||||
stations.add(new Station(network, location, lineDestinations));
|
stations.add(new Station(network, location, lineDestinations));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue