From c906341ffb5b0956a3670beb62088e7b503333d3 Mon Sep 17 00:00:00 2001 From: poppingmoon <63451158+poppingmoon@users.noreply.github.com> Date: Sat, 28 Oct 2023 18:48:48 +0900 Subject: [PATCH] =?UTF-8?q?DriveFileSelectDialog=E3=81=A7DrivePage?= =?UTF-8?q?=E3=82=92=E4=BD=BF=E3=81=86?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- lib/router/app_router.dart | 2 +- lib/router/app_router.gr.dart | 26 +-- .../note_create_state_notifier.dart | 10 +- .../note_create_state_notifier.g.dart | 2 +- .../drive_file_select_dialog.dart | 182 +----------------- 5 files changed, 24 insertions(+), 198 deletions(-) diff --git a/lib/router/app_router.dart b/lib/router/app_router.dart index a2e1be860..f0dbb50b5 100644 --- a/lib/router/app_router.dart +++ b/lib/router/app_router.dart @@ -148,6 +148,7 @@ class AppRouter extends _$AppRouter { children: [ AutoRoute(page: DriveRoute.page), AutoRoute(page: DriveFileRoute.page), + AutoDialogRoute>(page: DriveFileSelectRoute.page), AutoModalRouteSheet(page: DriveCreateModalRoute.page), AutoModalRouteSheet(page: DriveFileModalRoute.page), AutoModalRouteSheet(page: DriveFilesModalRoute.page), @@ -180,7 +181,6 @@ class AppRouter extends _$AppRouter { AutoDialogRoute(page: UsersListSettingsRoute.page), AutoDialogRoute(page: AntennaSettingsRoute.page), AutoDialogRoute(page: FolderSelectRoute.page), - AutoDialogRoute>(page: DriveFileSelectRoute.page), AutoDialogRoute(page: TextFormFieldRoute.page), // モーダルシート diff --git a/lib/router/app_router.gr.dart b/lib/router/app_router.gr.dart index f1168078c..eb8990d1d 100644 --- a/lib/router/app_router.gr.dart +++ b/lib/router/app_router.gr.dart @@ -262,15 +262,14 @@ abstract class _$AppRouter extends RootStackRouter { ); }, DriveFileSelectRoute.name: (routeData) { - final args = routeData.argsAs(); + final args = routeData.argsAs( + orElse: () => const DriveFileSelectRouteArgs()); return AutoRoutePage>( routeData: routeData, - child: WrappedRoute( - child: DriveFileSelectDialog( - account: args.account, - key: args.key, + child: DriveFileSelectDialog( allowMultiple: args.allowMultiple, - )), + key: args.key, + ), ); }, DriveFilesModalRoute.name: (routeData) { @@ -1760,16 +1759,14 @@ class DriveFileRouteArgs { /// [DriveFileSelectDialog] class DriveFileSelectRoute extends PageRouteInfo { DriveFileSelectRoute({ - required Account account, - Key? key, bool allowMultiple = false, + Key? key, List? children, }) : super( DriveFileSelectRoute.name, args: DriveFileSelectRouteArgs( - account: account, - key: key, allowMultiple: allowMultiple, + key: key, ), initialChildren: children, ); @@ -1782,20 +1779,17 @@ class DriveFileSelectRoute extends PageRouteInfo { class DriveFileSelectRouteArgs { const DriveFileSelectRouteArgs({ - required this.account, - this.key, this.allowMultiple = false, + this.key, }); - final Account account; + final bool allowMultiple; final Key? key; - final bool allowMultiple; - @override String toString() { - return 'DriveFileSelectRouteArgs{account: $account, key: $key, allowMultiple: $allowMultiple}'; + return 'DriveFileSelectRouteArgs{allowMultiple: $allowMultiple, key: $key}'; } } diff --git a/lib/state_notifier/note_create_page/note_create_state_notifier.dart b/lib/state_notifier/note_create_page/note_create_state_notifier.dart index eeb3aba96..d2f254fe0 100644 --- a/lib/state_notifier/note_create_page/note_create_state_notifier.dart +++ b/lib/state_notifier/note_create_page/note_create_state_notifier.dart @@ -555,13 +555,13 @@ class NoteCreateNotifier extends _$NoteCreateNotifier { .push(const DriveModalRoute()); if (result == DriveModalSheetReturnValue.drive) { - final result = await ref.read(appRouterProvider).push>( - DriveFileSelectRoute( - account: ref.read(accountContextProvider).postAccount, - allowMultiple: true, + final result = await ref.read(appRouterProvider).push( + DriveShellRoute( + accountContext: ref.read(accountContextProvider), + children: [DriveRoute(selectFiles: true)], ), ); - if (result == null) return; + if (result is! List) return; final files = await Future.wait( result.map((file) async { if (file.type.startsWith("image")) { diff --git a/lib/state_notifier/note_create_page/note_create_state_notifier.g.dart b/lib/state_notifier/note_create_page/note_create_state_notifier.g.dart index 8b7f3f2bf..79837f513 100644 --- a/lib/state_notifier/note_create_page/note_create_state_notifier.g.dart +++ b/lib/state_notifier/note_create_page/note_create_state_notifier.g.dart @@ -7,7 +7,7 @@ part of 'note_create_state_notifier.dart'; // ************************************************************************** String _$noteCreateNotifierHash() => - r'5e20a6a2fc39214be0dd780f8c4f3a1ba97ae668'; + r'5a01bcf1206538b586fcd7140b2de491c150ba8d'; /// See also [NoteCreateNotifier]. @ProviderFor(NoteCreateNotifier) diff --git a/lib/view/note_create_page/drive_file_select_dialog.dart b/lib/view/note_create_page/drive_file_select_dialog.dart index 2fe1941be..d3f1e006b 100644 --- a/lib/view/note_create_page/drive_file_select_dialog.dart +++ b/lib/view/note_create_page/drive_file_select_dialog.dart @@ -1,189 +1,21 @@ import "package:auto_route/auto_route.dart"; import "package:flutter/material.dart"; -import "package:flutter_gen/gen_l10n/app_localizations.dart"; -import "package:flutter_hooks/flutter_hooks.dart"; import "package:hooks_riverpod/hooks_riverpod.dart"; -import "package:miria/model/account.dart"; -import "package:miria/providers.dart"; -import "package:miria/view/common/account_scope.dart"; -import "package:miria/view/common/misskey_notes/network_image.dart"; -import "package:miria/view/common/pushable_listview.dart"; -import "package:miria/view/themes/app_theme.dart"; +import "package:miria/view/drive_page/drive_page.dart"; import "package:misskey_dart/misskey_dart.dart"; @RoutePage>() -class DriveFileSelectDialog extends HookConsumerWidget - implements AutoRouteWrapper { - final Account account; +class DriveFileSelectDialog extends HookConsumerWidget { final bool allowMultiple; - const DriveFileSelectDialog({ - required this.account, - super.key, - this.allowMultiple = false, - }); - - @override - Widget wrappedRoute(BuildContext context) => - AccountContextScope.as(account: account, child: this); + const DriveFileSelectDialog({this.allowMultiple = false, super.key}); @override Widget build(BuildContext context, WidgetRef ref) { - final path = useState>([]); - final files = useState>([]); - - return AlertDialog( - title: AppBar( - leading: IconButton( - onPressed: path.value.isEmpty - ? null - : () => path.value = [...path.value..removeLast()], - icon: const Icon(Icons.arrow_back), - ), - title: path.value.isEmpty - ? Text(S.of(context).chooseFile) - : Text(path.value.map((e) => e.name).join("/")), - actions: [ - if (files.value.isNotEmpty) - Center( - child: Text( - "(${files.value.length})", - style: Theme.of(context).textTheme.titleMedium, - ), - ), - if (allowMultiple) - IconButton( - onPressed: files.value.isEmpty - ? null - : () => Navigator.of(context).pop(files.value), - icon: const Icon(Icons.check), - ), - ], - backgroundColor: Colors.transparent, - ), - content: SizedBox( - width: MediaQuery.of(context).size.width * 0.8, - height: MediaQuery.of(context).size.height * 0.8, - child: SingleChildScrollView( - child: Column( - children: [ - PushableListView( - hideIsEmpty: true, - shrinkWrap: true, - physics: const NeverScrollableScrollPhysics(), - showAd: false, - initializeFuture: () async { - final misskey = ref.read(misskeyGetContextProvider); - final response = await misskey.drive.folders.folders( - DriveFoldersRequest( - folderId: path.value.isEmpty ? null : path.value.last.id, - ), - ); - return response.toList(); - }, - nextFuture: (lastItem, _) async { - final misskey = ref.read(misskeyGetContextProvider); - final response = await misskey.drive.folders.folders( - DriveFoldersRequest( - untilId: lastItem.id, - folderId: path.value.isEmpty ? null : path.value.last.id, - ), - ); - return response.toList(); - }, - listKey: path.value.map((e) => e.id).join("/"), - itemBuilder: (context, item) { - return ListTile( - leading: const Icon(Icons.folder), - title: Text(item.name), - onTap: () => path.value = [...path.value, item], - ); - }, - ), - PushableListView( - shrinkWrap: true, - physics: const NeverScrollableScrollPhysics(), - showAd: false, - initializeFuture: () async { - final misskey = ref.read(misskeyGetContextProvider); - final response = await misskey.drive.files.files( - DriveFilesRequest( - folderId: path.value.isEmpty ? null : path.value.last.id, - ), - ); - return response.toList(); - }, - nextFuture: (lastItem, _) async { - final misskey = ref.read(misskeyGetContextProvider); - final response = await misskey.drive.files.files( - DriveFilesRequest( - untilId: lastItem.id, - folderId: path.value.isEmpty ? null : path.value.last.id, - ), - ); - return response.toList(); - }, - listKey: path.value.map((e) => e.id).join("/"), - itemBuilder: (context, item) { - final isSelected = - files.value.any((file) => file.id == item.id); - return Padding( - padding: const EdgeInsets.symmetric(vertical: 2), - child: InkWell( - customBorder: RoundedRectangleBorder( - borderRadius: BorderRadius.circular(5), - ), - onTap: () { - if (allowMultiple) { - if (isSelected) { - files.value = files.value - .where((file) => file.id != item.id) - .toList(); - } else { - files.value = [...files.value, item]; - } - } else { - Navigator.of(context).pop([item]); - } - }, - child: Container( - padding: const EdgeInsets.all(10), - decoration: (allowMultiple && isSelected) - ? BoxDecoration( - color: AppTheme.of(context) - .currentDisplayTabColor - .withOpacity(0.7), - borderRadius: BorderRadius.circular(5), - ) - : null, - child: Column( - crossAxisAlignment: CrossAxisAlignment.start, - children: [ - SizedBox( - width: double.infinity, - height: 200, - child: item.thumbnailUrl == null - ? const SizedBox.shrink() - : ClipRRect( - borderRadius: BorderRadius.circular(5), - child: NetworkImageView( - fit: BoxFit.cover, - url: item.thumbnailUrl!, - type: ImageType.imageThumbnail, - ), - ), - ), - Text(item.name), - ], - ), - ), - ), - ); - }, - ), - ], - ), - ), + return Dialog( + child: DrivePage( + selectFile: !allowMultiple, + selectFiles: allowMultiple, ), ); }