bitwarden-android/src/App/App.xaml.cs

93 lines
3.2 KiB
C#
Raw Normal View History

2019-04-10 06:24:03 +03:00
using Bit.App.Models;
using Bit.App.Pages;
2019-04-11 22:33:10 +03:00
using Bit.App.Resources;
using Bit.App.Services;
2019-03-30 04:23:34 +03:00
using Bit.App.Utilities;
2019-04-11 22:33:10 +03:00
using Bit.Core.Abstractions;
using Bit.Core.Utilities;
2019-03-29 00:10:10 +03:00
using System;
2019-03-28 03:12:44 +03:00
using Xamarin.Forms;
2019-03-30 00:54:03 +03:00
using Xamarin.Forms.StyleSheets;
2019-03-28 03:12:44 +03:00
using Xamarin.Forms.Xaml;
[assembly: XamlCompilation(XamlCompilationOptions.Compile)]
namespace Bit.App
{
public partial class App : Application
{
2019-04-11 22:33:10 +03:00
private readonly MobileI18nService _i18nService;
2019-04-19 16:42:55 +03:00
private readonly IUserService _userService;
private readonly IBroadcasterService _broadcasterService;
private readonly IMessagingService _messagingService;
2019-04-11 22:33:10 +03:00
2019-03-28 03:12:44 +03:00
public App()
{
2019-04-19 16:42:55 +03:00
_userService = ServiceContainer.Resolve<IUserService>("userService");
_broadcasterService = ServiceContainer.Resolve<IBroadcasterService>("broadcasterService");
_messagingService = ServiceContainer.Resolve<IMessagingService>("messagingService");
2019-04-11 22:33:10 +03:00
_i18nService = ServiceContainer.Resolve<II18nService>("i18nService") as MobileI18nService;
2019-03-30 00:54:03 +03:00
2019-04-11 22:33:10 +03:00
InitializeComponent();
SetCulture();
2019-04-05 20:35:19 +03:00
ThemeManager.SetTheme("light");
2019-04-19 14:42:36 +03:00
MainPage = new HomePage();
2019-04-19 16:42:55 +03:00
_userService.IsAuthenticatedAsync().ContinueWith(async authed =>
{
if(await authed)
{
Current.MainPage = new TabsPage();
}
else
{
Current.MainPage = new HomePage();
}
});
2019-04-10 06:24:03 +03:00
2019-04-11 22:33:10 +03:00
ServiceContainer.Resolve<MobilePlatformUtilsService>("platformUtilsService").Init();
2019-04-19 19:29:37 +03:00
_broadcasterService.Subscribe(nameof(App), async (message) =>
2019-04-10 06:24:03 +03:00
{
2019-04-19 19:29:37 +03:00
if(message.Command == "showDialog")
2019-04-10 06:24:03 +03:00
{
2019-04-19 19:29:37 +03:00
var details = message.Data as DialogDetails;
var confirmed = true;
var confirmText = string.IsNullOrWhiteSpace(details.ConfirmText) ?
AppResources.Ok : details.ConfirmText;
if(!string.IsNullOrWhiteSpace(details.CancelText))
{
confirmed = await MainPage.DisplayAlert(details.Title, details.Text, confirmText,
details.CancelText);
}
else
{
await MainPage.DisplayAlert(details.Title, details.Text, details.ConfirmText);
}
_messagingService.Send("showDialogResolve", new Tuple<int, bool>(details.DialogId, confirmed));
2019-04-10 06:24:03 +03:00
}
});
2019-03-28 03:12:44 +03:00
}
protected override void OnStart()
{
// Handle when your app starts
}
protected override void OnSleep()
{
// Handle when your app sleeps
}
protected override void OnResume()
{
// Handle when your app resumes
}
2019-04-11 22:33:10 +03:00
private void SetCulture()
{
// Calendars are removed by linker. ref https://bugzilla.xamarin.com/show_bug.cgi?id=59077
new System.Globalization.ThaiBuddhistCalendar();
new System.Globalization.HijriCalendar();
new System.Globalization.UmAlQuraCalendar();
}
2019-03-28 03:12:44 +03:00
}
}