示例#1
0
        /// <summary>
        /// Begins the listening for messages, and signals from the signal app
        /// </summary>
        public void StartListening()
        {
            SubscribeGeneralMessage(Gestures.UP);
            SubscribeGeneralMessage(Gestures.DOWN);
            SubscribeGeneralMessage(Gestures.LEFT);
            SubscribeGeneralMessage(Gestures.RIGHT);
            IMusicManager musicManager = new SpotifyManager();

            actionHandler.RegisterMusicManager(musicManager);
            MessagingCenter.Subscribe <SettingsViewModel>(this, Gestures.SPOTIFY, async message =>
            {
                if (!actionHandler.HasAuthenticatedMusicManager)
                {
                    MessagingCenter.Subscribe <SpotifyLoginMessage>(this, "LoginSuccess", message =>
                    {
                        if (!actionHandler.HasAuthenticatedMusicManager)
                        {
                            actionHandler.UpdateMusicManagerAuthentication(true);
                            MessagingCenter.Send(new SpotifyLoginMessage("RegistrationSuccess", message.HasPremium), "RegistrationSuccess");
                        }
                    });
                    await musicManager.Init();
                }
            });
            MessagingCenter.Subscribe <DNDPermissionMessage>(this, "DNDAdded", message =>
            {
                if (!notificationManager.IsNotificationPolicyAccessGranted)
                {
                    Intent intent = new Intent(Android.Provider.Settings.ActionNotificationPolicyAccessSettings);
                    StartActivity(intent);
                }
                else
                {
                    MessagingCenter.Send(new DNDPermissionMessage(), "DNDGranted");
                }
            });

            MessagingCenter.Subscribe <string>(this, "GPSRoute", async message =>
            {
                GPSManager gpsManager = new GPSManager();
                GPSHandler handler    = new GPSHandler();
                GPSSetting setting    = await handler.GetSetting();
                Rootobject root       = await gpsManager.GetDirectionsAsync(setting.Destination, setting.Mode);
                if (root.status.Equals("NOT_FOUND"))
                {
                    MessagingCenter.Send <string>("", "Unsuccessful");
                    return;
                }
                MessagingCenter.Send <string, Rootobject>("", "GetRoute", root);
            });
        }