Skip to content

Commit

Permalink
Remove IApplication.AppType
Browse files Browse the repository at this point in the history
  • Loading branch information
AigioL committed Oct 20, 2021
1 parent c5a3669 commit f026f62
Show file tree
Hide file tree
Showing 18 changed files with 81 additions and 144 deletions.
1 change: 0 additions & 1 deletion Directory.Packages.props
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,6 @@
<PackageVersion Include="MonoMac.NetStandard" Version="0.0.4" />
<PackageVersion Include="Microsoft.Windows.CsWinRT" Version="1.3.5" />
<PackageVersion Include="TaskScheduler" Version="2.9.2" />
<!--<PackageVersion Include="Microsoft.Identity.Client" Version="4.35.1" />-->
<PackageVersion Include="de.hdodenhof.circleimageview" Version="3.1.0" />
<PackageVersion Include="ReactiveUI.AndroidX" Version="16.2.6" />
<PackageVersion Include="Square.OkHttp3" Version="4.9.2" />
Expand Down
1 change: 0 additions & 1 deletion README.en.md
Original file line number Diff line number Diff line change
Expand Up @@ -239,7 +239,6 @@ Read what we [milestones](https://github.com/SteamTools-Team/SteamTools/mileston
* [AndroidX for Xamarin.Android](https://github.com/xamarin/AndroidX)
* [Android Jetpack](https://github.com/androidx/androidx)
* [ConstraintLayout](https://github.com/androidx/constraintlayout)
* [MSAL.NET](https://github.com/AzureAD/microsoft-authentication-library-for-dotnet)
* [Entity Framework Core](https://github.com/dotnet/efcore)
* [ASP.NET Core](https://github.com/dotnet/aspnetcore)
* [Windows Forms](https://github.com/dotnet/winforms)
Expand Down
1 change: 0 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -259,7 +259,6 @@ OS | Version | Architectures |
* [AndroidX for Xamarin.Android](https://github.com/xamarin/AndroidX)
* [Android Jetpack](https://github.com/androidx/androidx)
* [ConstraintLayout](https://github.com/androidx/constraintlayout)
* [MSAL.NET](https://github.com/AzureAD/microsoft-authentication-library-for-dotnet)
* [Entity Framework Core](https://github.com/dotnet/efcore)
* [ASP.NET Core](https://github.com/dotnet/aspnetcore)
* [Windows Forms](https://github.com/dotnet/winforms)
Expand Down
15 changes: 12 additions & 3 deletions src/AboutAppInfoPopup.cs
Original file line number Diff line number Diff line change
Expand Up @@ -373,10 +373,19 @@ static string GetJavaSystemGetProperty(string propertyKey)
#endif

#if AVALONIA
b.Append("[avalonia.ver] ");
b.Append(GetAssemblyVersion(typeof(global::Avalonia.Application).Assembly));
b.AppendLine();
if (IApplication.IsAvaloniaApp)
{
b.Append("[avalonia.ver] ");
b.Append(GetAssemblyVersion(Type.GetType(IApplication.TypeNames.Avalonia)!.Assembly));
b.AppendLine();
}
#endif
if (IApplication.IsXamarinForms)
{
b.Append("[forms.ver] ");
b.Append(GetAssemblyVersion(Type.GetType(IApplication.TypeNames.XamarinForms)!.Assembly));
b.AppendLine();
}

b.Append("[essentials.supported] ");
b.Append(Essentials.IsSupported.ToLowerString());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
using Google.Android.Material.Dialog;
using Google.Android.Material.TextField;
using ReactiveUI;
using System.Application.UI.Activities;
using System.Application.UI.Resx;
using System.Application.UI.ViewModels;
using System.Diagnostics.CodeAnalysis;
Expand Down Expand Up @@ -38,39 +39,39 @@ protected async Task<bool> PlatformShowWindow(CustomWindow customWindow, PageVie

protected Task<bool> PlatformShowWindowCore(Activity currentActivity, CustomWindow customWindow, PageViewModel? viewModel = null, string title = "")
{
//switch (customWindow)
//{
// case CustomWindow.ShowAuth:
// case CustomWindow.AuthTrade:
// if (viewModel is MyAuthenticatorWrapper viewModel_auth_w)
// {
// switch (customWindow)
// {
// case CustomWindow.ShowAuth:
// // Android Activity 传参需要序列化后再反序列化,不能直接传递
// // 所以此处传递 Id,在 Activity 中从关联的集合中根据 Id 取值
// SteamAuthDataActivity.StartActivity(currentActivity, viewModel_auth_w.Authenticator.Id);
// break;
// case CustomWindow.AuthTrade:
// SteamAuthTradeActivity.StartActivity(currentActivity, viewModel_auth_w.Authenticator.Id);
// break;
// }
// }
// return Task.FromResult(false);
//}
switch (customWindow)
{
case CustomWindow.ShowAuth:
case CustomWindow.AuthTrade:
if (viewModel is MyAuthenticatorWindowViewModel viewModel_auth_w && viewModel_auth_w.MyAuthenticator != null)
{
switch (customWindow)
{
case CustomWindow.ShowAuth:
// Android Activity 传参需要序列化后再反序列化,不能直接传递
// 所以此处传递 Id,在 Activity 中从关联的集合中根据 Id 取值
SteamAuthDataActivity.StartActivity(currentActivity, viewModel_auth_w.MyAuthenticator.Id);
break;
case CustomWindow.AuthTrade:
SteamAuthTradeActivity.StartActivity(currentActivity, viewModel_auth_w.MyAuthenticator.Id);
break;
}
}
return Task.FromResult(false);
}

//var activityType = customWindow switch
//{
// CustomWindow.AddAuth => typeof(AddAuthActivity),
// CustomWindow.ExportAuth => typeof(ExportAuthActivity),
// CustomWindow.EncryptionAuth => typeof(EncryptionAuthActivity),
// _ => null,
//};
//if (activityType != null)
//{
// currentActivity.StartActivity(activityType);
// return Task.FromResult(false);
//}
var activityType = customWindow switch
{
CustomWindow.AddAuth => typeof(AddAuthActivity),
CustomWindow.ExportAuth => typeof(ExportAuthActivity),
CustomWindow.EncryptionAuth => typeof(EncryptionAuthActivity),
_ => null,
};
if (activityType != null)
{
currentActivity.StartActivity(activityType);
return Task.FromResult(false);
}

TaskCompletionSource<bool> tcs = new();
try
Expand Down
6 changes: 4 additions & 2 deletions src/ST.Client.Android/UI/MainApplication.cs
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,10 @@ public sealed partial class MainApplication : IApplication
public MainApplication(IntPtr javaReference, JniHandleOwnership transfer) : base(javaReference, transfer)
{
IViewModelBase.IsInDesignMode = false;
IViewModelBase.IsMobileLayout = true;

// 此页面当前使用 Square.Picasso 库加载图片
AuthTradeWindowViewModel.IsLoadImage = false;
}

#if DEBUG
Expand Down Expand Up @@ -147,8 +151,6 @@ AppTheme IApplication.GetActualThemeByFollowingSystem()

bool IApplication.HasActiveWindow() => XEPlatform.CurrentActivity.HasValue();

IApplication.AppType IApplication.GetType() => IApplication.AppType.HybridAndroid;

#region Compat

void IApplication.SetThemeNotChangeValue(AppTheme value) => Theme = value;
Expand Down
2 changes: 0 additions & 2 deletions src/ST.Client.Desktop.Avalonia.App/App.axaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,6 @@ namespace System.Application.UI
{
public partial class App : AvaloniaApplication, IDisposableHolder, IApplication, IAvaloniaApplication, IClipboardPlatformService
{
IApplication.AppType IApplication.GetType() => IApplication.AppType.Avalonia;

public static App Instance => Current is App app ? app : throw new Exception("Impossible");

//public static DirectoryInfo RootDirectory => new(IOPath.BaseDirectory);
Expand Down
2 changes: 1 addition & 1 deletion src/ST.Client/ImageSouce.cs
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ public void Dispose()
{
if (filePathOrResUri == null)
return null;
if (IApplication.Type == IApplication.AppType.Avalonia)
if (IApplication.IsAvaloniaApp)
{
if (filePathOrResUri.StartsWith("avares:"))
return filePathOrResUri;
Expand Down
8 changes: 3 additions & 5 deletions src/ST.Client/Services/Mvvm/ToastService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
using System.Reactive.Subjects;
using System.Reactive.Linq;
using System.Application.UI;
using System.Application.Services.Implementation;

// ReSharper disable once CheckNamespace
namespace System.Application.Services
Expand All @@ -14,11 +15,8 @@ namespace System.Application.Services
/// </summary>
public sealed class ToastService : MvvmService<ToastService>
{
public static bool IsSupported => IApplication.Type switch
{
IApplication.AppType.Avalonia => true,
_ => false,
};
static readonly Lazy<bool> mIsSupported = new(() => DI.Get<IToast>() is ToastImpl);
public static bool IsSupported => mIsSupported.Value;

private readonly Subject<string> notifier;
private string persisitentMessage = "";
Expand Down
2 changes: 1 addition & 1 deletion src/ST.Client/Services/Mvvm/UserService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ public string DefaultAvaterPath
{
get
{
if (IApplication.Type == IApplication.AppType.Avalonia)
if (IApplication.IsAvaloniaApp)
{
return "avares://System.Application.SteamTools.Client.Avalonia/Application/UI/Assets/AppResources/avater_default.png";
}
Expand Down
12 changes: 0 additions & 12 deletions src/ST.Client/UI/IApplication.Helper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,18 +7,6 @@ namespace System.Application.UI
{
partial interface IApplication
{
static readonly Lazy<AppType> mType = new(() => Instance.GetType());
public static AppType Type => mType.Value;

/// <summary>
/// 是否使用移动端布局
/// </summary>
public static bool IsMobileLayout => Type switch
{
AppType.Maui or AppType.NativeAndroid => true,
_ => false,
};

public static bool EnableDevtools { get; set; } = ThisAssembly.Debuggable;

/// <summary>
Expand Down
85 changes: 12 additions & 73 deletions src/ST.Client/UI/IApplication.cs
Original file line number Diff line number Diff line change
Expand Up @@ -38,83 +38,22 @@ public partial interface IApplication : IService<IApplication>
/// <returns></returns>
protected AppTheme GetActualThemeByFollowingSystem();

protected AppType GetType();

enum AppType : byte
{
/// <summary>
/// https://github.com/AvaloniaUI/Avalonia
/// </summary>
Avalonia = 1,

/// <summary>
/// Maui / Xamarin Forms + Platform Native UI
/// <para>https://github.com/dotnet/maui</para>
/// <para>https://developer.android.google.cn/training/basics/firstapp/building-ui</para>
/// </summary>
HybridAndroid,

/// <summary>
/// Maui / Xamarin Forms
/// <para></para>
/// https://github.com/dotnet/maui
/// </summary>
[Obsolete]
Maui,

/// <summary>
/// https://github.com/unoplatform/uno
/// </summary>
[Obsolete]
Uno,

/// <summary>
/// https://developer.android.google.cn/training/basics/firstapp/building-ui
/// </summary>
[Obsolete]
NativeAndroid,

/// <summary>
/// https://docs.microsoft.com/zh-cn/xamarin/ios/user-interface/ios-ui
/// </summary>
[Obsolete]
NativeiOS,

/// <summary>
/// https://github.com/dotnet/winforms
/// <para></para>
/// https://github.com/mono/winforms
/// </summary>
[Obsolete]
WinForms,

/// <summary>
/// https://github.com/dotnet/wpf
/// </summary>
[Obsolete]
WPF,

/// <summary>
/// WinUI 2
/// <para></para>
/// https://github.com/Microsoft/microsoft-ui-xaml
/// <para></para>
/// https://docs.microsoft.com/zh-cn/windows/apps/winui/winui2
/// </summary>
[Obsolete]
UWP,

/// <summary>
/// https://docs.microsoft.com/zh-cn/windows/apps/winui/winui3/desktop-winui3-app-with-basic-interop
/// </summary>
[Obsolete]
WinUI3,
}

/// <summary>
/// 获取当前平台 UI Host
/// <para>reference to the ViewController (if using Xamarin.iOS), Activity (if using Xamarin.Android) IWin32Window or IntPtr (if using .Net Framework).</para>
/// </summary>
object CurrentPlatformUIHost { get; }

private static readonly Lazy<bool> mIsAvaloniaApp = new(() => Type.GetType(TypeNames.Avalonia) != null);
static bool IsAvaloniaApp => mIsAvaloniaApp.Value;

private static readonly Lazy<bool> mIsXamarinForms = new(() => Type.GetType(TypeNames.XamarinForms) != null);
static bool IsXamarinForms => mIsXamarinForms.Value;

static class TypeNames
{
public const string Avalonia = "Avalonia.Application, Avalonia.Controls";
public const string XamarinForms = "Xamarin.Forms.Application, Xamarin.Forms.Core";
}
}
}
5 changes: 5 additions & 0 deletions src/ST.Client/UI/ViewModels/Base/IViewModelBase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -20,5 +20,10 @@ public interface IViewModelBase : IReactiveObject, INotifyPropertyChanged, INoti
/// 是否在设计器的上下文中运行
/// </summary>
public static bool IsInDesignMode { protected get; set; } = true;

/// <summary>
/// 是否使用移动端布局
/// </summary>
public static bool IsMobileLayout { protected get; set; }
}
}
3 changes: 3 additions & 0 deletions src/ST.Client/UI/ViewModels/Base/ViewModelBase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,9 @@ public abstract class ViewModelBase : ReactiveObject, IViewModelBase, IActivatab
/// <inheritdoc cref="IViewModelBase.IsInDesignMode"/>
public static bool IsInDesignMode => IViewModelBase.IsInDesignMode;

/// <inheritdoc cref="IViewModelBase.IsMobileLayout"/>
public static bool IsMobileLayout => IViewModelBase.IsMobileLayout;

public ViewModelActivator Activator { get; }

public ViewModelBase()
Expand Down
2 changes: 1 addition & 1 deletion src/ST.Client/UI/ViewModels/General/PageViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ public virtual string Title

protected static string GetTitleByDisplayName(string displayName)
{
if (IApplication.Type == IApplication.AppType.Avalonia)
if (IApplication.IsAvaloniaApp)
{
return Constants.HARDCODED_APP_NAME + " | " + displayName;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ public AboutPageViewModel()
}
});

if (IApplication.IsMobileLayout)
if (IsMobileLayout)
{
preferenceButtons = new(Enum2.GetAll<PreferenceButton>().Select(x => PreferenceButtonViewModel.Create(x, this)));

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
using System.Application.Repositories;
using System.Application.Services;
using System.Collections.ObjectModel;
using System.IO;
using System.Linq;
using System.Properties;
using System.Reactive.Linq;
Expand Down Expand Up @@ -63,13 +64,9 @@ protected override void InitializeComponent()
}

/// <summary>
/// 是否加载确认物品图片
/// 是否使用 <see cref="IHttpService"/> 加载确认物品图片 <see cref="Stream"/>
/// </summary>
static bool IsLoadImage => IApplication.Type switch
{
IApplication.AppType.NativeAndroid => false,
_ => true,
};
public static bool IsLoadImage { protected get; set; } = true;

private string? AuthPassword;
private bool AuthIsLocal;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ IEnumerable<FastLoginChannelViewModel> GetFastLoginChannels()
#if DEBUG
yield return FastLoginChannelViewModel.Create(nameof(FastLoginChannel.Apple), this);
#endif
if (IApplication.IsMobileLayout)
if (IsMobileLayout)
{
yield return FastLoginChannelViewModel.Create(FastLoginChannelViewModel.PhoneNumber, this);
}
Expand Down Expand Up @@ -137,7 +137,7 @@ public short LoginState
if (_LoginState == value) return;
_LoginState = value;
this.RaisePropertyChanged();
if (IApplication.IsMobileLayout)
if (IsMobileLayout)
{
Title = _LoginState == 1 ? AppResources.User_PhoneLogin : AppResources.LoginAndRegister;
}
Expand Down

0 comments on commit f026f62

Please sign in to comment.