diff --git a/src/Common.ClientLib.Droid/Application/Services/Implementation/PlatformNotificationServiceImpl`2.cs b/src/Common.ClientLib.Droid/Application/Services/Implementation/PlatformNotificationServiceImpl`2.cs index 1a0715772..3470ab6e6 100644 --- a/src/Common.ClientLib.Droid/Application/Services/Implementation/PlatformNotificationServiceImpl`2.cs +++ b/src/Common.ClientLib.Droid/Application/Services/Implementation/PlatformNotificationServiceImpl`2.cs @@ -199,11 +199,9 @@ namespace System.Application.Services.Implementation TNotificationType notificationType, bool autoCancel, string? title, - TEntrance entrance) + TEntrance? entrance) { - var notificationEntrance = entrance != null ? - GetActivityType(entrance).GetJClass() : - R.activities.entrance; + var notificationEntrance = (entrance != null ? GetActivityType(entrance)?.GetJClass() : null) ?? R.activities.entrance; var context = AndroidApplication.Context; var manager = NotificationManagerCompat.From(context); var builder = BuildNotify(context, manager, text, notificationType, @@ -213,24 +211,25 @@ namespace System.Application.Services.Implementation } public Progress NotifyDownload( - string text, + Func text, TNotificationType notificationType, string? title) { var context = AndroidApplication.Context; var manager = NotificationManagerCompat.From(context); var builder = BuildNotify(context, manager, - text: text.Format(0), + text: text(), notificationType, title: title); // 进度单位说明 // 通用层采用 float 浮点数作为进度值,范围从0~100,保留两位小数 // 平台层采用 int 整型作为进度值,范围从0~10000,转换需要 乘 100 const int unit_convert_multiple = 100; // 从float到int转换单位倍数 - const int PROGRESS_MAX = 100 * unit_convert_multiple; // 进度条满值 + const float PROGRESS_MAX = IAppUpdateService.MaxProgressValue * unit_convert_multiple; // 进度条满值 + int PROGRESS_MAX_INT32 = PROGRESS_MAX.ToInt32(); // 发出零进度的初始通知 // Issue the initial notification with zero progress - builder.SetProgress(PROGRESS_MAX, 0, false); + builder.SetProgress(PROGRESS_MAX_INT32, 0, false); var notifyId = GetNotifyId(notificationType); manager.Notify(notifyId, builder.Build()); // 在这里完成跟踪进度的工作。 @@ -248,7 +247,7 @@ namespace System.Application.Services.Implementation void Handler(float current) { var currentInt32 = (current * unit_convert_multiple).ToInt32(); - if (currentInt32 >= PROGRESS_MAX) + if (currentInt32 >= PROGRESS_MAX_INT32) { // 这将使100%时直接取消通知,并不会在UI上显示 // 报告进度值满的操作应当是幂等的 @@ -266,8 +265,8 @@ namespace System.Application.Services.Implementation // 在报告进度值满后不可再更改进度 if (builder == null) throw new ArgumentNullException(nameof(builder)); if (manager == null) throw new ArgumentNullException(nameof(manager)); - builder.SetProgress(PROGRESS_MAX, currentInt32, false); - builder.SetContentText(text.Format(currentInt32)); + builder.SetProgress(PROGRESS_MAX_INT32, currentInt32, false); + builder.SetContentText(text()); manager.Notify(notifyId, builder.Build()); } } diff --git a/src/Common.ClientLib/Application/Services/INotificationService.cs b/src/Common.ClientLib/Application/Services/INotificationService.cs index 82685e1c9..fd7bd569c 100644 --- a/src/Common.ClientLib/Application/Services/INotificationService.cs +++ b/src/Common.ClientLib/Application/Services/INotificationService.cs @@ -45,7 +45,7 @@ namespace System.Application.Services /// 下载进度通知 /// Progress NotifyDownload( - string text, + Func text, TNotificationType notificationType, string? title = default); } diff --git a/src/ST.Client.Desktop.Avalonia/Application/UI/Views/Windows/LocalAuthPage/AddAuthWindow.axaml b/src/ST.Client.Desktop.Avalonia/Application/UI/Views/Windows/LocalAuthPage/AddAuthWindow.axaml index 7c9b4889b..d22a128b8 100644 --- a/src/ST.Client.Desktop.Avalonia/Application/UI/Views/Windows/LocalAuthPage/AddAuthWindow.axaml +++ b/src/ST.Client.Desktop.Avalonia/Application/UI/Views/Windows/LocalAuthPage/AddAuthWindow.axaml @@ -2,7 +2,10 @@ xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:d="http://schemas.microsoft.com/expression/blend/2008" xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" - mc:Ignorable="d" d:DesignWidth="800" d:DesignHeight="450" + mc:Ignorable="d" + d:DesignWidth="720" d:DesignHeight="400" + MinWidth="720" MinHeight="400" + Width="720" Height="400" x:Class="System.Application.UI.Views.Windows.AddAuthWindow" xmlns:resx="clr-namespace:System.Application.UI.Resx;assembly=System.Application.SteamTools.Client.Desktop" xmlns:vm="clr-namespace:System.Application.UI.ViewModels;assembly=System.Application.SteamTools.Client.Desktop" @@ -10,8 +13,6 @@ xmlns:controls="clr-namespace:System.Application.UI.Views.Controls" xmlns:ms="clr-namespace:System.Application.Models.Settings;assembly=System.Application.SteamTools.Client.Desktop" FontFamily="{Binding Source={x:Static ms:UISettings.FontName},Path=Value, Mode=OneWay,Converter={StaticResource NameToFontFamilyConverter}}" - MinWidth="600" - MinHeight="400" WindowStartupLocation="CenterOwner" ExtendClientAreaTitleBarHeightHint="30" Background="Transparent" diff --git a/src/ST.Client.Mobile.Droid/Services/Implementation/MobileAppUpdateServiceImpl.cs b/src/ST.Client.Mobile.Droid/Services/Implementation/MobileAppUpdateServiceImpl.cs index 13a6d1a96..c2c35d600 100644 --- a/src/ST.Client.Mobile.Droid/Services/Implementation/MobileAppUpdateServiceImpl.cs +++ b/src/ST.Client.Mobile.Droid/Services/Implementation/MobileAppUpdateServiceImpl.cs @@ -6,13 +6,16 @@ using System.Application.Models; using System.Windows; using XEPlatform = Xamarin.Essentials.Platform; using static System.Application.UI.Resx.AppResources; +using static System.Application.Services.IAppUpdateService; namespace System.Application.Services.Implementation { internal sealed partial class MobileAppUpdateServiceImpl : AppUpdateServiceImpl { - public MobileAppUpdateServiceImpl(IToast toast, ICloudServiceClient client, IOptions options) : base(toast, client, options) + readonly INotificationService notification; + public MobileAppUpdateServiceImpl(INotificationService notification, IToast toast, ICloudServiceClient client, IOptions options) : base(toast, client, options) { + this.notification = notification; } protected override Version OSVersion => @@ -46,5 +49,26 @@ namespace System.Application.Services.Implementation throw new NotImplementedException(); #endif } + + IProgress? progress; + protected override void OnReport(float value, string str) + { + base.OnReport(value, str); + if (value == 0) + { + progress?.Report(MaxProgressValue); + progress = notification.NotifyDownload(() => ProgressString, + NotificationType.NewVersionDownloadProgress); + } + else if (value == MaxProgressValue) + { + progress?.Report(MaxProgressValue); + progress = null; + } + else + { + progress?.Report(value); + } + } } } \ No newline at end of file diff --git a/src/ST.Client.Mobile.Droid/UI/MainApplication.cs b/src/ST.Client.Mobile.Droid/UI/MainApplication.cs index 94002927d..dee91908a 100644 --- a/src/ST.Client.Mobile.Droid/UI/MainApplication.cs +++ b/src/ST.Client.Mobile.Droid/UI/MainApplication.cs @@ -13,6 +13,8 @@ using XEPlatform = Xamarin.Essentials.Platform; using XEVersionTracking = Xamarin.Essentials.VersionTracking; using System.Application.Models.Settings; using AndroidX.AppCompat.App; +using System.Application.Services; +using System.Application.Services.Implementation; #if DEBUG using Square.LeakCanary; #endif @@ -79,6 +81,10 @@ namespace System.Application.UI Startup.Init(level); if (IsMainProcess) { + if (INotificationService.Instance is PlatformNotificationServiceImpl notification) + { + notification.InitNotificationChannels(this); + } XEVersionTracking.Track(); ImageLoader.Init(this); UISettings.Theme.Subscribe(x => diff --git a/src/ST.Client/NotificationType_Channel_EnumExtensions.cs b/src/ST.Client/Extensions/NotificationType_Channel_EnumExtensions.cs similarity index 98% rename from src/ST.Client/NotificationType_Channel_EnumExtensions.cs rename to src/ST.Client/Extensions/NotificationType_Channel_EnumExtensions.cs index 183a37041..cf3fa2e5a 100644 --- a/src/ST.Client/NotificationType_Channel_EnumExtensions.cs +++ b/src/ST.Client/Extensions/NotificationType_Channel_EnumExtensions.cs @@ -1,4 +1,4 @@ -using System.Application.Properties; +using System.Application.Properties; using System.Application.Services; namespace System.Application diff --git a/src/ST.Client/ST.Client.csproj b/src/ST.Client/ST.Client.csproj index bb5015afd..aadc6b3c0 100644 --- a/src/ST.Client/ST.Client.csproj +++ b/src/ST.Client/ST.Client.csproj @@ -23,16 +23,16 @@ - + - - - - - - + + + + + + diff --git a/src/ST.Client/Services/Implementation/AppUpdateServiceImpl.cs b/src/ST.Client/Services/Implementation/AppUpdateServiceImpl.cs index 90cc4d734..8c54a0862 100644 --- a/src/ST.Client/Services/Implementation/AppUpdateServiceImpl.cs +++ b/src/ST.Client/Services/Implementation/AppUpdateServiceImpl.cs @@ -211,7 +211,7 @@ namespace System.Application.Services.Implementation protected void OnReportCalcHashing(float value) => OnReport(value, SR.CalcHashing_.Format(MathF.Round(value, 2))); protected void OnReportDecompressing(float value) => OnReport(value, SR.Decompressing_.Format(MathF.Round(value, 2))); protected void OnReport(float value = 0f) => OnReport(value, string.Empty); - protected void OnReport(float value, string str) + protected virtual void OnReport(float value, string str) { ProgressValue = value; ProgressString = str; diff --git a/src/ST/NotificationType.cs b/src/ST/NotificationType.cs index c14e2f7b5..f21995962 100644 --- a/src/ST/NotificationType.cs +++ b/src/ST/NotificationType.cs @@ -1,4 +1,4 @@ -namespace System.Application +namespace System.Application { /// /// 通知类型 @@ -17,7 +17,7 @@ /// /// /// 添加新的枚举常量注意事项: - /// (客户端)如果要显示在设备的通知栏上,则需要在中添加对应渠道 + /// (客户端)如果要显示在设备的通知栏上,则需要在 src\ST.Client\Extensions\NotificationType_Channel_EnumExtensions.cs 中添加或指定已有渠道 /// public enum NotificationType {