2016-07-01 05:04:45 +03:00
using System ;
using System.Threading.Tasks ;
using Acr.UserDialogs ;
using Bit.App.Abstractions ;
using Bit.App.Controls ;
using Bit.App.Resources ;
using Xamarin.Forms ;
using XLabs.Ioc ;
namespace Bit.App.Pages
{
public class ToolsPage : ExtendedContentPage
{
private readonly IUserDialogs _userDialogs ;
2016-08-05 07:20:45 +03:00
private readonly IGoogleAnalyticsService _googleAnalyticsService ;
2016-07-01 05:04:45 +03:00
public ToolsPage ( )
{
_userDialogs = Resolver . Resolve < IUserDialogs > ( ) ;
2016-08-05 07:20:45 +03:00
_googleAnalyticsService = Resolver . Resolve < IGoogleAnalyticsService > ( ) ;
2016-07-01 05:04:45 +03:00
Init ( ) ;
}
public void Init ( )
{
2016-07-01 07:03:54 +03:00
var generatorCell = new ToolsViewCell ( "Password Generator" , "Automatically generate strong, unique passwords for your logins." , "refresh" ) ;
2016-07-02 09:01:47 +03:00
generatorCell . Tapped + = GeneratorCell_Tapped ;
2016-07-01 07:03:54 +03:00
var extensionCell = new ToolsViewCell ( "bitwarden App Extension" , "Use bitwarden in Safari and other apps to auto-fill your logins." , "upload" ) ;
2016-07-02 22:20:06 +03:00
extensionCell . Tapped + = ExtensionCell_Tapped ;
2016-07-01 07:03:54 +03:00
var webCell = new ToolsViewCell ( "bitwarden Web Vault" , "Manage your logins from any web browser with the bitwarden web vault." , "globe" ) ;
webCell . Tapped + = WebCell_Tapped ;
var importCell = new ToolsViewCell ( "Import Logins" , "Quickly bulk import your logins from other password management apps." , "cloudup" ) ;
importCell . Tapped + = ImportCell_Tapped ;
var table = new ExtendedTableView
{
EnableScrolling = true ,
2016-07-06 02:07:56 +03:00
Intent = TableIntent . Settings ,
2016-07-01 07:03:54 +03:00
HasUnevenRows = true ,
Root = new TableRoot
{
2016-07-06 02:07:56 +03:00
new TableSection
2016-07-01 07:03:54 +03:00
{
generatorCell ,
extensionCell ,
webCell ,
importCell
}
}
} ;
if ( Device . OS = = TargetPlatform . iOS )
{
table . RowHeight = - 1 ;
table . EstimatedRowHeight = 100 ;
}
2016-07-01 05:04:45 +03:00
Title = AppResources . Tools ;
2016-07-01 07:03:54 +03:00
Content = table ;
}
2016-07-02 22:20:06 +03:00
private void ExtensionCell_Tapped ( object sender , EventArgs e )
{
Navigation . PushModalAsync ( new ExtendedNavigationPage ( new ToolsExtensionPage ( ) ) ) ;
}
2016-07-02 09:01:47 +03:00
private void GeneratorCell_Tapped ( object sender , EventArgs e )
{
Navigation . PushModalAsync ( new ExtendedNavigationPage ( new ToolsPasswordGeneratorPage ( ) ) ) ;
}
2016-07-01 07:03:54 +03:00
private void WebCell_Tapped ( object sender , EventArgs e )
{
2016-08-05 07:20:45 +03:00
_googleAnalyticsService . TrackAppEvent ( "OpenedTool" , "Web" ) ;
2016-07-01 07:03:54 +03:00
Device . OpenUri ( new Uri ( "https://vault.bitwarden.com" ) ) ;
}
private async void ImportCell_Tapped ( object sender , EventArgs e )
{
if ( ! await _userDialogs . ConfirmAsync ( "You can bulk import logins from the bitwarden.com web vault. Do you want to visit the website now?" , null , AppResources . Yes , AppResources . Cancel ) )
{
return ;
}
2016-08-05 07:20:45 +03:00
_googleAnalyticsService . TrackAppEvent ( "OpenedTool" , "Import" ) ;
2016-07-01 07:03:54 +03:00
Device . OpenUri ( new Uri ( "https://vault.bitwarden.com" ) ) ;
}
public class ToolsViewCell : ExtendedViewCell
{
public ToolsViewCell ( string labelText , string detailText , string imageSource )
{
var label = new Label
{
VerticalOptions = LayoutOptions . CenterAndExpand ,
LineBreakMode = LineBreakMode . TailTruncation ,
Text = labelText
} ;
var detail = new Label
{
FontSize = Device . GetNamedSize ( NamedSize . Small , typeof ( Label ) ) ,
LineBreakMode = LineBreakMode . WordWrap ,
VerticalOptions = LayoutOptions . End ,
Style = ( Style ) Application . Current . Resources [ "text-muted" ] ,
Text = detailText
} ;
var labelDetailStackLayout = new StackLayout
{
HorizontalOptions = LayoutOptions . StartAndExpand ,
VerticalOptions = LayoutOptions . FillAndExpand ,
Children = { label , detail } ,
Spacing = 0
} ;
var image = new Image
{
HorizontalOptions = LayoutOptions . Start ,
VerticalOptions = LayoutOptions . FillAndExpand ,
Source = imageSource ,
Margin = new Thickness ( 0 , 0 , 10 , 0 )
} ;
var containerStackLayout = new StackLayout
{
Orientation = StackOrientation . Horizontal ,
Children = { image , labelDetailStackLayout } ,
Padding = new Thickness ( 15 , 25 )
} ;
ShowDisclousure = true ;
View = containerStackLayout ;
}
2016-07-01 05:04:45 +03:00
}
}
}