2016-07-02 22:20:06 +03:00
|
|
|
|
using System;
|
|
|
|
|
using System.Threading.Tasks;
|
|
|
|
|
using Acr.UserDialogs;
|
|
|
|
|
using Bit.App.Controls;
|
|
|
|
|
using Bit.App.Models.Page;
|
|
|
|
|
using Plugin.Settings.Abstractions;
|
|
|
|
|
using Xamarin.Forms;
|
|
|
|
|
using XLabs.Ioc;
|
2016-08-05 02:35:56 +03:00
|
|
|
|
using Bit.App.Abstractions;
|
2016-11-26 00:32:13 +03:00
|
|
|
|
using Bit.App.Resources;
|
2017-02-16 05:56:02 +03:00
|
|
|
|
using FFImageLoading.Forms;
|
2016-07-02 22:20:06 +03:00
|
|
|
|
|
|
|
|
|
namespace Bit.App.Pages
|
|
|
|
|
{
|
|
|
|
|
public class ToolsExtensionPage : ExtendedContentPage
|
|
|
|
|
{
|
|
|
|
|
private readonly IUserDialogs _userDialogs;
|
|
|
|
|
private readonly ISettings _settings;
|
2016-08-05 02:35:56 +03:00
|
|
|
|
private readonly IGoogleAnalyticsService _googleAnalyticsService;
|
2016-07-02 22:20:06 +03:00
|
|
|
|
|
|
|
|
|
public ToolsExtensionPage()
|
|
|
|
|
{
|
|
|
|
|
_userDialogs = Resolver.Resolve<IUserDialogs>();
|
|
|
|
|
_settings = Resolver.Resolve<ISettings>();
|
2016-08-05 02:35:56 +03:00
|
|
|
|
_googleAnalyticsService = Resolver.Resolve<IGoogleAnalyticsService>();
|
2016-07-02 22:20:06 +03:00
|
|
|
|
Model = new AppExtensionPageModel(_settings);
|
|
|
|
|
|
|
|
|
|
Init();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public AppExtensionPageModel Model { get; private set; }
|
|
|
|
|
|
|
|
|
|
public void Init()
|
|
|
|
|
{
|
|
|
|
|
// Not Started
|
|
|
|
|
|
|
|
|
|
var notStartedLabel = new Label
|
|
|
|
|
{
|
2016-11-26 00:32:13 +03:00
|
|
|
|
Text = AppResources.ExtensionInstantAccess,
|
2016-07-02 22:20:06 +03:00
|
|
|
|
VerticalOptions = LayoutOptions.Start,
|
|
|
|
|
HorizontalOptions = LayoutOptions.Center,
|
|
|
|
|
HorizontalTextAlignment = TextAlignment.Center,
|
|
|
|
|
LineBreakMode = LineBreakMode.WordWrap,
|
|
|
|
|
FontSize = Device.GetNamedSize(NamedSize.Large, typeof(Label))
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
var notStartedSublabel = new Label
|
|
|
|
|
{
|
2016-11-26 00:32:13 +03:00
|
|
|
|
Text = AppResources.ExtensionTurnOn,
|
2016-07-02 22:20:06 +03:00
|
|
|
|
VerticalOptions = LayoutOptions.Start,
|
|
|
|
|
HorizontalOptions = LayoutOptions.Center,
|
|
|
|
|
HorizontalTextAlignment = TextAlignment.Center,
|
|
|
|
|
LineBreakMode = LineBreakMode.WordWrap
|
|
|
|
|
};
|
|
|
|
|
|
2017-02-16 05:56:02 +03:00
|
|
|
|
var notStartedImage = new CachedImage
|
2016-07-02 22:20:06 +03:00
|
|
|
|
{
|
2016-07-28 07:24:51 +03:00
|
|
|
|
Source = "ext-more",
|
2016-07-02 22:20:06 +03:00
|
|
|
|
VerticalOptions = LayoutOptions.CenterAndExpand,
|
2016-07-28 07:24:51 +03:00
|
|
|
|
HorizontalOptions = LayoutOptions.Center,
|
2017-02-16 05:56:02 +03:00
|
|
|
|
Margin = new Thickness(0, -10, 0, 0),
|
|
|
|
|
WidthRequest = 290,
|
|
|
|
|
HeightRequest = 252
|
2016-07-02 22:20:06 +03:00
|
|
|
|
};
|
|
|
|
|
|
2016-08-24 07:07:46 +03:00
|
|
|
|
var notStartedButton = new ExtendedButton
|
2016-07-02 22:20:06 +03:00
|
|
|
|
{
|
2016-11-26 00:32:13 +03:00
|
|
|
|
Text = AppResources.ExtensionEnable,
|
2016-08-05 02:35:56 +03:00
|
|
|
|
Command = new Command(() => ShowExtension("NotStartedEnable")),
|
2016-07-28 07:24:51 +03:00
|
|
|
|
VerticalOptions = LayoutOptions.End,
|
2016-07-02 22:20:06 +03:00
|
|
|
|
HorizontalOptions = LayoutOptions.Fill,
|
|
|
|
|
Style = (Style)Application.Current.Resources["btn-primary"]
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
var notStartedStackLayout = new StackLayout
|
|
|
|
|
{
|
|
|
|
|
Orientation = StackOrientation.Vertical,
|
|
|
|
|
Spacing = 20,
|
2016-07-28 07:24:51 +03:00
|
|
|
|
Padding = new Thickness(20, 20, 20, 30),
|
|
|
|
|
Children = { notStartedLabel, notStartedSublabel, notStartedImage, notStartedButton },
|
|
|
|
|
VerticalOptions = LayoutOptions.FillAndExpand
|
2016-07-02 22:20:06 +03:00
|
|
|
|
};
|
|
|
|
|
|
2017-05-30 21:13:53 +03:00
|
|
|
|
notStartedStackLayout.SetBinding(IsVisibleProperty, nameof(AppExtensionPageModel.NotStarted));
|
2016-07-02 22:20:06 +03:00
|
|
|
|
|
|
|
|
|
// Not Activated
|
|
|
|
|
|
|
|
|
|
var notActivatedLabel = new Label
|
|
|
|
|
{
|
2016-11-26 00:32:13 +03:00
|
|
|
|
Text = AppResources.ExtensionAlmostDone,
|
2016-07-02 22:20:06 +03:00
|
|
|
|
VerticalOptions = LayoutOptions.Start,
|
|
|
|
|
HorizontalOptions = LayoutOptions.Center,
|
|
|
|
|
HorizontalTextAlignment = TextAlignment.Center,
|
|
|
|
|
LineBreakMode = LineBreakMode.WordWrap,
|
|
|
|
|
FontSize = Device.GetNamedSize(NamedSize.Large, typeof(Label))
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
var notActivatedSublabel = new Label
|
|
|
|
|
{
|
2016-11-26 00:32:13 +03:00
|
|
|
|
Text = AppResources.ExtensionTapIcon,
|
2016-07-02 22:20:06 +03:00
|
|
|
|
VerticalOptions = LayoutOptions.Start,
|
|
|
|
|
HorizontalOptions = LayoutOptions.Center,
|
|
|
|
|
HorizontalTextAlignment = TextAlignment.Center,
|
|
|
|
|
LineBreakMode = LineBreakMode.WordWrap
|
|
|
|
|
};
|
|
|
|
|
|
2017-02-16 05:56:02 +03:00
|
|
|
|
var notActivatedImage = new CachedImage
|
2016-07-02 22:20:06 +03:00
|
|
|
|
{
|
2016-07-28 07:24:51 +03:00
|
|
|
|
Source = "ext-act",
|
2016-07-02 22:20:06 +03:00
|
|
|
|
VerticalOptions = LayoutOptions.CenterAndExpand,
|
2016-07-28 07:24:51 +03:00
|
|
|
|
HorizontalOptions = LayoutOptions.Center,
|
2017-02-16 05:56:02 +03:00
|
|
|
|
Margin = new Thickness(0, -10, 0, 0),
|
|
|
|
|
WidthRequest = 290,
|
|
|
|
|
HeightRequest = 252
|
2016-07-02 22:20:06 +03:00
|
|
|
|
};
|
|
|
|
|
|
2016-08-24 07:07:46 +03:00
|
|
|
|
var notActivatedButton = new ExtendedButton
|
2016-07-02 22:20:06 +03:00
|
|
|
|
{
|
2016-11-26 00:32:13 +03:00
|
|
|
|
Text = AppResources.ExtensionEnable,
|
2016-08-05 02:35:56 +03:00
|
|
|
|
Command = new Command(() => ShowExtension("NotActivatedEnable")),
|
2016-07-28 07:24:51 +03:00
|
|
|
|
VerticalOptions = LayoutOptions.End,
|
2016-07-02 22:20:06 +03:00
|
|
|
|
HorizontalOptions = LayoutOptions.Fill,
|
|
|
|
|
Style = (Style)Application.Current.Resources["btn-primary"]
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
var notActivatedStackLayout = new StackLayout
|
|
|
|
|
{
|
|
|
|
|
Orientation = StackOrientation.Vertical,
|
|
|
|
|
Spacing = 20,
|
2016-07-28 07:24:51 +03:00
|
|
|
|
Padding = new Thickness(20, 20, 20, 30),
|
|
|
|
|
Children = { notActivatedLabel, notActivatedSublabel, notActivatedImage, notActivatedButton },
|
|
|
|
|
VerticalOptions = LayoutOptions.FillAndExpand
|
2016-07-02 22:20:06 +03:00
|
|
|
|
};
|
|
|
|
|
|
2017-05-30 21:13:53 +03:00
|
|
|
|
notActivatedStackLayout.SetBinding(IsVisibleProperty, nameof(AppExtensionPageModel.StartedAndNotActivated));
|
2016-07-02 22:20:06 +03:00
|
|
|
|
|
|
|
|
|
// Activated
|
|
|
|
|
|
|
|
|
|
var activatedLabel = new Label
|
|
|
|
|
{
|
2016-11-26 00:32:13 +03:00
|
|
|
|
Text = AppResources.ExtensionReady,
|
2016-07-02 22:20:06 +03:00
|
|
|
|
VerticalOptions = LayoutOptions.Start,
|
|
|
|
|
HorizontalOptions = LayoutOptions.Center,
|
|
|
|
|
HorizontalTextAlignment = TextAlignment.Center,
|
|
|
|
|
LineBreakMode = LineBreakMode.WordWrap,
|
|
|
|
|
FontSize = Device.GetNamedSize(NamedSize.Large, typeof(Label))
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
var activatedSublabel = new Label
|
|
|
|
|
{
|
2016-11-26 00:32:13 +03:00
|
|
|
|
Text = AppResources.ExtensionInSafari,
|
2016-07-02 22:20:06 +03:00
|
|
|
|
VerticalOptions = LayoutOptions.Start,
|
|
|
|
|
HorizontalOptions = LayoutOptions.Center,
|
|
|
|
|
HorizontalTextAlignment = TextAlignment.Center,
|
2016-07-05 06:11:44 +03:00
|
|
|
|
LineBreakMode = LineBreakMode.WordWrap,
|
|
|
|
|
Margin = new Thickness(0, 10, 0, 0)
|
2016-07-02 22:20:06 +03:00
|
|
|
|
};
|
|
|
|
|
|
2017-02-16 05:56:02 +03:00
|
|
|
|
var activatedImage = new CachedImage
|
2016-07-02 22:20:06 +03:00
|
|
|
|
{
|
2016-07-28 07:24:51 +03:00
|
|
|
|
Source = "ext-use",
|
2016-07-02 22:20:06 +03:00
|
|
|
|
VerticalOptions = LayoutOptions.CenterAndExpand,
|
2016-07-28 07:24:51 +03:00
|
|
|
|
HorizontalOptions = LayoutOptions.Center,
|
2017-02-16 05:56:02 +03:00
|
|
|
|
Margin = new Thickness(0, -10, 0, 0),
|
|
|
|
|
WidthRequest = 290,
|
|
|
|
|
HeightRequest = 252
|
2016-07-02 22:20:06 +03:00
|
|
|
|
};
|
|
|
|
|
|
2016-08-24 07:07:46 +03:00
|
|
|
|
var activatedButton = new ExtendedButton
|
2016-07-02 22:20:06 +03:00
|
|
|
|
{
|
2016-11-26 00:32:13 +03:00
|
|
|
|
Text = AppResources.ExtensionSeeApps,
|
2016-08-06 04:59:25 +03:00
|
|
|
|
Command = new Command(() =>
|
|
|
|
|
{
|
|
|
|
|
_googleAnalyticsService.TrackAppEvent("SeeSupportedApps");
|
2016-10-02 07:20:45 +03:00
|
|
|
|
Device.OpenUri(new Uri("https://bitwarden.com/ios/"));
|
2016-08-06 04:59:25 +03:00
|
|
|
|
}),
|
2016-07-28 07:24:51 +03:00
|
|
|
|
VerticalOptions = LayoutOptions.End,
|
2016-07-02 22:20:06 +03:00
|
|
|
|
HorizontalOptions = LayoutOptions.Fill,
|
|
|
|
|
Style = (Style)Application.Current.Resources["btn-primary"]
|
|
|
|
|
};
|
|
|
|
|
|
2016-08-24 07:07:46 +03:00
|
|
|
|
var activatedButtonReenable = new ExtendedButton
|
2016-07-05 06:11:44 +03:00
|
|
|
|
{
|
2016-11-26 00:32:13 +03:00
|
|
|
|
Text = AppResources.ExntesionReenable,
|
2016-08-05 02:35:56 +03:00
|
|
|
|
Command = new Command(() => ShowExtension("Re-enable")),
|
2016-07-05 06:11:44 +03:00
|
|
|
|
VerticalOptions = LayoutOptions.End,
|
|
|
|
|
HorizontalOptions = LayoutOptions.Fill,
|
|
|
|
|
Style = (Style)Application.Current.Resources["btn-primaryAccent"]
|
|
|
|
|
};
|
|
|
|
|
|
2016-07-02 22:20:06 +03:00
|
|
|
|
var activatedStackLayout = new StackLayout
|
|
|
|
|
{
|
|
|
|
|
Orientation = StackOrientation.Vertical,
|
2016-07-05 06:11:44 +03:00
|
|
|
|
Spacing = 10,
|
2016-07-28 07:24:51 +03:00
|
|
|
|
Padding = new Thickness(20, 20, 20, 30),
|
|
|
|
|
VerticalOptions = LayoutOptions.FillAndExpand,
|
2016-07-05 06:11:44 +03:00
|
|
|
|
Children = { activatedLabel, activatedSublabel, activatedImage, activatedButton, activatedButtonReenable }
|
2016-07-02 22:20:06 +03:00
|
|
|
|
};
|
|
|
|
|
|
2017-05-30 21:13:53 +03:00
|
|
|
|
activatedStackLayout.SetBinding(IsVisibleProperty, nameof(AppExtensionPageModel.StartedAndActivated));
|
2016-07-02 22:20:06 +03:00
|
|
|
|
|
|
|
|
|
var stackLayout = new StackLayout
|
|
|
|
|
{
|
2016-07-28 07:24:51 +03:00
|
|
|
|
Children = { notStartedStackLayout, notActivatedStackLayout, activatedStackLayout },
|
|
|
|
|
VerticalOptions = LayoutOptions.FillAndExpand
|
2016-07-02 22:20:06 +03:00
|
|
|
|
};
|
|
|
|
|
|
2017-05-30 21:13:53 +03:00
|
|
|
|
if(Device.RuntimePlatform == Device.iOS)
|
2016-07-02 22:20:06 +03:00
|
|
|
|
{
|
2016-11-26 00:32:13 +03:00
|
|
|
|
ToolbarItems.Add(new DismissModalToolBarItem(this, AppResources.Close));
|
2016-07-02 22:20:06 +03:00
|
|
|
|
}
|
|
|
|
|
|
2016-11-26 00:32:13 +03:00
|
|
|
|
Title = AppResources.AppExtension;
|
2016-07-28 07:24:51 +03:00
|
|
|
|
Content = new ScrollView { Content = stackLayout };
|
2016-07-02 22:20:06 +03:00
|
|
|
|
BindingContext = Model;
|
2016-07-05 06:11:44 +03:00
|
|
|
|
}
|
2016-07-02 22:20:06 +03:00
|
|
|
|
|
2016-08-05 02:35:56 +03:00
|
|
|
|
private void ShowExtension(string type)
|
2016-07-05 06:11:44 +03:00
|
|
|
|
{
|
2016-08-05 02:35:56 +03:00
|
|
|
|
_googleAnalyticsService.TrackAppEvent("ShowExtension", type);
|
2016-07-05 06:11:44 +03:00
|
|
|
|
MessagingCenter.Send(Application.Current, "ShowAppExtension", this);
|
2016-07-02 22:20:06 +03:00
|
|
|
|
}
|
|
|
|
|
|
2016-07-05 06:11:44 +03:00
|
|
|
|
public void EnabledExtension(bool enabled)
|
2016-07-02 22:20:06 +03:00
|
|
|
|
{
|
2016-08-05 02:35:56 +03:00
|
|
|
|
_googleAnalyticsService.TrackAppEvent("EnabledExtension", enabled.ToString());
|
2016-07-05 06:11:44 +03:00
|
|
|
|
Model.Started = true;
|
|
|
|
|
if(!Model.Activated && enabled)
|
|
|
|
|
{
|
|
|
|
|
Model.Activated = enabled;
|
|
|
|
|
}
|
2016-07-02 22:20:06 +03:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|