complete the branch

This commit is contained in:
NaBian committed 2019-01-29 20:12:17 +08:00
1 parent 2c0889f64b
commit cb20ea41f6
29 files changed
+426 -115

No files matched your search

+1 -1
View File
@@ -5,7 +5,7 @@ namespace HandyControlDemo.Data
{
internal class AppConfig
{
public static string SavePath = $"{AppDomain.CurrentDomain.BaseDirectory}AppConfig.json";
public static readonly string SavePath = $"{AppDomain.CurrentDomain.BaseDirectory}AppConfig.json";
public string Lang { get; set; } = "zh-cn";
+1 -2
View File
@@ -1,5 +1,4 @@
using System;
using System.IO;
using System.IO;
using Newtonsoft.Json;
namespace HandyControlDemo.Data
+1 -5
View File
@@ -146,11 +146,7 @@
public static readonly string ClearLeftSelected = nameof(ClearLeftSelected);
public static readonly string SendChatString = nameof(SendChatString);
public static readonly string SendChatImage = nameof(SendChatImage);
public static readonly string SendChatAudio = nameof(SendChatAudio);
public static readonly string SendChatMessage = nameof(SendChatMessage);
}
}
+1 -3
View File
@@ -85,9 +85,7 @@ var messageList = new List<string>
"FullSwitch",
"ContributorsView",
"ClearLeftSelected",
"SendChatString",
"SendChatImage",
"SendChatAudio"
"SendChatMessage"
};
#>
namespace HandyControlDemo.Data
+11 -3
View File
@@ -1,9 +1,17 @@
namespace HandyControlDemo.Data
using HandyControl.Data;
namespace HandyControlDemo.Data
{
public class ChatInfoModel
public struct ChatInfoModel
{
public string Message { get; set; }
public object Message { get; set; }
public string SenderId { get; set; }
public ChatRoleType Role { get; set; }
public ChatMessageType Type { get; set; }
public object Enclosure { get; set; }
}
}
+4 -2
View File
@@ -118,9 +118,10 @@
<DependentUpon>Lang.en.resx</DependentUpon>
</Compile>
<Compile Include="Service\DataService.cs" />
<Compile Include="Tools\AssemblyHelper.cs" />
<Compile Include="Tools\CommonHelper.cs" />
<Compile Include="Tools\Helper\AssemblyHelper.cs" />
<Compile Include="Tools\Helper\CommonHelper.cs" />
<Compile Include="Tools\Converter\StringRepeatConverter.cs" />
<Compile Include="Tools\Helper\ExternDllHelper.cs" />
<Compile Include="UserControl\Basic\Avatar.xaml.cs">
<DependentUpon>Avatar.xaml</DependentUpon>
</Compile>
@@ -836,5 +837,6 @@
<Name>HandyControl</Name>
</ProjectReference>
</ItemGroup>
<ItemGroup />
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
</Project>
+9
View File
@@ -915,6 +915,15 @@ namespace HandyControlDemo.Properties.Langs {
}
}
/// <summary>
/// 查找类似 秒 的本地化字符串。
/// </summary>
public static string Second {
get {
return ResourceManager.GetString("Second", resourceCulture);
}
}
/// <summary>
/// 查找类似 选中 的本地化字符串。
/// </summary>
@@ -492,4 +492,7 @@
<data name="PushToTalk" xml:space="preserve">
<value>Push to talk</value>
</data>
<data name="Second" xml:space="preserve">
<value>Sec</value>
</data>
</root>
@@ -492,4 +492,7 @@
<data name="PushToTalk" xml:space="preserve">
<value>按住说话</value>
</data>
<data name="Second" xml:space="preserve">
<value>秒</value>
</data>
</root>
Binary file not shown.

Before

Width:  |  Height:  |  Size: 41 KiB

After

Width:  |  Height:  |  Size: 57 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 64 KiB

After

Width:  |  Height:  |  Size: 49 KiB

