1
0
mirror of https://github.com/bitwarden/mobile.git synced 2024-12-18 15:37:42 +01:00

new tab page from code

This commit is contained in:
Kyle Spearrin 2019-05-14 09:43:46 -04:00
parent df802152d7
commit 4f4c6064db
8 changed files with 75 additions and 68 deletions

View File

@ -68,9 +68,6 @@
<Compile Update="Pages\Vault\GroupingsPage\GroupingsPage.xaml.cs">
<DependentUpon>GroupingsPage.xaml</DependentUpon>
</Compile>
<Compile Update="Pages\TabsPage.xaml.cs">
<DependentUpon>TabsPage.xaml</DependentUpon>
</Compile>
</ItemGroup>
<ItemGroup>

View File

@ -1,4 +1,5 @@
using System;
using System.Threading.Tasks;
using Xamarin.Forms;
namespace Bit.App.Pages
@ -6,17 +7,15 @@ namespace Bit.App.Pages
public partial class GeneratorPage : BaseContentPage
{
private GeneratorPageViewModel _vm;
private readonly bool _fromTabPage;
private readonly Action<string> _selectAction;
public GeneratorPage()
: this(null)
{ }
public GeneratorPage(Action<string> selectAction)
public GeneratorPage(bool fromTabPage, Action<string> selectAction = null)
{
InitializeComponent();
_vm = BindingContext as GeneratorPageViewModel;
_vm.Page = this;
_fromTabPage = fromTabPage;
_selectAction = selectAction;
if(selectAction == null)
{
@ -24,10 +23,18 @@ namespace Bit.App.Pages
}
}
public async Task InitAsync()
{
await _vm.InitAsync();
}
protected async override void OnAppearing()
{
base.OnAppearing();
await _vm.InitAsync();
if(!_fromTabPage)
{
await InitAsync();
}
}
private async void Regenerate_Clicked(object sender, EventArgs e)

48
src/App/Pages/TabsPage.cs Normal file
View File

@ -0,0 +1,48 @@
using Bit.App.Resources;
using Xamarin.Forms;
namespace Bit.App.Pages
{
public class TabsPage : TabbedPage
{
public TabsPage()
{
var groupingsPage = new NavigationPage(new GroupingsPage())
{
Title = AppResources.MyVault,
Icon = "lock.png"
};
Children.Add(groupingsPage);
var generatorPage = new NavigationPage(new GeneratorPage(true, null))
{
Title = AppResources.Generator,
Icon = "refresh.png"
};
Children.Add(generatorPage);
var settingsPage = new NavigationPage(new SettingsPage())
{
Title = AppResources.Settings,
Icon = "cogs.png"
};
Children.Add(settingsPage);
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);
}
protected async override void OnCurrentPageChanged()
{
if(CurrentPage is NavigationPage navPage)
{
if(navPage.RootPage is GeneratorPage genPage)
{
await genPage.InitAsync();
}
}
}
}
}

View File

@ -1,40 +0,0 @@
<?xml version="1.0" encoding="utf-8" ?>
<TabbedPage
xmlns="http://xamarin.com/schemas/2014/forms"
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
x:Class="Bit.App.Pages.TabsPage"
xmlns:pages="clr-namespace:Bit.App.Pages"
xmlns:android="clr-namespace:Xamarin.Forms.PlatformConfiguration.AndroidSpecific;assembly=Xamarin.Forms.Core"
android:TabbedPage.ToolbarPlacement="Bottom"
android:TabbedPage.IsSwipePagingEnabled="False">
<TabbedPage.Children>
<NavigationPage Title="My Vault">
<NavigationPage.Icon>
<FileImageSource File="lock.png"></FileImageSource>
</NavigationPage.Icon>
<x:Arguments>
<pages:GroupingsPage />
</x:Arguments>
</NavigationPage>
<NavigationPage Title="Generator">
<NavigationPage.Icon>
<FileImageSource File="refresh.png"></FileImageSource>
</NavigationPage.Icon>
<x:Arguments>
<pages:GeneratorPage />
</x:Arguments>
</NavigationPage>
<NavigationPage Title="Settings">
<NavigationPage.Icon>
<FileImageSource File="cogs.png"></FileImageSource>
</NavigationPage.Icon>
<x:Arguments>
<pages:SettingsPage />
</x:Arguments>
</NavigationPage>
</TabbedPage.Children>
</TabbedPage>

View File

@ -1,18 +0,0 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Xamarin.Forms;
using Xamarin.Forms.Xaml;
namespace Bit.App.Pages
{
public partial class TabsPage : TabbedPage
{
public TabsPage()
{
InitializeComponent();
}
}
}

View File

@ -429,7 +429,7 @@ namespace Bit.App.Pages
return;
}
}
var page = new GeneratorPage(async (password) =>
var page = new GeneratorPage(false, async (password) =>
{
Cipher.Login.Password = password;
TriggerCipherChanged();

View File

@ -1698,6 +1698,15 @@ namespace Bit.App.Resources {
}
}
/// <summary>
/// Looks up a localized string similar to Generator.
/// </summary>
public static string Generator {
get {
return ResourceManager.GetString("Generator", resourceCulture);
}
}
/// <summary>
/// Looks up a localized string similar to Get your master password hint.
/// </summary>

View File

@ -1460,4 +1460,8 @@
<value>Clear</value>
<comment>To clear something out. example: To clear browser history.</comment>
</data>
<data name="Generator" xml:space="preserve">
<value>Generator</value>
<comment>Short for "Password Generator"</comment>
</data>
</root>