2016-06-22 06:54:51 +03:00
|
|
|
|
using System;
|
|
|
|
|
using System.Threading.Tasks;
|
|
|
|
|
using Acr.UserDialogs;
|
|
|
|
|
using Bit.App.Abstractions;
|
|
|
|
|
using Bit.App.Resources;
|
|
|
|
|
using Xamarin.Forms;
|
|
|
|
|
using XLabs.Ioc;
|
|
|
|
|
using Plugin.Settings.Abstractions;
|
2016-06-24 06:03:00 +03:00
|
|
|
|
using Bit.App.Controls;
|
2017-02-16 05:56:02 +03:00
|
|
|
|
using FFImageLoading.Forms;
|
2016-06-22 06:54:51 +03:00
|
|
|
|
|
|
|
|
|
namespace Bit.App.Pages
|
|
|
|
|
{
|
2016-06-28 02:53:31 +03:00
|
|
|
|
public class HomePage : ExtendedContentPage
|
2016-06-22 06:54:51 +03:00
|
|
|
|
{
|
|
|
|
|
private readonly IAuthService _authService;
|
|
|
|
|
private readonly IUserDialogs _userDialogs;
|
|
|
|
|
private readonly ISettings _settings;
|
2017-05-20 19:36:09 +03:00
|
|
|
|
private DateTime? _lastAction;
|
2016-06-22 06:54:51 +03:00
|
|
|
|
|
|
|
|
|
public HomePage()
|
2016-08-09 02:00:36 +03:00
|
|
|
|
: base(updateActivity: false)
|
2016-06-22 06:54:51 +03:00
|
|
|
|
{
|
|
|
|
|
_authService = Resolver.Resolve<IAuthService>();
|
|
|
|
|
_userDialogs = Resolver.Resolve<IUserDialogs>();
|
|
|
|
|
_settings = Resolver.Resolve<ISettings>();
|
|
|
|
|
|
|
|
|
|
Init();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void Init()
|
|
|
|
|
{
|
2016-07-23 22:32:11 +03:00
|
|
|
|
MessagingCenter.Send(Application.Current, "ShowStatusBar", false);
|
|
|
|
|
|
2017-08-23 18:40:40 +03:00
|
|
|
|
var settingsButton = new Button
|
|
|
|
|
{
|
|
|
|
|
Image = "cog",
|
|
|
|
|
VerticalOptions = LayoutOptions.Start,
|
|
|
|
|
HorizontalOptions = LayoutOptions.Start,
|
|
|
|
|
WidthRequest = 25,
|
|
|
|
|
HeightRequest = 25,
|
|
|
|
|
BackgroundColor = Color.Transparent,
|
|
|
|
|
Margin = new Thickness(-20, -30, 0, 0),
|
|
|
|
|
Command = new Command(async () => await SettingsAsync())
|
|
|
|
|
};
|
|
|
|
|
|
2017-02-16 05:56:02 +03:00
|
|
|
|
var logo = new CachedImage
|
2016-06-22 06:54:51 +03:00
|
|
|
|
{
|
|
|
|
|
Source = "logo",
|
|
|
|
|
VerticalOptions = LayoutOptions.CenterAndExpand,
|
2017-02-16 05:56:02 +03:00
|
|
|
|
HorizontalOptions = LayoutOptions.Center,
|
|
|
|
|
WidthRequest = 282,
|
2017-08-23 18:40:40 +03:00
|
|
|
|
Margin = new Thickness(0, 30, 0, 0),
|
2017-02-16 05:56:02 +03:00
|
|
|
|
HeightRequest = 44
|
2016-06-22 06:54:51 +03:00
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
var message = new Label
|
|
|
|
|
{
|
2016-11-26 00:54:33 +03:00
|
|
|
|
Text = AppResources.LoginOrCreateNewAccount,
|
2016-06-23 06:50:38 +03:00
|
|
|
|
VerticalOptions = LayoutOptions.StartAndExpand,
|
2016-06-24 06:03:00 +03:00
|
|
|
|
HorizontalOptions = LayoutOptions.Center,
|
|
|
|
|
HorizontalTextAlignment = TextAlignment.Center,
|
|
|
|
|
LineBreakMode = LineBreakMode.WordWrap,
|
2016-06-28 03:56:59 +03:00
|
|
|
|
FontSize = Device.GetNamedSize(NamedSize.Large, typeof(Label)),
|
2016-06-28 05:18:48 +03:00
|
|
|
|
TextColor = Color.FromHex("333333")
|
2016-06-22 06:54:51 +03:00
|
|
|
|
};
|
|
|
|
|
|
2016-08-24 07:07:46 +03:00
|
|
|
|
var createAccountButton = new ExtendedButton
|
2016-06-22 06:54:51 +03:00
|
|
|
|
{
|
2016-11-26 00:54:33 +03:00
|
|
|
|
Text = AppResources.CreateAccount,
|
2016-06-26 03:54:17 +03:00
|
|
|
|
Command = new Command(async () => await RegisterAsync()),
|
2016-06-22 06:54:51 +03:00
|
|
|
|
VerticalOptions = LayoutOptions.End,
|
2016-06-23 06:50:38 +03:00
|
|
|
|
HorizontalOptions = LayoutOptions.Fill,
|
2016-08-19 07:27:37 +03:00
|
|
|
|
Style = (Style)Application.Current.Resources["btn-primary"],
|
2016-08-23 01:59:15 +03:00
|
|
|
|
FontSize = Device.GetNamedSize(NamedSize.Medium, typeof(Button))
|
2016-06-22 06:54:51 +03:00
|
|
|
|
};
|
|
|
|
|
|
2016-08-24 07:07:46 +03:00
|
|
|
|
var loginButton = new ExtendedButton
|
2016-06-22 06:54:51 +03:00
|
|
|
|
{
|
|
|
|
|
Text = AppResources.LogIn,
|
|
|
|
|
Command = new Command(async () => await LoginAsync()),
|
|
|
|
|
VerticalOptions = LayoutOptions.End,
|
2016-06-23 06:50:38 +03:00
|
|
|
|
Style = (Style)Application.Current.Resources["btn-primaryAccent"],
|
2016-08-19 07:27:37 +03:00
|
|
|
|
HorizontalOptions = LayoutOptions.Fill,
|
2016-08-27 02:13:25 +03:00
|
|
|
|
BackgroundColor = Color.Transparent,
|
|
|
|
|
FontSize = Device.GetNamedSize(NamedSize.Medium, typeof(Button))
|
2016-06-22 06:54:51 +03:00
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
var buttonStackLayout = new StackLayout
|
|
|
|
|
{
|
|
|
|
|
Padding = new Thickness(30, 40),
|
|
|
|
|
Spacing = 10,
|
2017-08-23 18:40:40 +03:00
|
|
|
|
Children = { settingsButton, logo, message, createAccountButton, loginButton }
|
2016-06-22 06:54:51 +03:00
|
|
|
|
};
|
|
|
|
|
|
2016-11-26 00:54:33 +03:00
|
|
|
|
Title = AppResources.Bitwarden;
|
2016-08-30 06:50:22 +03:00
|
|
|
|
NavigationPage.SetHasNavigationBar(this, false);
|
2016-07-05 05:31:15 +03:00
|
|
|
|
Content = new ScrollView { Content = buttonStackLayout };
|
2016-06-22 06:54:51 +03:00
|
|
|
|
}
|
|
|
|
|
|
2016-07-23 22:32:11 +03:00
|
|
|
|
protected override void OnAppearing()
|
|
|
|
|
{
|
|
|
|
|
base.OnAppearing();
|
|
|
|
|
MessagingCenter.Send(Application.Current, "ShowStatusBar", false);
|
|
|
|
|
}
|
|
|
|
|
|
2016-06-22 06:54:51 +03:00
|
|
|
|
public async Task LoginAsync()
|
|
|
|
|
{
|
2017-05-20 19:36:09 +03:00
|
|
|
|
if(_lastAction.LastActionWasRecent())
|
|
|
|
|
{
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
_lastAction = DateTime.UtcNow;
|
|
|
|
|
|
2016-08-30 06:50:22 +03:00
|
|
|
|
await Navigation.PushForDeviceAsync(new LoginPage());
|
2016-06-22 06:54:51 +03:00
|
|
|
|
}
|
2016-06-26 03:54:17 +03:00
|
|
|
|
|
|
|
|
|
public async Task RegisterAsync()
|
|
|
|
|
{
|
2017-05-20 19:36:09 +03:00
|
|
|
|
if(_lastAction.LastActionWasRecent())
|
|
|
|
|
{
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
_lastAction = DateTime.UtcNow;
|
|
|
|
|
|
2016-08-30 06:50:22 +03:00
|
|
|
|
await Navigation.PushForDeviceAsync(new RegisterPage(this));
|
2016-08-06 18:57:05 +03:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public async Task DismissRegisterAndLoginAsync(string email)
|
|
|
|
|
{
|
2016-08-30 06:50:22 +03:00
|
|
|
|
await Navigation.PopForDeviceAsync();
|
|
|
|
|
await Navigation.PushForDeviceAsync(new LoginPage(email));
|
2016-11-26 00:54:33 +03:00
|
|
|
|
_userDialogs.Toast(AppResources.AccountCreated);
|
2016-06-26 03:54:17 +03:00
|
|
|
|
}
|
2017-08-23 18:40:40 +03:00
|
|
|
|
|
|
|
|
|
public async Task SettingsAsync()
|
|
|
|
|
{
|
|
|
|
|
if(_lastAction.LastActionWasRecent())
|
|
|
|
|
{
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
_lastAction = DateTime.UtcNow;
|
|
|
|
|
|
|
|
|
|
await Navigation.PushForDeviceAsync(new EnvironmentPage());
|
|
|
|
|
}
|
2016-06-22 06:54:51 +03:00
|
|
|
|
}
|
|
|
|
|
}
|