Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 13 additions & 0 deletions src/main/java/org/mtransit/android/commons/CursorExt.kt
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,19 @@ fun Cursor.optNotNull(columnIndex: Int) = columnIndex.takeIf { it >= 0 }?.takeIf

// region Boolean

@JvmOverloads
fun Cursor.optBoolean(columnIndex: Int, fallback: Boolean? = null) =
optNotNull(columnIndex)?.let { getInt(it) }?.fromSQL() ?: fallback

@JvmOverloads
fun Cursor.optBoolean(columnName: String, fallback: Boolean? = null) =
this.optBoolean(getColumnIndex(columnName), fallback)

fun Cursor.optBooleanNN(columnIndex: Int, fallback: Boolean) =
optNotNull(columnIndex)?.let { getInt(it) }?.fromSQL() ?: fallback

fun Cursor.optBooleanNN(columnName: String, fallback: Boolean) = this.optBooleanNN(getColumnIndex(columnName), fallback)

fun Cursor.getBoolean(columnName: String) = this.getInt(getColumnIndexOrThrow(columnName)).fromSQL()

// endregion
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,14 @@
import org.json.JSONException;
import org.json.JSONObject;
import org.mtransit.android.commons.CursorExtKt;
import org.mtransit.android.commons.JSONUtils;
import org.mtransit.android.commons.MTLog;
import org.mtransit.android.commons.SpanUtils;
import org.mtransit.android.commons.SqlUtils;
import org.mtransit.android.commons.StringUtils;
import org.mtransit.android.commons.data.DataSourceTypeId.DataSourceType;
import org.mtransit.android.commons.provider.GTFSProviderContract;
import org.mtransit.commons.FeatureFlags;
import org.mtransit.commons.GTFSCommons;

