feat: More beautiful status
This commit is contained in:
parent
e569be7c07
commit
d9c2d4f754
|
@ -1,7 +1,7 @@
|
|||
import 'package:famedlysdk/famedlysdk.dart';
|
||||
import 'package:fluffychat/components/dialogs/presence_dialog.dart';
|
||||
import 'package:fluffychat/utils/app_route.dart';
|
||||
import 'package:fluffychat/views/chat.dart';
|
||||
import 'package:fluffychat/views/presence_view.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import '../avatar.dart';
|
||||
import '../matrix.dart';
|
||||
|
@ -33,13 +33,22 @@ class PresenceListItem extends StatelessWidget {
|
|||
borderRadius: BorderRadius.circular(8),
|
||||
onTap: () => presence?.presence?.statusMsg == null
|
||||
? _startChatAction(context, user.id)
|
||||
: showDialog(
|
||||
: /*showDialog(
|
||||
context: context,
|
||||
builder: (_) => PresenceDialog(
|
||||
presence,
|
||||
avatarUrl: user.avatarUrl,
|
||||
displayname: user.calcDisplayname(),
|
||||
),
|
||||
),*/
|
||||
Navigator.of(context).push(
|
||||
MaterialPageRoute(
|
||||
builder: (_) => PresenceView(
|
||||
presence: presence,
|
||||
avatarUrl: user.avatarUrl,
|
||||
displayname: user.calcDisplayname(),
|
||||
),
|
||||
),
|
||||
),
|
||||
child: Container(
|
||||
width: 76,
|
||||
|
|
|
@ -8,7 +8,6 @@ import 'package:fluffychat/components/adaptive_page_layout.dart';
|
|||
import 'package:fluffychat/components/avatar.dart';
|
||||
import 'package:fluffychat/components/chat_settings_popup_menu.dart';
|
||||
import 'package:fluffychat/components/connection_status_header.dart';
|
||||
import 'package:fluffychat/components/dialogs/presence_dialog.dart';
|
||||
import 'package:fluffychat/components/dialogs/recording_dialog.dart';
|
||||
import 'package:fluffychat/components/dialogs/simple_dialogs.dart';
|
||||
import 'package:fluffychat/components/encryption_button.dart';
|
||||
|
@ -460,24 +459,16 @@ class _ChatState extends State<_Chat> {
|
|||
return ListTile(
|
||||
leading: Avatar(room.avatar, room.displayname),
|
||||
contentPadding: EdgeInsets.zero,
|
||||
onTap: () =>
|
||||
room.isDirectChat && room.directChatPresence == null
|
||||
onTap: room.isDirectChat && room.directChatPresence == null
|
||||
? null
|
||||
: room.isDirectChat
|
||||
? null
|
||||
: room.isDirectChat
|
||||
? showDialog(
|
||||
context: context,
|
||||
builder: (c) => PresenceDialog(
|
||||
room.directChatPresence,
|
||||
avatarUrl: room.avatar,
|
||||
displayname: room.displayname,
|
||||
),
|
||||
)
|
||||
: Navigator.of(context).push(
|
||||
AppRoute.defaultRoute(
|
||||
context,
|
||||
ChatDetails(room),
|
||||
),
|
||||
: () => Navigator.of(context).push(
|
||||
AppRoute.defaultRoute(
|
||||
context,
|
||||
ChatDetails(room),
|
||||
),
|
||||
),
|
||||
title: Text(
|
||||
room.getLocalizedDisplayname(
|
||||
MatrixLocals(L10n.of(context))),
|
||||
|
|
|
@ -8,6 +8,7 @@ import 'package:fluffychat/components/dialogs/simple_dialogs.dart';
|
|||
import 'package:fluffychat/components/list_items/presence_list_item.dart';
|
||||
import 'package:fluffychat/components/list_items/public_room_list_item.dart';
|
||||
import 'package:fluffychat/utils/platform_infos.dart';
|
||||
import 'package:fluffychat/views/presence_view.dart';
|
||||
import 'package:flutter/foundation.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter_gen/gen_l10n/l10n.dart';
|
||||
|
@ -198,18 +199,20 @@ class _ChatListState extends State<ChatList> {
|
|||
|
||||
void _setStatus(BuildContext context) async {
|
||||
Navigator.of(context).pop();
|
||||
final status = await SimpleDialogs(context).enterText(
|
||||
multiLine: true,
|
||||
titleText: L10n.of(context).setStatus,
|
||||
labelText: L10n.of(context).setStatus,
|
||||
hintText: L10n.of(context).statusExampleMessage,
|
||||
);
|
||||
if (status?.isEmpty ?? true) return;
|
||||
await SimpleDialogs(context).tryRequestWithLoadingDialog(
|
||||
Matrix.of(context).client.sendPresence(
|
||||
Matrix.of(context).client.userID, PresenceType.online,
|
||||
statusMsg: status),
|
||||
);
|
||||
final ownProfile = await SimpleDialogs(context)
|
||||
.tryRequestWithLoadingDialog(Matrix.of(context).client.ownProfile);
|
||||
if (ownProfile is Profile) {
|
||||
await Navigator.of(context).push(
|
||||
MaterialPageRoute(
|
||||
builder: (_) => PresenceView(
|
||||
composeMode: true,
|
||||
avatarUrl: ownProfile.avatarUrl,
|
||||
displayname: ownProfile.displayname,
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
@override
|
||||
|
|
147
lib/views/presence_view.dart
Normal file
147
lib/views/presence_view.dart
Normal file
|
@ -0,0 +1,147 @@
|
|||
import 'package:famedlysdk/famedlysdk.dart';
|
||||
import 'package:fluffychat/components/avatar.dart';
|
||||
import 'package:fluffychat/components/dialogs/simple_dialogs.dart';
|
||||
import 'package:fluffychat/components/matrix.dart';
|
||||
import 'package:flutter_gen/gen_l10n/l10n.dart';
|
||||
import 'package:fluffychat/utils/app_route.dart';
|
||||
import 'package:fluffychat/utils/string_color.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:fluffychat/utils/presence_extension.dart';
|
||||
|
||||
import 'chat.dart';
|
||||
|
||||
class PresenceView extends StatelessWidget {
|
||||
final Uri avatarUrl;
|
||||
final String displayname;
|
||||
final Presence presence;
|
||||
final bool composeMode;
|
||||
final TextEditingController _composeController = TextEditingController();
|
||||
|
||||
PresenceView({
|
||||
this.composeMode = false,
|
||||
this.presence,
|
||||
this.avatarUrl,
|
||||
this.displayname,
|
||||
Key key,
|
||||
}) : super(key: key);
|
||||
|
||||
void _sendMessageAction(BuildContext context) async {
|
||||
final roomId = await User(
|
||||
presence.senderId,
|
||||
room: Room(id: '', client: Matrix.of(context).client),
|
||||
).startDirectChat();
|
||||
await Navigator.of(context).pushAndRemoveUntil(
|
||||
AppRoute.defaultRoute(
|
||||
context,
|
||||
ChatView(roomId),
|
||||
),
|
||||
(Route r) => r.isFirst);
|
||||
}
|
||||
|
||||
void _setStatusAction(BuildContext context) async {
|
||||
if (_composeController.text.isEmpty) return;
|
||||
await SimpleDialogs(context).tryRequestWithLoadingDialog(
|
||||
Matrix.of(context).client.sendPresence(
|
||||
Matrix.of(context).client.userID, PresenceType.online,
|
||||
statusMsg: _composeController.text),
|
||||
);
|
||||
await Navigator.of(context).popUntil((Route r) => r.isFirst);
|
||||
}
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
if (composeMode == false && presence == null) {
|
||||
throw ('If composeMode is null then the presence must be not null!');
|
||||
}
|
||||
final padding = const EdgeInsets.only(
|
||||
top: 16.0,
|
||||
right: 16.0,
|
||||
left: 16.0,
|
||||
bottom: 64.0,
|
||||
);
|
||||
return Scaffold(
|
||||
backgroundColor: displayname.color,
|
||||
extendBody: true,
|
||||
appBar: AppBar(
|
||||
brightness: Brightness.dark,
|
||||
leading: IconButton(
|
||||
icon: Icon(
|
||||
Icons.close,
|
||||
color: Colors.white,
|
||||
),
|
||||
onPressed: Navigator.of(context).pop,
|
||||
),
|
||||
backgroundColor: Colors.transparent,
|
||||
elevation: 1,
|
||||
title: ListTile(
|
||||
contentPadding: EdgeInsets.zero,
|
||||
leading: Avatar(avatarUrl, displayname),
|
||||
title: Text(
|
||||
displayname,
|
||||
style: TextStyle(color: Colors.white),
|
||||
),
|
||||
subtitle: Text(
|
||||
presence?.senderId ?? Matrix.of(context).client.userID,
|
||||
style: TextStyle(color: Colors.white),
|
||||
),
|
||||
),
|
||||
),
|
||||
body: Container(
|
||||
alignment: Alignment.center,
|
||||
decoration: BoxDecoration(
|
||||
gradient: LinearGradient(
|
||||
begin: Alignment.topLeft,
|
||||
end: Alignment.bottomRight,
|
||||
colors: [
|
||||
displayname.color,
|
||||
Theme.of(context).primaryColor,
|
||||
displayname.color,
|
||||
],
|
||||
),
|
||||
),
|
||||
child: composeMode
|
||||
? Padding(
|
||||
padding: padding,
|
||||
child: TextField(
|
||||
controller: _composeController,
|
||||
autofocus: true,
|
||||
minLines: 1,
|
||||
maxLines: 20,
|
||||
style: TextStyle(
|
||||
fontSize: 30,
|
||||
color: Colors.white,
|
||||
),
|
||||
textAlign: TextAlign.center,
|
||||
decoration: InputDecoration(
|
||||
border: InputBorder.none,
|
||||
),
|
||||
),
|
||||
)
|
||||
: ListView(
|
||||
shrinkWrap: true,
|
||||
padding: padding,
|
||||
children: [
|
||||
Text(
|
||||
presence.getLocalizedStatusMessage(context),
|
||||
textAlign: TextAlign.center,
|
||||
style: TextStyle(
|
||||
fontSize: 30,
|
||||
color: Colors.white,
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
floatingActionButton: FloatingActionButton.extended(
|
||||
backgroundColor: Theme.of(context).primaryColor,
|
||||
icon: Icon(composeMode ? Icons.edit : Icons.message_outlined),
|
||||
label: Text(composeMode
|
||||
? L10n.of(context).setStatus
|
||||
: L10n.of(context).sendAMessage),
|
||||
onPressed: () => composeMode
|
||||
? _setStatusAction(context)
|
||||
: _sendMessageAction(context),
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
Loading…
Reference in a new issue