Message Alignment First Try

This commit is contained in:
Patrick Hellebrand
2021-09-23 16:05:20 +02:00
committed by Felix Hartmann (PEA3-Fe-FI)
parent 5c4b4373d6
commit ac67ff38c6
3 changed files with 16 additions and 33 deletions

View File

@@ -98,10 +98,11 @@
<ListView x:Name="listViewMessages" HorizontalAlignment="Stretch" VerticalAlignment="Bottom" Margin="4 16">
<ListView.ItemTemplate>
<DataTemplate x:DataType="models:ChatMessage">
<StackPanel 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 TimeStamp.ToString()}" Foreground="{ThemeResource SystemAltMediumColor}"/>
<TextBlock Text="{x:Bind Foreign}" Foreground="{ThemeResource SystemAltMediumLowColor}" FontStyle="Italic" />
<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 TimeStamp.ToString()}" Foreground="{ThemeResource SystemAltMediumColor}"/>
</StackPanel>
</StackPanel>
</DataTemplate>
</ListView.ItemTemplate>

View File

@@ -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 !!!!
)
);
}

View File

@@ -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;
/// <summary>
/// Create own Message (directly sent)
/// </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
/// Create Message
/// </summary>
/// <param name="origin">Origin IP</param>
/// <param name="type">Message Type, usually "message"</param>
/// <param name="content">Message Content, usually plain text</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;
TimeStamp = timeStamp;
Type = type;
Content = content;
Align = foreign ? HorizontalAlignment.Right : HorizontalAlignment.Left;
Foreign = foreign;
Debug.WriteLine("Created Loaded Message: " + ToString());
}