1
0
mirror of https://github.com/bitwarden/mobile.git synced 2024-12-17 15:27:43 +01:00

grouping types filter

This commit is contained in:
Kyle Spearrin 2019-05-01 11:31:00 -04:00
parent caaec3ea57
commit ba9605383d
10 changed files with 118 additions and 43 deletions

View File

@ -43,8 +43,8 @@
ErrorPlaceholder="login.png" ErrorPlaceholder="login.png"
HorizontalOptions="Center" HorizontalOptions="Center"
VerticalOptions="Center" VerticalOptions="Center"
WidthRequest="20" WidthRequest="22"
HeightRequest="20" HeightRequest="22"
IsVisible="False"/> IsVisible="False"/>
<Label LineBreakMode="TailTruncation" <Label LineBreakMode="TailTruncation"
Grid.Column="1" Grid.Column="1"

View File

@ -22,34 +22,16 @@
ButtonCommand="{Binding BindingContext.CipherOptionsCommand, Source={x:Reference _page}}" /> ButtonCommand="{Binding BindingContext.CipherOptionsCommand, Source={x:Reference _page}}" />
</DataTemplate> </DataTemplate>
<DataTemplate x:Key="folderTemplate" <DataTemplate x:Key="groupTemplate"
x:DataType="pages:GroupingsPageListItem"> x:DataType="pages:GroupingsPageListItem">
<ViewCell> <ViewCell>
<StackLayout Orientation="Horizontal" <StackLayout Orientation="Horizontal"
StyleClass="list-row, list-row-platform"> StyleClass="list-row, list-row-platform">
<controls:FaLabel Text="{Binding Icon, Mode=OneWay}" <controls:FaLabel Text="{Binding Icon, Mode=OneWay}"
HorizontalOptions="Start" HorizontalOptions="Center"
VerticalOptions="CenterAndExpand" VerticalOptions="Center"
StyleClass="list-icon" /> StyleClass="list-icon" />
<Label Text="{Binding Folder.Name, Mode=OneWay}" <Label Text="{Binding Name, Mode=OneWay}"
LineBreakMode="TailTruncation"
HorizontalOptions="StartAndExpand"
VerticalOptions="CenterAndExpand"
StyleClass="list-title"/>
</StackLayout>
</ViewCell>
</DataTemplate>
<DataTemplate x:Key="collectionTemplate"
x:DataType="pages:GroupingsPageListItem">
<ViewCell>
<StackLayout Orientation="Horizontal"
StyleClass="list-row, list-row-platform">
<controls:FaLabel Text="{Binding Icon, Mode=OneWay}"
HorizontalOptions="Start"
VerticalOptions="CenterAndExpand"
StyleClass="list-icon" />
<Label Text="{Binding Collection.Name, Mode=OneWay}"
LineBreakMode="TailTruncation" LineBreakMode="TailTruncation"
HorizontalOptions="StartAndExpand" HorizontalOptions="StartAndExpand"
VerticalOptions="CenterAndExpand" VerticalOptions="CenterAndExpand"
@ -60,8 +42,7 @@
<pages:GroupingsPageListItemSelector x:Key="listItemDataTemplateSelector" <pages:GroupingsPageListItemSelector x:Key="listItemDataTemplateSelector"
CipherTemplate="{StaticResource cipherTemplate}" CipherTemplate="{StaticResource cipherTemplate}"
FolderTemplate="{StaticResource folderTemplate}" GroupTemplate="{StaticResource groupTemplate}" />
CollectionTemplate="{StaticResource collectionTemplate}" />
</ResourceDictionary> </ResourceDictionary>
</ContentPage.Resources> </ContentPage.Resources>
<StackLayout x:Name="_mainLayout"> <StackLayout x:Name="_mainLayout">

View File

@ -90,6 +90,10 @@ namespace Bit.App.Pages
{ {
await _viewModel.SelectCollectionAsync(item.Collection); await _viewModel.SelectCollectionAsync(item.Collection);
} }
else if(item.Type != null)
{
await _viewModel.SelectTypeAsync(item.Type.Value);
}
} }
} }
} }

View File

