Skip to content

Commit

Permalink
Added the support of custom icons in categories (#27)
Browse files Browse the repository at this point in the history
  • Loading branch information
veler authored Nov 9, 2020
1 parent f9393fe commit 4a85154
Show file tree
Hide file tree
Showing 58 changed files with 1,095 additions and 243 deletions.
6 changes: 4 additions & 2 deletions Windows/Def/PaZword.Api/Data/IDataManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -117,18 +117,20 @@ public interface IDataManager : IDisposable
/// Adds a new category to the bundle.
/// </summary>
/// <param name="name">The category name.</param>
/// <param name="icon">The category icon.</param>
/// <param name="cancellationToken">A token to cancel the task.</param>
/// <returns>The created <see cref="Category"/>.</returns>
Task<Category> AddNewCategoryAsync(string name, CancellationToken cancellationToken);
Task<Category> AddNewCategoryAsync(string name, CategoryIcon icon, CancellationToken cancellationToken);

/// <summary>
/// Renames a category in the bundle.
/// </summary>
/// <param name="id">The category ID.</param>
/// <param name="name">The category name.</param>
/// <param name="icon">The category icon.</param>
/// <param name="cancellationToken">A token to cancel the task.</param>
/// <returns>A <see cref="Task"/> representing the asynchronous operation.</returns>
Task RenameCategoryAsync(Guid id, string name, CancellationToken cancellationToken);
Task RenameCategoryAsync(Guid id, string name, CategoryIcon icon, CancellationToken cancellationToken);

/// <summary>
/// Deletes a category from the bundle.
Expand Down
21 changes: 19 additions & 2 deletions Windows/Def/PaZword.Api/Models/Category.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ namespace PaZword.Api.Models
public sealed class Category : INotifyPropertyChanged, IExactEquatable<Category>
{
private string _name;
private CategoryIcon _categoryIcon;

/// <summary>
/// Gets the category's unique ID.
Expand All @@ -31,6 +32,20 @@ public string Name
}
}

/// <summary>
/// Gets or sets the category's icon.
/// </summary>
[JsonProperty]
public CategoryIcon Icon
{
get => _categoryIcon;
set
{
_categoryIcon = value;
PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(nameof(Icon)));
}
}

/// <summary>
/// Gets or sets when is the last time this category has changed.
/// </summary>
Expand All @@ -51,10 +66,11 @@ public Category()
/// </summary>
/// <param name="id">The unique ID of the category</param>
/// <param name="name">The category name</param>
public Category(Guid id, string name)
public Category(Guid id, string name, CategoryIcon icon)
{
Id = id;
Name = name;
Icon = icon;
}

public override bool Equals(object obj)
Expand Down Expand Up @@ -88,7 +104,8 @@ public bool ExactEquals(Category other)
return ReferenceEquals(this, other)
|| (other.Id == Id
&& other.LastModificationDate == LastModificationDate
&& string.Equals(other.Name, Name, StringComparison.Ordinal));
&& string.Equals(other.Name, Name, StringComparison.Ordinal))
&& other.Icon == Icon;
}

public override int GetHashCode()
Expand Down
24 changes: 24 additions & 0 deletions Windows/Def/PaZword.Api/Models/CategoryIcon.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
namespace PaZword.Api.Models
{
public enum CategoryIcon
{
Default,
Bank,
Bank2,
BankCard,
Home,
Id,
Id2,
Key,
Money,
Personal,
Personal2,
Professional,
Professional2,
Professional3,
Safe,
SocialMedia,
UserGroup,
UserGroup2
}
}
1 change: 1 addition & 0 deletions Windows/Def/PaZword.Api/PaZword.Api.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
<Compile Include="Models\Account.cs" />
<Compile Include="Models\AccountData.cs" />
<Compile Include="Models\Category.cs" />
<Compile Include="Models\CategoryIcon.cs" />
<Compile Include="Services\IIconService.cs" />
<Compile Include="Services\IRecurrentTask.cs" />
<Compile Include="Services\IRecurrentTaskService.cs" />
Expand Down
4 changes: 2 additions & 2 deletions Windows/Def/PaZword.Api/Properties/AssemblyInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,6 @@
// You can specify all the values or you can default the Build and Revision Numbers
// by using the '*' as shown below:
// [assembly: AssemblyVersion("1.0.*")]
[assembly: AssemblyVersion("2020.8.23.3")]
[assembly: AssemblyFileVersion("2020.8.23.3")]
[assembly: AssemblyVersion("2020.11.9.4")]
[assembly: AssemblyFileVersion("2020.11.9.4")]

