예제 #1
0
        /// <summary>
        ///     This is the main class for this app. This function is the first function
        ///     called and it setups the app analytic (If in release mode), components,
        ///     requested theme and event handlers.
        /// </summary>
        public App()
        {
            // Init XAML Resources
            InitializeComponent();

            // We want to use the controler if on xbox
            if (DeviceHelper.IsXbox)
            {
                RequiresPointerMode = ApplicationRequiresPointerMode.WhenRequested;
            }

            // Check that we are not using the default theme,
            // if not change the requested theme to the users
            // picked theme.
            if (!SettingsService.Instance.IsDefaultTheme)
            {
                RequestedTheme = SettingsService.Instance.ThemeType;
            }

            // Registor the dialogs
            NavigationService.Current.RegisterTypeAsDialog <CrashDialog>();
            NavigationService.Current.RegisterTypeAsDialog <FilterDialog>();
            NavigationService.Current.RegisterTypeAsDialog <PendingUpdateDialog>();
            NavigationService.Current.RegisterTypeAsDialog <PinTileDialog>();
            NavigationService.Current.RegisterTypeAsDialog <PlaylistDialog>();
            NavigationService.Current.RegisterTypeAsDialog <ShareDialog>();

            // Init Keys
            ApiKeyService.Init();

            // Handle App Crashes
            CrashHelper.HandleAppCrashes(Current);

            // Enter and Leaving background handlers
            EnteredBackground += AppEnteredBackground;
            LeavingBackground += AppLeavingBackground;

            // During the transition from foreground to background the
            // memory limit allowed for the application changes. The application
            // has a short time to respond by bringing its memory usage
            // under the new limit.
            MemoryManager.AppMemoryUsageLimitChanging += MemoryManager_AppMemoryUsageLimitChanging;

            // After an application is backgrounded it is expected to stay
            // under a memory target to maintain priority to keep running.
            // Subscribe to the event that informs the app of this change.
            MemoryManager.AppMemoryUsageIncreased += MemoryManager_AppMemoryUsageIncreased;
        }
