Message Alignment First Try

This commit is contained in:
Patrick Hellebrand
2021-09-23 16:05:20 +02:00
parent de2d135fdf
commit 0a1ff66e38
3 changed files with 16 additions and 29 deletions

View File

@@ -98,10 +98,11 @@
<ListView x:Name="listViewMessages" HorizontalAlignment="Stretch" VerticalAlignment="Bottom" Margin="4 16"> <ListView x:Name="listViewMessages" HorizontalAlignment="Stretch" VerticalAlignment="Bottom" Margin="4 16">
<ListView.ItemTemplate> <ListView.ItemTemplate>
<DataTemplate x:DataType="models:ChatMessage"> <DataTemplate x:DataType="models:ChatMessage">
<StackPanel x:Name="Message" MaxWidth="320" Margin="0 4" Padding="16 8" CornerRadius="4" Background="{ThemeResource SystemAccentColor}"> <StackPanel Orientation="Horizontal" HorizontalAlignment="Stretch">
<StackPanel HorizontalAlignment="{x:Bind Align}" x:Name="Message" MaxWidth="320" Margin="0 4" Padding="16 8" CornerRadius="4" Background="{ThemeResource SystemAccentColor}">
<TextBlock Text="{x:Bind Content}" Foreground="{ThemeResource SystemAltHighColor}" TextWrapping="WrapWholeWords" FontSize="14"/> <TextBlock Text="{x:Bind Content}" Foreground="{ThemeResource SystemAltHighColor}" TextWrapping="WrapWholeWords" FontSize="14"/>
<TextBlock Text="{x:Bind TimeStamp.ToString()}" Foreground="{ThemeResource SystemAltMediumColor}"/> <TextBlock Text="{x:Bind TimeStamp.ToString()}" Foreground="{ThemeResource SystemAltMediumColor}"/>
<TextBlock Text="{x:Bind Foreign}" Foreground="{ThemeResource SystemAltMediumLowColor}" FontStyle="Italic" /> </StackPanel>
</StackPanel> </StackPanel>
</DataTemplate> </DataTemplate>
</ListView.ItemTemplate> </ListView.ItemTemplate>

View File

@@ -28,7 +28,6 @@ namespace PolyChat
private string username; private string username;
private static ElementTheme Theme = ElementTheme.Light; private static ElementTheme Theme = ElementTheme.Light;
public MainPage() public MainPage()
{ {
this.InitializeComponent(); this.InitializeComponent();
@@ -78,7 +77,7 @@ namespace PolyChat
public void OnSendMessage(object sender = null, RoutedEventArgs e = null) 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); Controller.SendMessage(selectedPartner.Code, "message", inputSend.Text);
// clear input // clear input
inputSend.Text = ""; inputSend.Text = "";
@@ -161,7 +160,7 @@ namespace PolyChat
Partners.Insert(index, sendingPartner); Partners.Insert(index, sendingPartner);
break; break;
default: default:
sendingPartner.AddMessage(new ChatMessage(origin, type, content, timeStamp)); sendingPartner.AddMessage(new ChatMessage(origin, type, content, timeStamp, true));
break; break;
} }
}); });
@@ -178,8 +177,9 @@ namespace PolyChat
new ChatMessage( new ChatMessage(
origin, origin,
item["type"].ToString(), item["type"].ToString(),
item["content"].ToString()//, item["content"].ToString(),
//DateTime.Parse(item["timestamp"].ToString()) DateTime.Parse(item["timestamp"].ToString()),
false // TODO: FIX !!!!
) )
); );
} }

View File

@@ -1,6 +1,7 @@
using System; using System;
using System.Diagnostics; using System.Diagnostics;
using System.Text.Json; using System.Text.Json;
using Windows.UI.Xaml;
namespace PolyChat.Models namespace PolyChat.Models
{ {
@@ -10,38 +11,23 @@ namespace PolyChat.Models
public string Type; public string Type;
public string Content; public string Content;
public DateTime TimeStamp; public DateTime TimeStamp;
public readonly bool Foreign; public HorizontalAlignment Align;
private bool Foreign;
/// <summary> /// <summary>
/// Create own Message (directly sent) /// Create Message
/// </summary>
/// <param name="origin">My IP</param>
/// <param name="type">Message Type</param>
/// <param name="content">Message Content (not JSON)</param>
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());
}
/// <summary>
/// Create Message loaded with timestamp
/// </summary> /// </summary>
/// <param name="origin">Origin IP</param> /// <param name="origin">Origin IP</param>
/// <param name="type">Message Type, usually "message"</param> /// <param name="type">Message Type, usually "message"</param>
/// <param name="content">Message Content, usually plain text</param> /// <param name="content">Message Content, usually plain text</param>
/// <param name="timeStamp">Parsed DateTime</param> /// <param name="timeStamp">Parsed DateTime</param>
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; Origin = origin;
TimeStamp = timeStamp; TimeStamp = timeStamp;
Type = type; Type = type;
Content = content; Content = content;
Align = foreign ? HorizontalAlignment.Right : HorizontalAlignment.Left;
Foreign = foreign; Foreign = foreign;
Debug.WriteLine("Created Loaded Message: " + ToString()); Debug.WriteLine("Created Loaded Message: " + ToString());
} }