bitwarden-android/src/App/Pages/HomePage.cs

147 lines
4.9 KiB
C#
Raw Normal View History

using System;
using System.Threading.Tasks;
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;
namespace Bit.App.Pages
{
public class HomePage : ExtendedContentPage
{
private readonly IAuthService _authService;
private readonly ISettings _settings;
2017-12-22 23:00:11 +03:00
private readonly IDeviceActionService _deviceActionService;
private DateTime? _lastAction;
public HomePage()
2018-01-18 21:18:08 +03:00
: base(updateActivity: false, requireAuth: false)
{
_authService = Resolver.Resolve<IAuthService>();
2017-12-22 23:00:11 +03:00
_deviceActionService = Resolver.Resolve<IDeviceActionService>();
_settings = Resolver.Resolve<ISettings>();
Init();
}
public void Init()
{
MessagingCenter.Send(Application.Current, "ShowStatusBar", false);
2017-10-19 15:55:18 +03:00
var settingsButton = new ExtendedButton
{
Image = "cog.png",
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
{
Source = "logo.png",
VerticalOptions = LayoutOptions.CenterAndExpand,
2017-02-16 05:56:02 +03:00
HorizontalOptions = LayoutOptions.Center,
WidthRequest = 282,
Margin = new Thickness(0, 30, 0, 0),
2017-02-16 05:56:02 +03:00
HeightRequest = 44
};
var message = new Label
{
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-08-24 07:07:46 +03:00
var createAccountButton = new ExtendedButton
{
Text = AppResources.CreateAccount,
Command = new Command(async () => await RegisterAsync()),
VerticalOptions = LayoutOptions.End,
2016-06-23 06:50:38 +03:00
HorizontalOptions = LayoutOptions.Fill,
Style = (Style)Application.Current.Resources["btn-primary"],
2016-08-23 01:59:15 +03:00
FontSize = Device.GetNamedSize(NamedSize.Medium, typeof(Button))
};
2016-08-24 07:07:46 +03:00
var loginButton = new ExtendedButton
{
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"],
HorizontalOptions = LayoutOptions.Fill,
2016-08-27 02:13:25 +03:00
BackgroundColor = Color.Transparent,
FontSize = Device.GetNamedSize(NamedSize.Medium, typeof(Button))
};
var buttonStackLayout = new StackLayout
{
Padding = new Thickness(30, 40),
Spacing = 10,
Children = { settingsButton, logo, message, createAccountButton, loginButton }
};
Title = AppResources.Bitwarden;
NavigationPage.SetHasNavigationBar(this, false);
Content = new ScrollView { Content = buttonStackLayout };
}
protected override void OnAppearing()
{
base.OnAppearing();
MessagingCenter.Send(Application.Current, "ShowStatusBar", false);
}
public async Task LoginAsync()
{
if(_lastAction.LastActionWasRecent())
{
return;
}
_lastAction = DateTime.UtcNow;
await Navigation.PushForDeviceAsync(new LoginPage());
}
public async Task RegisterAsync()
{
if(_lastAction.LastActionWasRecent())
{
return;
}
_lastAction = DateTime.UtcNow;
await Navigation.PushForDeviceAsync(new RegisterPage(this));
}
public async Task DismissRegisterAndLoginAsync(string email)
{
await Navigation.PopForDeviceAsync();
await Navigation.PushForDeviceAsync(new LoginPage(email));
2017-12-22 23:00:11 +03:00
_deviceActionService.Toast(AppResources.AccountCreated);
}
public async Task SettingsAsync()
{
if(_lastAction.LastActionWasRecent())
{
return;
}
_lastAction = DateTime.UtcNow;
await Navigation.PushForDeviceAsync(new EnvironmentPage());
}
}
}