From ac67ff38c69ca98e0920c7881140a71d3fd2ffe1 Mon Sep 17 00:00:00 2001 From: Patrick Hellebrand Date: Thu, 23 Sep 2021 16:05:20 +0200 Subject: [PATCH] Message Alignment First Try --- PolyChat/MainPage.xaml | 9 +++++---- PolyChat/MainPage.xaml.cs | 14 +++++--------- PolyChat/Models/ChatMessage.cs | 26 ++++++-------------------- 3 files changed, 16 insertions(+), 33 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 f8af190..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,12 +177,9 @@ namespace PolyChat new ChatMessage( origin, item["type"].ToString(), - item["content"].ToString()//, -<<<<<<< HEAD - //DateTime.Parse(item["timestamp"].ToString()) -======= - //DateTime.Parse(item["timestamp"].ToString()) ->>>>>>> be4eada (stuff) + 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()); }