diff --git a/lib/l10n/app_ja.arb b/lib/l10n/app_ja.arb index 55369c6e0..bc46bab4f 100644 --- a/lib/l10n/app_ja.arb +++ b/lib/l10n/app_ja.arb @@ -290,7 +290,8 @@ } }, "chooseFile": "ファイルを選択", - "uploadFile": "アップロード", + "uploadMedia": "メディアをアップロード", + "uploadFile": "ファイルをアップロード", "fromDrive": "ドライブから", "fileName": "ファイル名", "randomizeFileName": "ファイル名をランダムにする", 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 04c78dee6..3ed4d46d0 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 @@ -485,40 +485,51 @@ class NoteCreateNotifier extends _$NoteCreateNotifier { .read(appRouterProvider) .push(const DriveModalRoute()); - if (result == DriveModalSheetReturnValue.drive) { - final result = await ref.read(appRouterProvider).push>( - DriveFileSelectRoute( - account: ref.read(accountContextProvider).postAccount, - allowMultiple: true, - ), - ); - if (result == null || result.isEmpty) return; - - final files = result.map((file) => AlreadyPostedFile.file(file)); + switch (result) { + case DriveModalSheetReturnValue.drive: + final result = await ref.read(appRouterProvider).push>( + DriveFileSelectRoute( + account: ref.read(accountContextProvider).postAccount, + allowMultiple: true, + ), + ); + if (result == null || result.isEmpty) return; - state = state.copyWith( - files: [ - ...state.files, - ...files, - ], - ); - } else if (result == DriveModalSheetReturnValue.upload) { - final result = await FilePicker.platform.pickFiles( - allowMultiple: true, - allowCompression: false, - compressionQuality: 0, - ); - if (result == null || result.files.isEmpty) return; + final files = result.map((file) => AlreadyPostedFile.file(file)); - final files = result.files.map((file) { - final path = file.path; - if (path != null) { - return PostFile.file(_fileSystem.file(path)); - } - return null; - }).nonNulls; + state = state.copyWith( + files: [ + ...state.files, + ...files, + ], + ); + case DriveModalSheetReturnValue.uploadFile || + DriveModalSheetReturnValue.uploadMedia: + final pickerResult = await FilePicker.platform.pickFiles( + type: result == DriveModalSheetReturnValue.uploadMedia + ? FileType.media + : FileType.any, + allowMultiple: true, + ); + if (pickerResult == null || pickerResult.files.isEmpty) return; - state = state.copyWith(files: [...state.files, ...files]); + final files = pickerResult.files.map( + (file) { + final path = file.path; + if (path != null) { + return PostFile.file(_fileSystem.file(path)); + } + return null; + }, + ).nonNulls; + + state = state.copyWith( + files: [ + ...state.files, + ...files, + ], + ); + default: } } diff --git a/lib/view/note_create_page/drive_modal_sheet.dart b/lib/view/note_create_page/drive_modal_sheet.dart index 31047b826..7f96fa1c1 100644 --- a/lib/view/note_create_page/drive_modal_sheet.dart +++ b/lib/view/note_create_page/drive_modal_sheet.dart @@ -2,7 +2,7 @@ import "package:auto_route/auto_route.dart"; import "package:flutter/material.dart"; import "package:flutter_gen/gen_l10n/app_localizations.dart"; -enum DriveModalSheetReturnValue { upload, drive } +enum DriveModalSheetReturnValue { uploadMedia, uploadFile, drive } @RoutePage() class DriveModalSheet extends StatelessWidget { @@ -13,10 +13,17 @@ class DriveModalSheet extends StatelessWidget { return ListView( children: [ ListTile( - title: Text(S.of(context).uploadFile), + title: Text(S.of(context).uploadMedia), leading: const Icon(Icons.upload), onTap: () async => - context.maybePop(DriveModalSheetReturnValue.upload), + context.maybePop(DriveModalSheetReturnValue.uploadMedia), + ), + ListTile( + title: Text(S.of(context).uploadFile), + leading: const Icon(Icons.upload_file), + onTap: () { + Navigator.of(context).pop(DriveModalSheetReturnValue.uploadFile); + }, ), ListTile( title: Text(S.of(context).fromDrive), diff --git a/test/view/note_create_page/note_create_page_test.dart b/test/view/note_create_page/note_create_page_test.dart index 92dd45c43..780a92969 100644 --- a/test/view/note_create_page/note_create_page_test.dart +++ b/test/view/note_create_page/note_create_page_test.dart @@ -3014,7 +3014,7 @@ void main() { await tester.tap(find.byIcon(Icons.image)); await tester.pumpAndSettle(); - await tester.tap(find.text("アップロード")); + await tester.tap(find.text("ファイルをアップロード")); await tester.pumpAndSettle(); await tester.enterText( @@ -3102,7 +3102,7 @@ void main() { await tester.tap(find.byIcon(Icons.image)); await tester.pumpAndSettle(); - await tester.tap(find.text("アップロード")); + await tester.tap(find.text("ファイルをアップロード")); await tester.pumpAndSettle(); await tester.enterText(