2020-01-01 19:10:13 +01:00
|
|
|
import 'dart:io';
|
|
|
|
|
|
|
|
import 'package:famedlysdk/famedlysdk.dart';
|
|
|
|
import 'package:fluffychat/components/adaptive_page_layout.dart';
|
|
|
|
import 'package:fluffychat/components/content_banner.dart';
|
|
|
|
import 'package:fluffychat/components/matrix.dart';
|
2020-01-20 13:46:39 +01:00
|
|
|
import 'package:fluffychat/i18n/i18n.dart';
|
2020-01-08 14:19:15 +01:00
|
|
|
import 'package:fluffychat/utils/app_route.dart';
|
2020-02-15 09:20:08 +01:00
|
|
|
import 'package:fluffychat/views/app_info.dart';
|
2020-01-01 19:10:13 +01:00
|
|
|
import 'package:fluffychat/views/chat_list.dart';
|
2020-01-09 22:52:27 +01:00
|
|
|
import 'package:fluffychat/views/sign_up.dart';
|
2020-01-23 12:11:57 +01: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';
|
|
|
|
import 'package:toast/toast.dart';
|
2020-01-04 09:40:38 +01:00
|
|
|
import 'package:url_launcher/url_launcher.dart';
|
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;
|
|
|
|
void logoutAction(BuildContext context) async {
|
|
|
|
MatrixState matrix = Matrix.of(context);
|
2020-01-08 14:19:15 +01:00
|
|
|
await matrix.tryRequestWithLoadingDialog(matrix.client.logout());
|
2020-01-01 19:10:13 +01:00
|
|
|
matrix.clean();
|
2020-01-08 14:19:15 +01:00
|
|
|
await Navigator.of(context).pushAndRemoveUntil(
|
2020-01-09 22:52:27 +01:00
|
|
|
AppRoute.defaultRoute(context, SignUp()), (r) => false);
|
2020-01-01 19:10:13 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
void setDisplaynameAction(BuildContext context, String displayname) async {
|
|
|
|
final MatrixState matrix = Matrix.of(context);
|
|
|
|
final Map<String, dynamic> success =
|
|
|
|
await matrix.tryRequestWithLoadingDialog(
|
2020-01-19 15:07:42 +01:00
|
|
|
matrix.client.setDisplayname(displayname),
|
2020-01-01 19:10:13 +01:00
|
|
|
);
|
2020-01-02 22:31:39 +01:00
|
|
|
if (success != null && success.isEmpty) {
|
2020-01-01 19:10:13 +01:00
|
|
|
Toast.show(
|
2020-01-20 13:46:39 +01:00
|
|
|
I18n.of(context).displaynameHasBeenChanged,
|
2020-01-01 19:10:13 +01:00
|
|
|
context,
|
|
|
|
duration: Toast.LENGTH_LONG,
|
|
|
|
);
|
|
|
|
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 09:40:38 +01:00
|
|
|
final success = await matrix.tryRequestWithLoadingDialog(
|
2020-01-01 19:10:13 +01:00
|
|
|
matrix.client.setAvatar(
|
|
|
|
MatrixFile(
|
|
|
|
bytes: await tempFile.readAsBytes(),
|
|
|
|
path: tempFile.path,
|
|
|
|
),
|
|
|
|
),
|
|
|
|
);
|
2020-01-04 09:40:38 +01:00
|
|
|
if (success != false) {
|
2020-01-01 19:10:13 +01:00
|
|
|
Toast.show(
|
2020-01-20 13:46:39 +01:00
|
|
|
I18n.of(context).avatarHasBeenChanged,
|
2020-01-01 19:10:13 +01:00
|
|
|
context,
|
|
|
|
duration: Toast.LENGTH_LONG,
|
|
|
|
);
|
|
|
|
setState(() {
|
|
|
|
profileFuture = null;
|
|
|
|
profile = null;
|
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
@override
|
|
|
|
Widget build(BuildContext context) {
|
|
|
|
final Client 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(
|
|
|
|
appBar: AppBar(
|
2020-01-20 13:46:39 +01:00
|
|
|
title: Text(I18n.of(context).settings),
|
2020-01-01 19:10:13 +01:00
|
|
|
),
|
|
|
|
body: ListView(
|
|
|
|
children: <Widget>[
|
|
|
|
ContentBanner(
|
|
|
|
profile?.avatarUrl ?? MxContent(""),
|
|
|
|
defaultIcon: Icons.account_circle,
|
|
|
|
loading: profile == null,
|
2020-01-23 12:11:57 +01:00
|
|
|
onEdit: kIsWeb ? null : () => setAvatarAction(context),
|
2020-01-01 19:10:13 +01:00
|
|
|
),
|
|
|
|
ListTile(
|
2020-01-04 09:40:38 +01:00
|
|
|
leading: Icon(Icons.edit),
|
2020-01-01 19:10:13 +01:00
|
|
|
title: TextField(
|
|
|
|
readOnly: profile == null,
|
|
|
|
textInputAction: TextInputAction.done,
|
|
|
|
onSubmitted: (s) => setDisplaynameAction(context, s),
|
|
|
|
decoration: InputDecoration(
|
|
|
|
border: InputBorder.none,
|
2020-01-20 13:46:39 +01:00
|
|
|
labelText: I18n.of(context).editDisplayname,
|
2020-01-01 19:10:13 +01:00
|
|
|
labelStyle: TextStyle(color: Colors.black),
|
|
|
|
hintText: (profile?.displayname ?? ""),
|
|
|
|
),
|
|
|
|
),
|
|
|
|
),
|
2020-01-19 15:07:42 +01:00
|
|
|
Divider(thickness: 8),
|
2020-01-01 19:10:13 +01:00
|
|
|
ListTile(
|
2020-01-04 09:40:38 +01:00
|
|
|
title: Text(
|
2020-01-20 13:46:39 +01:00
|
|
|
I18n.of(context).about,
|
2020-01-04 09:40:38 +01:00
|
|
|
style: TextStyle(
|
|
|
|
color: Theme.of(context).primaryColor,
|
|
|
|
fontWeight: FontWeight.bold,
|
|
|
|
),
|
|
|
|
),
|
|
|
|
),
|
2020-02-15 09:20:08 +01:00
|
|
|
ListTile(
|
|
|
|
leading: Icon(Icons.info),
|
|
|
|
title: Text(I18n.of(context).fluffychat),
|
|
|
|
onTap: () => Navigator.of(context).push(
|
|
|
|
AppRoute.defaultRoute(
|
|
|
|
context,
|
|
|
|
AppInfoView(),
|
|
|
|
),
|
|
|
|
),
|
|
|
|
),
|
2020-01-04 09:40:38 +01:00
|
|
|
ListTile(
|
2020-01-20 13:46:39 +01:00
|
|
|
leading: Icon(Icons.sentiment_very_satisfied),
|
|
|
|
title: Text(I18n.of(context).donate),
|
|
|
|
onTap: () => launch("https://ko-fi.com/krille"),
|
|
|
|
),
|
|
|
|
ListTile(
|
|
|
|
leading: Icon(Icons.help),
|
|
|
|
title: Text(I18n.of(context).help),
|
|
|
|
onTap: () => launch(
|
|
|
|
"https://gitlab.com/ChristianPauly/fluffychat-flutter/issues"),
|
|
|
|
),
|
2020-01-08 20:21:05 +01:00
|
|
|
ListTile(
|
2020-01-20 13:46:39 +01:00
|
|
|
leading: Icon(Icons.list),
|
|
|
|
title: Text(I18n.of(context).changelog),
|
|
|
|
onTap: () => launch(
|
|
|
|
"https://gitlab.com/ChristianPauly/fluffychat-flutter/blob/master/CHANGELOG.md"),
|
|
|
|
),
|
2020-01-04 09:40:38 +01:00
|
|
|
ListTile(
|
2020-01-20 13:46:39 +01:00
|
|
|
leading: Icon(Icons.link),
|
|
|
|
title: Text(I18n.of(context).license),
|
|
|
|
onTap: () => launch(
|
|
|
|
"https://gitlab.com/ChristianPauly/fluffychat-flutter/raw/master/LICENSE"),
|
|
|
|
),
|
2020-01-04 09:40:38 +01:00
|
|
|
ListTile(
|
2020-01-20 13:46:39 +01:00
|
|
|
leading: Icon(Icons.code),
|
|
|
|
title: Text(I18n.of(context).sourceCode),
|
|
|
|
onTap: () =>
|
|
|
|
launch("https://gitlab.com/ChristianPauly/fluffychat-flutter"),
|
|
|
|
),
|
2020-01-19 15:07:42 +01:00
|
|
|
Divider(thickness: 8),
|
2020-01-04 09:40:38 +01:00
|
|
|
ListTile(
|
|
|
|
title: Text(
|
2020-01-20 13:46:39 +01:00
|
|
|
I18n.of(context).logout,
|
2020-01-04 09:40:38 +01:00
|
|
|
style: TextStyle(
|
|
|
|
color: Theme.of(context).primaryColor,
|
|
|
|
fontWeight: FontWeight.bold,
|
|
|
|
),
|
|
|
|
),
|
|
|
|
),
|
|
|
|
ListTile(
|
|
|
|
leading: Icon(Icons.exit_to_app),
|
2020-01-20 13:46:39 +01:00
|
|
|
title: Text(I18n.of(context).logout),
|
2020-01-01 19:10:13 +01:00
|
|
|
onTap: () => logoutAction(context),
|
|
|
|
),
|
|
|
|
],
|
|
|
|
),
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|