Skip to content
Merged
Original file line number Diff line number Diff line change
Expand Up @@ -443,6 +443,14 @@ public static void savePrefLcl(@Nullable final Context context, @NonNull final S
savePrefLclAsync(context, prefKey, newValue);
}

@WorkerThread
public static void savePrefLclSync(@Nullable final Context context, @NonNull final String prefKey, @Nullable final Boolean newValue) {
if (context == null) {
return;
}
savePref(getPrefLcl(context), prefKey, newValue);
}

@MainThread
public static void savePrefLclAsync(@NonNull Context context, @NonNull String prefKey, @Nullable Boolean newValue) {
new MTAsyncTask<Void, Void, Void>() {
Expand Down
55 changes: 31 additions & 24 deletions src/main/java/org/mtransit/android/commons/data/DefaultPOI.java
Original file line number Diff line number Diff line change
Expand Up @@ -67,30 +67,37 @@ public DefaultPOI(@NonNull String authority, int id, @DataSourceType int dataSou

@Override
public boolean equals(Object o) {
if (o == null) {
return false;
}
if (this.getClass() != o.getClass()) {
return false;
}
DefaultPOI otherPOI = (DefaultPOI) o;
if (!this.getUUID().equals(otherPOI.getUUID())) {
return false;
}
if (this.getType() != otherPOI.getType()) {
return false;
}
if (this.getStatusType() != otherPOI.getStatusType()) {
return false;
}
if (this.getActionsType() != otherPOI.getActionsType()) {
return false;
}
//noinspection RedundantIfStatement
if (!Objects.equals(this.getName(), otherPOI.getName())) {
return false;
}
return true;
if (!(o instanceof DefaultPOI)) return false;
final DefaultPOI that = (DefaultPOI) o;
return id == that.id
&& authority.equals(that.authority)
&& name.equals(that.name)
&& Double.compare(lat, that.lat) == 0
&& Double.compare(lng, that.lng) == 0
&& accessible == that.accessible
&& type == that.type
&& dataSourceTypeId == that.dataSourceTypeId
&& statusType == that.statusType
&& actionsType == that.actionsType
&& Objects.equals(scoreOpt, that.scoreOpt)
;
Comment thread
mmathieum marked this conversation as resolved.
Comment thread
mmathieum marked this conversation as resolved.
}

@Override
public int hashCode() {
int result = 0;
result = 31 * result + id;
result = 31 * result + authority.hashCode();
result = 31 * result + name.hashCode();
result = 31 * result + Double.hashCode(lat);
result = 31 * result + Double.hashCode(lng);
result = 31 * result + accessible;
result = 31 * result + type;
result = 31 * result + dataSourceTypeId;
result = 31 * result + statusType;
result = 31 * result + actionsType;
result = 31 * result + Objects.hashCode(scoreOpt);
return result;
Comment thread
mmathieum marked this conversation as resolved.
Outdated
}
Comment thread
mmathieum marked this conversation as resolved.

@NonNull
Expand Down
24 changes: 24 additions & 0 deletions src/main/java/org/mtransit/android/commons/data/Direction.java
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@

import java.lang.annotation.Retention;
import java.util.Comparator;
import java.util.Objects;

@SuppressWarnings("WeakerAccess")
public class Direction implements Targetable {
Expand Down Expand Up @@ -273,6 +274,29 @@ public long getRouteId() {
return routeId;
}

@Override
public boolean equals(Object o) {
if (!(o instanceof Direction)) return false;
final Direction direction = (Direction) o;
return id == direction.id
&& authority.equals(direction.authority)
&& headsignType == direction.headsignType
&& headsignValue.equals(direction.headsignValue)
&& routeId == direction.routeId
;
Comment thread
mmathieum marked this conversation as resolved.
}

@Override
public int hashCode() {
int result = 0;
result = 31 * result + Long.hashCode(id);
result = 31 * result + authority.hashCode();
result = 31 * result + headsignType;
result = 31 * result + headsignValue.hashCode();
result = 31 * result + Long.hashCode(routeId);
return result;
Comment thread
mmathieum marked this conversation as resolved.
Outdated
Comment thread
mmathieum marked this conversation as resolved.
Outdated
}

public static class HeadSignComparator implements Comparator<Direction>, MTLog.Loggable {

private static final String LOG_TAG = Direction.class.getSimpleName() + ">" + HeadSignComparator.class.getSimpleName();
Expand Down
43 changes: 25 additions & 18 deletions src/main/java/org/mtransit/android/commons/data/Route.java
Original file line number Diff line number Diff line change
Expand Up @@ -117,24 +117,31 @@ public int getColorInt() {

@Override
public boolean equals(Object o) {
if (!(o instanceof Route)) {
return false;
}
Route otherRoute = (Route) o;
if (getId() != otherRoute.getId()) {
return false;
}
if (!Objects.equals(getShortName(), otherRoute.getShortName())) {
return false;
}
if (!Objects.equals(getLongName(), otherRoute.getLongName())) {
return false;
}
//noinspection RedundantIfStatement
if (!Objects.equals(getColor(), otherRoute.getColor())) {
return false;
}
return true;
if (!(o instanceof Route)) return false;
final Route route = (Route) o;
return id == route.id
&& authority.equals(route.authority)
&& shortName.equals(route.shortName)
&& longName.equals(route.longName)
&& color.equals(route.color)
&& Objects.equals(originalIdHash, route.originalIdHash)
&& Objects.equals(type, route.type)
&& Objects.equals(colorInt, route.colorInt)
;
Comment thread
mmathieum marked this conversation as resolved.
}

@Override
public int hashCode() {
int result = 0;
result = 31 * result + Long.hashCode(id);
result = 31 * result + authority.hashCode();
result = 31 * result + shortName.hashCode();
result = 31 * result + longName.hashCode();
result = 31 * result + color.hashCode();
result = 31 * result + Objects.hashCode(originalIdHash);
result = 31 * result + Objects.hashCode(type);
result = 31 * result + Objects.hashCode(colorInt);
return result;
Comment thread
mmathieum marked this conversation as resolved.
Outdated
Comment thread
mmathieum marked this conversation as resolved.
Outdated
}
Comment thread
mmathieum marked this conversation as resolved.

@NonNull
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,23 @@ public boolean equals(int routeId, int directionIdId) {
return getRoute().getId() == routeId && getDirection().getId() == directionIdId;
}

@Override
public boolean equals(Object o) {
if (!(o instanceof RouteDirection)) return false;
final RouteDirection that = (RouteDirection) o;
return route.equals(that.route)
&& direction.equals(that.direction)
;
Comment thread
mmathieum marked this conversation as resolved.
}

@Override
public int hashCode() {
int result = 0;
result = 31 * result + route.hashCode();
result = 31 * result + direction.hashCode();
return result;
Comment thread
mmathieum marked this conversation as resolved.
Outdated
Comment thread
mmathieum marked this conversation as resolved.
Outdated
}

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

import java.util.Arrays;
import java.util.Collection;
import java.util.Objects;

public class RouteDirectionStop extends DefaultPOI {

Expand Down Expand Up @@ -154,6 +155,30 @@ public boolean equals(int routeId, int directionIdId, int stopId) {
return getRoute().getId() == routeId && getDirection().getId() == directionIdId && getStop().getId() == stopId;
}

@Override
public boolean equals(Object o) {
if (!(o instanceof RouteDirectionStop)) return false;
if (!super.equals(o)) return false;
final RouteDirectionStop that = (RouteDirectionStop) o;
return route.equals(that.route)
&& direction.equals(that.direction)
&& stop.equals(that.stop)
&& noPickup == that.noPickup
&& Objects.equals(alwaysLastTripStop, that.alwaysLastTripStop)
;
Comment thread
mmathieum marked this conversation as resolved.
}

@Override
public int hashCode() {
int result = 0;
result = 31 * result + route.hashCode();
result = 31 * result + direction.hashCode();
result = 31 * result + stop.hashCode();
result = 31 * result + Boolean.hashCode(noPickup);
result = 31 * result + Objects.hashCode(alwaysLastTripStop);
return result;
Comment thread
mmathieum marked this conversation as resolved.
Outdated
Comment thread
mmathieum marked this conversation as resolved.
Outdated
}

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

import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.annotation.VisibleForTesting;

import org.mtransit.android.commons.ComparatorUtils;
import org.mtransit.android.commons.CursorExtKt;
Expand Down Expand Up @@ -258,6 +259,11 @@ public boolean isUseful() {
return this.lastUpdateInMs + this.maxValidityInMs >= TimeUtils.currentTimeMillis();
}

@VisibleForTesting
protected long getMaxValidityInMs() {
return maxValidityInMs;
}

@Nullable
public Integer getId() {
return this.id;
Expand Down
28 changes: 28 additions & 0 deletions src/main/java/org/mtransit/android/commons/data/Stop.java
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@
import org.mtransit.android.commons.provider.GTFSProviderContract;
import org.mtransit.commons.GTFSCommons;

import java.util.Objects;

@SuppressWarnings("WeakerAccess")
public class Stop {

Expand Down Expand Up @@ -209,4 +211,30 @@ public boolean isSameOriginalId(@Nullable String cleanedOriginalIdHash) {
return this.originalIdHash.toString().equals(cleanedOriginalIdHash);

}

@Override
public boolean equals(Object o) {
if (!(o instanceof Stop)) return false;
final Stop stop = (Stop) o;
return id == stop.id
&& code.equals(stop.code)
&& name.equals(stop.name)
&& Double.compare(lat, stop.lat) == 0
&& Double.compare(lng, stop.lng) == 0
&& accessible == stop.accessible
&& Objects.equals(originalIdHash, stop.originalIdHash);
Comment thread
mmathieum marked this conversation as resolved.
}

@Override
public int hashCode() {
int result = 0;
result = 31 * result + id;
result = 31 * result + code.hashCode();
result = 31 * result + name.hashCode();
result = 31 * result + Double.hashCode(lat);
result = 31 * result + Double.hashCode(lng);
result = 31 * result + accessible;
result = 31 * result + Objects.hashCode(originalIdHash);
return result;
Comment thread
mmathieum marked this conversation as resolved.
Outdated
Comment thread
mmathieum marked this conversation as resolved.
Outdated
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -415,6 +415,20 @@ public static String getAGENCY_TRIP_UPDATES_URL_CACHED(@NonNull Context context)
return agencyTripUpdatesUrlCached;
}

@Nullable
private static String targetAuthority = null;

/**
* Override if multiple {@link GTFSRealTimeProvider} implementations in same app.
*/
@NonNull
public static String getTARGET_AUTHORITY(@NonNull Context context) {
if (targetAuthority == null) {
targetAuthority = context.getResources().getString(R.string.gtfs_real_time_for_poi_authority);
}
return targetAuthority;
}

@Nullable
private static Boolean ignoreDirection = null;

Expand Down Expand Up @@ -917,6 +931,7 @@ private List<ServiceUpdate> loadAgencyServiceUpdateDataFromWWW(@NonNull Context
MTLog.d(this, "loadAgencyServiceUpdateDataFromWWW() > service update: %s.", serviceUpdate);
}
}
GTFSRealTimeServiceAlertsProvider.setTripIdsOutOfSync(this, serviceUpdates);
return serviceUpdates;
default:
MTLog.w(this, "ERROR: HTTP URL-Connection Response Code %s (Message: %s)", response.code(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import org.mtransit.android.commons.provider.poi.POIProviderContract

fun Context.getRDS(
authority: String,
routeId: Long,
routeId: Long? = null,
directionId: Long? = null,
): List<RouteDirectionStop>? = try {
contentResolver.query(
Expand All @@ -24,17 +24,20 @@ fun Context.getRDS(
POIProviderContract.Filter.toJSON(
POIProviderContract.Filter.getNewSqlSelectionFilter(
buildString {
append(
SqlUtils.getWhereEquals(
GTFSProviderContract.RouteDirectionStopColumns.T_ROUTE_K_ID,
routeId
routeId?.let {
append(
SqlUtils.getWhereEquals(
GTFSProviderContract.RouteDirectionStopColumns.T_ROUTE_K_ID,
it
)
)
)
}
directionId?.let {
append(SqlUtils.AND)
if (isNotEmpty()) append(SqlUtils.AND)
append(SqlUtils.getWhereEquals(GTFSProviderContract.RouteDirectionStopColumns.T_DIRECTION_K_ID, it))
}
})
}
)
).toString(),
null,
SqlUtils.getSortOrderAscending(GTFSProviderContract.RouteDirectionStopColumns.T_DIRECTION_STOPS_K_STOP_SEQUENCE)
Expand All @@ -57,10 +60,12 @@ fun Context.getRDS(
fun Context.getTripIds(authority: String, routeId: Long, directionId: Long? = null) =
getTrips(authority, routeId, directionId)?.map { it.tripId }

@JvmOverloads
fun Context.getTrips(
authority: String,
routeId: Long,
routeId: Long? = null,
directionId: Long? = null,
tripIds: List<String>? = null,
): List<Trip>? = try {
contentResolver.query(
Uri.withAppendedPath(
Expand All @@ -69,16 +74,22 @@ fun Context.getTrips(
),
GTFSProviderContract.PROJECTION_TRIP,
buildString {
append(
SqlUtils.getWhereEquals(
GTFSProviderContract.TripColumns.T_TRIP_K_ROUTE_ID,
routeId
routeId?.let {
append(
SqlUtils.getWhereEquals(
GTFSProviderContract.TripColumns.T_TRIP_K_ROUTE_ID,
it
)
)
)
}
directionId?.let {
append(SqlUtils.AND)
if (isNotEmpty()) append(SqlUtils.AND)
append(SqlUtils.getWhereEquals(GTFSProviderContract.TripColumns.T_TRIP_K_DIRECTION_ID, it))
}
tripIds?.let {
if (isNotEmpty()) append(SqlUtils.AND)
append(SqlUtils.getWhereIn(GTFSProviderContract.TripColumns.T_TRIP_K_TRIP_ID, it))
Comment thread
mmathieum marked this conversation as resolved.
Outdated
}
},
null,
GTFSRDSProvider.TRIP_SORT_ORDER,
Expand Down
Loading