mirror of
https://github.com/bitwarden/android.git
synced 2024-10-31 15:15:34 +03:00
conditionals if device has camera or not
This commit is contained in:
parent
f5dd91afe5
commit
408e9bf3fc
7 changed files with 74 additions and 39 deletions
|
@ -13,6 +13,9 @@
|
|||
<uses-permission android:name="com.google.android.c2dm.permission.RECEIVE" />
|
||||
<uses-permission android:name="com.x8bit.bitwarden.permission.C2D_MESSAGE" />
|
||||
|
||||
<uses-feature android:name="android.hardware.camera" android:required="false" />
|
||||
<uses-feature android:name="android.hardware.camera.autofocus" android:required="false" />
|
||||
|
||||
<application android:label="bitwarden" android:theme="@style/BitwardenTheme" android:allowBackup="false">
|
||||
<provider
|
||||
android:name="android.support.v4.content.FileProvider"
|
||||
|
|
|
@ -139,45 +139,47 @@ namespace Bit.Android.Services
|
|||
MessagingCenter.Unsubscribe<Application>(Application.Current, "SelectFileCameraPermissionDenied");
|
||||
|
||||
var hasStorageWritePermission = !_cameraPermissionsDenied && HasPermission(Manifest.Permission.WriteExternalStorage);
|
||||
var hasCameraPermission = !_cameraPermissionsDenied && HasPermission(Manifest.Permission.Camera);
|
||||
|
||||
if(!_cameraPermissionsDenied && !hasStorageWritePermission)
|
||||
{
|
||||
AskCameraPermission(Manifest.Permission.WriteExternalStorage);
|
||||
return Task.FromResult(0);
|
||||
}
|
||||
|
||||
if(!_cameraPermissionsDenied && !hasCameraPermission)
|
||||
{
|
||||
AskCameraPermission(Manifest.Permission.Camera);
|
||||
return Task.FromResult(0);
|
||||
}
|
||||
|
||||
var additionalIntents = new List<IParcelable>();
|
||||
if(Forms.Context.PackageManager.HasSystemFeature(PackageManager.FeatureCamera))
|
||||
{
|
||||
var hasCameraPermission = !_cameraPermissionsDenied && HasPermission(Manifest.Permission.Camera);
|
||||
|
||||
if(!_cameraPermissionsDenied && !hasStorageWritePermission)
|
||||
{
|
||||
AskCameraPermission(Manifest.Permission.WriteExternalStorage);
|
||||
return Task.FromResult(0);
|
||||
}
|
||||
|
||||
if(!_cameraPermissionsDenied && !hasCameraPermission)
|
||||
{
|
||||
AskCameraPermission(Manifest.Permission.Camera);
|
||||
return Task.FromResult(0);
|
||||
}
|
||||
|
||||
if(!_cameraPermissionsDenied && hasCameraPermission && hasStorageWritePermission)
|
||||
{
|
||||
try
|
||||
{
|
||||
var root = new Java.IO.File(global::Android.OS.Environment.ExternalStorageDirectory, "bitwarden");
|
||||
var file = new Java.IO.File(root, "temp_camera_photo.jpg");
|
||||
if(!file.Exists())
|
||||
{
|
||||
file.ParentFile.Mkdirs();
|
||||
file.CreateNewFile();
|
||||
}
|
||||
var outputFileUri = global::Android.Net.Uri.FromFile(file);
|
||||
additionalIntents.AddRange(GetCameraIntents(outputFileUri));
|
||||
}
|
||||
catch(Java.IO.IOException) { }
|
||||
}
|
||||
}
|
||||
|
||||
var docIntent = new Intent(Intent.ActionOpenDocument);
|
||||
docIntent.AddCategory(Intent.CategoryOpenable);
|
||||
docIntent.SetType("*/*");
|
||||
|
||||
var chooserIntent = Intent.CreateChooser(docIntent, AppResources.FileSource);
|
||||
|
||||
if(!_cameraPermissionsDenied && hasCameraPermission && hasStorageWritePermission)
|
||||
{
|
||||
try
|
||||
{
|
||||
var root = new Java.IO.File(global::Android.OS.Environment.ExternalStorageDirectory, "bitwarden");
|
||||
var file = new Java.IO.File(root, "temp_camera_photo.jpg");
|
||||
if(!file.Exists())
|
||||
{
|
||||
file.ParentFile.Mkdirs();
|
||||
file.CreateNewFile();
|
||||
}
|
||||
var outputFileUri = global::Android.Net.Uri.FromFile(file);
|
||||
additionalIntents.AddRange(GetCameraIntents(outputFileUri));
|
||||
}
|
||||
catch(Java.IO.IOException) { }
|
||||
}
|
||||
|
||||
if(additionalIntents.Count > 0)
|
||||
{
|
||||
chooserIntent.PutExtra(Intent.ExtraInitialIntents, additionalIntents.ToArray());
|
||||
|
|
|
@ -1,4 +1,5 @@
|
|||
using Android.App;
|
||||
using Android.Content.PM;
|
||||
using Android.OS;
|
||||
using Bit.App.Abstractions;
|
||||
|
||||
|
@ -42,5 +43,6 @@ namespace Bit.Android.Services
|
|||
}
|
||||
}
|
||||
public bool NfcEnabled => Utilities.NfcEnabled();
|
||||
public bool HasCamera => Xamarin.Forms.Forms.Context.PackageManager.HasSystemFeature(PackageManager.FeatureCamera);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -6,5 +6,6 @@
|
|||
int Version { get; }
|
||||
float Scale { get; }
|
||||
bool NfcEnabled { get; }
|
||||
bool HasCamera { get; }
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
|
||||
|
|
|
@ -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 () =>
|
||||
|
|
|
@ -23,5 +23,6 @@ namespace Bit.iOS.Core.Services
|
|||
}
|
||||
public float Scale => (float)UIScreen.MainScreen.Scale;
|
||||
public bool NfcEnabled => false;
|
||||
public bool HasCamera => true;
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue