Ejemplo n.º 1
0
        protected override async void OnActivated(IActivatedEventArgs args)
        {
            SetupShell(args);

            // we need to wait for the shell to load
            while (AppShell.Current == null)
            {
                await Task.Delay(200);
            }



            switch (args.Kind)
            {
            case ActivationKind.Protocol:
                ProtocolActivatedEventArgs           protocolArgs = args as ProtocolActivatedEventArgs;
                Windows.Foundation.WwwFormUrlDecoder decoder      = new Windows.Foundation.WwwFormUrlDecoder(protocolArgs.Uri.Query);
                var siteId = decoder.GetFirstValueByName("LaunchContext");
                var parameter = new TripNavigationParameter {
                    TripId = AppSettings.LastTripId, SightId = Guid.ParseExact(siteId, "D")
                }.GetJson();
                AppShell.Current.NavigateToPage(typeof(TripDetailPage), parameter);
                break;

            // Insert the M2_VoiceActivation snippet here

            case ActivationKind.VoiceCommand:
                VoiceCommandActivatedEventArgs voiceArgs = args as VoiceCommandActivatedEventArgs;
                HandleVoiceCommand(args);
                break;

            // Insert the M2_ToastActivation snippet here

            case ActivationKind.ToastNotification:
                var toast = args as ToastNotificationActivatedEventArgs;

                var props = toast.Argument.Split(':');
                if (props[0] == "View")
                {
                    var tripParam = new TripNavigationParameter {
                        TripId = AppSettings.LastTripId, SightId = Guid.ParseExact(props[1], "D")
                    }.GetJson();
                    AppShell.Current.NavigateToPage(typeof(TripDetailPage), tripParam);
                }
                else if (props[0] == "Remove")
                {
                    var tripParam = new TripNavigationParameter {
                        TripId = AppSettings.LastTripId, SightId = Guid.ParseExact(props[1], "D"), DeleteSight = true
                    }.GetJson();
                    AppShell.Current.NavigateToPage(typeof(TripDetailPage), tripParam);
                }
                break;

            default:
                break;
            }

            // Ensure the current window is active
            Window.Current.Activate();
        }
Ejemplo n.º 2
0
        protected override async void OnActivated(IActivatedEventArgs args)
        {
            SetupShell(args);

            // we need to wait for the shell to load
            while (AppShell.Current == null)
            {
                await Task.Delay(200);
            }



            switch (args.Kind)
            {
            case ActivationKind.Protocol:
                ProtocolActivatedEventArgs           protocolArgs = args as ProtocolActivatedEventArgs;
                Windows.Foundation.WwwFormUrlDecoder decoder      = new Windows.Foundation.WwwFormUrlDecoder(protocolArgs.Uri.Query);
                var siteId = decoder.GetFirstValueByName("LaunchContext");
                var parameter = new TripNavigationParameter {
                    TripId = AppSettings.LastTripId, SightId = Guid.ParseExact(siteId, "D")
                }.GetJson();
                AppShell.Current.NavigateToPage(typeof(TripDetailPage), parameter);
                break;

            default:
                break;
            }

            // Ensure the current window is active
            Window.Current.Activate();
        }
        protected override async void OnNavigatedTo(NavigationEventArgs e)
        {
            await AppShell.Current.SetBusyAsync("Loading Trip");

            if (e.Parameter != null)
            {
                var parameter = TripNavigationParameter.CreateFromJson(e.Parameter as string);
                if (e.NavigationMode == NavigationMode.Back)
                {
                    await ViewModel.LoadTripAsync(parameter.TripId, false);
                }
                else
                {
                    await ViewModel.LoadTripAsync(parameter.TripId);
                }

                if (parameter.DisplayClosestSight)
                {
                    await ViewModel.DisplayClosestSightAsync();
                }

                if (parameter.SightId != Guid.Empty)
                {
                    if (parameter.DeleteSight)
                    {
                        var task = ViewModel.ConfirmDeleteSightAsync(parameter.SightId);
                    }
                    else
                    {
                        ViewModel.ShowSight(parameter.SightId);
                    }
                }

                if (!string.IsNullOrEmpty(parameter.CuisinePreferences))
                {
                    ViewModel.SetEatsByCuisine(parameter.CuisinePreferences);
                }

                // Set the current Pivot
                switch (parameter.ShowPivotName)
                {
                case TripPivots.Sights:
                    LayoutPanel.SelectedIndex = 0;
                    break;

                case TripPivots.Eats:
                    LayoutPanel.SelectedIndex = 1;
                    break;

                default:
                    throw new ArgumentOutOfRangeException("parameter.ShowPivotName has an unexpected value");
                }
            }
            await AppShell.Current.ClearBusyAsync();

            base.OnNavigatedTo(e);
        }
