Merge branch 'ConnectionController' of https://sourcecode.socialcoding.bosch.com/scm/~hpl2fe/polychat into ConnectionController
This commit is contained in:
@@ -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}">
|
||||
<Grid>
|
||||
<Grid.ColumnDefinitions>
|
||||
<ColumnDefinition Width="224"/>
|
||||
<ColumnDefinition Width="*"/>
|
||||
</Grid.ColumnDefinitions>
|
||||
<!-- LEFT SIDE -->
|
||||
<Grid Grid.Column="0" Margin="16">
|
||||
<Grid Grid.Column="0" Padding="16" Background="{ThemeResource SystemChromeMediumColor}">
|
||||
<Grid.RowDefinitions>
|
||||
<RowDefinition Height="Auto"/>
|
||||
<RowDefinition Height="*"/>
|
||||
<RowDefinition Height="Auto"/>
|
||||
</Grid.RowDefinitions>
|
||||
<!-- CONNECTION HEADER -->
|
||||
<StackPanel HorizontalAlignment="Stretch" Spacing="8" Margin="0 0 0 8">
|
||||
@@ -37,7 +38,7 @@
|
||||
<TextBlock Text="Connect to" Foreground="{ThemeResource SystemColorDisabledTextColor}"/>
|
||||
<TextBlock x:Name="ipAddress" Grid.Column="1"/>
|
||||
</Grid>
|
||||
<Border BorderThickness="1" BorderBrush="{ThemeResource AppBarBorderThemeBrush}"/>
|
||||
<Border BorderThickness="1" BorderBrush="{ThemeResource SystemControlBackgroundListLowBrush}"/>
|
||||
<Grid HorizontalAlignment="Stretch" VerticalAlignment="Center">
|
||||
<Grid.ColumnDefinitions>
|
||||
<ColumnDefinition Width="*"/>
|
||||
@@ -55,12 +56,8 @@
|
||||
<DataTemplate x:DataType="models:ChatPartner">
|
||||
<RadioButton GroupName="chatSelect" Tag="{x:Bind Code}" HorizontalAlignment="Stretch" Height="64" Click="OnChatPartnerSelected">
|
||||
<StackPanel x:Name="ChatPartner" VerticalAlignment="Center" HorizontalAlignment="Stretch">
|
||||
<StackPanel Orientation="Horizontal" HorizontalAlignment="Stretch">
|
||||
<TextBlock HorizontalAlignment="Stretch" Text="{x:Bind Name}"/>
|
||||
<TextBlock Foreground="{ThemeResource SystemColorDisabledTextColor}" Text=" ("/>
|
||||
<TextBlock Foreground="{ThemeResource SystemColorDisabledTextColor}" Text="{x:Bind Code}"/>
|
||||
<TextBlock Foreground="{ThemeResource SystemColorDisabledTextColor}" Text=")"/>
|
||||
</StackPanel>
|
||||
<TextBlock HorizontalAlignment="Stretch" Text="{x:Bind Name}"/>
|
||||
<TextBlock Foreground="{ThemeResource SystemColorDisabledTextColor}" Text="{x:Bind Code}"/>
|
||||
<!--
|
||||
<StackPanel Orientation="Horizontal" HorizontalAlignment="Stretch">
|
||||
<TextBlock HorizontalAlignment="Stretch" Text="{x:Bind Messages.Last().toString()}"/>
|
||||
@@ -73,6 +70,7 @@
|
||||
</ListView.ItemTemplate>
|
||||
</ListView>
|
||||
</ScrollViewer>
|
||||
<Button Grid.Row="2" Click="OnToggleTheme" Content="Toggle Theme"/>
|
||||
</Grid>
|
||||
<TextBlock x:Name="textNoChatSelected" Grid.Column="1" Text="No Chat Selected" Foreground="{ThemeResource SystemColorDisabledTextColor}" FontSize="24" VerticalAlignment="Center" HorizontalAlignment="Center"/>
|
||||
<!-- RIGHT SIDE -->
|
||||
@@ -100,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>
|
||||
|
||||
@@ -26,7 +26,8 @@ namespace PolyChat
|
||||
private ObservableCollection<ChatPartner> 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<ChatPartner>();
|
||||
// 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<ContentDialogResult> SafelyOpenDialog(Dialog d)
|
||||
public static IAsyncOperation<ContentDialogResult> SafelyOpenDialog(ContentDialog d)
|
||||
{
|
||||
if(VisualTreeHelper.GetOpenPopups(Window.Current).Count == 0)
|
||||
return d.ShowAsync();
|
||||
return null;
|
||||
}
|
||||
|
||||
public static IAsyncOperation<ContentDialogResult> SafelyOpenDialog(NewChatDialog d)
|
||||
{
|
||||
if (VisualTreeHelper.GetOpenPopups(Window.Current).Count == 0)
|
||||
return d.ShowAsync();
|
||||
return null;
|
||||
}
|
||||
// GETTERS
|
||||
|
||||
public static IAsyncOperation<ContentDialogResult> 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
|
||||
|
||||
|
||||
@@ -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());
|
||||
}
|
||||
|
||||
@@ -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)
|
||||
|
||||
@@ -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()
|
||||
|
||||
@@ -20,6 +20,7 @@ namespace PolyChat.Views
|
||||
{
|
||||
this.InitializeComponent();
|
||||
IsPrimaryButtonEnabled = false;
|
||||
RequestedTheme = MainPage.GetTheme();
|
||||
}
|
||||
|
||||
public string getValue()
|
||||
|
||||
Reference in New Issue
Block a user