internal void SeachStation(string p)
        {
            if (string.IsNullOrEmpty(p))
            {
                StationList.Clear();
            }
            else
            {
                p = p.ToLower();


                var stations = StationNameService.GetStations().Where(x => x.Name.ToLower().StartsWith(p)).OrderBy(x => x.Sort).Take(7);

                if (stations.Count() < 7)
                {
                    var extraStations = StationNameService.GetStations().Where(x => x.StartsWith(p)).OrderBy(x => x.Sort).Take(7 - stations.Count());

                    stations = stations.Union(extraStations);
                }

                StationList.Clear();

                foreach (var s in stations)
                {
                    StationList.Add(s);
                }
            }
        }
Example #2
0
        async void _instance_PositionChanged(Geolocator sender, PositionChangedEventArgs args)
        {
            //Console.WriteLine(e.Position.Location.Latitude.ToString("0.000"));
            //Console.WriteLine(e.Position.Location.Longitude.ToString("0.000"));

            try
            {
                var list = await Task.Run(() =>
                {
                    CurrentLocation = args.Position.Coordinate;

                    var stationList = StationNameService.GetStations();

                    //int take = TakeLimit.HasValue ? TakeLimit.Value : 2;

                    foreach (var x in stationList)
                    {
                        CalcDistance(x);
                    }
                    return(stationList.OrderBy(x => x.Distance).Take(10));
                });

                DispatcherHelper.UIDispatcher.RunAsync(Windows.UI.Core.CoreDispatcherPriority.Normal, () =>
                {
                    Stations = list;
                });
            }
            catch { }
        }
        async void watcher_PositionChanged(object sender, GeoPositionChangedEventArgs <GeoCoordinate> e)
        {
            //Console.WriteLine(e.Position.Location.Latitude.ToString("0.000"));
            //Console.WriteLine(e.Position.Location.Longitude.ToString("0.000"));

            try
            {
                var list = await Task.Run(() =>
                {
                    CurrentLocation = e.Position.Location;

                    var stationList = StationNameService.GetStations();

                    //int take = TakeLimit.HasValue ? TakeLimit.Value : 2;


                    stationList.ForEach(x => CalcDistance(x));
                    return(stationList.OrderBy(x => x.Distance).Take(10));
                });

                Deployment.Current.Dispatcher.BeginInvoke(() =>
                {
                    Stations = list;
                });
            }
            catch { }
        }
Example #4
0
        internal void InitValues(string from, string to, string via, bool keepValues, DateTime?dateTime)
        {
            Settings = SettingService.GetSettings();

            if (!keepValues && !string.IsNullOrEmpty(from))
            {
                VanStation = StationNameService.GetStationByName(from);
                if (VanStation == null)
                {
                    VanStation = StationNameService.GetStationByCode(from);
                }
            }
            else if (!keepValues)
            {
                VanStation = null;
                GetGpsStation();
            }

            if (!keepValues && !string.IsNullOrEmpty(to))
            {
                NaarStation = StationNameService.GetStationByName(to);
            }
            else if (!keepValues)
            {
                NaarStation = null;
            }

            if (!keepValues && !string.IsNullOrEmpty(via))
            {
                ViaStation = StationNameService.GetStationByName(via);
            }
            else if (!keepValues)
            {
                ViaStation = null;
            }

            if (!keepValues)
            {
                if (dateTime.HasValue)
                {
                    Date = dateTime.Value.Date;
                    Time = dateTime.Value;
                }
                else
                {
                    Date = DateTime.Now;
                    Time = DateTime.Now;
                }

                IsYearCard     = Settings.HasYearCard;
                IsHogesnelheid = Settings.UseHsl;
                IsViaVisible   = false;
            }

            StationList.Clear();
        }
        internal void LoadForPicker()
        {
            if (Stations == null)
            {
                var all = StationNameService.GetStations();

                Stations = AlphaKeyGroup <Station> .CreateGroups(
                    all,
                    (Station s) => { return(s.Name); },
                    true);
            }
        }
        /// <summary>
        /// Show favorite stations
        /// </summary>
        private void ShowFavoriteStations()
        {
            //Show favoriete en gps stations
            var list = ViewModelLocator.MainStatic.StationList;

            if (list != null)
            {
                var stationCodes = list.Select(x => x.Code.ToLower());
                var stations     = StationNameService.GetStationsByCode(stationCodes).OrderBy(x => x.Name);
                foreach (var station in stations)
                {
                    StationList.Add(station);
                }
            }
        }
        public async void Initialize(string ritId, string company, string trein, string richting, string stationCode)
        {
            PageName = trein;
            Richting = _resourceLoader.GetString("RitInfoViewModelRichting") + " " + richting;
            RitStops = new List <RitInfoStop>();

            RitStops = await DataLoader.LoadAsync(async() =>
            {
                var serviceInfo = await RitnummerService.GetRit(ritId, company, DateTime.Now);

                List <RitInfoStop> stops = null;

                if (serviceInfo.FirstOrDefault() != null)
                {
                    stops = serviceInfo.First().Stops;

                    //Fill station name for each stop
                    foreach (var stop in stops)
                    {
                        var station = StationNameService.GetStationByCode(stop.Code);
                        if (station != null)
                        {
                            stop.Station = station.Name;
                        }

                        if (stop.Code.ToLower() == stationCode.ToLower())
                        {
                            stop.IsCurrent = true;
                        }
                    }
                }

                return(stops);
            });

            if (RitStops == null || !RitStops.Any())
            {
                RitStops = null;
                DataLoader.LoadingState = LoadingState.Error;
            }

            if (RitStops != null && RitInfoAvailable != null)
            {
                RitInfoAvailable(null, null);
            }
        }
