From 58524c4ced06fd3ed8744ce6617642e7d941d2d4 Mon Sep 17 00:00:00 2001 From: Donnie Ashok Date: Wed, 24 Jan 2024 20:36:51 +0100 Subject: [PATCH] v1.0.23 - Fix Summary page currency bug (#23) * v1.0.23 - Version * v1.0.23 - Fix transaction order * v1.0.23 - Fix non EUR preferred currency * v1.0.23 - Fix Summary page currency bug * v1.0.23 - Correction in Hide Alert * v1.0.23 - Correction in Menu * v1.0.23 - Let preferred currency change * v1.0.23 - Improve language * v1.0.23 - Update workflow --- .github/workflows/android_release.yml | 13 ++++- README.md | 4 +- lib/db/currency.dart | 10 +--- lib/db/months.dart | 8 ++- lib/pages/edit_account/account_body.dart | 15 +++--- lib/pages/home/entries/main.dart | 2 +- lib/pages/home/frame/mobile.dart | 4 +- lib/pages/home/months/main.dart | 2 +- lib/pages/settings/about.dart | 2 +- lib/pages/settings/currency.dart | 69 ++++++++++++++++++++++++ lib/pages/settings/main.dart | 7 +++ lib/pages/settings/reset_app.dart | 8 ++- pubspec.yaml | 2 +- 13 files changed, 119 insertions(+), 27 deletions(-) create mode 100644 lib/pages/settings/currency.dart diff --git a/.github/workflows/android_release.yml b/.github/workflows/android_release.yml index 6321dbc..c0c5151 100644 --- a/.github/workflows/android_release.yml +++ b/.github/workflows/android_release.yml @@ -1,6 +1,9 @@ name: Release Android on: + push: + tags: + - "v*.*.*" workflow_dispatch: inputs: releaseRef: @@ -17,11 +20,17 @@ jobs: steps: - name: Set env run: | - echo "RELEASE_VERSION=${{ github.event.inputs.releaseRef }}" >> $GITHUB_ENV + if [ "${{ github.event.inputs.releaseRef }}" != "" ]; then + RELEASE_REF=${{ github.event.inputs.releaseRef }} + else + RELEASE_REF=${GITHUB_REF} + fi + RELEASE_VERSION=$(echo $RELEASE_REF | sed -e 's/refs\/tags\///') + echo "RELEASE_VERSION=$RELEASE_VERSION" >> $GITHUB_ENV - uses: actions/checkout@v4 with: - ref: ${{ github.event.inputs.releaseRef }} + ref: ${{ env.RELEASE_VERSION }} - name: Install and set up Java uses: actions/setup-java@v3 diff --git a/README.md b/README.md index ae1cff6..dc9f40a 100644 --- a/README.md +++ b/README.md @@ -6,8 +6,8 @@ - - + + diff --git a/lib/db/currency.dart b/lib/db/currency.dart index 0f12b47..292f661 100644 --- a/lib/db/currency.dart +++ b/lib/db/currency.dart @@ -56,16 +56,10 @@ class CurrencyBoxService { String baseCurrency, String targetCurrency, ) async { - double baseRate = 1.0; - double targetRate = 1.0; // Assuming data is always available and up-to-date. // Retrieve the rates directly from the box. - if (baseCurrency != prefCurrency) { - baseRate = _box.get(baseCurrency) ?? 0; - } - if (targetCurrency != prefCurrency) { - targetRate = _box.get(targetCurrency) ?? 0; - } + double baseRate = _box.get(baseCurrency) ?? 0; + double targetRate = _box.get(targetCurrency) ?? 0; // rates must be available; if not, throw an exception. if (targetRate == 0 || baseRate == 0) { diff --git a/lib/db/months.dart b/lib/db/months.dart index c8e937d..12546d9 100644 --- a/lib/db/months.dart +++ b/lib/db/months.dart @@ -75,6 +75,9 @@ class MonthService { ELSE e.amount / ( SELECT cr.rate FROM rates cr WHERE cr.currency = ac.currency + ) * ( + SELECT cr.rate FROM rates cr + WHERE cr.currency = ? ) END ) FILTER ( @@ -86,6 +89,9 @@ class MonthService { ELSE e.amount / ( SELECT cr.rate FROM rates cr WHERE cr.currency = ac.currency + ) * ( + SELECT cr.rate FROM rates cr + WHERE cr.currency = ? ) END ) FILTER ( @@ -125,7 +131,7 @@ class MonthService { final results = await dbClient.rawQuery( query, - [prefCurrency, prefCurrency, prefCurrency], + [prefCurrency, prefCurrency, prefCurrency, prefCurrency, prefCurrency], ); currencyBoxService.close(); diff --git a/lib/pages/edit_account/account_body.dart b/lib/pages/edit_account/account_body.dart index 4224326..23e0367 100644 --- a/lib/pages/edit_account/account_body.dart +++ b/lib/pages/edit_account/account_body.dart @@ -118,7 +118,9 @@ class EditAccountBody extends StatelessWidget { context: context, builder: (BuildContext dialogContext) { return SwitchAlert( - word: "hide", + text: 'Once you hide an account, ' + 'you can still find it at the ' + 'bottom of the accounts page and unhide it.', onChange: onChangeHidden, ); }, @@ -141,7 +143,9 @@ class EditAccountBody extends StatelessWidget { context: context, builder: (BuildContext dialogContext) { return SwitchAlert( - word: "delete", + text: 'Once you delete an account, ' + 'you would never get it back,' + 'unless you restore from a backup!', onChange: (val) => val ? onDelete?.call() : {}, ); }, @@ -163,18 +167,17 @@ class SwitchAlert extends StatelessWidget { const SwitchAlert({ super.key, required this.onChange, - required this.word, + required this.text, }); final ValueChanged onChange; - final String word; + final String text; @override Widget build(BuildContext context) { return AlertDialog( title: const Text('Confirm'), - content: Text( - 'Once you $word an account, you would never get it back, unless you restore from a backup!'), + content: Text(text), actions: [ TextButton( onPressed: () { diff --git a/lib/pages/home/entries/main.dart b/lib/pages/home/entries/main.dart index f503a98..789458c 100644 --- a/lib/pages/home/entries/main.dart +++ b/lib/pages/home/entries/main.dart @@ -35,7 +35,7 @@ class EntriesPageState extends State { startDate: widget.startDate, endDate: widget.endDate, ); - entriesList.sort((a, b) => (b.id!.compareTo(a.id!))); + entriesList.sort((a, b) => (b.date!.compareTo(a.date!))); List mergedEntries = []; for (int i = 0; i < entriesList.length; i++) { diff --git a/lib/pages/home/frame/mobile.dart b/lib/pages/home/frame/mobile.dart index 76a0828..7f073aa 100644 --- a/lib/pages/home/frame/mobile.dart +++ b/lib/pages/home/frame/mobile.dart @@ -1,10 +1,10 @@ +import 'package:finease/db/accounts.dart'; +import 'package:finease/db/settings.dart'; import 'package:finease/pages/export.dart'; import 'package:finease/parts/export.dart'; import 'package:finease/routes/routes_name.dart'; import 'package:flutter/material.dart'; import 'package:go_router/go_router.dart'; -import 'package:finease/db/accounts.dart'; -import 'package:finease/db/settings.dart'; class SummaryPage extends StatefulWidget { const SummaryPage({super.key}); diff --git a/lib/pages/home/months/main.dart b/lib/pages/home/months/main.dart index 01033f2..3a3f87b 100644 --- a/lib/pages/home/months/main.dart +++ b/lib/pages/home/months/main.dart @@ -58,7 +58,7 @@ class MonthsPageState extends State { drawer: AppDrawer( onRefresh: loadMonths, scaffoldKey: scaffoldStateKey, - selectedIndex: 1, + selectedIndex: 3, destinations: destinations, onDestinationSelected: updateBody, ), diff --git a/lib/pages/settings/about.dart b/lib/pages/settings/about.dart index c6c6997..10e8564 100644 --- a/lib/pages/settings/about.dart +++ b/lib/pages/settings/about.dart @@ -45,7 +45,7 @@ class AboutWidget extends StatelessWidget { ), actions: [ TextButton( - child: const Text('Yus'), + child: const Text('Yus!'), onPressed: () { Navigator.of(context).pop(); }, diff --git a/lib/pages/settings/currency.dart b/lib/pages/settings/currency.dart new file mode 100644 index 0000000..7ee7c45 --- /dev/null +++ b/lib/pages/settings/currency.dart @@ -0,0 +1,69 @@ +import 'package:currency_picker/currency_picker.dart'; +import 'package:finease/core/extensions/text_style_extension.dart'; +import 'package:finease/db/settings.dart'; +import 'package:flutter/material.dart'; +import 'package:finease/db/currency.dart'; +import 'package:go_router/go_router.dart'; + +class CurrencySelectorWidget extends StatefulWidget { + final Function onChange; + const CurrencySelectorWidget({ + super.key, + required this.onChange, + }); + + @override + CurrencySelectorWidgetState createState() => CurrencySelectorWidgetState(); +} + +class CurrencySelectorWidgetState extends State { + final SettingService _settingService = SettingService(); + String? currency; + String? symbol; + + @override + void initState() { + super.initState(); + onLoad(); + } + + Future onLoad() async { + final curr = await _settingService.getSetting(Setting.prefCurrency); + + setState(() { + currency = curr; + symbol = SupportedCurrency[curr]; + }); + } + + void _showCurrencyPicker(BuildContext context) { + showCurrencyPicker( + context: context, + currencyFilter: SupportedCurrency.keys.toList(), + showFlag: true, + onSelect: (Currency selectedCurrency) async { + setState(() { + currency = selectedCurrency.code; + symbol = selectedCurrency.symbol; + }); + await _settingService.setSetting(Setting.prefCurrency, currency!); + // ignore: use_build_context_synchronously + context.pop(); + widget.onChange(); + }, + ); + } + + @override + Widget build(BuildContext context) { + return ListTile( + title: const Text("Preferred Currency"), + subtitle: Text(currency ?? ''), + leading: Text( + symbol ?? '', + style: context.titleLarge, + ), + onTap: () => _showCurrencyPicker(context), + ); + } +} diff --git a/lib/pages/settings/main.dart b/lib/pages/settings/main.dart index 7b3eb58..3bfb9d5 100644 --- a/lib/pages/settings/main.dart +++ b/lib/pages/settings/main.dart @@ -1,5 +1,6 @@ import 'package:finease/pages/export.dart'; import 'package:finease/pages/settings/about.dart'; +import 'package:finease/pages/settings/currency.dart'; import 'package:finease/pages/settings/toggle_encryption.dart'; import 'package:finease/parts/export.dart'; import 'package:flutter/material.dart'; @@ -41,6 +42,12 @@ class SettingsPage extends StatelessWidget { padding: EdgeInsets.zero, shrinkWrap: true, children: [ + SettingsGroup( + title: "Personalise", + options: [ + CurrencySelectorWidget(onChange: onFormSubmitted), + ], + ), SettingsGroup( title: "Database", options: [ diff --git a/lib/pages/settings/reset_app.dart b/lib/pages/settings/reset_app.dart index 2a1b24e..69e78cc 100644 --- a/lib/pages/settings/reset_app.dart +++ b/lib/pages/settings/reset_app.dart @@ -26,14 +26,18 @@ class _ResetAppWidgetState extends State { context: context, builder: (BuildContext dialogContext) => AlertDialog( title: const Text("Reset App"), - content: const Text("Are you sure you want to wipe all data in this App? This action cannot be undone!"), + content: const Text( + 'Are you sure you want to wipe ' + 'all data, and reset this App?' + '\n\nMake sure you export the database before!' + ), actions: [ TextButton( child: const Text("Cancel"), onPressed: () => Navigator.of(dialogContext).pop(false), ), TextButton( - child: const Text("Reset App"), + child: const Text("Reset App!"), onPressed: () async { await DatabaseHelper().clearDatabase().then((value) { Navigator.of(dialogContext).pop(false); diff --git a/pubspec.yaml b/pubspec.yaml index 0e19af8..917ddfe 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -1,7 +1,7 @@ name: finease description: "A full stack mobile app to keep track of financial transactions" publish_to: 'none' -version: 1.0.22 +version: 1.0.23 environment: sdk: '>=3.2.3 <4.0.0'