import java.util.Arrays;
Expand All @@ -43,6 +45,8 @@ public String getLogTag() {
@NonNull
private final Stop stop;
private final boolean noPickup;
@Nullable
private final Boolean alwaysLastTripStop;

@VisibleForTesting
public RouteDirectionStop(
Expand All @@ -55,18 +59,31 @@ public RouteDirectionStop(
this(dataSourceTypeId, route, direction, stop, noPickup);
}

@VisibleForTesting
public RouteDirectionStop(
@DataSourceType int dataSourceTypeId,
@NonNull Route route,
@NonNull Direction direction,
@NonNull Stop stop,
boolean noPickup
) {
this(dataSourceTypeId, route, direction, stop, noPickup, null);
}

public RouteDirectionStop(
@DataSourceType int dataSourceTypeId,
@NonNull Route route,
@NonNull Direction direction,
@NonNull Stop stop,
boolean noPickup,
@Nullable Boolean alwaysLastTripStop
) {
super(route.getAuthority(), -1, dataSourceTypeId, POI.ITEM_VIEW_TYPE_ROUTE_DIRECTION_STOP, POI.ITEM_STATUS_TYPE_SCHEDULE, POI.ITEM_ACTION_TYPE_ROUTE_DIRECTION_STOP);
this.route = route;
this.direction = direction;
this.stop = stop;
this.noPickup = noPickup;
this.alwaysLastTripStop = alwaysLastTripStop;
resetUUID();
}

Expand Down Expand Up @@ -176,6 +193,7 @@ public String toStringShort() {
private static final String JSON_DIRECTION = "trip"; // do not change to avoid breaking compat w/ old modules
private static final String JSON_STOP = "stop";
private static final String JSON_NO_PICKUP = "decentOnly";
private static final String JSON_ALWAYS_LAST_TRIP_STOP = "lastStop";

@Nullable
@Override
Expand All @@ -186,6 +204,9 @@ public JSONObject toJSON() {
json.put(JSON_DIRECTION, Direction.toJSON(getDirection()));
json.put(JSON_STOP, Stop.toJSON(getStop()));
json.put(JSON_NO_PICKUP, isNoPickup());
if (FeatureFlags.F_EXPORT_DIRECTION_STOP_LAST) {
json.put(JSON_ALWAYS_LAST_TRIP_STOP, isAlwaysLastTripStop());
}
DefaultPOI.toJSON(this, json);
return json;
} catch (JSONException jsone) {
Expand All @@ -204,12 +225,13 @@ public POI fromJSON(@NonNull JSONObject json) {
public static RouteDirectionStop fromJSONStatic(@NonNull JSONObject json) {
try {
final String authority = DefaultPOI.getAuthorityFromJSON(json);
final RouteDirectionStop rds = new RouteDirectionStop( //
DefaultPOI.getDSTypeIdFromJSON(json),//
Route.fromJSON(json.getJSONObject(JSON_ROUTE), authority), //
Direction.fromJSON(json.getJSONObject(JSON_DIRECTION), authority), //
Stop.fromJSON(json.getJSONObject(JSON_STOP)), //
json.getBoolean(JSON_NO_PICKUP) //
final RouteDirectionStop rds = new RouteDirectionStop(
DefaultPOI.getDSTypeIdFromJSON(json),
Route.fromJSON(json.getJSONObject(JSON_ROUTE), authority),
Direction.fromJSON(json.getJSONObject(JSON_DIRECTION), authority),
Stop.fromJSON(json.getJSONObject(JSON_STOP)),
json.getBoolean(JSON_NO_PICKUP),
JSONUtils.optBoolean(json, JSON_ALWAYS_LAST_TRIP_STOP)
);
DefaultPOI.fromJSON(json, rds);
return rds;
Expand Down Expand Up @@ -244,6 +266,9 @@ public ContentValues toContentValues() {
values.put(GTFSProviderContract.RouteDirectionStopColumns.T_STOP_K_ORIGINAL_ID_HASH, getStop().getOriginalIdHash());
// T_DIRECTION_STOPS_K_STOP_SEQUENCE not used in RouteDirectionStop class
values.put(GTFSProviderContract.RouteDirectionStopColumns.T_DIRECTION_STOPS_K_NO_PICKUP, SqlUtils.toSQLBoolean(isNoPickup()));
if (FeatureFlags.F_EXPORT_DIRECTION_STOP_LAST) {
values.put(GTFSProviderContract.RouteDirectionStopColumns.T_DIRECTION_STOPS_K_ALWAYS_LAST_TRIP_STOP, SqlUtils.toSQLBoolean(isAlwaysLastTripStop()));
}
return values;
}

Expand Down Expand Up @@ -282,7 +307,8 @@ public static RouteDirectionStop fromCursorStatic(@NonNull Cursor c, @NonNull St
CursorExtKt.optIntNN(c, GTFSProviderContract.RouteDirectionStopColumns.T_STOP_K_ACCESSIBLE, Accessibility.DEFAULT),
CursorExtKt.optInt(c, GTFSProviderContract.RouteDirectionStopColumns.T_STOP_K_ORIGINAL_ID_HASH, GTFSCommons.DEFAULT_ID_HASH)
),
CursorExtKt.getBoolean(c, GTFSProviderContract.RouteDirectionStopColumns.T_DIRECTION_STOPS_K_NO_PICKUP)
CursorExtKt.getBoolean(c, GTFSProviderContract.RouteDirectionStopColumns.T_DIRECTION_STOPS_K_NO_PICKUP),
CursorExtKt.optBoolean(c, GTFSProviderContract.RouteDirectionStopColumns.T_DIRECTION_STOPS_K_ALWAYS_LAST_TRIP_STOP)
);
DefaultPOI.fromCursor(c, rds);
return rds;
Expand All @@ -297,6 +323,11 @@ public boolean isNoPickup() {
return noPickup;
}

public boolean isAlwaysLastTripStop() {
if (!FeatureFlags.F_EXPORT_DIRECTION_STOP_LAST) return false;
return Boolean.TRUE.equals(alwaysLastTripStop);
}

@NonNull
@Override
public String getAuthority() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@

import org.mtransit.android.commons.ArrayUtils;
import org.mtransit.android.commons.provider.poi.POIProvider;
import org.mtransit.commons.FeatureFlags;

import java.util.ArrayList;

Expand Down Expand Up @@ -41,6 +42,9 @@ static String[] makePROJECTION_ROUTE_DIRECTION_STOP() {
//
projection.add(RouteDirectionStopColumns.T_DIRECTION_STOPS_K_STOP_SEQUENCE);
projection.add(RouteDirectionStopColumns.T_DIRECTION_STOPS_K_NO_PICKUP);
if (FeatureFlags.F_EXPORT_DIRECTION_STOP_LAST) {
projection.add(RouteDirectionStopColumns.T_DIRECTION_STOPS_K_ALWAYS_LAST_TRIP_STOP);
}
//
projection.add(RouteDirectionStopColumns.T_STOP_K_ID);
projection.add(RouteDirectionStopColumns.T_STOP_K_CODE);
Expand Down Expand Up @@ -132,6 +136,7 @@ class RouteDirectionStopColumns {
private static final String T_DIRECTION_STOPS = "trip_stops"; // do not change to avoid breaking compat w/ old modules
public static final String T_DIRECTION_STOPS_K_STOP_SEQUENCE = T_DIRECTION_STOPS + "_" + "stop_sequence";
public static final String T_DIRECTION_STOPS_K_NO_PICKUP = T_DIRECTION_STOPS + "_" + "decent_only";
public static final String T_DIRECTION_STOPS_K_ALWAYS_LAST_TRIP_STOP = T_DIRECTION_STOPS + "_" + "last_stop";
}

class StopColumns {
Expand Down Expand Up @@ -168,6 +173,7 @@ class DirectionStopColumns {
private static final String T_DIRECTION_STOPS = "trip_stops"; // do not change to avoid breaking compat w/ old modules
public static final String T_DIRECTION_STOPS_K_STOP_SEQUENCE = T_DIRECTION_STOPS + "_" + "stop_sequence";
public static final String T_DIRECTION_STOPS_K_NO_PICKUP = T_DIRECTION_STOPS + "_" + "decent_only";
public static final String T_DIRECTION_STOPS_K_ALWAYS_LAST_TRIP_STOP = T_DIRECTION_STOPS + "_" + "last_stop";
}

class TripColumns {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
import org.mtransit.android.commons.provider.common.ProviderContract;
import org.mtransit.android.commons.provider.poi.POIProvider;
import org.mtransit.android.commons.provider.poi.POIProviderContract;
import org.mtransit.commons.FeatureFlags;

import java.util.Map;

Expand Down Expand Up @@ -207,6 +208,9 @@ private static ArrayMap<String, String> getNewProjectionMap(String authority, in
//
sb.appendTableColumn(GTFSProviderDbHelper.T_DIRECTION_STOPS, GTFSProviderDbHelper.T_DIRECTION_STOPS_K_STOP_SEQUENCE, GTFSProviderContract.RouteDirectionStopColumns.T_DIRECTION_STOPS_K_STOP_SEQUENCE);
sb.appendTableColumn(GTFSProviderDbHelper.T_DIRECTION_STOPS, GTFSProviderDbHelper.T_DIRECTION_STOPS_K_NO_PICKUP, GTFSProviderContract.RouteDirectionStopColumns.T_DIRECTION_STOPS_K_NO_PICKUP);
if (FeatureFlags.F_EXPORT_DIRECTION_STOP_LAST) {
sb.appendTableColumn(GTFSProviderDbHelper.T_DIRECTION_STOPS, GTFSProviderDbHelper.T_DIRECTION_STOPS_K_ALWAYS_LAST_TRIP_STOP, GTFSProviderContract.RouteDirectionStopColumns.T_DIRECTION_STOPS_K_ALWAYS_LAST_TRIP_STOP);
}
//
sb.appendTableColumn(GTFSProviderDbHelper.T_DIRECTION, GTFSProviderDbHelper.T_DIRECTION_K_ID, GTFSProviderContract.RouteDirectionStopColumns.T_DIRECTION_K_ID);
sb.appendTableColumn(GTFSProviderDbHelper.T_DIRECTION, GTFSProviderDbHelper.T_DIRECTION_K_HEADSIGN_TYPE, GTFSProviderContract.RouteDirectionStopColumns.T_DIRECTION_K_HEADSIGN_TYPE);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,7 @@ public String getLogTag() {
static final String T_DIRECTION_STOPS_K_STOP_ID = GTFSCommons.T_DIRECTION_STOPS_K_STOP_ID;
static final String T_DIRECTION_STOPS_K_STOP_SEQUENCE = GTFSCommons.T_DIRECTION_STOPS_K_STOP_SEQUENCE;
static final String T_DIRECTION_STOPS_K_NO_PICKUP = GTFSCommons.T_DIRECTION_STOPS_K_NO_PICKUP;
static final String T_DIRECTION_STOPS_K_ALWAYS_LAST_TRIP_STOP = GTFSCommons.T_DIRECTION_STOPS_K_ALWAYS_LAST_TRIP_STOP;
private static final String T_DIRECTION_STOPS_SQL_CREATE = GTFSCommons.getT_DIRECTION_STOPS_SQL_CREATE();
private static final String T_DIRECTION_STOPS_SQL_INSERT = GTFSCommons.getT_DIRECTION_STOPS_SQL_INSERT();
private static final String T_DIRECTION_STOPS_SQL_DROP = GTFSCommons.getT_DIRECTION_STOPS_SQL_DROP();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,9 @@ public static void append(@NonNull UriMatcher uriMatcher, @NonNull String author
//
sb.appendTableColumn(GTFSProviderDbHelper.T_DIRECTION_STOPS, GTFSProviderDbHelper.T_DIRECTION_STOPS_K_STOP_SEQUENCE, GTFSProviderContract.RouteDirectionStopColumns.T_DIRECTION_STOPS_K_STOP_SEQUENCE);
sb.appendTableColumn(GTFSProviderDbHelper.T_DIRECTION_STOPS, GTFSProviderDbHelper.T_DIRECTION_STOPS_K_NO_PICKUP, GTFSProviderContract.RouteDirectionStopColumns.T_DIRECTION_STOPS_K_NO_PICKUP);
if (FeatureFlags.F_EXPORT_DIRECTION_STOP_LAST) {
sb.appendTableColumn(GTFSProviderDbHelper.T_DIRECTION_STOPS, GTFSProviderDbHelper.T_DIRECTION_STOPS_K_ALWAYS_LAST_TRIP_STOP, GTFSProviderContract.RouteDirectionStopColumns.T_DIRECTION_STOPS_K_ALWAYS_LAST_TRIP_STOP);
}
//
sb.appendTableColumn(GTFSProviderDbHelper.T_DIRECTION, GTFSProviderDbHelper.T_DIRECTION_K_ID, GTFSProviderContract.RouteDirectionStopColumns.T_DIRECTION_K_ID);
sb.appendTableColumn(GTFSProviderDbHelper.T_DIRECTION, GTFSProviderDbHelper.T_DIRECTION_K_HEADSIGN_TYPE, GTFSProviderContract.RouteDirectionStopColumns.T_DIRECTION_K_HEADSIGN_TYPE);
Expand Down Expand Up @@ -154,6 +157,9 @@ public static void append(@NonNull UriMatcher uriMatcher, @NonNull String author
//
sb.appendTableColumn(GTFSProviderDbHelper.T_DIRECTION_STOPS, GTFSProviderDbHelper.T_DIRECTION_STOPS_K_STOP_SEQUENCE, GTFSProviderContract.DirectionStopColumns.T_DIRECTION_STOPS_K_STOP_SEQUENCE);
sb.appendTableColumn(GTFSProviderDbHelper.T_DIRECTION_STOPS, GTFSProviderDbHelper.T_DIRECTION_STOPS_K_NO_PICKUP, GTFSProviderContract.DirectionStopColumns.T_DIRECTION_STOPS_K_NO_PICKUP);
if (FeatureFlags.F_EXPORT_DIRECTION_STOP_LAST) {
sb.appendTableColumn(GTFSProviderDbHelper.T_DIRECTION_STOPS, GTFSProviderDbHelper.T_DIRECTION_STOPS_K_ALWAYS_LAST_TRIP_STOP, GTFSProviderContract.DirectionStopColumns.T_DIRECTION_STOPS_K_ALWAYS_LAST_TRIP_STOP);
}
//
sb.appendTableColumn(GTFSProviderDbHelper.T_DIRECTION, GTFSProviderDbHelper.T_DIRECTION_K_ID, GTFSProviderContract.DirectionStopColumns.T_DIRECTION_K_ID);
sb.appendTableColumn(GTFSProviderDbHelper.T_DIRECTION, GTFSProviderDbHelper.T_DIRECTION_K_HEADSIGN_TYPE, GTFSProviderContract.DirectionStopColumns.T_DIRECTION_K_HEADSIGN_TYPE);
Expand Down