예제 #2
0
        public App()
        {
            // Initialize XAML Resources
            InitializeComponent();

            // Check that we are not using the default theme,
            // if not change the requested theme to the users
            // picked theme.
            if (!SettingsService.Instance.IsDefaultTheme)
            {
                RequestedTheme = SettingsService.Instance.ThemeType;
            }

            // We want to use the controller if on xbox
            if (DeviceHelper.IsXbox)
            {
                RequiresPointerMode = ApplicationRequiresPointerMode.WhenRequested;
            }

            try
            {
                // Handle application crashes
                CrashHelper.HandleAppCrashes(this);
            }
            catch { }

            // Register Event Handlers
            EnteredBackground += AppEnteredBackground;
            LeavingBackground += AppLeavingBackground;
            Suspending        += AppSuspending;

            // Used Reveal Focus on 1803+
            if (ApiInformation.IsEnumNamedValuePresent("Windows.UI.Xaml.FocusVisualKind", nameof(FocusVisualKind.Reveal)))
            {
                FocusVisualKind = FocusVisualKind.Reveal;
            }

            // During the transition from foreground to background the
            // memory limit allowed for the application changes. The application
            // has a short time to respond by bringing its memory usage
            // under the new limit.
            MemoryManager.AppMemoryUsageLimitChanging += MemoryManager_AppMemoryUsageLimitChanging;

            // After an application is backgrounded it is expected to stay
            // under a memory target to maintain priority to keep running.
            // Subscribe to the event that informs the app of this change.
            MemoryManager.AppMemoryUsageIncreased += MemoryManager_AppMemoryUsageIncreased;

            // Run this code when a service is connected to SoundByte
            SoundByteService.Current.OnServiceConnected += (type, token) =>
            {
                var vault = new PasswordVault();

                // Add the password to the vault so we can access it when restarting the app
                string vaultName;
                switch (type)
                {
                case ServiceTypes.SoundCloud:
                case ServiceTypes.SoundCloudV2:
                    vaultName = "SoundByte.SoundCloud";
                    break;

                case ServiceTypes.YouTube:
                    vaultName = "SoundByte.YouTube";
                    break;

                case ServiceTypes.SoundByte:
                    vaultName = "SoundByte.SoundByteV2";
                    break;

                default:
                    vaultName = string.Empty;
                    break;
                }

                if (string.IsNullOrEmpty(vaultName))
                {
                    return;
                }

                vault.Add(new PasswordCredential(vaultName, "Token", token.AccessToken));
                vault.Add(new PasswordCredential(vaultName, "RefreshToken", string.IsNullOrEmpty(token.RefreshToken) ? "n/a" : token.RefreshToken));
                vault.Add(new PasswordCredential(vaultName, "ExpireTime", string.IsNullOrEmpty(token.ExpireTime) ? "n/a" : token.ExpireTime));

                // Track the connect event
                SimpleIoc.Default.GetInstance <ITelemetryService>().TrackEvent("Service Connected",
                                                                               new Dictionary <string, string>
                {
                    { "Service", type.ToString() }
                });
            };

            // Run this code when a service is disconnected from SoundByte
            SoundByteService.Current.OnServiceDisconnected += async(type, reason) =>
            {
                // Delete the vault depending on the service type
                switch (type)
                {
                case ServiceTypes.SoundCloud:
                case ServiceTypes.SoundCloudV2:
                    SettingsService.Instance.DeleteAllFromVault("SoundByte.SoundCloud");
                    break;

                case ServiceTypes.YouTube:
                    SettingsService.Instance.DeleteAllFromVault("SoundByte.YouTube");
                    break;

                case ServiceTypes.SoundByte:
                    SettingsService.Instance.DeleteAllFromVault("SoundByte.SoundByteV2");
                    break;
                }

                // Track the disconnect event
                SimpleIoc.Default.GetInstance <ITelemetryService>().TrackEvent("Service Disconnected",
                                                                               new Dictionary <string, string>
                {
                    { "Service", type.ToString() },
                    { "Reason", reason }
                });

                // Attempt to log the user back in
                if (!string.IsNullOrEmpty(reason))
                {
                    // Navigate to the login page
                    NavigateTo(typeof(AccountView), new AccountView.AccountViewParams
                    {
                        Service = type,
                    });

                    // Tell the user what happened
                    await NavigationService.Current.CallMessageDialogAsync("One of your accounts has been logged out. SoundByte will now redirect you to the login page.", "Account disconnected");
                }
            };
        }
