move service to shared project.

This commit is contained in:
Tsanie Lily 2020-05-11 01:16:33 +08:00
parent 98007c98e4
commit 134affddaa
11 changed files with 60 additions and 142 deletions

View File

@ -70,13 +70,11 @@
<None Include="Info.plist" /> <None Include="Info.plist" />
<Compile Include="Properties\AssemblyInfo.cs" /> <Compile Include="Properties\AssemblyInfo.cs" />
<Compile Include="Renderers\AdaptedPageRenderer.cs" /> <Compile Include="Renderers\AdaptedPageRenderer.cs" />
<Compile Include="Services\EnvironmentService.cs" />
<Compile Include="Renderers\CircleImageRenderer.cs" /> <Compile Include="Renderers\CircleImageRenderer.cs" />
<Compile Include="Renderers\RoundLabelRenderer.cs" /> <Compile Include="Renderers\RoundLabelRenderer.cs" />
<Compile Include="Renderers\CardViewRenderer.cs" /> <Compile Include="Renderers\CardViewRenderer.cs" />
<Compile Include="Renderers\RoundImageRenderer.cs" /> <Compile Include="Renderers\RoundImageRenderer.cs" />
<Compile Include="GlobalSuppressions.cs" /> <Compile Include="GlobalSuppressions.cs" />
<Compile Include="Services\FileStore.cs" />
<Compile Include="Renderers\AppShellRenderer.cs" /> <Compile Include="Renderers\AppShellRenderer.cs" />
<Compile Include="Renderers\AppShellSection\AppShellSectionRootHeader.cs" /> <Compile Include="Renderers\AppShellSection\AppShellSectionRootHeader.cs" />
<Compile Include="Renderers\SegmentedControlRenderer.cs" /> <Compile Include="Renderers\SegmentedControlRenderer.cs" />
@ -157,7 +155,6 @@
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>
<Folder Include="Renderers\" /> <Folder Include="Renderers\" />
<Folder Include="Services\" />
<Folder Include="Renderers\AppShellSection\" /> <Folder Include="Renderers\AppShellSection\" />
<Folder Include="Effects\" /> <Folder Include="Effects\" />
<Folder Include="Assets.xcassets\LauncherLogo.imageset\" /> <Folder Include="Assets.xcassets\LauncherLogo.imageset\" />

View File

@ -1,6 +1,5 @@
using Foundation; using Foundation;
using Pixiview.iOS.Renderers; using Pixiview.iOS.Renderers;
using Pixiview.iOS.Services;
using Pixiview.UI; using Pixiview.UI;
using Pixiview.Utils; using Pixiview.Utils;
using UIKit; using UIKit;

View File

@ -18,22 +18,9 @@ namespace Pixiview
// public properties // public properties
public static AppTheme CurrentTheme { get; private set; } public static AppTheme CurrentTheme { get; private set; }
public static PlatformCulture CurrentCulture { get; private set; } public static PlatformCulture CurrentCulture { get; private set; }
public static Dictionary<string, object> ExtraResources { get; private set; }
private void InitResources(IEnvironmentService service) private void InitResources()
{ {
var p = service.GetEnvironment();
ExtraResources = new Dictionary<string, object>
{
{ ThemeBase.IconLightFontFamily, p.IconLightFontFamily },
{ ThemeBase.IconRegularFontFamily, p.IconRegularFontFamily },
{ ThemeBase.IconSolidFontFamily, p.IconSolidFontFamily },
{ ThemeBase.IconLeft, p.IconLeft }
};
//var theme = service.GetApplicationTheme();
var theme = AppInfo.RequestedTheme; var theme = AppInfo.RequestedTheme;
SetTheme(theme, true); SetTheme(theme, true);
} }
@ -61,10 +48,10 @@ namespace Pixiview
} }
} }
private void InitLanguage(IEnvironmentService service) private void InitLanguage()
{ {
var ci = service.GetCurrentCultureInfo(); var ci = EnvironmentService.GetCurrentCultureInfo();
service.SetCultureInfo(ci); EnvironmentService.SetCultureInfo(ci);
CurrentCulture = new PlatformCulture(ci.Name.ToLower()); CurrentCulture = new PlatformCulture(ci.Name.ToLower());
} }
@ -88,19 +75,20 @@ namespace Pixiview
{ {
themeInstance = LightTheme.Instance; themeInstance = LightTheme.Instance;
} }
//DependencyService.Get<IEnvironmentService>().SetStatusBarColor #if __ANDROID__
EnvironmentService.SetStatusBarColor
#endif
var style = (StatusBarStyles)themeInstance[ThemeBase.StatusBarStyle]; var style = (StatusBarStyles)themeInstance[ThemeBase.StatusBarStyle];
DependencyService.Get<IEnvironmentService>().SetStatusBarStyle(style); EnvironmentService.SetStatusBarStyle(style);
Resources = themeInstance; Resources = themeInstance;
} }
protected override void OnStart() protected override void OnStart()
{ {
var service = DependencyService.Get<IEnvironmentService>(); InitLanguage();
InitLanguage(service);
MainPage = new AppShell(); MainPage = new AppShell();
InitResources(service); InitResources();
InitPreferences(); InitPreferences();
} }
@ -110,7 +98,6 @@ namespace Pixiview
protected override void OnResume() protected override void OnResume()
{ {
//var theme = DependencyService.Get<IEnvironmentService>().GetApplicationTheme();
var theme = AppInfo.RequestedTheme; var theme = AppInfo.RequestedTheme;
SetTheme(theme); SetTheme(theme);
} }

View File

@ -345,8 +345,7 @@ namespace Pixiview.Illust
{ {
MainThread.BeginInvokeOnMainThread(async () => MainThread.BeginInvokeOnMainThread(async () =>
{ {
var service = DependencyService.Get<IFileStore>(); var result = await FileStore.SaveImageToGalleryAsync(image);
var result = await service.SaveImageToGalleryAsync(image);
string message = result ?? ResourceHelper.SaveSuccess; string message = result ?? ResourceHelper.SaveSuccess;
await DisplayAlert(ResourceHelper.Title, message, ResourceHelper.Ok); await DisplayAlert(ResourceHelper.Title, message, ResourceHelper.Ok);

View File

@ -73,8 +73,8 @@
</Compile> </Compile>
<Compile Include="$(MSBuildThisFileDirectory)Utils\Converters.cs" /> <Compile Include="$(MSBuildThisFileDirectory)Utils\Converters.cs" />
<Compile Include="$(MSBuildThisFileDirectory)Utils\Extensions.cs" /> <Compile Include="$(MSBuildThisFileDirectory)Utils\Extensions.cs" />
<Compile Include="$(MSBuildThisFileDirectory)Utils\IEnvironmentService.cs" /> <Compile Include="$(MSBuildThisFileDirectory)Utils\EnvironmentService.cs" />
<Compile Include="$(MSBuildThisFileDirectory)Utils\IFileStore.cs" /> <Compile Include="$(MSBuildThisFileDirectory)Utils\FileStore.cs" />
<Compile Include="$(MSBuildThisFileDirectory)Utils\IllustData.cs" /> <Compile Include="$(MSBuildThisFileDirectory)Utils\IllustData.cs" />
<Compile Include="$(MSBuildThisFileDirectory)Utils\LongPressEffect.cs" /> <Compile Include="$(MSBuildThisFileDirectory)Utils\LongPressEffect.cs" />
<Compile Include="$(MSBuildThisFileDirectory)Utils\Stores.cs" /> <Compile Include="$(MSBuildThisFileDirectory)Utils\Stores.cs" />

View File

@ -7,13 +7,8 @@ namespace Pixiview.UI
public static class StyleDefinition public static class StyleDefinition
{ {
public const double FontSizeTitle = 18.0; public const double FontSizeTitle = 18.0;
public const double FontSizeTitleIcon = 24.0;
public static readonly Thickness ScreenBottomPadding; public static readonly Thickness ScreenBottomPadding;
public static readonly Thickness HorizonLeft10 = new Thickness(10, 0, 0, 0);
public static readonly Thickness HorizonRight10 = new Thickness(0, 0, 10, 0);
public static readonly Thickness LeftBottom10 = new Thickness(10, 0, 0, 10);
public static readonly GridLength TitleIconWidth = 40;
public static readonly Color ColorLightShadow = Color.FromRgba(0, 0, 0, 0x20); public static readonly Color ColorLightShadow = Color.FromRgba(0, 0, 0, 0x20);
public static readonly Color ColorDeepShadow = Color.FromRgba(0, 0, 0, 0x50); public static readonly Color ColorDeepShadow = Color.FromRgba(0, 0, 0, 0x50);
public static readonly Color ColorRedBackground = Color.FromRgb(0xfd, 0x43, 0x63); public static readonly Color ColorRedBackground = Color.FromRgb(0xfd, 0x43, 0x63);
@ -22,6 +17,16 @@ namespace Pixiview.UI
public static readonly double FontSizeMicro = Device.GetNamedSize(NamedSize.Micro, typeof(Label)); public static readonly double FontSizeMicro = Device.GetNamedSize(NamedSize.Micro, typeof(Label));
public static readonly double FontSizeSmall = Device.GetNamedSize(NamedSize.Small, typeof(Label)); public static readonly double FontSizeSmall = Device.GetNamedSize(NamedSize.Small, typeof(Label));
#if __IOS__
public const string IconLightFontFamily = "FontAwesome5Pro-Light";
public const string IconRegularFontFamily = "FontAwesome5Pro-Regular";
public const string IconSolidFontFamily = "FontAwesome5Pro-Solid";
public const string IconLeft = "\uf104";
#else
// TODO
#endif
public const string IconUser = "\uf007"; public const string IconUser = "\uf007";
public const string IconSparkles = "\uf890"; public const string IconSparkles = "\uf890";
public const string IconOrder = "\uf88f"; public const string IconOrder = "\uf88f";
@ -29,7 +34,6 @@ namespace Pixiview.UI
public const string IconRefresh = "\uf2f1"; public const string IconRefresh = "\uf2f1";
public const string IconLove = "\uf004"; public const string IconLove = "\uf004";
public const string IconOption = "\uf013"; public const string IconOption = "\uf013";
public const string IconDownload = "\uf019";
public const string IconFavorite = "\uf02e"; public const string IconFavorite = "\uf02e";
public const string IconShare = "\uf35d"; public const string IconShare = "\uf35d";

View File

@ -11,7 +11,6 @@ namespace Pixiview.UI.Theme
public const string FontIconLove = nameof(FontIconLove); public const string FontIconLove = nameof(FontIconLove);
public const string FontIconNotLove = nameof(FontIconNotLove); public const string FontIconNotLove = nameof(FontIconNotLove);
public const string FontIconOption = nameof(FontIconOption); public const string FontIconOption = nameof(FontIconOption);
public const string FontIconDownload = nameof(FontIconDownload);
public const string FontIconFavorite = nameof(FontIconFavorite); public const string FontIconFavorite = nameof(FontIconFavorite);
public const string FontIconShare = nameof(FontIconShare); public const string FontIconShare = nameof(FontIconShare);
@ -29,36 +28,20 @@ namespace Pixiview.UI.Theme
public const string IconLightFontFamily = nameof(IconLightFontFamily); public const string IconLightFontFamily = nameof(IconLightFontFamily);
public const string IconRegularFontFamily = nameof(IconRegularFontFamily); public const string IconRegularFontFamily = nameof(IconRegularFontFamily);
public const string IconSolidFontFamily = nameof(IconSolidFontFamily); public const string IconSolidFontFamily = nameof(IconSolidFontFamily);
public const string IconLeft = nameof(IconLeft);
public const string FontSizeTitle = nameof(FontSizeTitle);
public const string FontSizeTitleIcon = nameof(FontSizeTitleIcon);
//public const string Horizon10 = nameof(Horizon10); //public const string Horizon10 = nameof(Horizon10);
public const string ScreenBottomPadding = nameof(ScreenBottomPadding); public const string ScreenBottomPadding = nameof(ScreenBottomPadding);
public const string NavigationBarHeight = nameof(NavigationBarHeight);
public const string IconRefresh = nameof(IconRefresh);
public const string IconOption = nameof(IconOption);
public const string IconDownload = nameof(IconDownload);
protected void InitResources() protected void InitResources()
{ {
Add(FontSizeTitle, StyleDefinition.FontSizeTitle);
Add(FontSizeTitleIcon, StyleDefinition.FontSizeTitleIcon);
//Add(Horizon10, StyleDefinition.Horizon10); //Add(Horizon10, StyleDefinition.Horizon10);
Add(ScreenBottomPadding, StyleDefinition.ScreenBottomPadding); Add(ScreenBottomPadding, StyleDefinition.ScreenBottomPadding);
Add(IconRefresh, StyleDefinition.IconRefresh);
Add(IconOption, StyleDefinition.IconOption);
Add(IconDownload, StyleDefinition.IconDownload);
if (App.ExtraResources != null) Add(IconLightFontFamily, StyleDefinition.IconLightFontFamily);
{ Add(IconRegularFontFamily, StyleDefinition.IconRegularFontFamily);
foreach (var kv in App.ExtraResources) Add(IconSolidFontFamily, StyleDefinition.IconSolidFontFamily);
{
Add(kv.Key, kv.Value);
}
}
var regularFontFamily = (string)this[IconRegularFontFamily]; var regularFontFamily = StyleDefinition.IconRegularFontFamily;
var solidFontFamily = (string)this[IconSolidFontFamily]; var solidFontFamily = StyleDefinition.IconSolidFontFamily;
Add(FontIconLove, GetSolidIcon(StyleDefinition.IconLove, solidFontFamily, StyleDefinition.ColorRedBackground)); Add(FontIconLove, GetSolidIcon(StyleDefinition.IconLove, solidFontFamily, StyleDefinition.ColorRedBackground));
Add(FontIconUser, GetSolidIcon(StyleDefinition.IconUser, solidFontFamily)); Add(FontIconUser, GetSolidIcon(StyleDefinition.IconUser, solidFontFamily));
@ -67,7 +50,6 @@ namespace Pixiview.UI.Theme
Add(FontIconRefresh, GetSolidIcon(StyleDefinition.IconRefresh, solidFontFamily)); Add(FontIconRefresh, GetSolidIcon(StyleDefinition.IconRefresh, solidFontFamily));
Add(FontIconNotLove, GetSolidIcon(StyleDefinition.IconLove, regularFontFamily)); Add(FontIconNotLove, GetSolidIcon(StyleDefinition.IconLove, regularFontFamily));
Add(FontIconOption, GetSolidIcon(StyleDefinition.IconOption, solidFontFamily)); Add(FontIconOption, GetSolidIcon(StyleDefinition.IconOption, solidFontFamily));
Add(FontIconDownload, GetSolidIcon(StyleDefinition.IconDownload, solidFontFamily));
Add(FontIconFavorite, GetSolidIcon(StyleDefinition.IconFavorite, solidFontFamily)); Add(FontIconFavorite, GetSolidIcon(StyleDefinition.IconFavorite, solidFontFamily));
Add(FontIconShare, GetSolidIcon(StyleDefinition.IconShare, solidFontFamily)); Add(FontIconShare, GetSolidIcon(StyleDefinition.IconShare, solidFontFamily));
} }

View File

@ -1,30 +1,16 @@
using System.Diagnostics.CodeAnalysis; using System.Diagnostics.CodeAnalysis;
using System.Globalization; using System.Globalization;
using System.Threading; using System.Threading;
using Foundation;
using Pixiview.iOS.Services;
using Pixiview.Resources; using Pixiview.Resources;
using Pixiview.Utils; #if __IOS__
using Foundation;
using UIKit; using UIKit;
using Xamarin.Forms; #endif
[assembly: Dependency(typeof(EnvironmentService))] namespace Pixiview.Utils
namespace Pixiview.iOS.Services
{ {
public class EnvironmentService : IEnvironmentService public class EnvironmentService
{ {
public EnvironmentParameter GetEnvironment()
{
return new EnvironmentParameter
{
IconLightFontFamily = "FontAwesome5Pro-Light",
IconRegularFontFamily = "FontAwesome5Pro-Regular",
IconSolidFontFamily = "FontAwesome5Pro-Solid",
IconLeft = "\uf104" // for android, it's "\uf060"
};
}
#region - Theme - #region - Theme -
/* /*
@ -54,18 +40,11 @@ namespace Pixiview.iOS.Services
} }
//*/ //*/
public void SetStatusBarStyle(StatusBarStyles style) public static void SetStatusBarStyle(StatusBarStyles style)
{ {
SetStatusBarStyle(ConvertStyle(style)); SetStatusBarStyle(ConvertStyle(style));
} }
public void SetStatusBarColor(Color color)
{
// nothing need to do
}
#endregion
public static void SetStatusBarStyle(UIStatusBarStyle style) public static void SetStatusBarStyle(UIStatusBarStyle style)
{ {
if (UIApplication.SharedApplication.StatusBarStyle == style) if (UIApplication.SharedApplication.StatusBarStyle == style)
@ -100,9 +79,19 @@ namespace Pixiview.iOS.Services
} }
} }
#endregion
#region - Culture Info - #region - Culture Info -
public CultureInfo GetCurrentCultureInfo() public static void SetCultureInfo(CultureInfo ci)
{
Thread.CurrentThread.CurrentCulture = ci;
Thread.CurrentThread.CurrentUICulture = ci;
App.DebugPrint($"CurrentCulture set: {ci.Name}");
}
public static CultureInfo GetCurrentCultureInfo()
{ {
string lang; string lang;
if (NSLocale.PreferredLanguages.Length > 0) if (NSLocale.PreferredLanguages.Length > 0)
@ -140,7 +129,7 @@ namespace Pixiview.iOS.Services
} }
[SuppressMessage("Style", "IDE1006:Naming Styles", Justification = "<Pending>")] [SuppressMessage("Style", "IDE1006:Naming Styles", Justification = "<Pending>")]
string iOSToDotnetLanguage(string iOSLanguage) private static string iOSToDotnetLanguage(string iOSLanguage)
{ {
string netLanguage; string netLanguage;
@ -165,7 +154,7 @@ namespace Pixiview.iOS.Services
return netLanguage; return netLanguage;
} }
string ToDotnetFallbackLanguage(PlatformCulture platCulture) private static string ToDotnetFallbackLanguage(PlatformCulture platCulture)
{ {
string netLanguage; string netLanguage;
@ -189,14 +178,6 @@ namespace Pixiview.iOS.Services
return netLanguage; return netLanguage;
} }
public void SetCultureInfo(CultureInfo ci)
{
Thread.CurrentThread.CurrentCulture = ci;
Thread.CurrentThread.CurrentUICulture = ci;
App.DebugPrint($"CurrentCulture set: {ci.Name}");
}
#endregion #endregion
} }
} }

View File

@ -1,17 +1,18 @@
using System.Threading.Tasks; using System.Threading.Tasks;
using Pixiview.iOS.Services;
using Pixiview.Utils;
using Xamarin.Forms; using Xamarin.Forms;
#if __IOS__
using Xamarin.Forms.Platform.iOS; using Xamarin.Forms.Platform.iOS;
#else
using Xamarin.Forms.Platform.Android;
#endif
[assembly: Dependency(typeof(FileStore))] namespace Pixiview.Utils
namespace Pixiview.iOS.Services
{ {
public class FileStore : IFileStore public class FileStore
{ {
public static Task<string> SaveImageToGalleryAsync(ImageSource image)
public Task<string> SaveImageToGalleryAsync(ImageSource image)
{ {
#if __IOS__
IImageSourceHandler renderer; IImageSourceHandler renderer;
if (image is UriImageSource) if (image is UriImageSource)
{ {
@ -40,6 +41,9 @@ namespace Pixiview.iOS.Services
}); });
} }
return task.Task; return task.Task;
#else
// TODO
#endif
} }
} }
} }

View File

@ -1,25 +0,0 @@
using System.Globalization;
using Xamarin.Forms;
namespace Pixiview.Utils
{
public interface IEnvironmentService
{
EnvironmentParameter GetEnvironment();
//AppTheme GetApplicationTheme();
void SetStatusBarStyle(StatusBarStyles style);
void SetStatusBarColor(Color color);
CultureInfo GetCurrentCultureInfo();
void SetCultureInfo(CultureInfo ci);
}
public class EnvironmentParameter
{
public string IconLightFontFamily { get; set; }
public string IconRegularFontFamily { get; set; }
public string IconSolidFontFamily { get; set; }
public string IconLeft { get; set; }
}
}

View File

@ -1,10 +0,0 @@
using System.Threading.Tasks;
using Xamarin.Forms;
namespace Pixiview.Utils
{
public interface IFileStore
{
Task<string> SaveImageToGalleryAsync(ImageSource image);
}
}