bitwarden-android/src/App/Controls/ExtendedContentPage.cs

68 lines
2 KiB
C#
Raw Normal View History

using Bit.App.Abstractions;
using Plugin.Settings.Abstractions;
using System;
using Xamarin.Forms;
using XLabs.Ioc;
namespace Bit.App.Controls
{
public class ExtendedContentPage : ContentPage
{
private ISyncService _syncService;
private IGoogleAnalyticsService _googleAnalyticsService;
private ISettings _settings;
2016-08-05 06:56:44 +03:00
private bool _syncIndicator;
private bool _updateActivity;
public ExtendedContentPage(bool syncIndicator = false, bool updateActivity = true)
{
2016-08-05 06:56:44 +03:00
_syncIndicator = syncIndicator;
_updateActivity = updateActivity;
_syncService = Resolver.Resolve<ISyncService>();
_googleAnalyticsService = Resolver.Resolve<IGoogleAnalyticsService>();
_settings = Resolver.Resolve<ISettings>();
BackgroundColor = Color.FromHex("efeff4");
2016-08-05 06:56:44 +03:00
if(_syncIndicator)
{
MessagingCenter.Subscribe<Application, bool>(Application.Current, "SyncCompleted", (sender, success) =>
{
Device.BeginInvokeOnMainThread(() => IsBusy = _syncService.SyncInProgress);
});
MessagingCenter.Subscribe<Application>(Application.Current, "SyncStarted", (sender) =>
{
Device.BeginInvokeOnMainThread(() => IsBusy = _syncService.SyncInProgress);
});
}
}
2016-08-04 04:45:01 +03:00
protected override void OnAppearing()
{
2016-08-05 06:56:44 +03:00
if(_syncIndicator)
{
IsBusy = _syncService.SyncInProgress;
}
if(_updateActivity)
{
_settings.AddOrUpdateValue(Constants.LastActivityDate, DateTime.UtcNow);
}
_googleAnalyticsService.TrackPage(GetType().Name);
2016-08-04 04:45:01 +03:00
base.OnAppearing();
}
2016-08-05 06:14:47 +03:00
protected override void OnDisappearing()
{
2016-08-05 06:56:44 +03:00
if(_syncIndicator)
{
IsBusy = false;
2016-08-05 06:56:44 +03:00
}
2016-08-05 06:14:47 +03:00
base.OnDisappearing();
}
}
}