diff --git a/PolyChat/MainPage.xaml b/PolyChat/MainPage.xaml
index e56eae1..4f2144e 100644
--- a/PolyChat/MainPage.xaml
+++ b/PolyChat/MainPage.xaml
@@ -19,34 +19,36 @@
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
+
-
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
@@ -55,14 +57,14 @@
-
-
-
+
+
+
@@ -72,8 +74,9 @@
+
-
+
@@ -112,9 +115,9 @@
-
-
-
+
+
+
diff --git a/PolyChat/MainPage.xaml.cs b/PolyChat/MainPage.xaml.cs
index f3905e7..bf584f4 100644
--- a/PolyChat/MainPage.xaml.cs
+++ b/PolyChat/MainPage.xaml.cs
@@ -19,23 +19,42 @@ namespace PolyChat
{
private NetworkingController networkingController;
private ObservableCollection Partners;
- private ChatPartner selectedPartner;
+ private ChatPartner selectedPartner = null;
private string username;
public MainPage()
{
this.InitializeComponent();
+ // init controller
networkingController = new NetworkingController(this);
-
- Partners = new ObservableCollection();
+ // ui variables
ipAddress.Text = IP.GetCodeFromIP(networkingController.getIP().ToString());
+ Partners = new ObservableCollection();
+ updateNoChatsPlaceholder();
+ updateNoUsernamePlaceholder();
+ updateNoChatSelected();
+ updateSendButtonEnabled();
}
+ public async void ShowConnectionError(string message)
+ {
+ ConnectionFailedDialog dialog = new ConnectionFailedDialog(message);
+ var result = await dialog.ShowAsync();
+ if (result == ContentDialogResult.Primary)
+ {
+ //retry
+ }
+ // else abort -> del chat
+ }
+
+ // EVENTS
+
public void OnChatPartnerSelected(object sender, RoutedEventArgs e)
{
string code = ((RadioButton)sender).Tag.ToString();
selectedPartner = Partners.First(p => p.Code == code);
listViewMessages.ItemsSource = selectedPartner.Messages;
selectedPartnerName.Text = selectedPartner.Name;
+ updateNoChatSelected();
}
public void OnSendMessage(object sender = null, RoutedEventArgs e = null)
@@ -55,15 +74,13 @@ namespace PolyChat
var result = await dialog.ShowAsync();
if (result == ContentDialogResult.Primary)
{
- string ip = dialog.getValue();
- if (IP.ValidateIP(ip))
- {
- networkingController.connectNewClient(ip);
- Partners.Add(new ChatPartner(
- "Connecting...",
- ip
- ));
- }
+ string ip = IP.GetIPfromCode(dialog.getValue());
+ networkingController.connectNewClient(ip);
+ Partners.Add(new ChatPartner(
+ "Connecting...",
+ ip
+ ));
+ updateNoChatsPlaceholder();
}
}
@@ -77,6 +94,7 @@ namespace PolyChat
if (username.Length == 0) textUsername.Text = "Unknown";
else textUsername.Text = username;
}
+ updateNoUsernamePlaceholder();
}
public void OnIncomingMessage(ChatMessage message)
@@ -92,14 +110,56 @@ namespace PolyChat
private void OnDeleteChat(object sender = null, RoutedEventArgs e = null)
{
Partners.Remove(selectedPartner);
+ updateNoChatsPlaceholder();
}
- private void OnKeyDown(object sender, Windows.UI.Xaml.Input.KeyRoutedEventArgs e)
+ private void OnKeyUp(object sender, Windows.UI.Xaml.Input.KeyRoutedEventArgs e)
{
+ updateSendButtonEnabled();
if (e.Key == Windows.System.VirtualKey.Enter)
{
OnSendMessage();
}
}
+
+ // UPDATE FUNCTIONS FOR UI PLACEHOLDERS
+
+ private void updateNoChatsPlaceholder()
+ {
+ textNoChats.Visibility = Partners.Count() == 0 ? Visibility.Visible : Visibility.Collapsed;
+ }
+
+ private void updateNoUsernamePlaceholder()
+ {
+ if (username == null)
+ {
+ textNoUsername.Visibility = Visibility.Visible;
+ textUsername.Visibility = Visibility.Collapsed;
+ }
+ else
+ {
+ textNoUsername.Visibility = Visibility.Collapsed;
+ textUsername.Visibility = Visibility.Visible;
+ }
+ }
+
+ private void updateNoChatSelected()
+ {
+ if (selectedPartner != null)
+ {
+ gridRight.Visibility = Visibility.Visible;
+ textNoChatSelected.Visibility = Visibility.Collapsed;
+ }
+ else
+ {
+ gridRight.Visibility = Visibility.Collapsed;
+ textNoChatSelected.Visibility = Visibility.Visible;
+ }
+ }
+
+ private void updateSendButtonEnabled()
+ {
+ buttonSend.IsEnabled = inputSend.Text.Length != 0;
+ }
}
}
diff --git a/PolyChat/PolyChat.csproj b/PolyChat/PolyChat.csproj
index 2e6b0b9..598220b 100644
--- a/PolyChat/PolyChat.csproj
+++ b/PolyChat/PolyChat.csproj
@@ -134,6 +134,9 @@
+
+ ConnectionFailedDialog.xaml
+
EditUsernameDialog.xaml
@@ -165,6 +168,10 @@
MSBuild:Compile
Designer
+
+ MSBuild:Compile
+ Designer
+
MSBuild:Compile
Designer
diff --git a/PolyChat/Views/ConnectionFailedDialog.xaml b/PolyChat/Views/ConnectionFailedDialog.xaml
new file mode 100644
index 0000000..fa8916e
--- /dev/null
+++ b/PolyChat/Views/ConnectionFailedDialog.xaml
@@ -0,0 +1,17 @@
+
+
+
+
+
+
+
diff --git a/PolyChat/Views/ConnectionFailedDialog.xaml.cs b/PolyChat/Views/ConnectionFailedDialog.xaml.cs
new file mode 100644
index 0000000..1c09a8f
--- /dev/null
+++ b/PolyChat/Views/ConnectionFailedDialog.xaml.cs
@@ -0,0 +1,26 @@
+using PolyChat.Models;
+using PolyChat.Util;
+using System;
+using System.Collections.ObjectModel;
+using System.Linq;
+using Windows.UI.Popups;
+using Windows.UI.Xaml;
+using Windows.UI.Xaml.Controls;
+using Windows.UI.Xaml.Media;
+
+// The Blank Page item template is documented at https://go.microsoft.com/fwlink/?LinkId=402352&clcid=0x409
+
+namespace PolyChat.Views
+{
+ ///
+ /// An empty page that can be used on its own or navigated to within a Frame.
+ ///
+ public sealed partial class ConnectionFailedDialog : ContentDialog
+ {
+ public ConnectionFailedDialog(string message)
+ {
+ this.InitializeComponent();
+ textError.Text = message;
+ }
+ }
+}
diff --git a/PolyChat/Views/EditUsernameDialog.xaml b/PolyChat/Views/EditUsernameDialog.xaml
index 7bfba27..cc02075 100644
--- a/PolyChat/Views/EditUsernameDialog.xaml
+++ b/PolyChat/Views/EditUsernameDialog.xaml
@@ -13,7 +13,7 @@
-
+
diff --git a/PolyChat/Views/NewChatDialog.xaml b/PolyChat/Views/NewChatDialog.xaml
index bfa8119..55cc9ca 100644
--- a/PolyChat/Views/NewChatDialog.xaml
+++ b/PolyChat/Views/NewChatDialog.xaml
@@ -13,10 +13,10 @@
-
+
-
-
+
+