Compare commits

..

1 commit

Author SHA1 Message Date
Matyáš Caras
fedb98c500
Added translation using Weblate (Slovak) 2024-01-22 16:36:42 +01:00
7 changed files with 388 additions and 503 deletions

View file

@ -1,7 +1,3 @@
# 1.0.0-alpha+5
- Add tests
- Add searching through entries to homepage
# 1.0.0-alpha+4 # 1.0.0-alpha+4
- Fix OCR downloads - Fix OCR downloads
# 1.0.0-alpha+3 # 1.0.0-alpha+3

View file

@ -4,8 +4,7 @@
<application <application
android:label="Prašule" android:label="Prašule"
android:name="${applicationName}" android:name="${applicationName}"
android:icon="@mipmap/ic_launcher" android:icon="@mipmap/ic_launcher">
android:enableOnBackInvokedCallback="true">
<activity <activity
android:name=".MainActivity" android:name=".MainActivity"
android:exported="true" android:exported="true"

View file

@ -90,6 +90,5 @@
"startingWithDate": "počínaje datem", "startingWithDate": "počínaje datem",
"evenMoney":"Váš stav je stejný jako minulý měsíc.", "evenMoney":"Váš stav je stejný jako minulý měsíc.",
"balanceStatusA": "Váš stav je ", "balanceStatusA": "Váš stav je ",
"balanceStatusB": " oproti minulému měsíci.", "balanceStatusB": " oproti minulému měsíci."
"searchLabel":"Prohledat záznamy..."
} }

View file

@ -206,6 +206,5 @@
}, },
"evenMoney":"You're on the same balance as last month.", "evenMoney":"You're on the same balance as last month.",
"balanceStatusA": "Your balance is ", "balanceStatusA": "Your balance is ",
"balanceStatusB": " compared to last month.", "balanceStatusB": " compared to last month."
"searchLabel":"Search entries..."
} }

View file

