1
0
mirror of https://github.com/bitwarden/mobile.git synced 2024-11-09 09:40:02 +01:00

Reusing App.xaml.cs Navigation for the Android RedirectPage

Some other cleanup and changes
This commit is contained in:
Dinis Vieira 2023-12-16 15:18:07 +00:00
parent da0866cc85
commit e39898bba6
No known key found for this signature in database
GPG Key ID: 9389160FF6C295F3
5 changed files with 28 additions and 110 deletions

View File

@ -96,8 +96,9 @@ namespace Bit.App
if (Options != null && (Options.FromAutofillFramework || Options.Uri != null || Options.OtpData != null || Options.CreateSend != null)) //"Internal" Autofill and Uri/Otp/CreateSend if (Options != null && (Options.FromAutofillFramework || Options.Uri != null || Options.OtpData != null || Options.CreateSend != null)) //"Internal" Autofill and Uri/Otp/CreateSend
{ {
_autofillWindow = new Window(new NavigationPage(new AndroidExtSplashPage(Options))); _autofillWindow = new Window(new NavigationPage(new AndroidNavigationRedirectPage()));
CurrentWindow = _autofillWindow; CurrentWindow = _autofillWindow;
_isResumed = true;
return CurrentWindow; return CurrentWindow;
} }

View File

@ -85,6 +85,9 @@
<LastGenOutput>AppResources.Designer.cs</LastGenOutput> <LastGenOutput>AppResources.Designer.cs</LastGenOutput>
<Generator>PublicResXFileCodeGenerator</Generator> <Generator>PublicResXFileCodeGenerator</Generator>
</EmbeddedResource> </EmbeddedResource>
<Compile Update="Pages\AndroidNavigationRedirectPage.xaml.cs">
<DependentUpon>AndroidNavigationRedirectPage.xaml</DependentUpon>
</Compile>
<Compile Update="Resources\Localization\AppResources.Designer.cs"> <Compile Update="Resources\Localization\AppResources.Designer.cs">
<DependentUpon>AppResources.resx</DependentUpon> <DependentUpon>AppResources.resx</DependentUpon>
<DesignTime>True</DesignTime> <DesignTime>True</DesignTime>
@ -92,7 +95,7 @@
</Compile> </Compile>
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>
<MauiXaml Update="Pages\AndroidExtSplashPage.xaml"> <MauiXaml Update="Pages\AndroidNavigationRedirectPage.xaml">
<Generator>MSBuild:Compile</Generator> <Generator>MSBuild:Compile</Generator>
</MauiXaml> </MauiXaml>
</ItemGroup> </ItemGroup>

View File

