This commit is contained in:
RMBGAME
2022-06-23 19:54:57 +08:00
parent f8bf05688b
commit aa29128742
3 changed files with 54 additions and 12 deletions
@@ -1,6 +1,9 @@
using Avalonia;
using Avalonia.Controls;
using Avalonia.LogicalTree;
using Avalonia.Markup.Xaml;
using DynamicData.Binding;
using System.Application.Services;
namespace System.Application.UI.Views.Controls
{
@@ -36,14 +39,44 @@ namespace System.Application.UI.Views.Controls
closeButton.Click += (s, e) =>
{
this.IsVisible = false;
RemoveAd();
};
}
UserService.Current.WhenValueChanged(x => x.User, false)
.Subscribe(_ => Check());
AdvertiseService.Current.WhenValueChanged(x => x.Advertisements, false)
.Subscribe(_ => Check());
}
private void InitializeComponent()
{
AvaloniaXamlLoader.Load(this);
}
protected override void OnAttachedToVisualTree(VisualTreeAttachmentEventArgs e)
{
base.OnAttachedToVisualTree(e);
Check();
}
void Check()
{
if (UserService.Current.User != null && UserService.Current.IsSponsorUser)
{
RemoveAd();
}
if (AdvertiseService.Current.IsInitialized && !AdvertiseService.Current.Advertisements.Any_Nullable())
{
RemoveAd();
}
}
void RemoveAd()
{
this.IsVisible = false;
}
}
}
@@ -141,7 +141,7 @@
Foreground="{DynamicResource HighlightForegroundBrushKey}"
Classes="h5"
VerticalAlignment="Center"/>
<Border IsVisible="{ReflectionBinding Path=User.IsSponsorUser,Mode=OneWay,Source={x:Static service:UserService.Current}}">
<Border IsVisible="{ReflectionBinding Path=IsSponsorUser,Mode=OneWay,Source={x:Static service:UserService.Current}}">
<TextBlock Text="{ReflectionBinding Path=Res.User_Sponsor,Mode=OneWay,Source={x:Static resx:R.Current},StringFormat={}💖 {0}}"
Classes="h8"/>
</Border>
+19 -10
View File
@@ -8,6 +8,7 @@ using DynamicData;
using System.Collections.ObjectModel;
using System.Reactive.Linq;
using DynamicData.Binding;
using ReactiveUI.Fody.Helpers;
namespace System.Application.Services
{
@@ -23,6 +24,9 @@ namespace System.Application.Services
public ReadOnlyObservableCollection<AdvertisementDTO> Advertisements => _Advertisements;
[Reactive]
public bool IsInitialized { get; set; }
private AdvertiseService()
{
mCurrent = this;
@@ -41,17 +45,22 @@ namespace System.Application.Services
public async void InitAdvertise()
{
var client = ICloudServiceClient.Instance.Advertisement;
var result = await client.All();
if (IsInitialized == false)
{
var client = ICloudServiceClient.Instance.Advertisement;
var result = await client.All();
if (result.IsSuccess && result.Content != null)
{
AdvertisementsSource.Clear();
AdvertisementsSource.AddRange(result.Content);
}
else
{
Log.Error(nameof(InitAdvertise), result.Message);
if (result.IsSuccess && result.Content != null)
{
AdvertisementsSource.Clear();
AdvertisementsSource.AddRange(result.Content);
}
else
{
Log.Error(nameof(InitAdvertise), result.Message);
}
IsInitialized = true;
}
}