8 changes: 8 additions & 0 deletions Windows/Def/PaZword.Api/UI/IWindowManager.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using System.Threading.Tasks;
using PaZword.Api.Models;
using Windows.UI.Xaml.Controls;

namespace PaZword.Api.UI
Expand Down Expand Up @@ -39,5 +40,12 @@ Task<string> ShowInputDialogAsync(
string primaryButtonText,
string defaultInputValue = null,
string title = null);

/// <summary>
/// Prompt a dialog to the user to add or rename a category.
/// </summary>
/// <param name="categoryToRename">Null when "Add a category" should be shown. Not null when renaming a category.</param>
/// <returns>Returns <code>True</code> if the user validated the prompt.</returns>
Task<(bool, string, CategoryIcon)> ShowAddOrRenameCategoryAsync(Category categoryToRename = null);
}
}
9 changes: 1 addition & 8 deletions Windows/Directory.Build.props
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
<WindowsXamlEnableOverview>true</WindowsXamlEnableOverview>

<CodeAnalysisRuleset>$(MSBuildThisFileDirectory)Analyzers.ruleset</CodeAnalysisRuleset>
<NoWarn>;2008;CA1822;</NoWarn>

<!-- Enable generation of .tt files -->
<TransformOnBuild>true</TransformOnBuild>
Expand All @@ -30,7 +31,6 @@
<DebugSymbols>true</DebugSymbols>
<OutputPath>bin\x86\Debug\</OutputPath>
<DefineConstants>DEBUG;TRACE;NETFX_CORE;WINDOWS_UWP</DefineConstants>
<NoWarn>;2008</NoWarn>
<DebugType>full</DebugType>
<PlatformTarget>x86</PlatformTarget>
<UseVSHostingProcess>false</UseVSHostingProcess>
Expand All @@ -41,7 +41,6 @@
<OutputPath>bin\x86\Release\</OutputPath>
<DefineConstants>TRACE;NETFX_CORE;WINDOWS_UWP</DefineConstants>
<Optimize>true</Optimize>
<NoWarn>;2008</NoWarn>
<DebugType>pdbonly</DebugType>
<PlatformTarget>x86</PlatformTarget>
<UseVSHostingProcess>false</UseVSHostingProcess>
Expand All @@ -53,7 +52,6 @@
<DebugSymbols>true</DebugSymbols>
<OutputPath>bin\ARM\Debug\</OutputPath>
<DefineConstants>DEBUG;TRACE;NETFX_CORE;WINDOWS_UWP</DefineConstants>
<NoWarn>;2008</NoWarn>
<DebugType>full</DebugType>
<PlatformTarget>ARM</PlatformTarget>
<UseVSHostingProcess>false</UseVSHostingProcess>
Expand All @@ -64,7 +62,6 @@
<OutputPath>bin\ARM\Release\</OutputPath>
<DefineConstants>TRACE;NETFX_CORE;WINDOWS_UWP</DefineConstants>
<Optimize>true</Optimize>
<NoWarn>;2008</NoWarn>
<DebugType>pdbonly</DebugType>
<PlatformTarget>ARM</PlatformTarget>
<UseVSHostingProcess>false</UseVSHostingProcess>
Expand All @@ -76,7 +73,6 @@
<DebugSymbols>true</DebugSymbols>
<OutputPath>bin\ARM64\Debug\</OutputPath>
<DefineConstants>DEBUG;TRACE;NETFX_CORE;WINDOWS_UWP</DefineConstants>
<NoWarn>;2008</NoWarn>
<DebugType>full</DebugType>
<PlatformTarget>ARM64</PlatformTarget>
<UseVSHostingProcess>false</UseVSHostingProcess>
Expand All @@ -88,7 +84,6 @@
<OutputPath>bin\ARM64\Release\</OutputPath>
<DefineConstants>TRACE;NETFX_CORE;WINDOWS_UWP</DefineConstants>
<Optimize>true</Optimize>
<NoWarn>;2008</NoWarn>
<DebugType>pdbonly</DebugType>
<PlatformTarget>ARM64</PlatformTarget>
<UseVSHostingProcess>false</UseVSHostingProcess>
Expand All @@ -100,7 +95,6 @@
<DebugSymbols>true</DebugSymbols>
<OutputPath>bin\x64\Debug\</OutputPath>
<DefineConstants>DEBUG;TRACE;NETFX_CORE;WINDOWS_UWP</DefineConstants>
<NoWarn>;2008</NoWarn>
<DebugType>full</DebugType>
<PlatformTarget>x64</PlatformTarget>
<UseVSHostingProcess>false</UseVSHostingProcess>
Expand All @@ -111,7 +105,6 @@
<OutputPath>bin\x64\Release\</OutputPath>
<DefineConstants>TRACE;NETFX_CORE;WINDOWS_UWP</DefineConstants>
<Optimize>true</Optimize>
<NoWarn>;2008</NoWarn>
<DebugType>pdbonly</DebugType>
<PlatformTarget>x64</PlatformTarget>
<UseVSHostingProcess>false</UseVSHostingProcess>
Expand Down
43 changes: 35 additions & 8 deletions Windows/Impl/PaZword.Core/Data/DataManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -299,7 +299,7 @@ public async Task SetBrownBagDataAsync(string name, string value, CancellationTo
}
}

