Merged PR 15265: Upddate Windows GraphNotificationsSample UI to match other platforms

Kept Accounts and Notifications pages, removed Logs page for parity
This commit is contained in:
Sudipta Dey (WDG) 2019-04-23 00:01:09 +00:00
Родитель 88c453c3b4
Коммит b59308d9e7
9 изменённых файлов: 91 добавлений и 170 удалений

Просмотреть файл

@ -31,8 +31,8 @@
<TextBlock Name="Description" Style="{StaticResource ScenarioDescriptionTextStyle}" TextWrapping="Wrap">
Please login with MSA or AAD account
</TextBlock>
<Button x:Name="AadButton" Content="Login with AAD" Margin="0,10,0,0" Click="Button_LoginAAD"/>
<Button x:Name="MsaButton" Content="Login with MSA" Margin="0,10,0,0" Click="Button_LoginMSA"/>
<Button x:Name="AadButton" Content="Login with AAD" Margin="0,10,0,0" Click="Button_LoginAAD"/>
</StackPanel>
<!-- Status Block for providing messages to the user. Use the

Просмотреть файл

@ -15,10 +15,18 @@ using Windows.UI.Xaml.Navigation;
namespace SDKTemplate
{
enum LoginState
{
LOGGED_IN_MSA,
LOGGED_IN_AAD,
LOGGED_OUT
}
public sealed partial class AccountsPage : Page
{
private MainPage rootPage;
private ConnectedDevicesManager connectedDevicesManager;
private MainPage m_rootPage;
private ConnectedDevicesManager m_connectedDevicesManager;
private LoginState m_state;
public AccountsPage()
{
@ -27,52 +35,102 @@ namespace SDKTemplate
protected override void OnNavigatedTo(NavigationEventArgs e)
{
rootPage = MainPage.Current;
connectedDevicesManager = ((App)Application.Current).ConnectedDevicesManager;
connectedDevicesManager.AccountsChanged += ConnectedDevicesManager_AccountsChanged;
UpdateUI();
m_rootPage = MainPage.Current;
m_connectedDevicesManager = ((App)Application.Current).ConnectedDevicesManager;
m_connectedDevicesManager.AccountsChanged += ConnectedDevicesManager_AccountsChanged;
UpdateView(GetCurrentLoginState());
}
private void ConnectedDevicesManager_AccountsChanged(object sender, System.EventArgs e)
{
UpdateUI();
}
private void UpdateUI()
{
// The ConnectedDevices SDK does not support multi-user currently. When this support becomes available
// these buttons would always be enabled.
bool hasAccount = connectedDevicesManager.Accounts.Count > 0;
MsaButton.IsEnabled = !hasAccount;
AadButton.IsEnabled = !hasAccount;
UpdateView(GetCurrentLoginState());
}
private async void Button_LoginMSA(object sender, RoutedEventArgs e)
{
bool success = await connectedDevicesManager.SignInMsaAsync();
if (m_state == LoginState.LOGGED_OUT)
{
bool success = await m_connectedDevicesManager.SignInMsaAsync();
if (!success)
{
rootPage.NotifyUser("MSA login failed!", NotifyType.ErrorMessage);
m_rootPage.NotifyUser("MSA login failed!", NotifyType.ErrorMessage);
}
else
{
rootPage.NotifyUser("MSA login successful", NotifyType.StatusMessage);
m_rootPage.NotifyUser("MSA login successful", NotifyType.StatusMessage);
UpdateView(LoginState.LOGGED_IN_MSA);
}
}
else
{
LogoutCurrentAccount();
}
}
private async void Button_LoginAAD(object sender, RoutedEventArgs e)
{
((Button)sender).IsEnabled = false;
bool success = await connectedDevicesManager.SignInAadAsync();
if (m_state == LoginState.LOGGED_OUT)
{
bool success = await m_connectedDevicesManager.SignInAadAsync();
if (!success)
{
rootPage.NotifyUser("AAD login failed!", NotifyType.ErrorMessage);
m_rootPage.NotifyUser("AAD login failed!", NotifyType.ErrorMessage);
}
else
{
rootPage.NotifyUser("AAD login successful", NotifyType.StatusMessage);
m_rootPage.NotifyUser("AAD login successful", NotifyType.StatusMessage);
UpdateView(LoginState.LOGGED_IN_AAD);
}
}
else
{
LogoutCurrentAccount();
}
}
private async void LogoutCurrentAccount()
{
UpdateView(LoginState.LOGGED_OUT);
var account = m_connectedDevicesManager.Accounts[0];
await m_connectedDevicesManager.LogoutAsync(account);
m_rootPage.NotifyUser("Logged out", NotifyType.ErrorMessage);
}
LoginState GetCurrentLoginState()
{
LoginState currentState = LoginState.LOGGED_OUT;
if (m_connectedDevicesManager.Accounts.Count > 0)
{
currentState = m_connectedDevicesManager.Accounts[0].Type == Microsoft.ConnectedDevices.ConnectedDevicesAccountType.AAD ? LoginState.LOGGED_IN_AAD : LoginState.LOGGED_IN_MSA;
}
return currentState;
}
void UpdateView(LoginState state)
{
m_state = state;
switch (state)
{
case LoginState.LOGGED_OUT:
AadButton.IsEnabled = true;
AadButton.Content = "Login with AAD";
MsaButton.IsEnabled = true;
MsaButton.Content = "Login with MSA";
break;
case LoginState.LOGGED_IN_AAD:
MsaButton.IsEnabled = false;
AadButton.Content = "Logout - AAD";
break;
case LoginState.LOGGED_IN_MSA:
AadButton.IsEnabled = false;
MsaButton.Content = "Logout - MSA";
break;
}
}
}
}

Просмотреть файл

@ -98,9 +98,6 @@
</PropertyGroup>
<ItemGroup>
<Compile Include="Properties\AssemblyInfo.cs" />
<Compile Include="LogsPage.xaml.cs">
<DependentUpon>LogsPage.xaml</DependentUpon>
</Compile>
<Compile Include="ConnectedDevicesManager.cs" />
<Compile Include="Logger.cs" />
<Compile Include="NotificationsPage.xaml.cs">
@ -130,10 +127,6 @@
<Generator>MSBuild:Compile</Generator>
<SubType>Designer</SubType>
</ApplicationDefinition>
<Page Include="LogsPage.xaml">
<Generator>MSBuild:Compile</Generator>
<SubType>Designer</SubType>
</Page>
<Page Include="MainPage.xaml">
<Generator>MSBuild:Compile</Generator>
<SubType>Designer</SubType>

Просмотреть файл

@ -1,51 +0,0 @@
<!--
//*********************************************************
//
// Copyright (c) Microsoft. All rights reserved.
// This code is licensed under the Microsoft Public License.
// THIS CODE IS PROVIDED *AS IS* WITHOUT WARRANTY OF
// ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING ANY
// IMPLIED WARRANTIES OF FITNESS FOR A PARTICULAR
// PURPOSE, MERCHANTABILITY, OR NON-INFRINGEMENT.
//
//*********************************************************
-->
<Page
x:Class="SDKTemplate.LogsPage"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:local="using:SDKTemplate"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
mc:Ignorable="d">
<Grid Background="{ThemeResource ApplicationPageBackgroundThemeBrush}">
<Grid Background="{ThemeResource ApplicationPageBackgroundThemeBrush}" Margin="12,20,12,12">
<Grid.RowDefinitions>
<RowDefinition Height="Auto"/>
<RowDefinition Height="Auto"/>
<RowDefinition Height="*"/>
<RowDefinition Height="Auto"/>
</Grid.RowDefinitions>
<StackPanel HorizontalAlignment="Left" VerticalAlignment="Top">
<TextBlock Name="Description" Style="{StaticResource ScenarioDescriptionTextStyle}" TextWrapping="Wrap">
Please login with MSA or AAD account
</TextBlock>
</StackPanel>
<StackPanel Grid.Row="1" Orientation="Horizontal" Margin="10">
<Button Content="Clear" Margin="10" BorderBrush="AntiqueWhite" Click="Button_Clear"/>
</StackPanel>
<ScrollViewer Grid.Row="2" VerticalScrollMode="Auto" VerticalScrollBarVisibility="Auto">
<Border BorderBrush="AntiqueWhite" BorderThickness="2" Margin="20,0,0,0" >
<TextBox x:Name="LogView" Foreground="Red" AcceptsReturn="True" IsReadOnly="True" TextWrapping="Wrap"/>
</Border>
</ScrollViewer>
<!-- Status Block for providing messages to the user. Use the
NotifyUser() method to populate the message -->
<TextBlock x:Name="StatusBlock" Grid.Row="3" Margin="12, 10, 12, 10" Visibility="Collapsed"/>
</Grid>
</Grid>
</Page>

Просмотреть файл

@ -1,64 +0,0 @@
//*********************************************************
//
// Copyright (c) Microsoft. All rights reserved.
// This code is licensed under the Microsoft Public License.
// THIS CODE IS PROVIDED *AS IS* WITHOUT WARRANTY OF
// ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING ANY
// IMPLIED WARRANTIES OF FITNESS FOR A PARTICULAR
// PURPOSE, MERCHANTABILITY, OR NON-INFRINGEMENT.
//
//*********************************************************
using System;
using Windows.UI.Core;
using Windows.UI.Xaml;
using Windows.UI.Xaml.Controls;
using Windows.UI.Xaml.Navigation;
namespace SDKTemplate
{
public sealed partial class LogsPage : Page
{
private MainPage rootPage;
public LogsPage()
{
this.InitializeComponent();
}
protected override void OnNavigatedTo(NavigationEventArgs e)
{
rootPage = MainPage.Current;
var connectedDevicesManager = ((App)Application.Current).ConnectedDevicesManager;
if (connectedDevicesManager.Accounts.Count > 0)
{
var account = connectedDevicesManager.Accounts[0];
Description.Text = $"{account.Type} user ";
}
LogView.Text = Logger.Instance.AppLogs;
Logger.Instance.LogUpdated += LogsUpdated;
}
protected override void OnNavigatedFrom(NavigationEventArgs e)
{
Logger.Instance.LogUpdated -= LogsUpdated;
}
private async void LogsUpdated(object sender, string message)
{
await Dispatcher.RunAsync(CoreDispatcherPriority.Normal, () =>
{
LogView.Text = message + Environment.NewLine + LogView.Text;
});
}
private void Button_Clear(object sender, RoutedEventArgs e)
{
LogView.Text = string.Empty;
Logger.Instance.AppLogs = string.Empty;
rootPage.NotifyUser("Logs cleared", NotifyType.ErrorMessage);
}
}
}

Просмотреть файл

@ -59,14 +59,9 @@ namespace SDKTemplate
// Populate the scenario list from the SampleConfiguration.cs file
ScenarioControl.ItemsSource = scenarios;
if (Window.Current.Bounds.Width < 640)
{
ScenarioControl.SelectedIndex = -1;
}
else
{
ScenarioControl.SelectedIndex = 0;
}
// Go to NotificationsPage if launched from Toast
ScenarioControl.SelectedIndex = string.IsNullOrEmpty(e.Parameter as string) ? 0 : 1;
}
private void RegisterBackgroundTask()

