2016-05-03 00:50:16 +03:00
using System ;
using Bit.App.Abstractions ;
2016-05-07 20:42:09 +03:00
using Bit.App.Resources ;
2016-05-03 00:50:16 +03:00
using Xamarin.Forms ;
using XLabs.Ioc ;
2016-05-13 04:30:02 +03:00
using Bit.App.Controls ;
2016-05-18 06:09:20 +03:00
using Acr.UserDialogs ;
2016-05-03 00:50:16 +03:00
namespace Bit.App.Pages
{
public class SettingsPage : ContentPage
{
2016-05-08 07:28:14 +03:00
private readonly IAuthService _authService ;
2016-05-18 06:09:20 +03:00
private readonly IUserDialogs _userDialogs ;
2016-05-03 00:50:16 +03:00
public SettingsPage ( )
{
2016-05-08 07:28:14 +03:00
_authService = Resolver . Resolve < IAuthService > ( ) ;
2016-05-18 06:09:20 +03:00
_userDialogs = Resolver . Resolve < IUserDialogs > ( ) ;
2016-05-08 07:28:14 +03:00
Init ( ) ;
}
private void Init ( )
{
2016-05-19 06:55:30 +03:00
var touchIdCell = new ExtendedSwitchCell
2016-05-18 06:09:20 +03:00
{
Text = "Use Touch ID"
} ;
2016-05-19 06:55:30 +03:00
touchIdCell . OnChanged + = TouchIdCell_Changed ;
2016-05-18 06:09:20 +03:00
2016-05-19 06:55:30 +03:00
var lockOnExitCell = new ExtendedSwitchCell
2016-05-18 06:09:20 +03:00
{
Text = "Lock Immediately On Exit"
} ;
2016-05-19 06:55:30 +03:00
lockOnExitCell . OnChanged + = LockOnExitCell_Changed ;
2016-05-18 06:09:20 +03:00
var changeMasterPasswordCell = new ExtendedTextCell
{
2016-05-19 06:55:30 +03:00
Text = "Change Master Password" ,
TextColor = Color . FromHex ( "333333" )
2016-05-18 06:09:20 +03:00
} ;
changeMasterPasswordCell . Tapped + = ChangeMasterPasswordCell_Tapped ;
var foldersCell = new ExtendedTextCell
{
Text = "Folders" ,
2016-05-19 06:55:30 +03:00
ShowDisclousure = true ,
TextColor = Color . FromHex ( "333333" )
2016-05-18 06:09:20 +03:00
} ;
2016-05-08 07:28:14 +03:00
foldersCell . Tapped + = FoldersCell_Tapped ;
2016-05-18 06:09:20 +03:00
var lockCell = new ExtendedTextCell
{
2016-05-19 06:55:30 +03:00
Text = "Lock" ,
TextColor = Color . FromHex ( "333333" )
2016-05-18 06:09:20 +03:00
} ;
lockCell . Tapped + = LockCell_Tapped ;
var logOutCell = new ExtendedTextCell
{
2016-05-19 06:55:30 +03:00
Text = "Log Out" ,
TextColor = Color . FromHex ( "333333" )
2016-05-18 06:09:20 +03:00
} ;
logOutCell . Tapped + = LogOutCell_Tapped ;
2016-05-13 04:30:02 +03:00
var table = new ExtendedTableView
2016-05-08 07:28:14 +03:00
{
2016-05-18 06:09:20 +03:00
EnableScrolling = true ,
2016-05-12 00:30:09 +03:00
Intent = TableIntent . Menu ,
2016-05-08 07:28:14 +03:00
Root = new TableRoot
{
2016-05-18 06:09:20 +03:00
new TableSection ( "Security" )
{
touchIdCell ,
lockOnExitCell ,
changeMasterPasswordCell
} ,
2016-05-08 07:28:14 +03:00
new TableSection ( "Manage Folders" )
{
foldersCell
2016-05-18 06:09:20 +03:00
} ,
new TableSection ( "Current Session" )
{
lockCell ,
logOutCell
2016-05-08 07:28:14 +03:00
}
}
} ;
2016-05-03 00:50:16 +03:00
2016-05-18 06:09:20 +03:00
var scrollView = new ScrollView
2016-05-03 00:50:16 +03:00
{
2016-05-18 06:09:20 +03:00
Content = table
2016-05-03 00:50:16 +03:00
} ;
2016-05-07 20:42:09 +03:00
Title = AppResources . Settings ;
2016-05-18 06:09:20 +03:00
Content = table ;
2016-05-03 00:50:16 +03:00
}
2016-05-08 07:28:14 +03:00
2016-05-18 06:09:20 +03:00
private void LockCell_Tapped ( object sender , EventArgs e )
2016-05-08 07:28:14 +03:00
{
}
2016-05-18 06:09:20 +03:00
private async void LogOutCell_Tapped ( object sender , EventArgs e )
{
if ( ! await _userDialogs . ConfirmAsync ( "Are you sure you want to log out?" , null , AppResources . Yes , AppResources . Cancel ) )
{
return ;
}
_authService . LogOut ( ) ;
Application . Current . MainPage = new LoginNavigationPage ( ) ;
}
2016-05-19 06:55:30 +03:00
private void LockOnExitCell_Changed ( object sender , EventArgs e )
2016-05-18 06:09:20 +03:00
{
}
private async void ChangeMasterPasswordCell_Tapped ( object sender , EventArgs e )
{
if ( ! await _userDialogs . ConfirmAsync ( "You can change your master password on the bitwarden.com web vault. Do you want to visit the website now?" , null , AppResources . Yes , AppResources . Cancel ) )
{
return ;
}
Device . OpenUri ( new Uri ( "https://vault.bitwarden.com" ) ) ;
}
2016-05-19 06:55:30 +03:00
private void TouchIdCell_Changed ( object sender , EventArgs e )
2016-05-18 06:09:20 +03:00
{
2016-05-19 05:53:34 +03:00
2016-05-18 06:09:20 +03:00
}
private void FoldersCell_Tapped ( object sender , EventArgs e )
{
Navigation . PushAsync ( new SettingsListFoldersPage ( ) ) ;
}
2016-05-03 00:50:16 +03:00
}
}