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

stub out settings page with a listview

This commit is contained in:
Kyle Spearrin 2019-05-14 11:53:41 -04:00
parent 3229835f50
commit ff1f895476
7 changed files with 154 additions and 39 deletions

View File

@ -1,5 +1,5 @@
<?xml version="1.0" encoding="utf-8" ?> <?xml version="1.0" encoding="utf-8" ?>
<ContentPage xmlns="http://xamarin.com/schemas/2014/forms" <pages:BaseContentPage xmlns="http://xamarin.com/schemas/2014/forms"
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml" xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
x:Class="Bit.App.Pages.SettingsPage" x:Class="Bit.App.Pages.SettingsPage"
xmlns:pages="clr-namespace:Bit.App.Pages" xmlns:pages="clr-namespace:Bit.App.Pages"
@ -11,39 +11,49 @@
<pages:SettingsPageViewModel /> <pages:SettingsPageViewModel />
</ContentPage.BindingContext> </ContentPage.BindingContext>
<ScrollView x:Name="_scrollView"> <ContentPage.Resources>
<StackLayout Spacing="20"> <ResourceDictionary>
<StackLayout StyleClass="box"> <DataTemplate
<StackLayout StyleClass="box-row-header"> x:Key="regularTemplate"
<Label Text="{u:I18n Manage}" x:DataType="pages:SettingsPageListItem">
StyleClass="box-header, box-header-platform" /> <ViewCell>
<StackLayout Orientation="Horizontal"
StyleClass="list-row, list-row-platform">
<Label Text="{Binding Name, Mode=OneWay}"
LineBreakMode="TailTruncation"
HorizontalOptions="StartAndExpand"
VerticalOptions="CenterAndExpand"
StyleClass="list-title"/>
</StackLayout> </StackLayout>
</StackLayout> </ViewCell>
<StackLayout StyleClass="box"> </DataTemplate>
<StackLayout StyleClass="box-row-header">
<Label Text="{u:I18n Security}"
StyleClass="box-header, box-header-platform" />
</StackLayout>
</StackLayout>
<StackLayout StyleClass="box">
<StackLayout StyleClass="box-row-header">
<Label Text="{u:I18n Account}"
StyleClass="box-header, box-header-platform" />
</StackLayout>
</StackLayout>
<StackLayout StyleClass="box">
<StackLayout StyleClass="box-row-header">
<Label Text="{u:I18n Tools}"
StyleClass="box-header, box-header-platform" />
</StackLayout>
</StackLayout>
<StackLayout StyleClass="box">
<StackLayout StyleClass="box-row-header">
<Label Text="{u:I18n Other}"
StyleClass="box-header, box-header-platform" />
</StackLayout>
</StackLayout>
</StackLayout>
</ScrollView>
</ContentPage> <pages:SettingsPageListItemSelector
x:Key="listItemDataTemplateSelector"
RegularTemplate="{StaticResource regularTemplate}" />
</ResourceDictionary>
</ContentPage.Resources>
<ListView
ItemsSource="{Binding GroupedItems}"
VerticalOptions="FillAndExpand"
HasUnevenRows="true"
ItemTemplate="{StaticResource listItemDataTemplateSelector}"
IsGroupingEnabled="True"
ItemSelected="RowSelected"
StyleClass="list, list-platform">
<ListView.GroupHeaderTemplate>
<DataTemplate x:DataType="pages:SettingsPageListGroup">
<ViewCell>
<StackLayout StyleClass="list-row-header">
<Label
Text="{Binding Name}"
StyleClass="list-header, list-header-platform" />
</StackLayout>
</ViewCell>
</DataTemplate>
</ListView.GroupHeaderTemplate>
</ListView>
</pages:BaseContentPage>

View File

@ -8,7 +8,7 @@ using Xamarin.Forms.Xaml;
namespace Bit.App.Pages namespace Bit.App.Pages
{ {
public partial class SettingsPage : ContentPage public partial class SettingsPage : BaseContentPage
{ {
private SettingsPageViewModel _vm; private SettingsPageViewModel _vm;
@ -18,5 +18,20 @@ namespace Bit.App.Pages
_vm = BindingContext as SettingsPageViewModel; _vm = BindingContext as SettingsPageViewModel;
_vm.Page = this; _vm.Page = this;
} }
private void RowSelected(object sender, SelectedItemChangedEventArgs e)
{
((ListView)sender).SelectedItem = null;
if(!DoOnce())
{
return;
}
if(!(e.SelectedItem is SettingsPageListItem item))
{
return;
}
// TODO
}
} }
} }

