Skip to content

Commit

Permalink
TW-1456: optionnal duration param added to snackbar
Browse files Browse the repository at this point in the history
  • Loading branch information
Te-Z committed Mar 28, 2024
1 parent 6a41e0c commit 8a44b28
Show file tree
Hide file tree
Showing 10 changed files with 205 additions and 149 deletions.
20 changes: 0 additions & 20 deletions lib/config/go_routes/go_router.dart
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ import 'package:fluffychat/pages/error_page/error_page.dart';
import 'package:fluffychat/pages/homeserver_picker/homeserver_picker.dart';
import 'package:fluffychat/pages/login/on_auth_redirect.dart';
import 'package:fluffychat/pages/new_group/new_group_chat_info.dart';
import 'package:fluffychat/pages/profile_info/profile_info_page.dart';
import 'package:fluffychat/pages/settings_dashboard/settings_app_language/settings_app_language.dart';
import 'package:fluffychat/pages/settings_dashboard/settings_profile/settings_profile.dart';
import 'package:fluffychat/pages/share/share.dart';
Expand Down Expand Up @@ -209,25 +208,6 @@ abstract class AppRoutes {
),
],
),
GoRoute(
path: 'profileinfo/:roomid/:userid',
pageBuilder: (context, state) {
final roomId = state.pathParameters['roomid'];
final userId = state.pathParameters['userid'];

if (roomId == null || userId == null) {
return defaultPageBuilder(context, const ErrorPage());
}

return defaultPageBuilder(
context,
ProfileInfoPage(
roomId: roomId,
userId: userId,
),
);
},
),
GoRoute(
path: 'archive',
pageBuilder: (context, state) => defaultPageBuilder(
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
import 'package:fluffychat/di/global/get_it_initializer.dart';
import 'package:fluffychat/pages/chat_details/participant_list_item/participant_list_item_style.dart';
import 'package:fluffychat/pages/profile_info/profile_info_body/profile_info_body.dart';
import 'package:fluffychat/pages/profile_info/profile_info_page.dart';
import 'package:fluffychat/utils/platform_infos.dart';
import 'package:fluffychat/utils/responsive/responsive_utils.dart';
import 'package:fluffychat/widgets/avatar/avatar.dart';
import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';

import 'package:flutter_gen/gen_l10n/l10n.dart';
Expand Down Expand Up @@ -96,7 +98,7 @@ class ParticipantListItem extends StatelessWidget {
Future _onItemTap(BuildContext context) async {
final responsive = getIt.get<ResponsiveUtils>();

if (PlatformInfos.isMobile || responsive.isMobile(context)) {
if (responsive.isMobile(context)) {
await _openProfileMenu(context);
} else {
await _openProfileDialog(context);
Expand All @@ -111,7 +113,7 @@ class ParticipantListItem extends StatelessWidget {
topRight: ParticipantListItemStyle.bottomSheetTopRadius,
),
),
builder: (c) {
builder: (bottomSheetContext) {
return Container(
padding: ParticipantListItemStyle.bottomSheetContentPadding,
decoration: BoxDecoration(
Expand Down Expand Up @@ -147,8 +149,16 @@ class ParticipantListItem extends StatelessWidget {
Expanded(
child: TextButton.icon(
onPressed: () {
context.go(
'/rooms/profileinfo/${member.room.id}/${member.id}',
if (PlatformInfos.isMobile) {
bottomSheetContext.pop();
}
Navigator.of(context).push(
CupertinoPageRoute(
builder: (ctx) => ProfileInfoPage(
roomId: member.room.id,
userId: member.id,
),
),
);
},
icon: Icon(
Expand Down Expand Up @@ -203,7 +213,6 @@ class ParticipantListItem extends StatelessWidget {
),
ProfileInfoBody(
user: member,
parentContext: context,
onNewChatOpen: () {
dialogContext.pop();
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ class CopiableProfileRow extends StatelessWidget {
onTap: () {
TwakeClipboard.instance.copyText(copiableText);
TwakeSnackBar.show(
duration: const Duration(milliseconds: 500),
context,
L10n.of(context)!.copiedToClipboard,
);
Expand Down
74 changes: 66 additions & 8 deletions lib/pages/profile_info/profile_info_body/profile_info_body.dart
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,10 @@ import 'package:fluffychat/di/global/get_it_initializer.dart';
import 'package:fluffychat/domain/app_state/contact/lookup_match_contact_state.dart';
import 'package:fluffychat/domain/usecase/contacts/lookup_match_contact_interactor.dart';
import 'package:fluffychat/pages/profile_info/profile_info_body/profile_info_body_view.dart';
import 'package:fluffychat/presentation/model/presentation_contact_constant.dart';
import 'package:fluffychat/presentation/model/search/presentation_search.dart';
import 'package:fluffychat/utils/platform_infos.dart';
import 'package:fluffychat/widgets/matrix.dart';
import 'package:flutter/material.dart';
import 'package:go_router/go_router.dart';

Expand All @@ -15,15 +19,12 @@ import 'package:matrix/matrix.dart';
class ProfileInfoBody extends StatefulWidget {
const ProfileInfoBody({
required this.user,
required this.parentContext,
this.onNewChatOpen,
Key? key,
}) : super(key: key);

final User? user;

final BuildContext parentContext;

final void Function()? onNewChatOpen;

@override
Expand All @@ -43,8 +44,6 @@ class ProfileInfoBodyController extends State<ProfileInfoBody> {

User? get user => widget.user;

BuildContext get parentContext => widget.parentContext;

bool get isOwnProfile => user?.id == user?.room.client.userID;

void lookupMatchContactAction() {
Expand All @@ -58,9 +57,68 @@ class ProfileInfoBodyController extends State<ProfileInfoBody> {
);
}

void openNewChat(String roomId) {
parentContext.go('/rooms/$roomId');
if (widget.onNewChatOpen != null) widget.onNewChatOpen!();
void openNewChat() {
if (user == null) return;
final roomId = Matrix.of(context).client.getDirectChatFromUserId(user!.id);

if (roomId == null) {
if (!PlatformInfos.isMobile && widget.onNewChatOpen != null) {
widget.onNewChatOpen!();
}

_goToDraftChat(
context: context,
path: "rooms",
contactPresentationSearch: user!.toContactPresentationSearch(),
);
} else {
if (PlatformInfos.isMobile) {
Navigator.of(context)
.popUntil((route) => route.settings.name == "/rooms/room");
} else {
if (widget.onNewChatOpen != null) widget.onNewChatOpen!();
}

context.go('/rooms/$roomId');
}
}

void _goToDraftChat({
required BuildContext context,
required String path,
required ContactPresentationSearch contactPresentationSearch,
}) {
if (contactPresentationSearch.matrixId !=
Matrix.of(context).client.userID) {
Router.neglect(
context,
() => PlatformInfos.isMobile
? context.push(
'/$path/draftChat',
extra: {
PresentationContactConstant.receiverId:
contactPresentationSearch.matrixId ?? '',
PresentationContactConstant.email:
contactPresentationSearch.email ?? '',
PresentationContactConstant.displayName:
contactPresentationSearch.displayName ?? '',
PresentationContactConstant.status: '',
},
)
: context.go(
'/$path/draftChat',
extra: {
PresentationContactConstant.receiverId:
contactPresentationSearch.matrixId ?? '',
PresentationContactConstant.email:
contactPresentationSearch.email ?? '',
PresentationContactConstant.displayName:
contactPresentationSearch.displayName ?? '',
PresentationContactConstant.status: '',
},
),
);
}
}

@override
Expand Down
117 changes: 5 additions & 112 deletions lib/pages/profile_info/profile_info_body/profile_info_body_view.dart
Original file line number Diff line number Diff line change
@@ -1,19 +1,11 @@
import 'package:fluffychat/domain/app_state/contact/lookup_match_contact_state.dart';
import 'package:fluffychat/pages/profile_info/copiable_profile_row/icon_copiable_profile_row.dart';
import 'package:fluffychat/pages/profile_info/copiable_profile_row/svg_copiable_profile_row.dart';
import 'package:fluffychat/pages/profile_info/profile_info_body/profile_info_body.dart';
import 'package:fluffychat/pages/profile_info/profile_info_body/profile_info_body_view_style.dart';
import 'package:fluffychat/resource/image_paths.dart';
import 'package:fluffychat/utils/dialog/twake_dialog.dart';
import 'package:fluffychat/utils/matrix_sdk_extensions/presence_extension.dart';
import 'package:fluffychat/widgets/avatar/avatar.dart';
import 'package:fluffychat/widgets/matrix.dart';
import 'package:flutter/foundation.dart';
import 'package:fluffychat/pages/profile_info/profile_info_body/profile_info_contact_rows.dart';
import 'package:fluffychat/pages/profile_info/profile_info_body/profile_info_header.dart';
import 'package:flutter/material.dart';

import 'package:flutter_gen/gen_l10n/l10n.dart';
import 'package:linagora_design_flutter/colors/linagora_sys_colors.dart';
import 'package:matrix/matrix.dart';

class ProfileInfoBodyView extends StatelessWidget {
const ProfileInfoBodyView({
Expand All @@ -35,8 +27,8 @@ class ProfileInfoBodyView extends StatelessWidget {
padding: ProfileInfoBodyViewStyle.profileInformationsTopPadding,
child: Column(
children: [
_ProfileInfoHeader(controller.user!),
_ProfileInfoContactRows(
ProfileInfoHeader(controller.user!),
ProfileInfoContactRows(
user: controller.user!,
lookupContactNotifier: controller.lookupContactNotifier,
),
Expand All @@ -54,15 +46,7 @@ class ProfileInfoBodyView extends StatelessWidget {
children: [
Expanded(
child: TextButton.icon(
onPressed: () async {
final roomIdResult =
await TwakeDialog.showFutureLoadingDialogFullScreen(
future: () => controller.user!.startDirectChat(),
);
if (roomIdResult.error != null) return;

controller.openNewChat(roomIdResult.result!);
},
onPressed: () => controller.openNewChat(),
icon: const Icon(Icons.chat_outlined),
label: L10n.of(context)?.newChat != null
? Row(
Expand All @@ -87,94 +71,3 @@ class ProfileInfoBodyView extends StatelessWidget {
);
}
}

class _ProfileInfoHeader extends StatelessWidget {
const _ProfileInfoHeader(this.user, {Key? key}) : super(key: key);
final User user;

@override
Widget build(BuildContext context) {
final client = Matrix.of(context).client;
final presence = client.presences[user.id];

return Column(
mainAxisSize: MainAxisSize.min,
children: [
Padding(
padding: ProfileInfoBodyViewStyle.avatarPadding,
child: Avatar(
mxContent: user.avatarUrl,
name: user.calcDisplayname(),
),
),
Text(
user.calcDisplayname(),
maxLines: 1,
overflow: TextOverflow.ellipsis,
),
if (presence != null) ...[
const SizedBox(height: 8),
Text(
presence.getLocalizedStatusMessage(context),
style: presence.getPresenceTextStyle(context),
),
],
],
);
}
}

class _ProfileInfoContactRows extends StatelessWidget {
const _ProfileInfoContactRows({
required this.user,
required this.lookupContactNotifier,
Key? key,
}) : super(key: key);
final User user;
final ValueListenable lookupContactNotifier;

@override
Widget build(BuildContext context) {
return Column(
children: [
const SizedBox(height: 16),
SvgCopiableProfileRow(
leadingIconPath: ImagePaths.icMatrixid,
caption: L10n.of(context)!.matrixId,
copiableText: user.id,
),
ValueListenableBuilder(
valueListenable: lookupContactNotifier,
// valueListenable: controller.lookupContactNotifier,
builder: (context, contact, child) {
return contact.fold(
(failure) => const SizedBox.shrink(),
(success) {
if (success is LookupMatchContactSuccess) {
return Column(
mainAxisSize: MainAxisSize.min,
children: [
if (success.contact.email != null)
IconCopiableProfileRow(
icon: Icons.alternate_email,
caption: L10n.of(context)!.email,
copiableText: success.contact.email!,
),
if (success.contact.phoneNumber != null)
IconCopiableProfileRow(
icon: Icons.call,
caption: L10n.of(context)!.phone,
copiableText: success.contact.phoneNumber!,
),
],
);
}
return const SizedBox.shrink();
},
);
},
),
],
);
}
}
Loading

0 comments on commit 8a44b28

Please sign in to comment.