mirror of
https://github.com/bitwarden/android.git
synced 2024-10-31 23:25:45 +03:00
stub out settings page with a listview
This commit is contained in:
parent
3229835f50
commit
ff1f895476
7 changed files with 154 additions and 39 deletions
|
@ -1,5 +1,5 @@
|
|||
<?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"
|
||||
x:Class="Bit.App.Pages.SettingsPage"
|
||||
xmlns:pages="clr-namespace:Bit.App.Pages"
|
||||
|
@ -11,39 +11,49 @@
|
|||
<pages:SettingsPageViewModel />
|
||||
</ContentPage.BindingContext>
|
||||
|
||||
<ScrollView x:Name="_scrollView">
|
||||
<StackLayout Spacing="20">
|
||||
<StackLayout StyleClass="box">
|
||||
<StackLayout StyleClass="box-row-header">
|
||||
<Label Text="{u:I18n Manage}"
|
||||
StyleClass="box-header, box-header-platform" />
|
||||
</StackLayout>
|
||||
</StackLayout>
|
||||
<StackLayout StyleClass="box">
|
||||
<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.Resources>
|
||||
<ResourceDictionary>
|
||||
<DataTemplate
|
||||
x:Key="regularTemplate"
|
||||
x:DataType="pages:SettingsPageListItem">
|
||||
<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>
|
||||
</ViewCell>
|
||||
</DataTemplate>
|
||||
|
||||
</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>
|
||||
|
|
|
@ -8,7 +8,7 @@ using Xamarin.Forms.Xaml;
|
|||
|
||||
namespace Bit.App.Pages
|
||||
{
|
||||
public partial class SettingsPage : ContentPage
|
||||
public partial class SettingsPage : BaseContentPage
|
||||
{
|
||||
private SettingsPageViewModel _vm;
|
||||
|
||||
|
@ -18,5 +18,20 @@ namespace Bit.App.Pages
|
|||
_vm = BindingContext as SettingsPageViewModel;
|
||||
_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
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
26
src/App/Pages/Settings/SettingsPageListGroup.cs
Normal file
26
src/App/Pages/Settings/SettingsPageListGroup.cs
Normal 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; }
|
||||
}
|
||||
}
|
9
src/App/Pages/Settings/SettingsPageListItem.cs
Normal file
9
src/App/Pages/Settings/SettingsPageListItem.cs
Normal 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; }
|
||||
}
|
||||
}
|
18
src/App/Pages/Settings/SettingsPageListItemSelector.cs
Normal file
18
src/App/Pages/Settings/SettingsPageListItemSelector.cs
Normal 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;
|
||||
}
|
||||
}
|
||||
}
|
|
@ -1,7 +1,6 @@
|
|||
using Bit.App.Resources;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Text;
|
||||
using System.Windows.Input;
|
||||
using Xamarin.Forms;
|
||||
|
||||
|
@ -15,9 +14,48 @@ namespace Bit.App.Pages
|
|||
|
||||
ButtonCommand = new Command(() => Page.DisplayAlert("Button 1 Command", "Button 1 message", "Cancel"));
|
||||
Button2Command = new Command(() => Page.DisplayAlert("Button 2 Command", "Button 2 message", "Cancel"));
|
||||
BuildList();
|
||||
}
|
||||
|
||||
public ICommand ButtonCommand { 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)
|
||||
};
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -87,7 +87,6 @@ namespace Bit.App.Pages
|
|||
{
|
||||
return;
|
||||
}
|
||||
|
||||
if(!(e.SelectedItem is GroupingsPageListItem item))
|
||||
{
|
||||
return;
|
||||
|
|
Loading…
Reference in a new issue