Skip to content

Commit

Permalink
added option to select what to see on landing page
Browse files Browse the repository at this point in the history
  • Loading branch information
Benimautner committed Jul 23, 2023
1 parent c7a5563 commit 6b276e5
Show file tree
Hide file tree
Showing 2 changed files with 79 additions and 36 deletions.
107 changes: 71 additions & 36 deletions lib/pages/landing_page.dart
Original file line number Diff line number Diff line change
Expand Up @@ -19,22 +19,19 @@ class HomeScreenWidget extends StatefulWidget {
// TODO: implement createState
throw UnimplementedError();
}


}


class LandingPage extends HomeScreenWidget {
LandingPage({Key? key}) : super(key: key);

@override
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');
Expand All @@ -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();
}
Expand Down Expand Up @@ -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(
Expand All @@ -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) { },
)
])))
];
}),
],
),

);
}

Expand Down Expand Up @@ -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();
}
}
8 changes: 8 additions & 0 deletions lib/service/services.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand All @@ -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");
Expand Down

0 comments on commit 6b276e5

Please sign in to comment.