1
0
mirror of https://github.com/bitwarden/mobile.git synced 2024-12-26 16:57:59 +01:00

autofill pages for ios

This commit is contained in:
Kyle Spearrin 2019-07-02 13:15:00 -04:00
parent e01bf57874
commit c2c73d5460
9 changed files with 311 additions and 9 deletions

View File

@ -51,6 +51,12 @@
<Compile Update="Pages\Generator\GeneratorHistoryPage.xaml.cs">
<DependentUpon>GeneratorHistoryPage.xaml</DependentUpon>
</Compile>
<Compile Update="Pages\Settings\AutofillPage.xaml.cs">
<DependentUpon>AutofillPage.xaml</DependentUpon>
</Compile>
<Compile Update="Pages\Settings\ExtensionPage.xaml.cs">
<DependentUpon>ExtensionPage.xaml</DependentUpon>
</Compile>
<Compile Update="Pages\Settings\AutofillServicePage.xaml.cs">
<DependentUpon>AutofillServicePage.xaml</DependentUpon>
</Compile>

View File

@ -0,0 +1,48 @@
<?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.AutofillPage"
xmlns:pages="clr-namespace:Bit.App.Pages"
xmlns:u="clr-namespace:Bit.App.Utilities"
Title="{u:I18n PasswordAutofill}">
<ContentPage.ToolbarItems>
<ToolbarItem Text="{u:I18n Close}" Clicked="Close_Clicked" Order="Primary" Priority="-1" />
</ContentPage.ToolbarItems>
<ScrollView>
<StackLayout Spacing="5"
Padding="20, 20, 20, 30"
VerticalOptions="FillAndExpand">
<Label Text="{u:I18n ExtensionInstantAccess}"
HorizontalOptions="Center"
HorizontalTextAlignment="Center"
LineBreakMode="WordWrap"
StyleClass="text-lg"
Margin="0, 0, 0, 15" />
<Label Text="{u:I18n AutofillTurnOn}"
HorizontalOptions="Center"
HorizontalTextAlignment="Center"
LineBreakMode="WordWrap"
Margin="0, 0, 0, 15" />
<Label Text="{u:I18n AutofillTurnOn1}"
LineBreakMode="WordWrap" />
<Label Text="{u:I18n AutofillTurnOn2}"
LineBreakMode="WordWrap" />
<Label Text="{u:I18n AutofillTurnOn3}"
LineBreakMode="WordWrap" />
<Label Text="{u:I18n AutofillTurnOn4}"
LineBreakMode="WordWrap" />
<Label Text="{u:I18n AutofillTurnOn5}"
LineBreakMode="WordWrap" />
<Image Source="autofill-kb.png"
VerticalOptions="CenterAndExpand"
HorizontalOptions="Center"
Margin="0, 10, 0, 0"
WidthRequest="290"
HeightRequest="252" />
</StackLayout>
</ScrollView>
</pages:BaseContentPage>

View File

@ -0,0 +1,20 @@
using System;
namespace Bit.App.Pages
{
public partial class AutofillPage : BaseContentPage
{
public AutofillPage()
{
InitializeComponent();
}
private void Close_Clicked(object sender, EventArgs e)
{
if(DoOnce())
{
Navigation.PopModalAsync();
}
}
}
}

View File