View File

@ -0,0 +1,26 @@
using System.Collections.Generic;
namespace Bit.App.Pages
{
public class SettingsPageListGroup : List<SettingsPageListItem>
{
public SettingsPageListGroup(List<SettingsPageListItem> groupItems, string name, bool doUpper = true)
{
AddRange(groupItems);
if(string.IsNullOrWhiteSpace(name))
{
Name = "-";
}
else if(doUpper)
{
Name = name.ToUpperInvariant();
}
else
{
Name = name;
}
}
public string Name { get; set; }
}
}

View File

@ -0,0 +1,9 @@
namespace Bit.App.Pages
{
public class SettingsPageListItem
{
public string Icon { get; set; }
public string Name { get; set; }
public string SubLabel { get; set; }
}
}

View File

@ -0,0 +1,18 @@
using Xamarin.Forms;
namespace Bit.App.Pages
{
public class SettingsPageListItemSelector : DataTemplateSelector
{
public DataTemplate RegularTemplate { get; set; }
protected override DataTemplate OnSelectTemplate(object item, BindableObject container)
{
if(item is SettingsPageListItem listItem)
{
return RegularTemplate;
}
return null;
}
}
}

View File

@ -1,7 +1,6 @@
using Bit.App.Resources; using Bit.App.Resources;
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Text;
using System.Windows.Input; using System.Windows.Input;
using Xamarin.Forms; using Xamarin.Forms;
@ -15,9 +14,48 @@ namespace Bit.App.Pages
ButtonCommand = new Command(() => Page.DisplayAlert("Button 1 Command", "Button 1 message", "Cancel")); ButtonCommand = new Command(() => Page.DisplayAlert("Button 1 Command", "Button 1 message", "Cancel"));
Button2Command = new Command(() => Page.DisplayAlert("Button 2 Command", "Button 2 message", "Cancel")); Button2Command = new Command(() => Page.DisplayAlert("Button 2 Command", "Button 2 message", "Cancel"));
BuildList();
} }
public ICommand ButtonCommand { get; } public ICommand ButtonCommand { get; }
public ICommand Button2Command { get; } public ICommand Button2Command { get; }
public List<SettingsPageListGroup> GroupedItems { get; set; }
private void BuildList()
{
var doUpper = Device.RuntimePlatform != Device.Android;
var manageItems = new List<SettingsPageListItem>
{
new SettingsPageListItem { Name = AppResources.Folders },
new SettingsPageListItem { Name = AppResources.Sync }
};
var securityItems = new List<SettingsPageListItem>
{
new SettingsPageListItem { Name = AppResources.LockOptions },
new SettingsPageListItem { Name = string.Format(AppResources.UnlockWith, AppResources.Fingerprint) },
new SettingsPageListItem { Name = AppResources.UnlockWithPIN },
new SettingsPageListItem { Name = AppResources.Lock },
new SettingsPageListItem { Name = AppResources.TwoStepLogin }
};
var accountItems = new List<SettingsPageListItem>
{
new SettingsPageListItem { Name = AppResources.ChangeMasterPassword },
new SettingsPageListItem { Name = AppResources.LogOut }
};
var otherItems = new List<SettingsPageListItem>
{
new SettingsPageListItem { Name = AppResources.Options },
new SettingsPageListItem { Name = AppResources.About },
new SettingsPageListItem { Name = AppResources.HelpAndFeedback },
new SettingsPageListItem { Name = AppResources.RateTheApp }
};
GroupedItems = new List<SettingsPageListGroup>
{
new SettingsPageListGroup(manageItems, AppResources.Manage, doUpper),
new SettingsPageListGroup(securityItems, AppResources.Security, doUpper),
new SettingsPageListGroup(accountItems, AppResources.Account, doUpper),
new SettingsPageListGroup(otherItems, AppResources.Other, doUpper)
};
}
} }
} }

View File

@ -87,7 +87,6 @@ namespace Bit.App.Pages
{ {
return; return;
} }
if(!(e.SelectedItem is GroupingsPageListItem item)) if(!(e.SelectedItem is GroupingsPageListItem item))
{ {
return; return;