Ejemplo n.º 1
0
        void MainPage_Loaded(object sender, RoutedEventArgs e)
        {
            if (firstLoad == true)
            {
                // Since this is the first load, pull down the bus and stop info
                viewModel.LoadInfoForLocation();

                // In this case, we've been re-created after a tombstone, resume their previous pivot
                if (PhoneApplicationService.Current.State.ContainsKey("MainPageSelectedPivot") == true)
                {
                    PC.SelectedIndex = (int)(MainPagePivots)PhoneApplicationService.Current.State["MainPageSelectedPivot"];
                }
                // The app was started fresh, not from tombstone.  Check pivot settings.  If there isn't a setting,
                // default to the last used pivot
                else if (IsolatedStorageSettings.ApplicationSettings.Contains("DefaultMainPagePivot") == true &&
                         (MainPagePivots)IsolatedStorageSettings.ApplicationSettings["DefaultMainPagePivot"] >= 0)
                {
                    PC.SelectedIndex = (int)(MainPagePivots)IsolatedStorageSettings.ApplicationSettings["DefaultMainPagePivot"];
                }
                else
                {
                    // Is is set to use the previous pivot, if this key doesn't exist just leave
                    // the pivot selection at the default
                    if (IsolatedStorageSettings.ApplicationSettings.Contains("LastUsedMainPagePivot") == true)
                    {
                        PC.SelectedIndex = (int)(MainPagePivots)IsolatedStorageSettings.ApplicationSettings["LastUsedMainPagePivot"];
                    }
                }
            }
            firstLoad = false;

            // Load favorites every time because they might have changed since the last load
            viewModel.LoadFavorites();

            viewModel.CheckForLocalTransitData(delegate(bool hasData)
            {
                Dispatcher.BeginInvoke(() =>
                {
                    if (hasData == false)
                    {
                        MessageBox.Show(
                            "Currently the OneBusAway service does not support your location." +
                            "Many functions of this app will not work."
                            );
                    }
                });
            });

            viewModel.LocationTracker.RunWhenLocationKnown(delegate(GeoCoordinate location)
            {
                Dispatcher.BeginInvoke(() => StopsMap.Center = location);
            }
                                                           );

            HideLoadingSplash();
        }