예제 #1
0
        // Declare the top level nav items

        /// <summary>
        ///     Initializes a new instance of the AppShell, sets the static 'Current' reference,
        ///     adds callbacks for Back requests and changes in the SplitView's DisplayMode, and
        ///     provide the nav menu list with the data to display.
        /// </summary>
        public AppShell()
        {
            InitializeComponent();

            Loading += async(sender, args) =>
            {
                // StatusBar is Mobile only
                if (Windows.Foundation.Metadata.ApiInformation.IsTypePresent("Windows.UI.ViewManagement.StatusBar"))
                {
                    await Windows.UI.ViewManagement.StatusBar.GetForCurrentView().HideAsync();
                }
            };

            Loaded += async(sender, args) =>
            {
                Current = this;

                //TogglePaneButton.Focus(FocusState.Programmatic);
                NavMenuList.SelectedIndex = 0;
                var dm = DataModelServiceFactory.CurrentDataModelService();

#if SQLITE
                var trips = await dm.LoadTripsAsync();

                if (AppSettings.HasRun && trips.Any())
                {
                    // Load trips from DB
                    foreach (var trip in trips)
                    {
                        AddTrip(trip.Name, trip.Id);
                    }
                    var parameter = new TripNavigationParameter {
                        TripId = trips.First().Id
                    }.GetJson();
                    NavigateToPage(typeof(TripDetailPage), parameter);
                    LandingPage.Visibility = Visibility.Collapsed;
                }
                else
                {
                    LandingPage.ShowCreateFirstTrip = true;
                }
#else
                // When connecting to Azure, this is where we authenticate and then load the seed data into the local tables.
                // Then sync to the cloud
                bool isAuthenticated = false;
                while (!isAuthenticated)
                {
                    var authResponse = await dm.AuthenticateAsync();

                    isAuthenticated = authResponse.Item1;
                    if (!isAuthenticated)
                    {
                        var dialog = new MessageDialog(authResponse.Item2);
                        dialog.Commands.Add(new UICommand("OK"));
                        await dialog.ShowAsync();
                    }
                }

                await SetBusyAsync("Synchronising");

                var trips = await dm.LoadTripsAsync();
                await ClearBusyAsync();

                if (trips.Any())
                {
                    AppSettings.HasRun = true;

                    // Load trips from DB
                    foreach (var trip in trips)
                    {
                        AddTrip(trip.Name, trip.Id);
                    }
                    var parameter = new TripNavigationParameter {
                        TripId = trips.First().Id
                    }.GetJson();
                    NavigateToPage(typeof(TripDetailPage), parameter);
                    LandingPage.Visibility = Visibility.Collapsed;
                }
                else
                {
                    LandingPage.ShowCreateFirstTrip = true;
                }
#endif
            };

            RootSplitView.RegisterPropertyChangedCallback(
                SplitView.DisplayModeProperty,
                (s, a) =>
            {
                // Ensure that we update the reported size of the TogglePaneButton when the SplitView's
                // DisplayMode changes.
                CheckTogglePaneButtonSizeChanged();
            });

            SystemNavigationManager.GetForCurrentView().BackRequested += SystemNavigationManager_BackRequested;
            PopupManager.Configure(this, ParentedPopup, HitBlocker);
        }