From b9571a93999306949fed3edd4b76528a572e26a0 Mon Sep 17 00:00:00 2001 From: "andreas.schildbach" Date: Mon, 6 Sep 2010 01:09:52 +0000 Subject: [PATCH] live departures for Berlin git-svn-id: https://public-transport-enabler.googlecode.com/svn/trunk@140 0924bc21-9374-b0fa-ee44-9ff1593b38f0 --- src/de/schildbach/pte/VbbProvider.java | 29 +++++++++++++++----------- 1 file changed, 17 insertions(+), 12 deletions(-) diff --git a/src/de/schildbach/pte/VbbProvider.java b/src/de/schildbach/pte/VbbProvider.java index e2135916..517c3ab8 100644 --- a/src/de/schildbach/pte/VbbProvider.java +++ b/src/de/schildbach/pte/VbbProvider.java @@ -530,9 +530,10 @@ public final class VbbProvider implements NetworkProvider + "\\s*((?:|).+?)\\s*" // , Pattern.DOTALL); private static final Pattern P_DEPARTURES_LIVE_FINE = Pattern.compile("" // - + "\\s*(.*?)[\\s\\*]*\\s*" // - + "\\s*(.*?)\\s*\\s*" // - + ".*?\\s*(.*?)\\s*.*?" // + + "\\s*(\\d{1,2}:\\d{2})\\s*" // time + + "(\\*)?\\s*\\s*" // planned + + "\\s*(.*?)\\s*\\s*" // line + + ".*?\\s*(.*?)\\s*.*?" // destination , Pattern.DOTALL); private static final Pattern P_DEPARTURES_PLAN_FINE = Pattern.compile("" // + "(\\d{1,2}:\\d{2}).*?" // time @@ -572,7 +573,6 @@ 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()) { - // time final Calendar current = new GregorianCalendar(); current.setTime(currentTime); final Calendar parsed = new GregorianCalendar(); @@ -583,20 +583,25 @@ public final class VbbProvider implements NetworkProvider 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))); + boolean isPlanned = live && mDepFine.group(2) != null; + + Date plannedTime = null; + Date predictedTime = null; + if (live && !isPlanned) + predictedTime = parsed.getTime(); + else + plannedTime = parsed.getTime(); + + final String line = normalizeLine(ParserUtils.resolveEntities(mDepFine.group(live ? 3 : 2))); - // position final String position = !live ? ParserUtils.resolveEntities(mDepFine.group(3)) : null; - // destinationId final int destinationId = !live ? Integer.parseInt(mDepFine.group(4)) : 0; - // destination - final String destination = ParserUtils.resolveEntities(mDepFine.group(live ? 3 : 5)); + final String destination = ParserUtils.resolveEntities(mDepFine.group(live ? 4 : 5)); - final Departure dep = new Departure(parsed.getTime(), line, line != null ? LINES.get(line) : null, position, destinationId, - destination); + final Departure dep = new Departure(plannedTime, predictedTime, line, line != null ? LINES.get(line) : null, position, + destinationId, destination); if (!departures.contains(dep)) departures.add(dep); }