custom filters
This commit is contained in:
@@ -3,6 +3,7 @@ library;
|
||||
|
||||
import 'package:flutter/foundation.dart';
|
||||
|
||||
import '../models/home_built_in_sections.dart';
|
||||
import '../models/home_filter_widget.dart';
|
||||
import '../models/overview_favourite.dart';
|
||||
import '../services/storage_service.dart';
|
||||
@@ -12,12 +13,14 @@ class PreferencesController extends ChangeNotifier {
|
||||
_lookAheadMaxYears = _storage.lookAheadMaxYears;
|
||||
_overviewFavourites = _storage.loadOverviewFavourites();
|
||||
_homeFilterWidgets = _storage.loadHomeFilterWidgets();
|
||||
_homeBuiltInSections = _storage.loadHomeBuiltInSections();
|
||||
}
|
||||
|
||||
final StorageService _storage;
|
||||
late int _lookAheadMaxYears;
|
||||
late List<OverviewFavourite> _overviewFavourites;
|
||||
late List<HomeFilterWidget> _homeFilterWidgets;
|
||||
late HomeBuiltInSections _homeBuiltInSections;
|
||||
|
||||
/// Fired after favourites are persisted (for cloud push debounce).
|
||||
VoidCallback? onFavouritesPersisted;
|
||||
@@ -50,6 +53,31 @@ class PreferencesController extends ChangeNotifier {
|
||||
bool get hasDisplayedHomeFilterWidgets =>
|
||||
_homeFilterWidgets.any((w) => w.display);
|
||||
|
||||
HomeBuiltInSections get homeBuiltInSections => _homeBuiltInSections;
|
||||
|
||||
Future<void> setHomeBuiltInSections(HomeBuiltInSections sections) async {
|
||||
if (sections.showTransactions == _homeBuiltInSections.showTransactions &&
|
||||
sections.showCategorized == _homeBuiltInSections.showCategorized &&
|
||||
sections.showRecent == _homeBuiltInSections.showRecent) {
|
||||
return;
|
||||
}
|
||||
_homeBuiltInSections = sections;
|
||||
notifyListeners();
|
||||
await _storage.saveHomeBuiltInSections(sections);
|
||||
}
|
||||
|
||||
Future<void> setHomeShowTransactions(bool value) => setHomeBuiltInSections(
|
||||
_homeBuiltInSections.copyWith(showTransactions: value),
|
||||
);
|
||||
|
||||
Future<void> setHomeShowCategorized(bool value) => setHomeBuiltInSections(
|
||||
_homeBuiltInSections.copyWith(showCategorized: value),
|
||||
);
|
||||
|
||||
Future<void> setHomeShowRecent(bool value) => setHomeBuiltInSections(
|
||||
_homeBuiltInSections.copyWith(showRecent: value),
|
||||
);
|
||||
|
||||
Future<void> setLookAheadMaxYears(int years) async {
|
||||
final next = years.clamp(1, 30);
|
||||
if (next == _lookAheadMaxYears) return;
|
||||
@@ -149,6 +177,19 @@ class PreferencesController extends ChangeNotifier {
|
||||
await updateHomeFilterWidget(current.copyWith(display: display));
|
||||
}
|
||||
|
||||
Future<void> reorderHomeFilterWidgets(int oldIndex, int newIndex) async {
|
||||
if (oldIndex == newIndex) return;
|
||||
final next = [..._homeFilterWidgets];
|
||||
final item = next.removeAt(oldIndex);
|
||||
final target = newIndex.clamp(0, next.length);
|
||||
next.insert(target, item);
|
||||
_homeFilterWidgets = [
|
||||
for (var i = 0; i < next.length; i++) next[i].copyWith(sortOrder: i),
|
||||
];
|
||||
notifyListeners();
|
||||
await _persistHomeWidgets();
|
||||
}
|
||||
|
||||
Future<void> replaceHomeFilterWidgets(
|
||||
List<HomeFilterWidget> widgets, {
|
||||
bool notify = true,
|
||||
|
||||
Reference in New Issue
Block a user