2021-08-11 14:09:03 +08:00

139 lines
5.4 KiB
C#

using System;
using Gallery.Util;
using Xamarin.Essentials;
using Xamarin.Forms;
namespace Gallery.Resources.UI
{
public static class Definition
{
public const double FontSizeTitle = 18.0;
public static readonly Thickness ScreenBottomPadding;
public static readonly Thickness TopOffset32 = new(0, 32, 0, 0);
public static readonly Color ColorLightShadow = Color.FromRgba(0, 0, 0, 0x20);
public static readonly Color ColorRedBackground = Color.FromRgb(0xfd, 0x43, 0x63);
public static readonly Color ColorDownloadBackground = Color.FromRgb(0xd7, 0xd9, 0xe0);
public static readonly ImageSource DownloadBackground = ImageSource.FromFile("download.png");
public static readonly double FontSizeSmall = Device.GetNamedSize(NamedSize.Small, typeof(Label));
#if __IOS__
public const string IconLightFamily = "FontAwesome5Pro-Light";
public const string IconRegularFamily = "FontAwesome5Pro-Regular";
public const string IconSolidFamily = "FontAwesome5Pro-Solid";
public const string IconLeft = "\uf104";
#elif __ANDROID__
public const string IconLightFamily = "fa-light-300.ttf#FontAwesome5Pro-Light";
public const string IconRegularFamily = "fa-regular-400.ttf#FontAwesome5Pro-Regular";
public const string IconSolidFamily = "fa-solid-900.ttf#FontAwesome5Pro-Solid";
public const string IconLeft = "\uf053";
#endif
public const string IconOption = "\uf013";
public const string IconRefresh = "\uf2f9";
public const string IconLove = "\uf004";
public const string IconCircleLove = "\uf4c7";
public const string IconClose = "\uf057";
static Definition()
{
_ = IsFullscreenDevice;
if (_isBottomPadding)
{
if (DeviceInfo.Idiom == DeviceIdiom.Phone)
{
ScreenBottomPadding = new Thickness(0, 0, 0, 26);
}
else
{
ScreenBottomPadding = new Thickness(0, 0, 0, 16);
}
}
}
private static bool _isBottomPadding;
private static bool? _isFullscreenDevice;
public static bool IsFullscreenDevice
{
get
{
if (_isFullscreenDevice != null)
{
return _isFullscreenDevice.Value;
}
#if __IOS__
try
{
var model = DeviceInfo.Model;
if (model == "iPhone10,3")
{
// iPhone X
_isFullscreenDevice = true;
_isBottomPadding = true;
}
else if (model.StartsWith("iPhone"))
{
var vs = model[6..].Split(',');
if (vs.Length == 2 && int.TryParse(vs[0], out int main) && int.TryParse(vs[1], out int sub))
{
// iPhone X
// iPhone XS/XR/11/12 or newer
var flag = (main == 10 && sub == 6) || main > 10;
_isFullscreenDevice = flag;
_isBottomPadding = flag;
}
else
{
_isFullscreenDevice = false;
}
}
else if (model.StartsWith("iPad"))
{
var vs = model[4..].Split(',');
if (vs.Length == 2 && int.TryParse(vs[0], out int main) && int.TryParse(vs[1], out int sub))
{
// iPad Pro 11-inch (gen 1~3)
// iPad Pro 12.9-inch (gen 3~5)
var flag = main == 8 || (main == 13 && sub >= 4 && sub < 12);
_isBottomPadding = flag;
}
else
{
_isFullscreenDevice = false;
}
}
else
{
#if DEBUG
// simulator
var name = DeviceInfo.Name;
var flag =
name.StartsWith("iPhone X") ||
name.StartsWith("iPhone 11") ||
name.StartsWith("iPhone 12");
_isFullscreenDevice = flag;
_isBottomPadding = flag ||
name.StartsWith("iPad Pro (11-inch)") ||
name.StartsWith("iPad Pro (12.9-inch) (3rd generation)") ||
name.StartsWith("iPad Pro (12.9-inch) (4th generation)") ||
name.StartsWith("iPad Pro (12.9-inch) (5th generation)");
#else
_isFullscreenDevice = false;
#endif
}
}
catch (Exception ex)
{
Log.Error("device.model.get", $"failed to get the device model. {ex.Message}");
}
#else
_isFullscreenDevice = false;
#endif
return _isFullscreenDevice.Value;
}
}
}
}