2020-01-01 18:10:13 +00:00
|
|
|
import 'dart:io';
|
|
|
|
|
|
|
|
import 'package:famedlysdk/famedlysdk.dart';
|
2020-02-23 07:49:58 +00:00
|
|
|
import 'package:fluffychat/components/settings_themes.dart';
|
2020-02-19 15:23:13 +00:00
|
|
|
import 'package:fluffychat/views/settings_devices.dart';
|
2020-04-03 18:24:25 +00:00
|
|
|
import 'package:flutter/foundation.dart';
|
2020-01-01 18:10:13 +00:00
|
|
|
import 'package:flutter/material.dart';
|
|
|
|
import 'package:image_picker/image_picker.dart';
|
2020-01-04 08:40:38 +00:00
|
|
|
import 'package:url_launcher/url_launcher.dart';
|
2020-01-01 18:10:13 +00:00
|
|
|
|
2020-02-16 14:57:50 +00:00
|
|
|
import 'app_info.dart';
|
|
|
|
import 'chat_list.dart';
|
2020-02-23 07:49:58 +00:00
|
|
|
import '../components/adaptive_page_layout.dart';
|
2020-02-16 14:57:50 +00:00
|
|
|
import 'sign_up.dart';
|
|
|
|
import '../components/dialogs/simple_dialogs.dart';
|
|
|
|
import '../components/content_banner.dart';
|
|
|
|
import '../components/matrix.dart';
|
|
|
|
import '../i18n/i18n.dart';
|
|
|
|
import '../utils/app_route.dart';
|
|
|
|
|
2020-01-01 18:10:13 +00:00
|
|
|
class SettingsView extends StatelessWidget {
|
|
|
|
@override
|
|
|
|
Widget build(BuildContext context) {
|
|
|
|
return AdaptivePageLayout(
|
|
|
|
primaryPage: FocusPage.SECOND,
|
|
|
|
firstScaffold: ChatList(),
|
|
|
|
secondScaffold: Settings(),
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
class Settings extends StatefulWidget {
|
|
|
|
@override
|
|
|
|
_SettingsState createState() => _SettingsState();
|
|
|
|
}
|
|
|
|
|
|
|
|
class _SettingsState extends State<Settings> {
|
|
|
|
Future<dynamic> profileFuture;
|
|
|
|
dynamic profile;
|
2020-02-16 14:57:50 +00:00
|
|
|
|
2020-01-01 18:10:13 +00:00
|
|
|
void logoutAction(BuildContext context) async {
|
2020-02-16 08:56:17 +00:00
|
|
|
if (await SimpleDialogs(context).askConfirmation() == false) {
|
|
|
|
return;
|
|
|
|
}
|
2020-01-01 18:10:13 +00:00
|
|
|
MatrixState matrix = Matrix.of(context);
|
2020-01-08 13:19:15 +00:00
|
|
|
await matrix.tryRequestWithLoadingDialog(matrix.client.logout());
|
2020-01-01 18:10:13 +00:00
|
|
|
matrix.clean();
|
2020-01-08 13:19:15 +00:00
|
|
|
await Navigator.of(context).pushAndRemoveUntil(
|
2020-01-09 21:52:27 +00:00
|
|
|
AppRoute.defaultRoute(context, SignUp()), (r) => false);
|
2020-01-01 18:10:13 +00:00
|
|
|
}
|
|
|
|
|
2020-02-16 08:56:17 +00:00
|
|
|
void setDisplaynameAction(BuildContext context) async {
|
|
|
|
final String displayname = await SimpleDialogs(context).enterText(
|
|
|
|
titleText: I18n.of(context).editDisplayname,
|
|
|
|
hintText:
|
|
|
|
profile?.displayname ?? Matrix.of(context).client.userID.localpart,
|
|
|
|
labelText: I18n.of(context).enterAUsername,
|
|
|
|
);
|
|
|
|
if (displayname == null) return;
|
2020-01-01 18:10:13 +00:00
|
|
|
final MatrixState matrix = Matrix.of(context);
|
2020-02-16 08:56:17 +00:00
|
|
|
final success = await matrix.tryRequestWithLoadingDialog(
|
2020-01-19 14:07:42 +00:00
|
|
|
matrix.client.setDisplayname(displayname),
|
2020-01-01 18:10:13 +00:00
|
|
|
);
|
2020-02-16 08:56:17 +00:00
|
|
|
if (success != false) {
|
2020-01-01 18:10:13 +00:00
|
|
|
setState(() {
|
|
|
|
profileFuture = null;
|
|
|
|
profile = null;
|
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void setAvatarAction(BuildContext context) async {
|
|
|
|
final File tempFile = await ImagePicker.pickImage(
|
|
|
|
source: ImageSource.gallery,
|
|
|
|
imageQuality: 50,
|
|
|
|
maxWidth: 1600,
|
|
|
|
maxHeight: 1600);
|
|
|
|
if (tempFile == null) return;
|
|
|
|
final MatrixState matrix = Matrix.of(context);
|
2020-01-04 08:40:38 +00:00
|
|
|
final success = await matrix.tryRequestWithLoadingDialog(
|
2020-01-01 18:10:13 +00:00
|
|
|
matrix.client.setAvatar(
|
|
|
|
MatrixFile(
|
|
|
|
bytes: await tempFile.readAsBytes(),
|
|
|
|
path: tempFile.path,
|
|
|
|
),
|
|
|
|
),
|
|
|
|
);
|
2020-01-04 08:40:38 +00:00
|
|
|
if (success != false) {
|
2020-01-01 18:10:13 +00:00
|
|
|
setState(() {
|
|
|
|
profileFuture = null;
|
|
|
|
profile = null;
|
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-04-03 18:24:25 +00:00
|
|
|
void setWallpaperAction(BuildContext context) async {
|
|
|
|
final wallpaper = await ImagePicker.pickImage(source: ImageSource.gallery);
|
|
|
|
if (wallpaper == null) return;
|
|
|
|
Matrix.of(context).wallpaper = wallpaper;
|
|
|
|
await Matrix.of(context)
|
|
|
|
.client
|
|
|
|
.storeAPI
|
|
|
|
.setItem("chat.fluffy.wallpaper", wallpaper.path);
|
|
|
|
setState(() => null);
|
|
|
|
}
|
|
|
|
|
|
|
|
void deleteWallpaperAction(BuildContext context) async {
|
|
|
|
Matrix.of(context).wallpaper = null;
|
|
|
|
await Matrix.of(context)
|
|
|
|
.client
|
|
|
|
.storeAPI
|
|
|
|
.setItem("chat.fluffy.wallpaper", null);
|
|
|
|
setState(() => null);
|
|
|
|
}
|
|
|
|
|
2020-01-01 18:10:13 +00:00
|
|
|
@override
|
|
|
|
Widget build(BuildContext context) {
|
|
|
|
final Client client = Matrix.of(context).client;
|
2020-01-19 14:30:23 +00:00
|
|
|
profileFuture ??= client.ownProfile;
|
2020-01-08 13:19:15 +00:00
|
|
|
profileFuture.then((p) {
|
|
|
|
if (mounted) setState(() => profile = p);
|
|
|
|
});
|
2020-01-01 18:10:13 +00:00
|
|
|
return Scaffold(
|
2020-02-16 09:42:59 +00:00
|
|
|
body: NestedScrollView(
|
|
|
|
headerSliverBuilder: (BuildContext context, bool innerBoxIsScrolled) =>
|
|
|
|
<Widget>[
|
|
|
|
SliverAppBar(
|
|
|
|
expandedHeight: 300.0,
|
|
|
|
floating: true,
|
|
|
|
pinned: true,
|
|
|
|
backgroundColor: Theme.of(context).appBarTheme.color,
|
|
|
|
flexibleSpace: FlexibleSpaceBar(
|
2020-02-16 19:11:39 +00:00
|
|
|
title: Text(
|
|
|
|
I18n.of(context).settings,
|
|
|
|
style: TextStyle(
|
2020-02-16 19:28:07 +00:00
|
|
|
color: Theme.of(context).appBarTheme.textTheme.title.color),
|
2020-02-16 19:11:39 +00:00
|
|
|
),
|
2020-02-16 09:42:59 +00:00
|
|
|
background: ContentBanner(
|
|
|
|
profile?.avatarUrl ?? MxContent(""),
|
|
|
|
height: 300,
|
|
|
|
defaultIcon: Icons.account_circle,
|
|
|
|
loading: profile == null,
|
|
|
|
onEdit: () => setAvatarAction(context),
|
2020-01-01 18:10:13 +00:00
|
|
|
),
|
|
|
|
),
|
|
|
|
),
|
2020-02-16 09:42:59 +00:00
|
|
|
],
|
|
|
|
body: ListView(
|
|
|
|
children: <Widget>[
|
2020-02-23 07:49:58 +00:00
|
|
|
ListTile(
|
|
|
|
title: Text(
|
|
|
|
I18n.of(context).changeTheme,
|
|
|
|
style: TextStyle(
|
|
|
|
color: Theme.of(context).primaryColor,
|
|
|
|
fontWeight: FontWeight.bold,
|
|
|
|
),
|
|
|
|
),
|
|
|
|
),
|
|
|
|
ThemesSettings(),
|
2020-04-03 18:24:25 +00:00
|
|
|
if (!kIsWeb && client.storeAPI != null) Divider(thickness: 1),
|
|
|
|
if (!kIsWeb && client.storeAPI != null)
|
|
|
|
ListTile(
|
|
|
|
title: Text(
|
|
|
|
I18n.of(context).wallpaper,
|
|
|
|
style: TextStyle(
|
|
|
|
color: Theme.of(context).primaryColor,
|
|
|
|
fontWeight: FontWeight.bold,
|
|
|
|
),
|
|
|
|
),
|
|
|
|
),
|
|
|
|
if (Matrix.of(context).wallpaper != null)
|
|
|
|
ListTile(
|
|
|
|
title: Image.file(
|
|
|
|
Matrix.of(context).wallpaper,
|
|
|
|
height: 38,
|
|
|
|
fit: BoxFit.cover,
|
|
|
|
),
|
|
|
|
trailing: Icon(
|
|
|
|
Icons.delete_forever,
|
|
|
|
color: Colors.red,
|
|
|
|
),
|
|
|
|
onTap: () => deleteWallpaperAction(context),
|
|
|
|
),
|
|
|
|
if (!kIsWeb && client.storeAPI != null)
|
|
|
|
Builder(builder: (context) {
|
|
|
|
return ListTile(
|
|
|
|
title: Text(I18n.of(context).changeWallpaper),
|
|
|
|
trailing: Icon(Icons.wallpaper),
|
|
|
|
onTap: () => setWallpaperAction(context),
|
|
|
|
);
|
|
|
|
}),
|
2020-02-23 07:49:58 +00:00
|
|
|
Divider(thickness: 1),
|
2020-02-16 09:42:59 +00:00
|
|
|
ListTile(
|
|
|
|
title: Text(
|
|
|
|
I18n.of(context).account,
|
|
|
|
style: TextStyle(
|
|
|
|
color: Theme.of(context).primaryColor,
|
|
|
|
fontWeight: FontWeight.bold,
|
|
|
|
),
|
2020-01-04 08:40:38 +00:00
|
|
|
),
|
|
|
|
),
|
2020-02-16 09:42:59 +00:00
|
|
|
ListTile(
|
|
|
|
trailing: Icon(Icons.edit),
|
|
|
|
title: Text(I18n.of(context).editDisplayname),
|
|
|
|
subtitle: Text(profile?.displayname ?? client.userID.localpart),
|
|
|
|
onTap: () => setDisplaynameAction(context),
|
2020-02-15 08:20:08 +00:00
|
|
|
),
|
2020-02-16 14:57:50 +00:00
|
|
|
ListTile(
|
2020-02-23 07:49:58 +00:00
|
|
|
trailing: Icon(Icons.devices_other),
|
|
|
|
title: Text(I18n.of(context).devices),
|
2020-02-16 14:57:50 +00:00
|
|
|
onTap: () async => await Navigator.of(context).push(
|
|
|
|
AppRoute.defaultRoute(
|
|
|
|
context,
|
2020-02-23 07:49:58 +00:00
|
|
|
DevicesSettingsView(),
|
2020-02-16 14:57:50 +00:00
|
|
|
),
|
|
|
|
),
|
|
|
|
),
|
2020-02-19 15:23:13 +00:00
|
|
|
ListTile(
|
2020-02-23 07:49:58 +00:00
|
|
|
trailing: Icon(Icons.account_circle),
|
|
|
|
title: Text(I18n.of(context).accountInformations),
|
|
|
|
onTap: () => Navigator.of(context).push(
|
2020-02-19 15:23:13 +00:00
|
|
|
AppRoute.defaultRoute(
|
|
|
|
context,
|
2020-02-23 07:49:58 +00:00
|
|
|
AppInfoView(),
|
2020-02-19 15:23:13 +00:00
|
|
|
),
|
|
|
|
),
|
|
|
|
),
|
2020-02-16 09:42:59 +00:00
|
|
|
ListTile(
|
|
|
|
trailing: Icon(Icons.exit_to_app),
|
|
|
|
title: Text(I18n.of(context).logout),
|
|
|
|
onTap: () => logoutAction(context),
|
|
|
|
),
|
|
|
|
Divider(thickness: 1),
|
|
|
|
ListTile(
|
|
|
|
title: Text(
|
|
|
|
I18n.of(context).about,
|
|
|
|
style: TextStyle(
|
|
|
|
color: Theme.of(context).primaryColor,
|
|
|
|
fontWeight: FontWeight.bold,
|
|
|
|
),
|
2020-02-16 08:56:17 +00:00
|
|
|
),
|
|
|
|
),
|
2020-02-16 09:42:59 +00:00
|
|
|
ListTile(
|
2020-03-29 10:06:25 +00:00
|
|
|
trailing: Icon(Icons.help),
|
2020-02-16 09:42:59 +00:00
|
|
|
title: Text(I18n.of(context).help),
|
|
|
|
onTap: () => launch(
|
|
|
|
"https://gitlab.com/ChristianPauly/fluffychat-flutter/issues"),
|
|
|
|
),
|
|
|
|
ListTile(
|
2020-03-29 10:06:25 +00:00
|
|
|
trailing: Icon(Icons.link),
|
2020-02-16 09:42:59 +00:00
|
|
|
title: Text(I18n.of(context).license),
|
|
|
|
onTap: () => launch(
|
|
|
|
"https://gitlab.com/ChristianPauly/fluffychat-flutter/raw/master/LICENSE"),
|
|
|
|
),
|
|
|
|
ListTile(
|
2020-03-29 10:06:25 +00:00
|
|
|
trailing: Icon(Icons.code),
|
2020-02-16 09:42:59 +00:00
|
|
|
title: Text(I18n.of(context).sourceCode),
|
|
|
|
onTap: () => launch(
|
|
|
|
"https://gitlab.com/ChristianPauly/fluffychat-flutter"),
|
|
|
|
),
|
|
|
|
],
|
|
|
|
),
|
2020-01-01 18:10:13 +00:00
|
|
|
),
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|