@@ -0,0 +1,12 @@
using System.Runtime.InteropServices;
namespace HandyControlDemo.Tools
{
internal class ExternDllHelper
{
private const string Winmm = "winmm.dll";
[DllImport(Winmm, EntryPoint = "mciSendString", CharSet = CharSet.Auto)]
public static extern int MciSendString(string lpstrCommand, string lpstrReturnString, int uReturnLength, int hwndCallback);
}
}
+29 -16
View File
@@ -5,8 +5,7 @@
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:controls="clr-namespace:HandyControl.Controls;assembly=HandyControl"
xmlns:langs="clr-namespace:HandyControlDemo.Properties.Langs"
xmlns:i="http://schemas.microsoft.com/expression/2010/interactivity"
xmlns:command="http://www.galasoft.ch/mvvmlight"
xmlns:interactivity="clr-namespace:HandyControl.Interactivity;assembly=HandyControl"
mc:Ignorable="d"
Height="486"
Effect="{StaticResource EffectShadow5}"
@@ -18,13 +17,18 @@
<RowDefinition/>
<RowDefinition Height="Auto"/>
</Grid.RowDefinitions>
<StackPanel>
<controls:ChatBubble Role="Receiver" Content="123123123123"/>
<controls:ChatBubble Content="123123123123"/>
<controls:ChatBubble Role="Receiver">
<Image Width="200" Source="/HandyControlDemo;component/Resources/Img/b1.jpg"/>
</controls:ChatBubble>
</StackPanel>
<ListBox ScrollViewer.HorizontalScrollBarVisibility="Disabled" ScrollViewer.CanContentScroll="False" Background="Transparent" controls:ChatBubble.MaxWidth="300" BorderThickness="0" Style="{StaticResource StackPanelVerticalListBox}" ItemsSource="{Binding ChatInfos}">
<interactivity:Interaction.Triggers>
<interactivity:RoutedEventTrigger RoutedEvent="controls:ChatBubble.Selected">
<interactivity:EventToCommand Command="{Binding ReadMessageCmd}" PassEventArgsToCommand="True" />
</interactivity:RoutedEventTrigger>
</interactivity:Interaction.Triggers>
<ListBox.ItemTemplate>
<DataTemplate>
<controls:ChatBubble Role="{Binding Role}" Type="{Binding Type}" Content="{Binding Message}" Tag="{Binding}"/>
</DataTemplate>
</ListBox.ItemTemplate>
</ListBox>
<Border Background="{DynamicResource DarkDefaultBrush}" Grid.Row="1">
<Grid>
<Grid.ColumnDefinitions>
@@ -34,14 +38,23 @@
</Grid.ColumnDefinitions>
<ToggleButton Name="ToggleButtonAudio" controls:BorderElement.CornerRadius="15" Width="30" Height="30" Padding="7" Margin="6" controls:IconSwitchElement.Geometry="{StaticResource AudioGeometry}" controls:IconSwitchElement.GeometrySelected="{StaticResource KeyboardGeometry}" Style="{StaticResource ToggleButtonIcon}"/>
<Button Command="{Binding OpenImageCmd}" Grid.Column="2" Margin="6,0,6,0" controls:BorderElement.CornerRadius="15" Width="30" Height="30" Padding="7" controls:IconElement.Geometry="{StaticResource ImageGeometry}"/>
<TextBox Grid.Column="1" Text="{Binding ChatString}" Visibility="{Binding IsChecked,ElementName=ToggleButtonAudio,Converter={StaticResource Boolean2VisibilityReConverter}}">
<i:Interaction.Triggers>
<i:EventTrigger EventName="KeyDown">
<command:EventToCommand Command="{Binding SendStringCmd}" PassEventArgsToCommand="True" />
</i:EventTrigger>
</i:Interaction.Triggers>
<TextBox Grid.Column="1" Text="{Binding ChatString,UpdateSourceTrigger=PropertyChanged}" Visibility="{Binding IsChecked,ElementName=ToggleButtonAudio,Converter={StaticResource Boolean2VisibilityReConverter}}">
<interactivity:Interaction.Triggers>
<interactivity:EventTrigger EventName="KeyDown">
<interactivity:EventToCommand Command="{Binding SendStringCmd}" PassEventArgsToCommand="True" />
</interactivity:EventTrigger>
</interactivity:Interaction.Triggers>
</TextBox>
<Button Grid.Column="1" Visibility="{Binding IsChecked,ElementName=ToggleButtonAudio,Converter={StaticResource Boolean2VisibilityConverter}}" Content="{x:Static langs:Lang.PushToTalk}" HorizontalAlignment="Stretch"/>
<Button Grid.Column="1" Visibility="{Binding IsChecked,ElementName=ToggleButtonAudio,Converter={StaticResource Boolean2VisibilityConverter}}" Content="{x:Static langs:Lang.PushToTalk}" HorizontalAlignment="Stretch">
<interactivity:Interaction.Triggers>
<interactivity:EventTrigger EventName="PreviewMouseLeftButtonDown">
<interactivity:EventToCommand Command="{Binding StartRecordCmd}"/>
</interactivity:EventTrigger>
<interactivity:EventTrigger EventName="PreviewMouseLeftButtonUp">
<interactivity:EventToCommand Command="{Binding StopRecordCmd}"/>
</interactivity:EventTrigger>
</interactivity:Interaction.Triggers>
</Button>
</Grid>
</Border>
</Grid>
@@ -4,7 +4,7 @@
xmlns:userControl="clr-namespace:HandyControlDemo.UserControl"
DataContext="{Binding ContributorsView,Source={StaticResource Locator}}"
Background="{DynamicResource SecondaryRegionBrush}">
<ListBox Background="{DynamicResource GitHubDrawingBrush}" ItemContainerStyle="{StaticResource ListBoxItemStyle}" BorderThickness="0" ItemsSource="{Binding DataList}" ItemsPanel="{StaticResource FluidMoveBehaviorWrapPanelItemsPanelTemplate}">
<ListBox Background="{DynamicResource GitHubDrawingBrush}" ItemContainerStyle="{StaticResource ListBoxItemCustom}" BorderThickness="0" ItemsSource="{Binding DataList}" ItemsPanel="{StaticResource FluidMoveBehaviorWrapPanelItemsPanelTemplate}">
<ListBox.ItemTemplate>
<DataTemplate>
<userControl:Avatar UserName="{Binding UserName}" Link="{Binding Link}" Source="{Binding AvatarUri}"/>
@@ -1,38 +1,42 @@
using System;
using System.Collections.ObjectModel;
using System.Diagnostics;
using System.IO;
using System.Media;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Input;
using System.Windows.Media.Imaging;
using GalaSoft.MvvmLight;
using GalaSoft.MvvmLight.CommandWpf;
using GalaSoft.MvvmLight.Messaging;
using HandyControl.Controls;
using HandyControl.Data;
using HandyControl.Tools;
using HandyControlDemo.Data;
using HandyControlDemo.Tools;
using Microsoft.Win32;
namespace HandyControlDemo.ViewModel
{
public class ChatBoxViewModel : ViewModelBase
{
private static readonly string AutioCachePath = $"{AppDomain.CurrentDomain.BaseDirectory}Cache";
private readonly string _id = Guid.NewGuid().ToString();
private readonly Stopwatch _stopwatch = new Lazy<Stopwatch>(() => new Stopwatch()).Value;
public ChatBoxViewModel()
{
Messenger.Default.Register<ChatInfoModel>(this, MessageToken.SendChatString, ReceiveString);
Messenger.Default.Register<ChatInfoModel>(this, MessageToken.SendChatImage, ReceiveImage);
Messenger.Default.Register<ChatInfoModel>(this, MessageToken.SendChatAudio, ReceiveAudio);
Messenger.Default.Register<ChatInfoModel>(this, MessageToken.SendChatMessage, ReceiveMessage);
}
private void ReceiveString(ChatInfoModel info)
private void ReceiveMessage(ChatInfoModel info)
{
if (!_id.Equals(info.SenderId)) return;
}
private void ReceiveImage(ChatInfoModel info)
{
if (!_id.Equals(info.SenderId)) return;
}
private void ReceiveAudio(ChatInfoModel info)
{
if (!_id.Equals(info.SenderId)) return;
if (_id.Equals(info.SenderId)) return;
info.Role = ChatRoleType.Receiver;
ChatInfos.Add(info);
}
private string _chatString;
@@ -43,6 +47,8 @@ namespace HandyControlDemo.ViewModel
set => Set(ref _chatString, value);
}
public ObservableCollection<ChatInfoModel> ChatInfos { get; set; } = new ObservableCollection<ChatInfoModel>();
public RelayCommand<KeyEventArgs> SendStringCmd => new Lazy<RelayCommand<KeyEventArgs>>(() =>
new RelayCommand<KeyEventArgs>(SendString)).Value;
@@ -51,15 +57,94 @@ namespace HandyControlDemo.ViewModel
if (e.Key == Key.Enter)
{
if (string.IsNullOrEmpty(ChatString)) return;
Messenger.Default.Send(new ChatInfoModel
var info = new ChatInfoModel
{
Message = ChatString,
SenderId = _id
}, MessageToken.SendChatString);
SenderId = _id,
Type = ChatMessageType.String,
Role = ChatRoleType.Sender
};
ChatInfos.Add(info);
Messenger.Default.Send(info, MessageToken.SendChatMessage);
ChatString = string.Empty;
}
}
public RelayCommand<RoutedEventArgs> ReadMessageCmd => new Lazy<RelayCommand<RoutedEventArgs>>(() =>
new RelayCommand<RoutedEventArgs>(ReadMessage)).Value;
private void ReadMessage(RoutedEventArgs e)
{
if (e.OriginalSource is FrameworkElement element && element.Tag is ChatInfoModel info)
{
if (info.Type == ChatMessageType.Image)
{
new ImageBrowser(new Uri(info.Enclosure.ToString()))
{
Owner = VisualHelper.GetActiveWindow()
}.Show();
}
else if (info.Type == ChatMessageType.Audio)
{
var player = new SoundPlayer(info.Enclosure.ToString());
player.PlaySync();
}
}
}
public RelayCommand StartRecordCmd => new Lazy<RelayCommand>(() =>
new RelayCommand(StartRecord)).Value;
private void StartRecord()
{
ExternDllHelper.MciSendString("set wave bitpersample 8", "", 0, 0);
ExternDllHelper.MciSendString("set wave samplespersec 20000", "", 0, 0);
ExternDllHelper.MciSendString("set wave channels 2", "", 0, 0);
ExternDllHelper.MciSendString("set wave format tag pcm", "", 0, 0);
ExternDllHelper.MciSendString("open new type WAVEAudio alias movie", "", 0, 0);
ExternDllHelper.MciSendString("record movie", "", 0, 0);
_stopwatch.Reset();
_stopwatch.Start();
}
public RelayCommand StopRecordCmd => new Lazy<RelayCommand>(() =>
new RelayCommand(StopRecord)).Value;
private void StopRecord()
{
if (!Directory.Exists(AutioCachePath))
{
try
{
Directory.CreateDirectory(AutioCachePath);
}
catch (Exception e)
{
Growl.Error(e.Message);
return;
}
}
var cachePath = $"{AutioCachePath}\\{Guid.NewGuid().ToString()}";
ExternDllHelper.MciSendString("stop movie", "", 0, 0);
ExternDllHelper.MciSendString($"save movie {cachePath}", "", 0, 0);
ExternDllHelper.MciSendString("close movie", "", 0, 0);
_stopwatch.Stop();
var info = new ChatInfoModel
{
Message = $"{_stopwatch.Elapsed.Seconds.ToString()} {Properties.Langs.Lang.Second}",
SenderId = _id,
Type = ChatMessageType.Audio,
Role = ChatRoleType.Sender,
Enclosure = cachePath
};
ChatInfos.Add(info);
Messenger.Default.Send(info, MessageToken.SendChatMessage);
}
public RelayCommand OpenImageCmd => new Lazy<RelayCommand>(() =>
new RelayCommand(OpenImage)).Value;
@@ -71,11 +156,16 @@ namespace HandyControlDemo.ViewModel
var fileName = dialog.FileName;
if (File.Exists(fileName))
{
Messenger.Default.Send(new ChatInfoModel
var info = new ChatInfoModel
{
Message = fileName,
SenderId = _id
}, MessageToken.SendChatImage);
Message = BitmapFrame.Create(new Uri(fileName)),
SenderId = _id,
Type = ChatMessageType.Image,
Role = ChatRoleType.Sender,
Enclosure = fileName
};
ChatInfos.Add(info);
Messenger.Default.Send(info, MessageToken.SendChatMessage);
}
}
}
@@ -46,7 +46,7 @@ namespace HandyControlDemo.ViewModel
public PaginationDemoViewModel PaginationDemo => ServiceLocator.Current.GetInstance<PaginationDemoViewModel>();
public ChatBoxViewModel ChatBox => ServiceLocator.Current.GetInstance<ChatBoxViewModel>();
public ChatBoxViewModel ChatBox => new ChatBoxViewModel();
#endregion
}