From 15679951bcb208d8e82f553fdf6a97170528a2d3 Mon Sep 17 00:00:00 2001 From: Patrick Hellebrand Date: Thu, 23 Sep 2021 14:54:25 +0200 Subject: [PATCH 1/3] removed ability to send empty messages --- PolyChat/MainPage.xaml.cs | 18 ++---------------- 1 file changed, 2 insertions(+), 16 deletions(-) diff --git a/PolyChat/MainPage.xaml.cs b/PolyChat/MainPage.xaml.cs index 752a608..1b6f6e2 100644 --- a/PolyChat/MainPage.xaml.cs +++ b/PolyChat/MainPage.xaml.cs @@ -213,33 +213,19 @@ namespace PolyChat private void OnKeyUp(object sender, Windows.UI.Xaml.Input.KeyRoutedEventArgs e) { updateSendButtonEnabled(); - if (e.Key == Windows.System.VirtualKey.Enter) + if (buttonSend.IsEnabled && e.Key == Windows.System.VirtualKey.Enter) { OnSendMessage(); } } - public static IAsyncOperation SafelyOpenDialog(Dialog d) + public static IAsyncOperation SafelyOpenDialog(ContentDialog d) { if(VisualTreeHelper.GetOpenPopups(Window.Current).Count == 0) return d.ShowAsync(); return null; } - public static IAsyncOperation SafelyOpenDialog(NewChatDialog d) - { - if (VisualTreeHelper.GetOpenPopups(Window.Current).Count == 0) - return d.ShowAsync(); - return null; - } - - public static IAsyncOperation SafelyOpenDialog(EditUsernameDialog d) - { - if (VisualTreeHelper.GetOpenPopups(Window.Current).Count == 0) - return d.ShowAsync(); - return null; - } - // UPDATE FUNCTIONS FOR UI PLACEHOLDERS private void updateNoChatsPlaceholder() From de2d135fdfaa80b58c78b80f2a2a4af9706d557c Mon Sep 17 00:00:00 2001 From: Patrick Hellebrand Date: Thu, 23 Sep 2021 15:31:30 +0200 Subject: [PATCH 2/3] Added Themes + Toggle --- PolyChat/MainPage.xaml | 16 +++++++--------- PolyChat/MainPage.xaml.cs | 16 +++++++++++++++- PolyChat/Views/Dialog.xaml.cs | 1 + PolyChat/Views/EditUsernameDialog.xaml.cs | 1 + PolyChat/Views/NewChatDialog.xaml.cs | 1 + 5 files changed, 25 insertions(+), 10 deletions(-) diff --git a/PolyChat/MainPage.xaml b/PolyChat/MainPage.xaml index 596ea2b..3ec2199 100644 --- a/PolyChat/MainPage.xaml +++ b/PolyChat/MainPage.xaml @@ -6,17 +6,18 @@ xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" xmlns:models="using:PolyChat.Models" mc:Ignorable="d" - Background="{ThemeResource ApplicationPageBackgroundThemeBrush}" RequestedTheme="Dark"> + Background="{ThemeResource ApplicationPageBackgroundThemeBrush}"> - + + @@ -37,7 +38,7 @@ - + @@ -55,12 +56,8 @@ - - - - - - + + diff --git a/PolyChat/MainPage.xaml.cs b/PolyChat/MainPage.xaml.cs index 1b6f6e2..d9286c2 100644 --- a/PolyChat/MainPage.xaml.cs +++ b/PolyChat/MainPage.xaml.cs @@ -26,6 +26,8 @@ namespace PolyChat private ObservableCollection Partners; private ChatPartner selectedPartner = null; private string username; + private static ElementTheme Theme = ElementTheme.Light; + public MainPage() { @@ -35,6 +37,9 @@ namespace PolyChat // ui variables ipAddress.Text = IP.GetCodeFromIP(Controller.getIP()); Partners = new ObservableCollection(); + // theming + RequestedTheme = Theme; + // updated placeholder updateNoChatsPlaceholder(); updateNoUsernamePlaceholder(); updateNoChatSelected(); @@ -181,7 +186,6 @@ namespace PolyChat }); } - private void OnDeleteChat(object sender = null, RoutedEventArgs e = null) { Controller.CloseChat(selectedPartner.Code); @@ -210,6 +214,12 @@ namespace PolyChat 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) { updateSendButtonEnabled(); @@ -226,6 +236,10 @@ namespace PolyChat return null; } + // GETTERS + + public static ElementTheme GetTheme() => Theme; + // UPDATE FUNCTIONS FOR UI PLACEHOLDERS private void updateNoChatsPlaceholder() diff --git a/PolyChat/Views/Dialog.xaml.cs b/PolyChat/Views/Dialog.xaml.cs index 331fb6f..75dd155 100644 --- a/PolyChat/Views/Dialog.xaml.cs +++ b/PolyChat/Views/Dialog.xaml.cs @@ -36,6 +36,7 @@ namespace PolyChat.Views Secondary = secondary.Action; // show MainPage.SafelyOpenDialog(this); + RequestedTheme = MainPage.GetTheme(); } private void setType(string type, string message) diff --git a/PolyChat/Views/EditUsernameDialog.xaml.cs b/PolyChat/Views/EditUsernameDialog.xaml.cs index faec438..8e44c1e 100644 --- a/PolyChat/Views/EditUsernameDialog.xaml.cs +++ b/PolyChat/Views/EditUsernameDialog.xaml.cs @@ -22,6 +22,7 @@ namespace PolyChat.Views if (initialValue == null || initialValue.Length == 0) IsSecondaryButtonEnabled = false; else input.Text = initialValue; validate(); + RequestedTheme = MainPage.GetTheme(); } public string getValue() diff --git a/PolyChat/Views/NewChatDialog.xaml.cs b/PolyChat/Views/NewChatDialog.xaml.cs index 4c888ba..a77d96f 100644 --- a/PolyChat/Views/NewChatDialog.xaml.cs +++ b/PolyChat/Views/NewChatDialog.xaml.cs @@ -20,6 +20,7 @@ namespace PolyChat.Views { this.InitializeComponent(); IsPrimaryButtonEnabled = false; + RequestedTheme = MainPage.GetTheme(); } public string getValue() From 0a1ff66e389d49e0ff826d20dfd62ed3deb6ce87 Mon Sep 17 00:00:00 2001 From: Patrick Hellebrand Date: Thu, 23 Sep 2021 16:05:20 +0200 Subject: [PATCH 3/3] Message Alignment First Try --- PolyChat/MainPage.xaml | 9 +++++---- PolyChat/MainPage.xaml.cs | 10 +++++----- PolyChat/Models/ChatMessage.cs | 26 ++++++-------------------- 3 files changed, 16 insertions(+), 29 deletions(-) diff --git a/PolyChat/MainPage.xaml b/PolyChat/MainPage.xaml index 3ec2199..1ed214d 100644 --- a/PolyChat/MainPage.xaml +++ b/PolyChat/MainPage.xaml @@ -98,10 +98,11 @@ - - - - + + + + + diff --git a/PolyChat/MainPage.xaml.cs b/PolyChat/MainPage.xaml.cs index d9286c2..77d97b7 100644 --- a/PolyChat/MainPage.xaml.cs +++ b/PolyChat/MainPage.xaml.cs @@ -28,7 +28,6 @@ namespace PolyChat private string username; private static ElementTheme Theme = ElementTheme.Light; - public MainPage() { this.InitializeComponent(); @@ -78,7 +77,7 @@ namespace PolyChat public void OnSendMessage(object sender = null, RoutedEventArgs e = null) { - selectedPartner.AddMessage(new ChatMessage(username, "message", inputSend.Text)); + selectedPartner.AddMessage(new ChatMessage(username, "message", inputSend.Text, DateTime.Now, false)); Controller.SendMessage(selectedPartner.Code, "message", inputSend.Text); // clear input inputSend.Text = ""; @@ -161,7 +160,7 @@ namespace PolyChat Partners.Insert(index, sendingPartner); break; default: - sendingPartner.AddMessage(new ChatMessage(origin, type, content, timeStamp)); + sendingPartner.AddMessage(new ChatMessage(origin, type, content, timeStamp, true)); break; } }); @@ -178,8 +177,9 @@ namespace PolyChat new ChatMessage( origin, item["type"].ToString(), - item["content"].ToString()//, - //DateTime.Parse(item["timestamp"].ToString()) + item["content"].ToString(), + DateTime.Parse(item["timestamp"].ToString()), + false // TODO: FIX !!!! ) ); } diff --git a/PolyChat/Models/ChatMessage.cs b/PolyChat/Models/ChatMessage.cs index 7428068..1f6d272 100644 --- a/PolyChat/Models/ChatMessage.cs +++ b/PolyChat/Models/ChatMessage.cs @@ -1,6 +1,7 @@ using System; using System.Diagnostics; using System.Text.Json; +using Windows.UI.Xaml; namespace PolyChat.Models { @@ -10,38 +11,23 @@ namespace PolyChat.Models public string Type; public string Content; public DateTime TimeStamp; - public readonly bool Foreign; + public HorizontalAlignment Align; + private bool Foreign; /// - /// Create own Message (directly sent) - /// - /// My IP - /// Message Type - /// Message Content (not JSON) - public ChatMessage(string origin, string type, string content) - { - Origin = origin; - TimeStamp = DateTime.Now; - Type = type; - Content = content; - // TODO - Foreign = false; - Debug.WriteLine("Created Message: " + ToString()); - } - - /// - /// Create Message loaded with timestamp + /// Create Message /// /// Origin IP /// Message Type, usually "message" /// Message Content, usually plain text /// Parsed DateTime - public ChatMessage(string origin, string type, string content, DateTime timeStamp, bool foreign = false) + public ChatMessage(string origin, string type, string content, DateTime timeStamp, bool foreign) { Origin = origin; TimeStamp = timeStamp; Type = type; Content = content; + Align = foreign ? HorizontalAlignment.Right : HorizontalAlignment.Left; Foreign = foreign; Debug.WriteLine("Created Loaded Message: " + ToString()); }