1
0
mirror of https://github.com/go-vikunja/app synced 2024-06-01 02:06:51 +00:00

added option to select what to see on landing page

This commit is contained in:
Benimautner 2023-07-23 22:34:10 +02:00
parent c7a556311d
commit 6b276e511d
2 changed files with 79 additions and 36 deletions

View File

@ -19,11 +19,8 @@ class HomeScreenWidget extends StatefulWidget {
// TODO: implement createState // TODO: implement createState
throw UnimplementedError(); throw UnimplementedError();
} }
} }
class LandingPage extends HomeScreenWidget { class LandingPage extends HomeScreenWidget {
LandingPage({Key? key}) : super(key: key); LandingPage({Key? key}) : super(key: key);
@ -31,10 +28,10 @@ class LandingPage extends HomeScreenWidget {
State<StatefulWidget> createState() => LandingPageState(); State<StatefulWidget> createState() => LandingPageState();
} }
class LandingPageState extends State<LandingPage> class LandingPageState extends State<LandingPage>
with AfterLayoutMixin<LandingPage> { with AfterLayoutMixin<LandingPage> {
int? defaultList; int? defaultList;
bool onlyDueDate = true;
List<Task> _tasks = []; List<Task> _tasks = [];
PageStatus landingPageStatus = PageStatus.built; PageStatus landingPageStatus = PageStatus.built;
static const platform = const MethodChannel('vikunja'); static const platform = const MethodChannel('vikunja');
@ -56,6 +53,7 @@ class LandingPageState extends State<LandingPage>
} catch (e) { } catch (e) {
log(e.toString()); log(e.toString());
} }
VikunjaGlobal.of(context).settingsManager.getLandingPageOnlyDueDateTasks().then((value) => onlyDueDate = value);
})); }));
super.initState(); super.initState();
} }
@ -105,10 +103,8 @@ class LandingPageState extends State<LandingPage>
]); ]);
break; break;
case PageStatus.empty: case PageStatus.empty:
body = new Stack(children: [ body = new Stack(
ListView(), children: [ListView(), Center(child: Text("This view is empty"))]);
Center(child: Text("This view is empty"))
]);
break; break;
case PageStatus.success: case PageStatus.success:
body = ListView( body = ListView(
@ -121,19 +117,44 @@ class LandingPageState extends State<LandingPage>
break; break;
} }
return new Scaffold( return new Scaffold(
body: body: RefreshIndicator(onRefresh: () => _loadList(context), child: body),
RefreshIndicator(onRefresh: () => _loadList(context), child: body), floatingActionButton: Builder(
floatingActionButton: Builder( builder: (context) => FloatingActionButton(
builder: (context) => FloatingActionButton( onPressed: () {
onPressed: () { _addItemDialog(context);
_addItemDialog(context); },
}, child: const Icon(Icons.add),
child: const Icon(Icons.add), )),
)),
appBar: AppBar( appBar: AppBar(
title: Text("Vikunja"), 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<LandingPage>
_tasks = []; _tasks = [];
landingPageStatus = PageStatus.loading; landingPageStatus = PageStatus.loading;
// FIXME: loads and reschedules tasks each time list is updated // 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) return VikunjaGlobal.of(context)
.taskService .settingsManager
.getByOptions(TaskServiceOptions()) .getLandingPageOnlyDueDateTasks()
.then<Future<void>?>((taskList) { .then((showOnlyDueDateTasks) {
if (taskList != null && taskList.isEmpty) { if (!showOnlyDueDateTasks) {
setState(() { return VikunjaGlobal.of(context).taskService.getAll().then((value) => _handleTaskList(value));
landingPageStatus = PageStatus.empty; } else {
}); return VikunjaGlobal
return null; .of(context)
.taskService
.getByOptions(TaskServiceOptions())
.then<Future<void>?>((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<void> _handleTaskList(List<Task>? 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();
} }
} }

View File

@ -259,6 +259,7 @@ class SettingsManager {
"workmanager-duration": "0", "workmanager-duration": "0",
"recent-servers": "[\"https://try.vikunja.io\"]", "recent-servers": "[\"https://try.vikunja.io\"]",
"theme_mode": "system", "theme_mode": "system",
"landing-page-due-date-tasks": "1"
}; };
void applydefaults() { void applydefaults() {
@ -283,6 +284,13 @@ class SettingsManager {
_storage.write(key: "ignore-certificates", value: value ? "1" : "0"); _storage.write(key: "ignore-certificates", value: value ? "1" : "0");
} }
Future<bool> getLandingPageOnlyDueDateTasks() {
return _storage.read(key: "landing-page-due-date-tasks").then((value) => value == "1");
}
Future<void> setLandingPageOnlyDueDateTasks(bool value) {
return _storage.write(key: "landing-page-due-date-tasks", value: value ? "1" : "0");
}
Future<String?> getVersionNotifications() { Future<String?> getVersionNotifications() {
return _storage.read(key: "get-version-notifications"); return _storage.read(key: "get-version-notifications");