affiche l'état de la connexion SignalR

vnext
Paul Schneider 8 years ago
parent 072f16fc0a
commit c114b851d2
2 changed files with 28 additions and 27 deletions

@ -1,60 +1,61 @@
<?xml version="1.0" encoding="utf-8" ?>
<TabbedPage xmlns="http://xamarin.com/schemas/2014/forms"
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
x:Class="BookAStar.Pages.ChatPage"
xmlns:views="clr-namespace:BookAStar.Views;assembly=BookAStar"
xmlns:controls="clr-namespace:XLabs.Forms.Controls;assembly=XLabs.Forms"
xmlns:toolkit="clr-namespace:XLabs.Forms.Mvvm;assembly=XLabs.Forms"
xmlns:converters="clr-namespace:BookAStar.Converters;assembly=BookAStar"
xmlns:local="clr-namespace:BookAStar;Assembly:BookAStar"
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
x:Class="BookAStar.Pages.ChatPage"
xmlns:views="clr-namespace:BookAStar.Views;assembly=BookAStar"
xmlns:controls="clr-namespace:XLabs.Forms.Controls;assembly=XLabs.Forms"
xmlns:toolkit="clr-namespace:XLabs.Forms.Mvvm;assembly=XLabs.Forms"
xmlns:converters="clr-namespace:BookAStar.Converters;assembly=BookAStar"
xmlns:local="clr-namespace:BookAStar;Assembly:BookAStar"
xmlns:extensions="clr-namespace:BookAStar.Extensions;assembly=BookAStar"
>
<!--
<TabbedPage.Resources>
<ResourceDictionary>
<converters:SignalRConnectionStateToObject x:Key="cxToStyleButton" x:TypeArguments="Style">
<converters:SignalRConnectionStateToObject x:Key="cxToStyleImage" x:TypeArguments="Style">
<converters:SignalRConnectionStateToObject.DisconnectedObject>
<Style TargetType="Button">
<Setter Property="Image"
<Style TargetType="Image">
<Setter Property="Source"
Value="{extensions:ImageResource BookAStar.Images.Chat.disconnected.png}" />
</Style>
</converters:SignalRConnectionStateToObject.DisconnectedObject>
<converters:SignalRConnectionStateToObject.ConnectedObject>
<Style TargetType="Button">
<Setter Property="Image"
<Style TargetType="Image">
<Setter Property="Source"
Value="{extensions:ImageResource BookAStar.Images.Chat.connected.png}" />
</Style>
</converters:SignalRConnectionStateToObject.ConnectedObject>
<converters:SignalRConnectionStateToObject.ConnectingObject>
<Style TargetType="Button">
<Style TargetType="Image">
<Setter Property="Source"
Value="{extensions:ImageResource BookAStar.Images.Chat.connecting.png}" />
</Style>
</converters:SignalRConnectionStateToObject.ConnectingObject>
<converters:SignalRConnectionStateToObject.ReconnectingObject>
<Style TargetType="Button">
<Style TargetType="Image">
<Setter Property="Source"
Value="{extensions:ImageResource BookAStar.Images.Chat.reconnecting.png}" />
</Style>
</converters:SignalRConnectionStateToObject.ReconnectingObject>
</converters:SignalRConnectionStateToObject>
</ResourceDictionary>
</TabbedPage.Resources> -->
</TabbedPage.Resources>
<TabbedPage.Children>
<ContentPage Title="Public" Icon="chat_icon_s.png" >
<StackLayout Padding="5, 5, 5, 5">
<StackLayout Spacing = "12"
Orientation = "Horizontal"
Padding="5, 0, 5, 0">
<Button x:Name="reconnectButton" Clicked="ReconnectButton_Clicked"/>
<!-- Style="{Binding Source={x:Static local:App.CurrentApp.ChatHubConnection},
<Image
x:Name="reconnectImage"
Style="{Binding Source={x:Static local:App.ChatHubConnection},
Path=State,
Converter={StaticResource cxToStyleButton}}" -->
Converter={StaticResource cxToStyleImage}}" />
<Entry x:Name="messageEntry" Placeholder = "enter your Message"
VerticalOptions = "Center"
HorizontalOptions = "FillAndExpand"></Entry>

@ -29,7 +29,7 @@ namespace BookAStar.Pages
try
{
ConnectionState cs = App.CurrentApp.ChatHubConnection.State;
ConnectionState cs = App.ChatHubConnection.State;
await App.CurrentApp.ChatHubProxy.Invoke<string>("Send", ChatUser, messageEntry.Text);
messageEntry.Text = null;
@ -48,8 +48,8 @@ namespace BookAStar.Pages
try
{
await App.CurrentApp.ChatHubProxy.Invoke<string>("SendPV", ChatUser, messageEntry.Text);
messageEntry.Text = null;
await App.CurrentApp.ChatHubProxy.Invoke<string>("SendPV", ChatUser, pvEntry.Text);
pvEntry.Text = null;
}
catch (Exception ex)
{
@ -59,7 +59,8 @@ namespace BookAStar.Pages
IsBusy = false;
};
messageList.ItemsSource = Messages = new ObservableCollection<ChatMessage>();
App.CurrentApp.ChatHubConnection.StateChanged += ChatHubConnection_StateChanged;
notifList.ItemsSource = Notifs = new ObservableCollection<ChatMessage>();
App.ChatHubConnection.StateChanged += ChatHubConnection_StateChanged;
MainSettings.UserChanged += MainSettings_UserChanged;
MainSettings_UserChanged(this, null);
@ -86,8 +87,8 @@ namespace BookAStar.Pages
private void ReconnectButton_Clicked(object sender, EventArgs e)
{
App.CurrentApp.ChatHubConnection.Stop();
App.CurrentApp.ChatHubConnection.Start();
App.ChatHubConnection.Stop();
App.ChatHubConnection.Start();
}
private void MainSettings_UserChanged(object sender, EventArgs e)
@ -102,7 +103,6 @@ namespace BookAStar.Pages
Xamarin.Forms.Device.BeginInvokeOnMainThread(
() => {
sendButton.IsEnabled = obj.NewState == ConnectionState.Connected;
reconnectButton.IsEnabled = obj.NewState != ConnectionState.Connected;
});
}
}

Loading…