1.0.0 release #31

Merged
hernik merged 31 commits from dev into main 2024-02-10 16:27:33 +01:00
Showing only changes of commit 2226d37f8f - Show all commits

View file

@ -24,6 +24,7 @@ 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';
@ -41,13 +42,15 @@ class HomeView extends StatefulWidget {
} }
class _HomeViewState extends State<HomeView> { class _HomeViewState extends State<HomeView> {
Wallet? selectedWallet; Wallet? selectedWallet; // current wallet
List<Wallet> wallets = []; List<Wallet> wallets = []; // all available wallets
DateTime? prevDate; DateTime? prevDate;
late String locale; late String locale; // user's locale
var _searchActive = false; var _searchActive = false; // whether search field is shown
var _filter = ""; var _filter = ""; // search filter
final searchFocus = FocusNode(); final searchFocus = FocusNode();
var sort = SortType.newest;
@override @override
void didChangeDependencies() { void didChangeDependencies() {
super.didChangeDependencies(); super.didChangeDependencies();
@ -191,8 +194,9 @@ class _HomeViewState extends State<HomeView> {
}, },
), ),
), ),
actions: [ actions: _searchActive
if (!_searchActive) ? []
: [
IconButton( IconButton(
onPressed: () { onPressed: () {
_searchActive = true; _searchActive = true;
@ -200,12 +204,38 @@ class _HomeViewState extends State<HomeView> {
}, },
icon: const Icon(Icons.search), icon: const Icon(Icons.search),
), ),
if (!_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;
setState(() {});
} else if (value ==
AppLocalizations.of(context).sortOldest) {
sort = SortType.oldest;
setState(() {});
}
},
),
PopupMenuButton( PopupMenuButton(
itemBuilder: (context) => [ itemBuilder: (context) => [
AppLocalizations.of(context).settings, AppLocalizations.of(context).settings,
AppLocalizations.of(context).about, AppLocalizations.of(context).about,
].map((e) => PopupMenuItem(value: e, child: Text(e))).toList(), ]
.map((e) => PopupMenuItem(value: e, child: Text(e)))
.toList(),
onSelected: (value) { onSelected: (value) {
if (value == AppLocalizations.of(context).settings) { if (value == AppLocalizations.of(context).settings) {
Navigator.of(context) Navigator.of(context)
@ -216,8 +246,8 @@ class _HomeViewState extends State<HomeView> {
) )
.then((value) async { .then((value) async {
wallets = await WalletManager.listWallets(); wallets = await WalletManager.listWallets();
selectedWallet = selectedWallet = await WalletManager.loadWallet(
await WalletManager.loadWallet(selectedWallet!.name); selectedWallet!.name);
}); });
} else if (value == AppLocalizations.of(context).about) { } else if (value == AppLocalizations.of(context).about) {
showAbout(context); showAbout(context);
@ -358,43 +388,15 @@ class _HomeViewState extends State<HomeView> {
) )
.toList(), .toList(),
itemComparator: (a, b) => itemComparator: (a, b) =>
b.date.compareTo(a.date), (sort == SortType.newest)
? 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) =>
// TODO: better sorting algorithm lol (sort == SortType.newest)
final yearA = ? groupSortNewest(a, b, locale)
RegExp(r'\d+').firstMatch(a); : groupSortOldest(a, b, locale),
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(),
@ -760,3 +762,12 @@ class _HomeViewState extends State<HomeView> {
); );
} }
} }
/// Represents entry sorting type
enum SortType {
/// Sort newest first
newest,
/// Sort oldest first
oldest
}