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
23 changes: 11 additions & 12 deletions src/main/java/org/mtransit/android/commons/SpanUtils.java
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
import android.text.style.TextAppearanceSpan;
import android.text.style.TypefaceSpan;

import androidx.annotation.CheckResult;
import androidx.annotation.ColorInt;
import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
Expand Down Expand Up @@ -132,13 +133,12 @@ public static ForegroundColorSpan getNewTextColor(@ColorInt int color) {
return new ForegroundColorSpan(color);
}

@CheckResult
@NonNull
public static CharSequence setAll(@Nullable CharSequence cs, @Nullable Object... spans) {
if (cs instanceof SpannableStringBuilder) {
return setAll((SpannableStringBuilder) cs, spans);
} else {
return setAll(new SpannableStringBuilder(cs), spans);
}
public static SpannableStringBuilder setAll(@Nullable CharSequence cs, @Nullable Object... spans) {
final SpannableStringBuilder ssb = cs instanceof SpannableStringBuilder ? (SpannableStringBuilder) cs
: cs == null ? new SpannableStringBuilder() : new SpannableStringBuilder(cs);
return setAllNN(ssb, spans);
}

@Nullable
Expand All @@ -151,13 +151,12 @@ public static SpannableStringBuilder setAllNN(@NonNull SpannableStringBuilder ss
return setNN(ssb, 0, ssb.length(), spans);
}

@CheckResult
@NonNull
public static CharSequence set(@Nullable CharSequence cs, int start, int end, @Nullable Object... spans) {
if (cs instanceof SpannableStringBuilder) {
return set((SpannableStringBuilder) cs, start, end, spans);
} else {
return set(new SpannableStringBuilder(cs), start, end, spans);
}
public static SpannableStringBuilder set(@Nullable CharSequence cs, int start, int end, @Nullable Object... spans) {
final SpannableStringBuilder ssb = cs instanceof SpannableStringBuilder ? (SpannableStringBuilder) cs
: cs == null ? new SpannableStringBuilder() : new SpannableStringBuilder(cs);
return set(ssb, start, end, spans);
}

@Nullable
Expand Down
47 changes: 30 additions & 17 deletions src/main/java/org/mtransit/android/commons/data/ServiceUpdate.java
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
import org.mtransit.android.commons.ComparatorUtils;
import org.mtransit.android.commons.CursorExtKt;
import org.mtransit.android.commons.MTLog;
import org.mtransit.android.commons.SqlUtils;
import org.mtransit.android.commons.TimeUtils;
import org.mtransit.android.commons.provider.serviceupdate.ServiceUpdateProviderContract;

Expand Down Expand Up @@ -50,6 +51,8 @@ public String getLogTag() {
@Nullable
private String textHTML;
private int severity;
@Nullable
private final Boolean noService;
private final String language;
@NonNull
private final String sourceLabel;
Expand All @@ -65,6 +68,7 @@ public ServiceUpdate(
@NonNull String text,
@Nullable String optTextHTML,
int severity,
@Nullable Boolean noService,
@NonNull String sourceId,
@NonNull String sourceLabel,
@Nullable String originalId,
Expand All @@ -78,6 +82,7 @@ public ServiceUpdate(
this.text = text;
this.textHTML = optTextHTML;
this.severity = severity;
this.noService = noService;
this.sourceId = sourceId;
this.sourceLabel = sourceLabel;
this.originalId = originalId;
Expand All @@ -102,6 +107,10 @@ public boolean isSeverityWarning() {
return isSeverityWarning(this.severity);
}

public boolean isNoService() {
return Boolean.TRUE.equals(this.noService);
}

public static boolean isSeverityWarning(int severity) {
return severity == SEVERITY_WARNING_UNKNOWN //
|| severity == SEVERITY_WARNING_AGENCY //
Expand Down Expand Up @@ -203,21 +212,20 @@ public boolean shouldDisplay() {
@NonNull
@Override
public String toString() {
return ServiceUpdate.class.getSimpleName() + '[' + //
"id:" + this.id + //
',' + //
"oId:" + this.originalId + //
',' + //
"tUUID:" + this.targetUUID + //
',' + //
"tTrip:" + this.targetTripId + //
',' + //
"lang:" + this.language + //
',' + //
"txt:" + this.text + //
',' + //
"svrt:" + this.severity + //
']';
final StringBuilder sb = new StringBuilder(ServiceUpdate.class.getSimpleName());
sb.append('[');
sb.append("id:").append(this.id).append(',');
sb.append("oId:").append(this.originalId).append(',');
sb.append("tUUID:").append(this.targetUUID).append(',');
sb.append("tTrip:").append(this.targetTripId).append(',');
sb.append("lang:").append(this.language).append(',');
sb.append("txt:").append(this.text).append(',');
sb.append("svrt:").append(this.severity);
if (isNoService()) {
sb.append("noSrv:").append(this.noService);
}
sb.append(']');
return sb.toString();
}

public boolean isUseful() {
Expand Down Expand Up @@ -248,7 +256,8 @@ public static ServiceUpdate fromCursor(@NonNull Cursor cursor) {
final String originalId = CursorExtKt.optString(cursor, ServiceUpdateProviderContract.Columns.T_SERVICE_UPDATE_K_ORIGINAL_ID, null);
final String sourceLabel = cursor.getString(cursor.getColumnIndexOrThrow(ServiceUpdateProviderContract.Columns.T_SERVICE_UPDATE_K_SOURCE_LABEL));
final String sourceId = cursor.getString(cursor.getColumnIndexOrThrow(ServiceUpdateProviderContract.Columns.T_SERVICE_UPDATE_K_SOURCE_ID));
return new ServiceUpdate(id, targetUUID, targetTripId, lastUpdateInMs, maxValidityInMs, text, htmlText, severity, sourceId, sourceLabel, originalId, language);
final Boolean noService = CursorExtKt.optBoolean(cursor, ServiceUpdateProviderContract.Columns.T_SERVICE_UPDATE_K_NO_SERVICE, null);
return new ServiceUpdate(id, targetUUID, targetTripId, lastUpdateInMs, maxValidityInMs, text, htmlText, severity, noService, sourceId, sourceLabel, originalId, language);
}

/**
Expand All @@ -268,7 +277,8 @@ public Object[] getCursorRow() {
language,
originalId,
sourceLabel,
sourceId
sourceId,
noService == null ? null : SqlUtils.toSQLBoolean(noService)
};
}

Expand All @@ -289,6 +299,9 @@ public ContentValues toContentValues() {
contentValues.put(ServiceUpdateProviderContract.Columns.T_SERVICE_UPDATE_K_ORIGINAL_ID, this.originalId);
contentValues.put(ServiceUpdateProviderContract.Columns.T_SERVICE_UPDATE_K_SOURCE_LABEL, this.sourceLabel);
contentValues.put(ServiceUpdateProviderContract.Columns.T_SERVICE_UPDATE_K_SOURCE_ID, this.sourceId);
if (this.noService != null) {
contentValues.put(ServiceUpdateProviderContract.Columns.T_SERVICE_UPDATE_K_NO_SERVICE, SqlUtils.toSQLBoolean(this.noService));
}
return contentValues;
}

Expand Down
28 changes: 16 additions & 12 deletions src/main/java/org/mtransit/android/commons/data/ServiceUpdateKtx.kt
Original file line number Diff line number Diff line change
Expand Up @@ -55,23 +55,25 @@ fun makeServiceUpdate(
text: String,
optTextHTML: String? = null,
severity: Int,
noService: Boolean? = null,
sourceId: String,
sourceLabel: String,
originalId: String? = null,
language: String
) = makeServiceUpdate(
optId,
targetUUID,
targetTripId,
lastUpdate.toMillis(),
maxValidity.inWholeMilliseconds,
text,
optTextHTML,
severity,
sourceId,
sourceLabel,
originalId,
language,
optId = optId,
targetUUID = targetUUID,
targetTripId = targetTripId,
lastUpdateMs = lastUpdate.toMillis(),
maxValidityMs = maxValidity.inWholeMilliseconds,
text = text,
optTextHTML = optTextHTML,
severity = severity,
noService = noService,
sourceId = sourceId,
sourceLabel = sourceLabel,
originalId = originalId,
language = language,
)

fun makeServiceUpdate(
Expand All @@ -83,6 +85,7 @@ fun makeServiceUpdate(
text: String,
optTextHTML: String? = null,
severity: Int,
noService: Boolean? = null,
sourceId: String,
sourceLabel: String,
originalId: String? = null,
Expand All @@ -96,6 +99,7 @@ fun makeServiceUpdate(
text,
optTextHTML,
severity,
noService,
sourceId,
sourceLabel,
originalId,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -895,11 +895,12 @@ private List<ServiceUpdate> loadAgencyServiceUpdateDataFromWWW(@NonNull Context
try {
GtfsRealtime.FeedMessage gFeedMessage = GtfsRealtime.FeedMessage.parseFrom(response.body().bytes());
List<Pair<GtfsRealtime.Alert, String>> alertsWithIdPair = GtfsRealtimeExt.toAlertsWithIdPair(gFeedMessage.getEntityList());
if (Constants.DEBUG) MTLog.d(this, "loadAgencyDataFromWWW() > GTFS alerts[%s]: ", alertsWithIdPair.size());
for (Pair<GtfsRealtime.Alert, String> gAlertAndId : GtfsRealtimeExt.sortAlertsPair(alertsWithIdPair, newLastUpdateInMs)) {
final GtfsRealtime.Alert gAlert = gAlertAndId.getFirst();
final String feedEntityId = gAlertAndId.getSecond();
if (Constants.DEBUG) {
MTLog.d(this, "loadAgencyServiceUpdateDataFromWWW() > GTFS alert[%s]: %s.", feedEntityId, GtfsRealtimeExt.toStringExt(gAlert));
MTLog.d(this, "loadAgencyServiceUpdateDataFromWWW() > - GTFS[%s] %s", feedEntityId, GtfsRealtimeExt.toStringExt(gAlert));
}
final Set<ServiceUpdate> alertsServiceUpdates = processAlerts(context, sourceLabel, feedEntityId, newLastUpdateInMs, gAlert, ignoreDirection);
if (alertsServiceUpdates != null && !alertsServiceUpdates.isEmpty()) {
Expand Down Expand Up @@ -1012,6 +1013,7 @@ private HashSet<ServiceUpdate> processAlerts(
languages.addAll(descriptionTexts.keySet());
languages.addAll(urlTexts.keySet());
setServiceUpdateLanguages(languages);
final boolean noService = gEffect == GtfsRealtime.Alert.Effect.NO_SERVICE;
HashSet<ServiceUpdate> serviceUpdates = new HashSet<>();
long serviceUpdateMaxValidityInMs = getServiceUpdateMaxValidityInMs();
for (Map.Entry<String, String> entry : targetUUIDAndTripId.entrySet()) {
Expand All @@ -1031,6 +1033,7 @@ private HashSet<ServiceUpdate> processAlerts(
targetUUID,
targetTripId,
severity == null ? ServiceUpdate.SEVERITY_INFO_UNKNOWN : severity,
noService,
language
);
serviceUpdates.add(newServiceUpdate);
Expand Down Expand Up @@ -1100,6 +1103,7 @@ private ServiceUpdate generateNewServiceUpdate(
@NonNull String targetUUID,
@Nullable String targetTripId,
int severity,
boolean noService,
String language
) {
final String header = headerTexts.get(language);
Expand All @@ -1123,6 +1127,7 @@ private ServiceUpdate generateNewServiceUpdate(
ServiceUpdateCleaner.makeText(header, description),
ServiceUpdateCleaner.makeTextHTML(header, textHtml, url),
severity,
noService,
AGENCY_SOURCE_ID,
sourceLabel,
feedEntityId,
Expand Down Expand Up @@ -1600,12 +1605,10 @@ public String getLogTag() {
public static int getDbVersion(@NonNull Context context) {
if (dbVersion < 0) {
dbVersion = context.getResources().getInteger(R.integer.gtfs_real_time_db_version);
dbVersion++; // add "service_update.original_id" column
dbVersion++; // add "vehicle_location" table
dbVersion++; // add "vehicle_location.report_timestamp" column
dbVersion++; // change "vehicle_location.[bearing|speed]" unit to Int
dbVersion++; // add "service_update.trip_id" column
dbVersion++; // add "status" table
dbVersion++; // add "vehicle_location" table
dbVersion = ServiceUpdateDbHelper.bumpDBVersion(dbVersion);
dbVersion = VehicleLocationDbHelper.bumpDBVersion(dbVersion);
}
return dbVersion;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1884,6 +1884,7 @@ private void addServiceUpdates(@NonNull String targetUUID, int severity, @Nullab
)
),
severity,
null,
AGENCY_SOURCE_ID,
this.sourceLabel,
this.currentMessageId,
Expand Down Expand Up @@ -1911,6 +1912,7 @@ private void addServiceUpdates(@NonNull String targetUUID, int severity, @Nullab
)
),
severity,
null,
AGENCY_SOURCE_ID,
this.sourceLabel,
this.currentMessageId,
Expand Down Expand Up @@ -1991,9 +1993,9 @@ public String getLogTag() {
public static int getDbVersion(@NonNull Context context) {
if (dbVersion < 0) {
dbVersion = context.getResources().getInteger(R.integer.next_bus_db_version);
dbVersion++; // add "service_update.original_id" column
dbVersion++; // add "vehicle_location" table
dbVersion++; // add "service_update.trip_id" column
dbVersion = ServiceUpdateDbHelper.bumpDBVersion(dbVersion);
dbVersion = VehicleLocationDbHelper.bumpDBVersion(dbVersion);
}
return dbVersion;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1160,6 +1160,7 @@ public void endElement(String uri, String localName, String qName) throws SAXExc
text,
textHtml,
severity,
null,
AGENCY_SOURCE_ID,
this.sourceLabel,
null, // TODO original ID?
Expand All @@ -1174,6 +1175,7 @@ public void endElement(String uri, String localName, String qName) throws SAXExc
text,
textHtml,
severity,
null,
AGENCY_SOURCE_ID,
this.sourceLabel,
null, // TODO original ID?
Expand Down Expand Up @@ -1520,8 +1522,7 @@ public String getLogTag() {
public static int getDbVersion(@NonNull Context context) {
if (dbVersion < 0) {
dbVersion = context.getResources().getInteger(R.integer.oc_transpo_db_version);
dbVersion++; // add "service_update.original_id" column
dbVersion++; // add "service_update.trip_id" column
dbVersion = ServiceUpdateDbHelper.bumpDBVersion(dbVersion);
}
return dbVersion;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1296,6 +1296,7 @@ public void endElement(String uri, String localName, String qName) throws SAXExc
textSb.toString(),
textHTMLSb.toString(),
severity,
null,
AGENCY_SOURCE_ID,
sourceLabel,
null, // TODO?
Expand Down Expand Up @@ -1526,8 +1527,7 @@ public String getLogTag() {
static int getDbVersion(@NonNull Context context) {
if (dbVersion < 0) {
dbVersion = context.getResources().getInteger(R.integer.rtc_quebec_db_version);
dbVersion++; // add "service_update.original_id" column
dbVersion++; // add "service_update.trip_id" column
dbVersion = ServiceUpdateDbHelper.bumpDBVersion(dbVersion);
}
return dbVersion;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -830,6 +830,7 @@ private List<ServiceUpdate> parseAgencyJSONArrivalsServiceUpdates(
routeLink
),
severity,
null,
SERVICE_UPDATE_SOURCE_ID,
sourceLabel,
null, // no original ID
Expand Down Expand Up @@ -861,6 +862,7 @@ private List<ServiceUpdate> parseAgencyJSONArrivalsServiceUpdates(
stopLink
),
severity,
null,
SERVICE_UPDATE_SOURCE_ID,
sourceLabel,
null, // no original ID
Expand Down Expand Up @@ -1158,6 +1160,7 @@ protected List<ServiceUpdate> parseAgencyJSONMessageResults(
fText,
textHtml,
severity,
null,
SERVICE_UPDATE_SOURCE_ID,
sourceLabel,
originalId,
Expand Down Expand Up @@ -1695,8 +1698,7 @@ public String getLogTag() {
public static int getDbVersion(@NonNull Context context) {
if (dbVersion < 0) {
dbVersion = context.getResources().getInteger(R.integer.stm_info_api_db_version);
dbVersion++; // add "service_update.original_id" column
dbVersion++; // add "service_update.trip_id" column
dbVersion = ServiceUpdateDbHelper.bumpDBVersion(dbVersion);
}
return dbVersion;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -519,6 +519,7 @@ private ServiceUpdate parseAgencyJsonText(JSONObject jMetroObject, String target
jMetroDataText,
textHtml,
severity,
null,
AGENCY_SOURCE_ID,
sourceLabel,
null, // no original ID
Expand Down Expand Up @@ -922,8 +923,7 @@ public String getLogTag() {
public static int getDbVersion(@NonNull Context context) {
if (dbVersion < 0) {
dbVersion = context.getResources().getInteger(R.integer.stm_info_db_version);
dbVersion++; // add "service_update.original_id" column
dbVersion++; // add "service_update.trip_id" column
dbVersion = ServiceUpdateDbHelper.bumpDBVersion(dbVersion);
}
return dbVersion;
}
Expand Down
Loading