Example #1
0
        protected override void OnElementChanged(ElementChangedEventArgs <Page> e)
        {
            base.OnElementChanged(e);

            // this is a ViewGroup - so should be able to load an AXML file and FindView<>
            var activity = this.Context as Activity;

            var auth = new MixRadioAuth(ApiKeys.ClientId,
                                        ApiKeys.ClientSecret,
                                        ApiKeys.OAuthScope.ToString(), // this is ignored and replaced in the MixRadioAuth class
                                        new Uri(ApiKeys.OAuthAuthorizeUrl),
                                        new Uri(ApiKeys.OAuthRedirectUrl),
                                        new Uri(ApiKeys.OAuthTokenUrl));

            auth.Title = "Sign in to MixRadio";

            auth.Completed += async(sender, eventArgs) =>
            {
                // We presented the UI, so it's up to us to dimiss it on iOS.
                if (eventArgs.IsAuthenticated)
                {
                    var app = (App.Current as App);
                    await app.ActivityViewModel.LoadXamarinAuthTokenDetails(eventArgs.Account.Properties);

                    // Xamarin Forms doesn't seem to fire OnAppearing consistantly
                    // on iOS and Android currently (1.3.1)
                    // - so this kicks off the initial fetch of data for us...
                    app.ActivityViewModel.StartPolling();
                }
                else
                {
                    // The user cancelled
                }

                await(App.Current as App).MainPage.Navigation.PopModalAsync();
            };

            activity.StartActivity(auth.GetUI(activity));
        }
Example #2
0
        protected override void OnElementChanged(ElementChangedEventArgs<Page> e)
        {
            base.OnElementChanged(e);

            // this is a ViewGroup - so should be able to load an AXML file and FindView<>
            var activity = this.Context as Activity;

            var auth = new MixRadioAuth(ApiKeys.ClientId,
                ApiKeys.ClientSecret,
                ApiKeys.OAuthScope.ToString(), // this is ignored and replaced in the MixRadioAuth class
                new Uri(ApiKeys.OAuthAuthorizeUrl),
                new Uri(ApiKeys.OAuthRedirectUrl),
                new Uri(ApiKeys.OAuthTokenUrl));

            auth.Title = "Sign in to MixRadio";

            auth.Completed += async (sender, eventArgs) =>
            {
                // We presented the UI, so it's up to us to dimiss it on iOS.
                if (eventArgs.IsAuthenticated)
                {
                    var app = (App.Current as App);
                    await app.ActivityViewModel.LoadXamarinAuthTokenDetails(eventArgs.Account.Properties);

                    // Xamarin Forms doesn't seem to fire OnAppearing consistantly
                    // on iOS and Android currently (1.3.1)
                    // - so this kicks off the initial fetch of data for us...
                    app.ActivityViewModel.StartPolling();
                }
                else
                {
                    // The user cancelled
                }

                await (App.Current as App).MainPage.Navigation.PopModalAsync();
            };

            activity.StartActivity(auth.GetUI(activity));
        }
Example #3
0
		public override void ViewDidAppear (bool animated)
		{
			base.ViewDidAppear (animated);

			// Fixed the issue that on iOS 8, the modal wouldn't be popped.
			// url : http://stackoverflow.com/questions/24105390/how-to-login-to-facebook-in-xamarin-forms
			if(	! IsShown ) {

				IsShown = true;

				var auth = new MixRadioAuth (ApiKeys.ClientId,
					ApiKeys.ClientSecret,
					ApiKeys.OAuthScope.ToString(), // this is ignored and replaced in the MixRadioAuth class
					new Uri (ApiKeys.OAuthAuthorizeUrl),
					new Uri (ApiKeys.OAuthRedirectUrl),
					new Uri (ApiKeys.OAuthTokenUrl));

				auth.Title = "Sign in to MixRadio";

				auth.Completed += async (sender, eventArgs) => {
					// We presented the UI, so it's up to us to dimiss it on iOS.
					if (eventArgs.IsAuthenticated) {
						await (App.Current as App).ActivityViewModel.LoadXamarinAuthTokenDetails(eventArgs.Account.Properties);

					} else {
						// The user cancelled
					}

					await (App.Current as App).MainPage.Navigation.PopModalAsync();
				};

				PresentViewController (auth.GetUI (), true, null);

			}

		}