add type to deviceinfo to avoid using XF

This commit is contained in:
Kyle Spearrin 2017-12-21 13:10:55 -05:00
parent 379a82972a
commit 2b4ffaa357
6 changed files with 14 additions and 5 deletions

View file

@ -8,6 +8,7 @@ namespace Bit.Android.Services
{ {
public class DeviceInfoService : IDeviceInfoService public class DeviceInfoService : IDeviceInfoService
{ {
public string Type => Xamarin.Forms.Device.Android;
public string Model => Build.Model; public string Model => Build.Model;
public int Version => (int)Build.VERSION.SdkInt; public int Version => (int)Build.VERSION.SdkInt;
public float Scale public float Scale

View file

@ -2,6 +2,7 @@
{ {
public interface IDeviceInfoService public interface IDeviceInfoService
{ {
string Type { get; }
string Model { get; } string Model { get; }
int Version { get; } int Version { get; }
float Scale { get; } float Scale { get; }

View file

@ -23,9 +23,14 @@ namespace Bit.App.Utilities
} }
public static T OnPlatform<T>(T iOS = default(T), T Android = default(T), public static T OnPlatform<T>(T iOS = default(T), T Android = default(T),
T WinPhone = default(T), T Windows = default(T)) T WinPhone = default(T), T Windows = default(T), string platform = null)
{ {
switch(Device.RuntimePlatform) if(platform == null)
{
platform = Device.RuntimePlatform;
}
switch(platform)
{ {
case Device.iOS: case Device.iOS:
return iOS; return iOS;

View file

@ -14,6 +14,7 @@ namespace Bit.App
{ {
var tokenService = Resolver.Resolve<ITokenService>(); var tokenService = Resolver.Resolve<ITokenService>();
var appIdService = Resolver.Resolve<IAppIdService>(); var appIdService = Resolver.Resolve<IAppIdService>();
var deviceInfoService = Resolver.Resolve<IDeviceInfoService>();
if(!string.IsNullOrWhiteSpace(tokenService.Token)) if(!string.IsNullOrWhiteSpace(tokenService.Token))
{ {
@ -25,7 +26,7 @@ namespace Bit.App
} }
Headers.Add("Device-Type", ((int)Helpers.OnPlatform(iOS: DeviceType.iOS, Headers.Add("Device-Type", ((int)Helpers.OnPlatform(iOS: DeviceType.iOS,
Android: DeviceType.Android, Windows: DeviceType.UWP)).ToString()); Android: DeviceType.Android, Windows: DeviceType.UWP, platform: deviceInfoService.Type)).ToString());
} }
public TokenHttpRequestMessage(object requestObject) public TokenHttpRequestMessage(object requestObject)

View file

@ -13,6 +13,7 @@ namespace Bit.UWP.Services
{ {
private const string SmartCardEmulatorType = "Windows.Devices.SmartCards.SmartCardEmulator"; private const string SmartCardEmulatorType = "Windows.Devices.SmartCards.SmartCardEmulator";
public string Type => Xamarin.Forms.Device.UWP;
public string Model => SystemInformation.DeviceModel; public string Model => SystemInformation.DeviceModel;
public int Version => SystemInformation.OperatingSystemVersion.Build; public int Version => SystemInformation.OperatingSystemVersion.Build;
public float Scale => (float)DisplayInformation.GetForCurrentView().RawPixelsPerViewPixel; public float Scale => (float)DisplayInformation.GetForCurrentView().RawPixelsPerViewPixel;

View file

@ -7,14 +7,14 @@ namespace Bit.iOS.Core.Services
{ {
public class DeviceInfoService : IDeviceInfoService public class DeviceInfoService : IDeviceInfoService
{ {
public string Type => Xamarin.Forms.Device.iOS;
public string Model => UIDevice.CurrentDevice.Model; public string Model => UIDevice.CurrentDevice.Model;
public int Version public int Version
{ {
get get
{ {
int version;
var versionParts = UIDevice.CurrentDevice.SystemVersion.Split('.'); var versionParts = UIDevice.CurrentDevice.SystemVersion.Split('.');
if(versionParts.Length > 0 && int.TryParse(versionParts[0], out version)) if(versionParts.Length > 0 && int.TryParse(versionParts[0], out int version))
{ {
return version; return version;
} }