@ -4,6 +4,10 @@ namespace Bit.App.Pages
{ {
public class GroupingsPageListGroup : List<GroupingsPageListItem> public class GroupingsPageListGroup : List<GroupingsPageListItem>
{ {
public GroupingsPageListGroup(string name, bool doUpper = true)
: this(new List<GroupingsPageListItem>(), name, doUpper)
{ }
public GroupingsPageListGroup(List<GroupingsPageListItem> groupItems, string name, bool doUpper = true) public GroupingsPageListGroup(List<GroupingsPageListItem> groupItems, string name, bool doUpper = true)
{ {
AddRange(groupItems); AddRange(groupItems);

View File

@ -1,14 +1,59 @@
using Bit.Core.Models.View; using Bit.App.Resources;
using Bit.Core.Enums;
using Bit.Core.Models.View;
namespace Bit.App.Pages namespace Bit.App.Pages
{ {
public class GroupingsPageListItem public class GroupingsPageListItem
{ {
private string _icon; private string _icon;
private string _name;
public FolderView Folder { get; set; } public FolderView Folder { get; set; }
public CollectionView Collection { get; set; } public CollectionView Collection { get; set; }
public CipherView Cipher { get; set; } public CipherView Cipher { get; set; }
public CipherType? Type { get; set; }
public string Name
{
get
{
if(_name != null)
{
return _name;
}
if(Folder != null)
{
_name = Folder.Name;
}
else if(Collection != null)
{
_name = Collection.Name;
}
else if(Type != null)
{
switch(Type.Value)
{
case CipherType.Login:
_name = AppResources.TypeLogin;
break;
case CipherType.SecureNote:
_name = AppResources.TypeSecureNote;
break;
case CipherType.Card:
_name = AppResources.TypeCard;
break;
case CipherType.Identity:
_name = AppResources.TypeIdentity;
break;
default:
break;
}
}
return _name;
}
}
public string Icon public string Icon
{ {
get get
@ -25,6 +70,27 @@ namespace Bit.App.Pages
{ {
_icon = ""; _icon = "";
} }
else if(Type != null)
{
switch(Type.Value)
{
case CipherType.Login:
_icon = "";
break;
case CipherType.SecureNote:
_icon = "";
break;
case CipherType.Card:
_icon = "";
break;
case CipherType.Identity:
_icon = "";
break;
default:
_icon = "";
break;
}
}
return _icon; return _icon;
} }
} }

View File

@ -5,22 +5,13 @@ namespace Bit.App.Pages
public class GroupingsPageListItemSelector : DataTemplateSelector public class GroupingsPageListItemSelector : DataTemplateSelector
{ {
public DataTemplate CipherTemplate { get; set; } public DataTemplate CipherTemplate { get; set; }
public DataTemplate FolderTemplate { get; set; } public DataTemplate GroupTemplate { get; set; }
public DataTemplate CollectionTemplate { get; set; }
protected override DataTemplate OnSelectTemplate(object item, BindableObject container) protected override DataTemplate OnSelectTemplate(object item, BindableObject container)
{ {
if(item is GroupingsPageListItem listItem) if(item is GroupingsPageListItem listItem)
{ {
if(listItem.Collection != null) return listItem.Cipher != null ? CipherTemplate : GroupTemplate;
{
return CollectionTemplate;
}
else if(listItem.Folder != null)
{
return FolderTemplate;
}
return CipherTemplate;
} }
return null; return null;
} }

View File

@ -125,6 +125,17 @@ namespace Bit.App.Pages
groupedItems.Add(new GroupingsPageListGroup(favListItems, AppResources.Favorites, groupedItems.Add(new GroupingsPageListGroup(favListItems, AppResources.Favorites,
Device.RuntimePlatform == Device.iOS)); Device.RuntimePlatform == Device.iOS));
} }
if(MainPage)
{
groupedItems.Add(new GroupingsPageListGroup(
AppResources.Types, Device.RuntimePlatform == Device.iOS)
{
new GroupingsPageListItem { Type = CipherType.Login },
new GroupingsPageListItem { Type = CipherType.Card },
new GroupingsPageListItem { Type = CipherType.Identity },
new GroupingsPageListItem { Type = CipherType.SecureNote }
});
}
if(folderListItems?.Any() ?? false) if(folderListItems?.Any() ?? false)
{ {
groupedItems.Add(new GroupingsPageListGroup(folderListItems, AppResources.Folders, groupedItems.Add(new GroupingsPageListGroup(folderListItems, AppResources.Folders,
@ -158,10 +169,10 @@ namespace Bit.App.Pages
await Page.Navigation.PushModalAsync(new NavigationPage(page)); await Page.Navigation.PushModalAsync(new NavigationPage(page));
} }
public async Task SelectFolderAsync(CipherType type) public async Task SelectTypeAsync(CipherType type)
{ {
string title = null; string title = null;
switch(Type.Value) switch(type)
{ {
case CipherType.Login: case CipherType.Login:
title = AppResources.Logins; title = AppResources.Logins;

View File

@ -3219,6 +3219,15 @@ namespace Bit.App.Resources {
} }
} }
/// <summary>
/// Looks up a localized string similar to Types.
/// </summary>
public static string Types {
get {
return ResourceManager.GetString("Types", resourceCulture);
}
}
/// <summary> /// <summary>
/// Looks up a localized string similar to Secure Note. /// Looks up a localized string similar to Secure Note.
/// </summary> /// </summary>

View File

@ -1390,4 +1390,7 @@
<data name="PasswordHistory" xml:space="preserve"> <data name="PasswordHistory" xml:space="preserve">
<value>Password History</value> <value>Password History</value>
</data> </data>
<data name="Types" xml:space="preserve">
<value>Types</value>
</data>
</root> </root>

View File

@ -62,7 +62,7 @@
<Style TargetType="StackLayout" <Style TargetType="StackLayout"
Class="list-row"> Class="list-row">
<Setter Property="Padding" <Setter Property="Padding"
Value="12" /> Value="10, 12" />
</Style> </Style>
<Style TargetType="Grid" <Style TargetType="Grid"
Class="list-row"> Class="list-row">
@ -90,8 +90,14 @@
<Style TargetType="Label" <Style TargetType="Label"
Class="list-icon" Class="list-icon"
ApplyToDerivedTypes="True"> ApplyToDerivedTypes="True">
<Setter Property="Margin" <Setter Property="WidthRequest"
Value="3, 3, 3, 0" /> Value="26" />
<Setter Property="HeightRequest"
Value="26" />
<Setter Property="HorizontalTextAlignment"
Value="Center" />
<Setter Property="VerticalTextAlignment"
Value="Center" />
<Setter Property="FontSize" <Setter Property="FontSize"
Value="Large" /> Value="Large" />
<Setter Property="TextColor" <Setter Property="TextColor"