From 51527028b14fe62a30f5721e5f34418f89c2ff6c Mon Sep 17 00:00:00 2001 From: poppingmoon <63451158+poppingmoon@users.noreply.github.com> Date: Sun, 21 Apr 2024 02:01:42 +0900 Subject: [PATCH] =?UTF-8?q?=E3=83=A1=E3=83=87=E3=82=A3=E3=82=A2=E3=82=92?= =?UTF-8?q?=E3=82=A2=E3=83=83=E3=83=97=E3=83=AD=E3=83=BC=E3=83=89=E3=81=A7?= =?UTF-8?q?=E3=81=8D=E3=82=8B=E3=82=88=E3=81=86=E3=81=AB?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- lib/l10n/app_ja.arb | 3 +- .../note_create_state_notifier.dart | 68 +++++++++++-------- .../note_create_state_notifier.g.dart | 2 +- .../note_create_page/drive_modal_sheet.dart | 13 +++- .../note_create_page_test.dart | 4 +- 5 files changed, 53 insertions(+), 37 deletions(-) diff --git a/lib/l10n/app_ja.arb b/lib/l10n/app_ja.arb index 506952a72..237bc1681 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 a2606f499..7a70f1f54 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 @@ -488,40 +488,48 @@ 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; + 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; - final files = result.map((file) => AlreadyPostedFile.file(file)); + final files = result.map((file) => AlreadyPostedFile.file(file)); - state = state.copyWith( - files: [ - ...state.files, - ...files, - ], - ); - } else if (result == DriveModalSheetReturnValue.upload) { - final result = await FilePicker.platform.pickFiles( - allowMultiple: true, - allowCompression: Platform.isIOS, // v8.1.3ではiOS以外でこの値を使用していない - compressionQuality: 0, // Androidでは0にすることで圧縮パススルー - ); - if (result == null || result.files.isEmpty) return; + 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, + allowCompression: Platform.isIOS, // v8.1.3ではiOS以外でこの値を使用していない + compressionQuality: 0, // Androidでは0にすることで圧縮パススルー + ); + if (pickerResult == null || pickerResult.files.isEmpty) return; - final files = result.files.map((file) { - final path = file.path; - if (path != null) { - return PostFile.file(_fileSystem.file(path)); - } - return null; - }).nonNulls; + 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]); + state = state.copyWith(files: [...state.files, ...files]); + default: } } 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 d7e5ffa05..9aa43f6a3 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'9ea4a8b12fff449ad17b560d8af7c6e505c52d46'; + r'b087cb3c15eb581131e0b5260d9ed2fc40360f67'; /// See also [NoteCreateNotifier]. @ProviderFor(NoteCreateNotifier) 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(