diff --git a/src/ST.Client.Desktop/UI/ViewModels/Windows/LoginOrRegisterWindowViewModel.cs b/src/ST.Client.Desktop/UI/ViewModels/Windows/LoginOrRegisterWindowViewModel.cs index c6c3d68d7..07aa09614 100644 --- a/src/ST.Client.Desktop/UI/ViewModels/Windows/LoginOrRegisterWindowViewModel.cs +++ b/src/ST.Client.Desktop/UI/ViewModels/Windows/LoginOrRegisterWindowViewModel.cs @@ -82,5 +82,11 @@ namespace System.Application.UI.ViewModels isDialog: true // 锁定父窗口,防止打开多个 WebViewWindow ); } + + internal Task GoToLoginOrRegisterByPhoneNumberAsync() + { + LoginState = 1; + return Task.CompletedTask; + } } } \ No newline at end of file diff --git a/src/ST.Client.Desktop/UI/ViewModels/Windows/LoginOrRegisterWindowViewModel.shared.cs b/src/ST.Client.Desktop/UI/ViewModels/Windows/LoginOrRegisterWindowViewModel.shared.cs index c3d8e384a..855db3154 100644 --- a/src/ST.Client.Desktop/UI/ViewModels/Windows/LoginOrRegisterWindowViewModel.shared.cs +++ b/src/ST.Client.Desktop/UI/ViewModels/Windows/LoginOrRegisterWindowViewModel.shared.cs @@ -51,6 +51,7 @@ namespace System.Application.UI.ViewModels switch (channel) { case nameof(PhoneNumber): + await GoToLoginOrRegisterByPhoneNumberAsync(); break; } } @@ -106,7 +107,8 @@ namespace System.Application.UI.ViewModels set => this.RaiseAndSetIfChanged(ref _IsLoading, value); } - short _LoginState = 2; + const short _LoginStateDefault = 2; + short _LoginState = _LoginStateDefault; public short LoginState { get => _LoginState; @@ -147,10 +149,12 @@ namespace System.Application.UI.ViewModels Toast.Show(msg); } +#if !__MOBILE__ public void ChangeLoginState(short state) { LoginState = state; } +#endif public Action? Close { get; set; } diff --git a/src/ST.Client.Mobile/Converters/LoginOrRegisterChannelBackgroundColorConverter.cs b/src/ST.Client.Mobile/Converters/LoginOrRegisterChannelBackgroundColorConverter.cs index 52c37db13..ed798ea45 100644 --- a/src/ST.Client.Mobile/Converters/LoginOrRegisterChannelBackgroundColorConverter.cs +++ b/src/ST.Client.Mobile/Converters/LoginOrRegisterChannelBackgroundColorConverter.cs @@ -24,7 +24,7 @@ namespace System.Application.Converters nameof(FastLoginChannel.Apple) => ColorFromHex("#000000"), nameof(FastLoginChannel.QQ) => ColorFromHex("#12B7F5"), "Phone" or "PhoneNumber" => ColorFromHex("#2196F3"), - _ => null, + _ => Binding.DoNothing, }; } diff --git a/src/ST.Client.Mobile/Converters/LoginOrRegisterChannelTextConverter.cs b/src/ST.Client.Mobile/Converters/LoginOrRegisterChannelTextConverter.cs index e47269960..6d697c38a 100644 --- a/src/ST.Client.Mobile/Converters/LoginOrRegisterChannelTextConverter.cs +++ b/src/ST.Client.Mobile/Converters/LoginOrRegisterChannelTextConverter.cs @@ -11,9 +11,9 @@ namespace System.Application.Converters { public class LoginOrRegisterChannelTextConverter : IMultiValueConverter { - public object? Convert(IList values, Type? targetType, object? parameter, CultureInfo? culture) + public object? Convert(IList? values, Type? targetType, object? parameter, CultureInfo? culture) { - if (values.Count >= 3) + if (values != null && values.Count >= 3) { var stringValues = values.Select(x => (x is not string str) ? x?.ToString() ?? string.Empty : str).ToArray(); var args = stringValues.Skip(1).FirstOrDefault(); @@ -28,12 +28,12 @@ namespace System.Application.Converters var format = stringValues.FirstOrDefault() ?? string.Empty; return format.Format(args); } - return null; + return Binding.DoNothing; } - public object? Convert(object?[] values, Type? targetType, object? parameter, CultureInfo? culture) + public object? Convert(object?[]? values, Type? targetType, object? parameter, CultureInfo? culture) { - IList values_ = values; + IList? values_ = values; return Convert(values_, targetType, parameter, culture); } diff --git a/src/ST.Client.Mobile/Converters/PathGeometryConverter.cs b/src/ST.Client.Mobile/Converters/PathGeometryConverter.cs index d8c21663b..dab2abf32 100644 --- a/src/ST.Client.Mobile/Converters/PathGeometryConverter.cs +++ b/src/ST.Client.Mobile/Converters/PathGeometryConverter.cs @@ -17,7 +17,7 @@ namespace System.Application.Converters catch { } - return null; + return Binding.DoNothing; } public object? Convert(object? value, Type targetType, object? parameter, CultureInfo culture) @@ -28,7 +28,7 @@ namespace System.Application.Converters var r = GetGeometryByPathString(this, valueStr); return r; } - return null; + return Binding.DoNothing; } public object? ConvertBack(object? value, Type targetType, object? parameter, CultureInfo culture) => throw new NotImplementedException(); diff --git a/src/ST.Client.Mobile/Converters/PathIconConverter.cs b/src/ST.Client.Mobile/Converters/PathIconConverter.cs index a647ddbb6..f25f469bb 100644 --- a/src/ST.Client.Mobile/Converters/PathIconConverter.cs +++ b/src/ST.Client.Mobile/Converters/PathIconConverter.cs @@ -20,7 +20,7 @@ namespace System.Application.Converters return r; } } - return null; + return Binding.DoNothing; } public object? ConvertBack(object? value, Type targetType, object? parameter, CultureInfo culture) => throw new NotImplementedException(); diff --git a/src/ST.Client.Mobile/Converters/ResourceKeyConverter.cs b/src/ST.Client.Mobile/Converters/ResourceKeyConverter.cs index b9c5c3a05..0f0771645 100644 --- a/src/ST.Client.Mobile/Converters/ResourceKeyConverter.cs +++ b/src/ST.Client.Mobile/Converters/ResourceKeyConverter.cs @@ -42,7 +42,7 @@ namespace System.Application.Converters var r = GetResourceByKey(valueStr); return r; } - return null; + return Binding.DoNothing; } public object? ConvertBack(object? value, Type targetType, object? parameter, CultureInfo culture) => throw new NotImplementedException(); diff --git a/src/ST.Client.Mobile/Converters/SwitchMultiValueConverter.cs b/src/ST.Client.Mobile/Converters/SwitchMultiValueConverter.cs new file mode 100644 index 000000000..0b6882908 --- /dev/null +++ b/src/ST.Client.Mobile/Converters/SwitchMultiValueConverter.cs @@ -0,0 +1,48 @@ +using System.Collections.Generic; +using System.Globalization; +using System.Linq; +#if !__MOBILE__ +using Avalonia.Data.Converters; +#else +using Xamarin.Forms; +#endif + +namespace System.Application.Converters +{ + public class SwitchMultiValueConverter : IMultiValueConverter + { + public object? Convert(IList? values, Type? targetType, object? parameter, CultureInfo? culture) + { + if (values != null && values.Count > 0) + { + var first = values.FirstOrDefault(); + if (first != null) + { + try + { + var index = System.Convert.ToInt32(first); + if (index > 0 && index < values.Count) + { + return values[index]; + } + } + catch + { + + } + } + } + return Binding.DoNothing; + } + + public object? Convert(object?[]? values, Type? targetType, object? parameter, CultureInfo? culture) + { + IList? values_ = values; + return Convert(values_, targetType, parameter, culture); + } + + public object? ConvertBack(object? value, Type? targetType, object? parameter, CultureInfo? culture) => throw new NotImplementedException(); + + public object[]? ConvertBack(object? value, Type[]? targetTypes, object? parameter, CultureInfo? culture) => throw new NotImplementedException(); + } +} diff --git a/src/ST.Client.Mobile/UI/AppShell.xaml.cs b/src/ST.Client.Mobile/UI/AppShell.xaml.cs index e2b56e237..6584d192d 100644 --- a/src/ST.Client.Mobile/UI/AppShell.xaml.cs +++ b/src/ST.Client.Mobile/UI/AppShell.xaml.cs @@ -5,12 +5,14 @@ namespace System.Application.UI { public partial class AppShell : Shell { + public const string Route_LoginOrRegister_Secondary = "LoginOrRegister/Secondary"; + public AppShell() { InitializeComponent(); Routing.RegisterRoute(nameof(ItemDetailPage), typeof(ItemDetailPage)); Routing.RegisterRoute(nameof(NewItemPage), typeof(NewItemPage)); - Routing.RegisterRoute("LoginOrRegister/PhoneNumber", typeof(LoginOrRegisterPage)); + Routing.RegisterRoute(Route_LoginOrRegister_Secondary, typeof(LoginOrRegisterPage)); } } } \ No newline at end of file diff --git a/src/ST.Client.Mobile/UI/ViewModels/AboutViewModel.cs b/src/ST.Client.Mobile/UI/ViewModels/AboutViewModel.cs index cd10b661a..fd0baeb4b 100644 --- a/src/ST.Client.Mobile/UI/ViewModels/AboutViewModel.cs +++ b/src/ST.Client.Mobile/UI/ViewModels/AboutViewModel.cs @@ -11,7 +11,7 @@ namespace System.Application.UI.ViewModels Title = "About"; OpenWebCommand = new Command(async () //=> await Browser.OpenAsync("https://aka.ms/xamarin-quickstart") - => await Shell.Current.GoToAsync("//LoginOrRegister/PhoneNumber") + => await Shell.Current.GoToAsync($"//LoginOrRegister") ); } diff --git a/src/ST.Client.Mobile/UI/ViewModels/LoginOrRegisterPageViewModel.cs b/src/ST.Client.Mobile/UI/ViewModels/LoginOrRegisterPageViewModel.cs index c692725f3..df309b68b 100644 --- a/src/ST.Client.Mobile/UI/ViewModels/LoginOrRegisterPageViewModel.cs +++ b/src/ST.Client.Mobile/UI/ViewModels/LoginOrRegisterPageViewModel.cs @@ -1,7 +1,10 @@ using System.Threading.Tasks; +using System.Windows.Input; +using Xamarin.Forms; namespace System.Application.UI.ViewModels { + [QueryProperty(nameof(LoginState_), nameof(LoginState))] partial class LoginOrRegisterPageViewModel : PageViewModel { internal static Task FastLoginOrRegisterAsync(Action? close = null, FastLoginChannel channel = FastLoginChannel.Steam, bool isBind = false) @@ -9,5 +12,18 @@ namespace System.Application.UI.ViewModels Toast.Show(channel.ToString()); return Task.CompletedTask; } + + static async Task GoToLoginOrRegisterByPhoneNumberAsync() + { + var url = $"//{AppShell.Route_LoginOrRegister_Secondary}?{nameof(LoginState)}=1"; + await Shell.Current.GoToAsync(url); + } + + public short LoginState_ + { + set => LoginState = value == default ? _LoginStateDefault : value; + } + + public ICommand? TbPhoneNumberReturnCommand { get; set; } } } \ No newline at end of file diff --git a/src/ST.Client.Mobile/UI/Views/LoginOrRegisterPage.xaml b/src/ST.Client.Mobile/UI/Views/LoginOrRegisterPage.xaml index 3f2ebc650..b2702242f 100644 --- a/src/ST.Client.Mobile/UI/Views/LoginOrRegisterPage.xaml +++ b/src/ST.Client.Mobile/UI/Views/LoginOrRegisterPage.xaml @@ -1,5 +1,5 @@ - - + + - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + + + + + + + + -