move service to shared project.
This commit is contained in:
parent
98007c98e4
commit
134affddaa
@ -70,13 +70,11 @@
|
||||
<None Include="Info.plist" />
|
||||
<Compile Include="Properties\AssemblyInfo.cs" />
|
||||
<Compile Include="Renderers\AdaptedPageRenderer.cs" />
|
||||
<Compile Include="Services\EnvironmentService.cs" />
|
||||
<Compile Include="Renderers\CircleImageRenderer.cs" />
|
||||
<Compile Include="Renderers\RoundLabelRenderer.cs" />
|
||||
<Compile Include="Renderers\CardViewRenderer.cs" />
|
||||
<Compile Include="Renderers\RoundImageRenderer.cs" />
|
||||
<Compile Include="GlobalSuppressions.cs" />
|
||||
<Compile Include="Services\FileStore.cs" />
|
||||
<Compile Include="Renderers\AppShellRenderer.cs" />
|
||||
<Compile Include="Renderers\AppShellSection\AppShellSectionRootHeader.cs" />
|
||||
<Compile Include="Renderers\SegmentedControlRenderer.cs" />
|
||||
@ -157,7 +155,6 @@
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<Folder Include="Renderers\" />
|
||||
<Folder Include="Services\" />
|
||||
<Folder Include="Renderers\AppShellSection\" />
|
||||
<Folder Include="Effects\" />
|
||||
<Folder Include="Assets.xcassets\LauncherLogo.imageset\" />
|
||||
|
@ -1,6 +1,5 @@
|
||||
using Foundation;
|
||||
using Pixiview.iOS.Renderers;
|
||||
using Pixiview.iOS.Services;
|
||||
using Pixiview.UI;
|
||||
using Pixiview.Utils;
|
||||
using UIKit;
|
||||
|
@ -18,22 +18,9 @@ namespace Pixiview
|
||||
// public properties
|
||||
public static AppTheme CurrentTheme { 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;
|
||||
SetTheme(theme, true);
|
||||
}
|
||||
@ -61,10 +48,10 @@ namespace Pixiview
|
||||
}
|
||||
}
|
||||
|
||||
private void InitLanguage(IEnvironmentService service)
|
||||
private void InitLanguage()
|
||||
{
|
||||
var ci = service.GetCurrentCultureInfo();
|
||||
service.SetCultureInfo(ci);
|
||||
var ci = EnvironmentService.GetCurrentCultureInfo();
|
||||
EnvironmentService.SetCultureInfo(ci);
|
||||
CurrentCulture = new PlatformCulture(ci.Name.ToLower());
|
||||
}
|
||||
|
||||
@ -88,19 +75,20 @@ namespace Pixiview
|
||||
{
|
||||
themeInstance = LightTheme.Instance;
|
||||
}
|
||||
//DependencyService.Get<IEnvironmentService>().SetStatusBarColor
|
||||
#if __ANDROID__
|
||||
EnvironmentService.SetStatusBarColor
|
||||
#endif
|
||||
var style = (StatusBarStyles)themeInstance[ThemeBase.StatusBarStyle];
|
||||
DependencyService.Get<IEnvironmentService>().SetStatusBarStyle(style);
|
||||
EnvironmentService.SetStatusBarStyle(style);
|
||||
Resources = themeInstance;
|
||||
}
|
||||
|
||||
protected override void OnStart()
|
||||
{
|
||||
var service = DependencyService.Get<IEnvironmentService>();
|
||||
InitLanguage(service);
|
||||
InitLanguage();
|
||||
MainPage = new AppShell();
|
||||
|
||||
InitResources(service);
|
||||
InitResources();
|
||||
InitPreferences();
|
||||
}
|
||||
|
||||
@ -110,7 +98,6 @@ namespace Pixiview
|
||||
|
||||
protected override void OnResume()
|
||||
{
|
||||
//var theme = DependencyService.Get<IEnvironmentService>().GetApplicationTheme();
|
||||
var theme = AppInfo.RequestedTheme;
|
||||
SetTheme(theme);
|
||||
}
|
||||
|
@ -345,8 +345,7 @@ namespace Pixiview.Illust
|
||||
{
|
||||
MainThread.BeginInvokeOnMainThread(async () =>
|
||||
{
|
||||
var service = DependencyService.Get<IFileStore>();
|
||||
var result = await service.SaveImageToGalleryAsync(image);
|
||||
var result = await FileStore.SaveImageToGalleryAsync(image);
|
||||
|
||||
string message = result ?? ResourceHelper.SaveSuccess;
|
||||
await DisplayAlert(ResourceHelper.Title, message, ResourceHelper.Ok);
|
||||
|
@ -73,8 +73,8 @@
|
||||
</Compile>
|
||||
<Compile Include="$(MSBuildThisFileDirectory)Utils\Converters.cs" />
|
||||
<Compile Include="$(MSBuildThisFileDirectory)Utils\Extensions.cs" />
|
||||
<Compile Include="$(MSBuildThisFileDirectory)Utils\IEnvironmentService.cs" />
|
||||
<Compile Include="$(MSBuildThisFileDirectory)Utils\IFileStore.cs" />
|
||||
<Compile Include="$(MSBuildThisFileDirectory)Utils\EnvironmentService.cs" />
|
||||
<Compile Include="$(MSBuildThisFileDirectory)Utils\FileStore.cs" />
|
||||
<Compile Include="$(MSBuildThisFileDirectory)Utils\IllustData.cs" />
|
||||
<Compile Include="$(MSBuildThisFileDirectory)Utils\LongPressEffect.cs" />
|
||||
<Compile Include="$(MSBuildThisFileDirectory)Utils\Stores.cs" />
|
||||
|
@ -7,13 +7,8 @@ namespace Pixiview.UI
|
||||
public static class StyleDefinition
|
||||
{
|
||||
public const double FontSizeTitle = 18.0;
|
||||
public const double FontSizeTitleIcon = 24.0;
|
||||
|
||||
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 ColorDeepShadow = Color.FromRgba(0, 0, 0, 0x50);
|
||||
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 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 IconSparkles = "\uf890";
|
||||
public const string IconOrder = "\uf88f";
|
||||
@ -29,7 +34,6 @@ namespace Pixiview.UI
|
||||
public const string IconRefresh = "\uf2f1";
|
||||
public const string IconLove = "\uf004";
|
||||
public const string IconOption = "\uf013";
|
||||
public const string IconDownload = "\uf019";
|
||||
public const string IconFavorite = "\uf02e";
|
||||
public const string IconShare = "\uf35d";
|
||||
|
||||
|
@ -11,7 +11,6 @@ namespace Pixiview.UI.Theme
|
||||
public const string FontIconLove = nameof(FontIconLove);
|
||||
public const string FontIconNotLove = nameof(FontIconNotLove);
|
||||
public const string FontIconOption = nameof(FontIconOption);
|
||||
public const string FontIconDownload = nameof(FontIconDownload);
|
||||
public const string FontIconFavorite = nameof(FontIconFavorite);
|
||||
public const string FontIconShare = nameof(FontIconShare);
|
||||
|
||||
@ -29,36 +28,20 @@ namespace Pixiview.UI.Theme
|
||||
public const string IconLightFontFamily = nameof(IconLightFontFamily);
|
||||
public const string IconRegularFontFamily = nameof(IconRegularFontFamily);
|
||||
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 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()
|
||||
{
|
||||
Add(FontSizeTitle, StyleDefinition.FontSizeTitle);
|
||||
Add(FontSizeTitleIcon, StyleDefinition.FontSizeTitleIcon);
|
||||
//Add(Horizon10, StyleDefinition.Horizon10);
|
||||
Add(ScreenBottomPadding, StyleDefinition.ScreenBottomPadding);
|
||||
Add(IconRefresh, StyleDefinition.IconRefresh);
|
||||
Add(IconOption, StyleDefinition.IconOption);
|
||||
Add(IconDownload, StyleDefinition.IconDownload);
|
||||
|
||||
if (App.ExtraResources != null)
|
||||
{
|
||||
foreach (var kv in App.ExtraResources)
|
||||
{
|
||||
Add(kv.Key, kv.Value);
|
||||
}
|
||||
}
|
||||
Add(IconLightFontFamily, StyleDefinition.IconLightFontFamily);
|
||||
Add(IconRegularFontFamily, StyleDefinition.IconRegularFontFamily);
|
||||
Add(IconSolidFontFamily, StyleDefinition.IconSolidFontFamily);
|
||||
|
||||
var regularFontFamily = (string)this[IconRegularFontFamily];
|
||||
var solidFontFamily = (string)this[IconSolidFontFamily];
|
||||
var regularFontFamily = StyleDefinition.IconRegularFontFamily;
|
||||
var solidFontFamily = StyleDefinition.IconSolidFontFamily;
|
||||
|
||||
Add(FontIconLove, GetSolidIcon(StyleDefinition.IconLove, solidFontFamily, StyleDefinition.ColorRedBackground));
|
||||
Add(FontIconUser, GetSolidIcon(StyleDefinition.IconUser, solidFontFamily));
|
||||
@ -67,7 +50,6 @@ namespace Pixiview.UI.Theme
|
||||
Add(FontIconRefresh, GetSolidIcon(StyleDefinition.IconRefresh, solidFontFamily));
|
||||
Add(FontIconNotLove, GetSolidIcon(StyleDefinition.IconLove, regularFontFamily));
|
||||
Add(FontIconOption, GetSolidIcon(StyleDefinition.IconOption, solidFontFamily));
|
||||
Add(FontIconDownload, GetSolidIcon(StyleDefinition.IconDownload, solidFontFamily));
|
||||
Add(FontIconFavorite, GetSolidIcon(StyleDefinition.IconFavorite, solidFontFamily));
|
||||
Add(FontIconShare, GetSolidIcon(StyleDefinition.IconShare, solidFontFamily));
|
||||
}
|
||||
|
@ -1,30 +1,16 @@
|
||||
using System.Diagnostics.CodeAnalysis;
|
||||
using System.Globalization;
|
||||
using System.Globalization;
|
||||
using System.Threading;
|
||||
using Foundation;
|
||||
using Pixiview.iOS.Services;
|
||||
using Pixiview.Resources;
|
||||
using Pixiview.Utils;
|
||||
#if __IOS__
|
||||
using Foundation;
|
||||
using UIKit;
|
||||
using Xamarin.Forms;
|
||||
#endif
|
||||
|
||||
[assembly: Dependency(typeof(EnvironmentService))]
|
||||
namespace Pixiview.iOS.Services
|
||||
namespace Pixiview.Utils
|
||||
{
|
||||
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 -
|
||||
|
||||
/*
|
||||
@ -54,18 +40,11 @@ namespace Pixiview.iOS.Services
|
||||
}
|
||||
//*/
|
||||
|
||||
public void SetStatusBarStyle(StatusBarStyles style)
|
||||
public static void SetStatusBarStyle(StatusBarStyles style)
|
||||
{
|
||||
SetStatusBarStyle(ConvertStyle(style));
|
||||
}
|
||||
|
||||
public void SetStatusBarColor(Color color)
|
||||
{
|
||||
// nothing need to do
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
public static void SetStatusBarStyle(UIStatusBarStyle style)
|
||||
{
|
||||
if (UIApplication.SharedApplication.StatusBarStyle == style)
|
||||
@ -100,9 +79,19 @@ namespace Pixiview.iOS.Services
|
||||
}
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#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;
|
||||
if (NSLocale.PreferredLanguages.Length > 0)
|
||||
@ -140,7 +129,7 @@ namespace Pixiview.iOS.Services
|
||||
}
|
||||
|
||||
[SuppressMessage("Style", "IDE1006:Naming Styles", Justification = "<Pending>")]
|
||||
string iOSToDotnetLanguage(string iOSLanguage)
|
||||
private static string iOSToDotnetLanguage(string iOSLanguage)
|
||||
{
|
||||
string netLanguage;
|
||||
|
||||
@ -165,7 +154,7 @@ namespace Pixiview.iOS.Services
|
||||
return netLanguage;
|
||||
}
|
||||
|
||||
string ToDotnetFallbackLanguage(PlatformCulture platCulture)
|
||||
private static string ToDotnetFallbackLanguage(PlatformCulture platCulture)
|
||||
{
|
||||
string netLanguage;
|
||||
|
||||
@ -189,14 +178,6 @@ namespace Pixiview.iOS.Services
|
||||
return netLanguage;
|
||||
}
|
||||
|
||||
public void SetCultureInfo(CultureInfo ci)
|
||||
{
|
||||
Thread.CurrentThread.CurrentCulture = ci;
|
||||
Thread.CurrentThread.CurrentUICulture = ci;
|
||||
|
||||
App.DebugPrint($"CurrentCulture set: {ci.Name}");
|
||||
}
|
||||
|
||||
#endregion
|
||||
}
|
||||
}
|
@ -1,17 +1,18 @@
|
||||
using System.Threading.Tasks;
|
||||
using Pixiview.iOS.Services;
|
||||
using Pixiview.Utils;
|
||||
using System.Threading.Tasks;
|
||||
using Xamarin.Forms;
|
||||
#if __IOS__
|
||||
using Xamarin.Forms.Platform.iOS;
|
||||
#else
|
||||
using Xamarin.Forms.Platform.Android;
|
||||
#endif
|
||||
|
||||
[assembly: Dependency(typeof(FileStore))]
|
||||
namespace Pixiview.iOS.Services
|
||||
namespace Pixiview.Utils
|
||||
{
|
||||
public class FileStore : IFileStore
|
||||
public class FileStore
|
||||
{
|
||||
|
||||
public Task<string> SaveImageToGalleryAsync(ImageSource image)
|
||||
public static Task<string> SaveImageToGalleryAsync(ImageSource image)
|
||||
{
|
||||
#if __IOS__
|
||||
IImageSourceHandler renderer;
|
||||
if (image is UriImageSource)
|
||||
{
|
||||
@ -40,6 +41,9 @@ namespace Pixiview.iOS.Services
|
||||
});
|
||||
}
|
||||
return task.Task;
|
||||
#else
|
||||
// TODO
|
||||
#endif
|
||||
}
|
||||
}
|
||||
}
|
@ -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; }
|
||||
}
|
||||
}
|
@ -1,10 +0,0 @@
|
||||
using System.Threading.Tasks;
|
||||
using Xamarin.Forms;
|
||||
|
||||
namespace Pixiview.Utils
|
||||
{
|
||||
public interface IFileStore
|
||||
{
|
||||
Task<string> SaveImageToGalleryAsync(ImageSource image);
|
||||
}
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user