2016-05-02 09:52:09 +03:00
|
|
|
|
using System;
|
|
|
|
|
using Android.App;
|
|
|
|
|
using Android.Content.PM;
|
|
|
|
|
using Android.Views;
|
|
|
|
|
using Android.OS;
|
|
|
|
|
using Bit.App.Abstractions;
|
|
|
|
|
using XLabs.Ioc;
|
2016-05-21 19:32:34 +03:00
|
|
|
|
using Plugin.Fingerprint.Abstractions;
|
|
|
|
|
using Plugin.Settings.Abstractions;
|
2016-07-02 01:54:00 +03:00
|
|
|
|
using Plugin.Connectivity.Abstractions;
|
|
|
|
|
using Acr.UserDialogs;
|
2016-08-18 06:08:26 +03:00
|
|
|
|
using Android.Content;
|
2016-08-19 02:58:25 +03:00
|
|
|
|
using System.Reflection;
|
2016-08-20 03:42:33 +03:00
|
|
|
|
using Xamarin.Forms.Platform.Android;
|
|
|
|
|
using Xamarin.Forms;
|
2016-08-27 21:36:32 +03:00
|
|
|
|
using System.Threading.Tasks;
|
2016-05-02 09:52:09 +03:00
|
|
|
|
|
|
|
|
|
namespace Bit.Android
|
|
|
|
|
{
|
2016-08-19 07:27:37 +03:00
|
|
|
|
[Activity(Label = "bitwarden",
|
2016-08-27 21:36:32 +03:00
|
|
|
|
Icon = "@drawable/icon",
|
2016-08-19 07:27:37 +03:00
|
|
|
|
ConfigurationChanges = ConfigChanges.ScreenSize | ConfigChanges.Orientation,
|
|
|
|
|
WindowSoftInputMode = SoftInput.StateHidden)]
|
2016-08-20 03:42:33 +03:00
|
|
|
|
public class MainActivity : FormsAppCompatActivity
|
2016-05-02 09:52:09 +03:00
|
|
|
|
{
|
2016-08-14 07:15:47 +03:00
|
|
|
|
private const string HockeyAppId = "d3834185b4a643479047b86c65293d42";
|
|
|
|
|
|
2016-08-27 22:00:12 +03:00
|
|
|
|
protected override void OnCreate(Bundle bundle)
|
2016-05-02 09:52:09 +03:00
|
|
|
|
{
|
2016-08-20 03:42:33 +03:00
|
|
|
|
ToolbarResource = Resource.Layout.toolbar;
|
|
|
|
|
TabLayoutResource = Resource.Layout.tabs;
|
|
|
|
|
|
2016-05-02 09:52:09 +03:00
|
|
|
|
base.OnCreate(bundle);
|
2016-08-27 21:36:32 +03:00
|
|
|
|
|
|
|
|
|
// workaround for app compat bug
|
|
|
|
|
// ref https://forums.xamarin.com/discussion/62414/app-resuming-results-in-crash-with-formsappcompatactivity
|
2016-08-27 22:00:12 +03:00
|
|
|
|
Task.Delay(10).Wait();
|
2016-08-27 21:36:32 +03:00
|
|
|
|
|
2016-06-05 05:35:03 +03:00
|
|
|
|
Console.WriteLine("A OnCreate");
|
2016-08-19 07:27:37 +03:00
|
|
|
|
Window.SetSoftInputMode(SoftInput.StateHidden);
|
|
|
|
|
Window.AddFlags(WindowManagerFlags.Secure);
|
2016-05-02 09:52:09 +03:00
|
|
|
|
|
2016-08-14 07:15:47 +03:00
|
|
|
|
var appIdService = Resolver.Resolve<IAppIdService>();
|
|
|
|
|
var authService = Resolver.Resolve<IAuthService>();
|
|
|
|
|
|
|
|
|
|
HockeyApp.Android.CrashManager.Register(this, HockeyAppId,
|
|
|
|
|
new HockeyAppCrashManagerListener(appIdService, authService));
|
2016-08-19 02:58:25 +03:00
|
|
|
|
|
2016-08-20 03:42:33 +03:00
|
|
|
|
Forms.Init(this, bundle);
|
2016-05-02 09:52:09 +03:00
|
|
|
|
|
2016-08-20 03:42:33 +03:00
|
|
|
|
typeof(Color).GetProperty("Accent", BindingFlags.Public | BindingFlags.Static)
|
|
|
|
|
.SetValue(null, Color.FromHex("d2d6de"));
|
2016-08-19 02:58:25 +03:00
|
|
|
|
|
|
|
|
|
|
2016-05-21 19:32:34 +03:00
|
|
|
|
LoadApplication(new App.App(
|
|
|
|
|
Resolver.Resolve<IAuthService>(),
|
2016-07-02 01:54:00 +03:00
|
|
|
|
Resolver.Resolve<IConnectivity>(),
|
|
|
|
|
Resolver.Resolve<IUserDialogs>(),
|
2016-05-21 19:32:34 +03:00
|
|
|
|
Resolver.Resolve<IDatabaseService>(),
|
2016-07-01 03:08:34 +03:00
|
|
|
|
Resolver.Resolve<ISyncService>(),
|
2016-05-21 19:32:34 +03:00
|
|
|
|
Resolver.Resolve<IFingerprint>(),
|
2016-07-20 01:46:39 +03:00
|
|
|
|
Resolver.Resolve<ISettings>(),
|
2016-08-04 07:06:09 +03:00
|
|
|
|
Resolver.Resolve<ILockService>(),
|
|
|
|
|
Resolver.Resolve<IGoogleAnalyticsService>()));
|
2016-08-18 06:08:26 +03:00
|
|
|
|
|
2016-08-27 21:36:32 +03:00
|
|
|
|
MessagingCenter.Subscribe<Xamarin.Forms.Application>(Xamarin.Forms.Application.Current, "RateApp", (sender) =>
|
2016-08-18 06:08:26 +03:00
|
|
|
|
{
|
|
|
|
|
RateApp();
|
|
|
|
|
});
|
2016-05-02 09:52:09 +03:00
|
|
|
|
}
|
|
|
|
|
|
2016-06-05 05:35:03 +03:00
|
|
|
|
protected override void OnPause()
|
|
|
|
|
{
|
|
|
|
|
Console.WriteLine("A OnPause");
|
|
|
|
|
base.OnPause();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
protected override void OnDestroy()
|
|
|
|
|
{
|
|
|
|
|
Console.WriteLine("A OnDestroy");
|
|
|
|
|
base.OnDestroy();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
protected override void OnRestart()
|
|
|
|
|
{
|
|
|
|
|
Console.WriteLine("A OnRestart");
|
|
|
|
|
base.OnRestart();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
protected override void OnStart()
|
|
|
|
|
{
|
|
|
|
|
Console.WriteLine("A OnStart");
|
|
|
|
|
base.OnStart();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
protected override void OnStop()
|
|
|
|
|
{
|
|
|
|
|
Console.WriteLine("A OnStop");
|
|
|
|
|
base.OnStop();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
protected override void OnResume()
|
|
|
|
|
{
|
|
|
|
|
Console.WriteLine("A OnResume");
|
|
|
|
|
base.OnResume();
|
|
|
|
|
}
|
2016-08-18 06:08:26 +03:00
|
|
|
|
|
|
|
|
|
public void RateApp()
|
|
|
|
|
{
|
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
var rateIntent = RateIntentForUrl("market://details");
|
|
|
|
|
StartActivity(rateIntent);
|
|
|
|
|
}
|
|
|
|
|
catch(ActivityNotFoundException)
|
|
|
|
|
{
|
|
|
|
|
var rateIntent = RateIntentForUrl("https://play.google.com/store/apps/details");
|
|
|
|
|
StartActivity(rateIntent);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private Intent RateIntentForUrl(string url)
|
|
|
|
|
{
|
|
|
|
|
var intent = new Intent(Intent.ActionView, global::Android.Net.Uri.Parse($"{url}?id={PackageName}"));
|
|
|
|
|
var flags = ActivityFlags.NoHistory | ActivityFlags.MultipleTask;
|
|
|
|
|
if((int)Build.VERSION.SdkInt >= 21)
|
|
|
|
|
{
|
|
|
|
|
flags |= ActivityFlags.NewDocument;
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
// noinspection deprecation
|
|
|
|
|
flags |= ActivityFlags.ClearWhenTaskReset;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
intent.AddFlags(flags);
|
|
|
|
|
return intent;
|
|
|
|
|
}
|
2016-05-02 09:52:09 +03:00
|
|
|
|
}
|
|
|
|
|
}
|