2020-06-20 11:32:49 +02:00
|
|
|
import 'dart:io';
|
|
|
|
|
2020-01-01 19:10:13 +01:00
|
|
|
import 'package:famedlysdk/famedlysdk.dart';
|
2020-02-23 08:49:58 +01:00
|
|
|
import 'package:fluffychat/components/settings_themes.dart';
|
2020-02-19 16:23:13 +01:00
|
|
|
import 'package:fluffychat/views/settings_devices.dart';
|
2020-04-03 20:24:25 +02:00
|
|
|
import 'package:flutter/foundation.dart';
|
2020-01-01 19:10:13 +01:00
|
|
|
import 'package:flutter/material.dart';
|
|
|
|
import 'package:image_picker/image_picker.dart';
|
2020-06-20 11:32:49 +02:00
|
|
|
import 'package:memoryfilepicker/memoryfilepicker.dart';
|
2020-01-04 09:40:38 +01:00
|
|
|
import 'package:url_launcher/url_launcher.dart';
|
2020-01-01 19:10:13 +01:00
|
|
|
|
2020-02-16 15:57:50 +01:00
|
|
|
import 'app_info.dart';
|
|
|
|
import 'chat_list.dart';
|
2020-02-23 08:49:58 +01:00
|
|
|
import '../components/adaptive_page_layout.dart';
|
2020-02-16 15:57:50 +01:00
|
|
|
import '../components/dialogs/simple_dialogs.dart';
|
|
|
|
import '../components/content_banner.dart';
|
|
|
|
import '../components/matrix.dart';
|
2020-05-07 07:52:40 +02:00
|
|
|
import '../l10n/l10n.dart';
|
2020-02-16 15:57:50 +01:00
|
|
|
import '../utils/app_route.dart';
|
2020-05-12 09:02:33 +02:00
|
|
|
import 'settings_emotes.dart';
|
2020-02-16 15:57:50 +01:00
|
|
|
|
2020-01-01 19:10:13 +01: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 15:57:50 +01:00
|
|
|
|
2020-01-01 19:10:13 +01:00
|
|
|
void logoutAction(BuildContext context) async {
|
2020-02-16 09:56:17 +01:00
|
|
|
if (await SimpleDialogs(context).askConfirmation() == false) {
|
|
|
|
return;
|
|
|
|
}
|
2020-05-13 15:58:59 +02:00
|
|
|
var matrix = Matrix.of(context);
|
2020-04-27 13:36:39 +02:00
|
|
|
await SimpleDialogs(context)
|
|
|
|
.tryRequestWithLoadingDialog(matrix.client.logout());
|
2020-01-01 19:10:13 +01:00
|
|
|
}
|
|
|
|
|
2020-04-08 17:43:07 +02:00
|
|
|
void setJitsiInstanceAction(BuildContext context) async {
|
|
|
|
var jitsi = await SimpleDialogs(context).enterText(
|
2020-05-07 07:52:40 +02:00
|
|
|
titleText: L10n.of(context).editJitsiInstance,
|
2020-04-08 17:43:07 +02:00
|
|
|
hintText: Matrix.of(context).jitsiInstance,
|
2020-05-07 07:52:40 +02:00
|
|
|
labelText: L10n.of(context).editJitsiInstance,
|
2020-04-08 17:43:07 +02:00
|
|
|
);
|
|
|
|
if (jitsi == null) return;
|
|
|
|
if (!jitsi.endsWith('/')) {
|
|
|
|
jitsi += '/';
|
|
|
|
}
|
2020-05-13 15:58:59 +02:00
|
|
|
final matrix = Matrix.of(context);
|
|
|
|
await matrix.store.setItem('chat.fluffy.jitsi_instance', jitsi);
|
2020-04-08 17:43:07 +02:00
|
|
|
matrix.jitsiInstance = jitsi;
|
|
|
|
}
|
|
|
|
|
2020-02-16 09:56:17 +01:00
|
|
|
void setDisplaynameAction(BuildContext context) async {
|
2020-05-13 15:58:59 +02:00
|
|
|
final displayname = await SimpleDialogs(context).enterText(
|
2020-05-07 07:52:40 +02:00
|
|
|
titleText: L10n.of(context).editDisplayname,
|
2020-02-16 09:56:17 +01:00
|
|
|
hintText:
|
|
|
|
profile?.displayname ?? Matrix.of(context).client.userID.localpart,
|
2020-05-07 07:52:40 +02:00
|
|
|
labelText: L10n.of(context).enterAUsername,
|
2020-02-16 09:56:17 +01:00
|
|
|
);
|
|
|
|
if (displayname == null) return;
|
2020-05-13 15:58:59 +02:00
|
|
|
final matrix = Matrix.of(context);
|
2020-04-27 13:36:39 +02:00
|
|
|
final success = await SimpleDialogs(context).tryRequestWithLoadingDialog(
|
2020-01-19 15:07:42 +01:00
|
|
|
matrix.client.setDisplayname(displayname),
|
2020-01-01 19:10:13 +01:00
|
|
|
);
|
2020-02-16 09:56:17 +01:00
|
|
|
if (success != false) {
|
2020-01-01 19:10:13 +01:00
|
|
|
setState(() {
|
|
|
|
profileFuture = null;
|
|
|
|
profile = null;
|
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void setAvatarAction(BuildContext context) async {
|
2020-06-20 11:32:49 +02:00
|
|
|
final tempFile = await MemoryFilePicker.getImage(
|
2020-01-01 19:10:13 +01:00
|
|
|
source: ImageSource.gallery,
|
|
|
|
imageQuality: 50,
|
|
|
|
maxWidth: 1600,
|
|
|
|
maxHeight: 1600);
|
|
|
|
if (tempFile == null) return;
|
2020-05-13 15:58:59 +02:00
|
|
|
final matrix = Matrix.of(context);
|
2020-04-27 13:36:39 +02:00
|
|
|
final success = await SimpleDialogs(context).tryRequestWithLoadingDialog(
|
2020-01-01 19:10:13 +01:00
|
|
|
matrix.client.setAvatar(
|
|
|
|
MatrixFile(
|
2020-06-20 11:32:49 +02:00
|
|
|
bytes: tempFile.bytes,
|
2020-01-01 19:10:13 +01:00
|
|
|
path: tempFile.path,
|
|
|
|
),
|
|
|
|
),
|
|
|
|
);
|
2020-01-04 09:40:38 +01:00
|
|
|
if (success != false) {
|
2020-01-01 19:10:13 +01:00
|
|
|
setState(() {
|
|
|
|
profileFuture = null;
|
|
|
|
profile = null;
|
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-04-03 20:24:25 +02:00
|
|
|
void setWallpaperAction(BuildContext context) async {
|
2020-06-20 11:32:49 +02:00
|
|
|
final wallpaper = await ImagePicker().getImage(source: ImageSource.gallery);
|
2020-04-03 20:24:25 +02:00
|
|
|
if (wallpaper == null) return;
|
2020-06-20 11:32:49 +02:00
|
|
|
Matrix.of(context).wallpaper = File(wallpaper.path);
|
2020-04-03 20:24:25 +02:00
|
|
|
await Matrix.of(context)
|
2020-05-13 15:58:59 +02:00
|
|
|
.store
|
|
|
|
.setItem('chat.fluffy.wallpaper', wallpaper.path);
|
2020-04-03 20:24:25 +02:00
|
|
|
setState(() => null);
|
|
|
|
}
|
|
|
|
|
|
|
|
void deleteWallpaperAction(BuildContext context) async {
|
|
|
|
Matrix.of(context).wallpaper = null;
|
2020-05-13 15:58:59 +02:00
|
|
|
await Matrix.of(context).store.setItem('chat.fluffy.wallpaper', null);
|
2020-04-03 20:24:25 +02:00
|
|
|
setState(() => null);
|
|
|
|
}
|
|
|
|
|
2020-01-01 19:10:13 +01:00
|
|
|
@override
|
|
|
|
Widget build(BuildContext context) {
|
2020-05-13 15:58:59 +02:00
|
|
|
final client = Matrix.of(context).client;
|
2020-01-19 15:30:23 +01:00
|
|
|
profileFuture ??= client.ownProfile;
|
2020-01-08 14:19:15 +01:00
|
|
|
profileFuture.then((p) {
|
|
|
|
if (mounted) setState(() => profile = p);
|
|
|
|
});
|
2020-01-01 19:10:13 +01:00
|
|
|
return Scaffold(
|
2020-02-16 10:42:59 +01: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 20:11:39 +01:00
|
|
|
title: Text(
|
2020-05-07 07:52:40 +02:00
|
|
|
L10n.of(context).settings,
|
2020-02-16 20:11:39 +01:00
|
|
|
style: TextStyle(
|
2020-05-06 18:43:30 +02:00
|
|
|
color: Theme.of(context)
|
|
|
|
.appBarTheme
|
|
|
|
.textTheme
|
|
|
|
.headline6
|
|
|
|
.color),
|
2020-02-16 20:11:39 +01:00
|
|
|
),
|
2020-02-16 10:42:59 +01:00
|
|
|
background: ContentBanner(
|
2020-04-28 14:11:56 +02:00
|
|
|
profile?.avatarUrl,
|
2020-02-16 10:42:59 +01:00
|
|
|
height: 300,
|
|
|
|
defaultIcon: Icons.account_circle,
|
|
|
|
loading: profile == null,
|
|
|
|
onEdit: () => setAvatarAction(context),
|
2020-01-01 19:10:13 +01:00
|
|
|
),
|
|
|
|
),
|
|
|
|
),
|
2020-02-16 10:42:59 +01:00
|
|
|
],
|
|
|
|
body: ListView(
|
|
|
|
children: <Widget>[
|
2020-02-23 08:49:58 +01:00
|
|
|
ListTile(
|
|
|
|
title: Text(
|
2020-05-07 07:52:40 +02:00
|
|
|
L10n.of(context).changeTheme,
|
2020-02-23 08:49:58 +01:00
|
|
|
style: TextStyle(
|
|
|
|
color: Theme.of(context).primaryColor,
|
|
|
|
fontWeight: FontWeight.bold,
|
|
|
|
),
|
|
|
|
),
|
|
|
|
),
|
|
|
|
ThemesSettings(),
|
2020-05-13 15:58:59 +02:00
|
|
|
if (!kIsWeb && Matrix.of(context).store != null)
|
|
|
|
Divider(thickness: 1),
|
|
|
|
if (!kIsWeb && Matrix.of(context).store != null)
|
2020-04-03 20:24:25 +02:00
|
|
|
ListTile(
|
|
|
|
title: Text(
|
2020-05-07 07:52:40 +02:00
|
|
|
L10n.of(context).wallpaper,
|
2020-04-03 20:24:25 +02:00
|
|
|
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),
|
|
|
|
),
|
2020-05-13 15:58:59 +02:00
|
|
|
if (!kIsWeb && Matrix.of(context).store != null)
|
2020-04-03 20:24:25 +02:00
|
|
|
Builder(builder: (context) {
|
|
|
|
return ListTile(
|
2020-05-07 07:52:40 +02:00
|
|
|
title: Text(L10n.of(context).changeWallpaper),
|
2020-04-03 20:24:25 +02:00
|
|
|
trailing: Icon(Icons.wallpaper),
|
|
|
|
onTap: () => setWallpaperAction(context),
|
|
|
|
);
|
|
|
|
}),
|
2020-02-23 08:49:58 +01:00
|
|
|
Divider(thickness: 1),
|
2020-05-09 13:36:41 +02:00
|
|
|
ListTile(
|
|
|
|
title: Text(
|
|
|
|
L10n.of(context).chat,
|
|
|
|
style: TextStyle(
|
|
|
|
color: Theme.of(context).primaryColor,
|
|
|
|
fontWeight: FontWeight.bold,
|
|
|
|
),
|
|
|
|
),
|
|
|
|
),
|
|
|
|
ListTile(
|
|
|
|
title: Text(L10n.of(context).renderRichContent),
|
|
|
|
trailing: Switch(
|
|
|
|
value: Matrix.of(context).renderHtml,
|
|
|
|
activeColor: Theme.of(context).primaryColor,
|
|
|
|
onChanged: (bool newValue) async {
|
|
|
|
Matrix.of(context).renderHtml = newValue;
|
2020-05-13 15:58:59 +02:00
|
|
|
await Matrix.of(context)
|
|
|
|
.store
|
|
|
|
.setItem('chat.fluffy.renderHtml', newValue ? '1' : '0');
|
2020-05-09 13:36:41 +02:00
|
|
|
setState(() => null);
|
|
|
|
},
|
|
|
|
),
|
|
|
|
),
|
2020-05-12 09:02:33 +02:00
|
|
|
ListTile(
|
|
|
|
title: Text(L10n.of(context).emoteSettings),
|
|
|
|
onTap: () async => await Navigator.of(context).push(
|
|
|
|
AppRoute.defaultRoute(
|
|
|
|
context,
|
|
|
|
EmotesSettingsView(),
|
|
|
|
),
|
|
|
|
),
|
|
|
|
trailing: Icon(Icons.insert_emoticon),
|
|
|
|
),
|
2020-05-09 13:36:41 +02:00
|
|
|
Divider(thickness: 1),
|
2020-02-16 10:42:59 +01:00
|
|
|
ListTile(
|
|
|
|
title: Text(
|
2020-05-07 07:52:40 +02:00
|
|
|
L10n.of(context).account,
|
2020-02-16 10:42:59 +01:00
|
|
|
style: TextStyle(
|
|
|
|
color: Theme.of(context).primaryColor,
|
|
|
|
fontWeight: FontWeight.bold,
|
|
|
|
),
|
2020-01-04 09:40:38 +01:00
|
|
|
),
|
|
|
|
),
|
2020-02-16 10:42:59 +01:00
|
|
|
ListTile(
|
|
|
|
trailing: Icon(Icons.edit),
|
2020-05-07 07:52:40 +02:00
|
|
|
title: Text(L10n.of(context).editDisplayname),
|
2020-02-16 10:42:59 +01:00
|
|
|
subtitle: Text(profile?.displayname ?? client.userID.localpart),
|
|
|
|
onTap: () => setDisplaynameAction(context),
|
2020-02-15 09:20:08 +01:00
|
|
|
),
|
2020-04-08 17:43:07 +02:00
|
|
|
ListTile(
|
|
|
|
trailing: Icon(Icons.phone),
|
2020-05-07 07:52:40 +02:00
|
|
|
title: Text(L10n.of(context).editJitsiInstance),
|
2020-04-08 17:43:07 +02:00
|
|
|
subtitle: Text(Matrix.of(context).jitsiInstance),
|
|
|
|
onTap: () => setJitsiInstanceAction(context),
|
|
|
|
),
|
2020-02-16 15:57:50 +01:00
|
|
|
ListTile(
|
2020-02-23 08:49:58 +01:00
|
|
|
trailing: Icon(Icons.devices_other),
|
2020-05-07 07:52:40 +02:00
|
|
|
title: Text(L10n.of(context).devices),
|
2020-02-16 15:57:50 +01:00
|
|
|
onTap: () async => await Navigator.of(context).push(
|
|
|
|
AppRoute.defaultRoute(
|
|
|
|
context,
|
2020-02-23 08:49:58 +01:00
|
|
|
DevicesSettingsView(),
|
2020-02-16 15:57:50 +01:00
|
|
|
),
|
|
|
|
),
|
|
|
|
),
|
2020-02-19 16:23:13 +01:00
|
|
|
ListTile(
|
2020-02-23 08:49:58 +01:00
|
|
|
trailing: Icon(Icons.account_circle),
|
2020-05-07 07:52:40 +02:00
|
|
|
title: Text(L10n.of(context).accountInformations),
|
2020-02-23 08:49:58 +01:00
|
|
|
onTap: () => Navigator.of(context).push(
|
2020-02-19 16:23:13 +01:00
|
|
|
AppRoute.defaultRoute(
|
|
|
|
context,
|
2020-02-23 08:49:58 +01:00
|
|
|
AppInfoView(),
|
2020-02-19 16:23:13 +01:00
|
|
|
),
|
|
|
|
),
|
|
|
|
),
|
2020-02-16 10:42:59 +01:00
|
|
|
ListTile(
|
|
|
|
trailing: Icon(Icons.exit_to_app),
|
2020-05-07 07:52:40 +02:00
|
|
|
title: Text(L10n.of(context).logout),
|
2020-02-16 10:42:59 +01:00
|
|
|
onTap: () => logoutAction(context),
|
|
|
|
),
|
|
|
|
Divider(thickness: 1),
|
|
|
|
ListTile(
|
|
|
|
title: Text(
|
2020-05-07 07:52:40 +02:00
|
|
|
L10n.of(context).about,
|
2020-02-16 10:42:59 +01:00
|
|
|
style: TextStyle(
|
|
|
|
color: Theme.of(context).primaryColor,
|
|
|
|
fontWeight: FontWeight.bold,
|
|
|
|
),
|
2020-02-16 09:56:17 +01:00
|
|
|
),
|
|
|
|
),
|
2020-02-16 10:42:59 +01:00
|
|
|
ListTile(
|
2020-03-29 12:06:25 +02:00
|
|
|
trailing: Icon(Icons.help),
|
2020-05-07 07:52:40 +02:00
|
|
|
title: Text(L10n.of(context).help),
|
2020-02-16 10:42:59 +01:00
|
|
|
onTap: () => launch(
|
2020-05-13 15:58:59 +02:00
|
|
|
'https://gitlab.com/ChristianPauly/fluffychat-flutter/issues'),
|
2020-02-16 10:42:59 +01:00
|
|
|
),
|
|
|
|
ListTile(
|
2020-03-29 12:06:25 +02:00
|
|
|
trailing: Icon(Icons.link),
|
2020-05-07 07:52:40 +02:00
|
|
|
title: Text(L10n.of(context).license),
|
2020-02-16 10:42:59 +01:00
|
|
|
onTap: () => launch(
|
2020-05-13 15:58:59 +02:00
|
|
|
'https://gitlab.com/ChristianPauly/fluffychat-flutter/raw/master/LICENSE'),
|
2020-02-16 10:42:59 +01:00
|
|
|
),
|
|
|
|
ListTile(
|
2020-03-29 12:06:25 +02:00
|
|
|
trailing: Icon(Icons.code),
|
2020-05-07 07:52:40 +02:00
|
|
|
title: Text(L10n.of(context).sourceCode),
|
2020-02-16 10:42:59 +01:00
|
|
|
onTap: () => launch(
|
2020-05-13 15:58:59 +02:00
|
|
|
'https://gitlab.com/ChristianPauly/fluffychat-flutter'),
|
2020-02-16 10:42:59 +01:00
|
|
|
),
|
|
|
|
],
|
|
|
|
),
|
2020-01-01 19:10:13 +01:00
|
|
|
),
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|