2020-09-16 22:53:04 +02:00
|
|
|
import 'package:flutter/cupertino.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';
|
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 {
|
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,
|
|
|
|
),
|
|
|
|
body: Container(
|
|
|
|
child: ListView(
|
|
|
|
children: [
|
|
|
|
ListTile(
|
|
|
|
leading: Icon(Icons.person),
|
|
|
|
title: Text('Accounts'),
|
2020-09-02 01:35:30 +02:00
|
|
|
onTap: () {
|
2020-09-16 22:53:04 +02:00
|
|
|
goTo(context, (_) => AccountsConfigPage());
|
2020-09-02 01:35:30 +02:00
|
|
|
},
|
2020-08-31 16:17:39 +02:00
|
|
|
),
|
|
|
|
ListTile(
|
|
|
|
leading: Icon(Icons.color_lens),
|
|
|
|
title: Text('Appearance'),
|
|
|
|
onTap: () {
|
2020-09-16 22:53:04 +02:00
|
|
|
goTo(context, (_) => AppearanceConfigPage());
|
2020-08-31 16:17:39 +02:00
|
|
|
},
|
2020-10-01 17:57:04 +02:00
|
|
|
),
|
|
|
|
AboutTile()
|
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 {
|
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: [
|
|
|
|
_SectionHeading('Theme'),
|
|
|
|
for (final theme in ThemeMode.values)
|
|
|
|
RadioListTile<ThemeMode>(
|
|
|
|
value: theme,
|
|
|
|
title: Text(theme.toString().split('.')[1]),
|
|
|
|
groupValue: configStore.theme,
|
|
|
|
onChanged: (selected) {
|
|
|
|
configStore.theme = selected;
|
|
|
|
},
|
|
|
|
),
|
|
|
|
SwitchListTile(
|
|
|
|
title: Text('AMOLED dark mode'),
|
|
|
|
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-09-22 01:05:20 +02:00
|
|
|
removeInstanceDialog(String instanceUrl) async {
|
2020-09-19 20:15:42 +02:00
|
|
|
if (await showDialog<bool>(
|
|
|
|
context: context,
|
|
|
|
builder: (context) => AlertDialog(
|
2020-09-22 01:05:20 +02:00
|
|
|
title: Text('Remove instance?'),
|
2020-09-19 20:15:42 +02:00
|
|
|
content: Text('Are you sure you want to remove $instanceUrl?'),
|
|
|
|
actions: [
|
2020-09-23 23:37:26 +02:00
|
|
|
FlatButton(
|
|
|
|
child: Text('no'),
|
|
|
|
onPressed: () => Navigator.of(context).pop(false),
|
|
|
|
),
|
2020-09-19 20:15:42 +02:00
|
|
|
FlatButton(
|
|
|
|
child: Text('yes'),
|
|
|
|
onPressed: () => Navigator.of(context).pop(true),
|
|
|
|
),
|
|
|
|
],
|
|
|
|
),
|
|
|
|
) ??
|
|
|
|
false) {
|
2020-09-22 00:34:45 +02:00
|
|
|
accountsStore.removeInstance(instanceUrl);
|
2020-09-19 20:15:42 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-09-23 23:39:41 +02:00
|
|
|
Future<void> removeUserDialog(String instanceUrl, String username) async {
|
2020-09-22 00:34:45 +02:00
|
|
|
if (await showDialog<bool>(
|
|
|
|
context: context,
|
|
|
|
builder: (context) => AlertDialog(
|
|
|
|
title: Text('Remove user?'),
|
|
|
|
content: Text(
|
|
|
|
'Are you sure you want to remove $username@$instanceUrl?'),
|
|
|
|
actions: [
|
2020-09-23 23:37:26 +02:00
|
|
|
FlatButton(
|
|
|
|
child: Text('no'),
|
|
|
|
onPressed: () => Navigator.of(context).pop(false),
|
|
|
|
),
|
2020-09-22 00:34:45 +02:00
|
|
|
FlatButton(
|
|
|
|
child: Text('yes'),
|
|
|
|
onPressed: () => Navigator.of(context).pop(true),
|
|
|
|
),
|
|
|
|
],
|
|
|
|
),
|
|
|
|
) ??
|
|
|
|
false) {
|
|
|
|
accountsStore.removeAccount(instanceUrl, username);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
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
|
|
|
|
closeManually: false,
|
|
|
|
curve: Curves.bounceIn,
|
|
|
|
tooltip: 'Add account or instance',
|
2020-09-08 00:34:09 +02:00
|
|
|
child: Icon(Icons.add),
|
2020-09-24 15:48:05 +02:00
|
|
|
overlayColor: theme.canvasColor,
|
2020-09-22 13:22:45 +02:00
|
|
|
children: [
|
|
|
|
SpeedDialChild(
|
|
|
|
child: Icon(Icons.person_add),
|
|
|
|
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-09-29 23:15:51 +02:00
|
|
|
AddAccountPage(instanceUrl: accountsStore.instances.last)),
|
2020-09-22 13:22:45 +02:00
|
|
|
),
|
|
|
|
SpeedDialChild(
|
|
|
|
child: 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()),
|
|
|
|
),
|
|
|
|
],
|
2020-09-08 00:34:09 +02:00
|
|
|
),
|
2020-10-25 22:33:44 +01:00
|
|
|
body: ListView(
|
|
|
|
children: [
|
|
|
|
if (accountsStore.tokens.isEmpty)
|
|
|
|
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
|
|
|
),
|
2020-10-25 22:33:44 +01:00
|
|
|
icon: Icon(Icons.add),
|
|
|
|
label: Text('Add instance')),
|
2020-09-23 15:27:52 +02:00
|
|
|
),
|
2020-10-25 22:33:44 +01:00
|
|
|
],
|
|
|
|
),
|
|
|
|
for (final entry in accountsStore.tokens.entries) ...[
|
|
|
|
SizedBox(height: 40),
|
|
|
|
Slidable(
|
|
|
|
actionPane: SlidableBehindActionPane(),
|
|
|
|
secondaryActions: [
|
|
|
|
IconSlideAction(
|
|
|
|
closeOnTap: true,
|
|
|
|
onTap: () => removeInstanceDialog(entry.key),
|
|
|
|
icon: Icons.delete_sweep,
|
|
|
|
color: Colors.red,
|
2020-09-19 20:15:42 +02:00
|
|
|
),
|
2020-10-25 22:33:44 +01:00
|
|
|
],
|
|
|
|
key: Key(entry.key),
|
|
|
|
child: Container(
|
|
|
|
color: theme.canvasColor,
|
|
|
|
child: ListTile(
|
|
|
|
dense: true,
|
|
|
|
contentPadding: EdgeInsets.only(left: 0, top: 0),
|
|
|
|
title: _SectionHeading(entry.key),
|
|
|
|
),
|
|
|
|
),
|
|
|
|
),
|
|
|
|
for (final username in entry.value.keys) ...[
|
|
|
|
Slidable(
|
|
|
|
actionPane: SlidableBehindActionPane(),
|
|
|
|
key: Key('$username@${entry.key}'),
|
|
|
|
secondaryActions: [
|
|
|
|
IconSlideAction(
|
|
|
|
closeOnTap: true,
|
|
|
|
onTap: () => removeUserDialog(entry.key, username),
|
|
|
|
icon: Icons.delete_sweep,
|
|
|
|
color: Colors.red,
|
|
|
|
),
|
|
|
|
],
|
|
|
|
child: Container(
|
|
|
|
decoration: BoxDecoration(color: theme.canvasColor),
|
|
|
|
child: ListTile(
|
|
|
|
trailing:
|
|
|
|
username == accountsStore.defaultUsernameFor(entry.key)
|
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: () {
|
|
|
|
accountsStore.setDefaultAccountFor(entry.key, username);
|
2020-09-22 13:22:45 +02:00
|
|
|
},
|
2020-10-25 22:33:44 +01:00
|
|
|
onTap: () {}, // TODO: go to managing account
|
2020-09-22 13:22:45 +02:00
|
|
|
),
|
2020-10-25 22:33:44 +01:00
|
|
|
),
|
|
|
|
),
|
2020-09-08 16:37:58 +02:00
|
|
|
],
|
2020-10-25 22:33:44 +01:00
|
|
|
if (entry.value.keys.isEmpty)
|
|
|
|
ListTile(
|
|
|
|
leading: Icon(Icons.add),
|
|
|
|
title: Text('Add account'),
|
|
|
|
onTap: () {
|
|
|
|
showCupertinoModalPopup(
|
|
|
|
context: context,
|
|
|
|
builder: (_) => AddAccountPage(instanceUrl: entry.key));
|
|
|
|
},
|
|
|
|
),
|
|
|
|
]
|
|
|
|
],
|
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(
|
|
|
|
child: Text(text.toUpperCase(),
|
|
|
|
style: theme.textTheme.subtitle2.copyWith(color: theme.accentColor)),
|
2020-09-19 20:15:42 +02:00
|
|
|
padding: EdgeInsets.only(left: 20, top: 0),
|
2020-09-03 23:14:26 +02:00
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|