feat: allow searching through entries
This commit is contained in:
parent
66ebff38a5
commit
91be906894
7 changed files with 507 additions and 392 deletions
|
@ -1,3 +1,7 @@
|
||||||
|
|
||||||
|
# 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
|
||||||
|
|
|
@ -4,7 +4,8 @@
|
||||||
<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"
|
||||||
|
|
|
@ -90,5 +90,6 @@
|
||||||
"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..."
|
||||||
}
|
}
|
|
@ -206,5 +206,6 @@
|
||||||
},
|
},
|
||||||
"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..."
|
||||||
}
|
}
|
|
@ -21,6 +21,8 @@ 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;
|
||||||
|
@ -34,6 +36,8 @@ 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(
|
||||||
|
@ -43,10 +47,11 @@ class PlatformField extends PlatformWidget<TextField, CupertinoTextField> {
|
||||||
obscureText: obscureText,
|
obscureText: obscureText,
|
||||||
decoration: InputDecoration(
|
decoration: InputDecoration(
|
||||||
labelText: labelText,
|
labelText: labelText,
|
||||||
border: OutlineInputBorder(borderRadius: BorderRadius.circular(4)),
|
border: inputBorder,
|
||||||
),
|
),
|
||||||
autocorrect: autocorrect,
|
autocorrect: autocorrect,
|
||||||
keyboardType: keyboardType,
|
keyboardType: keyboardType,
|
||||||
|
focusNode: focusNode,
|
||||||
style: textStyle,
|
style: textStyle,
|
||||||
inputFormatters: inputFormatters,
|
inputFormatters: inputFormatters,
|
||||||
onChanged: onChanged,
|
onChanged: onChanged,
|
||||||
|
@ -66,6 +71,7 @@ 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,
|
||||||
);
|
);
|
||||||
|
|
|
@ -22,6 +22,7 @@ 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';
|
||||||
|
@ -44,6 +45,9 @@ 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();
|
||||||
|
@ -73,7 +77,16 @@ class _HomeViewState extends State<HomeView> {
|
||||||
|
|
||||||
@override
|
@override
|
||||||
Widget build(BuildContext context) {
|
Widget build(BuildContext context) {
|
||||||
return Scaffold(
|
return PopScope(
|
||||||
|
canPop: !_searchActive, // don't pop when we just want
|
||||||
|
// to deactivate searchfield
|
||||||
|
onPopInvoked: (b) {
|
||||||
|
if (b) return;
|
||||||
|
_searchActive = false;
|
||||||
|
_filter = "";
|
||||||
|
setState(() {});
|
||||||
|
},
|
||||||
|
child: Scaffold(
|
||||||
drawer: makeDrawer(context, 1),
|
drawer: makeDrawer(context, 1),
|
||||||
floatingActionButton: SpeedDial(
|
floatingActionButton: SpeedDial(
|
||||||
icon: Icons.add,
|
icon: Icons.add,
|
||||||
|
@ -115,7 +128,8 @@ class _HomeViewState extends State<HomeView> {
|
||||||
label: AppLocalizations.of(context).addCamera,
|
label: AppLocalizations.of(context).addCamera,
|
||||||
onTap: () async {
|
onTap: () async {
|
||||||
final picker = ImagePicker();
|
final picker = ImagePicker();
|
||||||
final media = await picker.pickImage(source: ImageSource.camera);
|
final media =
|
||||||
|
await picker.pickImage(source: ImageSource.camera);
|
||||||
logger.i(media?.name);
|
logger.i(media?.name);
|
||||||
},
|
},
|
||||||
),
|
),
|
||||||
|
@ -129,9 +143,24 @@ class _HomeViewState extends State<HomeView> {
|
||||||
],
|
],
|
||||||
),
|
),
|
||||||
appBar: AppBar(
|
appBar: AppBar(
|
||||||
title: DropdownButton<int>(
|
title: AnimatedCrossFade(
|
||||||
value:
|
duration: const Duration(milliseconds: 500),
|
||||||
(selectedWallet == null) ? -1 : wallets.indexOf(selectedWallet!),
|
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: [
|
items: [
|
||||||
...wallets.map(
|
...wallets.map(
|
||||||
(e) => DropdownMenuItem(
|
(e) => DropdownMenuItem(
|
||||||
|
@ -164,7 +193,17 @@ class _HomeViewState extends State<HomeView> {
|
||||||
setState(() {});
|
setState(() {});
|
||||||
},
|
},
|
||||||
),
|
),
|
||||||
|
),
|
||||||
actions: [
|
actions: [
|
||||||
|
if (!_searchActive)
|
||||||
|
IconButton(
|
||||||
|
onPressed: () {
|
||||||
|
_searchActive = true;
|
||||||
|
setState(() {});
|
||||||
|
},
|
||||||
|
icon: const Icon(Icons.search),
|
||||||
|
),
|
||||||
|
if (!_searchActive)
|
||||||
PopupMenuButton(
|
PopupMenuButton(
|
||||||
itemBuilder: (context) => [
|
itemBuilder: (context) => [
|
||||||
AppLocalizations.of(context).settings,
|
AppLocalizations.of(context).settings,
|
||||||
|
@ -222,13 +261,18 @@ class _HomeViewState extends State<HomeView> {
|
||||||
),
|
),
|
||||||
],
|
],
|
||||||
)
|
)
|
||||||
: Column(
|
: Overlay(
|
||||||
|
initialEntries: [
|
||||||
|
OverlayEntry(
|
||||||
|
builder: (context) => Column(
|
||||||
children: [
|
children: [
|
||||||
Text(
|
Text(
|
||||||
NumberFormat.compactCurrency(
|
NumberFormat.compactCurrency(
|
||||||
locale: locale,
|
locale: locale,
|
||||||
symbol: selectedWallet!.currency.symbol,
|
symbol: selectedWallet!.currency.symbol,
|
||||||
).format(selectedWallet!.calculateCurrentBalance()),
|
).format(
|
||||||
|
selectedWallet!.calculateCurrentBalance(),
|
||||||
|
),
|
||||||
style: const TextStyle(
|
style: const TextStyle(
|
||||||
fontWeight: FontWeight.bold,
|
fontWeight: FontWeight.bold,
|
||||||
fontSize: 22,
|
fontSize: 22,
|
||||||
|
@ -282,9 +326,11 @@ class _HomeViewState extends State<HomeView> {
|
||||||
),
|
),
|
||||||
text: NumberFormat.compactCurrency(
|
text: NumberFormat.compactCurrency(
|
||||||
locale: locale,
|
locale: locale,
|
||||||
symbol: selectedWallet!.currency.symbol,
|
symbol:
|
||||||
|
selectedWallet!.currency.symbol,
|
||||||
).format(
|
).format(
|
||||||
selectedWallet!.calculateMonthStatus(
|
selectedWallet!
|
||||||
|
.calculateMonthStatus(
|
||||||
DateTime.now().month,
|
DateTime.now().month,
|
||||||
DateTime.now().year,
|
DateTime.now().year,
|
||||||
),
|
),
|
||||||
|
@ -303,35 +349,53 @@ class _HomeViewState extends State<HomeView> {
|
||||||
Expanded(
|
Expanded(
|
||||||
child: GroupedListView(
|
child: GroupedListView(
|
||||||
groupHeaderBuilder: (element) => Text(
|
groupHeaderBuilder: (element) => Text(
|
||||||
DateFormat.yMMMM(locale).format(element.date),
|
DateFormat.yMMMM(locale)
|
||||||
|
.format(element.date),
|
||||||
style: TextStyle(
|
style: TextStyle(
|
||||||
color: Theme.of(context).colorScheme.primary,
|
color: Theme.of(context)
|
||||||
|
.colorScheme
|
||||||
|
.primary,
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
elements: selectedWallet!.entries,
|
elements: selectedWallet!.entries
|
||||||
itemComparator: (a, b) => b.date.compareTo(a.date),
|
.where((element) =>
|
||||||
|
element.data.name.contains(_filter))
|
||||||
|
.toList(),
|
||||||
|
itemComparator: (a, b) =>
|
||||||
|
b.date.compareTo(a.date),
|
||||||
groupBy: (e) =>
|
groupBy: (e) =>
|
||||||
DateFormat.yMMMM(locale).format(e.date),
|
DateFormat.yMMMM(locale).format(e.date),
|
||||||
groupComparator: (a, b) {
|
groupComparator: (a, b) {
|
||||||
// TODO: better sorting algorithm lol
|
// TODO: better sorting algorithm lol
|
||||||
final yearA = RegExp(r'\d+').firstMatch(a);
|
final yearA =
|
||||||
|
RegExp(r'\d+').firstMatch(a);
|
||||||
if (yearA == null) return 0;
|
if (yearA == null) return 0;
|
||||||
final yearB = RegExp(r'\d+').firstMatch(b);
|
final yearB =
|
||||||
|
RegExp(r'\d+').firstMatch(b);
|
||||||
if (yearB == null) return 0;
|
if (yearB == null) return 0;
|
||||||
final compareYears = int.parse(yearB.group(0)!)
|
final compareYears =
|
||||||
.compareTo(int.parse(yearA.group(0)!));
|
int.parse(yearB.group(0)!).compareTo(
|
||||||
if (compareYears != 0) return compareYears;
|
int.parse(yearA.group(0)!),
|
||||||
|
);
|
||||||
|
if (compareYears != 0) {
|
||||||
|
return compareYears;
|
||||||
|
}
|
||||||
final months = List<String>.generate(
|
final months = List<String>.generate(
|
||||||
12,
|
12,
|
||||||
(index) => DateFormat.MMMM(locale).format(
|
(index) =>
|
||||||
|
DateFormat.MMMM(locale).format(
|
||||||
DateTime(2023, index + 1),
|
DateTime(2023, index + 1),
|
||||||
),
|
),
|
||||||
);
|
);
|
||||||
final monthA = RegExp('[^0-9 ]+').firstMatch(a);
|
final monthA =
|
||||||
|
RegExp('[^0-9 ]+').firstMatch(a);
|
||||||
if (monthA == null) return 0;
|
if (monthA == null) return 0;
|
||||||
final monthB = RegExp('[^0-9 ]+').firstMatch(b);
|
final monthB =
|
||||||
|
RegExp('[^0-9 ]+').firstMatch(b);
|
||||||
if (monthB == null) return 0;
|
if (monthB == null) return 0;
|
||||||
return months.indexOf(monthB.group(0)!).compareTo(
|
return months
|
||||||
|
.indexOf(monthB.group(0)!)
|
||||||
|
.compareTo(
|
||||||
months.indexOf(monthA.group(0)!),
|
months.indexOf(monthA.group(0)!),
|
||||||
);
|
);
|
||||||
},
|
},
|
||||||
|
@ -344,7 +408,8 @@ class _HomeViewState extends State<HomeView> {
|
||||||
Navigator.of(context)
|
Navigator.of(context)
|
||||||
.push<WalletSingleEntry>(
|
.push<WalletSingleEntry>(
|
||||||
MaterialPageRoute(
|
MaterialPageRoute(
|
||||||
builder: (c) => CreateSingleEntryView(
|
builder: (c) =>
|
||||||
|
CreateSingleEntryView(
|
||||||
w: selectedWallet!,
|
w: selectedWallet!,
|
||||||
editEntry: element,
|
editEntry: element,
|
||||||
),
|
),
|
||||||
|
@ -352,7 +417,9 @@ class _HomeViewState extends State<HomeView> {
|
||||||
)
|
)
|
||||||
.then(
|
.then(
|
||||||
(editedEntry) {
|
(editedEntry) {
|
||||||
if (editedEntry == null) return;
|
if (editedEntry == null) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
selectedWallet!.entries
|
selectedWallet!.entries
|
||||||
.remove(element);
|
.remove(element);
|
||||||
selectedWallet!.entries
|
selectedWallet!.entries
|
||||||
|
@ -364,40 +431,48 @@ class _HomeViewState extends State<HomeView> {
|
||||||
},
|
},
|
||||||
);
|
);
|
||||||
},
|
},
|
||||||
backgroundColor:
|
backgroundColor: Theme.of(context)
|
||||||
Theme.of(context).colorScheme.secondary,
|
.colorScheme
|
||||||
|
.secondary,
|
||||||
foregroundColor: Theme.of(context)
|
foregroundColor: Theme.of(context)
|
||||||
.colorScheme
|
.colorScheme
|
||||||
.onSecondary,
|
.onSecondary,
|
||||||
icon: Icons.edit,
|
icon: Icons.edit,
|
||||||
),
|
),
|
||||||
SlidableAction(
|
SlidableAction(
|
||||||
backgroundColor:
|
backgroundColor: Theme.of(context)
|
||||||
Theme.of(context).colorScheme.error,
|
.colorScheme
|
||||||
foregroundColor:
|
.error,
|
||||||
Theme.of(context).colorScheme.onError,
|
foregroundColor: Theme.of(context)
|
||||||
|
.colorScheme
|
||||||
|
.onError,
|
||||||
icon: Icons.delete,
|
icon: Icons.delete,
|
||||||
onPressed: (c) {
|
onPressed: (c) {
|
||||||
showDialog(
|
showDialog(
|
||||||
context: context,
|
context: context,
|
||||||
builder: (cx) => PlatformDialog(
|
builder: (cx) => PlatformDialog(
|
||||||
title: AppLocalizations.of(context)
|
title: AppLocalizations.of(
|
||||||
.sureDialog,
|
context,
|
||||||
|
).sureDialog,
|
||||||
content: Text(
|
content: Text(
|
||||||
AppLocalizations.of(context)
|
AppLocalizations.of(context)
|
||||||
.deleteSure,
|
.deleteSure,
|
||||||
),
|
),
|
||||||
actions: [
|
actions: [
|
||||||
PlatformButton(
|
PlatformButton(
|
||||||
text: AppLocalizations.of(context)
|
text: AppLocalizations.of(
|
||||||
.yes,
|
context,
|
||||||
|
).yes,
|
||||||
onPressed: () {
|
onPressed: () {
|
||||||
selectedWallet?.entries
|
selectedWallet?.entries
|
||||||
.removeWhere(
|
.removeWhere(
|
||||||
(e) => e.id == element.id,
|
(e) =>
|
||||||
|
e.id ==
|
||||||
|
element.id,
|
||||||
);
|
);
|
||||||
|
|
||||||
WalletManager.saveWallet(
|
WalletManager
|
||||||
|
.saveWallet(
|
||||||
selectedWallet!,
|
selectedWallet!,
|
||||||
);
|
);
|
||||||
Navigator.of(cx).pop();
|
Navigator.of(cx).pop();
|
||||||
|
@ -405,8 +480,9 @@ class _HomeViewState extends State<HomeView> {
|
||||||
},
|
},
|
||||||
),
|
),
|
||||||
PlatformButton(
|
PlatformButton(
|
||||||
text: AppLocalizations.of(context)
|
text: AppLocalizations.of(
|
||||||
.no,
|
context,
|
||||||
|
).no,
|
||||||
onPressed: () {
|
onPressed: () {
|
||||||
Navigator.of(cx).pop();
|
Navigator.of(cx).pop();
|
||||||
},
|
},
|
||||||
|
@ -421,7 +497,8 @@ class _HomeViewState extends State<HomeView> {
|
||||||
child: ListTile(
|
child: ListTile(
|
||||||
leading: Container(
|
leading: Container(
|
||||||
decoration: BoxDecoration(
|
decoration: BoxDecoration(
|
||||||
borderRadius: BorderRadius.circular(16),
|
borderRadius:
|
||||||
|
BorderRadius.circular(16),
|
||||||
color: element.category.color,
|
color: element.category.color,
|
||||||
),
|
),
|
||||||
child: Padding(
|
child: Padding(
|
||||||
|
@ -439,8 +516,8 @@ class _HomeViewState extends State<HomeView> {
|
||||||
children: [
|
children: [
|
||||||
TextSpan(
|
TextSpan(
|
||||||
text: NumberFormat.currency(
|
text: NumberFormat.currency(
|
||||||
symbol:
|
symbol: selectedWallet!
|
||||||
selectedWallet!.currency.symbol,
|
.currency.symbol,
|
||||||
).format(element.data.amount),
|
).format(element.data.amount),
|
||||||
style: TextStyle(
|
style: TextStyle(
|
||||||
color: (element.type ==
|
color: (element.type ==
|
||||||
|
@ -448,8 +525,10 @@ class _HomeViewState extends State<HomeView> {
|
||||||
? (MediaQuery.of(context)
|
? (MediaQuery.of(context)
|
||||||
.platformBrightness ==
|
.platformBrightness ==
|
||||||
Brightness.dark)
|
Brightness.dark)
|
||||||
? Colors.green.shade300
|
? Colors
|
||||||
: Colors.green.harmonizeWith(
|
.green.shade300
|
||||||
|
: Colors.green
|
||||||
|
.harmonizeWith(
|
||||||
Theme.of(context)
|
Theme.of(context)
|
||||||
.colorScheme
|
.colorScheme
|
||||||
.primary,
|
.primary,
|
||||||
|
@ -458,7 +537,8 @@ class _HomeViewState extends State<HomeView> {
|
||||||
.platformBrightness ==
|
.platformBrightness ==
|
||||||
Brightness.dark)
|
Brightness.dark)
|
||||||
? Colors.red.shade300
|
? Colors.red.shade300
|
||||||
: Colors.red.harmonizeWith(
|
: Colors.red
|
||||||
|
.harmonizeWith(
|
||||||
Theme.of(context)
|
Theme.of(context)
|
||||||
.colorScheme
|
.colorScheme
|
||||||
.primary,
|
.primary,
|
||||||
|
@ -485,6 +565,28 @@ class _HomeViewState extends State<HomeView> {
|
||||||
],
|
],
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
|
OverlayEntry(
|
||||||
|
builder: (context) => SizedBox(
|
||||||
|
width: MediaQuery.of(context).size.width,
|
||||||
|
height: MediaQuery.of(context).size.height,
|
||||||
|
child: GestureDetector(
|
||||||
|
onTap: () {
|
||||||
|
if (!_searchActive) return;
|
||||||
|
if (!searchFocus.hasFocus) {
|
||||||
|
_searchActive = false;
|
||||||
|
_filter = "";
|
||||||
|
setState(() {});
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
searchFocus.unfocus();
|
||||||
|
},
|
||||||
|
),
|
||||||
|
),
|
||||||
|
),
|
||||||
|
],
|
||||||
|
),
|
||||||
|
),
|
||||||
|
),
|
||||||
),
|
),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
|
@ -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+4
|
version: 1.0.0-alpha+5
|
||||||
|
|
||||||
environment:
|
environment:
|
||||||
sdk: '>=3.1.0-262.2.beta <4.0.0'
|
sdk: '>=3.1.0-262.2.beta <4.0.0'
|
||||||
|
|
Loading…
Reference in a new issue