Пример #1
0
        public StopResultVM(BusRoute br)
        {
            Context = br;
            Title = Context.Title;
            //this.Title = "stop results";
            //HeaderTitle = "bus alarm - " + Context.Title;
            HeaderTitle = "stop results";
            //this.HeaderTitle = "bus alarm";
            Stops = new ObservableCollection<BusStop>();

            StopResultVM.CurrentInstance = this;
        }
Пример #2
0
        public StopResultVM(BusRoute br)
        {
            Context = br;
            Title   = Context.Title;
            //this.Title = "stop results";
            //HeaderTitle = "bus alarm - " + Context.Title;
            HeaderTitle = "stop results";
            //this.HeaderTitle = "bus alarm";
            Stops = new ObservableCollection <BusStop>();

            StopResultVM.CurrentInstance = this;
        }
Пример #3
0
        /// <summary>
        /// Finds the nearest matching route
        /// </summary>
        /// <param name="routeName">Name of route</param>
        /// <returns></returns>
        private static async Task <BusRoute> GetNearestMatchingRoute(string routeName)
        {
            BusRoute retRoute = null;

            if (RouteIDs.ContainsKey(routeName))
            {
                if (RouteIDs[routeName].Count == 0)
                {
                    return(null);
                }
                if (RouteIDs[routeName].Count == 1)
                {
                    if (!AppSettings.KnownRoutes.Value.ContainsKey(RouteIDs[routeName][0]))
                    {
                        return(null);
                    }
                    retRoute = await TransitLoader.GetRoute(RouteIDs[routeName][0]);

                    return(retRoute);
                }

                double minDist = double.PositiveInfinity;
                foreach (string id in RouteIDs[routeName])
                {
                    if (!AppSettings.KnownRoutes.Value.ContainsKey(id))
                    {
                        return(retRoute);
                    }
                    var br = AppSettings.KnownRoutes.Value[id];
                    if (br.Stop_Ids == null || br.Stop_Ids.Count == 0)
                    {
                        return(retRoute);
                    }

                    BusStop firststop = await TransitLoader.GetStop(br.Stop_Ids[0]);

                    if (firststop == null)
                    {
                        continue;
                    }
                    var dist = MyLocation.GetDistanceTo(firststop.Location);
                    if (minDist > dist)
                    {
                        retRoute = br;
                        minDist  = dist;
                    }
                }
                return(retRoute);
            }
            return(null);
        }
Пример #4
0
        protected override async void OnNavigatedTo(NavigationEventArgs e)
        {
            base.OnNavigatedTo(e);

            // Update current dispatcher
            Util.CurrentDispatcher = this.Dispatcher;

            if (this.startup)
            {
                // Initialize progress bar
                this.InitializeProgress();

                // Setup ViewModel
                string route_id;
                string route_name;
                if (this.NavigationContext.QueryString.TryGetValue("route_id", out route_id))
                {
                    this.ViewModel = new StopResultVM(AppSettings.KnownRoutes.Value[route_id]);
                    await InitializeFromViewModel();
                }
                else if (this.NavigationContext.QueryString.TryGetValue(VoiceHelper.RouteNumPhraseList, out route_name))
                {
                    ProgressIndicatorHelper.Instance.Push(LoadingEnum.Routes);
                    BusRoute br = await TransitInfo.SearchForRoute(route_name);

                    ProgressIndicatorHelper.Instance.Remove(LoadingEnum.Routes);
                    if (LocationTracker.GetPermission())
                    {
                        LocationTracker.RetrieveLocation();
                    }
                    if (br != null)
                    {
                        this.ViewModel = new StopResultVM(br);
                        await InitializeFromViewModel();
                    }
                    else
                    {
                        MessageBox.Show(string.Format("Could not find route {0}.", route_name),
                                        "No matches", MessageBoxButton.OK);
                    }
                }
            }
        }
Пример #5
0
        /// <summary>
        /// Download route if necessary
        /// </summary>
        /// <param name="id"></param>
        /// <returns></returns>
        public static async Task <BusRoute> GetRoute(string id)
        {
            if (AppSettings.KnownRoutes.Value.ContainsKey(id))
            {
                return(AppSettings.KnownRoutes.Value[id]);
            }
            else
            {
                try
                {
                    var response = await DownloadString(rStop(id).ToUri());

                    BusRoute retval = JsonConvert.DeserializeObject <BusRoute>(response);
                    AppSettings.KnownRoutes.Value[id] = retval;
                    AppSettings.KnownRoutes.Save();
                    return(retval);
                }
                catch { return(null); }
            }
        }
Пример #6
0
        /// <summary>
        /// Search the text in the route box
        /// </summary>
        /// <returns></returns>
        private async Task SearchRoutes()
        {
            this.Focus();

            // Blank route
            if (this.RouteSearchBox.Text == EmptyTextBox ||
                string.IsNullOrWhiteSpace(this.RouteSearchBox.Text))
            {
                MessageBox.Show("Please enter the number of a bus route in your area.",
                                "No input", MessageBoxButton.OK);
                return;
            }

            ProgressIndicatorHelper.Instance.Push(LoadingEnum.Routes);
            BusRoute br = await TransitInfo.SearchForRoute(this.RouteSearchBox.Text);

            if (br == null && !AppSettings.LocationConsent.Value && LocationTracker.GetPermission())
            {
                br = await TransitInfo.SearchForRoute(this.RouteSearchBox.Text);
            }
            ProgressIndicatorHelper.Instance.Remove(LoadingEnum.Routes);
            if (br == null)
            {
                TransitLoader.InternetAvailable();
                MessageBox.Show(string.Format("Could not find route {0}.", this.RouteSearchBox.Text),
                                "No matches", MessageBoxButton.OK);
                return;
            }

            this.RouteSearchBox.Text = "";
            if (this.SpacingPanel.Height == spacerMaxHeight)
            {
                this.SetSearchBarVisibility(Visibility.Collapsed);
            }
            NavigationService.Navigate(new Uri(
                                           string.Format("/Pages/StopResultPage.xaml?route_id={0}", br.Id),
                                           UriKind.Relative));
            //NavigationService.Navigate(new Uri("/Pages/StopResultPage.xaml", UriKind.Relative));
        }
Пример #7
0
        /// <summary>
        /// Search for route within known routes.
        /// If not found, load up nearby transit info and search again.
        /// TODO: If there is a known far away stop, this will fail.
        /// </summary>
        /// <param name="routeName"></param>
        /// <returns></returns>
        public static async Task <BusRoute> SearchForRoute(string routeName)
        {
            BusRoute result = null;

            result = await GetNearestMatchingRoute(routeName);

            if (result != null)
            {
                return(result);
            }

            if (MyLocation != null)
            {
                await TransitLoader.GetTransitNetwork(TransitInfo.MyLocation);
            }

            //RefreshRouteIDs();
            await RefreshRouteIDsAsync();

            result = await GetNearestMatchingRoute(routeName);

            return(result);
        }