Merge branch 'vnext' of github.com:pazof/yavsc into vnext
This commit is contained in:
commit
fbb87fefdf
6 changed files with 120 additions and 66 deletions
|
|
@ -138,7 +138,7 @@ namespace BookAStar
|
||||||
{
|
{
|
||||||
ViewFactory.EnableCache = true;
|
ViewFactory.EnableCache = true;
|
||||||
ViewFactory.Register<ChatPage, ChatViewModel>(
|
ViewFactory.Register<ChatPage, ChatViewModel>(
|
||||||
r=> new ChatViewModel { UserName = MainSettings.UserName }
|
r=> new ChatViewModel { ChatUser = MainSettings.UserName }
|
||||||
);
|
);
|
||||||
ViewFactory.Register<DashboardPage, DashboardViewModel>(
|
ViewFactory.Register<DashboardPage, DashboardViewModel>(
|
||||||
resolver => new DashboardViewModel());
|
resolver => new DashboardViewModel());
|
||||||
|
|
@ -304,8 +304,8 @@ namespace BookAStar
|
||||||
// TODO log in debug binaries
|
// TODO log in debug binaries
|
||||||
}
|
}
|
||||||
|
|
||||||
private IHubProxy chatHubProxy = null;
|
private static IHubProxy chatHubProxy = null;
|
||||||
public IHubProxy ChatHubProxy
|
public static IHubProxy ChatHubProxy
|
||||||
{
|
{
|
||||||
get
|
get
|
||||||
{
|
{
|
||||||
|
|
|
||||||
|
|
@ -26,6 +26,9 @@ namespace BookAStar.Model
|
||||||
return UserHelpers.Avatar(Avatar);
|
return UserHelpers.Avatar(Avatar);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public string ChatHubConnectionId { get; set; }
|
||||||
|
|
||||||
public override string ToString()
|
public override string ToString()
|
||||||
{
|
{
|
||||||
return UserName;
|
return UserName;
|
||||||
|
|
|
||||||
|
|
@ -9,7 +9,6 @@
|
||||||
xmlns:local="clr-namespace:BookAStar;Assembly:BookAStar"
|
xmlns:local="clr-namespace:BookAStar;Assembly:BookAStar"
|
||||||
xmlns:extensions="clr-namespace:BookAStar.Extensions;assembly=BookAStar"
|
xmlns:extensions="clr-namespace:BookAStar.Extensions;assembly=BookAStar"
|
||||||
>
|
>
|
||||||
|
|
||||||
|
|
||||||
<TabbedPage.Resources>
|
<TabbedPage.Resources>
|
||||||
<ResourceDictionary>
|
<ResourceDictionary>
|
||||||
|
|
@ -51,19 +50,15 @@
|
||||||
<StackLayout Spacing = "12"
|
<StackLayout Spacing = "12"
|
||||||
Orientation = "Horizontal"
|
Orientation = "Horizontal"
|
||||||
Padding="5, 0, 5, 0">
|
Padding="5, 0, 5, 0">
|
||||||
<Image
|
<Image Style="{Binding Path=State, Converter={StaticResource cxToStyleImage}}" />
|
||||||
x:Name="reconnectImage"
|
|
||||||
Style="{Binding Source={x:Static local:App.ChatHubConnection},
|
|
||||||
Path=State,
|
|
||||||
Converter={StaticResource cxToStyleImage}}" />
|
|
||||||
<Entry x:Name="messageEntry" Placeholder = "enter your Message"
|
<Entry x:Name="messageEntry" Placeholder = "enter your Message"
|
||||||
VerticalOptions = "Center"
|
VerticalOptions = "Center"
|
||||||
HorizontalOptions = "FillAndExpand"></Entry>
|
HorizontalOptions = "FillAndExpand"></Entry>
|
||||||
<Button x:Name="sendButton" Text = "Send" HorizontalOptions = "End"
|
<Button x:Name="sendButton" Text = "Send" HorizontalOptions = "End"
|
||||||
VerticalOptions = "Center"></Button>
|
VerticalOptions = "Center"></Button>
|
||||||
</StackLayout>
|
</StackLayout>
|
||||||
<ListView x:Name="messageList" HasUnevenRows="true"
|
<ListView x:Name="messageList" HasUnevenRows="true" ItemsSource="{Binding Messages}">
|
||||||
>
|
|
||||||
<ListView.ItemTemplate HeightRequest="80" VerticalOptions="StartAndExpand">
|
<ListView.ItemTemplate HeightRequest="80" VerticalOptions="StartAndExpand">
|
||||||
<DataTemplate>
|
<DataTemplate>
|
||||||
<ViewCell>
|
<ViewCell>
|
||||||
|
|
@ -83,7 +78,7 @@
|
||||||
</ContentPage>
|
</ContentPage>
|
||||||
<ContentPage Title="Notifications" Icon="exclam.png" >
|
<ContentPage Title="Notifications" Icon="exclam.png" >
|
||||||
<StackLayout Padding="5, 5, 5, 5">
|
<StackLayout Padding="5, 5, 5, 5">
|
||||||
<ListView x:Name="notifList" HasUnevenRows="true">
|
<ListView x:Name="notifList" HasUnevenRows="true" ItemsSource="{Binding Notifs}">
|
||||||
<ListView.ItemTemplate HeightRequest="80" VerticalOptions="StartAndExpand">
|
<ListView.ItemTemplate HeightRequest="80" VerticalOptions="StartAndExpand">
|
||||||
<DataTemplate>
|
<DataTemplate>
|
||||||
<ViewCell>
|
<ViewCell>
|
||||||
|
|
@ -113,11 +108,11 @@
|
||||||
<!--
|
<!--
|
||||||
<controls:ExtendedPicker x:Name="contactPicker" Display="{Binding UserName}"></controls:ExtendedPicker>
|
<controls:ExtendedPicker x:Name="contactPicker" Display="{Binding UserName}"></controls:ExtendedPicker>
|
||||||
-->
|
-->
|
||||||
<controls:ExtendedPicker x:Name="contactPicker" />
|
<controls:ExtendedPicker x:Name="contactPicker" ItemsSource="{Binding Contacts}" />
|
||||||
<Button x:Name="sendPVButton" Text = "Send" HorizontalOptions = "End"
|
<Button x:Name="sendPVButton" Text = "Send" HorizontalOptions = "End"
|
||||||
VerticalOptions = "Center"></Button>
|
VerticalOptions = "Center"></Button>
|
||||||
</StackLayout>
|
</StackLayout>
|
||||||
<ListView x:Name="PVList" HasUnevenRows="true">
|
<ListView x:Name="PVList" HasUnevenRows="true" ItemsSource="{Binding PVs}">
|
||||||
<ListView.ItemTemplate HeightRequest="80"
|
<ListView.ItemTemplate HeightRequest="80"
|
||||||
VerticalOptions="StartAndExpand">
|
VerticalOptions="StartAndExpand">
|
||||||
<DataTemplate>
|
<DataTemplate>
|
||||||
|
|
|
||||||
|
|
@ -1,20 +1,16 @@
|
||||||
using BookAStar.Data;
|
using System;
|
||||||
using BookAStar.Model.Social.Messaging;
|
|
||||||
using Microsoft.AspNet.SignalR.Client;
|
|
||||||
using System;
|
|
||||||
using System.Collections.ObjectModel;
|
|
||||||
using System.Diagnostics;
|
using System.Diagnostics;
|
||||||
|
using Microsoft.AspNet.SignalR.Client;
|
||||||
using Xamarin.Forms;
|
using Xamarin.Forms;
|
||||||
using XLabs.Caching;
|
|
||||||
using XLabs.Forms.Controls;
|
|
||||||
using XLabs.Ioc;
|
|
||||||
|
|
||||||
namespace BookAStar.Pages
|
namespace BookAStar.Pages
|
||||||
{
|
{
|
||||||
|
using Data;
|
||||||
|
using Model;
|
||||||
|
using System.Linq;
|
||||||
|
using ViewModels;
|
||||||
public partial class ChatPage : TabbedPage
|
public partial class ChatPage : TabbedPage
|
||||||
{
|
{
|
||||||
public ObservableCollection<ChatMessage> Messages { get; set; }
|
|
||||||
public ObservableCollection<ChatMessage> Notifs { get; set; }
|
|
||||||
public string ChatUser { get; set; }
|
public string ChatUser { get; set; }
|
||||||
|
|
||||||
public ChatPage()
|
public ChatPage()
|
||||||
|
|
@ -22,6 +18,7 @@ namespace BookAStar.Pages
|
||||||
InitializeComponent();
|
InitializeComponent();
|
||||||
|
|
||||||
Title = "Chat";
|
Title = "Chat";
|
||||||
|
BindingContext = new ChatViewModel();
|
||||||
|
|
||||||
sendButton.Clicked += async (sender, args) =>
|
sendButton.Clicked += async (sender, args) =>
|
||||||
{
|
{
|
||||||
|
|
@ -31,7 +28,7 @@ namespace BookAStar.Pages
|
||||||
{
|
{
|
||||||
ConnectionState cs = App.ChatHubConnection.State;
|
ConnectionState cs = App.ChatHubConnection.State;
|
||||||
|
|
||||||
await App.CurrentApp.ChatHubProxy.Invoke<string>("Send", ChatUser, messageEntry.Text);
|
await App.ChatHubProxy.Invoke<string>("Send", ChatUser, messageEntry.Text);
|
||||||
messageEntry.Text = null;
|
messageEntry.Text = null;
|
||||||
}
|
}
|
||||||
catch (Exception ex)
|
catch (Exception ex)
|
||||||
|
|
@ -44,45 +41,24 @@ namespace BookAStar.Pages
|
||||||
|
|
||||||
sendPVButton.Clicked += async (sender, args) =>
|
sendPVButton.Clicked += async (sender, args) =>
|
||||||
{
|
{
|
||||||
|
string userName = contactPicker.SelectedItem as string;
|
||||||
|
if (string.IsNullOrEmpty(userName)) return;
|
||||||
|
var user = DataManager.Current.Contacts.Single(
|
||||||
|
c => c.UserName == userName);
|
||||||
|
if (string.IsNullOrEmpty(user.ChatHubConnectionId)) return;
|
||||||
IsBusy = true;
|
IsBusy = true;
|
||||||
|
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
await App.CurrentApp.ChatHubProxy.Invoke<string>("SendPV", ChatUser, pvEntry.Text);
|
await App.ChatHubProxy.Invoke<string>("SendPV", user.ChatHubConnectionId, pvEntry.Text);
|
||||||
pvEntry.Text = null;
|
pvEntry.Text = null;
|
||||||
}
|
}
|
||||||
catch (Exception ex)
|
catch (Exception ex)
|
||||||
{
|
{
|
||||||
Debug.WriteLine(ex);
|
Debug.WriteLine(ex);
|
||||||
}
|
}
|
||||||
|
|
||||||
IsBusy = false;
|
IsBusy = false;
|
||||||
};
|
};
|
||||||
messageList.ItemsSource = Messages = new ObservableCollection<ChatMessage>();
|
|
||||||
notifList.ItemsSource = Notifs = new ObservableCollection<ChatMessage>();
|
|
||||||
App.ChatHubConnection.StateChanged += ChatHubConnection_StateChanged;
|
|
||||||
MainSettings.UserChanged += MainSettings_UserChanged;
|
|
||||||
MainSettings_UserChanged(this, null);
|
|
||||||
|
|
||||||
App.CurrentApp.ChatHubProxy.On<string, string>("addMessage", (n, m) =>
|
|
||||||
{
|
|
||||||
Messages.Add(new ChatMessage
|
|
||||||
{
|
|
||||||
Message = m,
|
|
||||||
SenderId = n,
|
|
||||||
Date = DateTime.Now
|
|
||||||
});
|
|
||||||
});
|
|
||||||
|
|
||||||
App.CurrentApp.ChatHubProxy.On<string, string>("notify", (n, m) =>
|
|
||||||
{
|
|
||||||
Notifs.Add(new ChatMessage
|
|
||||||
{
|
|
||||||
Message = m,
|
|
||||||
SenderId = n,
|
|
||||||
Date = DateTime.Now
|
|
||||||
});
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private void ReconnectButton_Clicked(object sender, EventArgs e)
|
private void ReconnectButton_Clicked(object sender, EventArgs e)
|
||||||
|
|
@ -91,12 +67,6 @@ namespace BookAStar.Pages
|
||||||
App.ChatHubConnection.Start();
|
App.ChatHubConnection.Start();
|
||||||
}
|
}
|
||||||
|
|
||||||
private void MainSettings_UserChanged(object sender, EventArgs e)
|
|
||||||
{
|
|
||||||
ChatUser = MainSettings.UserName;
|
|
||||||
contactPicker.ItemsSource = DataManager.Current.Contacts;
|
|
||||||
PVList.ItemsSource = DataManager.Current.PrivateMessages;
|
|
||||||
}
|
|
||||||
|
|
||||||
private void ChatHubConnection_StateChanged(StateChange obj)
|
private void ChatHubConnection_StateChanged(StateChange obj)
|
||||||
{
|
{
|
||||||
|
|
|
||||||
|
|
@ -17,7 +17,6 @@
|
||||||
</ContentPage.Resources>
|
</ContentPage.Resources>
|
||||||
<ScrollView>
|
<ScrollView>
|
||||||
<StackLayout Padding="10,10,10,10" x:Name="mainLayout">
|
<StackLayout Padding="10,10,10,10" x:Name="mainLayout">
|
||||||
|
|
||||||
<Grid MinimumHeightRequest="12">
|
<Grid MinimumHeightRequest="12">
|
||||||
<Grid.RowDefinitions>
|
<Grid.RowDefinitions>
|
||||||
<RowDefinition Height="*" />
|
<RowDefinition Height="*" />
|
||||||
|
|
|
||||||
|
|
@ -1,16 +1,103 @@
|
||||||
using System;
|
using Microsoft.AspNet.SignalR.Client;
|
||||||
using System.Collections.Generic;
|
using System;
|
||||||
|
using System.Collections.ObjectModel;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
using System.Text;
|
|
||||||
using System.Threading.Tasks;
|
|
||||||
using XLabs.Forms.Mvvm;
|
using XLabs.Forms.Mvvm;
|
||||||
|
|
||||||
namespace BookAStar.ViewModels
|
namespace BookAStar.ViewModels
|
||||||
{
|
{
|
||||||
|
using Data;
|
||||||
|
using Model;
|
||||||
|
using Model.Social.Messaging;
|
||||||
|
|
||||||
class ChatViewModel: ViewModel
|
class ChatViewModel: ViewModel
|
||||||
{
|
{
|
||||||
public string UserName {
|
public ObservableCollection<ChatMessage> Messages { get; set; }
|
||||||
get; set;
|
public ObservableCollection<ChatMessage> Notifs { get; set; }
|
||||||
|
public ObservableCollection<ChatMessage> PVs { get; set; }
|
||||||
|
public ObservableCollection<ClientProviderInfo> Contacts { get; set; }
|
||||||
|
private string chatUser;
|
||||||
|
public string ChatUser
|
||||||
|
{
|
||||||
|
get
|
||||||
|
{
|
||||||
|
return chatUser;
|
||||||
|
}
|
||||||
|
set
|
||||||
|
{
|
||||||
|
SetProperty<string>(ref chatUser, value);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
private ConnectionState state;
|
||||||
|
public ConnectionState State
|
||||||
|
{
|
||||||
|
get { return state; }
|
||||||
|
}
|
||||||
|
|
||||||
|
public ChatViewModel()
|
||||||
|
{
|
||||||
|
App.ChatHubConnection.StateChanged += ChatHubConnection_StateChanged;
|
||||||
|
MainSettings.UserChanged += MainSettings_UserChanged;
|
||||||
|
Messages = new ObservableCollection<ChatMessage>();
|
||||||
|
Notifs = new ObservableCollection<ChatMessage>();
|
||||||
|
PVs = DataManager.Current.PrivateMessages;
|
||||||
|
Contacts = DataManager.Current.Contacts;
|
||||||
|
App.ChatHubProxy.On<string, string>("addMessage", (n, m) =>
|
||||||
|
{
|
||||||
|
Messages.Add(new ChatMessage
|
||||||
|
{
|
||||||
|
Message = m,
|
||||||
|
SenderId = n,
|
||||||
|
Date = DateTime.Now
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
App.ChatHubProxy.On<string, string, string>("notify", (eventId, cxId, userName) =>
|
||||||
|
{
|
||||||
|
// TODO make admin possible
|
||||||
|
// by assigning a server side username to anonymous.
|
||||||
|
// From now, don't log anonymous
|
||||||
|
if (!string.IsNullOrEmpty(userName))
|
||||||
|
{
|
||||||
|
Notifs.Add(new ChatMessage
|
||||||
|
{
|
||||||
|
Message = eventId,
|
||||||
|
SenderId = userName,
|
||||||
|
Date = DateTime.Now
|
||||||
|
});
|
||||||
|
if (eventId == "connected")
|
||||||
|
OnUserConnected(cxId, userName);
|
||||||
|
else if (eventId == "disconnected")
|
||||||
|
OnUserDisconnected(userName);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
ChatUser = MainSettings.UserName;
|
||||||
|
}
|
||||||
|
|
||||||
|
private void OnUserConnected(string cxId, string userName)
|
||||||
|
{
|
||||||
|
var user = Contacts.SingleOrDefault(
|
||||||
|
c => c.UserName == userName);
|
||||||
|
if (user != null)
|
||||||
|
user.ChatHubConnectionId = cxId;
|
||||||
|
}
|
||||||
|
|
||||||
|
private void OnUserDisconnected (string userName)
|
||||||
|
{
|
||||||
|
var user = Contacts.SingleOrDefault(
|
||||||
|
c => c.UserName == userName);
|
||||||
|
if (user != null)
|
||||||
|
user.ChatHubConnectionId = null;
|
||||||
|
}
|
||||||
|
|
||||||
|
private void MainSettings_UserChanged(object sender, EventArgs e)
|
||||||
|
{
|
||||||
|
ChatUser = MainSettings.UserName;
|
||||||
|
}
|
||||||
|
|
||||||
|
private void ChatHubConnection_StateChanged(StateChange obj)
|
||||||
|
{
|
||||||
|
SetProperty<ConnectionState>(ref state, obj.NewState, "State");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue