Added Themes + Toggle

This commit is contained in:
Patrick Hellebrand
2021-09-23 15:31:30 +02:00
committed by Felix Hartmann (PEA3-Fe-FI)
parent 4c0413e7d8
commit 5c4b4373d6
5 changed files with 25 additions and 10 deletions

View File

@@ -6,17 +6,18 @@
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:models="using:PolyChat.Models" xmlns:models="using:PolyChat.Models"
mc:Ignorable="d" mc:Ignorable="d"
Background="{ThemeResource ApplicationPageBackgroundThemeBrush}" RequestedTheme="Dark"> Background="{ThemeResource ApplicationPageBackgroundThemeBrush}">
<Grid> <Grid>
<Grid.ColumnDefinitions> <Grid.ColumnDefinitions>
<ColumnDefinition Width="224"/> <ColumnDefinition Width="224"/>
<ColumnDefinition Width="*"/> <ColumnDefinition Width="*"/>
</Grid.ColumnDefinitions> </Grid.ColumnDefinitions>
<!-- LEFT SIDE --> <!-- LEFT SIDE -->
<Grid Grid.Column="0" Margin="16"> <Grid Grid.Column="0" Padding="16" Background="{ThemeResource SystemChromeMediumColor}">
<Grid.RowDefinitions> <Grid.RowDefinitions>
<RowDefinition Height="Auto"/> <RowDefinition Height="Auto"/>
<RowDefinition Height="*"/> <RowDefinition Height="*"/>
<RowDefinition Height="Auto"/>
</Grid.RowDefinitions> </Grid.RowDefinitions>
<!-- CONNECTION HEADER --> <!-- CONNECTION HEADER -->
<StackPanel HorizontalAlignment="Stretch" Spacing="8" Margin="0 0 0 8"> <StackPanel HorizontalAlignment="Stretch" Spacing="8" Margin="0 0 0 8">
@@ -37,7 +38,7 @@
<TextBlock Text="Connect to" Foreground="{ThemeResource SystemColorDisabledTextColor}"/> <TextBlock Text="Connect to" Foreground="{ThemeResource SystemColorDisabledTextColor}"/>
<TextBlock x:Name="ipAddress" Grid.Column="1"/> <TextBlock x:Name="ipAddress" Grid.Column="1"/>
</Grid> </Grid>
<Border BorderThickness="1" BorderBrush="{ThemeResource AppBarBorderThemeBrush}"/> <Border BorderThickness="1" BorderBrush="{ThemeResource SystemControlBackgroundListLowBrush}"/>
<Grid HorizontalAlignment="Stretch" VerticalAlignment="Center"> <Grid HorizontalAlignment="Stretch" VerticalAlignment="Center">
<Grid.ColumnDefinitions> <Grid.ColumnDefinitions>
<ColumnDefinition Width="*"/> <ColumnDefinition Width="*"/>
@@ -55,12 +56,8 @@
<DataTemplate x:DataType="models:ChatPartner"> <DataTemplate x:DataType="models:ChatPartner">
<RadioButton GroupName="chatSelect" Tag="{x:Bind Code}" HorizontalAlignment="Stretch" Height="64" Click="OnChatPartnerSelected"> <RadioButton GroupName="chatSelect" Tag="{x:Bind Code}" HorizontalAlignment="Stretch" Height="64" Click="OnChatPartnerSelected">
<StackPanel x:Name="ChatPartner" VerticalAlignment="Center" HorizontalAlignment="Stretch"> <StackPanel x:Name="ChatPartner" VerticalAlignment="Center" HorizontalAlignment="Stretch">
<StackPanel Orientation="Horizontal" HorizontalAlignment="Stretch"> <TextBlock HorizontalAlignment="Stretch" Text="{x:Bind Name}"/>
<TextBlock HorizontalAlignment="Stretch" Text="{x:Bind Name}"/> <TextBlock Foreground="{ThemeResource SystemColorDisabledTextColor}" Text="{x:Bind Code}"/>
<TextBlock Foreground="{ThemeResource SystemColorDisabledTextColor}" Text=" ("/>
<TextBlock Foreground="{ThemeResource SystemColorDisabledTextColor}" Text="{x:Bind Code}"/>
<TextBlock Foreground="{ThemeResource SystemColorDisabledTextColor}" Text=")"/>
</StackPanel>
<!-- <!--
<StackPanel Orientation="Horizontal" HorizontalAlignment="Stretch"> <StackPanel Orientation="Horizontal" HorizontalAlignment="Stretch">
<TextBlock HorizontalAlignment="Stretch" Text="{x:Bind Messages.Last().toString()}"/> <TextBlock HorizontalAlignment="Stretch" Text="{x:Bind Messages.Last().toString()}"/>
@@ -73,6 +70,7 @@
</ListView.ItemTemplate> </ListView.ItemTemplate>
</ListView> </ListView>
</ScrollViewer> </ScrollViewer>
<Button Grid.Row="2" Click="OnToggleTheme" Content="Toggle Theme"/>
</Grid> </Grid>
<TextBlock x:Name="textNoChatSelected" Grid.Column="1" Text="No Chat Selected" Foreground="{ThemeResource SystemColorDisabledTextColor}" FontSize="24" VerticalAlignment="Center" HorizontalAlignment="Center"/> <TextBlock x:Name="textNoChatSelected" Grid.Column="1" Text="No Chat Selected" Foreground="{ThemeResource SystemColorDisabledTextColor}" FontSize="24" VerticalAlignment="Center" HorizontalAlignment="Center"/>
<!-- RIGHT SIDE --> <!-- RIGHT SIDE -->