Ejemplo n.º 4
0
        public async void CreateTrip()
        {
#if !SQLITE
            await AppShell.Current.SetBusyAsync("Synchronising");

            await SeedDataFactory.LoadDataAsync();

            await AppShell.Current.ClearBusyAsync();
#endif

            // NOTE: SeedDatafactory sets AppSettings.LastTripId to the trip Id value generated from the Seed Data
            AppShell.Current.AddTrip("San Francisco", AppSettings.LastTripId);
            AppSettings.HasRun = true;

            // the following will launch directly to the detail view of the closest sight
            //var parameter = new TripNavigationParameter { TripId = AppSettings.LastTripId, DisplayClosestSight = true }.GetJson();
            var parameter = new TripNavigationParameter {
                TripId = AppSettings.LastTripId
            }.GetJson();
            AppShell.Current.NavigateToPage(typeof(TripDetailPage), parameter);
            AppShell.Current.Frame?.BackStack.Clear();
        }
Ejemplo n.º 5
0
        // Insert the M2_HandleVoiceCommand snippet here

        private void HandleVoiceCommand(IActivatedEventArgs args)
        {
            var commandArgs             = args as VoiceCommandActivatedEventArgs;
            var speechRecognitionResult = commandArgs.Result;
            var command = speechRecognitionResult.Text;

            var voiceCommandName = speechRecognitionResult.RulePath[0];
            var textSpoken       = speechRecognitionResult.Text;

            Debug.WriteLine("Command: " + command);
            Debug.WriteLine("Text spoken: " + textSpoken);

            string parameter;

            switch (voiceCommandName)
            {
            case "LaunchApp":
                parameter = new TripNavigationParameter {
                    TripId = AppSettings.LastTripId
                }.GetJson();
                AppShell.Current.NavigateToPage(typeof(TripDetailPage), parameter);

                break;

            // Insert the M2_NearbyCase snippet here

            case "NearbySights":
                parameter = new TripNavigationParameter {
                    TripId = AppSettings.LastTripId
                }.GetJson();
                AppShell.Current.NavigateToPage(typeof(TripDetailPage), parameter);

                break;

            default:
                break;
            }
        }
Ejemplo n.º 6
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);
        }
Ejemplo n.º 7
0
        protected override async void OnActivated(IActivatedEventArgs args)
        {
            SetupShell(args);

            // we need to wait for the shell to load
            while (AppShell.Current == null)
            {
                await Task.Delay(200);
            }



            switch (args.Kind)
            {
            case ActivationKind.Protocol:
                ProtocolActivatedEventArgs protocolArgs = args as ProtocolActivatedEventArgs;

                // Is this a protocol launch from Cortana actions, or from voice command?
                if (protocolArgs.Uri.Scheme == "sights2see")
                {
                    Windows.Foundation.WwwFormUrlDecoder decoder = new Windows.Foundation.WwwFormUrlDecoder(protocolArgs.Uri.Query);
                    var foodpref = decoder.GetFirstValueByName("foodpref");
                    var parameter = new TripNavigationParameter {
                        TripId = AppSettings.LastTripId, ShowPivotName = TripPivots.Eats, CuisinePreferences = foodpref
                    }.GetJson();
                    AppShell.Current.NavigateToPage(typeof(TripDetailPage), parameter);
                }
                else
                {
                    Windows.Foundation.WwwFormUrlDecoder decoder = new Windows.Foundation.WwwFormUrlDecoder(protocolArgs.Uri.Query);
                    var siteId = decoder.GetFirstValueByName("LaunchContext");
                    var parameter = new TripNavigationParameter {
                        TripId = AppSettings.LastTripId, SightId = Guid.ParseExact(siteId, "D")
                    }.GetJson();
                    AppShell.Current.NavigateToPage(typeof(TripDetailPage), parameter);
                }
                break;

            // Voice activation behavior
            case ActivationKind.VoiceCommand:
                VoiceCommandActivatedEventArgs voiceArgs = args as VoiceCommandActivatedEventArgs;
                HandleVoiceCommand(args);
                break;

            case ActivationKind.ToastNotification:
                var toast = args as ToastNotificationActivatedEventArgs;

                var props = toast.Argument.Split(':');
                if (props[0] == "View")
                {
                    var tripParam = new TripNavigationParameter {
                        TripId = AppSettings.LastTripId, SightId = Guid.ParseExact(props[1], "D")
                    }.GetJson();
                    AppShell.Current.NavigateToPage(typeof(TripDetailPage), tripParam);
                }
                else if (props[0] == "Remove")
                {
                    var tripParam = new TripNavigationParameter {
                        TripId = AppSettings.LastTripId, SightId = Guid.ParseExact(props[1], "D"), DeleteSight = true
                    }.GetJson();
                    AppShell.Current.NavigateToPage(typeof(TripDetailPage), tripParam);
                }
                break;

            default:
                break;
            }

            // Ensure the current window is active
            Window.Current.Activate();
        }