1
0
mirror of https://github.com/bitwarden/mobile synced 2025-12-31 23:53:25 +00:00

conditionals if device has camera or not

This commit is contained in:
Kyle Spearrin
2017-09-07 00:33:19 -04:00
parent f5dd91afe5
commit 408e9bf3fc
7 changed files with 74 additions and 39 deletions

View File

@@ -6,5 +6,6 @@
int Version { get; }
float Scale { get; }
bool NfcEnabled { get; }
bool HasCamera { get; }
}
}

View File

@@ -25,6 +25,7 @@ namespace Bit.App.Pages
private readonly IGoogleAnalyticsService _googleAnalyticsService;
private readonly ISettings _settings;
private readonly IAppInfoService _appInfoService;
private readonly IDeviceInfoService _deviceInfo;
private readonly string _defaultUri;
private readonly string _defaultName;
private readonly bool _fromAutofill;
@@ -43,6 +44,7 @@ namespace Bit.App.Pages
_googleAnalyticsService = Resolver.Resolve<IGoogleAnalyticsService>();
_settings = Resolver.Resolve<ISettings>();
_appInfoService = Resolver.Resolve<IAppInfoService>();
_deviceInfo = Resolver.Resolve<IDeviceInfoService>();
Init();
}
@@ -61,8 +63,11 @@ namespace Bit.App.Pages
NotesCell = new FormEditorCell(height: 180);
TotpCell = new FormEntryCell(AppResources.AuthenticatorKey, nextElement: NotesCell.Editor,
useButton: true);
TotpCell.Button.Image = "camera";
useButton: _deviceInfo.HasCamera);
if(_deviceInfo.HasCamera)
{
TotpCell.Button.Image = "camera";
}
TotpCell.Entry.DisableAutocapitalize = true;
TotpCell.Entry.Autocorrect = false;
TotpCell.Entry.FontFamily = Helpers.OnPlatform(iOS: "Courier", Android: "monospace", WinPhone: "Courier");
@@ -142,7 +147,12 @@ namespace Bit.App.Pages
}
else if(Device.RuntimePlatform == Device.Android)
{
PasswordCell.Button.WidthRequest = TotpCell.Button.WidthRequest = 40;
PasswordCell.Button.WidthRequest = 40;
if(TotpCell.Button != null)
{
TotpCell.Button.WidthRequest = 40;
}
}
var saveToolBarItem = new ToolbarItem(AppResources.Save, null, async () =>
@@ -234,7 +244,10 @@ namespace Bit.App.Pages
TotpCell.InitEvents();
FolderCell.InitEvents();
PasswordCell.Button.Clicked += PasswordButton_Clicked;
TotpCell.Button.Clicked += TotpButton_Clicked;
if(TotpCell?.Button != null)
{
TotpCell.Button.Clicked += TotpButton_Clicked;
}
GenerateCell.Tapped += GenerateCell_Tapped;
if(!_fromAutofill && !_settings.GetValueOrDefault(AddedLoginAlertKey, false))
@@ -266,7 +279,10 @@ namespace Bit.App.Pages
TotpCell.Dispose();
FolderCell.Dispose();
PasswordCell.Button.Clicked -= PasswordButton_Clicked;
TotpCell.Button.Clicked -= TotpButton_Clicked;
if(TotpCell?.Button != null)
{
TotpCell.Button.Clicked -= TotpButton_Clicked;
}
GenerateCell.Tapped -= GenerateCell_Tapped;
}

View File

@@ -19,6 +19,7 @@ namespace Bit.App.Pages
private readonly IFolderService _folderService;
private readonly IUserDialogs _userDialogs;
private readonly IConnectivity _connectivity;
private readonly IDeviceInfoService _deviceInfo;
private readonly IGoogleAnalyticsService _googleAnalyticsService;
private DateTime? _lastAction;
@@ -29,6 +30,7 @@ namespace Bit.App.Pages
_folderService = Resolver.Resolve<IFolderService>();
_userDialogs = Resolver.Resolve<IUserDialogs>();
_connectivity = Resolver.Resolve<IConnectivity>();
_deviceInfo = Resolver.Resolve<IDeviceInfoService>();
_googleAnalyticsService = Resolver.Resolve<IGoogleAnalyticsService>();
Init();
@@ -58,9 +60,12 @@ namespace Bit.App.Pages
NotesCell.Editor.Text = login.Notes?.Decrypt(login.OrganizationId);
TotpCell = new FormEntryCell(AppResources.AuthenticatorKey, nextElement: NotesCell.Editor,
useButton: true);
useButton: _deviceInfo.HasCamera);
if(_deviceInfo.HasCamera)
{
TotpCell.Button.Image = "camera";
}
TotpCell.Entry.Text = login.Totp?.Decrypt(login.OrganizationId);
TotpCell.Button.Image = "camera";
TotpCell.Entry.DisableAutocapitalize = true;
TotpCell.Entry.Autocorrect = false;
TotpCell.Entry.FontFamily = Helpers.OnPlatform(iOS: "Courier", Android: "monospace", WinPhone: "Courier");
@@ -161,7 +166,12 @@ namespace Bit.App.Pages
}
else if(Device.RuntimePlatform == Device.Android)
{
PasswordCell.Button.WidthRequest = TotpCell.Button.WidthRequest = 40;
PasswordCell.Button.WidthRequest = 40;
if(TotpCell.Button != null)
{
TotpCell.Button.WidthRequest = 40;
}
}
var saveToolBarItem = new ToolbarItem(AppResources.Save, null, async () =>