Skip to content

Commit

Permalink
Merge pull request #663 from NickvisionApps/space
Browse files Browse the repository at this point in the history
Amount Display Style Option in Custom Currency
  • Loading branch information
nlogozzo authored Aug 24, 2023
2 parents 0604b23 + 64d1d24 commit 5cdafee
Show file tree
Hide file tree
Showing 112 changed files with 6,033 additions and 4,916 deletions.
7 changes: 7 additions & 0 deletions NickvisionMoney.GNOME/Blueprints/account_settings_dialog.blp
Original file line number Diff line number Diff line change
Expand Up @@ -174,6 +174,13 @@ Adw.Window _root {
Adw.EntryRow _customCodeRow {
title: _("Currency Code");
}

Adw.ComboRow _customAmountStyleRow {
title: _("Amount Display Style");
model: Gtk.StringList {
strings ["$100", "100$", "$ 100", "100 $"]
};
}

Adw.ComboRow _customDecimalSeparatorRow {
title: _("Decimal Separator");
Expand Down
7 changes: 7 additions & 0 deletions NickvisionMoney.GNOME/Blueprints/new_account_dialog.blp
Original file line number Diff line number Diff line change
Expand Up @@ -240,6 +240,13 @@ Adw.Window _root {
Adw.EntryRow _customCodeRow {
title: _("Currency Code");
}

Adw.ComboRow _customAmountStyleRow {
title: _("Amount Display Style");
model: Gtk.StringList {
strings ["$100", "100$", "$ 100", "100 $"]
};
}

Adw.ComboRow _customDecimalSeparatorRow {
title: _("Decimal Separator");
Expand Down
1 change: 1 addition & 0 deletions NickvisionMoney.GNOME/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ public Program(string[] args)
_mainWindowController = new MainWindowController(args);
_mainWindowController.AppInfo.Changelog =
@"* Added a password strength indicator when creating an account password
* Added an Amount Display Style option to custom currency settings
* Fixed an issue where selecting the current month on an empty account in the calendar would cause a crash
* Fixed an issue where adding receipts to a new transaction would cause a crash
* Improved UI/UX
Expand Down
23 changes: 20 additions & 3 deletions NickvisionMoney.GNOME/Views/AccountSettingsDialog.cs
Original file line number Diff line number Diff line change
Expand Up @@ -29,10 +29,11 @@ public partial class AccountSettingsDialog : Adw.Window
[Gtk.Connect] private readonly Gtk.Switch _switchCustomCurrency;
[Gtk.Connect] private readonly Adw.EntryRow _customSymbolRow;
[Gtk.Connect] private readonly Adw.EntryRow _customCodeRow;
[Gtk.Connect] private readonly Gtk.Entry _customDecimalSeparatorText;
[Gtk.Connect] private readonly Adw.ComboRow _customAmountStyleRow;
[Gtk.Connect] private readonly Adw.ComboRow _customDecimalSeparatorRow;
[Gtk.Connect] private readonly Gtk.Entry _customGroupSeparatorText;
[Gtk.Connect] private readonly Gtk.Entry _customDecimalSeparatorText;
[Gtk.Connect] private readonly Adw.ComboRow _customGroupSeparatorRow;
[Gtk.Connect] private readonly Gtk.Entry _customGroupSeparatorText;
[Gtk.Connect] private readonly Adw.ComboRow _customDecimalDigitsRow;
[Gtk.Connect] private readonly Adw.ActionRow _managePasswordRow;
[Gtk.Connect] private readonly Gtk.Label _lblPasswordStatus;
Expand Down Expand Up @@ -163,6 +164,16 @@ private AccountSettingsDialog(Gtk.Builder builder, AccountSettingsDialogControll
}
}
};
_customAmountStyleRow.OnNotify += (sender, e) =>
{
if (e.Pspec.GetName() == "selected")
{
if (!_constructing)
{
Validate();
}
}
};
_customDecimalSeparatorRow.OnNotify += (sender, e) =>
{
if (e.Pspec.GetName() == "selected")
Expand Down Expand Up @@ -279,6 +290,7 @@ private AccountSettingsDialog(Gtk.Builder builder, AccountSettingsDialogControll
_switchCustomCurrency.SetActive(_controller.Metadata.UseCustomCurrency);
_customSymbolRow.SetText(_controller.Metadata.CustomCurrencySymbol ?? "");
_customCodeRow.SetText(_controller.Metadata.CustomCurrencyCode ?? "");
_customAmountStyleRow.SetSelected(_controller.Metadata.CustomCurrencyAmountStyle.HasValue ? (uint)_controller.Metadata.CustomCurrencyAmountStyle.Value : 0u);
_customDecimalSeparatorRow.SetSelected(_controller.Metadata.CustomCurrencyDecimalSeparator switch
{
null => 0,
Expand Down Expand Up @@ -347,7 +359,7 @@ private void Validate()
4 => _customGroupSeparatorText.GetText()
};
var customDecimalDigits = _customDecimalDigitsRow.GetSelected() == 5 ? 99 : _customDecimalDigitsRow.GetSelected() + 2;
var checkStatus = _controller.UpdateMetadata(_nameRow.GetText(), (AccountType)_accountTypeRow.GetSelected(), _switchCustomCurrency.GetActive(), _customSymbolRow.GetText(), _customCodeRow.GetText(), customDecimalSeparator, customGroupSeparator, customDecimalDigits, transactionType, (RemindersThreshold)_transactionRemindersRow.GetSelected(), _newPasswordRow.GetText(), _newPasswordConfirmRow.GetText());
var checkStatus = _controller.UpdateMetadata(_nameRow.GetText(), (AccountType)_accountTypeRow.GetSelected(), _switchCustomCurrency.GetActive(), _customSymbolRow.GetText(), _customCodeRow.GetText(), (int?)_customAmountStyleRow.GetSelected(), customDecimalSeparator, customGroupSeparator, (int?)customDecimalDigits, transactionType, (RemindersThreshold)_transactionRemindersRow.GetSelected(), _newPasswordRow.GetText(), _newPasswordConfirmRow.GetText());
_nameRow.RemoveCssClass("error");
_nameRow.SetTitle(_("Name"));
_customCurrencyRow.RemoveCssClass("error");
Expand All @@ -363,7 +375,12 @@ private void Validate()
_lblPasswordStatus.SetText("");
if (checkStatus == AccountMetadataCheckStatus.Valid)
{
_constructing = true;
var oldSelection = _customAmountStyleRow.GetSelected();
_customAmountStyleRow.SetModel(Gtk.StringList.New(_controller.CustomCurrencyAmountStyleStrings!));
_customAmountStyleRow.SetSelected(oldSelection);
_applyButton.SetSensitive(true);
_constructing = false;
}
else
{
Expand Down
21 changes: 20 additions & 1 deletion NickvisionMoney.GNOME/Views/NewAccountDialog.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ namespace NickvisionMoney.GNOME.Views;
public partial class NewAccountDialog : Adw.Window
{
private readonly NewAccountDialogController _controller;
private bool _constructing = false;
private uint _currentPageNumber;

[Gtk.Connect] private readonly Gtk.Button _backButton;
Expand All @@ -38,6 +39,7 @@ public partial class NewAccountDialog : Adw.Window
[Gtk.Connect] private readonly Adw.ExpanderRow _rowCustomCurrency;
[Gtk.Connect] private readonly Adw.EntryRow _customSymbolRow;
[Gtk.Connect] private readonly Adw.EntryRow _customCodeRow;
[Gtk.Connect] private readonly Adw.ComboRow _customAmountStyleRow;
[Gtk.Connect] private readonly Gtk.Entry _customDecimalSeparatorText;
[Gtk.Connect] private readonly Adw.ComboRow _customDecimalSeparatorRow;
[Gtk.Connect] private readonly Gtk.Entry _customGroupSeparatorText;
Expand All @@ -60,6 +62,7 @@ public partial class NewAccountDialog : Adw.Window
private NewAccountDialog(Gtk.Builder builder, NewAccountDialogController controller, Gtk.Window parent) : base(builder.GetPointer("_root"), false)
{
_controller = controller;
_constructing = true;
_currentPageNumber = 0;
//Dialog Settings
SetTransientFor(parent);
Expand Down Expand Up @@ -134,6 +137,16 @@ private NewAccountDialog(Gtk.Builder builder, NewAccountDialogController control
ValidateCurrency();
}
};
_customAmountStyleRow.OnNotify += (sender, e) =>
{
if (e.Pspec.GetName() == "selected")
{
if (!_constructing)
{
ValidateCurrency();
}
}
};
_customDecimalSeparatorRow.SetSelected(0);
_customDecimalSeparatorRow.OnNotify += (sender, e) =>
{
Expand Down Expand Up @@ -212,6 +225,7 @@ private NewAccountDialog(Gtk.Builder builder, NewAccountDialogController control
_incomeButton.SetActive(true);
_transactionRemindersRow.SetSelected(0);
_reportedCurrencyLabel.SetLabel($"{_("Your system reported that your currency is")}\n<b>{_controller.ReportedCurrencyString}</b>");
_constructing = false;
}

/// <summary>
Expand Down Expand Up @@ -363,10 +377,15 @@ private void ValidateCurrency()
_customDecimalSeparatorRow.SetTitle(_("Decimal Separator"));
_customGroupSeparatorRow.RemoveCssClass("error");
_customGroupSeparatorRow.SetTitle(_("Group Separator"));
var checkStatus = _controller.UpdateCurrency(_rowCustomCurrency.GetExpanded(), _customSymbolRow.GetText(), _customCodeRow.GetText(), customDecimalSeparator, customGroupSeparator, customDecimalDigits);
var checkStatus = _controller.UpdateCurrency(_rowCustomCurrency.GetExpanded(), _customSymbolRow.GetText(), _customCodeRow.GetText(), (int?)_customAmountStyleRow.GetSelected(), customDecimalSeparator, customGroupSeparator, (int?)customDecimalDigits);
if (checkStatus == CurrencyCheckStatus.Valid)
{
_constructing = true;
var oldSelection = _customAmountStyleRow.GetSelected();
_customAmountStyleRow.SetModel(Gtk.StringList.New(_controller.CustomCurrencyAmountStyleStrings!));
_customAmountStyleRow.SetSelected(oldSelection);
_createButton.SetSensitive(true);
_constructing = false;
}
else
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -84,19 +84,18 @@ public string ReportedCurrencyString
}

/// <summary>
/// Gets a color for an account type
/// Strings to show for a custom currency's amount styles if available
/// </summary>
/// <param name="accountType">The account type</param>
/// <returns>The rgb color for the account type</returns>
public string GetColorForAccountType(AccountType accountType)
public string[]? CustomCurrencyAmountStyleStrings
{
return accountType switch
get
{
AccountType.Checking => Configuration.Current.AccountCheckingColor,
AccountType.Savings => Configuration.Current.AccountSavingsColor,
AccountType.Business => Configuration.Current.AccountBusinessColor,
_ => Configuration.Current.AccountSavingsColor
};
if (Metadata.CustomCurrencySymbol != null)
{
return new string[] { $"{Metadata.CustomCurrencySymbol}100", $"100{Metadata.CustomCurrencySymbol}", $"{Metadata.CustomCurrencySymbol} 100", $"100 {Metadata.CustomCurrencySymbol}" };
}
return null;
}
}

/// <summary>
Expand All @@ -107,6 +106,7 @@ public string GetColorForAccountType(AccountType accountType)
/// <param name="useCustom">Whether or not to use a custom currency</param>
/// <param name="customSymbol">The new custom currency symbol</param>
/// <param name="customCode">The new custom currency code</param>
/// <param name="customAmountStyle">The new custom currency amount style</param>
/// <param name="customDecimalSeparator">The new custom decimal separator</param>
/// <param name="customGroupSeparator">The new custom group separator</param>
/// <param name="customDecimalDigits">The new custom decimal digits number</param>
Expand All @@ -115,7 +115,7 @@ public string GetColorForAccountType(AccountType accountType)
/// <param name="newPassword">The new password</param>
/// <param name="confirmPassword">The new password confirmed</param>
/// <returns>AccountMetadataCheckStatus</returns>
public AccountMetadataCheckStatus UpdateMetadata(string name, AccountType type, bool useCustom, string? customSymbol, string? customCode, string? customDecimalSeparator, string? customGroupSeparator, uint customDecimalDigits, TransactionType defaultTransactionType, RemindersThreshold transactionReminder, string newPassword, string confirmPassword)
public AccountMetadataCheckStatus UpdateMetadata(string name, AccountType type, bool useCustom, string? customSymbol, string? customCode, int? customAmountStyle, string? customDecimalSeparator, string? customGroupSeparator, int? customDecimalDigits, TransactionType defaultTransactionType, RemindersThreshold transactionReminder, string newPassword, string confirmPassword)
{
AccountMetadataCheckStatus result = 0;
if (string.IsNullOrEmpty(name))
Expand All @@ -126,8 +126,7 @@ public AccountMetadataCheckStatus UpdateMetadata(string name, AccountType type,
{
result |= AccountMetadataCheckStatus.EmptyCurrencySymbol;
}
decimal symbolAsNumber;
if (useCustom && !string.IsNullOrEmpty(customSymbol) && Decimal.TryParse(customSymbol, out symbolAsNumber))
if (useCustom && !string.IsNullOrEmpty(customSymbol) && Decimal.TryParse(customSymbol, out _))
{
result |= AccountMetadataCheckStatus.InvalidCurrencySymbol;
}
Expand Down Expand Up @@ -174,14 +173,16 @@ public AccountMetadataCheckStatus UpdateMetadata(string name, AccountType type,
{
Metadata.CustomCurrencySymbol = customSymbol;
Metadata.CustomCurrencyCode = customCode?.ToUpper();
Metadata.CustomCurrencyAmountStyle = customAmountStyle;
Metadata.CustomCurrencyDecimalSeparator = customDecimalSeparator;
Metadata.CustomCurrencyGroupSeparator = customGroupSeparator;
Metadata.CustomCurrencyDecimalDigits = (int?)customDecimalDigits;
Metadata.CustomCurrencyDecimalDigits = customDecimalDigits;
}
else
{
Metadata.CustomCurrencySymbol = null;
Metadata.CustomCurrencyCode = null;
Metadata.CustomCurrencyAmountStyle = null;
Metadata.CustomCurrencyDecimalSeparator = null;
Metadata.CustomCurrencyGroupSeparator = null;
Metadata.CustomCurrencyDecimalDigits = null;
Expand Down
3 changes: 2 additions & 1 deletion NickvisionMoney.Shared/Controllers/AccountViewController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -587,6 +587,7 @@ public void SetPassword(string password, bool showNotification = true)
public void UpdateMetadata(AccountMetadata metadata)
{
var oldSymbol = _account.Metadata.CustomCurrencySymbol;
var oldStyle = _account.Metadata.CustomCurrencyAmountStyle;
var oldDecimalSeparator = _account.Metadata.CustomCurrencyDecimalSeparator;
var oldGroupSeparator = _account.Metadata.CustomCurrencyGroupSeparator;
var oldDecimalDigits = _account.Metadata.CustomCurrencyDecimalDigits;
Expand All @@ -598,7 +599,7 @@ public void UpdateMetadata(AccountMetadata metadata)
});
Aura.Active.SaveConfig("config");
RecentAccountsChanged?.Invoke(this, EventArgs.Empty);
if (oldSymbol != metadata.CustomCurrencySymbol || oldDecimalSeparator != metadata.CustomCurrencyDecimalSeparator || oldGroupSeparator != metadata.CustomCurrencyGroupSeparator || oldDecimalDigits != metadata.CustomCurrencyDecimalDigits)
if (oldSymbol != metadata.CustomCurrencySymbol || oldStyle != metadata.CustomCurrencyAmountStyle || oldDecimalSeparator != metadata.CustomCurrencyDecimalSeparator || oldGroupSeparator != metadata.CustomCurrencyGroupSeparator || oldDecimalDigits != metadata.CustomCurrencyDecimalDigits)
{
foreach (var pair in _account.Groups)
{
Expand Down
25 changes: 21 additions & 4 deletions NickvisionMoney.Shared/Controllers/NewAccountDialogController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,21 @@ public string ReportedCurrencyString
}
}

/// <summary>
/// Strings to show for a custom currency's amount styles if available
/// </summary>
public string[]? CustomCurrencyAmountStyleStrings
{
get
{
if (Metadata.CustomCurrencySymbol != null)
{
return new string[] { $"{Metadata.CustomCurrencySymbol}100", $"100{Metadata.CustomCurrencySymbol}", $"{Metadata.CustomCurrencySymbol} 100", $"100 {Metadata.CustomCurrencySymbol}" };
}
return null;
}
}

/// <summary>
/// Updates the account name
/// </summary>
Expand Down Expand Up @@ -139,19 +154,19 @@ public NameCheckStatus UpdateName(string name)
/// <param name="useCustom">Whether or not to use a custom currency</param>
/// <param name="customSymbol">The new custom currency symbol</param>
/// <param name="customCode">The new custom currency code</param>
/// <param name="customAmountStyle">The new custom currency amount style</param>
/// <param name="customDecimalSeparator">The new custom decimal separator</param>
/// <param name="customGroupSeparator">The new custom group separator</param>
/// <param name="customDecimalDigits">The new custom decimal digits number</param>
/// <returns>CurrencyCheckStatus</returns>
public CurrencyCheckStatus UpdateCurrency(bool useCustom, string? customSymbol, string? customCode, string? customDecimalSeparator, string? customGroupSeparator, uint customDecimalDigits)
public CurrencyCheckStatus UpdateCurrency(bool useCustom, string? customSymbol, string? customCode, int? customAmountStyle, string? customDecimalSeparator, string? customGroupSeparator, int? customDecimalDigits)
{
CurrencyCheckStatus result = 0;
if (useCustom && string.IsNullOrEmpty(customSymbol))
{
result |= CurrencyCheckStatus.EmptyCurrencySymbol;
}
decimal symbolAsNumber;
if (useCustom && !string.IsNullOrEmpty(customSymbol) && Decimal.TryParse(customSymbol, out symbolAsNumber))
if (useCustom && !string.IsNullOrEmpty(customSymbol) && Decimal.TryParse(customSymbol, out _))
{
result |= CurrencyCheckStatus.InvalidCurrencySymbol;
}
Expand Down Expand Up @@ -192,14 +207,16 @@ public CurrencyCheckStatus UpdateCurrency(bool useCustom, string? customSymbol,
{
Metadata.CustomCurrencySymbol = customSymbol;
Metadata.CustomCurrencyCode = customCode?.ToUpper();
Metadata.CustomCurrencyAmountStyle = customAmountStyle;
Metadata.CustomCurrencyDecimalSeparator = customDecimalSeparator;
Metadata.CustomCurrencyGroupSeparator = customGroupSeparator;
Metadata.CustomCurrencyDecimalDigits = (int?)customDecimalDigits;
Metadata.CustomCurrencyDecimalDigits = customDecimalDigits;
}
else
{
Metadata.CustomCurrencySymbol = null;
Metadata.CustomCurrencyCode = null;
Metadata.CustomCurrencyAmountStyle = null;
Metadata.CustomCurrencyDecimalSeparator = null;
Metadata.CustomCurrencyGroupSeparator = null;
Metadata.CustomCurrencyDecimalDigits = null;
Expand Down
10 changes: 10 additions & 0 deletions NickvisionMoney.Shared/Docs/html/C/account.html
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,16 @@
<p class="p">Up to 3 characters or 1 emoji.</p>
<p class="p">An example to understand the difference between a symbol and a code: <span class="em">$</span> is a symbol, <span class="em">USD</span> is a code.</p>
</dd>
<dt class="terms">Custom Currency Amount Style</dt>
<dd class="terms">
<p class="p">A choice of displaying an amount in one of the following ways: </p>
<div class="list"><div class="inner"><div class="region"><ul class="list">
<li class="list"><p class="p">$n</p></li>
<li class="list"><p class="p">n$</p></li>
<li class="list"><p class="p">$ n</p></li>
<li class="list"><p class="p">n $</p></li>
</ul></div></div></div>
</dd>
<dt class="terms">Custom Currency Decimal and Group Separators</dt>
<dd class="terms"><p class="p">Up to 2 characters or 1 emoji.</p></dd>
<dt class="terms">Custom Currency Decimal Digits</dt>
Expand Down
10 changes: 10 additions & 0 deletions NickvisionMoney.Shared/Docs/html/ar/account.html
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,16 @@
<p class="p">Up to 3 characters or 1 emoji.</p>
<p class="p">An example to understand the difference between a symbol and a code: <span class="em">$</span> is a symbol, <span class="em">USD</span> is a code.</p>
</dd>
<dt class="terms">Custom Currency Amount Style</dt>
<dd class="terms">
<p class="p">A choice of displaying an amount in one of the following ways: </p>
<div class="list"><div class="inner"><div class="region"><ul class="list">
<li class="list"><p class="p">$n</p></li>
<li class="list"><p class="p">n$</p></li>
<li class="list"><p class="p">$ n</p></li>
<li class="list"><p class="p">n $</p></li>
</ul></div></div></div>
</dd>
<dt class="terms">Custom Currency Decimal and Group Separators</dt>
<dd class="terms"><p class="p">Up to 2 characters or 1 emoji.</p></dd>
<dt class="terms">Custom Currency Decimal Digits</dt>
Expand Down
Loading

0 comments on commit 5cdafee

Please sign in to comment.