Skip to content

Commit

Permalink
增强Image2的功能优化所有头像加载逻辑
Browse files Browse the repository at this point in the history
  • Loading branch information
rmbadmin committed Nov 3, 2021
1 parent e86e95c commit f67d9ab
Show file tree
Hide file tree
Showing 23 changed files with 67 additions and 87 deletions.
2 changes: 1 addition & 1 deletion references/AvaloniaGif
2 changes: 1 addition & 1 deletion src/ST.Client.Desktop.Avalonia.App/Views/MainWindow.axaml
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
x:DataType="vm:MainWindowViewModel"
x:CompileBindings="True">
<Panel Margin="{Binding #MainWindow.OffScreenMargin}">
<controls:EmptyControl x:Name="DesktopBackground"
<controls:WallpaperControl x:Name="DesktopBackground"
IsVisible="{ReflectionBinding Source={x:Static ms:UISettings.EnableDesktopBackground},Path=Value,Mode=TwoWay}"/>
<local:MainView DataContext="{Binding}"/>
<!--<controls:WebView3 IsVisible="False" InitialUrl="chrome://version"></controls:WebView3>-->
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ public MainWindow() : base()
{
InitializeComponent();

var background = this.FindControl<EmptyControl>("DesktopBackground");
var background = this.FindControl<WallpaperControl>("DesktopBackground");
_backHandle = background.Handle;

#if DEBUG
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,15 +8,15 @@

namespace System.Application.UI.Views.Controls
{
public class EmptyControl : TemplatedControl
public class WallpaperControl : TemplatedControl
{
readonly INativeWindowApiService windowApiService = INativeWindowApiService.Instance;

Window window;
Window ParentWindow;
IntPtr _Handle;
IntPtr _DwmHandle;
public EmptyControl()
public WallpaperControl()
{
//this.InitializeComponent();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -120,17 +120,18 @@
HorizontalAlignment="Stretch">
<!--<Image x:Name="avatar" Source="/Application/UI/Assets/Icon.ico" Height="64" Width="64"/>
<Label Content="{ReflectionBinding Path=Title}" Foreground="{DynamicResource HighlightForegroundBrushKey}" VerticalContentAlignment="Center" FontSize="18" Margin="8,0,0,0"/>-->
<Image x:Name="avatar" Clip=""
Source="{ReflectionBinding Path=AvatarPath, Source={x:Static service:UserService.Current},Mode=OneWay,Converter={StaticResource BitmapAssetValueConverter},ConverterParameter=64}"
<gif:Image2 x:Name="avatar"
Source="{ReflectionBinding Path=AvatarPath, Source={x:Static service:UserService.Current},Mode=OneWay}"
Stretch="Uniform"
VerticalAlignment="Center"
HorizontalAlignment="Left"
Height="64"
Width="64">
<Image.Clip>
Width="64"
FallbackSource="avares://System.Application.SteamTools.Client.Avalonia/Application/UI/Assets/AppResources/avatar.jpg">
<gif:Image2.Clip>
<EllipseGeometry Rect="0,0,64,64" />
</Image.Clip>
</Image>
</gif:Image2.Clip>
</gif:Image2>
<StackPanel Spacing="5" VerticalAlignment="Center">
<TextBlock Text="{ReflectionBinding Path=Res.User_UnLogin,Mode=OneWay,Source={x:Static resx:R.Current}}"
IsVisible="{ReflectionBinding Path=User,Mode=OneWay,Source={x:Static service:UserService.Current},Converter={StaticResource IsNullConverter}}"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
using Avalonia.Media;
using Avalonia.Platform;
using Avalonia.ReactiveUI;
using AvaloniaGif;
using FluentAvalonia.UI.Controls;
using FluentAvalonia.UI.Media.Animation;
using System.Application.Settings;
Expand All @@ -25,7 +26,7 @@ public MainView()
{
InitializeComponent();

var avatar = this.FindControl<Image>("avatar");
var avatar = this.FindControl<Image2>("avatar");
var nav = this.FindControl<NavigationView>("NavigationView");
var back = this.FindControl<ExperimentalAcrylicBorder>("NavBarBackground");

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,15 +54,9 @@
<gif:Image2
Width="184"
Stretch="Uniform"
Source="{Binding AvatarUrl}">
Source="{Binding AvatarUrl}"
FallbackSource="avares://System.Application.SteamTools.Client.Avalonia/Application/UI/Assets/AppResources/avatar.jpg">
</gif:Image2>
<!--<Image Width="184"
Stretch="Uniform"
Source="{Binding AvatarUrl,Converter={StaticResource BitmapAssetValueConverter}}">
</Image>-->
<!--<Image Width="184" Stretch="Uniform" IsVisible="{Binding AvatarStream^,Converter={StaticResource IsNullConverter}}"
Source="avares://System.Application.SteamTools.Client.Avalonia/Application/UI/Assets/AppResources/avatar.jpg">
</Image>-->
</Panel>
<Panel Grid.Column="1" Margin="10 5">
<StackPanel Spacing="8">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
Background="{DynamicResource ThemeBrushKey}"
Padding="10"
Margin="{StaticResource ScrollMargin}">
<ui:CommandBar DefaultLabelPosition="Right"
<ui:CommandBar DefaultLabelPosition="Right"
IsSticky="False">
<ui:CommandBar.PrimaryCommands>
<ui:CommandBarButton Icon="Add"
Expand Down Expand Up @@ -95,7 +95,7 @@
</ia:EventTriggerBehavior>
</i:Interaction.Behaviors>

<Grid Height="184"
<Grid Height="224"
ColumnDefinitions="Auto,*">
<Border CornerRadius="{StaticResource PaperRadiusLeft}"
ClipToBounds="True">
Expand All @@ -112,18 +112,15 @@
Width="184"
AutoStart="true"
Stretch="Uniform"
Source="{Binding AvatarStream^}">
Source="{Binding AvatarStream^}"
FallbackSource="avares://System.Application.SteamTools.Client.Avalonia/Application/UI/Assets/AppResources/avatar.jpg">
</gif:Image2>
<Image Width="184"
Stretch="Uniform"
IsVisible="{Binding AvatarStream^,Converter={StaticResource IsNullConverter}}"
Source="avares://System.Application.SteamTools.Client.Avalonia/Application/UI/Assets/AppResources/avatar.jpg">
</Image>
<!--<gif:Image2 Width="184" Height="184"
AutoStart="true"
Source="{Binding MiniProfile.AvatarFrameStream^}"
Stretch="Uniform"
IsVisible="{Binding MiniProfile.AvatarFrameStream^,Converter={StaticResource IsNullConverter},ConverterParameter=invert}"/>-->
<gif:Image2 Width="224"
Height="224"
AutoStart="true"
Source="{Binding MiniProfile.AvatarFrameStream^}"
Stretch="Uniform"
IsVisible="{Binding MiniProfile.AvatarFrameStream^,Converter={StaticResource IsNullConverter},ConverterParameter=invert}"/>
</Panel>
</Border>
<Panel Grid.Column="1" Margin="10 0 0 0">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,31 +66,27 @@
Margin="10 0">
<Grid Height="92"
ColumnDefinitions="Auto,*,Auto">
<Panel x:Name="avatar"
Cursor="Hand"
ToolTip.Tip="{ReflectionBinding Path=Res.UserChange_OpenUserUrl,Mode=OneWay,Source={x:Static resx:R.Current}}">
<!--OpenUserProfileUrl-->
<i:Interaction.Behaviors>
<ia:EventTriggerBehavior EventName="Tapped" SourceObject="{ReflectionBinding #avatar}">
<ia:InvokeCommandAction Command="{ReflectionBinding #u.DataContext.OpenUserProfileUrl}" CommandParameter="{Binding}"/>
</ia:EventTriggerBehavior>
</i:Interaction.Behaviors>
<gif:Image2
Width="92"
AutoStart="true"
Stretch="UniformToFill"
StretchDirection="Both"
Source="{Binding AvatarStream^}">
</gif:Image2>
<Image Width="92" Stretch="UniformToFill" IsVisible="{Binding AvatarStream^,Converter={StaticResource IsNullConverter}}"
Source="avares://System.Application.SteamTools.Client.Avalonia/Application/UI/Assets/AppResources/avatar.jpg">
</Image>
<!--<gif:Image2 Width="184" Height="184"
AutoStart="true"
Source="{Binding MiniProfile.AvatarFrameStream^}"
Stretch="Uniform"
IsVisible="{Binding MiniProfile.AvatarFrameStream^,Converter={StaticResource IsNullConverter},ConverterParameter=invert}"/>-->
</Panel>
<Border CornerRadius="{StaticResource PaperRadiusLeft}"
ClipToBounds="True">
<Panel x:Name="avatar"
Cursor="Hand"
ToolTip.Tip="{ReflectionBinding Path=Res.UserChange_OpenUserUrl,Mode=OneWay,Source={x:Static resx:R.Current}}">
<!--OpenUserProfileUrl-->
<i:Interaction.Behaviors>
<ia:EventTriggerBehavior EventName="Tapped" SourceObject="{ReflectionBinding #avatar}">
<ia:InvokeCommandAction Command="{ReflectionBinding #u.DataContext.OpenUserProfileUrl}" CommandParameter="{Binding}"/>
</ia:EventTriggerBehavior>
</i:Interaction.Behaviors>
<gif:Image2
Width="92"
AutoStart="true"
Stretch="UniformToFill"
StretchDirection="Both"
Source="{Binding AvatarStream^}"
FallbackSource="avares://System.Application.SteamTools.Client.Avalonia/Application/UI/Assets/AppResources/avatar.jpg">
</gif:Image2>
</Panel>
</Border>
<Panel Grid.Column="1" Margin="10 5">
<StackPanel>
<DockPanel LastChildFill="True">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
xmlns:ccl_services="using:System.Application.Services"
xmlns:sys_app="using:System.Application"
xmlns:service="using:System.Application.Services"
xmlns:gif="using:AvaloniaGif"
xmlns:vm="using:System.Application.UI.ViewModels"
ExtendClientAreaTitleBarHeightHint="30"
WindowStartupLocation="CenterOwner"
Expand Down Expand Up @@ -74,12 +75,15 @@
<Panel Margin="{StaticResource ContentMargin}">
<StackPanel VerticalAlignment="Center">
<DockPanel>
<Image Source="{ReflectionBinding Path=AvatarPath, Source={x:Static service:UserService.Current},Mode=OneWay,Converter={StaticResource BitmapAssetValueConverter},ConverterParameter=184}"
Width="184" Height="184">
<Image.Clip>
<EllipseGeometry Rect="0,0,184,184"/>
</Image.Clip>
</Image>
<gif:Image2 Source="{ReflectionBinding Path=AvatarPath,Source={x:Static service:UserService.Current},Mode=OneWay}"
Stretch="Uniform"
Height="184"
Width="184"
FallbackSource="avares://System.Application.SteamTools.Client.Avalonia/Application/UI/Assets/AppResources/avatar.jpg">
<gif:Image2.Clip>
<EllipseGeometry Rect="0,0,184,184" />
</gif:Image2.Clip>
</gif:Image2>
<StackPanel Orientation="Vertical" Margin="16,0,0,0">
<Button Content="{ReflectionBinding Path=Res.AsyncSteamAvatar,Mode=OneWay,Source={x:Static resx:R.Current}}"
Opacity="0"
Expand Down Expand Up @@ -251,7 +255,7 @@
Command="{Binding OnBindFastLoginClick}"
CommandParameter="{Binding CurrentSelectChannel}"/>
</StackPanel>

<Button Classes="Hyperlink"
HorizontalAlignment="Center"
HorizontalContentAlignment="Center"
Expand Down
4 changes: 1 addition & 3 deletions src/ST.Client/Services/Mvvm/SteamConnectService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -92,8 +92,7 @@ public SteamUser? CurrentSteamUser
}
}

const string DefaultAvatarPath = "avares://System.Application.SteamTools.Client.Avalonia/Application/UI/Assets/AppResources/avatar.jpg";
object? _AvatarPath = DefaultAvatarPath;
object? _AvatarPath;
public object? AvatarPath
{
get => _AvatarPath;
Expand Down Expand Up @@ -254,7 +253,6 @@ public void Initialize()
{
IsConnectToSteam = false;
CurrentSteamUser = null;
AvatarPath = DefaultAvatarPath;
}
}
catch (Exception ex)
Expand Down
23 changes: 5 additions & 18 deletions src/ST.Client/Services/Mvvm/UserService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -103,23 +103,10 @@ public SteamUser? CurrentSteamUser
set => this.RaiseAndSetIfChanged(ref _SteamUser, value);
}

public string DefaultAvatarPath
{
get
{
if (OperatingSystem2.Application.UseAvalonia)
{
return "avares://System.Application.SteamTools.Client.Avalonia/Application/UI/Assets/AppResources/avatar.jpg";
}
return string.Empty;
}
}

object? _AvatarPath;

public object? AvatarPath
{
get => _AvatarPath ?? DefaultAvatarPath;
get => _AvatarPath;
set => this.RaiseAndSetIfChanged(ref _AvatarPath, value);
}

Expand All @@ -134,7 +121,7 @@ public UserService()
{
User = null;
CurrentSteamUser = null;
AvatarPath = DefaultAvatarPath;
AvatarPath = null;
};

Task.Run(Initialize).ForgetAndDispose();
Expand Down Expand Up @@ -217,7 +204,7 @@ public async Task RefreshUserAvatarAsync()
{
var avatarLocalFilePath = await httpService.GetImageAsync(avatarUrl, ImageChannelType.SteamAvatars);
var avatarSouce = ImageSouce.TryParse(avatarLocalFilePath, isCircle: true);
AvatarPath = avatarSouce ?? DefaultAvatarPath;
AvatarPath = avatarSouce;
}
return;
}
Expand All @@ -240,7 +227,7 @@ async Task<bool> RefreshSteamUserAvatarAsync()
CurrentSteamUser = await steamworksWebApiService.GetUserInfo(User.SteamAccountId.Value);
CurrentSteamUser.AvatarStream = httpService.GetImageAsync(CurrentSteamUser.AvatarFull, ImageChannelType.SteamAvatars);
var avatarSouce = ImageSouce.TryParse(await CurrentSteamUser.AvatarStream, isCircle: true);
AvatarPath = avatarSouce ?? DefaultAvatarPath;
AvatarPath = avatarSouce;
return true;
}
else
Expand All @@ -250,7 +237,7 @@ async Task<bool> RefreshSteamUserAvatarAsync()
}
}

AvatarPath = DefaultAvatarPath;
AvatarPath = null;
}

/// <summary>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,9 @@ public async override void Initialize()
{
if (!string.IsNullOrEmpty(miniProfile.AnimatedAvatar))
item.AvatarStream = httpService.GetImageAsync(miniProfile.AnimatedAvatar, ImageChannelType.SteamAvatars);
//miniProfile.AvatarFrameStream = httpService.GetImageAsync(miniProfile.AvatarFrame, ImageChannelType.SteamAvatars);

if (!string.IsNullOrEmpty(miniProfile.AvatarFrame))
miniProfile.AvatarFrameStream = httpService.GetImageAsync(miniProfile.AvatarFrame, ImageChannelType.SteamAvatars);
}
}
_SteamUsersSourceList.Refresh();
Expand Down

0 comments on commit f67d9ab

Please sign in to comment.