refactor: Implement own adaptive dialogs and remove package

This commit is contained in:
krille-chan 2024-12-10 18:47:58 +01:00
commit 8819c40ebd
No known key found for this signature in database
42 changed files with 597 additions and 439 deletions

View file

@ -4,7 +4,6 @@ import 'package:flutter/foundation.dart';
import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
import 'package:adaptive_dialog/adaptive_dialog.dart';
import 'package:cross_file/cross_file.dart';
import 'package:flutter_gen/gen_l10n/l10n.dart';
import 'package:flutter_shortcuts/flutter_shortcuts.dart';
@ -21,6 +20,9 @@ import 'package:fluffychat/utils/matrix_sdk_extensions/matrix_locals.dart';
import 'package:fluffychat/utils/platform_infos.dart';
import 'package:fluffychat/utils/show_scaffold_dialog.dart';
import 'package:fluffychat/utils/show_update_snackbar.dart';
import 'package:fluffychat/widgets/adaptive_dialogs/show_modal_action_popup.dart';
import 'package:fluffychat/widgets/adaptive_dialogs/show_ok_cancel_alert_dialog.dart';
import 'package:fluffychat/widgets/adaptive_dialogs/show_text_input_dialog.dart';
import 'package:fluffychat/widgets/avatar.dart';
import 'package:fluffychat/widgets/future_loading_dialog.dart';
import 'package:fluffychat/widgets/share_scaffold_dialog.dart';
@ -188,23 +190,19 @@ class ChatListController extends State<ChatList>
context: context,
okLabel: L10n.of(context).ok,
cancelLabel: L10n.of(context).cancel,
textFields: [
DialogTextField(
prefixText: 'https://',
hintText: Matrix.of(context).client.homeserver?.host,
initialText: searchServer,
keyboardType: TextInputType.url,
autocorrect: false,
validator: (server) => server?.contains('.') == true
? null
: L10n.of(context).invalidServerName,
),
],
prefixText: 'https://',
hintText: Matrix.of(context).client.homeserver?.host,
initialText: searchServer,
keyboardType: TextInputType.url,
autocorrect: false,
validator: (server) => server.contains('.') == true
? null
: L10n.of(context).invalidServerName,
);
if (newServer == null) return;
Matrix.of(context).store.setString(_serverStoreNamespace, newServer.single);
Matrix.of(context).store.setString(_serverStoreNamespace, newServer);
setState(() {
searchServer = newServer.single;
searchServer = newServer;
});
_coolDown?.cancel();
_coolDown = Timer(const Duration(milliseconds: 500), _search);
@ -668,7 +666,7 @@ class ChatListController extends State<ChatList>
message: L10n.of(context).archiveRoomDescription,
okLabel: L10n.of(context).leave,
cancelLabel: L10n.of(context).cancel,
isDestructiveAction: true,
isDestructive: true,
);
if (confirmed == OkCancelResult.cancel) return;
if (!mounted) return;
@ -677,13 +675,13 @@ class ChatListController extends State<ChatList>
return;
case ChatContextAction.addToSpace:
final space = await showConfirmationDialog(
final space = await showModalActionPopup(
context: context,
title: L10n.of(context).space,
actions: spacesWithPowerLevels
.map(
(space) => AlertDialogAction(
key: space,
(space) => AdaptiveModalAction(
value: space,
label: space
.getLocalizedDisplayname(MatrixLocals(L10n.of(context))),
),
@ -724,15 +722,11 @@ class ChatListController extends State<ChatList>
message: L10n.of(context).leaveEmptyToClearStatus,
okLabel: L10n.of(context).ok,
cancelLabel: L10n.of(context).cancel,
textFields: [
DialogTextField(
hintText: L10n.of(context).statusExampleMessage,
maxLines: 6,
minLines: 1,
maxLength: 255,
initialText: currentPresence.statusMsg,
),
],
hintText: L10n.of(context).statusExampleMessage,
maxLines: 6,
minLines: 1,
maxLength: 255,
initialText: currentPresence.statusMsg,
);
if (input == null) return;
if (!mounted) return;
@ -741,7 +735,7 @@ class ChatListController extends State<ChatList>
future: () => client.setPresence(
client.userID!,
PresenceType.online,
statusMsg: input.single,
statusMsg: input,
),
);
}
@ -834,17 +828,18 @@ class ChatListController extends State<ChatList>
final client = Matrix.of(context)
.widget
.clients[Matrix.of(context).getClientIndexByMatrixId(userId!)];
final action = await showConfirmationDialog<EditBundleAction>(
final action = await showModalActionPopup<EditBundleAction>(
context: context,
title: L10n.of(context).editBundlesForAccount,
cancelLabel: L10n.of(context).cancel,
actions: [
AlertDialogAction(
key: EditBundleAction.addToBundle,
AdaptiveModalAction(
value: EditBundleAction.addToBundle,
label: L10n.of(context).addToBundle,
),
if (activeBundle != client.userID)
AlertDialogAction(
key: EditBundleAction.removeFromBundle,
AdaptiveModalAction(
value: EditBundleAction.removeFromBundle,
label: L10n.of(context).removeFromBundle,
),
],
@ -855,12 +850,12 @@ class ChatListController extends State<ChatList>
final bundle = await showTextInputDialog(
context: context,
title: l10n.bundleName,
textFields: [DialogTextField(hintText: l10n.bundleName)],
hintText: l10n.bundleName,
);
if (bundle == null || bundle.isEmpty || bundle.single.isEmpty) return;
if (bundle == null || bundle.isEmpty || bundle.isEmpty) return;
await showFutureLoadingDialog(
context: context,
future: () => client.setAccountBundle(bundle.single),
future: () => client.setAccountBundle(bundle),
);
break;
case EditBundleAction.removeFromBundle:

View file

@ -1,12 +1,12 @@
import 'package:flutter/material.dart';
import 'package:adaptive_dialog/adaptive_dialog.dart';
import 'package:flutter_gen/gen_l10n/l10n.dart';
import 'package:matrix/matrix.dart';
import 'package:fluffychat/config/app_config.dart';
import 'package:fluffychat/utils/matrix_sdk_extensions/matrix_locals.dart';
import 'package:fluffychat/utils/room_status_extension.dart';
import 'package:fluffychat/widgets/adaptive_dialogs/show_ok_cancel_alert_dialog.dart';
import 'package:fluffychat/widgets/future_loading_dialog.dart';
import 'package:fluffychat/widgets/hover_builder.dart';
import '../../config/themes.dart';
@ -51,7 +51,7 @@ class ChatListItem extends StatelessWidget {
okLabel: L10n.of(context).leave,
cancelLabel: L10n.of(context).cancel,
message: L10n.of(context).archiveRoomDescription,
isDestructiveAction: true,
isDestructive: true,
);
if (confirmed != OkCancelResult.ok) return false;
final leaveResult = await showFutureLoadingDialog(

View file

@ -1,10 +1,10 @@
import 'package:flutter/material.dart';
import 'package:adaptive_dialog/adaptive_dialog.dart';
import 'package:flutter_gen/gen_l10n/l10n.dart';
import 'package:go_router/go_router.dart';
import 'package:matrix/matrix.dart';
import 'package:fluffychat/widgets/adaptive_dialogs/show_ok_cancel_alert_dialog.dart';
import 'package:fluffychat/widgets/avatar.dart';
import 'package:fluffychat/widgets/matrix.dart';
import '../../utils/fluffy_share.dart';

View file

@ -1,6 +1,5 @@
import 'package:flutter/material.dart';
import 'package:adaptive_dialog/adaptive_dialog.dart';
import 'package:collection/collection.dart';
import 'package:flutter_gen/gen_l10n/l10n.dart';
import 'package:go_router/go_router.dart';
@ -13,6 +12,9 @@ import 'package:fluffychat/pages/chat_list/search_title.dart';
import 'package:fluffychat/utils/adaptive_bottom_sheet.dart';
import 'package:fluffychat/utils/localized_exception_extension.dart';
import 'package:fluffychat/utils/stream_extension.dart';
import 'package:fluffychat/widgets/adaptive_dialogs/show_modal_action_popup.dart';
import 'package:fluffychat/widgets/adaptive_dialogs/show_ok_cancel_alert_dialog.dart';
import 'package:fluffychat/widgets/adaptive_dialogs/show_text_input_dialog.dart';
import 'package:fluffychat/widgets/avatar.dart';
import 'package:fluffychat/widgets/future_loading_dialog.dart';
import 'package:fluffychat/widgets/matrix.dart';
@ -136,7 +138,7 @@ class _SpaceViewState extends State<SpaceView> {
okLabel: L10n.of(context).ok,
cancelLabel: L10n.of(context).cancel,
message: L10n.of(context).archiveRoomDescription,
isDestructiveAction: true,
isDestructive: true,
);
if (!mounted) return;
if (confirmed != OkCancelResult.ok) return;
@ -152,16 +154,16 @@ class _SpaceViewState extends State<SpaceView> {
}
void _addChatOrSubspace() async {
final roomType = await showConfirmationDialog(
final roomType = await showModalActionPopup(
context: context,
title: L10n.of(context).addChatOrSubSpace,
actions: [
AlertDialogAction(
key: AddRoomType.subspace,
AdaptiveModalAction(
value: AddRoomType.subspace,
label: L10n.of(context).createNewSpace,
),
AlertDialogAction(
key: AddRoomType.chat,
AdaptiveModalAction(
value: AddRoomType.chat,
label: L10n.of(context).createGroup,
),
],
@ -173,28 +175,18 @@ class _SpaceViewState extends State<SpaceView> {
title: roomType == AddRoomType.subspace
? L10n.of(context).createNewSpace
: L10n.of(context).createGroup,
textFields: [
DialogTextField(
hintText: roomType == AddRoomType.subspace
? L10n.of(context).spaceName
: L10n.of(context).groupName,
minLines: 1,
maxLines: 1,
maxLength: 64,
validator: (text) {
if (text == null || text.isEmpty) {
return L10n.of(context).pleaseChoose;
}
return null;
},
),
DialogTextField(
hintText: L10n.of(context).chatDescription,
minLines: 4,
maxLines: 8,
maxLength: 255,
),
],
hintText: roomType == AddRoomType.subspace
? L10n.of(context).spaceName
: L10n.of(context).groupName,
minLines: 1,
maxLines: 1,
maxLength: 64,
validator: (text) {
if (text.isEmpty) {
return L10n.of(context).pleaseChoose;
}
return null;
},
okLabel: L10n.of(context).create,
cancelLabel: L10n.of(context).cancel,
);
@ -209,29 +201,20 @@ class _SpaceViewState extends State<SpaceView> {
if (roomType == AddRoomType.subspace) {
roomId = await client.createSpace(
name: names.first,
topic: names.last.isEmpty ? null : names.last,
name: names,
visibility: activeSpace.joinRules == JoinRules.public
? sdk.Visibility.public
: sdk.Visibility.private,
);
} else {
roomId = await client.createGroupChat(
groupName: names.first,
groupName: names,
preset: activeSpace.joinRules == JoinRules.public
? CreateRoomPreset.publicChat
: CreateRoomPreset.privateChat,
visibility: activeSpace.joinRules == JoinRules.public
? sdk.Visibility.public
: sdk.Visibility.private,
initialState: names.length > 1 && names.last.isNotEmpty
? [
StateEvent(
type: EventTypes.RoomTopic,
content: {'topic': names.last},
),
]
: null,
);
}
await activeSpace.setSpaceChild(roomId);