Skip to content

Commit

Permalink
Improved custom number format
Browse files Browse the repository at this point in the history
Added complete editing text action button in add transaction page
Fix line graph double currency icon in label
Fix currency exchange icon
  • Loading branch information
jameskokoska committed Mar 22, 2024
1 parent e508a2a commit 6402587
Show file tree
Hide file tree
Showing 19 changed files with 216 additions and 114 deletions.
9 changes: 4 additions & 5 deletions budget/assets/static/Convert.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,11 +24,10 @@
for currencyInfo in data2:
if (currencyInfo["Code"]).lower()==currency.lower():
found = True
result[currency] = {
"Currency": currencyInfo["Currency"],
"Code": currencyInfo["Code"],
"Symbol": currencyInfo["Symbol"],
}
result[currency] = {}
for key in ["Currency", "Code", "Symbol"]:
if key in currencyInfo:
result[currency][key] = currencyInfo[key]
if("CountryName" in currencyInfo):
result[currency]["CountryName"] = currencyInfo["CountryName"]
for country in countries:
Expand Down
3 changes: 1 addition & 2 deletions budget/assets/static/currenciesInfo.json
Original file line number Diff line number Diff line change
Expand Up @@ -764,8 +764,7 @@
"Flag": "https://www.currencyremitapp.com/wp-content/themes/currencyremitapp/images/countryimages/uzbekistan.png",
"CountryName": "Uzbekistan",
"Currency": "Som",
"Code": "UZS",
"Symbol": "лв"
"Code": "UZS"
},
{
"Flag": "https://www.currencyremitapp.com/wp-content/themes/currencyremitapp/images/countryimages/venezuela.png",
Expand Down
1 change: 0 additions & 1 deletion budget/assets/static/generated/currencies.json
Original file line number Diff line number Diff line change
Expand Up @@ -2605,7 +2605,6 @@
"uzs": {
"Currency": "Som",
"Code": "UZS",
"Symbol": "лв",
"CountryName": "Uzbekistan",
"CountryCode": "UZ"
},
Expand Down
57 changes: 38 additions & 19 deletions budget/lib/functions.dart
Original file line number Diff line number Diff line change
Expand Up @@ -211,7 +211,8 @@ String convertToMoney(AllWallets allWallets, double amount,

final NumberFormat formatter;
if (getCustomNumberFormat != null) {
formatter = getCustomNumberFormat(decimalDigits, locale, symbol);
formatter = getCustomNumberFormat(
decimalDigits, locale, useCustomNumberFormat ? "" : symbol);
} else if (forceDefaultNumberFormatter == false &&
(forceCompactNumberFormatter ||
appStateSettings["shortNumberFormat"] == "compact")) {
Expand All @@ -221,7 +222,6 @@ String convertToMoney(AllWallets allWallets, double amount,
symbol: useCustomNumberFormat ? "" : symbol,
);
formatter.significantDigitsInUse = false;
formatter.currencyName = symbol;
} else {
formatter = NumberFormat.currency(
decimalDigits: decimalDigits,
Expand All @@ -239,11 +239,11 @@ String convertToMoney(AllWallets allWallets, double amount,
addCurrencyName = true;
}
String formatOutput = formatter.format(amount).trim();
String? currencyName;
if (addCurrencyName == true && currencyKey != null) {
formatOutput = formatOutput + " " + currencyKey.toUpperCase();
currencyName = " " + currencyKey.toUpperCase();
} else if (addCurrencyName == true) {
formatOutput = formatOutput +
" " +
currencyName = " " +
(allWallets.indexedByPk[appStateSettings["selectedWalletPk"]]
?.currency ??
"")
Expand All @@ -252,11 +252,15 @@ String convertToMoney(AllWallets allWallets, double amount,

if (useCustomNumberFormat) {
formatOutput = formatOutputWithNewDelimiterAndDecimal(
formatOutput,
appStateSettings["numberFormatDelimiter"],
appStateSettings["numberFormatDecimal"],
symbol,
amount: finalNumber ?? amount,
currencyName: currencyName,
input: formatOutput,
delimiter: appStateSettings["numberFormatDelimiter"],
decimal: appStateSettings["numberFormatDecimal"],
symbol: symbol,
);
} else if (useCustomNumberFormat == false && currencyName != null) {
formatOutput = formatOutput + currencyName;
}

if (editFormattedOutput != null) {
Expand Down Expand Up @@ -287,16 +291,31 @@ String convertToMoney(AllWallets allWallets, double amount,
// return currency.format(amount);
}

String formatOutputWithNewDelimiterAndDecimal(
String input, String delimiter, String decimal, String symbol) {
String formatOutputWithNewDelimiterAndDecimal({
required double amount,
required String input,
required String delimiter,
required String decimal,
required String symbol,
required String? currencyName,
}) {
// Use a placeholder
input = input.replaceAll(".", "\uFFFD");
input = input.replaceAll(",", delimiter);
input = input.replaceAll("\uFFFD", decimal);
String negativeSign = "";
if (amount < 0) {
input = input.replaceRange(0, 1, "");
negativeSign = "-";
}
if (appStateSettings["numberFormatCurrencyFirst"] == false) {
return input + symbol;
return negativeSign +
input +
(symbol.length > 0 ? "  " : "") +
symbol +
(currencyName ?? "");
} else {
return symbol + input;
return negativeSign + symbol + input + (currencyName ?? "");
}
}

Expand Down Expand Up @@ -713,20 +732,20 @@ String getWordedNumber(
value,
forceHideCurrencyName: true,
addCurrencyName: false,
editFormattedOutput: (output) {
return getCurrencyString(Provider.of<AllWallets>(context)) + output;
},
getCustomNumberFormat: (decimalDigits, locale, currencySymbol) {
final NumberFormat formatter = NumberFormat.compact(locale: locale);
final NumberFormat formatter = NumberFormat.compactCurrency(
locale: locale,
decimalDigits: decimalDigits,
symbol: currencySymbol,
);
formatter.significantDigitsInUse = false;
formatter.maximumFractionDigits = value.abs() < 1000
? value.abs() < 10
? (decimalDigits ?? 2)
: 0
: 1;
formatter.minimumFractionDigits =
value.abs() < 10 ? (decimalDigits ?? 2) : 0;
formatter.significantDigitsInUse = false;
formatter.currencyName = currencySymbol;
return formatter;
},
);
Expand Down
2 changes: 1 addition & 1 deletion budget/lib/pages/addBudgetPage.dart
Original file line number Diff line number Diff line change
Expand Up @@ -648,7 +648,7 @@ class _AddBudgetPageState extends State<AddBudgetPage> {
],
),
],
overlay: Align(
staticOverlay: Align(
alignment: Alignment.bottomCenter,
child: selectedTitle == "" || selectedTitle == null
? SaveBottomButton(
Expand Down
2 changes: 1 addition & 1 deletion budget/lib/pages/addCategoryPage.dart
Original file line number Diff line number Diff line change
Expand Up @@ -377,7 +377,7 @@ class _AddCategoryPageState extends State<AddCategoryPage>
)
: SizedBox.shrink()
],
overlay: Align(
staticOverlay: Align(
alignment: Alignment.bottomCenter,
child: selectedTitle == "" || selectedTitle == null
? SaveBottomButton(
Expand Down
2 changes: 1 addition & 1 deletion budget/lib/pages/addObjectivePage.dart
Original file line number Diff line number Diff line change
Expand Up @@ -478,7 +478,7 @@ class _AddObjectivePageState extends State<AddObjectivePage>
],
),
],
overlay: Align(
staticOverlay: Align(
alignment: Alignment.bottomCenter,
child: selectedTitle == "" || selectedTitle == null
? SaveBottomButton(
Expand Down
50 changes: 14 additions & 36 deletions budget/lib/pages/addTransactionPage.dart
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,7 @@ class AddTransactionPage extends StatefulWidget {
this.selectedType,
this.selectedObjective,
this.selectedIncome,
this.useCategorySelectedIncome = false,
this.selectedAmount,
this.selectedTitle,
this.selectedCategory,
Expand All @@ -112,6 +113,7 @@ class AddTransactionPage extends StatefulWidget {
final Objective? selectedObjective;
final RoutesToPopAfterDelete routesToPopAfterDelete;
final bool? selectedIncome;
final bool useCategorySelectedIncome;
final double? selectedAmount;
final String? selectedTitle;
final TransactionCategory? selectedCategory;
Expand Down Expand Up @@ -814,6 +816,8 @@ class _AddTransactionPageState extends State<AddTransactionPage>
}
if (widget.selectedCategory != null) {
selectedCategory = widget.selectedCategory;
if (widget.useCategorySelectedIncome)
selectedIncome = selectedCategory?.income ?? selectedIncome;
}
if (widget.selectedSubCategory != null) {
selectedSubCategory = widget.selectedSubCategory;
Expand Down Expand Up @@ -2006,7 +2010,8 @@ class _AddTransactionPageState extends State<AddTransactionPage>
)
: SizedBox.shrink()
],
overlay: Align(
overlay: MinimizeKeyboardFABOverlay(isEnabled: notesInputFocused),
staticOverlay: Align(
alignment: Alignment.bottomCenter,
child: Row(
children: [
Expand Down Expand Up @@ -2096,35 +2101,6 @@ class _AddTransactionPageState extends State<AddTransactionPage>
key: ValueKey(2),
),
),
AnimatedSizeSwitcher(
child: notesInputFocused && getPlatform() == PlatformOS.isIOS
? WidgetSizeBuilder(
widgetBuilder: (Size? size) {
return Container(
key: ValueKey(1),
width: size?.width,
child: SaveBottomButton(
margin: EdgeInsets.only(left: 5),
color: isTransactionActionDealtWith(
createTransaction())
? Theme.of(context).colorScheme.primary
: null,
labelColor: isTransactionActionDealtWith(
createTransaction())
? Theme.of(context).colorScheme.onPrimary
: null,
label: "done".tr(),
onTap: () async {
FocusManager.instance.primaryFocus?.unfocus();
},
),
);
},
)
: Container(
key: ValueKey(2),
),
),
],
),
),
Expand Down Expand Up @@ -4282,12 +4258,14 @@ class _TransactionNotesTextInputState extends State<TransactionNotesTextInput> {
),
HorizontalBreak(
padding: EdgeInsets.zero,
color: dynamicPastel(
context,
Theme.of(context).colorScheme.secondaryContainer,
amount: 0.1,
inverse: true,
),
color: appStateSettings["materialYou"]
? dynamicPastel(
context,
Theme.of(context).colorScheme.secondaryContainer,
amount: 0.1,
inverse: true,
)
: getColor(context, "lightDarkAccent"),
),
LinkInNotes(
color: (appStateSettings["materialYou"]
Expand Down
2 changes: 1 addition & 1 deletion budget/lib/pages/addWalletPage.dart
Original file line number Diff line number Diff line change
Expand Up @@ -437,7 +437,7 @@ class _AddWalletPageState extends State<AddWalletPage> {
],
),
],
overlay: Align(
staticOverlay: Align(
alignment: Alignment.bottomCenter,
child: selectedTitle == "" || selectedTitle == null
? SaveBottomButton(
Expand Down
3 changes: 2 additions & 1 deletion budget/lib/pages/autoTransactionsPageEmail.dart
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,7 @@ Future queueTransactionFromMessage(String messageString) async {
pushRoute(
navigatorKey.currentContext!,
AddTransactionPage(
useCategorySelectedIncome: true,
routesToPopAfterDelete: RoutesToPopAfterDelete.None,
selectedAmount: amountDouble,
selectedTitle: title,
Expand Down Expand Up @@ -520,7 +521,7 @@ Future<void> parseEmailsInBackground(context,
Transaction transactionToAdd = Transaction(
transactionPk: "-1",
name: title,
amount: (amountDouble).abs() * -1,
amount: (amountDouble).abs() * (selectedCategory.income ? 1 : -1),
note: "",
categoryFk: selectedCategory.categoryPk,
walletFk: appStateSettings["selectedWalletPk"],
Expand Down
4 changes: 2 additions & 2 deletions budget/lib/pages/billSplitter.dart
Original file line number Diff line number Diff line change
Expand Up @@ -1156,7 +1156,7 @@ class _AddBillItemPageState extends State<AddBillItemPage> {
},
),
],
overlay: Align(
staticOverlay: Align(
alignment: Alignment.bottomCenter,
child: SaveBottomButton(
label: widget.billSplitterItem == null
Expand Down Expand Up @@ -1365,7 +1365,7 @@ class SummaryPage extends StatelessWidget {
return PageFramework(
title: "summary".tr(),
dragDownToDismiss: true,
overlay: Align(
staticOverlay: Align(
alignment: Alignment.bottomCenter,
child: SaveBottomButton(
label: "generate-loan-transactions".tr(),
Expand Down
2 changes: 1 addition & 1 deletion budget/lib/pages/budgetPage.dart
Original file line number Diff line number Diff line change
Expand Up @@ -296,7 +296,7 @@ class _BudgetPageContentState extends State<_BudgetPageContent> {
routesToPopAfterDelete: RoutesToPopAfterDelete.One,
),
color: budgetColorScheme.secondary,
colorPlus: budgetColorScheme.onSecondary,
colorIcon: budgetColorScheme.onSecondary,
),
),
actions: [
Expand Down
2 changes: 1 addition & 1 deletion budget/lib/pages/objectivePage.dart
Original file line number Diff line number Diff line change
Expand Up @@ -221,7 +221,7 @@ class _ObjectivePageContentState extends State<_ObjectivePageContent> {
selectedIncome: widget.objective.income,
),
color: objectiveColorScheme.secondary,
colorPlus: objectiveColorScheme.onSecondary,
colorIcon: objectiveColorScheme.onSecondary,
),
),
expandedHeight: 56,
Expand Down
Loading

0 comments on commit 6402587

Please sign in to comment.