Merged Theming with AsyncDialogs
This commit is contained in:
@@ -29,8 +29,6 @@ namespace PolyChat
|
|||||||
private readonly FileManager fileManager;
|
private readonly FileManager fileManager;
|
||||||
// Props
|
// Props
|
||||||
private Dictionary<string, Connection> Connections = new Dictionary<string, Connection>();
|
private Dictionary<string, Connection> Connections = new Dictionary<string, Connection>();
|
||||||
private string OwnName = "";
|
|
||||||
private string OwnIP;
|
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Initializes Controller with UI access
|
/// Initializes Controller with UI access
|
||||||
@@ -40,7 +38,6 @@ namespace PolyChat
|
|||||||
{
|
{
|
||||||
UIController = uiController;
|
UIController = uiController;
|
||||||
fileManager = new FileManager(uiController);
|
fileManager = new FileManager(uiController);
|
||||||
OwnIP = getIP();
|
|
||||||
fileManager.loadChats();
|
fileManager.loadChats();
|
||||||
Serve();
|
Serve();
|
||||||
|
|
||||||
@@ -96,7 +93,6 @@ namespace PolyChat
|
|||||||
Debug.WriteLine("---- Added new Connection ----");
|
Debug.WriteLine("---- Added new Connection ----");
|
||||||
Connections.Add(ForeignIp, new Connection(socket, Data => OnMessage(ForeignIp, Data), CloseChat));
|
Connections.Add(ForeignIp, new Connection(socket, Data => OnMessage(ForeignIp, Data), CloseChat));
|
||||||
UIController.OnIncomingConnection(ForeignIp);
|
UIController.OnIncomingConnection(ForeignIp);
|
||||||
fileManager.loadChat(ForeignIp);
|
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
@@ -139,7 +135,7 @@ namespace PolyChat
|
|||||||
else Debug.WriteLine("Undefined: " + data);
|
else Debug.WriteLine("Undefined: " + data);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void CloseChat(string IP, bool wasConnected = true)
|
public void CloseChat(string IP, bool wasConnected = true, bool delete = false)
|
||||||
{
|
{
|
||||||
Debug.WriteLine($"Deleting connection with IP:{IP}");
|
Debug.WriteLine($"Deleting connection with IP:{IP}");
|
||||||
if (IP != null && Connections.ContainsKey(IP))
|
if (IP != null && Connections.ContainsKey(IP))
|
||||||
@@ -147,13 +143,17 @@ namespace PolyChat
|
|||||||
Connections[IP].Close();
|
Connections[IP].Close();
|
||||||
Connections.Remove(IP);
|
Connections.Remove(IP);
|
||||||
}
|
}
|
||||||
CloseChatUI(IP, wasConnected);
|
if (delete || !wasConnected)
|
||||||
|
CloseChatUI(IP, wasConnected, delete);
|
||||||
|
if (delete)
|
||||||
|
fileManager.deleteChat(IP);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void CloseChatUI(string IP, bool wasConnected = true)
|
private void CloseChatUI(string IP, bool wasConnected = true, bool delete = false)
|
||||||
{
|
{
|
||||||
UIController.OnChatPartnerDeleted(IP);
|
UIController.OnChatPartnerDeleted(IP);
|
||||||
string heading = wasConnected ? "Connection Closed" : "Connection Failed";
|
string heading = wasConnected ? "Connection Closed" : "Connection Failed";
|
||||||
|
if(!delete)
|
||||||
UIController.ShowConnectionError(IP, heading, $"Connecting to {IP} failed...");
|
UIController.ShowConnectionError(IP, heading, $"Connecting to {IP} failed...");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -70,6 +70,7 @@ namespace PolyChat
|
|||||||
() => { /* do nothing */ }
|
() => { /* do nothing */ }
|
||||||
)
|
)
|
||||||
);
|
);
|
||||||
|
SafelyOpenDialog(dialog);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -102,6 +103,8 @@ namespace PolyChat
|
|||||||
{
|
{
|
||||||
string ip = IP.GetIPFromCode(dialog.getValue());
|
string ip = IP.GetIPFromCode(dialog.getValue());
|
||||||
Controller.Connect(ip);
|
Controller.Connect(ip);
|
||||||
|
ChatPartner pa = Partners.FirstOrDefault(p => p.Code == ip);
|
||||||
|
if (pa == null)
|
||||||
Partners.Add(new ChatPartner(
|
Partners.Add(new ChatPartner(
|
||||||
"Connecting...",
|
"Connecting...",
|
||||||
ip
|
ip
|
||||||
@@ -188,7 +191,7 @@ namespace PolyChat
|
|||||||
|
|
||||||
private void OnDeleteChat(object sender = null, RoutedEventArgs e = null)
|
private void OnDeleteChat(object sender = null, RoutedEventArgs e = null)
|
||||||
{
|
{
|
||||||
Controller.CloseChat(selectedPartner.Code);
|
Controller.CloseChat(selectedPartner.Code,delete: true);
|
||||||
Partners.Remove(selectedPartner);
|
Partners.Remove(selectedPartner);
|
||||||
updateNoChatsPlaceholder();
|
updateNoChatsPlaceholder();
|
||||||
updateNoChatSelected();
|
updateNoChatSelected();
|
||||||
|
|||||||
@@ -15,9 +15,9 @@ namespace PolyChat.Models
|
|||||||
private SocketIOSocket Socket;
|
private SocketIOSocket Socket;
|
||||||
private bool Connected = false;
|
private bool Connected = false;
|
||||||
private readonly string IP;
|
private readonly string IP;
|
||||||
private Action<string, bool> DeleteConnection;
|
private Action<string, bool, bool> DeleteConnection;
|
||||||
|
|
||||||
public Connection(string ip, ushort port, Action<JToken[]> onMessage, Action<string, bool> onClose)
|
public Connection(string ip, ushort port, Action<JToken[]> onMessage, Action<string, bool, bool> onClose)
|
||||||
{
|
{
|
||||||
Debug.WriteLine("! CONNECTING TO SERVER !");
|
Debug.WriteLine("! CONNECTING TO SERVER !");
|
||||||
IP = ip;
|
IP = ip;
|
||||||
@@ -32,7 +32,7 @@ namespace PolyChat.Models
|
|||||||
Client.On("message", (Action<JToken[]>) onMessage);
|
Client.On("message", (Action<JToken[]>) onMessage);
|
||||||
}
|
}
|
||||||
|
|
||||||
public Connection(SocketIOSocket socket, Action<JToken[]> onMessage, Action<string, bool> onClose)
|
public Connection(SocketIOSocket socket, Action<JToken[]> onMessage, Action<string, bool, bool> onClose)
|
||||||
{
|
{
|
||||||
Socket = socket;
|
Socket = socket;
|
||||||
DeleteConnection = onClose;
|
DeleteConnection = onClose;
|
||||||
@@ -66,7 +66,7 @@ namespace PolyChat.Models
|
|||||||
{
|
{
|
||||||
Debug.WriteLine("--- Disconnected! ---");
|
Debug.WriteLine("--- Disconnected! ---");
|
||||||
Debug.WriteLine($"--- Deleting Connection with IP: {IP}---");
|
Debug.WriteLine($"--- Deleting Connection with IP: {IP}---");
|
||||||
DeleteConnection(IP, IsConnected());
|
DeleteConnection(IP, IsConnected(),false);
|
||||||
Connected = false;
|
Connected = false;
|
||||||
}
|
}
|
||||||
private void OnError(JToken[] data)
|
private void OnError(JToken[] data)
|
||||||
|
|||||||
@@ -36,7 +36,7 @@ namespace PolyChat.Models
|
|||||||
{
|
{
|
||||||
foreach (String path in filepaths)
|
foreach (String path in filepaths)
|
||||||
{
|
{
|
||||||
if (Path.GetFileName(path).Equals(ip))
|
if (Path.GetFileName(path).Equals(ip+".txt"))
|
||||||
{
|
{
|
||||||
File.Delete(path);
|
File.Delete(path);
|
||||||
return;
|
return;
|
||||||
|
|||||||
@@ -34,8 +34,6 @@ namespace PolyChat.Views
|
|||||||
// TODO: use event handlers and asign actions here
|
// TODO: use event handlers and asign actions here
|
||||||
Primary = primary.Action;
|
Primary = primary.Action;
|
||||||
Secondary = secondary.Action;
|
Secondary = secondary.Action;
|
||||||
// show
|
|
||||||
MainPage.SafelyOpenDialog(this);
|
|
||||||
RequestedTheme = MainPage.GetTheme();
|
RequestedTheme = MainPage.GetTheme();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user