Compare commits

..

No commits in common. "943bf15aab09dd2dc5bac120714a4e44485e4cea" and "095e2f62ba00a16ff388e43fb50540ea10ec0a04" have entirely different histories.

6 changed files with 77 additions and 159 deletions

View file

@ -4,9 +4,6 @@
- Placeholder text is now inserted into the field in setup, instead of showing as label
- Show version text in about dialog
- Added tessdata license text into about dialog
- Added sorting by oldest
- Moved search into three-dot menu
- Make search case-insensitive
# 1.0.0-alpha+5
- Add tests
- Add searching through entries to homepage

View file

@ -106,9 +106,5 @@
"exportCompleted":"Export dokončen",
"importCompleted":"Import dokončen",
"setup":"Prvotní nastavení",
"sourceCode":"Zdrojový kód",
"sortNewest":"Nejnovější první",
"sortOldest":"Nejstarší první",
"sort":"Seřadit",
"search":"Prohledat"
"sourceCode":"Zdrojový kód"
}

View file

@ -222,9 +222,5 @@
"exportCompleted":"Export completed",
"importCompleted":"Import completed",
"setup":"Setup",
"sourceCode":"Source code",
"sortNewest":"Newest first",
"sortOldest":"Oldest first",
"sort":"Sort",
"search":"Search"
"sourceCode":"Source code"
}

View file

@ -1,58 +0,0 @@
import 'package:grouped_list/grouped_list.dart';
import 'package:intl/intl.dart';
/// Sorts [GroupedListView]'s group by newest group
int groupSortNewest(String a, String b, String locale) {
// 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)!),
);
}
/// Sorts [GroupedListView]'s group by oldest group
int groupSortOldest(String a, String b, String locale) {
// 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(yearA.group(0)!).compareTo(
int.parse(yearB.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(monthA.group(0)!).compareTo(
months.indexOf(monthB.group(0)!),
);
}

View file

@ -24,7 +24,6 @@ import 'package:prasule/pw/platformbutton.dart';
import 'package:prasule/pw/platformfield.dart';
import 'package:prasule/pw/platformroute.dart';
import 'package:prasule/util/drawer.dart';
import 'package:prasule/util/sorting.dart';
import 'package:prasule/util/text_color.dart';
import 'package:prasule/util/utils.dart';
import 'package:prasule/views/create_entry.dart';
@ -42,15 +41,13 @@ class HomeView extends StatefulWidget {
}
class _HomeViewState extends State<HomeView> {
Wallet? selectedWallet; // current wallet
List<Wallet> wallets = []; // all available wallets
Wallet? selectedWallet;
List<Wallet> wallets = [];
DateTime? prevDate;
late String locale; // user's locale
var _searchActive = false; // whether search field is shown
var _filter = ""; // search filter
late String locale;
var _searchActive = false;
var _filter = "";
final searchFocus = FocusNode();
var sort = SortType.newest;
@override
void didChangeDependencies() {
super.didChangeDependencies();
@ -194,42 +191,21 @@ class _HomeViewState extends State<HomeView> {
},
),
),
actions: _searchActive
? []
: [
PopupMenuButton(
tooltip: AppLocalizations.of(context).sort,
icon: const Icon(Icons.sort_rounded),
itemBuilder: (context) => [
AppLocalizations.of(context).sortNewest,
AppLocalizations.of(context).sortOldest,
]
.map(
(e) => PopupMenuItem(
value: e,
child: Text(e),
),
)
.toList(),
onSelected: (value) {
if (value == AppLocalizations.of(context).sortNewest) {
sort = SortType.newest;
actions: [
if (!_searchActive)
IconButton(
onPressed: () {
_searchActive = true;
setState(() {});
} else if (value ==
AppLocalizations.of(context).sortOldest) {
sort = SortType.oldest;
setState(() {});
}
},
icon: const Icon(Icons.search),
),
if (!_searchActive)
PopupMenuButton(
itemBuilder: (context) => [
AppLocalizations.of(context).settings,
AppLocalizations.of(context).search,
AppLocalizations.of(context).about,
]
.map((e) => PopupMenuItem(value: e, child: Text(e)))
.toList(),
].map((e) => PopupMenuItem(value: e, child: Text(e))).toList(),
onSelected: (value) {
if (value == AppLocalizations.of(context).settings) {
Navigator.of(context)
@ -240,17 +216,11 @@ class _HomeViewState extends State<HomeView> {
)
.then((value) async {
wallets = await WalletManager.listWallets();
selectedWallet = await WalletManager.loadWallet(
selectedWallet!.name);
selectedWallet =
await WalletManager.loadWallet(selectedWallet!.name);
});
} else if (value == AppLocalizations.of(context).about) {
showAbout(context);
} else if (value == AppLocalizations.of(context).search) {
_searchActive = !_searchActive;
if (!_searchActive) {
_filter = "";
}
setState(() {});
}
},
),
@ -384,20 +354,47 @@ class _HomeViewState extends State<HomeView> {
elements: selectedWallet!.entries
.where(
(element) => element.data.name
.toLowerCase()
.contains(_filter.toLowerCase()),
.contains(_filter),
)
.toList(),
itemComparator: (a, b) =>
(sort == SortType.newest)
? b.date.compareTo(a.date)
: a.date.compareTo(b.date),
b.date.compareTo(a.date),
groupBy: (e) =>
DateFormat.yMMMM(locale).format(e.date),
groupComparator: (a, b) =>
(sort == SortType.newest)
? groupSortNewest(a, b, locale)
: groupSortOldest(a, b, locale),
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(),
@ -763,12 +760,3 @@ class _HomeViewState extends State<HomeView> {
);
}
}
/// Represents entry sorting type
enum SortType {
/// Sort newest first
newest,
/// Sort oldest first
oldest
}

View file

@ -57,7 +57,6 @@ class _SetupViewState extends State<SetupView> {
void didChangeDependencies() {
super.didChangeDependencies();
if (categories.isEmpty) {
name = AppLocalizations.of(context).setupNamePlaceholder;
categories = [
WalletCategory(
name: AppLocalizations.of(context).noCategory,