Skip to content

Commit

Permalink
Upgrade to .NET 6.0.100-preview.5.21302.13
Browse files Browse the repository at this point in the history
  • Loading branch information
AigioL committed Jun 18, 2021
1 parent 271514f commit 0139aa6
Show file tree
Hide file tree
Showing 22 changed files with 256 additions and 63 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/dotnet.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ jobs:
- name: Setup .NET 6
uses: actions/setup-dotnet@v1
with:
dotnet-version: 6.0.100-preview.4.21255.9
dotnet-version: 6.0.100-preview.5.21302.13

- name: Checkout repository
uses: actions/checkout@v2
Expand Down
2 changes: 1 addition & 1 deletion global.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,6 @@
"MSBuild.Sdk.Extras": "3.0.22"
},
"sdk": {
"version": "6.0.100-preview.4.21255.9"
"version": "6.0.100-preview.5.21302.13"
}
}
8 changes: 8 additions & 0 deletions src/Common.ClientLib/ReactiveUI/IReadOnlyViewFor.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
// ReSharper disable once CheckNamespace
namespace ReactiveUI
{
public interface IReadOnlyViewFor<out T> where T : class
{
T? ViewModel { get; }
}
}
20 changes: 13 additions & 7 deletions src/ST.Client.Desktop/UI/Resx/R.cs
Original file line number Diff line number Diff line change
@@ -1,31 +1,32 @@
using ReactiveUI;
using System.Application.Services;
using System.Collections.Generic;
using System.Drawing;
using System.Drawing.Text;
using System.Globalization;
using System.Linq;
using System.Reactive.Linq;
using System.Text.RegularExpressions;
#if __MOBILE__
using R_Res_TYPE = System.Byte;
#else
using R_Res_TYPE = System.Application.UI.Resx.AppResources;
#endif

namespace System.Application.UI.Resx
{
public sealed class R : ReactiveObject
{
public static R Current { get; }
public static R Current { get; } = new();

public static readonly IReadOnlyCollection<KeyValuePair<string, string>> Languages;
public static readonly Dictionary<string, string> SteamLanguages;
static readonly Lazy<IReadOnlyCollection<KeyValuePair<string, string>>> mFonts = new(() => IFontManager.Instance.GetFonts());
public static IReadOnlyCollection<KeyValuePair<string, string>> Fonts => mFonts.Value;

public AppResources Res { get; set; } = new AppResources();
public R_Res_TYPE Res { get; set; } = new();

public static CultureInfo DefaultCurrentUICulture { get; }

static R()
{
Current = new R();
DefaultCurrentUICulture = CultureInfo.CurrentUICulture;
Languages = new Dictionary<string, string>(StringComparer.OrdinalIgnoreCase)
{
Expand Down Expand Up @@ -82,7 +83,12 @@ public static void ChangeLanguage(string? cultureName)
CultureInfo.DefaultThreadCurrentCulture = AppResources.Culture;
mAcceptLanguage = GetAcceptLanguageCore();
mLanguage = GetLanguageCore();
Current.Res = new AppResources();
Current.Res =
#if __MOBILE__
++Current.Res;
#else
new AppResources();
#endif
Current.RaisePropertyChanged(nameof(Res));
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -191,15 +191,18 @@ async Task SendSmsAsync()

public ICommand OpenHyperlink { get; }

public const string Agreement = "Agreement";
public const string Privacy = "Privacy";

void OpenHyperlink_(string parameter)
{
if (string.IsNullOrWhiteSpace(parameter)) return;
switch (parameter)
{
case "Agreement":
case Agreement:
parameter = "https://steampp.net/AgreementBox";
break;
case "Privacy":
case Privacy:
parameter = "https://steampp.net/PrivacyBox";
break;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
android:name="androidx.navigation.fragment.NavHostFragment"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@color/grey_window_background"
app:defaultNavHost="true"
app:navGraph="@navigation/nav_graph_login_or_register"
xamarin:managedType="AndroidX.Fragment.App.FragmentContainerView">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,7 @@
xmlns:xamarin="http://schemas.xamarin.com/android/xamarin/tools"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical"
android:background="@color/grey_window_background">
android:layout_gravity="center_vertical">

<LinearLayout
android:layout_width="match_parent"
Expand Down Expand Up @@ -41,7 +40,10 @@
android:layout_marginTop="22dp"
android:layout_marginEnd="@dimen/fast_login_or_register_margin"
android:layout_marginBottom="22dp"
android:clickable="true"
android:focusable="true"
android:textColor="@color/text_primary"
android:textColorLink="@color/text_link"
android:textSize="14sp"
tools:text="注册即代表您已阅读并同意 用户协议 和 隐私政策"
xamarin:managedType="AndroidX.AppCompat.Widget.AppCompatTextView" />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -90,8 +90,12 @@
android:layout_marginStart="@dimen/fast_login_or_register_margin"
android:layout_marginTop="@dimen/fast_login_or_register_margin"
android:layout_marginEnd="@dimen/fast_login_or_register_margin"
android:clickable="true"
android:focusable="true"
android:gravity="center_horizontal"
android:textAlignment="center"
android:textColor="@color/text_primary"
android:textColorLink="@color/text_link"
android:textSize="14sp"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,5 @@
<color name="grey_window_background">#FF000000</color>
<color name="text_primary">#f2f2f7</color>
<color name="text_secondary">#979797</color>
<color name="text_link">#0089ff</color>
</resources>
Original file line number Diff line number Diff line change
Expand Up @@ -13,4 +13,5 @@
<color name="grey_window_background">#F9F9F9</color>
<color name="text_primary">#333333</color>
<color name="text_secondary">#666666</color>
<color name="text_link">#007ffc</color>
</resources>
Original file line number Diff line number Diff line change
Expand Up @@ -25,4 +25,9 @@
<style name="MainTheme.Splash.Base.V28" parent="MainTheme.Splash.Base" />

<style name="MainTheme.Splash" parent="MainTheme.Splash.Base.V28" />

<style name="MainTheme.NoActionBar" parent="MainTheme">
<item name="windowActionBar">false</item>
<item name="windowNoTitle">true</item>
</style>
</resources>
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
using Android.Views;
using System;
using Color = Android.Graphics.Color;

// ReSharper disable once CheckNamespace
namespace Android.Text.Style
{
public sealed class HyperlinkClickableSpan : ClickableSpan
{
readonly Action<View?> onClick;
readonly bool underlineText;

public HyperlinkClickableSpan(Action<View?> onClick, bool underlineText = false)
{
this.onClick = onClick;
this.underlineText = underlineText;
}

public override void OnClick(View widget) => onClick(widget);

public override void UpdateDrawState(TextPaint ds)
{
ds.Color = new Color(ds.LinkColor);
ds.UnderlineText = underlineText;
}
}
}
2 changes: 1 addition & 1 deletion src/ST.Client.Mobile.Droid/ST.Client.Mobile.Droid.csproj
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<Project Sdk="MSBuild.Sdk.Extras">
<Project Sdk="MSBuild.Sdk.Extras">

<PropertyGroup>
<TargetFramework>MonoAndroid11.0</TargetFramework>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,28 +3,64 @@
using Android.Content.PM;
using Android.OS;
using Android.Runtime;
using AndroidX.Navigation;
using Android.Text;
using Android.Text.Style;
using AndroidX.Navigation.Fragment;
using AndroidX.Navigation.UI;
using Binding;
using Microsoft.Identity.Client;
using ReactiveUI;
using System.Application.Mvvm;
using System.Application.UI.Resx;
using System.Application.UI.ViewModels;
using System.Collections.Generic;
using System.Reactive.Disposables;
using System.Text;
using JObject = Java.Lang.Object;

namespace System.Application.UI.Activities
{
[Register(JavaPackageConstants.Activities + nameof(LoginOrRegisterActivity))]
[Activity(Theme = "@style/MainTheme",
[Activity(Theme = "@style/MainTheme.NoActionBar",
LaunchMode = LaunchMode.SingleTask,
ConfigurationChanges = ManifestConstants.ConfigurationChanges)]
internal sealed class LoginOrRegisterActivity : BaseActivity
internal sealed class LoginOrRegisterActivity : BaseActivity<activity_login_or_register, LoginOrRegisterPageViewModel>, IDisposableHolder
{
readonly CompositeDisposable disposables = new();
ICollection<IDisposable> IDisposableHolder.CompositeDisposable => disposables;

protected override int? LayoutResource => Resource.Layout.activity_login_or_register;

//static readonly Dictionary<int, Func<string>> title_strings = new()
//{
// { Resource.Id.navigation_login_or_register_fast, () => AppResources.LoginAndRegister },
// { Resource.Id.navigation_login_or_register_phone_number, () => AppResources.User_PhoneLogin },
//};

protected override void OnCreate(Bundle? savedInstanceState)
{
base.OnCreate(savedInstanceState);

ViewModel = new();
ViewModel.AddTo(this);

var appBarConfiguration = new AppBarConfiguration.Builder(Resource.Id.navigation_login_or_register_fast).Build();
navController = ((NavHostFragment)SupportFragmentManager.FindFragmentById(Resource.Id.nav_host_fragment)).NavController;
NavigationUI.SetupActionBarWithNavController(this, navController, appBarConfiguration);

//R.Current.WhenAnyValue(x => x.Res).Subscribe(_ =>
//{
// var currentDestinationId = navController.CurrentDestination.Id;
// foreach (var item in title_strings)
// {
// var title = item.Value();
// this.SetNavigationGraphTitle(item.Key, title);
// if (currentDestinationId == item.Key && ActionBar != null)
// {
// ActionBar.Title = title;
// }
// }
//}).AddTo(this);
}

protected override void OnActivityResult(int requestCode, Result resultCode, Intent? data)
Expand All @@ -34,5 +70,35 @@ protected override void OnActivityResult(int requestCode, Result resultCode, Int
// Return control to MSAL
AuthenticationContinuationHelper.SetAuthenticationContinuationEventArgs(requestCode, resultCode, data);
}

public static SpannableString CreateAgreementAndPrivacy(LoginOrRegisterPageViewModel viewModel)
{
int length;
var linkTextIndexs = new List<(JObject what, int start, int end, SpanTypes flags)>();
StringBuilder str = new(AppResources.User_RegisterAgreed);
str.Append(" ");
length = str.Length;
str.Append(AppResources.User_Agreement);
linkTextIndexs.Add((new HyperlinkClickableSpan(_ =>
{
viewModel.OpenHyperlink.Invoke(LoginOrRegisterPageViewModel.Agreement);
}), length, str.Length, SpanTypes.ExclusiveExclusive));
str.Append(" ");
str.Append(AppResources.And);
str.Append(" ");
length = str.Length;
str.Append(AppResources.User_Privacy);
linkTextIndexs.Add((new HyperlinkClickableSpan(_ =>
{
viewModel.OpenHyperlink.Invoke(LoginOrRegisterPageViewModel.Privacy);
}), length, str.Length, SpanTypes.ExclusiveExclusive));

SpannableString spannable = new(str.ToString());
foreach (var (what, start, end, flags) in linkTextIndexs)
{
spannable.SetSpan(what, start, end, flags);
}
return spannable;
}
}
}
16 changes: 6 additions & 10 deletions src/ST.Client.Mobile.Droid/UI/Activities/MainActivity.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ namespace System.Application.UI.Activities
[Activity(Theme = "@style/MainTheme",
LaunchMode = LaunchMode.SingleTask,
ConfigurationChanges = ManifestConstants.ConfigurationChanges)]
internal sealed class MainActivity : BaseActivity<activity_main>, IDisposableHolder
internal sealed class MainActivity : BaseActivity<activity_main>, IDisposableHolder, IReadOnlyViewFor<MyPageViewModel>
{
readonly CompositeDisposable disposables = new();
ICollection<IDisposable> IDisposableHolder.CompositeDisposable => disposables;
Expand All @@ -29,6 +29,8 @@ internal sealed class MainActivity : BaseActivity<activity_main>, IDisposableHol

public MyPageViewModel MyPageViewModel { get; } = new();

MyPageViewModel? IReadOnlyViewFor<MyPageViewModel>.ViewModel => MyPageViewModel;

void SetBottomNavigationMenuTitle(int resId, ICharSequence value)
{
if (binding == null) return;
Expand All @@ -38,25 +40,19 @@ void SetBottomNavigationMenuTitle(int resId, ICharSequence value)
menuItem.SetTitle(value);
}

void SetNavigationGraphTitle(int resId, ICharSequence value)
{
if (navController == null) return;
var navNode = navController.Graph.FindNode(resId);
if (navNode == null) return;
navNode.LabelFormatted = value;
}

void SetSubPageTitle(int resId, string value)
{
var value_ = value.ToJavaString();
SetBottomNavigationMenuTitle(resId, value_);
SetNavigationGraphTitle(resId, value_);
this.SetNavigationGraphTitle(resId, value_);
}

protected override void OnCreate(Bundle? savedInstanceState)
{
base.OnCreate(savedInstanceState);

MyPageViewModel.AddTo(this);

var appBarConfiguration = new AppBarConfiguration.Builder(
Resource.Id.navigation_local_auth,
Resource.Id.navigation_community_fix,
Expand Down
3 changes: 2 additions & 1 deletion src/ST.Client.Mobile.Droid/UI/Base/BaseActivity.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
using Android.Runtime;
using Android.Views;
using AndroidX.AppCompat.App;
using ReactiveUI;
using ReactiveUI.AndroidX;
using System.Application.UI.ViewModels;
using XEPlatform = Xamarin.Essentials.Platform;
Expand Down Expand Up @@ -80,7 +81,7 @@ protected override void OnDestroy()
/// </summary>
/// <typeparam name="TViewBinding"></typeparam>
/// <typeparam name="TViewModel"></typeparam>
public abstract partial class BaseActivity<TViewBinding, TViewModel> : ReactiveAppCompatActivity<TViewModel> where TViewBinding : class
public abstract partial class BaseActivity<TViewBinding, TViewModel> : ReactiveAppCompatActivity<TViewModel>, IReadOnlyViewFor<TViewModel> where TViewBinding : class
where TViewModel : ViewModelBase
{
protected override void OnCreate(Bundle? savedInstanceState)
Expand Down
Loading

0 comments on commit 0139aa6

Please sign in to comment.