1
0
mirror of https://github.com/bitwarden/mobile.git synced 2024-11-23 11:45:38 +01:00

theming with resource dictionary

This commit is contained in:
Kyle Spearrin 2019-04-22 11:32:17 -04:00
parent a6cd16cdb5
commit b48c231500
19 changed files with 302 additions and 18 deletions

View File

@ -27,6 +27,9 @@
<Compile Update="Pages\GeneratorPage.xaml.cs">
<DependentUpon>GeneratorPage.xaml</DependentUpon>
</Compile>
<Compile Update="Pages\ViewPage.xaml.cs">
<DependentUpon>ViewPage.xaml</DependentUpon>
</Compile>
<Compile Update="Pages\SettingsPage.xaml.cs">
<DependentUpon>SettingsPage.xaml</DependentUpon>
</Compile>
@ -54,6 +57,18 @@
<DesignTime>True</DesignTime>
<AutoGen>True</AutoGen>
</Compile>
<Compile Update="Styles\Light.xaml.cs">
<DependentUpon>Light.xaml</DependentUpon>
</Compile>
<Compile Update="Styles\Dark.xaml.cs">
<DependentUpon>Dark.xaml</DependentUpon>
</Compile>
<Compile Update="Styles\iOS.xaml.cs">
<DependentUpon>iOS.xaml</DependentUpon>
</Compile>
<Compile Update="Styles\Android.xaml.cs">
<DependentUpon>Android.xaml</DependentUpon>
</Compile>
</ItemGroup>
<ItemGroup>
@ -61,6 +76,9 @@
<LastGenOutput>AppResources.Designer.cs</LastGenOutput>
<Generator>ResXFileCodeGenerator</Generator>
</EmbeddedResource>
<EmbeddedResource Update="Styles\Base.xaml">
<Generator>MSBuild:UpdateDesignTimeXaml</Generator>
</EmbeddedResource>
</ItemGroup>
<Target Name="PreBuild" BeforeTargets="PreBuildEvent">

View File

@ -29,7 +29,8 @@ namespace Bit.App
InitializeComponent();
SetCulture();
ThemeManager.SetTheme("light");
// ThemeManager.SetTheme("light");
ThemeManager.SetThemeStyle("light");
MainPage = new HomePage();
var mainPageTask = SetMainPageAsync();

View File

@ -6,15 +6,16 @@
<ViewCell.View>
<StackLayout x:Name="_layout"
Padding="10"
x:DataType="controls:CipherViewCellViewModel">
x:DataType="controls:CipherViewCellViewModel"
StyleClass="list-row">
<StackLayout.BindingContext>
<controls:CipherViewCellViewModel />
</StackLayout.BindingContext>
<Label Text="{Binding Cipher.Name}"
LineBreakMode="NoWrap"
FontSize="16" />
<Label Text="{Binding Cipher.Name, Mode=OneWay}"
StyleClass="list-title" />
<Label Text="{Binding Cipher.SubTitle, Mode=OneWay}"
StyleClass="list-subtitle" />
</StackLayout>
</ViewCell.View>

View File

@ -21,14 +21,17 @@
<DataTemplate x:Key="folderTemplate"
x:DataType="pages:GroupingsPageListItem">
<ViewCell>
<StackLayout StyleClass="list-cell">
<StackLayout Orientation="Horizontal"
StyleClass="list-row">
<controls:FaLabel Text="&#xf07c;"
HorizontalOptions="Start"
VerticalOptions="CenterAndExpand" />
<Label Text="{Binding Folder.Name}"
VerticalOptions="CenterAndExpand"
StyleClass="list-icon" />
<Label Text="{Binding Folder.Name, Mode=OneWay}"
LineBreakMode="TailTruncation"
HorizontalOptions="StartAndExpand"
VerticalOptions="CenterAndExpand" />
VerticalOptions="CenterAndExpand"
StyleClass="list-title"/>
</StackLayout>
</ViewCell>
</DataTemplate>
@ -36,14 +39,17 @@
<DataTemplate x:Key="collectionTemplate"
x:DataType="pages:GroupingsPageListItem">
<ViewCell>
<StackLayout StyleClass="list-cell">
<StackLayout Orientation="Horizontal"
StyleClass="list-row">
<controls:FaLabel Text="&#xf1b2;"
HorizontalOptions="Start"
VerticalOptions="CenterAndExpand" />
<Label Text="{Binding Collection.Name}"
VerticalOptions="CenterAndExpand"
StyleClass="list-icon" />
<Label Text="{Binding Collection.Name, Mode=OneWay}"
LineBreakMode="TailTruncation"
HorizontalOptions="StartAndExpand"
VerticalOptions="CenterAndExpand" />
VerticalOptions="CenterAndExpand"
StyleClass="list-title"/>
</StackLayout>
</ViewCell>
</DataTemplate>
@ -65,11 +71,15 @@
IsRefreshing="{Binding Loading, Mode=OneWay}"
CachingStrategy="RecycleElement"
ItemTemplate="{StaticResource listItemDataTemplateSelector}"
IsGroupingEnabled="True">
IsGroupingEnabled="True"
StyleClass="list">
<ListView.GroupHeaderTemplate>
<DataTemplate x:DataType="pages:GroupingsPageListGroup">
<ViewCell>
<Label Text="{Binding Name}" />
<StackLayout StyleClass="list-row-header">
<Label Text="{Binding Name}"
StyleClass="list-header, list-header-themed, list-header-platform" />
</StackLayout>
</ViewCell>
</DataTemplate>
</ListView.GroupHeaderTemplate>

View File

@ -0,0 +1,31 @@
<?xml version="1.0" encoding="utf-8" ?>
<ContentPage
xmlns="http://xamarin.com/schemas/2014/forms"
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
x:Class="Bit.App.Pages.ViewPage"
xmlns:pages="clr-namespace:Bit.App.Pages"
xmlns:i18n="clr-namespace:Bit.App.Utilities"
xmlns:bv="clr-namespace:Bit.App.Controls.BoxedView"
x:DataType="pages:ViewPageViewModel"
Title="{Binding PageTitle}">
<ContentPage.BindingContext>
<pages:ViewPageViewModel />
</ContentPage.BindingContext>
<ContentPage.ToolbarItems>
<ToolbarItem Icon="cogs.png" Text="{i18n:Translate Edit}" />
</ContentPage.ToolbarItems>
<bv:BoxedView HasUnevenRows="True">
<bv:BoxedSection HeaderHeight="0">
<bv:EntryCell Title="{i18n:Translate EmailAddress}"
ValueText="{Binding Email}" />
<bv:EntryCell Title="{i18n:Translate MasterPassword}"
ValueText="{Binding MasterPassword}"
IsPassword="True"
Button1Icon="cogs"
Button1Command="{Binding ShowPasswordCommand}" />
</bv:BoxedSection>
</bv:BoxedView>
</ContentPage>

View File

@ -0,0 +1,22 @@
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 ViewPage : ContentPage
{
private ViewPageViewModel _vm;
public ViewPage()
{
InitializeComponent();
_vm = BindingContext as ViewPageViewModel;
_vm.Page = this;
}
}
}

View File

@ -0,0 +1,33 @@
using Bit.App.Abstractions;
using Bit.App.Resources;
using Bit.Core.Abstractions;
using Bit.Core.Exceptions;
using Bit.Core.Utilities;
using System.Threading.Tasks;
using System.Windows.Input;
using Xamarin.Forms;
namespace Bit.App.Pages
{
public class ViewPageViewModel : BaseViewModel
{
private readonly IDeviceActionService _deviceActionService;
private readonly IAuthService _authService;
private readonly ISyncService _syncService;
public ViewPageViewModel()
{
_deviceActionService = ServiceContainer.Resolve<IDeviceActionService>("deviceActionService");
_authService = ServiceContainer.Resolve<IAuthService>("authService");
_syncService = ServiceContainer.Resolve<ISyncService>("syncService");
PageTitle = AppResources.Bitwarden;
ShowPasswordCommand = new Command(() =>
Page.DisplayAlert("Button 1 Command", "Button 1 message", "Cancel"));
}
public ICommand ShowPasswordCommand { get; }
public string Email { get; set; }
public string MasterPassword { get; set; }
}
}

View File

@ -0,0 +1,9 @@
<?xml version="1.0" encoding="utf-8" ?>
<ResourceDictionary xmlns="http://xamarin.com/schemas/2014/forms"
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
x:Class="Bit.App.Styles.Android">
<Style TargetType="Label"
Class="list-header-platform">
</Style>
</ResourceDictionary>

View File

@ -0,0 +1,12 @@
using Xamarin.Forms;
namespace Bit.App.Styles
{
public partial class Android : ResourceDictionary
{
public Android()
{
InitializeComponent();
}
}
}

41
src/App/Styles/Base.xaml Normal file
View File

