2022-04-12 22:32:21 +00:00
|
|
|
import 'package:flutter/material.dart';
|
2023-05-10 21:50:30 +00:00
|
|
|
import 'package:permission_handler/permission_handler.dart';
|
2022-04-12 22:32:21 +00:00
|
|
|
import 'package:vikunja_app/global.dart';
|
2024-01-05 22:07:41 +00:00
|
|
|
import 'package:collection/collection.dart';
|
2022-04-12 22:32:21 +00:00
|
|
|
|
2023-05-17 10:52:26 +00:00
|
|
|
import '../main.dart';
|
2023-07-22 23:50:55 +00:00
|
|
|
import '../models/project.dart';
|
2023-12-23 21:38:16 +00:00
|
|
|
import '../models/user.dart';
|
2023-07-23 15:25:58 +00:00
|
|
|
import '../service/services.dart';
|
2023-05-17 10:52:26 +00:00
|
|
|
|
2022-04-12 22:32:21 +00:00
|
|
|
class SettingsPage extends StatefulWidget {
|
|
|
|
@override
|
|
|
|
State<StatefulWidget> createState() => SettingsPageState();
|
|
|
|
}
|
|
|
|
|
|
|
|
class SettingsPageState extends State<SettingsPage> {
|
2023-07-22 23:50:55 +00:00
|
|
|
List<Project>? projectList;
|
|
|
|
int? defaultProject;
|
2022-08-27 21:04:43 +00:00
|
|
|
bool? ignoreCertificates;
|
2024-09-26 11:31:26 +00:00
|
|
|
bool? sentryEnabled;
|
2023-01-07 02:55:29 +00:00
|
|
|
bool? getVersionNotifications;
|
2023-01-07 01:17:00 +00:00
|
|
|
String? versionTag, newestVersionTag;
|
2023-01-07 15:55:40 +00:00
|
|
|
late TextEditingController durationTextController;
|
|
|
|
bool initialized = false;
|
2023-07-23 15:25:58 +00:00
|
|
|
FlutterThemeMode? themeMode;
|
2023-12-23 21:38:16 +00:00
|
|
|
User? currentUser;
|
2023-05-17 10:52:26 +00:00
|
|
|
|
2023-01-07 15:55:40 +00:00
|
|
|
void init() {
|
|
|
|
durationTextController = TextEditingController();
|
|
|
|
|
|
|
|
VikunjaGlobal.of(context)
|
2023-07-22 23:50:55 +00:00
|
|
|
.projectService
|
2023-01-07 15:55:40 +00:00
|
|
|
.getAll()
|
2023-07-22 23:50:55 +00:00
|
|
|
.then((value) => setState(() => projectList = value));
|
2023-01-07 15:55:40 +00:00
|
|
|
|
|
|
|
VikunjaGlobal.of(context).settingsManager.getIgnoreCertificates().then(
|
|
|
|
(value) =>
|
|
|
|
setState(() => ignoreCertificates = value == "1" ? true : false));
|
2023-01-07 02:55:29 +00:00
|
|
|
|
2024-09-26 11:31:26 +00:00
|
|
|
VikunjaGlobal.of(context)
|
|
|
|
.settingsManager
|
|
|
|
.getSentryEnabled()
|
|
|
|
.then((value) => setState(() => sentryEnabled = value));
|
|
|
|
|
2023-01-07 15:55:40 +00:00
|
|
|
VikunjaGlobal.of(context).settingsManager.getVersionNotifications().then(
|
|
|
|
(value) => setState(
|
|
|
|
() => getVersionNotifications = value == "1" ? true : false));
|
2023-01-07 02:55:29 +00:00
|
|
|
|
2023-01-07 15:55:40 +00:00
|
|
|
VikunjaGlobal.of(context)
|
|
|
|
.versionChecker
|
|
|
|
.getCurrentVersionTag()
|
|
|
|
.then((value) => setState(() => versionTag = value));
|
2023-01-07 02:55:29 +00:00
|
|
|
|
2024-04-05 20:36:56 +00:00
|
|
|
VikunjaGlobal.of(context).settingsManager.getWorkmanagerDuration().then(
|
|
|
|
(value) => setState(
|
|
|
|
() => durationTextController.text = (value.inMinutes.toString())));
|
|
|
|
|
2023-01-07 15:55:40 +00:00
|
|
|
VikunjaGlobal.of(context)
|
|
|
|
.settingsManager
|
2024-04-05 20:36:56 +00:00
|
|
|
.getThemeMode()
|
|
|
|
.then((value) => setState(() => themeMode = value));
|
2023-05-17 10:52:26 +00:00
|
|
|
|
2023-12-23 21:38:16 +00:00
|
|
|
VikunjaGlobal.of(context).newUserService?.getCurrentUser().then((value) => {
|
2024-04-05 20:36:56 +00:00
|
|
|
setState(() {
|
|
|
|
currentUser = value!;
|
|
|
|
defaultProject = value.settings?.default_project_id;
|
|
|
|
}),
|
|
|
|
});
|
2023-12-23 21:38:16 +00:00
|
|
|
|
2023-01-07 15:55:40 +00:00
|
|
|
initialized = true;
|
|
|
|
}
|
2022-07-18 21:25:47 +00:00
|
|
|
|
2023-01-07 15:55:40 +00:00
|
|
|
@override
|
|
|
|
Widget build(BuildContext context) {
|
2023-12-23 21:38:16 +00:00
|
|
|
final global = VikunjaGlobal.of(context);
|
2023-01-07 15:55:40 +00:00
|
|
|
if (!initialized) init();
|
2022-04-12 22:32:21 +00:00
|
|
|
return new Scaffold(
|
2024-04-05 20:36:56 +00:00
|
|
|
appBar: AppBar(
|
|
|
|
title: Text("Settings"),
|
|
|
|
),
|
2023-05-17 10:28:55 +00:00
|
|
|
body: ListView(
|
2022-04-12 22:32:21 +00:00
|
|
|
children: [
|
2023-05-15 22:26:01 +00:00
|
|
|
UserAccountsDrawerHeader(
|
2024-04-05 20:36:56 +00:00
|
|
|
accountName:
|
|
|
|
currentUser != null ? Text(currentUser!.username) : null,
|
2023-12-23 21:38:16 +00:00
|
|
|
accountEmail: currentUser != null ? Text(currentUser!.name) : null,
|
2023-05-15 22:26:01 +00:00
|
|
|
currentAccountPicture: currentUser == null
|
|
|
|
? null
|
|
|
|
: CircleAvatar(
|
2024-04-05 20:36:56 +00:00
|
|
|
backgroundImage: (currentUser?.username != "")
|
|
|
|
? NetworkImage(currentUser!.avatarUrl(context))
|
|
|
|
: null,
|
|
|
|
),
|
2023-05-15 22:26:01 +00:00
|
|
|
decoration: BoxDecoration(
|
|
|
|
image: DecorationImage(
|
|
|
|
image: AssetImage("assets/graphics/hypnotize.png"),
|
|
|
|
repeat: ImageRepeat.repeat,
|
|
|
|
colorFilter: ColorFilter.mode(
|
|
|
|
Theme.of(context).primaryColor, BlendMode.multiply)),
|
|
|
|
),
|
|
|
|
),
|
2023-07-22 23:50:55 +00:00
|
|
|
projectList != null
|
2023-01-07 02:55:29 +00:00
|
|
|
? ListTile(
|
|
|
|
title: Text("Default List"),
|
|
|
|
trailing: DropdownButton<int>(
|
|
|
|
items: [
|
|
|
|
DropdownMenuItem(
|
|
|
|
child: Text("None"),
|
|
|
|
value: null,
|
|
|
|
),
|
2023-07-22 23:50:55 +00:00
|
|
|
...projectList!
|
2023-01-07 02:55:29 +00:00
|
|
|
.map((e) => DropdownMenuItem(
|
|
|
|
child: Text(e.title), value: e.id))
|
|
|
|
.toList()
|
|
|
|
],
|
2024-04-05 20:36:56 +00:00
|
|
|
value: projectList?.firstWhereOrNull(
|
|
|
|
(element) => element.id == defaultProject) !=
|
|
|
|
null
|
|
|
|
? defaultProject
|
|
|
|
: null,
|
2023-01-07 02:55:29 +00:00
|
|
|
onChanged: (int? value) {
|
2023-07-22 23:50:55 +00:00
|
|
|
setState(() => defaultProject = value);
|
2024-04-05 20:36:56 +00:00
|
|
|
global.newUserService
|
|
|
|
?.setCurrentUserSettings(currentUser!.settings!
|
|
|
|
.copyWith(default_project_id: value))
|
|
|
|
.then((value) => currentUser!.settings = value);
|
2023-12-23 21:38:16 +00:00
|
|
|
//VikunjaGlobal.of(context).userManager.setDefaultList(value);
|
2023-01-07 02:55:29 +00:00
|
|
|
},
|
|
|
|
),
|
|
|
|
)
|
|
|
|
: ListTile(
|
|
|
|
title: Text("..."),
|
|
|
|
),
|
2023-05-15 22:26:01 +00:00
|
|
|
Divider(),
|
2023-05-17 10:52:26 +00:00
|
|
|
ListTile(
|
|
|
|
title: Text("Theme"),
|
2023-07-23 15:25:58 +00:00
|
|
|
trailing: DropdownButton<FlutterThemeMode>(
|
2023-05-17 10:52:26 +00:00
|
|
|
items: [
|
|
|
|
DropdownMenuItem(
|
|
|
|
child: Text("System"),
|
2023-07-23 15:25:58 +00:00
|
|
|
value: FlutterThemeMode.system,
|
2023-05-17 10:52:26 +00:00
|
|
|
),
|
|
|
|
DropdownMenuItem(
|
|
|
|
child: Text("Light"),
|
2023-07-23 15:25:58 +00:00
|
|
|
value: FlutterThemeMode.light,
|
2023-05-17 10:52:26 +00:00
|
|
|
),
|
|
|
|
DropdownMenuItem(
|
|
|
|
child: Text("Dark"),
|
2023-07-23 15:25:58 +00:00
|
|
|
value: FlutterThemeMode.dark,
|
|
|
|
),
|
|
|
|
DropdownMenuItem(
|
2023-07-23 19:56:34 +00:00
|
|
|
child: Text("Material You Light"),
|
|
|
|
value: FlutterThemeMode.materialYouLight,
|
|
|
|
),
|
|
|
|
DropdownMenuItem(
|
|
|
|
child: Text("Material You Dark"),
|
|
|
|
value: FlutterThemeMode.materialYouDark,
|
2023-05-17 10:52:26 +00:00
|
|
|
),
|
|
|
|
],
|
|
|
|
value: themeMode,
|
2023-07-23 15:25:58 +00:00
|
|
|
onChanged: (FlutterThemeMode? value) {
|
2024-04-05 20:36:56 +00:00
|
|
|
VikunjaGlobal.of(context).settingsManager.setThemeMode(value!);
|
2023-05-17 10:52:26 +00:00
|
|
|
setState(() => themeMode = value);
|
2024-09-26 11:31:26 +00:00
|
|
|
if (themeMode != null) themeModel.themeMode = themeMode!;
|
2023-05-17 10:52:26 +00:00
|
|
|
},
|
|
|
|
),
|
|
|
|
),
|
|
|
|
Divider(),
|
2023-01-07 02:55:29 +00:00
|
|
|
ignoreCertificates != null
|
|
|
|
? CheckboxListTile(
|
|
|
|
title: Text("Ignore Certificates"),
|
|
|
|
value: ignoreCertificates,
|
|
|
|
onChanged: (value) {
|
|
|
|
setState(() => ignoreCertificates = value);
|
2024-04-05 13:41:48 +00:00
|
|
|
VikunjaGlobal.of(context).client.reloadIgnoreCerts(value);
|
2023-01-07 02:55:29 +00:00
|
|
|
})
|
|
|
|
: ListTile(title: Text("...")),
|
2024-04-05 20:36:56 +00:00
|
|
|
Divider(),
|
2024-09-26 11:31:26 +00:00
|
|
|
sentryEnabled != null
|
|
|
|
? CheckboxListTile(
|
|
|
|
title: Text("Enable Sentry"),
|
|
|
|
subtitle: Text(
|
|
|
|
"Help us debug errors better and faster by sending bug reports to us directly. This is completely anonymous."),
|
|
|
|
value: sentryEnabled,
|
|
|
|
onChanged: (value) {
|
|
|
|
if (value == null) return;
|
|
|
|
setState(() => sentryEnabled = value);
|
|
|
|
VikunjaGlobal.of(context)
|
|
|
|
.settingsManager
|
|
|
|
.setSentryEnabled(value)
|
|
|
|
.then((_) => themeModel.notify());
|
|
|
|
})
|
|
|
|
: ListTile(title: Text("...")),
|
|
|
|
Divider(),
|
2024-04-05 20:36:56 +00:00
|
|
|
Padding(
|
|
|
|
padding: EdgeInsets.only(left: 15, right: 15),
|
2023-01-07 15:55:40 +00:00
|
|
|
child: Row(children: [
|
2024-04-05 20:36:56 +00:00
|
|
|
Flexible(
|
|
|
|
child: TextField(
|
|
|
|
controller: durationTextController,
|
|
|
|
decoration: InputDecoration(
|
|
|
|
labelText: 'Background Refresh Interval (minutes): ',
|
|
|
|
helperText: 'Minimum: 15, Set limit of 0 for no refresh',
|
|
|
|
),
|
|
|
|
)),
|
|
|
|
TextButton(
|
|
|
|
onPressed: () => VikunjaGlobal.of(context)
|
|
|
|
.settingsManager
|
|
|
|
.setWorkmanagerDuration(Duration(
|
|
|
|
minutes: int.parse(durationTextController.text)))
|
|
|
|
.then((value) => VikunjaGlobal.of(context)
|
|
|
|
.updateWorkmanagerDuration()),
|
|
|
|
child: Text("Save")),
|
|
|
|
])),
|
2023-05-15 22:26:01 +00:00
|
|
|
Divider(),
|
2023-01-07 02:55:29 +00:00
|
|
|
getVersionNotifications != null
|
|
|
|
? CheckboxListTile(
|
|
|
|
title: Text("Get Version Notifications"),
|
|
|
|
value: getVersionNotifications,
|
|
|
|
onChanged: (value) {
|
|
|
|
setState(() => getVersionNotifications = value);
|
2023-01-07 15:55:40 +00:00
|
|
|
if (value != null)
|
|
|
|
VikunjaGlobal.of(context)
|
|
|
|
.settingsManager
|
|
|
|
.setVersionNotifications(value);
|
2023-01-07 02:55:29 +00:00
|
|
|
})
|
|
|
|
: ListTile(title: Text("...")),
|
2023-01-07 15:55:40 +00:00
|
|
|
TextButton(
|
2023-05-10 21:50:30 +00:00
|
|
|
onPressed: () async {
|
|
|
|
await Permission.notification.isDenied.then((value) {
|
|
|
|
if (value) {
|
|
|
|
Permission.notification.request();
|
|
|
|
}
|
|
|
|
});
|
2023-01-07 21:50:32 +00:00
|
|
|
VikunjaGlobal.of(context).notifications.sendTestNotification();
|
2023-01-07 15:55:40 +00:00
|
|
|
},
|
|
|
|
child: Text("Send test notification")),
|
2023-01-07 02:55:29 +00:00
|
|
|
TextButton(
|
|
|
|
onPressed: () => VikunjaGlobal.of(context)
|
|
|
|
.versionChecker
|
|
|
|
.getLatestVersionTag()
|
2023-01-07 22:00:31 +00:00
|
|
|
.then((value) => setState(() => newestVersionTag = value)),
|
2023-01-07 02:55:29 +00:00
|
|
|
child: Text("Check for latest version")),
|
2023-01-07 01:17:00 +00:00
|
|
|
Text("Current version: ${versionTag ?? "loading"}"),
|
2023-01-07 02:55:29 +00:00
|
|
|
Text(newestVersionTag != null
|
2023-01-07 12:45:10 +00:00
|
|
|
? "Latest version: $newestVersionTag"
|
2023-05-15 22:26:01 +00:00
|
|
|
: ""),
|
|
|
|
Divider(),
|
|
|
|
TextButton(
|
2023-05-16 23:22:59 +00:00
|
|
|
onPressed: () => VikunjaGlobal.of(context).logoutUser(context),
|
2023-05-15 22:26:01 +00:00
|
|
|
child: Text("Logout")),
|
2022-04-12 22:32:21 +00:00
|
|
|
],
|
|
|
|
),
|
|
|
|
);
|
|
|
|
}
|
2023-01-07 02:55:29 +00:00
|
|
|
}
|