diff --git a/lib/pages/landing_page.dart b/lib/pages/landing_page.dart index d4c3f1a..670ac96 100644 --- a/lib/pages/landing_page.dart +++ b/lib/pages/landing_page.dart @@ -19,11 +19,8 @@ class HomeScreenWidget extends StatefulWidget { // TODO: implement createState throw UnimplementedError(); } - - } - class LandingPage extends HomeScreenWidget { LandingPage({Key? key}) : super(key: key); @@ -31,10 +28,10 @@ class LandingPage extends HomeScreenWidget { State createState() => LandingPageState(); } - class LandingPageState extends State with AfterLayoutMixin { int? defaultList; + bool onlyDueDate = true; List _tasks = []; PageStatus landingPageStatus = PageStatus.built; static const platform = const MethodChannel('vikunja'); @@ -56,6 +53,7 @@ class LandingPageState extends State } catch (e) { log(e.toString()); } + VikunjaGlobal.of(context).settingsManager.getLandingPageOnlyDueDateTasks().then((value) => onlyDueDate = value); })); super.initState(); } @@ -105,10 +103,8 @@ class LandingPageState extends State ]); break; case PageStatus.empty: - body = new Stack(children: [ - ListView(), - Center(child: Text("This view is empty")) - ]); + body = new Stack( + children: [ListView(), Center(child: Text("This view is empty"))]); break; case PageStatus.success: body = ListView( @@ -121,19 +117,44 @@ class LandingPageState extends State break; } return new Scaffold( - body: - RefreshIndicator(onRefresh: () => _loadList(context), child: body), - floatingActionButton: Builder( - builder: (context) => FloatingActionButton( - onPressed: () { - _addItemDialog(context); - }, - child: const Icon(Icons.add), - )), + body: RefreshIndicator(onRefresh: () => _loadList(context), child: body), + floatingActionButton: Builder( + builder: (context) => FloatingActionButton( + onPressed: () { + _addItemDialog(context); + }, + child: const Icon(Icons.add), + )), appBar: AppBar( title: Text("Vikunja"), + actions: [ + PopupMenuButton(itemBuilder: (BuildContext context) { + return [ + PopupMenuItem( + child: + InkWell( + onTap: () { + Navigator.pop(context); + bool newval = !onlyDueDate; + VikunjaGlobal.of(context).settingsManager.setLandingPageOnlyDueDateTasks(newval).then((value) { + setState(() { + onlyDueDate = newval; + _loadList(context); + }); + }); + }, + child: + Row(mainAxisAlignment: MainAxisAlignment.end, children: [ + Text("Only show tasks with due date"), + Checkbox( + value: onlyDueDate, + onChanged: (bool? value) { }, + ) + ]))) + ]; + }), + ], ), - ); } @@ -196,27 +217,41 @@ class LandingPageState extends State _tasks = []; landingPageStatus = PageStatus.loading; // FIXME: loads and reschedules tasks each time list is updated - VikunjaGlobal.of(context).notifications.scheduleDueNotifications(VikunjaGlobal.of(context).taskService); + VikunjaGlobal.of(context) + .notifications + .scheduleDueNotifications(VikunjaGlobal.of(context).taskService); return VikunjaGlobal.of(context) - .taskService - .getByOptions(TaskServiceOptions()) - .then?>((taskList) { - if (taskList != null && taskList.isEmpty) { - setState(() { - landingPageStatus = PageStatus.empty; - }); - return null; + .settingsManager + .getLandingPageOnlyDueDateTasks() + .then((showOnlyDueDateTasks) { + if (!showOnlyDueDateTasks) { + return VikunjaGlobal.of(context).taskService.getAll().then((value) => _handleTaskList(value)); + } else { + return VikunjaGlobal + .of(context) + .taskService + .getByOptions(TaskServiceOptions()) + .then?>((taskList) => _handleTaskList(taskList)); } - //taskList.forEach((task) {task.list = lists.firstWhere((element) => element.id == task.list_id);}); - setState(() { - if (taskList != null) { - _tasks = taskList; - landingPageStatus = PageStatus.success; - } else { - landingPageStatus = PageStatus.error; - } }); - return null; + } + + Future _handleTaskList(List? taskList) { + if (taskList != null && taskList.isEmpty) { + setState(() { + landingPageStatus = PageStatus.empty; + }); + return Future.value(); + } + //taskList.forEach((task) {task.list = lists.firstWhere((element) => element.id == task.list_id);}); + setState(() { + if (taskList != null) { + _tasks = taskList; + landingPageStatus = PageStatus.success; + } else { + landingPageStatus = PageStatus.error; + } }); + return Future.value(); } } diff --git a/lib/service/services.dart b/lib/service/services.dart index 9a4f7b9..f8b99e5 100644 --- a/lib/service/services.dart +++ b/lib/service/services.dart @@ -259,6 +259,7 @@ class SettingsManager { "workmanager-duration": "0", "recent-servers": "[\"https://try.vikunja.io\"]", "theme_mode": "system", + "landing-page-due-date-tasks": "1" }; void applydefaults() { @@ -283,6 +284,13 @@ class SettingsManager { _storage.write(key: "ignore-certificates", value: value ? "1" : "0"); } + Future getLandingPageOnlyDueDateTasks() { + return _storage.read(key: "landing-page-due-date-tasks").then((value) => value == "1"); + } + Future setLandingPageOnlyDueDateTasks(bool value) { + return _storage.write(key: "landing-page-due-date-tasks", value: value ? "1" : "0"); + } + Future getVersionNotifications() { return _storage.read(key: "get-version-notifications");