ConnectionFailedDialog -> Dialog for Success and Error Messages with heading, message and buttons/actions
This commit is contained in:
committed by
Felix Hartmann (PEA3-Fe-FI)
parent
e2de9f5917
commit
ea81547540
@@ -8,6 +8,10 @@ using SocketIOSharp.Server.Client;
|
|||||||
|
|
||||||
namespace PolyChat
|
namespace PolyChat
|
||||||
{
|
{
|
||||||
|
|
||||||
|
// 10.1.211.26 Marc
|
||||||
|
// 10.1.218.90 Felix
|
||||||
|
// 10.4.141.77 Pat
|
||||||
class Controller
|
class Controller
|
||||||
{
|
{
|
||||||
// Constants
|
// Constants
|
||||||
@@ -28,10 +32,6 @@ namespace PolyChat
|
|||||||
UIController = uiController;
|
UIController = uiController;
|
||||||
OwnIP = getIP();
|
OwnIP = getIP();
|
||||||
Serve();
|
Serve();
|
||||||
|
|
||||||
//Connect("10.1.211.26"); // Marc
|
|
||||||
//Connect("10.1.218.90"); // Felix
|
|
||||||
//Connect("10.4.141.77"); // Pat
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public void Connect(string ip)
|
public void Connect(string ip)
|
||||||
@@ -43,9 +43,7 @@ namespace PolyChat
|
|||||||
private void Serve()
|
private void Serve()
|
||||||
{
|
{
|
||||||
Debug.WriteLine("--- Controller.Serve ---");
|
Debug.WriteLine("--- Controller.Serve ---");
|
||||||
SocketIOServer server = new SocketIOServer(new SocketIOServerOption(
|
SocketIOServer server = new SocketIOServer(new SocketIOServerOption(PORT));
|
||||||
PORT
|
|
||||||
));
|
|
||||||
server.Start();
|
server.Start();
|
||||||
Debug.WriteLine("Port " + server.Option.Port);
|
Debug.WriteLine("Port " + server.Option.Port);
|
||||||
Debug.WriteLine("Path " + server.Option.Path);
|
Debug.WriteLine("Path " + server.Option.Path);
|
||||||
@@ -95,7 +93,7 @@ namespace PolyChat
|
|||||||
Connections.Remove(IP);
|
Connections.Remove(IP);
|
||||||
UIController.OnChatPartnerDeleted(IP);
|
UIController.OnChatPartnerDeleted(IP);
|
||||||
if(!wasConnected)
|
if(!wasConnected)
|
||||||
UIController.ShowConnectionError(IP, $"Connection to {IP} failed...");
|
UIController.ShowConnectionError("Connection close", IP, $"Connection to {IP} failed...");
|
||||||
}
|
}
|
||||||
|
|
||||||
public string getIP()
|
public string getIP()
|
||||||
|
|||||||
@@ -36,13 +36,17 @@ namespace PolyChat
|
|||||||
updateSendButtonEnabled();
|
updateSendButtonEnabled();
|
||||||
}
|
}
|
||||||
|
|
||||||
public async void ShowConnectionError(string code, string message)
|
public async void ShowConnectionError(string code, string heading, string message)
|
||||||
{
|
{
|
||||||
await Dispatcher.RunAsync(CoreDispatcherPriority.Normal, async () =>
|
await Dispatcher.RunAsync(CoreDispatcherPriority.Normal, () =>
|
||||||
{
|
{
|
||||||
ConnectionFailedDialog dialog = new ConnectionFailedDialog(message);
|
Dialog dialog = new Dialog(
|
||||||
var result = await dialog.ShowAsync();
|
Dialog.TYPE_ERROR,
|
||||||
if (result == ContentDialogResult.Primary)
|
heading,
|
||||||
|
message,
|
||||||
|
new DialogButton(
|
||||||
|
"Retry",
|
||||||
|
() =>
|
||||||
{
|
{
|
||||||
Controller.Connect(code);
|
Controller.Connect(code);
|
||||||
Partners.Add(new ChatPartner(
|
Partners.Add(new ChatPartner(
|
||||||
@@ -51,6 +55,12 @@ namespace PolyChat
|
|||||||
));
|
));
|
||||||
updateNoChatsPlaceholder();
|
updateNoChatsPlaceholder();
|
||||||
}
|
}
|
||||||
|
),
|
||||||
|
new DialogButton(
|
||||||
|
"Ignore",
|
||||||
|
() => { /* do nothing */ }
|
||||||
|
)
|
||||||
|
);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
20
PolyChat/Models/DialogButton.cs
Normal file
20
PolyChat/Models/DialogButton.cs
Normal file
@@ -0,0 +1,20 @@
|
|||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Text;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
|
||||||
|
namespace PolyChat.Models
|
||||||
|
{
|
||||||
|
public class DialogButton
|
||||||
|
{
|
||||||
|
public string Text;
|
||||||
|
public Action Action;
|
||||||
|
|
||||||
|
public DialogButton(string text, Action action)
|
||||||
|
{
|
||||||
|
Text = text;
|
||||||
|
Action = action;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -119,6 +119,7 @@
|
|||||||
<Compile Include="App.xaml.cs">
|
<Compile Include="App.xaml.cs">
|
||||||
<DependentUpon>App.xaml</DependentUpon>
|
<DependentUpon>App.xaml</DependentUpon>
|
||||||
</Compile>
|
</Compile>
|
||||||
|
<Compile Include="Models\DialogButton.cs" />
|
||||||
<Compile Include="Models\Connection.cs" />
|
<Compile Include="Models\Connection.cs" />
|
||||||
<Compile Include="Controller.cs" />
|
<Compile Include="Controller.cs" />
|
||||||
<Compile Include="MainPage.xaml.cs">
|
<Compile Include="MainPage.xaml.cs">
|
||||||
@@ -130,8 +131,8 @@
|
|||||||
<Compile Include="Models\Exceptions\ConnectionFailedException.cs" />
|
<Compile Include="Models\Exceptions\ConnectionFailedException.cs" />
|
||||||
<Compile Include="Properties\AssemblyInfo.cs" />
|
<Compile Include="Properties\AssemblyInfo.cs" />
|
||||||
<Compile Include="Util\IP.cs" />
|
<Compile Include="Util\IP.cs" />
|
||||||
<Compile Include="Views\ConnectionFailedDialog.xaml.cs">
|
<Compile Include="Views\Dialog.xaml.cs">
|
||||||
<DependentUpon>ConnectionFailedDialog.xaml</DependentUpon>
|
<DependentUpon>Dialog.xaml</DependentUpon>
|
||||||
</Compile>
|
</Compile>
|
||||||
<Compile Include="Views\EditUsernameDialog.xaml.cs">
|
<Compile Include="Views\EditUsernameDialog.xaml.cs">
|
||||||
<DependentUpon>EditUsernameDialog.xaml</DependentUpon>
|
<DependentUpon>EditUsernameDialog.xaml</DependentUpon>
|
||||||
@@ -164,7 +165,7 @@
|
|||||||
<Generator>MSBuild:Compile</Generator>
|
<Generator>MSBuild:Compile</Generator>
|
||||||
<SubType>Designer</SubType>
|
<SubType>Designer</SubType>
|
||||||
</Page>
|
</Page>
|
||||||
<Page Include="Views\ConnectionFailedDialog.xaml">
|
<Page Include="Views\Dialog.xaml">
|
||||||
<Generator>MSBuild:Compile</Generator>
|
<Generator>MSBuild:Compile</Generator>
|
||||||
<SubType>Designer</SubType>
|
<SubType>Designer</SubType>
|
||||||
</Page>
|
</Page>
|
||||||
|
|||||||
@@ -1,26 +0,0 @@
|
|||||||
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
|
|
||||||
{
|
|
||||||
/// <summary>
|
|
||||||
/// An empty page that can be used on its own or navigated to within a Frame.
|
|
||||||
/// </summary>
|
|
||||||
public sealed partial class ConnectionFailedDialog : ContentDialog
|
|
||||||
{
|
|
||||||
public ConnectionFailedDialog(string message)
|
|
||||||
{
|
|
||||||
this.InitializeComponent();
|
|
||||||
textError.Text = message;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,17 +1,20 @@
|
|||||||
<ContentDialog x:Class="PolyChat.Views.ConnectionFailedDialog"
|
<ContentDialog x:Class="PolyChat.Views.Dialog"
|
||||||
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
|
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
|
||||||
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
|
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
|
||||||
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
|
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
|
||||||
xmlns:local="using:PolyChat.Views"
|
xmlns:local="using:PolyChat.Views"
|
||||||
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
|
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
|
||||||
x:Name="MessageDialog"
|
x:Name="MessageDialog"
|
||||||
Title="Connection Failed"
|
Title="Header"
|
||||||
PrimaryButtonText="Retry"
|
PrimaryButtonText="Primary"
|
||||||
SecondaryButtonText="Abort"
|
PrimaryButtonClick="OnPrimaryButtonClick"
|
||||||
|
SecondaryButtonText="Secondary"
|
||||||
|
SecondaryButtonClick="OnSecondaryButtonClick"
|
||||||
mc:Ignorable="d">
|
mc:Ignorable="d">
|
||||||
|
|
||||||
<StackPanel>
|
<StackPanel>
|
||||||
<TextBlock Text="Message:" Foreground="{ThemeResource SystemColorDisabledTextColor}" Margin="0 0 0 8"/>
|
<TextBlock Text="Message:" Foreground="{ThemeResource SystemColorDisabledTextColor}" Margin="0 0 0 8"/>
|
||||||
<TextBlock x:Name="textError" Foreground="{ThemeResource SystemErrorTextColor}"/>
|
<TextBlock x:Name="textError" Foreground="{ThemeResource SystemErrorTextColor}" Visibility="Collapsed"/>
|
||||||
|
<TextBlock x:Name="textSuccess" Foreground="{ThemeResource SystemAccentColor}" Visibility="Collapsed"/>
|
||||||
</StackPanel>
|
</StackPanel>
|
||||||
</ContentDialog>
|
</ContentDialog>
|
||||||
70
PolyChat/Views/Dialog.xaml.cs
Normal file
70
PolyChat/Views/Dialog.xaml.cs
Normal file
@@ -0,0 +1,70 @@
|
|||||||
|
using PolyChat.Models;
|
||||||
|
using PolyChat.Util;
|
||||||
|
using System;
|
||||||
|
using System.Collections.ObjectModel;
|
||||||
|
using System.Linq;
|
||||||
|
using Windows.Foundation;
|
||||||
|
using Windows.UI.Core;
|
||||||
|
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
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// An empty page that can be used on its own or navigated to within a Frame.
|
||||||
|
/// </summary>
|
||||||
|
public sealed partial class Dialog : ContentDialog
|
||||||
|
{
|
||||||
|
public const string TYPE_ERROR = "error";
|
||||||
|
public const string TYPE_SUCCESS = "success";
|
||||||
|
private Action Primary;
|
||||||
|
private Action Secondary;
|
||||||
|
public Dialog(string type, string header, string message, DialogButton primary, DialogButton secondary)
|
||||||
|
{
|
||||||
|
this.InitializeComponent();
|
||||||
|
Title = header;
|
||||||
|
setType(type, message);
|
||||||
|
PrimaryButtonText = primary.Text;
|
||||||
|
SecondaryButtonText = secondary.Text;
|
||||||
|
// TODO: use event handlers and asign actions here
|
||||||
|
Primary = primary.Action;
|
||||||
|
Secondary = secondary.Action;
|
||||||
|
// show
|
||||||
|
ShowDialogAsync();
|
||||||
|
}
|
||||||
|
|
||||||
|
private void setType(string type, string message)
|
||||||
|
{
|
||||||
|
switch (type)
|
||||||
|
{
|
||||||
|
case TYPE_ERROR:
|
||||||
|
textError.Text = message;
|
||||||
|
textError.Visibility = Visibility.Visible;
|
||||||
|
break;
|
||||||
|
case TYPE_SUCCESS:
|
||||||
|
textSuccess.Text = message;
|
||||||
|
textSuccess.Visibility = Visibility.Visible;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private async void ShowDialogAsync()
|
||||||
|
{
|
||||||
|
await ShowAsync();
|
||||||
|
}
|
||||||
|
|
||||||
|
private void OnPrimaryButtonClick(ContentDialog sender, ContentDialogButtonClickEventArgs args)
|
||||||
|
{
|
||||||
|
Primary();
|
||||||
|
}
|
||||||
|
|
||||||
|
private void OnSecondaryButtonClick(ContentDialog sender, ContentDialogButtonClickEventArgs args)
|
||||||
|
{
|
||||||
|
Secondary();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user