mirror of
https://github.com/BeyondDimension/SteamTools.git
synced 2026-10-28 23:19:53 +08:00
Misc
This commit is contained in:
@@ -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>
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user