@ -0,0 +1,99 @@
<?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.ExtensionPage"
xmlns:pages="clr-namespace:Bit.App.Pages"
xmlns:u="clr-namespace:Bit.App.Utilities"
x:DataType="pages:ExtensionPageViewModel"
Title="{Binding PageTitle}">
<ContentPage.BindingContext>
<pages:ExtensionPageViewModel />
</ContentPage.BindingContext>
<ContentPage.ToolbarItems>
<ToolbarItem Text="{u:I18n Close}" Clicked="Close_Clicked" Order="Primary" Priority="-1" />
</ContentPage.ToolbarItems>
<ScrollView>
<StackLayout Padding="0" Spacing="0" VerticalOptions="FillAndExpand">
<StackLayout Spacing="20"
Padding="20, 20, 20, 30"
VerticalOptions="FillAndExpand"
IsVisible="{Binding NotStarted}">
<Label Text="{u:I18n ExtensionInstantAccess}"
StyleClass="text-lg"
HorizontalOptions="Center"
HorizontalTextAlignment="Center"
LineBreakMode="WordWrap" />
<Label Text="{u:I18n ExtensionTurnOn}"
HorizontalOptions="Center"
HorizontalTextAlignment="Center"
LineBreakMode="WordWrap" />
<Image Source="ext-more.png"
VerticalOptions="CenterAndExpand"
HorizontalOptions="Center"
Margin="0, -10, 0, 0"
WidthRequest="290"
HeightRequest="252" />
<Button Text="{u:I18n ExtensionEnable}"
Clicked="Show_Clicked"
VerticalOptions="End"
HorizontalOptions="Fill" />
</StackLayout>
<StackLayout Spacing="20"
Padding="20, 20, 20, 30"
VerticalOptions="FillAndExpand"
IsVisible="{Binding StartedAndNotActivated}">
<Label Text="{u:I18n ExtensionAlmostDone}"
StyleClass="text-lg"
HorizontalOptions="Center"
HorizontalTextAlignment="Center"
LineBreakMode="WordWrap" />
<Label Text="{u:I18n ExtensionTapIcon}"
HorizontalOptions="Center"
HorizontalTextAlignment="Center"
LineBreakMode="WordWrap" />
<Image Source="ext-act.png"
VerticalOptions="CenterAndExpand"
HorizontalOptions="Center"
Margin="0, -10, 0, 0"
WidthRequest="290"
HeightRequest="252" />
<Button Text="{u:I18n ExtensionEnable}"
Clicked="Show_Clicked"
VerticalOptions="End"
HorizontalOptions="Fill" />
</StackLayout>
<StackLayout Spacing="20"
Padding="20, 20, 20, 30"
VerticalOptions="FillAndExpand"
IsVisible="{Binding StartedAndActivated}">
<Label Text="{u:I18n ExtensionReady}"
StyleClass="text-lg"
HorizontalOptions="Center"
HorizontalTextAlignment="Center"
LineBreakMode="WordWrap" />
<Label Text="{u:I18n ExtensionInSafari}"
HorizontalOptions="Center"
HorizontalTextAlignment="Center"
LineBreakMode="WordWrap" />
<Image Source="ext-use.png"
VerticalOptions="CenterAndExpand"
HorizontalOptions="Center"
Margin="0, -10, 0, 0"
WidthRequest="290"
HeightRequest="252" />
<Button Text="{u:I18n ExtensionSeeApps}"
Clicked="SeeApps_Clicked"
VerticalOptions="End"
HorizontalOptions="Fill" />
<Button Text="{u:I18n ExntesionReenable}"
Clicked="Show_Clicked"
VerticalOptions="End"
HorizontalOptions="Fill" />
</StackLayout>
</StackLayout>
</ScrollView>
</pages:BaseContentPage>

View File

@ -0,0 +1,46 @@
using System;
namespace Bit.App.Pages
{
public partial class ExtensionPage : BaseContentPage
{
private readonly ExtensionPageViewModel _vm;
public ExtensionPage()
{
InitializeComponent();
_vm = BindingContext as ExtensionPageViewModel;
_vm.Page = this;
}
protected async override void OnAppearing()
{
base.OnAppearing();
await _vm.InitAsync();
}
private void SeeApps_Clicked(object sender, EventArgs e)
{
if(DoOnce())
{
_vm.SeeApps();
}
}
private void Show_Clicked(object sender, EventArgs e)
{
if(DoOnce())
{
_vm.ShowExtension();
}
}
private void Close_Clicked(object sender, EventArgs e)
{
if(DoOnce())
{
Navigation.PopModalAsync();
}
}
}
}

View File

