QueryHistoryProvider: Fix mapping of null coord to 0/0 ints.

This commit is contained in:
Andreas Schildbach 2018-11-17 18:29:13 +01:00
parent 1ded58bc56
commit 78fdf6d43f
3 changed files with 44 additions and 25 deletions

View file

@ -1299,22 +1299,31 @@ public class DirectionsActivity extends OeffiMainActivity implements ActivityCom
final String fromName = cursor.getString(fromNameC);
if (fromName.toLowerCase(Constants.DEFAULT_LOCALE)
.contains(constraintStr.toLowerCase(Constants.DEFAULT_LOCALE))) {
final Location location = new Location(
QueryHistoryProvider.convert(cursor.getInt(fromTypeC)),
cursor.getString(fromIdC),
Point.from1E6(cursor.getInt(fromLatC), cursor.getInt(fromLonC)),
cursor.getString(fromPlaceC), fromName);
final LocationType fromType = QueryHistoryProvider
.convert(cursor.getInt(fromTypeC));
final String fromId = cursor.getString(fromIdC);
final int fromLat = cursor.getInt(fromLatC);
final int fromLon = cursor.getInt(fromLonC);
final Point fromCoord = fromLat != 0 || fromLon != 0
? Point.from1E6(fromLat, fromLon) : null;
final String fromPlace = cursor.getString(fromPlaceC);
final Location location = new Location(fromType, fromId, fromCoord, fromPlace,
fromName);
if (!results.contains(location))
results.add(location);
}
final String toName = cursor.getString(toNameC);
if (toName.toLowerCase(Constants.DEFAULT_LOCALE)
.contains(constraintStr.toLowerCase(Constants.DEFAULT_LOCALE))) {
final Location location = new Location(
QueryHistoryProvider.convert(cursor.getInt(toTypeC)),
cursor.getString(toIdC),
Point.from1E6(cursor.getInt(toLatC), cursor.getInt(toLonC)),
cursor.getString(toPlaceC), toName);
final LocationType toType = QueryHistoryProvider
.convert(cursor.getInt(toTypeC));
final String toId = cursor.getString(toIdC);
final int toLat = cursor.getInt(toLatC);
final int toLon = cursor.getInt(toLonC);
final Point toCoord = toLat != 0 || toLon != 0 ? Point.from1E6(toLat, toLon)
: null;
final String toPlace = cursor.getString(toPlaceC);
final Location location = new Location(toType, toId, toCoord, toPlace, toName);
if (!results.contains(location))
results.add(location);
}

View file

@ -96,8 +96,8 @@ public class QueryHistoryProvider extends ContentProvider {
if (cursor.getInt(cursor.getColumnIndexOrThrow(QueryHistoryProvider.KEY_FROM_LAT)) == 0
&& cursor.getInt(cursor.getColumnIndexOrThrow(QueryHistoryProvider.KEY_FROM_LON)) == 0) {
values.put(QueryHistoryProvider.KEY_FROM_LAT, from.getLatAs1E6());
values.put(QueryHistoryProvider.KEY_FROM_LON, from.getLonAs1E6());
values.put(QueryHistoryProvider.KEY_FROM_LAT, from.hasCoord() ? from.getLatAs1E6() : 0);
values.put(QueryHistoryProvider.KEY_FROM_LON, from.hasCoord() ? from.getLonAs1E6() : 0);
}
if (cursor.getInt(cursor.getColumnIndexOrThrow(QueryHistoryProvider.KEY_TO_ID)) == 0)
@ -105,8 +105,8 @@ public class QueryHistoryProvider extends ContentProvider {
if (cursor.getInt(cursor.getColumnIndexOrThrow(QueryHistoryProvider.KEY_TO_LAT)) == 0
&& cursor.getInt(cursor.getColumnIndexOrThrow(QueryHistoryProvider.KEY_TO_LON)) == 0) {
values.put(QueryHistoryProvider.KEY_TO_LAT, to.getLatAs1E6());
values.put(QueryHistoryProvider.KEY_TO_LON, to.getLonAs1E6());
values.put(QueryHistoryProvider.KEY_TO_LAT, to.hasCoord() ? to.getLatAs1E6() : 0);
values.put(QueryHistoryProvider.KEY_TO_LON, to.hasCoord() ? to.getLonAs1E6() : 0);
}
if (favorite != null)
@ -125,14 +125,14 @@ public class QueryHistoryProvider extends ContentProvider {
final ContentValues values = new ContentValues();
values.put(QueryHistoryProvider.KEY_FROM_TYPE, QueryHistoryProvider.convert(from.type));
values.put(QueryHistoryProvider.KEY_FROM_ID, from.id);
values.put(QueryHistoryProvider.KEY_FROM_LAT, from.getLatAs1E6());
values.put(QueryHistoryProvider.KEY_FROM_LON, from.getLonAs1E6());
values.put(QueryHistoryProvider.KEY_FROM_LAT, from.hasCoord() ? from.getLatAs1E6() : 0);
values.put(QueryHistoryProvider.KEY_FROM_LON, from.hasCoord() ? from.getLonAs1E6() : 0);
values.put(QueryHistoryProvider.KEY_FROM_PLACE, from.place);
values.put(QueryHistoryProvider.KEY_FROM_NAME, from.name);
values.put(QueryHistoryProvider.KEY_TO_TYPE, QueryHistoryProvider.convert(to.type));
values.put(QueryHistoryProvider.KEY_TO_ID, to.id);
values.put(QueryHistoryProvider.KEY_TO_LAT, to.getLatAs1E6());
values.put(QueryHistoryProvider.KEY_TO_LON, to.getLonAs1E6());
values.put(QueryHistoryProvider.KEY_TO_LAT, to.hasCoord() ? to.getLatAs1E6() : 0);
values.put(QueryHistoryProvider.KEY_TO_LON, to.hasCoord() ? to.getLonAs1E6() : 0);
values.put(QueryHistoryProvider.KEY_TO_PLACE, to.place);
values.put(QueryHistoryProvider.KEY_TO_NAME, to.name);

View file

@ -22,6 +22,7 @@ import de.schildbach.oeffi.directions.QueryHistoryProvider;
import de.schildbach.oeffi.stations.FavoriteStationsProvider;
import de.schildbach.pte.NetworkId;
import de.schildbach.pte.dto.Location;
import de.schildbach.pte.dto.LocationType;
import de.schildbach.pte.dto.Point;
import android.content.ContentResolver;
@ -184,13 +185,22 @@ public class QueryHistoryAdapter extends RecyclerView.Adapter<QueryHistoryViewHo
public void onBindViewHolder(final QueryHistoryViewHolder holder, final int position) {
cursor.moveToPosition(position);
final long rowId = cursor.getLong(rowIdColumn);
final Location from = new Location(QueryHistoryProvider.convert(cursor.getInt(fromTypeColumn)),
cursor.getString(fromIdColumn),
Point.from1E6(cursor.getInt(fromLatColumn), cursor.getInt(fromLonColumn)),
cursor.getString(fromPlaceColumn), cursor.getString(fromNameColumn));
final Location to = new Location(QueryHistoryProvider.convert(cursor.getInt(toTypeColumn)),
cursor.getString(toIdColumn), Point.from1E6(cursor.getInt(toLatColumn), cursor.getInt(toLonColumn)),
cursor.getString(toPlaceColumn), cursor.getString(toNameColumn));
final LocationType fromType = QueryHistoryProvider.convert(cursor.getInt(fromTypeColumn));
final String fromId = cursor.getString(fromIdColumn);
final int fromLat = cursor.getInt(fromLatColumn);
final int fromLon = cursor.getInt(fromLonColumn);
final Point fromCoord = fromLat != 0 || fromLon != 0 ? Point.from1E6(fromLat, fromLon) : null;
final String fromPlace = cursor.getString(fromPlaceColumn);
final String fromName = cursor.getString(fromNameColumn);
final Location from = new Location(fromType, fromId, fromCoord, fromPlace, fromName);
final LocationType toType = QueryHistoryProvider.convert(cursor.getInt(toTypeColumn));
final String toId = cursor.getString(toIdColumn);
final int toLat = cursor.getInt(toLatColumn);
final int toLon = cursor.getInt(toLonColumn);
final Point toCoord = toLat != 0 || toLon != 0 ? Point.from1E6(toLat, toLon) : null;
final String toPlace = cursor.getString(toPlaceColumn);
final String toName = cursor.getString(toNameColumn);
final Location to = new Location(toType, toId, toCoord, toPlace, toName);
final boolean isFavorite = cursor.getInt(favoriteColumn) == 1;
final long savedTripDepartureTime = cursor.getLong(savedTripDepartureTimeColumn);
final byte[] serializedSavedTrip = cursor.getBlob(savedTripColumn);