accessibility settings page

This commit is contained in:
Kyle Spearrin 2019-06-03 12:05:18 -04:00
parent 7ed45c3535
commit 22f16ea514
8 changed files with 216 additions and 2 deletions

View file

@ -512,6 +512,35 @@ namespace Bit.Droid.Services
return afm.IsEnabled && afm.HasEnabledAutofillServices;
}
public void OpenAccessibilitySettings()
{
var activity = (MainActivity)CrossCurrentActivity.Current.Activity;
var intent = new Intent(Settings.ActionAccessibilitySettings);
activity.StartActivity(intent);
}
public void OpenAutofillSettings()
{
var activity = (MainActivity)CrossCurrentActivity.Current.Activity;
try
{
var intent = new Intent(Settings.ActionRequestSetAutofillService);
intent.SetData(Android.Net.Uri.Parse("package:com.x8bit.bitwarden"));
activity.StartActivity(intent);
}
catch(ActivityNotFoundException)
{
var alertBuilder = new AlertDialog.Builder(activity);
alertBuilder.SetMessage(AppResources.BitwardenAutofillGoToSettings);
alertBuilder.SetCancelable(true);
alertBuilder.SetPositiveButton(AppResources.Ok, (sender, args) =>
{
(sender as AlertDialog)?.Cancel();
});
alertBuilder.Create().Show();
}
}
private bool DeleteDir(Java.IO.File dir)
{
if(dir != null && dir.IsDirectory)

View file

@ -31,5 +31,7 @@ namespace Bit.App.Abstractions
bool AutofillAccessibilityServiceRunning();
bool AutofillServiceEnabled();
string GetBuildNumber();
void OpenAccessibilitySettings();
void OpenAutofillSettings();
}
}

View file

@ -60,6 +60,9 @@
<Compile Update="Pages\Settings\OptionsPage.xaml.cs">
<DependentUpon>OptionsPage.xaml</DependentUpon>
</Compile>
<Compile Update="Pages\Settings\AccessibilityServicePage.xaml.cs">
<DependentUpon>AccessibilityServicePage.xaml</DependentUpon>
</Compile>
<Compile Update="Pages\Settings\SyncPage.xaml.cs">
<DependentUpon>SyncPage.xaml</DependentUpon>
</Compile>

View file

@ -0,0 +1,85 @@
<?xml version="1.0" encoding="utf-8" ?>
<pages:BaseContentPage
xmlns="http://xamarin.com/schemas/2014/forms"
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
x:Class="Bit.App.Pages.AccessibilityServicePage"
xmlns:pages="clr-namespace:Bit.App.Pages"
xmlns:u="clr-namespace:Bit.App.Utilities"
x:DataType="pages:AccessibilityServicePageViewModel"
Title="{Binding PageTitle}">
<ContentPage.BindingContext>
<pages:AccessibilityServicePageViewModel />
</ContentPage.BindingContext>
<ContentPage.Resources>
<ResourceDictionary>
<u:InverseBoolConverter x:Key="inverseBool" />
</ResourceDictionary>
</ContentPage.Resources>
<ScrollView>
<StackLayout Spacing="20"
Padding="10, 30"
VerticalOptions="FillAndExpand">
<Label Text="{u:I18n AutofillAccessibilityDescription}"
VerticalOptions="Start"
HorizontalTextAlignment="Center"
LineBreakMode="WordWrap" />
<StackLayout IsVisible="{Binding Enabled, Converter={StaticResource inverseBool}}"
VerticalOptions="CenterAndExpand"
HorizontalOptions="Center">
<StackLayout Orientation="Horizontal" HorizontalOptions="CenterAndExpand">
<Label Text="{u:I18n Status}" />
<Label Text="{u:I18n Disabled}"
StyleClass="text-danger, text-bold" />
</StackLayout>
<Image Source="accessibility_step1.png"
HorizontalOptions="Center"
Margin="0, 20, 0, 0"
WidthRequest="300"
HeightRequest="98" />
<Label Text="{u:I18n BitwardenAutofillServiceStep1}"
HorizontalTextAlignment="Center"
LineBreakMode="WordWrap"
StyleClass="text-sm" />
<Image Source="accessibility_step2.png"
HorizontalOptions="Center"
Margin="0, 20, 0, 0"
WidthRequest="300"
HeightRequest="67" />
<Label Text="{u:I18n BitwardenAutofillServiceStep2}"
HorizontalTextAlignment="Center"
LineBreakMode="WordWrap"
StyleClass="text-sm" />
</StackLayout>
<StackLayout IsVisible="{Binding Enabled}"
VerticalOptions="CenterAndExpand"
HorizontalOptions="Center">
<StackLayout Orientation="Horizontal" HorizontalOptions="Center">
<Label Text="{u:I18n Status}" />
<Label Text="{u:I18n Enabled}"
StyleClass="text-success, text-bold" />
</StackLayout>
<Image Source="accessibility_notification_icon.png"
HorizontalOptions="Center"
Margin="0, 20, 0, 0"
WidthRequest="300"
HeightRequest="54" />
<Image Source="accessibility_notification.png"
HorizontalOptions="Center"
Margin="0, 20, 0, 0"
WidthRequest="300"
HeightRequest="74" />
<Label Text="{u:I18n BitwardenAutofillServiceNotification}"
HorizontalTextAlignment="Center"
LineBreakMode="WordWrap"
StyleClass="text-sm" />
</StackLayout>
<Button Text="{u:I18n BitwardenAutofillServiceOpenAccessibilitySettings}"
Clicked="Settings_Clicked"
HorizontalOptions="Fill"
VerticalOptions="End"></Button>
</StackLayout>
</ScrollView>
</pages:BaseContentPage>

View file

@ -0,0 +1,52 @@
using System;
using Xamarin.Forms;
namespace Bit.App.Pages
{
public partial class AccessibilityServicePage : BaseContentPage
{
private readonly AccessibilityServicePageViewModel _vm;
private readonly SettingsPage _settingsPage;
private DateTime? _timerStarted = null;
private TimeSpan _timerMaxLength = TimeSpan.FromMinutes(5);
public AccessibilityServicePage(SettingsPage settingsPage)
{
InitializeComponent();
_vm = BindingContext as AccessibilityServicePageViewModel;
_vm.Page = this;
_settingsPage = settingsPage;
}
protected override void OnAppearing()
{
_vm.UpdateEnabled();
_timerStarted = DateTime.UtcNow;
Device.StartTimer(new TimeSpan(0, 0, 3), () =>
{
if(_timerStarted == null || (DateTime.UtcNow - _timerStarted) > _timerMaxLength)
{
return false;
}
_vm.UpdateEnabled();
return true;
});
base.OnAppearing();
}
protected override void OnDisappearing()
{
_timerStarted = null;
_settingsPage.BuildList();
base.OnDisappearing();
}
private void Settings_Clicked(object sender, EventArgs e)
{
if(DoOnce())
{
_vm.OpenSettings();
}
}
}
}

View file

@ -0,0 +1,38 @@
using Bit.App.Abstractions;
using Bit.App.Resources;
using Bit.Core.Abstractions;
using Bit.Core.Utilities;
namespace Bit.App.Pages
{
public class AccessibilityServicePageViewModel : BaseViewModel
{
private readonly IDeviceActionService _deviceActionService;
private readonly IPlatformUtilsService _platformUtilsService;
private bool _enabled;
public AccessibilityServicePageViewModel()
{
_deviceActionService = ServiceContainer.Resolve<IDeviceActionService>("deviceActionService");
_platformUtilsService = ServiceContainer.Resolve<IPlatformUtilsService>("platformUtilsService");
PageTitle = AppResources.AutofillAccessibilityService;
}
public bool Enabled
{
get => _enabled;
set => SetProperty(ref _enabled, value);
}
public void OpenSettings()
{
_deviceActionService.OpenAccessibilitySettings();
}
public void UpdateEnabled()
{
Enabled = _deviceActionService.AutofillAccessibilityServiceRunning();
}
}
}

View file

@ -26,6 +26,11 @@ namespace Bit.App.Pages
await _vm.InitAsync();
}
public void BuildList()
{
_vm.BuildList();
}
protected override bool OnBackButtonPressed()
{
if(Device.RuntimePlatform == Device.Android && _tabsPage != null)
@ -54,7 +59,7 @@ namespace Bit.App.Pages
}
else if(item.Name == AppResources.AutofillAccessibilityService)
{
// await Navigation.PushModalAsync(new NavigationPage(new OptionsPage()));
await Navigation.PushModalAsync(new NavigationPage(new AccessibilityServicePage(this)));
}
else if(item.Name == AppResources.AutofillService)
{

View file

@ -270,7 +270,7 @@ namespace Bit.App.Pages
BuildList();
}
private void BuildList()
public void BuildList()
{
var doUpper = Device.RuntimePlatform != Device.Android;
var autofillItems = new List<SettingsPageListItem>();