mirror of
https://gitlab.com/oeffi/public-transport-enabler.git
synced 2025-07-09 17:38:49 +00:00
made destinations in departures clickable
git-svn-id: https://public-transport-enabler.googlecode.com/svn/trunk@72 0924bc21-9374-b0fa-ee44-9ff1593b38f0
This commit is contained in:
parent
48dff200a1
commit
f0cffe63f7
6 changed files with 38 additions and 32 deletions
|
@ -484,7 +484,7 @@ public final class BahnProvider implements NetworkProvider
|
|||
if (ParserUtils.timeDiff(parsed.getTime(), currentTime) < -PARSER_DAY_ROLLOVER_THRESHOLD_MS)
|
||||
parsed.add(Calendar.DAY_OF_MONTH, 1);
|
||||
|
||||
return new Departure(parsed.getTime(), line, line != null ? LINES.get(line.charAt(0)) : null, destination);
|
||||
return new Departure(parsed.getTime(), line, line != null ? LINES.get(line.charAt(0)) : null, 0, destination);
|
||||
}
|
||||
|
||||
private static final Pattern P_NORMALIZE_LINE_NUMBER = Pattern.compile("\\d{2,5}");
|
||||
|
|
|
@ -27,13 +27,15 @@ public final class Departure
|
|||
final public Date time;
|
||||
final public String line;
|
||||
final public int[] lineColors;
|
||||
final public int destinationId;
|
||||
final public String destination;
|
||||
|
||||
public Departure(final Date time, final String line, final int[] lineColors, final String destination)
|
||||
public Departure(final Date time, final String line, final int[] lineColors, final int destinationId, final String destination)
|
||||
{
|
||||
this.time = time;
|
||||
this.line = line;
|
||||
this.lineColors = lineColors;
|
||||
this.destinationId = destinationId;
|
||||
this.destination = destination;
|
||||
}
|
||||
|
||||
|
@ -45,6 +47,8 @@ public final class Departure
|
|||
builder.append(",");
|
||||
builder.append(line != null ? line : "null");
|
||||
builder.append(",");
|
||||
builder.append(destinationId);
|
||||
builder.append(",");
|
||||
builder.append(destination != null ? destination : "null");
|
||||
builder.append(")");
|
||||
return builder.toString();
|
||||
|
@ -66,6 +70,8 @@ public final class Departure
|
|||
return false;
|
||||
if (this.line != null && !this.line.equals(other.line))
|
||||
return false;
|
||||
if (this.destinationId != other.destinationId)
|
||||
return false;
|
||||
if (!this.destination.equals(other.destination))
|
||||
return false;
|
||||
return true;
|
||||
|
@ -79,6 +85,8 @@ public final class Departure
|
|||
if (line != null)
|
||||
hashCode += line.hashCode();
|
||||
hashCode *= 29;
|
||||
hashCode += destinationId;
|
||||
hashCode *= 29;
|
||||
hashCode += destination.hashCode();
|
||||
return hashCode;
|
||||
}
|
||||
|
|
|
@ -522,7 +522,7 @@ public class MvvProvider implements NetworkProvider
|
|||
calendar.set(Calendar.MINUTE, Integer.parseInt(mDepFine.group(4)));
|
||||
final String normalizedLine = normalizeLine(mDepFine.group(5), mDepFine.group(6));
|
||||
final String destination = normalizeStationName(mDepFine.group(7));
|
||||
final Departure departure = new Departure(calendar.getTime(), normalizedLine, LINES.get(normalizedLine), destination);
|
||||
final Departure departure = new Departure(calendar.getTime(), normalizedLine, LINES.get(normalizedLine), 0, destination);
|
||||
departures.add(departure);
|
||||
}
|
||||
else
|
||||
|
|
|
@ -480,7 +480,7 @@ public class RmvProvider implements NetworkProvider
|
|||
if (ParserUtils.timeDiff(parsed.getTime(), currentTime) < -PARSER_DAY_ROLLOVER_THRESHOLD_MS)
|
||||
parsed.add(Calendar.DAY_OF_MONTH, 1);
|
||||
|
||||
return new Departure(parsed.getTime(), line, line != null ? LINES.get(line.charAt(0)) : null, destination);
|
||||
return new Departure(parsed.getTime(), line, line != null ? LINES.get(line.charAt(0)) : null, 0, destination);
|
||||
}
|
||||
|
||||
private static final Pattern P_NORMALIZE_LINE = Pattern.compile("([A-Za-zÄÖÜäöüß]+)[\\s-]*(.*)");
|
||||
|
|
|
@ -430,7 +430,7 @@ public class SbbProvider implements NetworkProvider
|
|||
if (ParserUtils.timeDiff(parsed.getTime(), currentTime) < -PARSER_DAY_ROLLOVER_THRESHOLD_MS)
|
||||
parsed.add(Calendar.DAY_OF_MONTH, 1);
|
||||
|
||||
return new Departure(parsed.getTime(), line, line != null ? LINES.get(line.charAt(0)) : null, destination);
|
||||
return new Departure(parsed.getTime(), line, line != null ? LINES.get(line.charAt(0)) : null, 0, destination);
|
||||
}
|
||||
|
||||
private static final Pattern P_NORMALIZE_LINE = Pattern.compile("([A-Za-zÄÖÜäöüß]+)[\\s-]*(.*)");
|
||||
|
|
|
@ -451,15 +451,15 @@ public final class VbbProvider implements NetworkProvider
|
|||
return uri.toString();
|
||||
}
|
||||
|
||||
private static final Pattern P_DEPARTURES_HEAD = Pattern.compile(".*<strong>(.*?)</strong>.*Datum:(.*?)<br />.*", Pattern.DOTALL);
|
||||
private static final Pattern P_DEPARTURES_HEAD = Pattern.compile(".*?<strong>(.*?)</strong>.*?Datum:(.*?)<br />.*", Pattern.DOTALL);
|
||||
private static final Pattern P_DEPARTURES_COARSE = Pattern.compile(
|
||||
"<tr class=\"ivu_table_bg\\d\">\\s*((?:<td class=\"ivu_table_c_dep\">|<td>).+?)\\s*</tr>", Pattern.DOTALL);
|
||||
private static final Pattern P_DEPARTURES_LIVE_FINE = Pattern.compile("<td class=\"ivu_table_c_dep\">\\s*(.*?)[\\s\\*]*</td>\\s*" //
|
||||
+ "<td class=\"ivu_table_c_line\">\\s*(.*?)\\s*</td>\\s*" //
|
||||
+ "<td>.*?<a.*?[^-]>\\s*(.*?)\\s*</a>.*?</td>", Pattern.DOTALL);
|
||||
private static final Pattern P_DEPARTURES_PLAN_FINE = Pattern.compile("<td><strong>\\s*(.*?)[\\s\\*]*</strong></td>\\s*" //
|
||||
+ "<td>\\s*<strong>\\s*(.*?)[\\s\\*]*</strong>.*?</td>\\s*" //
|
||||
+ "<td>\\s*<a.*?>\\s*(.*?)\\s*</a>\\s*</td>", Pattern.DOTALL);
|
||||
private static final Pattern P_DEPARTURES_PLAN_FINE = Pattern.compile("<td><strong>(\\d{2}:\\d{2})</strong></td>.*?" //
|
||||
+ "<strong>\\s*(.*?)[\\s\\*]*</strong>.*?" //
|
||||
+ "<a href=\"/Fahrinfo/bin/stboard\\.bin/dox/dox.*?evaId=(\\d+)&.*?>\\s*(.*?)\\s*</a>.*?", Pattern.DOTALL);
|
||||
private static final Pattern P_DEPARTURES_SERVICE_DOWN = Pattern.compile("Wartungsarbeiten");
|
||||
private static final Pattern P_DEPARTURES_URI_STATION_ID = Pattern.compile("input=(\\d+)");
|
||||
|
||||
|
@ -491,7 +491,27 @@ public final class VbbProvider implements NetworkProvider
|
|||
final Matcher mDepFine = (live ? P_DEPARTURES_LIVE_FINE : P_DEPARTURES_PLAN_FINE).matcher(mDepCoarse.group(1));
|
||||
if (mDepFine.matches())
|
||||
{
|
||||
final Departure dep = parseDeparture(mDepFine, currentTime);
|
||||
// time
|
||||
final Calendar current = new GregorianCalendar();
|
||||
current.setTime(currentTime);
|
||||
final Calendar parsed = new GregorianCalendar();
|
||||
parsed.setTime(ParserUtils.parseTime(mDepFine.group(1)));
|
||||
parsed.set(Calendar.YEAR, current.get(Calendar.YEAR));
|
||||
parsed.set(Calendar.MONTH, current.get(Calendar.MONTH));
|
||||
parsed.set(Calendar.DAY_OF_MONTH, current.get(Calendar.DAY_OF_MONTH));
|
||||
if (ParserUtils.timeDiff(parsed.getTime(), currentTime) < -PARSER_DAY_ROLLOVER_THRESHOLD_MS)
|
||||
parsed.add(Calendar.DAY_OF_MONTH, 1);
|
||||
|
||||
// line
|
||||
final String line = normalizeLine(ParserUtils.resolveEntities(mDepFine.group(2)));
|
||||
|
||||
// destinationId
|
||||
final int destinationId = !live ? Integer.parseInt(mDepFine.group(3)) : 0;
|
||||
|
||||
// destination
|
||||
final String destination = ParserUtils.resolveEntities(mDepFine.group(live ? 3 : 4));
|
||||
|
||||
final Departure dep = new Departure(parsed.getTime(), line, line != null ? LINES.get(line) : null, destinationId, destination);
|
||||
if (!departures.contains(dep))
|
||||
departures.add(dep);
|
||||
}
|
||||
|
@ -509,28 +529,6 @@ public final class VbbProvider implements NetworkProvider
|
|||
}
|
||||
}
|
||||
|
||||
private static Departure parseDeparture(final Matcher mDep, final Date currentTime)
|
||||
{
|
||||
// time
|
||||
final Calendar current = new GregorianCalendar();
|
||||
current.setTime(currentTime);
|
||||
final Calendar parsed = new GregorianCalendar();
|
||||
parsed.setTime(ParserUtils.parseTime(mDep.group(1)));
|
||||
parsed.set(Calendar.YEAR, current.get(Calendar.YEAR));
|
||||
parsed.set(Calendar.MONTH, current.get(Calendar.MONTH));
|
||||
parsed.set(Calendar.DAY_OF_MONTH, current.get(Calendar.DAY_OF_MONTH));
|
||||
if (ParserUtils.timeDiff(parsed.getTime(), currentTime) < -PARSER_DAY_ROLLOVER_THRESHOLD_MS)
|
||||
parsed.add(Calendar.DAY_OF_MONTH, 1);
|
||||
|
||||
// line
|
||||
final String line = normalizeLine(ParserUtils.resolveEntities(mDep.group(2)));
|
||||
|
||||
// destination
|
||||
final String destination = ParserUtils.resolveEntities(mDep.group(3));
|
||||
|
||||
return new Departure(parsed.getTime(), line, line != null ? LINES.get(line) : null, destination);
|
||||
}
|
||||
|
||||
private static final Date parseDate(String str)
|
||||
{
|
||||
try
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue