Skip to content

Commit

Permalink
Merge pull request #17 from tinyAdapter/master
Browse files Browse the repository at this point in the history
一些与MVVM架构相关的代码重构
  • Loading branch information
CHKZL authored May 12, 2020
2 parents 016041a + 20de26a commit d52cef1
Show file tree
Hide file tree
Showing 10 changed files with 411 additions and 182 deletions.
1 change: 1 addition & 0 deletions Auxiliary/Auxiliary.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -148,6 +148,7 @@
<Compile Include="Program.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
<Compile Include="RoomInit.cs" />
<Compile Include="Server.cs" />
<Compile Include="youtube.cs" />
<Compile Include="外部API.cs" />
</ItemGroup>
Expand Down
20 changes: 20 additions & 0 deletions Auxiliary/Server.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Auxiliary
{
public static class Server
{
public static readonly string PROJECT_ADDRESS = "https://github.com/CHKZL/DDTV2/releases/latest";
public static class RequestCode
{
public static readonly int GET_TOGGLE_PUSH_NOTIFICATION = 20009;
public static readonly int GET_PUSH_NOTIFICATION = 20010;
public static readonly int GET_LATEST_VERSION_NUMBER = 20011;
public static readonly int GET_UPDATE_ANNOUNCEMENT = 20011;
}
}
}
8 changes: 8 additions & 0 deletions DDTV_New/App.config
Original file line number Diff line number Diff line change
Expand Up @@ -46,4 +46,12 @@
</providers>
</roleManager>
</system.web>
<runtime>
<assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
<dependentAssembly>
<assemblyIdentity name="System.Reactive" publicKeyToken="94bc3704cddfc263" culture="neutral" />
<bindingRedirect oldVersion="0.0.0.0-4.4.0.0" newVersion="4.4.0.0" />
</dependentAssembly>
</assemblyBinding>
</runtime>
</configuration>
9 changes: 8 additions & 1 deletion DDTV_New/App.xaml.cs
Original file line number Diff line number Diff line change
@@ -1,8 +1,11 @@
using System;
using ReactiveUI;
using Splat;
using System;
using System.Collections.Generic;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Reflection;
using System.Threading.Tasks;
using System.Windows;

Expand All @@ -13,5 +16,9 @@ namespace DDTV_New
/// </summary>
public partial class App : Application
{
public App()
{
Locator.CurrentMutable.RegisterViewsForViewModels(Assembly.GetCallingAssembly());
}
}
}
40 changes: 38 additions & 2 deletions DDTV_New/DDTV_New.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@
<WarningLevel>4</WarningLevel>
<NoWarn>
</NoWarn>
<LangVersion>8.0</LangVersion>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
<PlatformTarget>AnyCPU</PlatformTarget>
Expand All @@ -56,6 +57,7 @@
<DefineConstants>TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
<LangVersion>8.0</LangVersion>
</PropertyGroup>
<PropertyGroup>
<ApplicationIcon>DDTV.ico</ApplicationIcon>
Expand All @@ -69,7 +71,7 @@
<DefineConstants>DEBUG;TRACE</DefineConstants>
<DebugType>full</DebugType>
<PlatformTarget>x86</PlatformTarget>
<LangVersion>7.3</LangVersion>
<LangVersion>8.0</LangVersion>
<ErrorReport>prompt</ErrorReport>
<CodeAnalysisRuleSet>MinimumRecommendedRules.ruleset</CodeAnalysisRuleSet>
<Prefer32Bit>true</Prefer32Bit>
Expand All @@ -80,7 +82,7 @@
<Optimize>true</Optimize>
<DebugType>pdbonly</DebugType>
<PlatformTarget>x86</PlatformTarget>
<LangVersion>7.3</LangVersion>
<LangVersion>8.0</LangVersion>
<ErrorReport>prompt</ErrorReport>
<CodeAnalysisRuleSet>MinimumRecommendedRules.ruleset</CodeAnalysisRuleSet>
<Prefer32Bit>true</Prefer32Bit>
Expand All @@ -93,6 +95,9 @@
<Reference Include="BiliAccount, Version=2.3.4.18, Culture=neutral, processorArchitecture=MSIL">
<HintPath>..\packages\BiliAccount.2.3.4.18\lib\net472\BiliAccount.dll</HintPath>
</Reference>
<Reference Include="DynamicData, Version=6.14.0.0, Culture=neutral, processorArchitecture=MSIL">
<HintPath>..\packages\DynamicData.6.14.14\lib\net461\DynamicData.dll</HintPath>
</Reference>
<Reference Include="Interop.APlayer3Lib, Version=1.0.0.0, Culture=neutral, processorArchitecture=MSIL">
<SpecificVersion>False</SpecificVersion>
<EmbedInteropTypes>True</EmbedInteropTypes>
Expand All @@ -101,12 +106,41 @@
<Reference Include="Newtonsoft.Json, Version=12.0.0.0, Culture=neutral, PublicKeyToken=30ad4fe6b2a6aeed, processorArchitecture=MSIL">
<HintPath>..\packages\Newtonsoft.Json.12.0.2\lib\net45\Newtonsoft.Json.dll</HintPath>
</Reference>
<Reference Include="Pharmacist.Common, Version=1.5.0.0, Culture=neutral, processorArchitecture=MSIL">
<HintPath>..\packages\Pharmacist.Common.1.5.15\lib\netstandard2.0\Pharmacist.Common.dll</HintPath>
</Reference>
<Reference Include="PresentationFramework.Aero" />
<Reference Include="ReactiveUI, Version=11.4.0.0, Culture=neutral, processorArchitecture=MSIL">
<HintPath>..\packages\ReactiveUI.11.4.1\lib\net461\ReactiveUI.dll</HintPath>
</Reference>
<Reference Include="ReactiveUI.Events.WPF, Version=11.4.0.0, Culture=neutral, processorArchitecture=MSIL">
<HintPath>..\packages\ReactiveUI.Events.WPF.11.4.1\lib\net461\ReactiveUI.Events.WPF.dll</HintPath>
</Reference>
<Reference Include="ReactiveUI.WPF, Version=11.4.0.0, Culture=neutral, processorArchitecture=MSIL">
<HintPath>..\packages\ReactiveUI.WPF.11.4.1\lib\net461\ReactiveUI.WPF.dll</HintPath>
</Reference>
<Reference Include="Splat, Version=9.4.0.0, Culture=neutral, processorArchitecture=MSIL">
<HintPath>..\packages\Splat.9.4.5\lib\net461\Splat.dll</HintPath>
</Reference>
<Reference Include="System" />
<Reference Include="System.Configuration" />
<Reference Include="System.Data" />
<Reference Include="System.Drawing" />
<Reference Include="System.Reactive, Version=4.4.0.0, Culture=neutral, PublicKeyToken=94bc3704cddfc263, processorArchitecture=MSIL">
<HintPath>..\packages\System.Reactive.4.4.1\lib\net46\System.Reactive.dll</HintPath>
</Reference>
<Reference Include="System.Runtime.CompilerServices.Unsafe, Version=4.0.4.1, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL">
<HintPath>..\packages\System.Runtime.CompilerServices.Unsafe.4.5.3\lib\net461\System.Runtime.CompilerServices.Unsafe.dll</HintPath>
</Reference>
<Reference Include="System.Threading.Tasks.Extensions, Version=4.2.0.1, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51, processorArchitecture=MSIL">
<HintPath>..\packages\System.Threading.Tasks.Extensions.4.5.4\lib\net461\System.Threading.Tasks.Extensions.dll</HintPath>
</Reference>
<Reference Include="System.ValueTuple, Version=4.0.3.0, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51, processorArchitecture=MSIL">
<HintPath>..\packages\System.ValueTuple.4.5.0\lib\net47\System.ValueTuple.dll</HintPath>
</Reference>
<Reference Include="System.Web" />
<Reference Include="System.Web.Extensions" />
<Reference Include="System.Windows" />
<Reference Include="System.Windows.Forms" />
<Reference Include="System.Xml" />
<Reference Include="Microsoft.CSharp" />
Expand All @@ -129,9 +163,11 @@
<SubType>Designer</SubType>
</ApplicationDefinition>
<Compile Include="Plugin\BilibiliAccount.cs" />
<Compile Include="Utility\NewThreadTask.cs" />
<Compile Include="UserControl1.xaml.cs">
<DependentUpon>UserControl1.xaml</DependentUpon>
</Compile>
<Compile Include="MainViewModel.cs" />
<Compile Include="window\BiliLoginWindowQR.xaml.cs">
<DependentUpon>BiliLoginWindowQR.xaml</DependentUpon>
</Compile>
Expand Down
118 changes: 118 additions & 0 deletions DDTV_New/MainViewModel.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,118 @@
using ReactiveUI;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Reactive.Linq;
using System.Text;
using System.Threading.Tasks;

