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
throw UnimplementedError();
}
}
class LandingPage extends HomeScreenWidget {
LandingPage({Key? key}) : super(key: key);
@ -31,10 +28,10 @@ class LandingPage extends HomeScreenWidget {
State<StatefulWidget> createState() => LandingPageState();
}
class LandingPageState extends State<LandingPage>
with AfterLayoutMixin<LandingPage> {
int? defaultList;
bool onlyDueDate = true;
List<Task> _tasks = [];
PageStatus landingPageStatus = PageStatus.built;
static const platform = const MethodChannel('vikunja');
@ -56,6 +53,7 @@ class LandingPageState extends State<LandingPage>
} catch (e) {
log(e.toString());
}
VikunjaGlobal.of(context).settingsManager.getLandingPageOnlyDueDateTasks().then((value) => onlyDueDate = value);
}));
super.initState();
}
@ -105,10 +103,8 @@ class LandingPageState extends State<LandingPage>
]);
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<LandingPage>
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<LandingPage>
_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<Future<void>?>((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<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",
"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<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() {
return _storage.read(key: "get-version-notifications");