예제 #3
0
        /// <summary>
        ///     This is the main class for this app. This function is the first function
        ///     called and it setups the app analytic (If in release mode), components,
        ///     requested theme and event handlers.
        /// </summary>
        public App()
        {
            LoggingService.Log(LoggingService.LogType.Debug, "----- App Started -----");

            // Init XAML Resources
            InitializeComponent();

            LoggingService.Log(LoggingService.LogType.Debug, "Loaded XAML");

            // We want to use the controler if on xbox
            if (DeviceHelper.IsXbox)
            {
                RequiresPointerMode = ApplicationRequiresPointerMode.WhenRequested;
            }

            // Check that we are not using the default theme,
            // if not change the requested theme to the users
            // picked theme.
            if (!SettingsService.Instance.IsDefaultTheme)
            {
                RequestedTheme = SettingsService.Instance.ThemeType;
            }

            // Register the dialogs
            NavigationService.Current.RegisterTypeAsDialog <CrashDialog>();
            NavigationService.Current.RegisterTypeAsDialog <PendingUpdateDialog>();
            NavigationService.Current.RegisterTypeAsDialog <PinTileDialog>();
            NavigationService.Current.RegisterTypeAsDialog <PlaylistDialog>();
            NavigationService.Current.RegisterTypeAsDialog <ShareDialog>();
            NavigationService.Current.RegisterTypeAsDialog <LoginDialog>();

            // Live tile helpers
            TileHelper.Init();

            // Init service
            InitV3Service();

            // Handle App Crashes
            CrashHelper.HandleAppCrashes(Current);

            // Enter and Leaving background handlers
            EnteredBackground += AppEnteredBackground;
            LeavingBackground += AppLeavingBackground;

            // During the transition from foreground to background the
            // memory limit allowed for the application changes. The application
            // has a short time to respond by bringing its memory usage
            // under the new limit.
            MemoryManager.AppMemoryUsageLimitChanging += MemoryManager_AppMemoryUsageLimitChanging;

            // After an application is backgrounded it is expected to stay
            // under a memory target to maintain priority to keep running.
            // Subscribe to the event that informs the app of this change.
            MemoryManager.AppMemoryUsageIncreased += MemoryManager_AppMemoryUsageIncreased;

            // Run this code when a service is connected to SoundByte
            SoundByteV3Service.Current.OnServiceConnected += (type, token) =>
            {
                var vault = new PasswordVault();

                // Add the password to the vault so we can access it when restarting the app
                switch (type)
                {
                case ServiceType.SoundCloud:
                case ServiceType.SoundCloudV2:
                    vault.Add(new PasswordCredential("SoundByte.SoundCloud", "Token", token.AccessToken));
                    vault.Add(new PasswordCredential("SoundByte.SoundCloud", "Scope", token.Scope));
                    break;

                case ServiceType.Fanburst:
                    vault.Add(new PasswordCredential("SoundByte.FanBurst", "Token", token.AccessToken));
                    break;

                case ServiceType.YouTube:
                    vault.Add(new PasswordCredential("SoundByte.YouTube", "Token", token.AccessToken));
                    break;
                }

                // Track the connect event
                TelemetryService.Instance.TrackEvent("Service Connected",
                                                     new Dictionary <string, string>
                {
                    { "Service", type.ToString() }
                });

                // Navigate home if we connected SoundCloud, else navigate to explore
                NavigateTo(type == ServiceType.SoundCloud ? typeof(SoundCloudStreamView) : typeof(ExploreView));

                // Update the UI depending if we are logged in or not
                if (SoundByteV3Service.Current.IsServiceConnected(ServiceType.SoundCloud) ||
                    SoundByteV3Service.Current.IsServiceConnected(ServiceType.YouTube) ||
                    SoundByteV3Service.Current.IsServiceConnected(ServiceType.Fanburst))
                {
                    Shell.ShowLoginContent();
                }
                else
                {
                    Shell.ShowLogoutContent();
                }
            };

            // Run this code when a service is disconencted from SoundByte
            SoundByteV3Service.Current.OnServiceDisconnected += type =>
            {
                // Get the password vault
                var vault = new PasswordVault();

                // Delte the vault depending on the service type
                switch (type)
                {
                case ServiceType.SoundCloud:
                case ServiceType.SoundCloudV2:
                    vault.FindAllByResource("SoundByte.SoundCloud").ForEach(x => vault.Remove(x));
                    break;

                case ServiceType.Fanburst:
                    vault.FindAllByResource("SoundByte.FanBurst").ForEach(x => vault.Remove(x));
                    break;

                case ServiceType.YouTube:
                    vault.FindAllByResource("SoundByte.YouTube").ForEach(x => vault.Remove(x));
                    break;
                }

                // Track the disconnect event
                TelemetryService.Instance.TrackEvent("Service Disconnected",
                                                     new Dictionary <string, string>
                {
                    { "Service", type.ToString() }
                });

                // Navigate to the explore view
                NavigateTo(typeof(ExploreView));

                // Update the UI depending if we are logged in or not
                if (SoundByteV3Service.Current.IsServiceConnected(ServiceType.SoundCloud) ||
                    SoundByteV3Service.Current.IsServiceConnected(ServiceType.YouTube) ||
                    SoundByteV3Service.Current.IsServiceConnected(ServiceType.Fanburst))
                {
                    Shell.ShowLoginContent();
                }
                else
                {
                    Shell.ShowLogoutContent();
                }
            };
        }