A Chat window
This commit is contained in:
parent
1bffe247e3
commit
c88fc39a29
11 changed files with 137 additions and 1 deletions
|
|
@ -103,6 +103,9 @@ namespace BookAStar
|
|||
private void Configure(IXFormsApp app)
|
||||
{
|
||||
ViewFactory.EnableCache = true;
|
||||
ViewFactory.Register<ChatPage, ChatViewModel>(
|
||||
r=> new ChatViewModel { UserName = MainSettings.UserName }
|
||||
);
|
||||
ViewFactory.Register<DashboardPage, DashboardViewModel>(
|
||||
resolver => new DashboardViewModel());
|
||||
ViewFactory.Register<BookQueryPage, BookQueryViewModel>();
|
||||
|
|
@ -180,12 +183,24 @@ namespace BookAStar
|
|||
Text = "Accueil",
|
||||
Icon = "icon.png"
|
||||
};
|
||||
ToolbarItem tiPubChat= new ToolbarItem()
|
||||
{
|
||||
Text = "Chat",
|
||||
Icon = "chat_icon_s.png"
|
||||
};
|
||||
tiPubChat.Clicked += TiPubChat_Clicked;
|
||||
masterDetail.ToolbarItems.Add(tiHome);
|
||||
masterDetail.ToolbarItems.Add(tiSetts);
|
||||
masterDetail.ToolbarItems.Add(tiPubChat);
|
||||
this.MainPage = masterDetail;
|
||||
NavigationService = new NavigationService(masterDetail.Detail.Navigation);
|
||||
}
|
||||
|
||||
private void TiPubChat_Clicked(object sender, EventArgs e)
|
||||
{
|
||||
NavigationService.NavigateTo<ChatPage>();
|
||||
}
|
||||
|
||||
public static INavigationService NavigationService { protected set; get; }
|
||||
public void PostDeviceInfo()
|
||||
{
|
||||
|
|
|
|||
|
|
@ -77,6 +77,9 @@
|
|||
<Compile Include="Pages\BookQueryPage.xaml.cs">
|
||||
<DependentUpon>BookQueryPage.xaml</DependentUpon>
|
||||
</Compile>
|
||||
<Compile Include="Pages\ChatPage.xaml.cs">
|
||||
<DependentUpon>ChatPage.xaml</DependentUpon>
|
||||
</Compile>
|
||||
<Compile Include="Pages\EditBillingLinePage.xaml.cs">
|
||||
<DependentUpon>EditBillingLinePage.xaml</DependentUpon>
|
||||
</Compile>
|
||||
|
|
@ -138,6 +141,7 @@
|
|||
<Compile Include="ViewModels\BookQueriesViewModel.cs" />
|
||||
<Compile Include="ViewModels\BookQueryViewModel.cs" />
|
||||
<Compile Include="ViewModels\BillingLineViewModel.cs" />
|
||||
<Compile Include="ViewModels\ChatViewModel.cs" />
|
||||
<Compile Include="ViewModels\DashboardViewModel.cs" />
|
||||
<Compile Include="ViewModels\EstimateViewModel.cs" />
|
||||
<Compile Include="ViewModels\UserLoginViewModel.cs" />
|
||||
|
|
@ -218,6 +222,14 @@
|
|||
<HintPath>..\..\packages\SQLite.Net-PCL.3.1.1\lib\portable-win8+net45+wp8+wpa81+MonoAndroid1+MonoTouch1\SQLite.Net.dll</HintPath>
|
||||
<Private>True</Private>
|
||||
</Reference>
|
||||
<Reference Include="System.Net.Http.Extensions, Version=1.5.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL">
|
||||
<HintPath>..\..\packages\Microsoft.Net.Http.2.2.29\lib\portable-net45+win8+wpa81\System.Net.Http.Extensions.dll</HintPath>
|
||||
<Private>True</Private>
|
||||
</Reference>
|
||||
<Reference Include="System.Net.Http.Primitives, Version=4.2.29.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL">
|
||||
<HintPath>..\..\packages\Microsoft.Net.Http.2.2.29\lib\portable-net45+win8+wpa81\System.Net.Http.Primitives.dll</HintPath>
|
||||
<Private>True</Private>
|
||||
</Reference>
|
||||
<Reference Include="Xamarin.Forms.Core, Version=2.0.0.0, Culture=neutral, processorArchitecture=MSIL">
|
||||
<HintPath>..\..\packages\Xamarin.Forms.2.3.2.127\lib\portable-win+net45+wp80+win81+wpa81+MonoAndroid10+MonoTouch10+Xamarin.iOS10\Xamarin.Forms.Core.dll</HintPath>
|
||||
<Private>True</Private>
|
||||
|
|
@ -329,6 +341,15 @@
|
|||
<SubType>Designer</SubType>
|
||||
</EmbeddedResource>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<EmbeddedResource Include="Pages\ChatPage.xaml">
|
||||
<Generator>MSBuild:UpdateDesignTimeXaml</Generator>
|
||||
<SubType>Designer</SubType>
|
||||
</EmbeddedResource>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<EmbeddedResource Include="Images\Chat\chat_icon_s.png" />
|
||||
</ItemGroup>
|
||||
<Import Project="$(MSBuildExtensionsPath32)\Microsoft\Portable\$(TargetFrameworkVersion)\Microsoft.Portable.CSharp.targets" />
|
||||
<Import Project="..\..\packages\Xamarin.Forms.2.3.2.127\build\portable-win+net45+wp80+win81+wpa81+MonoAndroid10+MonoTouch10+Xamarin.iOS10\Xamarin.Forms.targets" Condition="Exists('..\..\packages\Xamarin.Forms.2.3.2.127\build\portable-win+net45+wp80+win81+wpa81+MonoAndroid10+MonoTouch10+Xamarin.iOS10\Xamarin.Forms.targets')" />
|
||||
<Target Name="EnsureNuGetPackageBuildImports" BeforeTargets="PrepareForBuild">
|
||||
|
|
@ -337,6 +358,11 @@
|
|||
</PropertyGroup>
|
||||
<Error Condition="!Exists('..\..\packages\Xamarin.Forms.2.3.2.127\build\portable-win+net45+wp80+win81+wpa81+MonoAndroid10+MonoTouch10+Xamarin.iOS10\Xamarin.Forms.targets')" Text="$([System.String]::Format('$(ErrorText)', '..\..\packages\Xamarin.Forms.2.3.2.127\build\portable-win+net45+wp80+win81+wpa81+MonoAndroid10+MonoTouch10+Xamarin.iOS10\Xamarin.Forms.targets'))" />
|
||||
</Target>
|
||||
<Import Project="..\..\packages\Microsoft.Bcl.Build.1.0.14\tools\Microsoft.Bcl.Build.targets" Condition="Exists('..\..\packages\Microsoft.Bcl.Build.1.0.14\tools\Microsoft.Bcl.Build.targets')" />
|
||||
<Target Name="EnsureBclBuildImported" BeforeTargets="BeforeBuild" Condition="'$(BclBuildImported)' == ''">
|
||||
<Error Condition="!Exists('..\..\packages\Microsoft.Bcl.Build.1.0.14\tools\Microsoft.Bcl.Build.targets')" Text="This project references NuGet package(s) that are missing on this computer. Enable NuGet Package Restore to download them. For more information, see http://go.microsoft.com/fwlink/?LinkID=317567." HelpKeyword="BCLBUILD2001" />
|
||||
<Error Condition="Exists('..\..\packages\Microsoft.Bcl.Build.1.0.14\tools\Microsoft.Bcl.Build.targets')" Text="The build restored NuGet packages. Build the project again to include these packages in the build. For more information, see http://go.microsoft.com/fwlink/?LinkID=317568." HelpKeyword="BCLBUILD2002" />
|
||||
</Target>
|
||||
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
|
||||
Other similar extension points exist, see Microsoft.Common.targets.
|
||||
<Target Name="BeforeBuild">
|
||||
|
|
|
|||
|
|
@ -19,7 +19,7 @@ namespace BookAStar
|
|||
public static readonly string UserInfoUrl = YavscApiUrl + "/me";
|
||||
public static readonly string BlogUrl = YavscApiUrl + "/blogs";
|
||||
public static readonly string FsUrl = YavscApiUrl + "/fs";
|
||||
|
||||
public static readonly string SignalRHubsUrl = YavscHomeUrl + "/signalr/hubs";
|
||||
#endregion
|
||||
|
||||
}
|
||||
|
|
|
|||
BIN
BookAStar/BookAStar/Images/Chat/chat_icon_s.png
Normal file
BIN
BookAStar/BookAStar/Images/Chat/chat_icon_s.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 1 KiB |
BIN
BookAStar/BookAStar/Images/chat_icon.png
Normal file
BIN
BookAStar/BookAStar/Images/chat_icon.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 1.9 KiB |
BIN
BookAStar/BookAStar/Images/chat_icon_l.png
Normal file
BIN
BookAStar/BookAStar/Images/chat_icon_l.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 7.2 KiB |
BIN
BookAStar/BookAStar/Images/chat_icon_m.png
Normal file
BIN
BookAStar/BookAStar/Images/chat_icon_m.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 3.8 KiB |
22
BookAStar/BookAStar/Pages/ChatPage.xaml
Normal file
22
BookAStar/BookAStar/Pages/ChatPage.xaml
Normal file
|
|
@ -0,0 +1,22 @@
|
|||
<?xml version="1.0" encoding="utf-8" ?>
|
||||
<ContentPage xmlns="http://xamarin.com/schemas/2014/forms"
|
||||
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
|
||||
x:Class="BookAStar.Pages.ChatPage"
|
||||
>
|
||||
|
||||
<StackLayout Padding="5, 5, 5, 5">
|
||||
<StackLayout Spacing = "12"
|
||||
Orientation = "Horizontal"
|
||||
Padding="5, 0, 5, 0">
|
||||
<Entry x:Name="messageEntry" Placeholder = "enter your Message"
|
||||
VerticalOptions = "Center"
|
||||
HorizontalOptions = "FillAndExpand"></Entry>
|
||||
<Button x:Name="sendButton" Text = "Send" HorizontalOptions = "End"
|
||||
VerticalOptions = "Center"></Button>
|
||||
|
||||
<Label Text="{Binding MainText}" VerticalOptions="Center" HorizontalOptions="Center" />
|
||||
|
||||
</StackLayout>
|
||||
<ListView x:Name="messageList"></ListView>
|
||||
</StackLayout>
|
||||
</ContentPage>
|
||||
54
BookAStar/BookAStar/Pages/ChatPage.xaml.cs
Normal file
54
BookAStar/BookAStar/Pages/ChatPage.xaml.cs
Normal file
|
|
@ -0,0 +1,54 @@
|
|||
using Microsoft.AspNet.SignalR.Client;
|
||||
using System;
|
||||
using System.Collections.ObjectModel;
|
||||
using System.Diagnostics;
|
||||
using Xamarin.Forms;
|
||||
|
||||
namespace BookAStar.Pages
|
||||
{
|
||||
public partial class ChatPage : ContentPage
|
||||
{
|
||||
public ObservableCollection<string> Messages { get; set; }
|
||||
public string ChatUser { get; set; }
|
||||
|
||||
private HubConnection chatHubConnection;
|
||||
private IHubProxy chatHubProxy;
|
||||
|
||||
public ChatPage()
|
||||
{
|
||||
InitializeComponent();
|
||||
|
||||
Title = "Chat";
|
||||
|
||||
sendButton.Clicked += async (sender, args) => {
|
||||
IsBusy = true;
|
||||
|
||||
try
|
||||
{
|
||||
await chatHubProxy.Invoke<string>("Send", ChatUser, messageEntry.Text);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
|
||||
Debug.WriteLine(ex);
|
||||
}
|
||||
|
||||
IsBusy = false;
|
||||
};
|
||||
messageList.ItemsSource = Messages = new ObservableCollection<string>();
|
||||
}
|
||||
|
||||
protected override async void OnAppearing()
|
||||
{
|
||||
IsBusy = true;
|
||||
chatHubConnection = new HubConnection(Constants.SignalRHubsUrl);
|
||||
chatHubProxy = chatHubConnection.CreateHubProxy("ChatHub");
|
||||
chatHubProxy.On<string, string>("AddMessage", (n, m) => {
|
||||
Messages.Add(string.Format("{0} says: {1}", n, m));
|
||||
});
|
||||
await chatHubConnection.Start();
|
||||
IsBusy = false;
|
||||
sendButton.IsEnabled = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
16
BookAStar/BookAStar/ViewModels/ChatViewModel.cs
Normal file
16
BookAStar/BookAStar/ViewModels/ChatViewModel.cs
Normal file
|
|
@ -0,0 +1,16 @@
|
|||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using XLabs.Forms.Mvvm;
|
||||
|
||||
namespace BookAStar.ViewModels
|
||||
{
|
||||
class ChatViewModel: ViewModel
|
||||
{
|
||||
public string UserName {
|
||||
get; set;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -4,6 +4,9 @@
|
|||
<package id="Json.NET.Web" version="1.0.49" targetFramework="portable45-net45+win8+wpa81" />
|
||||
<package id="MarkdownDeep.NET" version="1.5" targetFramework="portable45-net45+win8+wpa81" />
|
||||
<package id="Microsoft.AspNet.SignalR.Client" version="2.2.1" targetFramework="portable45-net45+win8+wpa81" />
|
||||
<package id="Microsoft.Bcl" version="1.1.10" targetFramework="portable45-net45+win8+wpa81" />
|
||||
<package id="Microsoft.Bcl.Build" version="1.0.14" targetFramework="portable45-net45+win8+wpa81" />
|
||||
<package id="Microsoft.Net.Http" version="2.2.29" targetFramework="portable45-net45+win8+wpa81" />
|
||||
<package id="Newtonsoft.Json" version="9.0.1" targetFramework="portable45-net45+win8+wpa81" />
|
||||
<package id="SQLite.Net.Core-PCL" version="3.1.1" targetFramework="portable45-net45+win8+wpa81" />
|
||||
<package id="SQLite.Net-PCL" version="3.1.1" targetFramework="portable45-net45+win8+wpa81" />
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue