diff --git a/Gallery.Share/App.cs b/Gallery.Share/App.cs new file mode 100644 index 0000000..f31de39 --- /dev/null +++ b/Gallery.Share/App.cs @@ -0,0 +1,85 @@ +using Xamarin.Forms; +using Gallery.Services; +using Xamarin.Essentials; +using Gallery.Resources; +using Gallery.Util; +using Gallery.Resources.Theme; + +namespace Gallery +{ + public partial class App : Application + { + public static AppTheme CurrentTheme { get; private set; } + public static PlatformCulture CurrentCulture { get; private set; } + + public App() + { + DependencyService.Register(); + } + + private void InitResource() + { + var theme = AppInfo.RequestedTheme; + SetTheme(theme, true); + } + + private void InitPreference() + { + + } + + private void InitLanguage() + { + var ci = Environment.GetCurrentCultureInfo(); + Environment.SetCultureInfo(ci); + CurrentCulture = new PlatformCulture(ci.Name.ToLower()); + } + + private void SetTheme(AppTheme theme, bool force = false) + { + if (force || theme != CurrentTheme) + { + CurrentTheme = theme; + } + else + { + return; + } +#if DEBUG + Log.Print($"application theme: {theme}"); +#endif + Theme themeInstance = theme switch + { + AppTheme.Dark => DarkTheme.Instance, + _ => LightTheme.Instance + }; +#if __IOS__ + var style = (StatusBarStyles)themeInstance[Theme.StatusBarStyle]; + Environment.SetStatusBarStyle(style); +#elif __ANDROID__ + var color = (Color)themeInstance[Theme.NavigationColor]; + Environment.SetStatusBarColor(color); +#endif + Resources = themeInstance; + } + + protected override void OnStart() + { + InitLanguage(); + MainPage = new AppShell(); + + InitResource(); + InitPreference(); + } + + protected override void OnSleep() + { + } + + protected override void OnResume() + { + var theme = AppInfo.RequestedTheme; + SetTheme(theme); + } + } +} diff --git a/Gallery.Share/App.xaml b/Gallery.Share/App.xaml deleted file mode 100644 index 941638c..0000000 --- a/Gallery.Share/App.xaml +++ /dev/null @@ -1,32 +0,0 @@ - - - - - - #2196F3 - - - - diff --git a/Gallery.Share/App.xaml.cs b/Gallery.Share/App.xaml.cs deleted file mode 100644 index 02e8a23..0000000 --- a/Gallery.Share/App.xaml.cs +++ /dev/null @@ -1,32 +0,0 @@ -using System; -using Xamarin.Forms; -using Xamarin.Forms.Xaml; -using Gallery.Services; -using Gallery.Views; - -namespace Gallery -{ - public partial class App : Application - { - - public App() - { - InitializeComponent(); - - DependencyService.Register(); - MainPage = new AppShell(); - } - - protected override void OnStart() - { - } - - protected override void OnSleep() - { - } - - protected override void OnResume() - { - } - } -} diff --git a/Gallery.Share/AppShell.xaml b/Gallery.Share/AppShell.xaml index 234c874..44a59fe 100644 --- a/Gallery.Share/AppShell.xaml +++ b/Gallery.Share/AppShell.xaml @@ -14,12 +14,12 @@