@ -0,0 +1,80 @@
using Bit.App.Resources;
using Bit.Core.Abstractions;
using Bit.Core.Utilities;
using System.Threading.Tasks;
namespace Bit.App.Pages
{
public class ExtensionPageViewModel : BaseViewModel
{
private const string StartedKey = "appExtensionStarted";
private const string ActivatedKey = "appExtensionActivated";
private readonly IMessagingService _messagingService;
private readonly IStorageService _storageService;
private readonly IPlatformUtilsService _platformUtilsService;
private bool _started;
private bool _activated;
public ExtensionPageViewModel()
{
_messagingService = ServiceContainer.Resolve<IMessagingService>("messagingService");
_storageService = ServiceContainer.Resolve<IStorageService>("storageService");
_platformUtilsService = ServiceContainer.Resolve<IPlatformUtilsService>("platformUtilsService");
PageTitle = AppResources.AppExtension;
}
public bool Started
{
get => _started;
set => SetProperty(ref _started, value, additionalPropertyNames: new string[]
{
nameof(NotStarted),
nameof(StartedAndNotActivated),
nameof(StartedAndActivated)
});
}
public bool Activated
{
get => _activated;
set => SetProperty(ref _activated, value, additionalPropertyNames: new string[]
{
nameof(StartedAndNotActivated),
nameof(StartedAndActivated)
});
}
public bool NotStarted => !Started;
public bool StartedAndNotActivated => Started && !Activated;
public bool StartedAndActivated => Started && Activated;
public async Task InitAsync()
{
var started = await _storageService.GetAsync<bool?>(StartedKey);
var activated = await _storageService.GetAsync<bool?>(ActivatedKey);
Started = started.GetValueOrDefault();
Activated = activated.GetValueOrDefault();
}
public void SeeApps()
{
_platformUtilsService.LaunchUri("https://bitwarden.com/ios/");
}
public void ShowExtension()
{
_messagingService.Send("showAppExtension", this);
}
public void EnabledExtension(bool enabled)
{
Started = true;
if(!Activated && enabled)
{
Activated = enabled;
}
}
}
}

View File

@ -67,11 +67,11 @@ namespace Bit.App.Pages
}
else if(item.Name == AppResources.PasswordAutofill)
{
// await Navigation.PushModalAsync(new NavigationPage(new OptionsPage()));
await Navigation.PushModalAsync(new NavigationPage(new AutofillPage()));
}
else if(item.Name == AppResources.AppExtension)
{
// await Navigation.PushModalAsync(new NavigationPage(new OptionsPage()));
await Navigation.PushModalAsync(new NavigationPage(new ExtensionPage()));
}
else if(item.Name == AppResources.Options)
{

View File

@ -18,6 +18,7 @@ namespace Bit.iOS.Extension
public override void ViewDidLoad()
{
base.ViewDidLoad();
var descriptor = UIFontDescriptor.PreferredBody;
DescriptionLabel.Text = $@"{AppResources.ExtensionSetup}
@ -31,7 +32,6 @@ namespace Bit.iOS.Extension
BackButton.TintColor = ThemeHelpers.NavBarTextColor;
BackButton.Title = AppResources.Back;
base.ViewDidLoad();
}
partial void BackButton_Activated(UIBarButtonItem sender)

View File

@ -3,6 +3,7 @@ using System.Collections.Generic;
using System.Threading.Tasks;
using AuthenticationServices;
using Bit.App.Abstractions;
using Bit.App.Pages;
using Bit.App.Resources;
using Bit.App.Services;
using Bit.App.Utilities;
@ -79,7 +80,7 @@ namespace Bit.iOS
}
else if(message.Command == "showAppExtension")
{
Device.BeginInvokeOnMainThread(() => ShowAppExtension((ExtensionPageViewModel)message.Data));
}
else if(message.Command == "showStatusBar")
{
@ -389,18 +390,20 @@ namespace Bit.iOS
});
}
private void ShowAppExtension()
private void ShowAppExtension(ExtensionPageViewModel extensionPageViewModel)
{
var itemProvider = new NSItemProvider(new NSDictionary(), Core.Constants.UTTypeAppExtensionSetup);
var extensionItem = new NSExtensionItem
{
Attachments = new NSItemProvider[] { itemProvider }
};
var activityViewController = new UIActivityViewController(new NSExtensionItem[] { extensionItem }, null);
activityViewController.CompletionHandler = (activityType, completed) =>
var activityViewController = new UIActivityViewController(new NSExtensionItem[] { extensionItem }, null)
{
// TODO
//page.EnabledExtension(completed && activityType == "com.8bit.bitwarden.find-login-action-extension");
CompletionHandler = (activityType, completed) =>
{
extensionPageViewModel.EnabledExtension(
completed && activityType == "com.8bit.bitwarden.find-login-action-extension");
}
};
var modal = UIApplication.SharedApplication.KeyWindow.RootViewController.ModalViewController;
if(activityViewController.PopoverPresentationController != null)