2023-05-05 06:45:00 -04:00
|
|
|
import 'package:contacts_plus_plus/client_holder.dart';
|
2023-05-03 11:51:18 -04:00
|
|
|
import 'package:flutter/material.dart';
|
2023-05-03 15:55:34 -04:00
|
|
|
import 'package:url_launcher/url_launcher.dart';
|
2023-05-04 07:13:24 -04:00
|
|
|
import 'package:workmanager/workmanager.dart';
|
2023-05-03 11:51:18 -04:00
|
|
|
|
|
|
|
class SettingsPage extends StatelessWidget {
|
|
|
|
const SettingsPage({super.key});
|
2023-05-04 07:13:24 -04:00
|
|
|
static const Map<int, String> _intervalSelections = {
|
|
|
|
5: "5 Minutes",
|
|
|
|
15: "15 Minutes",
|
|
|
|
30: "30 Minutes",
|
|
|
|
60: "1 Hour",
|
|
|
|
120: "2 Hours",
|
|
|
|
300: "6 Hours",
|
|
|
|
600: "12 Hours",
|
|
|
|
};
|
2023-05-03 17:24:27 -04:00
|
|
|
|
2023-05-03 11:51:18 -04:00
|
|
|
@override
|
|
|
|
Widget build(BuildContext context) {
|
2023-05-03 17:24:27 -04:00
|
|
|
final sClient = ClientHolder.of(context).settingsClient;
|
2023-05-03 11:51:18 -04:00
|
|
|
return Scaffold(
|
|
|
|
appBar: AppBar(
|
|
|
|
leading: IconButton(
|
|
|
|
onPressed: () {
|
|
|
|
Navigator.of(context).pop();
|
|
|
|
},
|
|
|
|
icon: const Icon(Icons.arrow_back),
|
|
|
|
),
|
|
|
|
title: const Text("Settings"),
|
|
|
|
),
|
|
|
|
body: ListView(
|
|
|
|
children: [
|
2023-05-03 17:24:27 -04:00
|
|
|
const ListSectionHeader(name: "Notifications"),
|
|
|
|
BooleanSettingsTile(
|
2023-05-04 07:13:24 -04:00
|
|
|
title: "Enable Notifications",
|
|
|
|
initialState: !sClient.currentSettings.notificationsDenied.valueOrDefault,
|
|
|
|
onChanged: (value) async => await sClient.changeSettings(sClient.currentSettings.copyWith(notificationsDenied: !value)),
|
2023-05-03 17:24:27 -04:00
|
|
|
),
|
|
|
|
ListTile(
|
2023-05-04 07:13:24 -04:00
|
|
|
trailing: StatefulBuilder(
|
|
|
|
builder: (context, setState) {
|
|
|
|
return DropdownButton<int>(
|
|
|
|
items: _intervalSelections.keys.map((e) => DropdownMenuItem<int>(value: e, child: Text("${_intervalSelections[e]}"))).toList(),
|
|
|
|
value: sClient.currentSettings.unreadCheckIntervalMinutes.valueOrDefault,
|
|
|
|
onChanged: (int? value) async {
|
|
|
|
await sClient.changeSettings(sClient.currentSettings.copyWith(unreadCheckIntervalMinutes: value));
|
|
|
|
setState(() {});
|
|
|
|
},
|
|
|
|
);
|
|
|
|
}
|
|
|
|
),
|
|
|
|
title: const Text("Check Interval"),
|
2023-05-03 17:24:27 -04:00
|
|
|
onTap: () {
|
|
|
|
},
|
|
|
|
),
|
|
|
|
const ListSectionHeader(name: "Other"),
|
2023-05-03 11:51:18 -04:00
|
|
|
ListTile(
|
2023-05-03 12:16:40 -04:00
|
|
|
trailing: const Icon(Icons.logout),
|
2023-05-03 11:51:18 -04:00
|
|
|
title: const Text("Sign out"),
|
|
|
|
onTap: () {
|
|
|
|
showDialog(
|
|
|
|
context: context,
|
|
|
|
builder: (context) =>
|
|
|
|
AlertDialog(
|
|
|
|
title: Text("Are you sure you want to sign out?", style: Theme
|
|
|
|
.of(context)
|
|
|
|
.textTheme
|
|
|
|
.titleLarge,),
|
|
|
|
actions: [
|
|
|
|
TextButton(onPressed: () => Navigator.of(context).pop(), child: const Text("No")),
|
|
|
|
TextButton(
|
|
|
|
onPressed: () async {
|
2023-05-03 15:55:34 -04:00
|
|
|
await ClientHolder.of(context).apiClient.logout(context);
|
2023-05-03 11:51:18 -04:00
|
|
|
},
|
|
|
|
child: const Text("Yes"),
|
|
|
|
),
|
|
|
|
],
|
|
|
|
),
|
|
|
|
);
|
|
|
|
},
|
2023-05-03 15:55:34 -04:00
|
|
|
),
|
|
|
|
ListTile(
|
|
|
|
trailing: const Icon(Icons.info_outline),
|
|
|
|
title: const Text("About Contacts++"),
|
|
|
|
onTap: () {
|
|
|
|
showAboutDialog(
|
|
|
|
context: context,
|
|
|
|
applicationVersion: "0.0.1",
|
|
|
|
applicationIcon: InkWell(
|
|
|
|
onTap: () async {
|
|
|
|
if (!await launchUrl(Uri.parse("https://github.com/Nutcake/contacts-plus-plus"), mode: LaunchMode.externalApplication)) {
|
|
|
|
if (context.mounted) {
|
|
|
|
ScaffoldMessenger.of(context).showSnackBar(const SnackBar(content: Text("Failed to open link.")));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
},
|
|
|
|
child: Container(
|
|
|
|
margin: const EdgeInsets.all(16),
|
|
|
|
constraints: const BoxConstraints(maxWidth: 64),
|
|
|
|
child: Image.asset("assets/images/logo512.png"),
|
|
|
|
),
|
|
|
|
),
|
|
|
|
applicationLegalese: "Created by Nutcake with love <3",
|
|
|
|
);
|
|
|
|
},
|
2023-05-03 11:51:18 -04:00
|
|
|
)
|
|
|
|
],
|
|
|
|
),
|
|
|
|
);
|
|
|
|
}
|
2023-05-03 17:24:27 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
class ListSectionHeader extends StatelessWidget {
|
|
|
|
const ListSectionHeader({required this.name, super.key});
|
|
|
|
|
|
|
|
final String name;
|
|
|
|
|
|
|
|
@override
|
|
|
|
Widget build(BuildContext context) {
|
|
|
|
final theme = Theme.of(context);
|
|
|
|
return Padding(
|
|
|
|
padding: const EdgeInsets.all(8.0),
|
|
|
|
child: Row(
|
|
|
|
crossAxisAlignment: CrossAxisAlignment.center,
|
|
|
|
children: [
|
|
|
|
Text(name, style: theme.textTheme.labelSmall?.copyWith(color: theme.colorScheme.onSurfaceVariant)),
|
|
|
|
Expanded(
|
|
|
|
child: Container(
|
|
|
|
margin: const EdgeInsets.symmetric(horizontal: 8),
|
|
|
|
color: Colors.white12,
|
|
|
|
height: 1,
|
|
|
|
),
|
|
|
|
)
|
|
|
|
],
|
|
|
|
),
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
class BooleanSettingsTile extends StatefulWidget {
|
|
|
|
const BooleanSettingsTile({required this.title, required this.initialState, required this.onChanged, super.key});
|
|
|
|
|
|
|
|
final String title;
|
|
|
|
final bool initialState;
|
|
|
|
final Function(bool) onChanged;
|
|
|
|
|
|
|
|
@override
|
|
|
|
State<StatefulWidget> createState() => _BooleanSettingsTileState();
|
|
|
|
}
|
|
|
|
|
|
|
|
class _BooleanSettingsTileState extends State<BooleanSettingsTile> {
|
|
|
|
late bool state = widget.initialState;
|
|
|
|
|
|
|
|
@override
|
|
|
|
Widget build(BuildContext context) {
|
|
|
|
return ListTile(
|
|
|
|
trailing: Switch(
|
|
|
|
onChanged: (value) async {
|
|
|
|
await widget.onChanged(value);
|
|
|
|
setState(() {
|
|
|
|
state = value;
|
|
|
|
});
|
|
|
|
},
|
|
|
|
value: state,
|
|
|
|
),
|
|
|
|
title: Text(widget.title),
|
|
|
|
onTap: () async {
|
|
|
|
await widget.onChanged(!state);
|
|
|
|
setState(() {
|
|
|
|
state = !state;
|
|
|
|
});
|
|
|
|
},
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2023-05-03 11:51:18 -04:00
|
|
|
}
|