2019-06-12 15:31:33 +03:00
|
|
|
|
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
|
|
|
|
|
{
|
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-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
|
|
|
|
{
|
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();
|
|
|
|
|
if (await _keyConnectorService.UserNeedsMigration())
|
|
|
|
|
{
|
|
|
|
|
_messagingService.Send("convertAccountToKeyConnector");
|
|
|
|
|
}
|
2019-05-14 16:43:46 +03:00
|
|
|
|
}
|
|
|
|
|
|
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();
|
|
|
|
|
}
|
|
|
|
|
}
|
2019-05-14 16:43:46 +03:00
|
|
|
|
}
|
|
|
|
|
}
|