Compare commits

..

1 commit

Author SHA1 Message Date
Matyáš Caras
5ce09b1930
Added translation using Weblate (Slovak) 2024-01-29 19:42:53 +01:00
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 - Placeholder text is now inserted into the field in setup, instead of showing as label
- Show version text in about dialog - Show version text in about dialog
- Added tessdata license text into 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 # 1.0.0-alpha+5
- Add tests - Add tests
- Add searching through entries to homepage - Add searching through entries to homepage

View file

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

View file

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

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/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/sorting.dart';
import 'package:prasule/util/text_color.dart'; import 'package:prasule/util/text_color.dart';
import 'package:prasule/util/utils.dart'; import 'package:prasule/util/utils.dart';
import 'package:prasule/views/create_entry.dart'; import 'package:prasule/views/create_entry.dart';
@ -42,15 +41,13 @@ class HomeView extends StatefulWidget {
} }
class _HomeViewState extends State<HomeView> { class _HomeViewState extends State<HomeView> {
Wallet? selectedWallet; // current wallet Wallet? selectedWallet;
List<Wallet> wallets = []; // all available wallets List<Wallet> wallets = [];
DateTime? prevDate; DateTime? prevDate;
late String locale; // user's locale late String locale;
var _searchActive = false; // whether search field is shown var _searchActive = false;
var _filter = ""; // search filter var _filter = "";
final searchFocus = FocusNode(); final searchFocus = FocusNode();
var sort = SortType.newest;
@override @override
void didChangeDependencies() { void didChangeDependencies() {
super.didChangeDependencies(); super.didChangeDependencies();
@ -194,67 +191,40 @@ class _HomeViewState extends State<HomeView> {
}, },
), ),
), ),
actions: _searchActive actions: [
? [] if (!_searchActive)
: [ IconButton(
PopupMenuButton( onPressed: () {
tooltip: AppLocalizations.of(context).sort, _searchActive = true;
icon: const Icon(Icons.sort_rounded), setState(() {});
itemBuilder: (context) => [ },
AppLocalizations.of(context).sortNewest, icon: const Icon(Icons.search),
AppLocalizations.of(context).sortOldest, ),
] if (!_searchActive)
.map( PopupMenuButton(
(e) => PopupMenuItem( itemBuilder: (context) => [
value: e, AppLocalizations.of(context).settings,
child: Text(e), AppLocalizations.of(context).about,
), ].map((e) => PopupMenuItem(value: e, child: Text(e))).toList(),
) onSelected: (value) {
.toList(), if (value == AppLocalizations.of(context).settings) {
onSelected: (value) { Navigator.of(context)
if (value == AppLocalizations.of(context).sortNewest) { .push(
sort = SortType.newest; platformRoute(
setState(() {}); (context) => const SettingsView(),
} else if (value == ),
AppLocalizations.of(context).sortOldest) { )
sort = SortType.oldest; .then((value) async {
setState(() {}); wallets = await WalletManager.listWallets();
} selectedWallet =
}, await WalletManager.loadWallet(selectedWallet!.name);
), });
PopupMenuButton( } else if (value == AppLocalizations.of(context).about) {
itemBuilder: (context) => [ showAbout(context);
AppLocalizations.of(context).settings, }
AppLocalizations.of(context).search, },
AppLocalizations.of(context).about, ),
] ],
.map((e) => PopupMenuItem(value: e, child: Text(e)))
.toList(),
onSelected: (value) {
if (value == AppLocalizations.of(context).settings) {
Navigator.of(context)
.push(
platformRoute(
(context) => const SettingsView(),
),
)
.then((value) async {
wallets = await WalletManager.listWallets();
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(() {});
}
},
),
],
), ),
body: Center( body: Center(
child: SizedBox( child: SizedBox(
@ -384,20 +354,47 @@ class _HomeViewState extends State<HomeView> {
elements: selectedWallet!.entries elements: selectedWallet!.entries
.where( .where(
(element) => element.data.name (element) => element.data.name
.toLowerCase() .contains(_filter),
.contains(_filter.toLowerCase()),
) )
.toList(), .toList(),
itemComparator: (a, b) => itemComparator: (a, b) =>
(sort == SortType.newest) b.date.compareTo(a.date),
? b.date.compareTo(a.date)
: a.date.compareTo(b.date),
groupBy: (e) => groupBy: (e) =>
DateFormat.yMMMM(locale).format(e.date), DateFormat.yMMMM(locale).format(e.date),
groupComparator: (a, b) => groupComparator: (a, b) {
(sort == SortType.newest) // TODO: better sorting algorithm lol
? groupSortNewest(a, b, locale) final yearA =
: groupSortOldest(a, b, locale), 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( itemBuilder: (context, element) => Slidable(
endActionPane: ActionPane( endActionPane: ActionPane(
motion: const ScrollMotion(), 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() { void didChangeDependencies() {
super.didChangeDependencies(); super.didChangeDependencies();
if (categories.isEmpty) { if (categories.isEmpty) {
name = AppLocalizations.of(context).setupNamePlaceholder;
categories = [ categories = [
WalletCategory( WalletCategory(
name: AppLocalizations.of(context).noCategory, name: AppLocalizations.of(context).noCategory,