private static Task <OAuthProvider> SelectProviderFromList()
        {
            _awaiter.Reset();
            OAuthProvider provider           = null;
            var           selectionViewModel = new ProviderSelectionViewModel(_providers);

            selectionViewModel.ProviderSelected += (s, e) =>
            {
                provider = e.Provider;
                _awaiter.Set();
            };

            Device.BeginInvokeOnMainThread(() =>
                                           Application.Current.MainPage = new ProviderSelectionPage(selectionViewModel));
            _awaiter.WaitOne();
            _awaiter.Reset();

            return(Task.FromResult(provider));
        }
Ejemplo n.º 2
0
        public ProviderSelectionPage(ProviderSelectionViewModel viewModel)
            : base()
        {
            BindingContext = _viewModel = viewModel;
            var grid = new Grid();

            var label = new Label
            {
                Text              = OAuthAuthenticator.ProviderSelectText,
                VerticalOptions   = LayoutOptions.Center,
                HorizontalOptions = LayoutOptions.Center
            };
            var fontSize = Device.GetNamedSize(NamedSize.Large, label);

            grid.Children.Add(new Button
            {
                Text    = OAuthAuthenticator.BackButtonText,
                Command = viewModel.Cancel
            });

            grid.RowDefinitions.Add(new RowDefinition {
                Height = GridLength.Auto
            });
            grid.RowDefinitions.Add(new RowDefinition {
                Height = new GridLength(fontSize * 2)
            });
            grid.RowDefinitions.Add(new RowDefinition());

            Grid.SetRow(label, 1);
            label.FontSize = fontSize;

            grid.Children.Add(label);

            var providerStack = new StackLayout
            {
                VerticalOptions   = LayoutOptions.Center,
                HorizontalOptions = LayoutOptions.Center,
                Spacing           = fontSize
            };

            foreach (var provider in viewModel.Providers)
            {
                var button = new ProviderButton
                {
                    Command = BuildSelectionHandler()
                };
                button.SetBinding(ProviderButton.TextProperty, OAuthProvider.NameProperty, BindingMode.OneWay);
                button.SetBinding(ProviderButton.ImageProperty, OAuthProvider.LogoProperty, BindingMode.OneWay);
                providerStack.Children.Add(button);
                button.BindingContext = provider;
            }

            var scrollView = new ScrollView
            {
                Content = providerStack
            };

            Grid.SetRow(scrollView, 2);
            grid.Children.Add(scrollView);

            Padding = fontSize;
            Content = grid;
        }