feat: add basic sorting (#9)
also made some cosmetic changes elsewhere,
This commit is contained in:
parent
2226d37f8f
commit
943bf15aab
6 changed files with 81 additions and 10 deletions
|
@ -4,6 +4,9 @@
|
|||
- 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
|
||||
|
|
|
@ -106,5 +106,9 @@
|
|||
"exportCompleted":"Export dokončen",
|
||||
"importCompleted":"Import dokončen",
|
||||
"setup":"Prvotní nastavení",
|
||||
"sourceCode":"Zdrojový kód"
|
||||
"sourceCode":"Zdrojový kód",
|
||||
"sortNewest":"Nejnovější první",
|
||||
"sortOldest":"Nejstarší první",
|
||||
"sort":"Seřadit",
|
||||
"search":"Prohledat"
|
||||
}
|
|
@ -222,5 +222,9 @@
|
|||
"exportCompleted":"Export completed",
|
||||
"importCompleted":"Import completed",
|
||||
"setup":"Setup",
|
||||
"sourceCode":"Source code"
|
||||
"sourceCode":"Source code",
|
||||
"sortNewest":"Newest first",
|
||||
"sortOldest":"Oldest first",
|
||||
"sort":"Sort",
|
||||
"search":"Search"
|
||||
}
|
58
lib/util/sorting.dart
Normal file
58
lib/util/sorting.dart
Normal file
|
@ -0,0 +1,58 @@
|
|||
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)!),
|
||||
);
|
||||
}
|
|
@ -197,13 +197,6 @@ class _HomeViewState extends State<HomeView> {
|
|||
actions: _searchActive
|
||||
? []
|
||||
: [
|
||||
IconButton(
|
||||
onPressed: () {
|
||||
_searchActive = true;
|
||||
setState(() {});
|
||||
},
|
||||
icon: const Icon(Icons.search),
|
||||
),
|
||||
PopupMenuButton(
|
||||
tooltip: AppLocalizations.of(context).sort,
|
||||
icon: const Icon(Icons.sort_rounded),
|
||||
|
@ -232,6 +225,7 @@ class _HomeViewState extends State<HomeView> {
|
|||
PopupMenuButton(
|
||||
itemBuilder: (context) => [
|
||||
AppLocalizations.of(context).settings,
|
||||
AppLocalizations.of(context).search,
|
||||
AppLocalizations.of(context).about,
|
||||
]
|
||||
.map((e) => PopupMenuItem(value: e, child: Text(e)))
|
||||
|
@ -251,6 +245,12 @@ class _HomeViewState extends State<HomeView> {
|
|||
});
|
||||
} else if (value == AppLocalizations.of(context).about) {
|
||||
showAbout(context);
|
||||
} else if (value == AppLocalizations.of(context).search) {
|
||||
_searchActive = !_searchActive;
|
||||
if (!_searchActive) {
|
||||
_filter = "";
|
||||
}
|
||||
setState(() {});
|
||||
}
|
||||
},
|
||||
),
|
||||
|
@ -384,7 +384,8 @@ class _HomeViewState extends State<HomeView> {
|
|||
elements: selectedWallet!.entries
|
||||
.where(
|
||||
(element) => element.data.name
|
||||
.contains(_filter),
|
||||
.toLowerCase()
|
||||
.contains(_filter.toLowerCase()),
|
||||
)
|
||||
.toList(),
|
||||
itemComparator: (a, b) =>
|
||||
|
|
|
@ -57,6 +57,7 @@ class _SetupViewState extends State<SetupView> {
|
|||
void didChangeDependencies() {
|
||||
super.didChangeDependencies();
|
||||
if (categories.isEmpty) {
|
||||
name = AppLocalizations.of(context).setupNamePlaceholder;
|
||||
categories = [
|
||||
WalletCategory(
|
||||
name: AppLocalizations.of(context).noCategory,
|
||||
|
|
Loading…
Reference in a new issue