2020-09-16 22:53:04 +02:00
|
|
|
import 'package:flutter/cupertino.dart';
|
2021-01-02 16:41:08 +01:00
|
|
|
import 'package:flutter/foundation.dart';
|
2020-08-31 16:17:39 +02:00
|
|
|
import 'package:flutter/material.dart';
|
2020-09-08 00:34:09 +02:00
|
|
|
import 'package:flutter_hooks/flutter_hooks.dart';
|
2020-09-22 00:34:45 +02:00
|
|
|
import 'package:flutter_slidable/flutter_slidable.dart';
|
2020-09-22 13:22:45 +02:00
|
|
|
import 'package:flutter_speed_dial/flutter_speed_dial.dart';
|
2020-08-31 16:17:39 +02:00
|
|
|
|
2020-09-16 23:22:04 +02:00
|
|
|
import '../hooks/stores.dart';
|
2020-09-16 22:53:04 +02:00
|
|
|
import '../util/goto.dart';
|
2020-10-01 17:57:04 +02:00
|
|
|
import '../widgets/about_tile.dart';
|
2020-09-19 01:34:04 +02:00
|
|
|
import 'add_account.dart';
|
|
|
|
import 'add_instance.dart';
|
2021-01-06 00:51:19 +01:00
|
|
|
import 'manage_account.dart';
|
2020-08-31 16:17:39 +02:00
|
|
|
|
2020-09-30 19:05:00 +02:00
|
|
|
/// Page with a list of different settings sections
|
2020-09-03 14:33:17 +02:00
|
|
|
class SettingsPage extends StatelessWidget {
|
2021-01-03 19:43:39 +01:00
|
|
|
const SettingsPage();
|
|
|
|
|
2020-08-31 16:17:39 +02:00
|
|
|
@override
|
|
|
|
Widget build(BuildContext context) {
|
2020-09-16 23:22:04 +02:00
|
|
|
final theme = Theme.of(context);
|
2020-08-31 16:17:39 +02:00
|
|
|
|
|
|
|
return Scaffold(
|
|
|
|
appBar: AppBar(
|
2020-09-19 23:19:49 +02:00
|
|
|
brightness: theme.brightness,
|
2020-08-31 16:17:39 +02:00
|
|
|
backgroundColor: theme.scaffoldBackgroundColor,
|
|
|
|
shadowColor: Colors.transparent,
|
|
|
|
iconTheme: theme.iconTheme,
|
|
|
|
title: Text('Settings', style: theme.textTheme.headline6),
|
|
|
|
centerTitle: true,
|
|
|
|
),
|
2021-01-03 18:03:59 +01:00
|
|
|
body: ListView(
|
|
|
|
children: [
|
|
|
|
ListTile(
|
2021-01-03 19:43:39 +01:00
|
|
|
leading: const Icon(Icons.person),
|
|
|
|
title: const Text('Accounts'),
|
2021-01-03 18:03:59 +01:00
|
|
|
onTap: () {
|
|
|
|
goTo(context, (_) => AccountsConfigPage());
|
|
|
|
},
|
|
|
|
),
|
|
|
|
ListTile(
|
2021-01-03 19:43:39 +01:00
|
|
|
leading: const Icon(Icons.color_lens),
|
|
|
|
title: const Text('Appearance'),
|
2021-01-03 18:03:59 +01:00
|
|
|
onTap: () {
|
2021-01-03 19:43:39 +01:00
|
|
|
goTo(context, (_) => const AppearanceConfigPage());
|
2021-01-03 18:03:59 +01:00
|
|
|
},
|
|
|
|
),
|
2021-01-03 21:03:40 +01:00
|
|
|
const AboutTile()
|
2021-01-03 18:03:59 +01:00
|
|
|
],
|
2020-08-31 16:17:39 +02:00
|
|
|
),
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-09-30 19:05:00 +02:00
|
|
|
/// Settings for theme color, AMOLED switch
|
2020-09-17 00:24:49 +02:00
|
|
|
class AppearanceConfigPage extends HookWidget {
|
2021-01-03 19:43:39 +01:00
|
|
|
const AppearanceConfigPage();
|
|
|
|
|
2020-08-31 16:17:39 +02:00
|
|
|
@override
|
|
|
|
Widget build(BuildContext context) {
|
2020-09-16 23:22:04 +02:00
|
|
|
final theme = Theme.of(context);
|
2020-09-16 23:15:42 +02:00
|
|
|
final configStore = useConfigStore();
|
2020-08-31 16:17:39 +02:00
|
|
|
|
|
|
|
return Scaffold(
|
|
|
|
appBar: AppBar(
|
2020-09-19 23:19:49 +02:00
|
|
|
brightness: theme.brightness,
|
2020-08-31 16:17:39 +02:00
|
|
|
backgroundColor: theme.scaffoldBackgroundColor,
|
|
|
|
shadowColor: Colors.transparent,
|
|
|
|
iconTheme: theme.iconTheme,
|
|
|
|
title: Text('Appearance', style: theme.textTheme.headline6),
|
|
|
|
centerTitle: true,
|
|
|
|
),
|
2020-10-25 22:33:44 +01:00
|
|
|
body: ListView(
|
|
|
|
children: [
|
2021-01-03 19:43:39 +01:00
|
|
|
const _SectionHeading('Theme'),
|
2020-10-25 22:33:44 +01:00
|
|
|
for (final theme in ThemeMode.values)
|
|
|
|
RadioListTile<ThemeMode>(
|
|
|
|
value: theme,
|
2021-01-02 16:41:08 +01:00
|
|
|
title: Text(describeEnum(theme)),
|
2020-10-25 22:33:44 +01:00
|
|
|
groupValue: configStore.theme,
|
|
|
|
onChanged: (selected) {
|
|
|
|
configStore.theme = selected;
|
|
|
|
},
|
|
|
|
),
|
|
|
|
SwitchListTile(
|
2021-01-03 19:43:39 +01:00
|
|
|
title: const Text('AMOLED dark mode'),
|
2020-10-25 22:33:44 +01:00
|
|
|
value: configStore.amoledDarkMode,
|
|
|
|
onChanged: (checked) {
|
|
|
|
configStore.amoledDarkMode = checked;
|
|
|
|
})
|
|
|
|
],
|
2020-08-31 16:17:39 +02:00
|
|
|
),
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|
2020-09-02 01:35:30 +02:00
|
|
|
|
2020-09-30 19:05:00 +02:00
|
|
|
/// Settings for managing accounts
|
2020-09-08 21:44:27 +02:00
|
|
|
class AccountsConfigPage extends HookWidget {
|
2020-09-08 00:34:09 +02:00
|
|
|
final GlobalKey<ScaffoldState> _scaffoldKey = GlobalKey();
|
|
|
|
|
2020-09-02 01:35:30 +02:00
|
|
|
@override
|
|
|
|
Widget build(BuildContext context) {
|
2020-09-16 23:22:04 +02:00
|
|
|
final theme = Theme.of(context);
|
2020-09-16 23:15:42 +02:00
|
|
|
final accountsStore = useAccountsStore();
|
2020-09-02 01:35:30 +02:00
|
|
|
|
2020-12-31 14:58:23 +01:00
|
|
|
removeInstanceDialog(String instanceHost) async {
|
2020-09-19 20:15:42 +02:00
|
|
|
if (await showDialog<bool>(
|
|
|
|
context: context,
|
|
|
|
builder: (context) => AlertDialog(
|
2021-01-03 19:43:39 +01:00
|
|
|
title: const Text('Remove instance?'),
|
2020-12-31 14:58:23 +01:00
|
|
|
content: Text('Are you sure you want to remove $instanceHost?'),
|
2020-09-19 20:15:42 +02:00
|
|
|
actions: [
|
2020-09-23 23:37:26 +02:00
|
|
|
FlatButton(
|
|
|
|
onPressed: () => Navigator.of(context).pop(false),
|
2021-01-03 19:43:39 +01:00
|
|
|
child: const Text('no'),
|
2020-09-23 23:37:26 +02:00
|
|
|
),
|
2020-09-19 20:15:42 +02:00
|
|
|
FlatButton(
|
|
|
|
onPressed: () => Navigator.of(context).pop(true),
|
2021-01-03 19:43:39 +01:00
|
|
|
child: const Text('yes'),
|
2020-09-19 20:15:42 +02:00
|
|
|
),
|
|
|
|
],
|
|
|
|
),
|
|
|
|
) ??
|
|
|
|
false) {
|
2020-12-31 14:58:23 +01:00
|
|
|
accountsStore.removeInstance(instanceHost);
|
2020-09-19 20:15:42 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-12-31 14:58:23 +01:00
|
|
|
Future<void> removeUserDialog(String instanceHost, String username) async {
|
2020-09-22 00:34:45 +02:00
|
|
|
if (await showDialog<bool>(
|
|
|
|
context: context,
|
|
|
|
builder: (context) => AlertDialog(
|
2021-01-03 19:43:39 +01:00
|
|
|
title: const Text('Remove user?'),
|
2020-09-22 00:34:45 +02:00
|
|
|
content: Text(
|
2020-12-31 14:58:23 +01:00
|
|
|
'Are you sure you want to remove $username@$instanceHost?'),
|
2020-09-22 00:34:45 +02:00
|
|
|
actions: [
|
2020-09-23 23:37:26 +02:00
|
|
|
FlatButton(
|
|
|
|
onPressed: () => Navigator.of(context).pop(false),
|
2021-01-03 19:43:39 +01:00
|
|
|
child: const Text('no'),
|
2020-09-23 23:37:26 +02:00
|
|
|
),
|
2020-09-22 00:34:45 +02:00
|
|
|
FlatButton(
|
|
|
|
onPressed: () => Navigator.of(context).pop(true),
|
2021-01-03 19:43:39 +01:00
|
|
|
child: const Text('yes'),
|
2020-09-22 00:34:45 +02:00
|
|
|
),
|
|
|
|
],
|
|
|
|
),
|
|
|
|
) ??
|
|
|
|
false) {
|
2020-12-31 14:58:23 +01:00
|
|
|
accountsStore.removeAccount(instanceHost, username);
|
2020-09-22 00:34:45 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-09-02 01:35:30 +02:00
|
|
|
return Scaffold(
|
2020-09-08 00:34:09 +02:00
|
|
|
key: _scaffoldKey,
|
2020-09-02 01:35:30 +02:00
|
|
|
appBar: AppBar(
|
|
|
|
backgroundColor: theme.scaffoldBackgroundColor,
|
2020-09-19 23:19:49 +02:00
|
|
|
brightness: theme.brightness,
|
2020-09-02 01:35:30 +02:00
|
|
|
shadowColor: Colors.transparent,
|
|
|
|
iconTheme: theme.iconTheme,
|
|
|
|
title: Text('Accounts', style: theme.textTheme.headline6),
|
|
|
|
centerTitle: true,
|
|
|
|
),
|
2020-09-22 13:22:45 +02:00
|
|
|
floatingActionButton: SpeedDial(
|
|
|
|
animatedIcon: AnimatedIcons.menu_close, // TODO: change to + => x
|
|
|
|
curve: Curves.bounceIn,
|
|
|
|
tooltip: 'Add account or instance',
|
2020-09-24 15:48:05 +02:00
|
|
|
overlayColor: theme.canvasColor,
|
2020-09-22 13:22:45 +02:00
|
|
|
children: [
|
|
|
|
SpeedDialChild(
|
2021-01-03 19:43:39 +01:00
|
|
|
child: const Icon(Icons.person_add),
|
2020-09-22 13:22:45 +02:00
|
|
|
label: 'Add account',
|
2020-09-24 15:48:05 +02:00
|
|
|
labelBackgroundColor: theme.canvasColor,
|
2020-09-22 13:22:45 +02:00
|
|
|
onTap: () => showCupertinoModalPopup(
|
|
|
|
context: context,
|
|
|
|
builder: (_) =>
|
2020-12-31 14:58:23 +01:00
|
|
|
AddAccountPage(instanceHost: accountsStore.instances.last)),
|
2020-09-22 13:22:45 +02:00
|
|
|
),
|
|
|
|
SpeedDialChild(
|
2021-01-03 19:43:39 +01:00
|
|
|
child: const Icon(Icons.dns),
|
2020-09-24 15:48:05 +02:00
|
|
|
labelBackgroundColor: theme.canvasColor,
|
2020-09-22 13:22:45 +02:00
|
|
|
label: 'Add instance',
|
|
|
|
onTap: () => showCupertinoModalPopup(
|
|
|
|
context: context, builder: (_) => AddInstancePage()),
|
|
|
|
),
|
|
|
|
],
|
2021-01-03 19:43:39 +01:00
|
|
|
child: const Icon(Icons.add),
|
2020-09-08 00:34:09 +02:00
|
|
|
),
|
2020-10-25 22:33:44 +01:00
|
|
|
body: ListView(
|
|
|
|
children: [
|
2021-01-17 17:35:47 +01:00
|
|
|
if (accountsStore.instances.isEmpty)
|
2020-10-25 22:33:44 +01:00
|
|
|
Row(
|
|
|
|
mainAxisAlignment: MainAxisAlignment.center,
|
|
|
|
children: [
|
|
|
|
Padding(
|
|
|
|
padding: const EdgeInsets.only(top: 100),
|
|
|
|
child: FlatButton.icon(
|
|
|
|
shape: RoundedRectangleBorder(
|
|
|
|
borderRadius: BorderRadius.circular(10),
|
|
|
|
),
|
|
|
|
onPressed: () => showCupertinoModalPopup(
|
|
|
|
context: context,
|
|
|
|
builder: (_) => AddInstancePage(),
|
2020-09-23 15:27:52 +02:00
|
|
|
),
|
2021-01-03 19:43:39 +01:00
|
|
|
icon: const Icon(Icons.add),
|
|
|
|
label: const Text('Add instance')),
|
2020-09-23 15:27:52 +02:00
|
|
|
),
|
2020-10-25 22:33:44 +01:00
|
|
|
],
|
|
|
|
),
|
2021-01-06 00:51:19 +01:00
|
|
|
for (final instance in accountsStore.instances) ...[
|
2021-01-03 19:43:39 +01:00
|
|
|
const SizedBox(height: 40),
|
2020-10-25 22:33:44 +01:00
|
|
|
Slidable(
|
2021-01-03 19:43:39 +01:00
|
|
|
actionPane: const SlidableBehindActionPane(),
|
2020-10-25 22:33:44 +01:00
|
|
|
secondaryActions: [
|
|
|
|
IconSlideAction(
|
2021-01-06 00:51:19 +01:00
|
|
|
onTap: () => removeInstanceDialog(instance),
|
2020-10-25 22:33:44 +01:00
|
|
|
icon: Icons.delete_sweep,
|
|
|
|
color: Colors.red,
|
2020-09-19 20:15:42 +02:00
|
|
|
),
|
2020-10-25 22:33:44 +01:00
|
|
|
],
|
2021-01-06 00:51:19 +01:00
|
|
|
key: Key(instance),
|
|
|
|
// TODO: missing ripple effect
|
2020-10-25 22:33:44 +01:00
|
|
|
child: Container(
|
2021-01-06 00:51:19 +01:00
|
|
|
color: theme.scaffoldBackgroundColor,
|
2020-10-25 22:33:44 +01:00
|
|
|
child: ListTile(
|
|
|
|
dense: true,
|
2021-01-03 18:03:59 +01:00
|
|
|
contentPadding: EdgeInsets.zero,
|
2021-01-06 00:51:19 +01:00
|
|
|
title: _SectionHeading(instance),
|
2020-10-25 22:33:44 +01:00
|
|
|
),
|
|
|
|
),
|
|
|
|
),
|
2021-01-17 17:35:47 +01:00
|
|
|
for (final username in accountsStore.usernamesFor(instance)) ...[
|
2020-10-25 22:33:44 +01:00
|
|
|
Slidable(
|
2021-01-03 19:43:39 +01:00
|
|
|
actionPane: const SlidableBehindActionPane(),
|
2021-01-06 00:51:19 +01:00
|
|
|
key: Key('$username@$instance'),
|
2020-10-25 22:33:44 +01:00
|
|
|
secondaryActions: [
|
|
|
|
IconSlideAction(
|
2021-01-06 00:51:19 +01:00
|
|
|
onTap: () => removeUserDialog(instance, username),
|
2020-10-25 22:33:44 +01:00
|
|
|
icon: Icons.delete_sweep,
|
|
|
|
color: Colors.red,
|
|
|
|
),
|
|
|
|
],
|
2021-01-06 00:51:19 +01:00
|
|
|
// TODO: missing ripple effect
|
2020-10-25 22:33:44 +01:00
|
|
|
child: Container(
|
2021-01-06 00:51:19 +01:00
|
|
|
color: theme.scaffoldBackgroundColor,
|
2020-10-25 22:33:44 +01:00
|
|
|
child: ListTile(
|
|
|
|
trailing:
|
2021-01-06 00:51:19 +01:00
|
|
|
username == accountsStore.defaultUsernameFor(instance)
|
2020-09-03 23:14:26 +02:00
|
|
|
? Icon(
|
|
|
|
Icons.check_circle_outline,
|
|
|
|
color: theme.accentColor,
|
|
|
|
)
|
2020-09-02 01:35:30 +02:00
|
|
|
: null,
|
2020-10-25 22:33:44 +01:00
|
|
|
title: Text(username),
|
|
|
|
onLongPress: () {
|
2021-01-06 00:51:19 +01:00
|
|
|
accountsStore.setDefaultAccountFor(instance, username);
|
|
|
|
},
|
|
|
|
onTap: () {
|
|
|
|
goTo(
|
|
|
|
context,
|
2021-01-06 18:45:56 +01:00
|
|
|
(_) => ManageAccountPage(
|
2021-01-06 00:51:19 +01:00
|
|
|
instanceHost: instance,
|
|
|
|
username: username,
|
|
|
|
));
|
2020-09-22 13:22:45 +02:00
|
|
|
},
|
|
|
|
),
|
2020-10-25 22:33:44 +01:00
|
|
|
),
|
|
|
|
),
|
2020-09-08 16:37:58 +02:00
|
|
|
],
|
2021-01-17 17:35:47 +01:00
|
|
|
if (accountsStore.usernamesFor(instance).isEmpty)
|
2020-10-25 22:33:44 +01:00
|
|
|
ListTile(
|
2021-01-03 19:43:39 +01:00
|
|
|
leading: const Icon(Icons.add),
|
|
|
|
title: const Text('Add account'),
|
2020-10-25 22:33:44 +01:00
|
|
|
onTap: () {
|
|
|
|
showCupertinoModalPopup(
|
|
|
|
context: context,
|
2021-01-06 00:51:19 +01:00
|
|
|
builder: (_) => AddAccountPage(instanceHost: instance));
|
2020-10-25 22:33:44 +01:00
|
|
|
},
|
|
|
|
),
|
|
|
|
]
|
|
|
|
],
|
2020-09-02 01:35:30 +02:00
|
|
|
),
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|
2020-09-03 23:14:26 +02:00
|
|
|
|
|
|
|
class _SectionHeading extends StatelessWidget {
|
|
|
|
final String text;
|
|
|
|
|
|
|
|
const _SectionHeading(this.text);
|
|
|
|
|
|
|
|
@override
|
|
|
|
Widget build(BuildContext context) {
|
|
|
|
final theme = Theme.of(context);
|
|
|
|
return Padding(
|
2021-01-03 19:43:39 +01:00
|
|
|
padding: const EdgeInsets.only(left: 20),
|
2020-09-03 23:14:26 +02:00
|
|
|
child: Text(text.toUpperCase(),
|
|
|
|
style: theme.textTheme.subtitle2.copyWith(color: theme.accentColor)),
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|