Example #8
0
        internal async Task LoadStation(string station)
        {
            //Check input
            if (string.IsNullOrEmpty(station))
            {
                return;
            }

            PageName       = station;
            CurrentStation = StationNameService.GetStationByName(station);

            //Dont continue if the station is not found
            if (CurrentStation == null)
            {
                TijdList = new ObservableCollection <Vertrektijd>();
                DataLoader.LoadingState = LoadingState.Error;
                return;
            }

            TijdList = null;


            var list = await DataLoader.LoadAsync(() => NSApiService.GetVertrektijden(this.CurrentStation.Code));

            if (list != null)
            {
                TijdList = new ObservableCollection <Vertrektijd>(list);
            }
            else
            {
                TijdList = new ObservableCollection <Vertrektijd>();
            }

            try
            {
                var mystations = await StationService.GetMyStationsAsync();

                InMyStations = mystations.Where(x => x.Code == CurrentStation.Code).Any();
            }
            catch
            {
                //This is secondary, dont crash
            }
        }
        /// <summary>
        /// Search a station
        /// </summary>
        /// <param name="p"></param>
        internal void SeachStation(string p)
        {
            if (string.IsNullOrEmpty(p))
            {
                StationList.Clear();

                ShowFavoriteStations();
            }
            else
            {
                p = p.ToLower();

                //Do a normal starts with
                var stations = StationNameService.GetStations().Where(x => x.Name.ToLower().StartsWith(p)).OrderBy(x => x.Sort).Take(8);

                if (stations.Count() < 8)
                {
                    //Search extra names codes etc
                    var extraStations = StationNameService.GetStations().Where(x => x.StartsWith(p)).OrderBy(x => x.Sort).Take(8 - stations.Count());

                    stations = stations.Union(extraStations);
                }

                //No results? Search international
                if (stations.Count() <= 2)
                {
                    //Search extra names codes etc
                    var extraStations = StationNameService.GetStations(true).Where(x => x.StartsWith(p)).OrderBy(x => x.Sort).Take(8);

                    //Remove stations already found from extraStations
                    var dubbel = extraStations.Where(x => stations.Select(s => s.Code).Contains(x.Code)).ToList();
                    extraStations = extraStations.Except(dubbel);

                    stations = stations.Union(extraStations);
                }

                StationList.Clear();

                foreach (var station in stations)
                {
                    StationList.Add(station);
                }
            }
        }
        private void PinStation(string name)
        {
            var station = StationNameService.GetStationByName(name);

            LiveTileService.CreateStation(name, station.Code);
        }
Example #11
0
        public async void Initialize(string ritId, string company, string trein, string richting, string stationCode)
        {
            PageName = trein;

            if (!string.IsNullOrEmpty(richting))
            {
                Richting = AppResources.RitInfoViewModelRichting + " " + richting;
            }

            RitStops     = new List <RitInfoStop>();
            TreinInfo    = null;
            _stationCode = stationCode;

            var ritStopsLoader = DataLoader.LoadAsync(async() =>
            {
                var serviceInfo = await RitnummerService.GetRit(ritId, company, DateTime.Now);

                List <RitInfoStop> stops = null;

                if (serviceInfo.FirstOrDefault() != null)
                {
                    stops = serviceInfo.First().Stops;

                    //Fill station name for each stop
                    foreach (var stop in stops)
                    {
                        var station = StationNameService.GetStationByCode(stop.Code);
                        if (station != null)
                        {
                            stop.Station = station.Name;
                        }

                        if (stop.Code.ToLower() == stationCode.ToLower())
                        {
                            stop.IsCurrent = true;
                            _vertrekTijd   = stop.Departure;
                        }
                    }
                }

                return(stops);
            });

            //Start loading treinfo (but dont await yet)
            var treinInfoLoader = RitnummerService.GetTreinInfo(ritId);

            RitStops = await ritStopsLoader;

            if (RitStops == null || !RitStops.Any())
            {
                RitStops = null;
                DataLoader.LoadingState = LoadingState.Error;
            }

            if (RitStops != null && RitInfoAvailable != null)
            {
                RitInfoAvailable(null, null);
            }

            try
            {
                //Optional Treinfo
                TreinInfo = await treinInfoLoader;
            }
            catch { }
        }