@ -0,0 +1,41 @@
<?xml version="1.0" encoding="utf-8" ?>
<ResourceDictionary xmlns="http://xamarin.com/schemas/2014/forms"
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
x:Class="Bit.App.Styles.Base">
<Style TargetType="ListView"
Class="list">
<Setter Property="SeparatorColor"
Value="Transparent" />
</Style>
<Style TargetType="StackLayout"
Class="list-row-header">
<Setter Property="Padding"
Value="10" />
</Style>
<Style TargetType="Label"
Class="list-header">
<Setter Property="FontSize"
Value="Medium" />
</Style>
<Style TargetType="StackLayout"
Class="list-row">
<Setter Property="Padding"
Value="10" />
</Style>
<Style TargetType="Label"
Class="list-title">
<Setter Property="FontSize"
Value="Medium" />
</Style>
<Style TargetType="Label"
Class="list-subtitle">
<Setter Property="FontSize"
Value="Small" />
</Style>
<Style TargetType="Label"
Class="list-icon"
ApplyToDerivedTypes="True">
<Setter Property="FontSize"
Value="Medium" />
</Style>
</ResourceDictionary>

View File

@ -0,0 +1,12 @@
using Xamarin.Forms;
namespace Bit.App.Styles
{
public partial class Base : ResourceDictionary
{
public Base()
{
InitializeComponent();
}
}
}

10
src/App/Styles/Dark.xaml Normal file
View File

@ -0,0 +1,10 @@
<?xml version="1.0" encoding="utf-8" ?>
<ResourceDictionary xmlns="http://xamarin.com/schemas/2014/forms"
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
x:Class="Bit.App.Styles.Dark">
<Style TargetType="Label"
Class="list-header-themed">
<Setter Property="TextColor"
Value="Green" />
</Style>
</ResourceDictionary>

View File

@ -0,0 +1,12 @@
using Xamarin.Forms;
namespace Bit.App.Styles
{
public partial class Dark : ResourceDictionary
{
public Dark()
{
InitializeComponent();
}
}
}

10
src/App/Styles/Light.xaml Normal file
View File

@ -0,0 +1,10 @@
<?xml version="1.0" encoding="utf-8" ?>
<ResourceDictionary xmlns="http://xamarin.com/schemas/2014/forms"
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
x:Class="Bit.App.Styles.Light">
<Style TargetType="Label"
Class="list-header-themed">
<Setter Property="TextColor"
Value="Blue" />
</Style>
</ResourceDictionary>

View File

@ -0,0 +1,12 @@
using Xamarin.Forms;
namespace Bit.App.Styles
{
public partial class Light : ResourceDictionary
{
public Light()
{
InitializeComponent();
}
}
}

6
src/App/Styles/iOS.xaml Normal file
View File

@ -0,0 +1,6 @@
<?xml version="1.0" encoding="utf-8" ?>
<ResourceDictionary xmlns="http://xamarin.com/schemas/2014/forms"
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
x:Class="Bit.App.Styles.iOS">
</ResourceDictionary>

View File

@ -0,0 +1,12 @@
using Xamarin.Forms;
namespace Bit.App.Styles
{
public partial class iOS : ResourceDictionary
{
public iOS()
{
InitializeComponent();
}
}
}

View File

@ -1,4 +1,6 @@
using System.Reflection;
using Bit.App.Styles;
using System;
using System.Reflection;
using Xamarin.Forms;
using Xamarin.Forms.StyleSheets;
@ -21,5 +23,35 @@ namespace Bit.App.Utilities
Application.Current.Resources.Add(StyleSheet.FromAssemblyResource(assembly,
string.Format(themeFormat, "styles")));
}
public static void SetThemeStyle(string name)
{
// Reset styles
Application.Current.Resources.Clear();
Application.Current.Resources.MergedDictionaries.Clear();
// Base styles
Application.Current.Resources.MergedDictionaries.Add(new Base());
// Platform styles
if(Device.RuntimePlatform == Device.Android)
{
Application.Current.Resources.MergedDictionaries.Add(new Android());
}
else if(Device.RuntimePlatform == Device.iOS)
{
Application.Current.Resources.MergedDictionaries.Add(new iOS());
}
// Theme styles
if(name == "dark")
{
Application.Current.Resources.MergedDictionaries.Add(new Dark());
}
else
{
Application.Current.Resources.MergedDictionaries.Add(new Light());
}
}
}
}

View File

@ -45,7 +45,7 @@ namespace Bit.Core.Models.View
public DateTime RevisionDate { get; set; }
public string Subtitle
public string SubTitle
{
get
{