@ -21,8 +21,6 @@ class PlatformField extends PlatformWidget<TextField, CupertinoTextField> {
this.textStyle, this.textStyle,
this.textAlign = TextAlign.start, this.textAlign = TextAlign.start,
this.maxLines = 1, this.maxLines = 1,
this.focusNode,
this.inputBorder = const OutlineInputBorder(),
}); });
final TextEditingController? controller; final TextEditingController? controller;
final bool? enabled; final bool? enabled;
@ -36,8 +34,6 @@ class PlatformField extends PlatformWidget<TextField, CupertinoTextField> {
final TextStyle? textStyle; final TextStyle? textStyle;
final TextAlign textAlign; final TextAlign textAlign;
final int? maxLines; final int? maxLines;
final InputBorder inputBorder;
final FocusNode? focusNode;
@override @override
TextField createAndroidWidget(BuildContext context) => TextField( TextField createAndroidWidget(BuildContext context) => TextField(
@ -47,11 +43,10 @@ class PlatformField extends PlatformWidget<TextField, CupertinoTextField> {
obscureText: obscureText, obscureText: obscureText,
decoration: InputDecoration( decoration: InputDecoration(
labelText: labelText, labelText: labelText,
border: inputBorder, border: OutlineInputBorder(borderRadius: BorderRadius.circular(4)),
), ),
autocorrect: autocorrect, autocorrect: autocorrect,
keyboardType: keyboardType, keyboardType: keyboardType,
focusNode: focusNode,
style: textStyle, style: textStyle,
inputFormatters: inputFormatters, inputFormatters: inputFormatters,
onChanged: onChanged, onChanged: onChanged,
@ -71,7 +66,6 @@ class PlatformField extends PlatformWidget<TextField, CupertinoTextField> {
keyboardType: keyboardType, keyboardType: keyboardType,
inputFormatters: inputFormatters, inputFormatters: inputFormatters,
onChanged: onChanged, onChanged: onChanged,
focusNode: focusNode,
maxLines: maxLines, maxLines: maxLines,
style: textStyle, style: textStyle,
); );

View file

@ -22,7 +22,6 @@ import 'package:prasule/main.dart';
import 'package:prasule/network/tessdata.dart'; import 'package:prasule/network/tessdata.dart';
import 'package:prasule/pw/platformbutton.dart'; import 'package:prasule/pw/platformbutton.dart';
import 'package:prasule/pw/platformdialog.dart'; import 'package:prasule/pw/platformdialog.dart';
import 'package:prasule/pw/platformfield.dart';
import 'package:prasule/pw/platformroute.dart'; import 'package:prasule/pw/platformroute.dart';
import 'package:prasule/util/drawer.dart'; import 'package:prasule/util/drawer.dart';
import 'package:prasule/util/text_color.dart'; import 'package:prasule/util/text_color.dart';
@ -45,9 +44,6 @@ class _HomeViewState extends State<HomeView> {
List<Wallet> wallets = []; List<Wallet> wallets = [];
DateTime? prevDate; DateTime? prevDate;
late String locale; late String locale;
var _searchActive = false;
var _filter = "";
final searchFocus = FocusNode();
@override @override
void didChangeDependencies() { void didChangeDependencies() {
super.didChangeDependencies(); super.didChangeDependencies();
@ -77,515 +73,417 @@ class _HomeViewState extends State<HomeView> {
@override @override
Widget build(BuildContext context) { Widget build(BuildContext context) {
return PopScope( return Scaffold(
canPop: !_searchActive, // don't pop when we just want drawer: makeDrawer(context, 1),
// to deactivate searchfield floatingActionButton: SpeedDial(
onPopInvoked: (b) { icon: Icons.add,
if (b) return; activeIcon: Icons.close,
_searchActive = false; children: [
_filter = ""; if (kDebugMode)
setState(() {});
},
child: Scaffold(
drawer: makeDrawer(context, 1),
floatingActionButton: SpeedDial(
icon: Icons.add,
activeIcon: Icons.close,
children: [
if (kDebugMode)
SpeedDialChild(
child: const Icon(Icons.bug_report),
label: AppLocalizations.of(context).createTestData,
onTap: () {
// debug option to quickly fill a wallet with data
if (selectedWallet == null) return;
selectedWallet!.createTestEntries().then((_) {
Navigator.of(context).pushReplacement(
platformRoute(
(p0) => const HomeView(),
),
);
});
},
),
SpeedDialChild( SpeedDialChild(
child: const Icon(Icons.edit), child: const Icon(Icons.bug_report),
label: AppLocalizations.of(context).addNew, label: AppLocalizations.of(context).createTestData,
onTap: () async {
final sw = await Navigator.of(context).push<Wallet>(
MaterialPageRoute(
builder: (c) => CreateSingleEntryView(w: selectedWallet!),
),
);
if (sw != null) {
selectedWallet = sw;
}
setState(() {});
},
),
SpeedDialChild(
child: const Icon(Icons.camera_alt),
label: AppLocalizations.of(context).addCamera,
onTap: () async {
final picker = ImagePicker();
final media =
await picker.pickImage(source: ImageSource.camera);
logger.i(media?.name);
},
),
SpeedDialChild(
child: const Icon(Icons.image),
label: AppLocalizations.of(context).addGallery,
onTap: () { onTap: () {
startOcr(ImageSource.gallery); // debug option to quickly fill a wallet with data
}, if (selectedWallet == null) return;
), selectedWallet!.createTestEntries().then((_) {
], Navigator.of(context).pushReplacement(
),
appBar: AppBar(
title: AnimatedCrossFade(
duration: const Duration(milliseconds: 500),
crossFadeState: _searchActive
? CrossFadeState.showFirst
: CrossFadeState.showSecond,
firstChild: PlatformField(
inputBorder: InputBorder.none,
focusNode: searchFocus,
onChanged: (e) {
_filter = e;
setState(() {});
},
labelText: AppLocalizations.of(context).searchLabel,
),
secondChild: DropdownButton<int>(
value: (selectedWallet == null)
? -1
: wallets.indexOf(selectedWallet!),
items: [
...wallets.map(
(e) => DropdownMenuItem(
value: wallets.indexOf(
e,
),
child: Text(e.name),
),
),
DropdownMenuItem(
value: -1,
child: Text(AppLocalizations.of(context).newWallet),
),
],
onChanged: (v) async {
if (v == null || v == -1) {
await Navigator.of(context).push(
platformRoute( platformRoute(
(c) => const SetupView( (p0) => const HomeView(),
newWallet: true,
),
), ),
); );
wallets = await WalletManager.listWallets(); });
selectedWallet = wallets.last;
setState(() {});
return;
}
selectedWallet = wallets[v];
setState(() {});
}, },
), ),
SpeedDialChild(
child: const Icon(Icons.edit),
label: AppLocalizations.of(context).addNew,
onTap: () async {
final sw = await Navigator.of(context).push<Wallet>(
MaterialPageRoute(
builder: (c) => CreateSingleEntryView(w: selectedWallet!),
),
);
if (sw != null) {
selectedWallet = sw;
}
setState(() {});
},
), ),
actions: [ SpeedDialChild(
if (!_searchActive) child: const Icon(Icons.camera_alt),
IconButton( label: AppLocalizations.of(context).addCamera,
onPressed: () { onTap: () async {
_searchActive = true; final picker = ImagePicker();
setState(() {}); final media = await picker.pickImage(source: ImageSource.camera);
}, logger.i(media?.name);
icon: const Icon(Icons.search), },
), ),
if (!_searchActive) SpeedDialChild(
PopupMenuButton( child: const Icon(Icons.image),
itemBuilder: (context) => [ label: AppLocalizations.of(context).addGallery,
AppLocalizations.of(context).settings, onTap: () {
AppLocalizations.of(context).about, startOcr(ImageSource.gallery);
].map((e) => PopupMenuItem(value: e, child: Text(e))).toList(), },
onSelected: (value) { ),
if (value == AppLocalizations.of(context).settings) { ],
Navigator.of(context) ),
.push( appBar: AppBar(
platformRoute( title: DropdownButton<int>(
(context) => const SettingsView(), value:
), (selectedWallet == null) ? -1 : wallets.indexOf(selectedWallet!),
) items: [
.then((value) async { ...wallets.map(
selectedWallet = (e) => DropdownMenuItem(
await WalletManager.loadWallet(selectedWallet!.name); value: wallets.indexOf(
}); e,
} else if (value == AppLocalizations.of(context).about) { ),
showAboutDialog( child: Text(e.name),
context: context,
applicationLegalese: AppLocalizations.of(context).license,
applicationName: "Prašule",
);
}
},
), ),
),
DropdownMenuItem(
value: -1,
child: Text(AppLocalizations.of(context).newWallet),
),
], ],
onChanged: (v) async {
if (v == null || v == -1) {
await Navigator.of(context).push(
platformRoute(
(c) => const SetupView(
newWallet: true,
),
),
);
wallets = await WalletManager.listWallets();
selectedWallet = wallets.last;
setState(() {});
return;
}
selectedWallet = wallets[v];
setState(() {});
},
), ),
body: Center( actions: [
child: SizedBox( PopupMenuButton(
width: MediaQuery.of(context).size.width * 0.9, itemBuilder: (context) => [
height: MediaQuery.of(context).size.height, AppLocalizations.of(context).settings,
child: (selectedWallet == null) AppLocalizations.of(context).about,
? const Column( ].map((e) => PopupMenuItem(value: e, child: Text(e))).toList(),
children: [ onSelected: (value) {
SizedBox( if (value == AppLocalizations.of(context).settings) {
width: 40, Navigator.of(context)
height: 40, .push(
child: CircularProgressIndicator(), platformRoute(
), (context) => const SettingsView(),
], ),
) )
: (selectedWallet!.entries.isEmpty) .then((value) async {
? Column( selectedWallet =
children: [ await WalletManager.loadWallet(selectedWallet!.name);
Text( });
AppLocalizations.of(context).noEntries, } else if (value == AppLocalizations.of(context).about) {
style: const TextStyle( showAboutDialog(
fontSize: 20, context: context,
fontWeight: FontWeight.bold, applicationLegalese: AppLocalizations.of(context).license,
), applicationName: "Prašule",
);
}
},
),
],
),
body: Center(
child: SizedBox(
width: MediaQuery.of(context).size.width * 0.9,
height: MediaQuery.of(context).size.height,
child: (selectedWallet == null)
? const Column(
children: [
SizedBox(
width: 40,
height: 40,
child: CircularProgressIndicator(),
),
],
)
: (selectedWallet!.entries.isEmpty)
? Column(
children: [
Text(
AppLocalizations.of(context).noEntries,
style: const TextStyle(
fontSize: 20,
fontWeight: FontWeight.bold,
), ),
Text( ),
AppLocalizations.of(context).noEntriesSub, Text(
AppLocalizations.of(context).noEntriesSub,
),
],
)
: Column(
children: [
Text(
NumberFormat.compactCurrency(
locale: locale,
symbol: selectedWallet!.currency.symbol,
).format(selectedWallet!.calculateCurrentBalance()),
style: const TextStyle(
fontWeight: FontWeight.bold,
fontSize: 22,
), ),
], ),
) const SizedBox(
: Overlay( height: 5,
initialEntries: [ ),
OverlayEntry( if (selectedWallet!.calculateMonthStatus(
builder: (context) => Column( DateTime.now().month,
DateTime.now().year,
) ==
0)
Text(AppLocalizations.of(context).evenMoney)
else
RichText(
text: TextSpan(
children: [ children: [
Text( TextSpan(
NumberFormat.compactCurrency( text: AppLocalizations.of(context)
locale: locale, .balanceStatusA,
symbol: selectedWallet!.currency.symbol,
).format(
selectedWallet!.calculateCurrentBalance(),
),
style: const TextStyle(
fontWeight: FontWeight.bold,
fontSize: 22,
),
), ),
const SizedBox( TextSpan(
height: 5, style: TextStyle(
), color: (selectedWallet!
if (selectedWallet!.calculateMonthStatus(
DateTime.now().month,
DateTime.now().year,
) ==
0)
Text(AppLocalizations.of(context).evenMoney)
else
RichText(
text: TextSpan(
children: [
TextSpan(
text: AppLocalizations.of(context)
.balanceStatusA,
),
TextSpan(
style: TextStyle(
color: (selectedWallet!
.calculateMonthStatus(
DateTime.now().month,
DateTime.now().year,
) >
0
? ((MediaQuery.of(context)
.platformBrightness ==
Brightness.dark)
? Colors.green.shade300
: Colors.green)
.harmonizeWith(
Theme.of(context)
.colorScheme
.primary,
)
: ((MediaQuery.of(context)
.platformBrightness ==
Brightness.dark)
? Colors.red.shade300
: Colors.red)
.harmonizeWith(
Theme.of(context)
.colorScheme
.primary,
)),
),
text: NumberFormat.compactCurrency(
locale: locale,
symbol:
selectedWallet!.currency.symbol,
).format(
selectedWallet!
.calculateMonthStatus( .calculateMonthStatus(
DateTime.now().month, DateTime.now().month,
DateTime.now().year, DateTime.now().year,
), ) >
), 0
), ? ((MediaQuery.of(context)
TextSpan( .platformBrightness ==
text: AppLocalizations.of(context) Brightness.dark)
.balanceStatusB, ? Colors.green.shade300
), : Colors.green)
], .harmonizeWith(
Theme.of(context)
.colorScheme
.primary,
)
: ((MediaQuery.of(context)
.platformBrightness ==
Brightness.dark)
? Colors.red.shade300
: Colors.red)
.harmonizeWith(
Theme.of(context)
.colorScheme
.primary,
)),
),
text: NumberFormat.compactCurrency(
locale: locale,
symbol: selectedWallet!.currency.symbol,
).format(
selectedWallet!.calculateMonthStatus(
DateTime.now().month,
DateTime.now().year,
), ),
), ),
const SizedBox(
height: 10,
), ),
Expanded( TextSpan(
child: GroupedListView( text: AppLocalizations.of(context)
groupHeaderBuilder: (element) => Text( .balanceStatusB,
DateFormat.yMMMM(locale)
.format(element.date),
style: TextStyle(
color: Theme.of(context)
.colorScheme
.primary,
),
),
elements: selectedWallet!.entries
.where((element) =>
element.data.name.contains(_filter))
.toList(),
itemComparator: (a, b) =>
b.date.compareTo(a.date),
groupBy: (e) =>
DateFormat.yMMMM(locale).format(e.date),
groupComparator: (a, b) {
// TODO: better sorting algorithm lol
final yearA =
RegExp(r'\d+').firstMatch(a);
if (yearA == null) return 0;
final yearB =
RegExp(r'\d+').firstMatch(b);
if (yearB == null) return 0;
final compareYears =
int.parse(yearB.group(0)!).compareTo(
int.parse(yearA.group(0)!),
);
if (compareYears != 0) {
return compareYears;
}
final months = List<String>.generate(
12,
(index) =>
DateFormat.MMMM(locale).format(
DateTime(2023, index + 1),
),
);
final monthA =
RegExp('[^0-9 ]+').firstMatch(a);
if (monthA == null) return 0;
final monthB =
RegExp('[^0-9 ]+').firstMatch(b);
if (monthB == null) return 0;
return months
.indexOf(monthB.group(0)!)
.compareTo(
months.indexOf(monthA.group(0)!),
);
},
itemBuilder: (context, element) => Slidable(
endActionPane: ActionPane(
motion: const ScrollMotion(),
children: [
SlidableAction(
onPressed: (c) {
Navigator.of(context)
.push<WalletSingleEntry>(
MaterialPageRoute(
builder: (c) =>
CreateSingleEntryView(
w: selectedWallet!,
editEntry: element,
),
),
)
.then(
(editedEntry) {
if (editedEntry == null) {
return;
}
selectedWallet!.entries
.remove(element);
selectedWallet!.entries
.add(editedEntry);
WalletManager.saveWallet(
selectedWallet!,
);
setState(() {});
},
);
},
backgroundColor: Theme.of(context)
.colorScheme
.secondary,
foregroundColor: Theme.of(context)
.colorScheme
.onSecondary,
icon: Icons.edit,
),
SlidableAction(
backgroundColor: Theme.of(context)
.colorScheme
.error,
foregroundColor: Theme.of(context)
.colorScheme
.onError,
icon: Icons.delete,
onPressed: (c) {
showDialog(
context: context,
builder: (cx) => PlatformDialog(
title: AppLocalizations.of(
context,
).sureDialog,
content: Text(
AppLocalizations.of(context)
.deleteSure,
),
actions: [
PlatformButton(
text: AppLocalizations.of(
context,
).yes,
onPressed: () {
selectedWallet?.entries
.removeWhere(
(e) =>
e.id ==
element.id,
);
WalletManager
.saveWallet(
selectedWallet!,
);
Navigator.of(cx).pop();
setState(() {});
},
),
PlatformButton(
text: AppLocalizations.of(
context,
).no,
onPressed: () {
Navigator.of(cx).pop();
},
),
],
),
);
},
),
],
),
child: ListTile(
leading: Container(
decoration: BoxDecoration(
borderRadius:
BorderRadius.circular(16),
color: element.category.color,
),
child: Padding(
padding: const EdgeInsets.all(8),
child: Icon(
element.category.icon,
color: element.category.color
.calculateTextColor(),
),
),
),
title: Text(element.data.name),
subtitle: RichText(
text: TextSpan(
children: [
TextSpan(
text: NumberFormat.currency(
symbol: selectedWallet!
.currency.symbol,
).format(element.data.amount),
style: TextStyle(
color: (element.type ==
EntryType.income)
? (MediaQuery.of(context)
.platformBrightness ==
Brightness.dark)
? Colors
.green.shade300
: Colors.green
.harmonizeWith(
Theme.of(context)
.colorScheme
.primary,
)
: (MediaQuery.of(context)
.platformBrightness ==
Brightness.dark)
? Colors.red.shade300
: Colors.red
.harmonizeWith(
Theme.of(context)
.colorScheme
.primary,
),
),
),
TextSpan(
text:
" | ${DateFormat.MMMd(locale).format(element.date)}",
style: TextStyle(
color: Theme.of(context)
.colorScheme
.background
.calculateTextColor(),
),
),
],
),
),
),
),
),
), ),
], ],
), ),
), ),
OverlayEntry( const SizedBox(
builder: (context) => SizedBox( height: 10,
width: MediaQuery.of(context).size.width, ),
height: MediaQuery.of(context).size.height, Expanded(
child: GestureDetector( child: GroupedListView(
onTap: () { groupHeaderBuilder: (element) => Text(
if (!_searchActive) return; DateFormat.yMMMM(locale).format(element.date),
if (!searchFocus.hasFocus) { style: TextStyle(
_searchActive = false; color: Theme.of(context).colorScheme.primary,
_filter = ""; ),
setState(() {}); ),
return; elements: selectedWallet!.entries,
} itemComparator: (a, b) => b.date.compareTo(a.date),
searchFocus.unfocus(); groupBy: (e) =>
}, DateFormat.yMMMM(locale).format(e.date),
groupComparator: (a, b) {
// TODO: better sorting algorithm lol
final yearA = RegExp(r'\d+').firstMatch(a);
if (yearA == null) return 0;
final yearB = RegExp(r'\d+').firstMatch(b);
if (yearB == null) return 0;
final compareYears = int.parse(yearB.group(0)!)
.compareTo(int.parse(yearA.group(0)!));
if (compareYears != 0) return compareYears;
final months = List<String>.generate(
12,
(index) => DateFormat.MMMM(locale).format(
DateTime(2023, index + 1),
),
);
final monthA = RegExp('[^0-9 ]+').firstMatch(a);
if (monthA == null) return 0;
final monthB = RegExp('[^0-9 ]+').firstMatch(b);
if (monthB == null) return 0;
return months.indexOf(monthB.group(0)!).compareTo(
months.indexOf(monthA.group(0)!),
);
},
itemBuilder: (context, element) => Slidable(
endActionPane: ActionPane(
motion: const ScrollMotion(),
children: [
SlidableAction(
onPressed: (c) {
Navigator.of(context)
.push<WalletSingleEntry>(
MaterialPageRoute(
builder: (c) => CreateSingleEntryView(
w: selectedWallet!,
editEntry: element,
),
),
)
.then(
(editedEntry) {
if (editedEntry == null) return;
selectedWallet!.entries
.remove(element);
selectedWallet!.entries
.add(editedEntry);
WalletManager.saveWallet(
selectedWallet!,
);
setState(() {});
},
);
},
backgroundColor:
Theme.of(context).colorScheme.secondary,
foregroundColor: Theme.of(context)
.colorScheme
.onSecondary,
icon: Icons.edit,
),
SlidableAction(
backgroundColor:
Theme.of(context).colorScheme.error,
foregroundColor:
Theme.of(context).colorScheme.onError,
icon: Icons.delete,
onPressed: (c) {
showDialog(
context: context,
builder: (cx) => PlatformDialog(
title: AppLocalizations.of(context)
.sureDialog,
content: Text(
AppLocalizations.of(context)
.deleteSure,
),
actions: [
PlatformButton(
text: AppLocalizations.of(context)
.yes,
onPressed: () {
selectedWallet?.entries
.removeWhere(
(e) => e.id == element.id,
);
WalletManager.saveWallet(
selectedWallet!,
);
Navigator.of(cx).pop();
setState(() {});
},
),
PlatformButton(
text: AppLocalizations.of(context)
.no,
onPressed: () {
Navigator.of(cx).pop();
},
),
],
),
);
},
),
],
),
child: ListTile(
leading: Container(
decoration: BoxDecoration(
borderRadius: BorderRadius.circular(16),
color: element.category.color,
),
child: Padding(
padding: const EdgeInsets.all(8),
child: Icon(
element.category.icon,
color: element.category.color
.calculateTextColor(),
),
),
),
title: Text(element.data.name),
subtitle: RichText(
text: TextSpan(
children: [
TextSpan(
text: NumberFormat.currency(
symbol:
selectedWallet!.currency.symbol,
).format(element.data.amount),
style: TextStyle(
color: (element.type ==
EntryType.income)
? (MediaQuery.of(context)
.platformBrightness ==
Brightness.dark)
? Colors.green.shade300
: Colors.green.harmonizeWith(
Theme.of(context)
.colorScheme
.primary,
)
: (MediaQuery.of(context)
.platformBrightness ==
Brightness.dark)
? Colors.red.shade300
: Colors.red.harmonizeWith(
Theme.of(context)
.colorScheme
.primary,
),
),
),
TextSpan(
text:
" | ${DateFormat.MMMd(locale).format(element.date)}",
style: TextStyle(
color: Theme.of(context)
.colorScheme
.background
.calculateTextColor(),
),
),
],
),
),
), ),
), ),
), ),
], ),
), ],
), ),
), ),
), ),
); );

View file

@ -1,7 +1,7 @@
name: prasule name: prasule
description: Open-source private expense tracker description: Open-source private expense tracker
version: 1.0.0-alpha+5 version: 1.0.0-alpha+4
environment: environment:
sdk: '>=3.1.0-262.2.beta <4.0.0' sdk: '>=3.1.0-262.2.beta <4.0.0'