namespace DDTV_New
{
public class MainViewModel : ReactiveObject
{
public MainViewModel()
{
_tabText = this
.WhenAnyValue(x => x.NowStreamingNum)
.Select(num =>
{
if (num == -1) return "单推列表正在更新中.....";
if (num == 0) return "监控列表中没有直播中的单推对象";
return "在监控列表中有" + num + "个单推对象正在直播";
})
.ToProperty(this, x => x.TabText);

_serverDelayBilibiliText = this
.WhenAnyValue(x => x.ServerDelayBilibili)
.Select(delay =>
{
if (delay == -1.0) return "国内服务器延迟(阿B): 未测试";
if (delay == -2.0) return "国内服务器延迟(阿B): 连接超时";
return "国内服务器延迟(阿B): " + delay + "ms";
})
.ToProperty(this, x => x.ServerDelayBilibiliText);

_serverDelayYoutubeText = this
.WhenAnyValue(x => x.ServerDelayYoutube)
.Select(delay =>
{
if (delay == -1.0) return "国外服务器延迟(404): 未测试";
if (delay == -2.0) return "国外服务器延迟(404): 连接超时";
return "国外服务器延迟(404): " + delay + "ms";
})
.ToProperty(this, x => x.ServerDelayYoutubeText);

_latestDataUpdateTimeText = this
.WhenAnyValue(x => x.LatestDataUpdateTime)
.Select(time =>
{
if (time == null) return "数据更新时间: 单推列表正在更新中.....";
return "数据更新时间: " + time.ToString("yyyy-MM-dd HH:mm:ss");
})
.ToProperty(this, x => x.LatestDataUpdateTimeText);
}

private int _tanoshiNum;
public int TanoshiNum
{
get => _tanoshiNum;
set => this.RaiseAndSetIfChanged(ref _tanoshiNum, value);
}

private string _announcement;
public string Announcement
{
get => _announcement;
set => this.RaiseAndSetIfChanged(ref _announcement, value);
}

private double _serverDelayBilibili;
public double ServerDelayBilibili
{
get => _serverDelayBilibili;
set => this.RaiseAndSetIfChanged(ref _serverDelayBilibili, value);
}
private double _serverDelayYoutube;
public double ServerDelayYoutube
{
get => _serverDelayYoutube;
set => this.RaiseAndSetIfChanged(ref _serverDelayYoutube, value);
}
private readonly ObservableAsPropertyHelper<string> _serverDelayBilibiliText;
public string ServerDelayBilibiliText => _serverDelayBilibiliText.Value;
private readonly ObservableAsPropertyHelper<string> _serverDelayYoutubeText;
public string ServerDelayYoutubeText => _serverDelayYoutubeText.Value;

private int _nowStreamingNum = -1;
public int NowStreamingNum
{
get => _nowStreamingNum;
set => this.RaiseAndSetIfChanged(ref _nowStreamingNum, value);
}
private int _notStreamingNum = -1;
public int NotStreamingNum
{
get => _notStreamingNum;
set => this.RaiseAndSetIfChanged(ref _notStreamingNum, value);
}

private readonly ObservableAsPropertyHelper<string> _tabText;
public string TabText => _tabText.Value;

private string _pushNotification;
public string PushNotification
{
get => _pushNotification;
set => this.RaiseAndSetIfChanged(ref _pushNotification, value);
}

private DateTime _latestDataUpdateTime;
public DateTime LatestDataUpdateTime
{
get => _latestDataUpdateTime;
set => this.RaiseAndSetIfChanged(ref _latestDataUpdateTime, value);
}
private readonly ObservableAsPropertyHelper<string> _latestDataUpdateTimeText;
public string LatestDataUpdateTimeText => _latestDataUpdateTimeText.Value;
}
}
15 changes: 8 additions & 7 deletions DDTV_New/MainWindow.xaml
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
<Window x:Class="DDTV_New.MainWindow"
<Window
x:Class="DDTV_New.MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
Expand All @@ -16,7 +17,7 @@
<Grid x:Name="home" Width="800" Height="515" Visibility="Collapsed">
<Image Source="res/img/home_ba.png" Stretch="Fill" Width="800" Height="515" Margin="0,-30,0,30"/>
<Image Margin="317,127,283,188" Source="res/ico/right.png" Stretch="Fill"/>
<Label x:Name="tabText" Content="单推列表正在更新中....." Margin="142,98,140,377" VerticalAlignment="Center" Height="40" HorizontalAlignment="Center" Width="518" HorizontalContentAlignment="Center" VerticalContentAlignment="Center" FontSize="24"/>
<Label x:Name="TabTextLabel" Margin="142,98,140,377" VerticalAlignment="Center" Height="40" HorizontalAlignment="Center" Width="518" HorizontalContentAlignment="Center" VerticalContentAlignment="Center" FontSize="24"/>
<Image Margin="110,326,590,89" Source="res/ico/barrage.png" Stretch="Fill" Width="100" Height="100" MouseLeftButtonDown="关注列表_点击事件"/>
<Label Content="单推列表" Margin="100,422,580,53" VerticalAlignment="Center" Height="40" HorizontalAlignment="Center" Width="120" HorizontalContentAlignment="Center" VerticalContentAlignment="Center" FontSize="24" Foreground="#FF646464"/>
<Image Margin="270,326,430,89" Source="res/ico/tools.png" Stretch="Fill" Width="100" Height="100" MouseLeftButtonDown="插件_点击事件"/>
Expand All @@ -25,14 +26,14 @@
<Label Content="其他工具" Margin="580,422,100,53" VerticalAlignment="Center" Height="40" HorizontalAlignment="Center" Width="120" HorizontalContentAlignment="Center" VerticalContentAlignment="Center" FontSize="24" Foreground="#FF646464"/>
<Image Margin="430,326,270,89" Source="res/ico/setup.png" Stretch="Fill" Width="100" Height="100" MouseLeftButtonDown="设置层_点击事件"/>
<Label Content="设置" Margin="420,422,260,53" VerticalAlignment="Center" Height="40" HorizontalAlignment="Center" Width="120" HorizontalContentAlignment="Center" VerticalContentAlignment="Center" FontSize="24" Foreground="#FF646464"/>
<Label x:Name="版本显示" Content="版本:2.0.1.2" HorizontalAlignment="Left" Margin="10,258,0,0" VerticalAlignment="Top"/>
<Label x:Name="版本显示" HorizontalAlignment="Left" Margin="10,258,0,0" VerticalAlignment="Top"/>
<Label Content="已单推" HorizontalAlignment="Left" Margin="691,228,0,0" VerticalAlignment="Top"/>
<Label x:Name="newtime" Content="数据更新时间:单推列表正在更新中....." HorizontalAlignment="Left" Margin="576,258,0,0" VerticalAlignment="Top"/>
<Label x:Name="newtime" HorizontalAlignment="Left" Margin="592,258,0,0" VerticalAlignment="Top"/>
<Label Content="" HorizontalAlignment="Left" Margin="768,228,0,0" VerticalAlignment="Top"/>
<Label x:Name="ppnum" Content="114" HorizontalAlignment="Left" Margin="730,223,0,0" VerticalAlignment="Top" Foreground="#FFFFA421" FontSize="20" HorizontalContentAlignment="Center" VerticalContentAlignment="Center" Width="45"/>
<Label x:Name="TanoshiNumLabel" HorizontalAlignment="Left" Margin="730,223,0,0" VerticalAlignment="Top" Foreground="#FFFFA421" FontSize="20" HorizontalContentAlignment="Center" VerticalContentAlignment="Center" Width="45"/>
<Label x:Name="推送内容1" Content="" VerticalAlignment="Center" HorizontalAlignment="Center" Height="31" Width="251" VerticalContentAlignment="Center" Foreground="Black" Margin="533,187,16,297" />
<Label x:Name="国内服务器延迟" Content="国内服务器延迟(阿B):" VerticalAlignment="Center" HorizontalAlignment="Center" Height="28" Width="200" VerticalContentAlignment="Center" Foreground="Black" Margin="10,229,590,258" />
<Label x:Name="国外服务器延迟" Content="服务器延迟(404):" VerticalAlignment="Center" HorizontalAlignment="Center" Height="28" Width="200" VerticalContentAlignment="Center" Foreground="Black" Margin="10,201,590,286" />
<Label x:Name="国内服务器延迟" VerticalAlignment="Center" HorizontalAlignment="Center" Height="28" Width="200" VerticalContentAlignment="Center" Foreground="Black" Margin="10,229,590,258" />
<Label x:Name="国外服务器延迟" VerticalAlignment="Center" HorizontalAlignment="Center" Height="28" Width="200" VerticalContentAlignment="Center" Foreground="Black" Margin="10,201,590,286" />
<Image Margin="10,283,740,182" Source="res/ico/帮助.png" Stretch="Fill" Width="50" Height="50" MouseLeftButtonDown="帮助_按钮事件"/>
<Label Content="说明/帮助" HorizontalAlignment="Left" Margin="4,327,0,0" VerticalAlignment="Top" Foreground="#FF4B4B4B"/>
<Image Margin="742,283,8,182" Source="res/ico/关于.png" Stretch="Fill" Width="50" Height="50" MouseLeftButtonDown="关于_按钮事件"/>
Expand Down
Loading

0 comments on commit d52cef1

Please sign in to comment.