public async Task<Category> AddNewCategoryAsync(string name, CancellationToken cancellationToken)
public async Task<Category> AddNewCategoryAsync(string name, CategoryIcon icon, CancellationToken cancellationToken)
{
Arguments.NotNullOrEmpty(name, nameof(name));

Expand All @@ -309,7 +309,7 @@ public async Task<Category> AddNewCategoryAsync(string name, CancellationToken c
CheckState();

Guid uniqueId = GenerateUniqueId();
category = new Category(uniqueId, name)
category = new Category(uniqueId, name, icon)
{
LastModificationDate = DateTime.Now
};
Expand All @@ -322,7 +322,7 @@ public async Task<Category> AddNewCategoryAsync(string name, CancellationToken c
return category;
}

public async Task RenameCategoryAsync(Guid id, string name, CancellationToken cancellationToken)
public async Task RenameCategoryAsync(Guid id, string name, CategoryIcon icon, CancellationToken cancellationToken)
{
Arguments.NotNull(id, nameof(id));
Arguments.NotNullOrEmpty(name, nameof(name));
Expand All @@ -342,6 +342,7 @@ public async Task RenameCategoryAsync(Guid id, string name, CancellationToken ca
await TaskHelper.RunOnUIThreadAsync(() =>
{
existingCategory.Name = name;
existingCategory.Icon = icon;
}).ConfigureAwait(false);

SortData();
Expand Down Expand Up @@ -643,11 +644,37 @@ private bool MergeUserDataBundle(UserDataBundle dataFromExternalSource)
private void CreateNewUserDataBundle()
{
_data = new UserDataBundle();
_data.Categories.Add(new Category(new Guid(Constants.CategoryAllId), LanguageManager.Instance.Core.CategoryAll));
_data.Categories.Add(new Category(GenerateUniqueId(), LanguageManager.Instance.Core.CategoryFinancial));
_data.Categories.Add(new Category(GenerateUniqueId(), LanguageManager.Instance.Core.CategoryPersonal));
_data.Categories.Add(new Category(GenerateUniqueId(), LanguageManager.Instance.Core.CategoryProfessional));
_data.Categories.Add(new Category(GenerateUniqueId(), LanguageManager.Instance.Core.CategorySocial));

// Add the default categories
_data.Categories.Add(
new Category(
new Guid(Constants.CategoryAllId),
LanguageManager.Instance.Core.CategoryAll,
CategoryIcon.Home));

_data.Categories.Add(
new Category(
GenerateUniqueId(),
LanguageManager.Instance.Core.CategoryFinancial,
CategoryIcon.BankCard));

_data.Categories.Add(
new Category(
GenerateUniqueId(),
LanguageManager.Instance.Core.CategoryPersonal,
CategoryIcon.Personal2));

_data.Categories.Add(
new Category(
GenerateUniqueId(),
LanguageManager.Instance.Core.CategoryProfessional,
CategoryIcon.Professional));

_data.Categories.Add(
new Category(
GenerateUniqueId(),
LanguageManager.Instance.Core.CategorySocial,
CategoryIcon.SocialMedia));

SortData();
}
Expand Down
Loading

0 comments on commit 4a85154

Please sign in to comment.