diff --git a/PolyChat/MainPage.xaml b/PolyChat/MainPage.xaml index 596ea2b..1ed214d 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 @@ - - - - - - + + @@ -100,10 +98,11 @@ - - - - + + + + + diff --git a/PolyChat/MainPage.xaml.cs b/PolyChat/MainPage.xaml.cs index 452e752..2e976d2 100644 --- a/PolyChat/MainPage.xaml.cs +++ b/PolyChat/MainPage.xaml.cs @@ -26,7 +26,8 @@ namespace PolyChat private ObservableCollection Partners; private ChatPartner selectedPartner = null; private string username; - + private static ElementTheme Theme = ElementTheme.Light; + public MainPage() { this.InitializeComponent(); @@ -35,6 +36,9 @@ namespace PolyChat // ui variables ipAddress.Text = IP.GetCodeFromIP(Controller.getIP()); Partners = new ObservableCollection(); + // theming + RequestedTheme = Theme; + // updated placeholder updateNoChatsPlaceholder(); updateNoUsernamePlaceholder(); updateNoChatSelected(); @@ -74,7 +78,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 = ""; @@ -159,7 +163,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; } }); @@ -176,15 +180,15 @@ 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 !!!! ) ); } }); } - private void OnDeleteChat(object sender = null, RoutedEventArgs e = null) { Controller.CloseChat(selectedPartner.Code,delete: true); @@ -213,35 +217,31 @@ 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(); - 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; - } + // GETTERS - public static IAsyncOperation SafelyOpenDialog(EditUsernameDialog d) - { - if (VisualTreeHelper.GetOpenPopups(Window.Current).Count == 0) - return d.ShowAsync(); - return null; - } + public static ElementTheme GetTheme() => Theme; // UPDATE FUNCTIONS FOR UI PLACEHOLDERS 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()); } diff --git a/PolyChat/Views/Dialog.xaml.cs b/PolyChat/Views/Dialog.xaml.cs index 6e1ce68..f8b5bd6 100644 --- a/PolyChat/Views/Dialog.xaml.cs +++ b/PolyChat/Views/Dialog.xaml.cs @@ -34,6 +34,7 @@ namespace PolyChat.Views // TODO: use event handlers and asign actions here Primary = primary.Action; Secondary = secondary.Action; + 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()