2022-05-31 20:34:54 +03:00
|
|
|
|
using System;
|
|
|
|
|
using System.Threading.Tasks;
|
|
|
|
|
using Bit.App.Effects;
|
2019-06-05 23:37:54 +03:00
|
|
|
|
using Bit.App.Models;
|
2019-05-31 04:24:03 +03:00
|
|
|
|
using Bit.App.Resources;
|
2021-10-08 15:47:40 +03:00
|
|
|
|
using Bit.Core.Abstractions;
|
2022-02-23 20:40:17 +03:00
|
|
|
|
using Bit.Core.Models.Data;
|
2021-10-08 15:47:40 +03:00
|
|
|
|
using Bit.Core.Utilities;
|
2019-05-14 16:43:46 +03:00
|
|
|
|
using Xamarin.Forms;
|
|
|
|
|
|
|
|
|
|
namespace Bit.App.Pages
|
|
|
|
|
{
|
|
|
|
|
public class TabsPage : TabbedPage
|
|
|
|
|
{
|
2022-05-31 20:34:54 +03:00
|
|
|
|
private readonly IBroadcasterService _broadcasterService;
|
2021-10-08 15:47:40 +03:00
|
|
|
|
private readonly IMessagingService _messagingService;
|
2021-11-11 04:46:48 +03:00
|
|
|
|
private readonly IKeyConnectorService _keyConnectorService;
|
2022-05-31 20:34:54 +03:00
|
|
|
|
private readonly LazyResolve<ILogger> _logger = new LazyResolve<ILogger>("logger");
|
2022-04-26 18:21:17 +03:00
|
|
|
|
|
2019-05-31 21:15:37 +03:00
|
|
|
|
private NavigationPage _groupingsPage;
|
2021-02-11 03:50:10 +03:00
|
|
|
|
private NavigationPage _sendGroupingsPage;
|
2019-06-05 23:37:54 +03:00
|
|
|
|
private NavigationPage _generatorPage;
|
2019-05-31 21:15:37 +03:00
|
|
|
|
|
2019-07-31 23:50:16 +03:00
|
|
|
|
public TabsPage(AppOptions appOptions = null, PreviousPageInfo previousPage = null)
|
2019-05-14 16:43:46 +03:00
|
|
|
|
{
|
2022-05-31 20:34:54 +03:00
|
|
|
|
_broadcasterService = ServiceContainer.Resolve<IBroadcasterService>("broadcasterService");
|
2021-10-08 15:47:40 +03:00
|
|
|
|
_messagingService = ServiceContainer.Resolve<IMessagingService>("messagingService");
|
2021-11-11 04:46:48 +03:00
|
|
|
|
_keyConnectorService = ServiceContainer.Resolve<IKeyConnectorService>("keyConnectorService");
|
2021-10-08 15:47:40 +03:00
|
|
|
|
|
2019-07-31 23:50:16 +03:00
|
|
|
|
_groupingsPage = new NavigationPage(new GroupingsPage(true, previousPage: previousPage))
|
2019-05-14 16:43:46 +03:00
|
|
|
|
{
|
|
|
|
|
Title = AppResources.MyVault,
|
2020-03-11 16:46:48 +03:00
|
|
|
|
IconImageSource = "lock.png"
|
2019-05-14 16:43:46 +03:00
|
|
|
|
};
|
2019-05-31 21:15:37 +03:00
|
|
|
|
Children.Add(_groupingsPage);
|
2019-05-14 16:43:46 +03:00
|
|
|
|
|
2021-03-31 17:19:05 +03:00
|
|
|
|
_sendGroupingsPage = new NavigationPage(new SendGroupingsPage(true, null, null, appOptions))
|
2021-02-11 03:50:10 +03:00
|
|
|
|
{
|
|
|
|
|
Title = AppResources.Send,
|
2022-01-21 12:31:03 +03:00
|
|
|
|
IconImageSource = "send.png",
|
2021-02-11 03:50:10 +03:00
|
|
|
|
};
|
|
|
|
|
Children.Add(_sendGroupingsPage);
|
|
|
|
|
|
2019-06-05 23:37:54 +03:00
|
|
|
|
_generatorPage = new NavigationPage(new GeneratorPage(true, null, this))
|
2019-05-14 16:43:46 +03:00
|
|
|
|
{
|
|
|
|
|
Title = AppResources.Generator,
|
2022-01-21 12:31:03 +03:00
|
|
|
|
IconImageSource = "generate.png"
|
2019-05-14 16:43:46 +03:00
|
|
|
|
};
|
2019-06-05 23:37:54 +03:00
|
|
|
|
Children.Add(_generatorPage);
|
2019-05-14 16:43:46 +03:00
|
|
|
|
|
2019-05-31 21:15:37 +03:00
|
|
|
|
var settingsPage = new NavigationPage(new SettingsPage(this))
|
2019-05-14 16:43:46 +03:00
|
|
|
|
{
|
|
|
|
|
Title = AppResources.Settings,
|
2022-02-23 20:40:17 +03:00
|
|
|
|
IconImageSource = "cog_settings.png"
|
2019-05-14 16:43:46 +03:00
|
|
|
|
};
|
|
|
|
|
Children.Add(settingsPage);
|
|
|
|
|
|
2020-03-28 16:16:28 +03:00
|
|
|
|
if (Device.RuntimePlatform == Device.Android)
|
2019-05-31 04:24:03 +03:00
|
|
|
|
{
|
|
|
|
|
Effects.Add(new TabBarEffect());
|
|
|
|
|
|
|
|
|
|
Xamarin.Forms.PlatformConfiguration.AndroidSpecific.TabbedPage.SetToolbarPlacement(this,
|
|
|
|
|
Xamarin.Forms.PlatformConfiguration.AndroidSpecific.ToolbarPlacement.Bottom);
|
|
|
|
|
Xamarin.Forms.PlatformConfiguration.AndroidSpecific.TabbedPage.SetIsSwipePagingEnabled(this, false);
|
|
|
|
|
Xamarin.Forms.PlatformConfiguration.AndroidSpecific.TabbedPage.SetIsSmoothScrollEnabled(this, false);
|
|
|
|
|
}
|
2019-06-05 23:37:54 +03:00
|
|
|
|
|
2020-03-28 16:16:28 +03:00
|
|
|
|
if (appOptions?.GeneratorTile ?? false)
|
2019-06-05 23:37:54 +03:00
|
|
|
|
{
|
|
|
|
|
appOptions.GeneratorTile = false;
|
|
|
|
|
ResetToGeneratorPage();
|
|
|
|
|
}
|
2020-03-28 16:16:28 +03:00
|
|
|
|
else if (appOptions?.MyVaultTile ?? false)
|
2019-06-07 03:34:59 +03:00
|
|
|
|
{
|
|
|
|
|
appOptions.MyVaultTile = false;
|
|
|
|
|
}
|
2021-03-31 17:19:05 +03:00
|
|
|
|
else if (appOptions?.CreateSend != null)
|
|
|
|
|
{
|
|
|
|
|
ResetToSendPage();
|
|
|
|
|
}
|
2021-11-11 04:46:48 +03:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
protected override async void OnAppearing()
|
|
|
|
|
{
|
|
|
|
|
base.OnAppearing();
|
2022-05-31 20:34:54 +03:00
|
|
|
|
_broadcasterService.Subscribe(nameof(TabsPage), async (message) =>
|
|
|
|
|
{
|
|
|
|
|
if (message.Command == "syncCompleted")
|
|
|
|
|
{
|
|
|
|
|
Device.BeginInvokeOnMainThread(async () => await UpdateVaultButtonTitleAsync());
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
await UpdateVaultButtonTitleAsync();
|
2021-11-11 04:46:48 +03:00
|
|
|
|
if (await _keyConnectorService.UserNeedsMigration())
|
|
|
|
|
{
|
|
|
|
|
_messagingService.Send("convertAccountToKeyConnector");
|
|
|
|
|
}
|
2019-05-14 16:43:46 +03:00
|
|
|
|
}
|
|
|
|
|
|
2022-05-31 20:34:54 +03:00
|
|
|
|
protected override void OnDisappearing()
|
|
|
|
|
{
|
|
|
|
|
base.OnDisappearing();
|
|
|
|
|
_broadcasterService.Unsubscribe(nameof(TabsPage));
|
|
|
|
|
}
|
|
|
|
|
|
2019-05-31 21:15:37 +03:00
|
|
|
|
public void ResetToVaultPage()
|
|
|
|
|
{
|
|
|
|
|
CurrentPage = _groupingsPage;
|
|
|
|
|
}
|
|
|
|
|
|
2019-06-05 23:37:54 +03:00
|
|
|
|
public void ResetToGeneratorPage()
|
|
|
|
|
{
|
|
|
|
|
CurrentPage = _generatorPage;
|
|
|
|
|
}
|
2022-04-26 18:21:17 +03:00
|
|
|
|
|
2021-03-31 17:19:05 +03:00
|
|
|
|
public void ResetToSendPage()
|
|
|
|
|
{
|
|
|
|
|
CurrentPage = _sendGroupingsPage;
|
|
|
|
|
}
|
2019-06-05 23:37:54 +03:00
|
|
|
|
|
2019-05-14 16:43:46 +03:00
|
|
|
|
protected async override void OnCurrentPageChanged()
|
|
|
|
|
{
|
2020-03-28 16:16:28 +03:00
|
|
|
|
if (CurrentPage is NavigationPage navPage)
|
2019-05-14 16:43:46 +03:00
|
|
|
|
{
|
2022-02-23 20:40:17 +03:00
|
|
|
|
if (_groupingsPage?.RootPage is GroupingsPage groupingsPage)
|
|
|
|
|
{
|
|
|
|
|
await groupingsPage.HideAccountSwitchingOverlayAsync();
|
|
|
|
|
}
|
|
|
|
|
|
2021-10-08 15:47:40 +03:00
|
|
|
|
_messagingService.Send("updatedTheme");
|
2022-02-23 20:40:17 +03:00
|
|
|
|
if (navPage.RootPage is GroupingsPage)
|
2019-05-14 16:51:13 +03:00
|
|
|
|
{
|
|
|
|
|
// Load something?
|
|
|
|
|
}
|
2020-03-28 16:16:28 +03:00
|
|
|
|
else if (navPage.RootPage is GeneratorPage genPage)
|
2019-05-14 16:43:46 +03:00
|
|
|
|
{
|
|
|
|
|
await genPage.InitAsync();
|
|
|
|
|
}
|
2020-03-28 16:16:28 +03:00
|
|
|
|
else if (navPage.RootPage is SettingsPage settingsPage)
|
2019-05-14 16:51:13 +03:00
|
|
|
|
{
|
2019-05-31 21:18:32 +03:00
|
|
|
|
await settingsPage.InitAsync();
|
2019-05-14 16:51:13 +03:00
|
|
|
|
}
|
2019-05-14 16:43:46 +03:00
|
|
|
|
}
|
|
|
|
|
}
|
2022-02-23 20:40:17 +03:00
|
|
|
|
|
|
|
|
|
public void OnPageReselected()
|
|
|
|
|
{
|
|
|
|
|
if (_groupingsPage?.RootPage is GroupingsPage groupingsPage)
|
|
|
|
|
{
|
|
|
|
|
groupingsPage.HideAccountSwitchingOverlayAsync().FireAndForget();
|
|
|
|
|
}
|
|
|
|
|
}
|
2022-05-31 20:34:54 +03:00
|
|
|
|
|
|
|
|
|
private async Task UpdateVaultButtonTitleAsync()
|
|
|
|
|
{
|
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
var policyService = ServiceContainer.Resolve<IPolicyService>("policyService");
|
|
|
|
|
var isShowingVaultFilter = await policyService.ShouldShowVaultFilterAsync();
|
|
|
|
|
_groupingsPage.Title = isShowingVaultFilter ? AppResources.Vaults : AppResources.MyVault;
|
|
|
|
|
}
|
|
|
|
|
catch (Exception ex)
|
|
|
|
|
{
|
|
|
|
|
_logger.Value.Exception(ex);
|
|
|
|
|
}
|
|
|
|
|
}
|
2019-05-14 16:43:46 +03:00
|
|
|
|
}
|
|
|
|
|
}
|