Просмотреть файл

@ -37,8 +37,7 @@
</StackPanel>
<StackPanel Grid.Row="1" Orientation="Horizontal" Margin="10">
<Button Name="RefreshButton" Content="Retrieve Notifications History" Margin="10" BorderBrush="AntiqueWhite" Click="Button_Refresh"/>
<Button x:Name="LogoutButton" Content="Logout" BorderBrush="AntiqueWhite" Click="Button_Logout" HorizontalAlignment="Center" VerticalAlignment="Center"/>
<Button Name="RefreshButton" Content="Refresh" Margin="10" BorderBrush="AntiqueWhite" Click="Button_Refresh"/>
</StackPanel>
<Grid Grid.Row="2">

Просмотреть файл

@ -85,7 +85,6 @@ namespace SDKTemplate
}
RefreshButton.IsEnabled = (m_userNotificationManager != null);
LogoutButton.IsEnabled = (m_account != null);
if (m_account != null)
{
Description.Text = $"{m_account.Type} user ";
@ -148,13 +147,6 @@ namespace SDKTemplate
await m_userNotificationManager.RefreshAsync();
}
private async void Button_Logout(object sender, RoutedEventArgs e)
{
rootPage.NotifyUser("Logged out", NotifyType.ErrorMessage);
await ((App)Application.Current).ConnectedDevicesManager.LogoutAsync(m_account);
await RefreshAsync();
}
private async void Button_MarkRead(object sender, RoutedEventArgs e)
{
var item = ((Grid)((Border)((Button)sender).Parent).Parent).DataContext as NotificationListItem;

Просмотреть файл

@ -27,9 +27,8 @@ namespace SDKTemplate
List<Scenario> scenarios = new List<Scenario>
{
new Scenario() { Title="Login/Logout", ClassType=typeof(AccountsPage)},
new Scenario() { Title="Notification History", ClassType=typeof(NotificationsPage)},
new Scenario() { Title="App Logs", ClassType=typeof(LogsPage)},
new Scenario() { Title="Accounts", ClassType=typeof(AccountsPage)},
new Scenario() { Title="Notifications", ClassType=typeof(NotificationsPage)},
};
}