View File

@@ -26,6 +26,8 @@ namespace PolyChat
private ObservableCollection<ChatPartner> Partners; private ObservableCollection<ChatPartner> Partners;
private ChatPartner selectedPartner = null; private ChatPartner selectedPartner = null;
private string username; private string username;
private static ElementTheme Theme = ElementTheme.Light;
public MainPage() public MainPage()
{ {
@@ -35,6 +37,9 @@ namespace PolyChat
// ui variables // ui variables
ipAddress.Text = IP.GetCodeFromIP(Controller.getIP()); ipAddress.Text = IP.GetCodeFromIP(Controller.getIP());
Partners = new ObservableCollection<ChatPartner>(); Partners = new ObservableCollection<ChatPartner>();
// theming
RequestedTheme = Theme;
// updated placeholder
updateNoChatsPlaceholder(); updateNoChatsPlaceholder();
updateNoUsernamePlaceholder(); updateNoUsernamePlaceholder();
updateNoChatSelected(); updateNoChatSelected();
@@ -185,7 +190,6 @@ namespace PolyChat
}); });
} }
private void OnDeleteChat(object sender = null, RoutedEventArgs e = null) private void OnDeleteChat(object sender = null, RoutedEventArgs e = null)
{ {
Controller.CloseChat(selectedPartner.Code); Controller.CloseChat(selectedPartner.Code);
@@ -214,6 +218,12 @@ namespace PolyChat
if (!Controller.IsConnected(code)) Controller.Connect(code); if (!Controller.IsConnected(code)) Controller.Connect(code);
} }
public void OnToggleTheme(object sender, RoutedEventArgs e)
{
Theme = Theme == ElementTheme.Light ? ElementTheme.Dark : ElementTheme.Light;
RequestedTheme = Theme;
}
private void OnKeyUp(object sender, Windows.UI.Xaml.Input.KeyRoutedEventArgs e) private void OnKeyUp(object sender, Windows.UI.Xaml.Input.KeyRoutedEventArgs e)
{ {
updateSendButtonEnabled(); updateSendButtonEnabled();
@@ -230,6 +240,10 @@ namespace PolyChat
return null; return null;
} }
// GETTERS
public static ElementTheme GetTheme() => Theme;
// UPDATE FUNCTIONS FOR UI PLACEHOLDERS // UPDATE FUNCTIONS FOR UI PLACEHOLDERS
private void updateNoChatsPlaceholder() private void updateNoChatsPlaceholder()

View File

@@ -36,6 +36,7 @@ namespace PolyChat.Views
Secondary = secondary.Action; Secondary = secondary.Action;
// show // show
MainPage.SafelyOpenDialog(this); MainPage.SafelyOpenDialog(this);
RequestedTheme = MainPage.GetTheme();
} }
private void setType(string type, string message) private void setType(string type, string message)

View File

@@ -22,6 +22,7 @@ namespace PolyChat.Views
if (initialValue == null || initialValue.Length == 0) IsSecondaryButtonEnabled = false; if (initialValue == null || initialValue.Length == 0) IsSecondaryButtonEnabled = false;
else input.Text = initialValue; else input.Text = initialValue;
validate(); validate();
RequestedTheme = MainPage.GetTheme();
} }
public string getValue() public string getValue()

View File

@@ -20,6 +20,7 @@ namespace PolyChat.Views
{ {
this.InitializeComponent(); this.InitializeComponent();
IsPrimaryButtonEnabled = false; IsPrimaryButtonEnabled = false;
RequestedTheme = MainPage.GetTheme();
} }
public string getValue() public string getValue()