@ -1,105 +0,0 @@
using Bit.App.Models;
using Bit.App.Pages;
using Bit.App.Utilities.AccountManagement;
using Bit.Core.Abstractions;
using Bit.Core.Utilities;
namespace Bit.Core.Pages;
public partial class AndroidExtSplashPage : ContentPage
{
private IConditionedAwaiterManager _conditionedAwaiterManager;
private IVaultTimeoutService _vaultTimeoutService;
private IStateService _stateService;
private AppOptions _appOptions;
public AndroidExtSplashPage(AppOptions appOptions)
{
InitializeComponent();
_appOptions = appOptions ?? new AppOptions();
_conditionedAwaiterManager = ServiceContainer.Resolve<IConditionedAwaiterManager>();
_vaultTimeoutService = ServiceContainer.Resolve<IVaultTimeoutService>("vaultTimeoutService");
_stateService = ServiceContainer.Resolve<IStateService>();
}
private async Task GetNavigationToExecuteAsync(AppOptions options, Window window)
{
await _conditionedAwaiterManager.GetAwaiterForPrecondition(AwaiterPrecondition.EnvironmentUrlsInited);
var authed = await _stateService.IsAuthenticatedAsync();
if (authed)
{
if (await _vaultTimeoutService.IsLoggedOutByTimeoutAsync() ||
await _vaultTimeoutService.ShouldLogOutByTimeoutAsync())
{
// TODO implement orgIdentifier flow to SSO Login page, same as email flow below
// var orgIdentifier = await _stateService.GetOrgIdentifierAsync();
var email = await _stateService.GetEmailAsync();
options.HideAccountSwitcher = await _stateService.GetActiveUserIdAsync() == null;
var navParams = new LoginNavigationParams(email);
if (navParams is LoginNavigationParams loginParams)
{
window.Page = new NavigationPage(new LoginPage(loginParams.Email, options));
}
}
else if (await _vaultTimeoutService.IsLockedAsync() ||
await _vaultTimeoutService.ShouldLockAsync())
{
/* //TODO: is lockParams needed here?
if (navParams is LockNavigationParams lockParams)
{
return () => new Window(new NavigationPage(new LockPage(Options, lockParams.AutoPromptBiometric)));
}
else
{*/
window.Page = new NavigationPage(new LockPage(options));
/*}*/
}
else if (options.FromAutofillFramework && options.SaveType.HasValue)
{
window.Page = new NavigationPage(new CipherAddEditPage(appOptions: options));
}
else if (options.Uri != null)
{
window.Page = new NavigationPage(new CipherSelectionPage(options));
}
else if (options.OtpData != null)
{
window.Page = new NavigationPage(new CipherSelectionPage(options));
}
else if (options.CreateSend != null)
{
window.Page = new NavigationPage(new SendAddEditPage(options));
}
else
{
window.Page = new TabsPage(options);
}
}
else
{
options.HideAccountSwitcher = await _stateService.GetActiveUserIdAsync() == null;
if (await _vaultTimeoutService.IsLoggedOutByTimeoutAsync() ||
await _vaultTimeoutService.ShouldLogOutByTimeoutAsync())
{
// TODO implement orgIdentifier flow to SSO Login page, same as email flow below
// var orgIdentifier = await _stateService.GetOrgIdentifierAsync();
var email = await _stateService.GetEmailAsync();
await _stateService.SetRememberedEmailAsync(email);
window.Page = new NavigationPage(new HomePage(options));
}
else
{
window.Page = new NavigationPage(new HomePage(options));
}
}
}
private async void AndroidExtSplashPage_OnLoaded(object sender, EventArgs e)
{
await GetNavigationToExecuteAsync(_appOptions, this.Window);
}
}

View File

@ -1,9 +1,8 @@
<?xml version="1.0" encoding="utf-8" ?> <?xml version="1.0" encoding="utf-8" ?>
<ContentPage xmlns="http://schemas.microsoft.com/dotnet/2021/maui" <ContentPage xmlns="http://schemas.microsoft.com/dotnet/2021/maui"
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml" xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
x:Class="Bit.Core.Pages.AndroidExtSplashPage" x:Class="Bit.Core.Pages.AndroidNavigationRedirectPage"
Title="AndroidExtSplashPage" Loaded="AndroidNavigationRedirectPage_OnLoaded">
Loaded="AndroidExtSplashPage_OnLoaded">
<Grid> <Grid>
<ActivityIndicator VerticalOptions="Center" HorizontalOptions="Center" IsRunning="True" /> <ActivityIndicator VerticalOptions="Center" HorizontalOptions="Center" IsRunning="True" />
</Grid> </Grid>

View File

@ -0,0 +1,20 @@
using Bit.App.Abstractions;
using Bit.Core.Utilities;
namespace Bit.Core.Pages;
public partial class AndroidNavigationRedirectPage : ContentPage
{
private readonly IAccountsManager _accountsManager;
public AndroidNavigationRedirectPage()
{
_accountsManager = ServiceContainer.Resolve<IAccountsManager>("accountsManager");
InitializeComponent();
}
private void AndroidNavigationRedirectPage_OnLoaded(object sender, EventArgs e)
{
_accountsManager.NavigateOnAccountChangeAsync().FireAndForget();
}
}