private async void CheckAlertTiming() { while (true) { // check each stop and each svc that are enabled // incl public bus foreach (string busStopCode in enabledStops) { foreach (string routeName in enabledSvcs) { var stop = BusHelper.BusStops [busStopCode]; if (stop.services.Union(stop.publicServices).Contains(routeName)) { // get arrival timing of svc in stop and display alert if below alert minutes var arrivalTimingStr = (stop.services.Contains(routeName)) ? BusHelper.GetArrivalTiming(busStopCode, routeName) : await BusHelper.GetPublicBusesArrivalTiming(busStopCode, routeName); var nextTimingStr = Regex.Match(arrivalTimingStr, @"\d+").Value; if (!nextTimingStr.Equals(String.Empty)) { var nextTiming = Int32.Parse(nextTimingStr); if (nextTiming == 0) { await DisplayAlert("Bus Alert", routeName + " is arriving " + stop.name + "!", "OK", "Cancel"); } else if (nextTiming <= SettingsVars.Variables ["ALERT_MINUTES"].value) { await DisplayAlert("Bus Alert", routeName + " is arriving " + stop.name + " at " + nextTiming + " min.", "OK", "Cancel"); } } else if (arrivalTimingStr.Contains("Arr")) { await DisplayAlert("Bus Alert", routeName + " is arriving " + stop.name + "!", "OK", "Cancel"); } } } } // continue after interval await Task.Delay(TimeSpan.FromSeconds(SettingsVars.Variables ["REFRESH_ALERT_INTERVAL"].value)); } }
private async void UpdateStopPins() { while (true) { // skip update pins if map is freezed (user clicks on pin) if (!FreezeMap) { // remove all stop pins foreach (CustomPin p in map.StopPins) { map.Pins.Remove(p.Pin); } map.StopPins.Clear(); // add stop pins, with change in arrival timing foreach (BusStop busStop in BusHelper.BusStops.Values) { var description = ""; foreach (string svc in busStop.services) { // handle repeated service in bus stop case // show timing for both directions if (busStop.repeatedServices != null && busStop.repeatedServices.Contains(svc)) { description += svc + "(to " + BusHelper.BusStops [BusHelper.BusSvcs [svc].loopStop].name + "): "; description += BusHelper.GetArrivalTiming(busStop.busStopCode, svc, "BEFORE") + "\n"; description += svc + "(to " + BusHelper.BusStops [BusHelper.BusSvcs [svc].lastStop].name + "): "; description += BusHelper.GetArrivalTiming(busStop.busStopCode, svc, "AFTER") + "\n"; } else { description += svc + ": " + BusHelper.GetArrivalTiming(busStop.busStopCode, svc) + "\n"; } } // get public bus arrival timing for bus stop (if public buses pass by) // busStopCode with all digits -> public bus will pass by if (BusHelper.IsPublic(busStop.busStopCode)) { description += await BusHelper.GetPublicBusesArrivalTiming(busStop.busStopCode); } var pin = new Pin { Type = PinType.Place, Position = new Xamarin.Forms.Maps.Position(busStop.latitude, busStop.longitude), Label = busStop.name + " - " + busStop.busStopCode, Address = description }; var stop = new CustomPin { Pin = pin, Id = "stop", Url = "stop.png" }; map.Pins.Add(pin); map.StopPins.Add(stop); } } // continue after interval await Task.Delay(TimeSpan.FromSeconds(SettingsVars.Variables ["REFRESH_STOP_INTERVAL"].value)); } }