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-08-31 16:17:39 +02:00
|
|
|
import 'package:flutter_mobx/flutter_mobx.dart';
|
|
|
|
|
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-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-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(
|
|
|
|
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-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(
|
|
|
|
backgroundColor: theme.scaffoldBackgroundColor,
|
|
|
|
shadowColor: Colors.transparent,
|
|
|
|
iconTheme: theme.iconTheme,
|
|
|
|
title: Text('Appearance', style: theme.textTheme.headline6),
|
|
|
|
centerTitle: true,
|
|
|
|
),
|
|
|
|
body: Observer(
|
2020-09-03 22:20:32 +02:00
|
|
|
builder: (ctx) => ListView(
|
2020-08-31 16:17:39 +02:00
|
|
|
children: [
|
2020-09-03 23:14:26 +02:00
|
|
|
_SectionHeading('Theme'),
|
2020-08-31 16:17:39 +02:00
|
|
|
for (final theme in ThemeMode.values)
|
|
|
|
RadioListTile<ThemeMode>(
|
|
|
|
value: theme,
|
|
|
|
title: Text(theme.toString().split('.')[1]),
|
2020-09-16 23:15:42 +02:00
|
|
|
groupValue: configStore.theme,
|
2020-08-31 16:17:39 +02:00
|
|
|
onChanged: (selected) {
|
2020-09-16 23:15:42 +02:00
|
|
|
configStore.theme = selected;
|
2020-08-31 16:17:39 +02:00
|
|
|
},
|
|
|
|
),
|
2020-09-08 10:23:08 +02:00
|
|
|
SwitchListTile(
|
2020-09-08 10:24:47 +02:00
|
|
|
title: Text('AMOLED dark mode'),
|
2020-09-16 23:15:42 +02:00
|
|
|
value: configStore.amoledDarkMode,
|
2020-09-08 10:23:08 +02:00
|
|
|
onChanged: (checked) {
|
2020-09-16 23:15:42 +02:00
|
|
|
configStore.amoledDarkMode = checked;
|
2020-09-08 10:23:08 +02:00
|
|
|
})
|
2020-08-31 16:17:39 +02:00
|
|
|
],
|
|
|
|
),
|
|
|
|
),
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|
2020-09-02 01:35:30 +02:00
|
|
|
|
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-19 20:15:42 +02:00
|
|
|
deleteInstanceDialog(String instanceUrl) async {
|
|
|
|
if (await showDialog<bool>(
|
|
|
|
context: context,
|
|
|
|
builder: (context) => AlertDialog(
|
|
|
|
title: Text('Delete instance?'),
|
|
|
|
content: Text('Are you sure you want to remove $instanceUrl?'),
|
|
|
|
actions: [
|
|
|
|
FlatButton(
|
|
|
|
child: Text('yes'),
|
|
|
|
onPressed: () => Navigator.of(context).pop(true),
|
|
|
|
),
|
|
|
|
FlatButton(
|
|
|
|
child: Text('no'),
|
|
|
|
onPressed: () => Navigator.of(context).pop(false),
|
|
|
|
)
|
|
|
|
],
|
|
|
|
),
|
|
|
|
) ??
|
|
|
|
false) {
|
|
|
|
print('delete $instanceUrl');
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
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,
|
|
|
|
shadowColor: Colors.transparent,
|
|
|
|
iconTheme: theme.iconTheme,
|
|
|
|
title: Text('Accounts', style: theme.textTheme.headline6),
|
|
|
|
centerTitle: true,
|
|
|
|
),
|
2020-09-08 00:34:09 +02:00
|
|
|
floatingActionButton: FloatingActionButton(
|
2020-09-08 01:27:02 +02:00
|
|
|
onPressed: () {
|
2020-09-19 01:34:04 +02:00
|
|
|
showCupertinoModalPopup(
|
|
|
|
context: context, builder: (_) => AddInstancePage());
|
2020-09-08 00:34:09 +02:00
|
|
|
},
|
|
|
|
child: Icon(Icons.add),
|
|
|
|
),
|
2020-09-02 01:35:30 +02:00
|
|
|
body: Observer(
|
|
|
|
builder: (ctx) {
|
2020-09-16 23:22:04 +02:00
|
|
|
final theme = Theme.of(context);
|
2020-09-02 01:35:30 +02:00
|
|
|
|
2020-09-03 22:20:32 +02:00
|
|
|
return ListView(
|
2020-09-02 01:35:30 +02:00
|
|
|
children: [
|
2020-09-16 23:22:04 +02:00
|
|
|
for (final entry in accountsStore.users.entries) ...[
|
2020-09-19 20:15:42 +02:00
|
|
|
SizedBox(height: 40),
|
|
|
|
ListTile(
|
|
|
|
dense: true,
|
|
|
|
contentPadding: EdgeInsets.only(left: 0, top: 0),
|
|
|
|
onLongPress: () => deleteInstanceDialog(entry.key),
|
|
|
|
title: _SectionHeading(entry.key),
|
|
|
|
),
|
2020-09-16 23:22:04 +02:00
|
|
|
for (final username in entry.value.keys) ...[
|
2020-09-02 01:35:30 +02:00
|
|
|
ListTile(
|
|
|
|
trailing:
|
|
|
|
username == accountsStore.defaultUserFor(entry.key).name
|
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,
|
|
|
|
title: Text(username),
|
|
|
|
onLongPress: () {
|
|
|
|
accountsStore.setDefaultAccountFor(entry.key, username);
|
|
|
|
},
|
2020-09-03 23:14:26 +02:00
|
|
|
|
2020-09-02 01:35:30 +02:00
|
|
|
onTap: () {}, // TODO: go to managing account
|
|
|
|
),
|
|
|
|
],
|
2020-09-08 01:27:02 +02:00
|
|
|
ListTile(
|
|
|
|
leading: Icon(Icons.add),
|
|
|
|
title: Text('Add account'),
|
|
|
|
onTap: () {
|
2020-09-19 01:34:04 +02:00
|
|
|
showCupertinoModalPopup(
|
|
|
|
context: context,
|
|
|
|
builder: (_) => AddAccountPage(instanceUrl: entry.key));
|
2020-09-08 01:27:02 +02:00
|
|
|
},
|
|
|
|
),
|
2020-09-02 01:35:30 +02:00
|
|
|
]
|
2020-09-08 16:37:58 +02: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(
|
|
|
|
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
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|