bitwarden-android/src/Android/MainApplication.cs

58 lines
2.2 KiB
C#
Raw Normal View History

2019-03-28 03:12:44 +03:00
using System;
2019-04-11 21:14:34 +03:00
using System.IO;
2019-03-28 03:12:44 +03:00
using Android.App;
using Android.Runtime;
2019-04-11 21:14:34 +03:00
using Bit.App.Abstractions;
using Bit.App.Services;
using Bit.Core.Abstractions;
using Bit.Core.Services;
using Bit.Core.Utilities;
using Bit.Droid.Services;
2019-03-28 03:12:44 +03:00
namespace Bit.Droid
{
#if DEBUG
[Application(Debuggable = true)]
#else
[Application(Debuggable = false)]
#endif
[Register("com.x8bit.bitwarden.MainApplication")]
public class MainApplication : Application
{
public MainApplication(IntPtr handle, JniHandleOwnership transer)
: base(handle, transer)
2019-04-11 21:14:34 +03:00
{
if(ServiceContainer.RegisteredServices.Count == 0)
{
RegisterLocalServices();
ServiceContainer.Init();
}
}
2019-04-10 06:24:03 +03:00
public override void OnCreate()
{
base.OnCreate();
Plugin.CurrentActivity.CrossCurrentActivity.Current.Init(this);
}
2019-04-11 21:14:34 +03:00
public void RegisterLocalServices()
{
var preferencesStorage = new PreferencesStorageService(null);
var documentsPath = Environment.GetFolderPath(Environment.SpecialFolder.Personal);
var liteDbStorage = new LiteDbStorageService(Path.Combine(documentsPath, "bitwarden.db"));
var deviceActionService = new DeviceActionService();
2019-04-11 22:33:10 +03:00
var localizeService = new LocalizeService();
2019-04-11 21:14:34 +03:00
2019-04-11 22:33:10 +03:00
ServiceContainer.Register<ILocalizeService>("localizeService", localizeService);
ServiceContainer.Register<II18nService>("i18nService",
new MobileI18nService(localizeService.GetCurrentCultureInfo()));
2019-04-11 21:14:34 +03:00
ServiceContainer.Register<ICryptoPrimitiveService>("cryptoPrimitiveService", new CryptoPrimitiveService());
ServiceContainer.Register<IStorageService>("storageService",
new MobileStorageService(preferencesStorage, liteDbStorage));
ServiceContainer.Register<IStorageService>("secureStorageService", new SecureStorageService());
ServiceContainer.Register<IDeviceActionService>("deviceActionService", deviceActionService);
ServiceContainer.Register<IPlatformUtilsService>("platformUtilsService",
new MobilePlatformUtilsService(deviceActionService));
}
2019-03-28 03:12:44 +03:00
}
}