From ab36416e8847e79b5f2157e185eb02508b960374 Mon Sep 17 00:00:00 2001 From: poppingmoon <63451158+poppingmoon@users.noreply.github.com> Date: Sat, 29 Jul 2023 00:21:56 +0900 Subject: [PATCH 1/3] lint and format --- lib/repository/import_export_repository.dart | 78 +++++--- .../folder_select_dialog.dart | 105 ++++++----- .../import_export_page.dart | 177 +++++++++--------- 3 files changed, 197 insertions(+), 163 deletions(-) diff --git a/lib/repository/import_export_repository.dart b/lib/repository/import_export_repository.dart index dc7d80c39..a8101b569 100644 --- a/lib/repository/import_export_repository.dart +++ b/lib/repository/import_export_repository.dart @@ -36,15 +36,22 @@ class ImportExportRepository extends ChangeNotifier { ), ); - var alreadyExists = await reader(misskeyProvider(account)) - .drive - .files - .find(DriveFilesFindRequest(name: "miria.json", folderId: folder?.id)); - + Iterable alreadyExists = + await reader(misskeyProvider(account)).drive.files.find( + DriveFilesFindRequest( + name: "miria.json", + folderId: folder?.id, + ), + ); + + if (!context.mounted) return; if (alreadyExists.isEmpty) { alreadyExists = await reader(misskeyProvider(account)).drive.files.find( - DriveFilesFindRequest( - name: "miria.json.unknown", folderId: folder?.id)); + DriveFilesFindRequest( + name: "miria.json.unknown", + folderId: folder?.id, + ), + ); if (alreadyExists.isEmpty) { await SimpleMessageDialog.show(context, "ここにMiriaの設定ファイルあれへんかったわ"); @@ -82,9 +89,11 @@ class ImportExportRepository extends ChangeNotifier { final tabSettings = []; for (final tabSetting in json["tabSettings"]) { - final account = accounts.firstWhereOrNull((element) => - tabSetting["account"]["host"] == element.host && - tabSetting["account"]["userId"] == element.userId); + final account = accounts.firstWhereOrNull( + (element) => + tabSetting["account"]["host"] == element.host && + tabSetting["account"]["userId"] == element.userId, + ); if (account == null) { continue; @@ -95,13 +104,17 @@ class ImportExportRepository extends ChangeNotifier { (tabSetting as Map) ..remove("account") ..addEntries( - [MapEntry("account", jsonDecode(jsonEncode(account.toJson())))]); + [MapEntry("account", jsonDecode(jsonEncode(account.toJson())))], + ); tabSettings.add(TabSetting.fromJson(tabSetting)); } reader(tabSettingsRepositoryProvider).save(tabSettings); + if (!context.mounted) return; await SimpleMessageDialog.show(context, "インポート終わったで。"); + + if (!context.mounted) return; context.router ..removeWhere((route) => true) ..push(const SplashRoute()); @@ -120,18 +133,22 @@ class ImportExportRepository extends ChangeNotifier { ), ); - final alreadyExists = await reader(misskeyProvider(account)) - .drive - .files - .find(DriveFilesFindRequest( - name: "miria.json.unknown", folderId: folder?.id)); + final alreadyExists = + await reader(misskeyProvider(account)).drive.files.find( + DriveFilesFindRequest( + name: "miria.json.unknown", + folderId: folder?.id, + ), + ); + if (!context.mounted) return; if (alreadyExists.isNotEmpty) { final alreadyConfirm = await SimpleConfirmDialog.show( - context: context, - message: "ここにもうあるけど上書きするか?", - primary: "上書きする", - secondary: "やっぱやめた"); + context: context, + message: "ここにもうあるけど上書きするか?", + primary: "上書きする", + secondary: "やっぱやめた", + ); if (alreadyConfirm != true) return; for (final element in alreadyExists) { @@ -143,13 +160,11 @@ class ImportExportRepository extends ChangeNotifier { } final data = ExportedSetting( - generalSettings: reader(generalSettingsRepositoryProvider).settings, - tabSettings: - reader(tabSettingsRepositoryProvider).tabSettings.toList(), - accountSettings: reader(accountSettingsRepositoryProvider) - .accountSettings - .toList()) - .toJson(); + generalSettings: reader(generalSettingsRepositoryProvider).settings, + tabSettings: reader(tabSettingsRepositoryProvider).tabSettings.toList(), + accountSettings: + reader(accountSettingsRepositoryProvider).accountSettings.toList(), + ).toJson(); // 外に漏れると困るので for (final element in data["tabSettings"] as List) { @@ -159,13 +174,16 @@ class ImportExportRepository extends ChangeNotifier { } await reader(misskeyProvider(account)).drive.files.createAsBinary( - DriveFilesCreateRequest( + DriveFilesCreateRequest( folderId: folder?.id, name: "miria.json", comment: "Miria設定ファイル", - force: true), - Uint8List.fromList(utf8.encode(jsonEncode(data)))); + force: true, + ), + Uint8List.fromList(utf8.encode(jsonEncode(data))), + ); + if (!context.mounted) return; await SimpleMessageDialog.show(context, "エクスポート終わったで"); } } diff --git a/lib/view/settings_page/import_export_page/folder_select_dialog.dart b/lib/view/settings_page/import_export_page/folder_select_dialog.dart index ddf7184cd..7786fa67f 100644 --- a/lib/view/settings_page/import_export_page/folder_select_dialog.dart +++ b/lib/view/settings_page/import_export_page/folder_select_dialog.dart @@ -34,12 +34,13 @@ class FolderSelectDialogState extends ConsumerState { children: [ if (path.isNotEmpty) IconButton( - onPressed: () { - setState(() { - path.removeLast(); - }); - }, - icon: const Icon(Icons.arrow_back)), + onPressed: () { + setState(() { + path.removeLast(); + }); + }, + icon: const Icon(Icons.arrow_back), + ), Expanded(child: Text(path.map((e) => e.name).join("/"))), ], ) @@ -52,35 +53,40 @@ class FolderSelectDialogState extends ConsumerState { child: Column( children: [ PushableListView( - shrinkWrap: true, - physics: const NeverScrollableScrollPhysics(), - initializeFuture: () async { - final misskey = ref.read(misskeyProvider(widget.account)); - final response = await misskey.drive.folders.folders( - DriveFoldersRequest( - folderId: path.isEmpty ? null : path.last.id)); - return response.toList(); - }, - nextFuture: (lastItem, _) async { - final misskey = ref.read(misskeyProvider(widget.account)); - final response = await misskey.drive.folders.folders( - DriveFoldersRequest( - untilId: lastItem.id, - folderId: path.isEmpty ? null : path.last.id)); - return response.toList(); - }, - listKey: path.map((e) => e.id).join("/"), - itemBuilder: (context, item) { - return ListTile( - leading: const Icon(Icons.folder), - title: Text(item.name ?? ""), - onTap: () { - setState(() { - path.add(item); - }); - }, - ); - }), + shrinkWrap: true, + physics: const NeverScrollableScrollPhysics(), + initializeFuture: () async { + final misskey = ref.read(misskeyProvider(widget.account)); + final response = await misskey.drive.folders.folders( + DriveFoldersRequest( + folderId: path.isEmpty ? null : path.last.id, + ), + ); + return response.toList(); + }, + nextFuture: (lastItem, _) async { + final misskey = ref.read(misskeyProvider(widget.account)); + final response = await misskey.drive.folders.folders( + DriveFoldersRequest( + untilId: lastItem.id, + folderId: path.isEmpty ? null : path.last.id, + ), + ); + return response.toList(); + }, + listKey: path.map((e) => e.id).join("/"), + itemBuilder: (context, item) { + return ListTile( + leading: const Icon(Icons.folder), + title: Text(item.name ?? ""), + onTap: () { + setState(() { + path.add(item); + }); + }, + ); + }, + ), if (widget.fileShowTarget != null) FutureListView( shrinkWrap: true, @@ -88,18 +94,24 @@ class FolderSelectDialogState extends ConsumerState { future: () async { final list = []; for (final element in widget.fileShowTarget!) { - list.addAll(await ref - .read(misskeyProvider(widget.account)) - .drive - .files - .find(DriveFilesFindRequest( - folderId: path.lastOrNull?.id, name: element))); + list.addAll( + await ref + .read(misskeyProvider(widget.account)) + .drive + .files + .find( + DriveFilesFindRequest( + folderId: path.lastOrNull?.id, + name: element, + ), + ), + ); } return list.toList(); }(), builder: (context, item) => Row( children: [ - Icon(Icons.description), + const Icon(Icons.description), Expanded(child: Text(item.name)), ], ), @@ -110,10 +122,11 @@ class FolderSelectDialogState extends ConsumerState { ), actions: [ ElevatedButton( - onPressed: () { - Navigator.of(context).pop(path.lastOrNull); - }, - child: const Text("このフォルダーに保存する")) + onPressed: () { + Navigator.of(context).pop(path.lastOrNull); + }, + child: const Text("このフォルダーに保存する"), + ) ], ); } diff --git a/lib/view/settings_page/import_export_page/import_export_page.dart b/lib/view/settings_page/import_export_page/import_export_page.dart index d20114f08..c3b9e9755 100644 --- a/lib/view/settings_page/import_export_page/import_export_page.dart +++ b/lib/view/settings_page/import_export_page/import_export_page.dart @@ -25,95 +25,98 @@ class ImportExportPageState extends ConsumerState { body: Padding( padding: const EdgeInsets.only(left: 10, right: 10), child: Column( - mainAxisAlignment: MainAxisAlignment.start, - crossAxisAlignment: CrossAxisAlignment.start, - children: [ - Text( - "設定のインポート", - style: Theme.of(context).textTheme.titleLarge, - ), - const Text( - "設定ファイルをドライブから読み込みます。設定ファイルには保存されたときのすべてのアカウントの設定情報が記録されていますが、そのうちこの端末でログインしているアカウントの情報のみを読み込みます。"), - Row( - children: [ - Expanded( - child: DropdownButton( - isExpanded: true, - items: [ - for (final account - in ref.read(accountRepository).account) - DropdownMenuItem( - value: account, - child: Text("@${account.userId}@${account.host}"), - ), - ], - value: selectedImportAccount, - onChanged: (Account? value) { - setState(() { - selectedImportAccount = value; - }); - }, - ), + mainAxisAlignment: MainAxisAlignment.start, + crossAxisAlignment: CrossAxisAlignment.start, + children: [ + Text( + "設定のインポート", + style: Theme.of(context).textTheme.titleLarge, + ), + const Text( + "設定ファイルをドライブから読み込みます。設定ファイルには保存されたときのすべてのアカウントの設定情報が記録されていますが、そのうちこの端末でログインしているアカウントの情報のみを読み込みます。", + ), + Row( + children: [ + Expanded( + child: DropdownButton( + isExpanded: true, + items: [ + for (final account in ref.read(accountRepository).account) + DropdownMenuItem( + value: account, + child: Text("@${account.userId}@${account.host}"), + ), + ], + value: selectedImportAccount, + onChanged: (Account? value) { + setState(() { + selectedImportAccount = value; + }); + }, ), - ElevatedButton( - onPressed: () async { - final account = selectedImportAccount; - if (account == null) { - await SimpleMessageDialog.show(context, "アカウントを選んでや"); - return; - } - await ref - .read(importExportRepository) - .import(context, account); - }, - child: const Text("設定ファイル選択")), - ], - ), - const Padding(padding: EdgeInsets.only(top: 30)), - Text( - "設定のエクスポート", - style: Theme.of(context).textTheme.titleLarge, - ), - const Text( - "設定ファイルをドライブに保存します。設定ファイルにはこの端末でログインしているすべてのアカウントの、ログイン情報以外の情報が記録されます。"), - const Text("設定ファイルは1回のエクスポートにつき1つのアカウントに対して保存します。"), - Row( - children: [ - Expanded( - child: DropdownButton( - isExpanded: true, - items: [ - for (final account - in ref.read(accountRepository).account) - DropdownMenuItem( - value: account, - child: Text("@${account.userId}@${account.host}"), - ), - ], - value: selectedExportAccount, - onChanged: (Account? value) { - setState(() { - selectedExportAccount = value; - }); - }, - ), + ), + ElevatedButton( + onPressed: () async { + final account = selectedImportAccount; + if (account == null) { + await SimpleMessageDialog.show(context, "アカウントを選んでや"); + return; + } + await ref + .read(importExportRepository) + .import(context, account); + }, + child: const Text("選択"), + ), + ], + ), + const Padding(padding: EdgeInsets.only(top: 30)), + Text( + "設定のエクスポート", + style: Theme.of(context).textTheme.titleLarge, + ), + const Text( + "設定ファイルをドライブに保存します。設定ファイルにはこの端末でログインしているすべてのアカウントの、ログイン情報以外の情報が記録されます。", + ), + const Text("設定ファイルは1回のエクスポートにつき1つのアカウントに対して保存します。"), + Row( + children: [ + Expanded( + child: DropdownButton( + isExpanded: true, + items: [ + for (final account in ref.read(accountRepository).account) + DropdownMenuItem( + value: account, + child: Text("@${account.userId}@${account.host}"), + ), + ], + value: selectedExportAccount, + onChanged: (Account? value) { + setState(() { + selectedExportAccount = value; + }); + }, ), - ElevatedButton( - onPressed: () { - final account = selectedExportAccount; - if (account == null) { - SimpleMessageDialog.show( - context, "設定ファイルを保存するアカウントを選んでや"); - return; - } - ref - .read(importExportRepository) - .export(context, account); - }, - child: const Text("保存")), - ], - ), - ]), + ), + ElevatedButton( + onPressed: () { + final account = selectedExportAccount; + if (account == null) { + SimpleMessageDialog.show( + context, + "設定ファイルを保存するアカウントを選んでや", + ); + return; + } + ref.read(importExportRepository).export(context, account); + }, + child: const Text("保存"), + ), + ], + ), + ], + ), ), ); } From d83280b5335da724350292de267035c822ecd7b1 Mon Sep 17 00:00:00 2001 From: poppingmoon <63451158+poppingmoon@users.noreply.github.com> Date: Sat, 29 Jul 2023 00:23:43 +0900 Subject: [PATCH 2/3] =?UTF-8?q?=E8=A8=AD=E5=AE=9A=E3=81=AE=E3=82=A4?= =?UTF-8?q?=E3=83=B3=E3=83=9D=E3=83=BC=E3=83=88=E3=83=BB=E3=82=A8=E3=82=AF?= =?UTF-8?q?=E3=82=B9=E3=83=9D=E3=83=BC=E3=83=88=E3=81=A7=E3=83=80=E3=82=A4?= =?UTF-8?q?=E3=82=A2=E3=83=AD=E3=82=B0=E3=82=92=E9=96=89=E3=81=98=E3=82=89?= =?UTF-8?q?=E3=82=8C=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/repository/import_export_repository.dart | 31 +++++++++---------- .../folder_select_dialog.dart | 8 ++++- 2 files changed, 22 insertions(+), 17 deletions(-) diff --git a/lib/repository/import_export_repository.dart b/lib/repository/import_export_repository.dart index a8101b569..647428028 100644 --- a/lib/repository/import_export_repository.dart +++ b/lib/repository/import_export_repository.dart @@ -24,17 +24,16 @@ class ImportExportRepository extends ChangeNotifier { ImportExportRepository(this.reader); Future import(BuildContext context, Account account) async { - final folder = await showDialog( - barrierDismissible: false, + final result = await showDialog( context: context, - builder: (context2) => WillPopScope( - onWillPop: () async => false, - child: FolderSelectDialog( - account: account, - fileShowTarget: const ["miria.json", "miria.json.unknown"], - ), + builder: (context2) => FolderSelectDialog( + account: account, + fileShowTarget: const ["miria.json", "miria.json.unknown"], ), ); + if (result == null) return; + + final folder = result.folder; Iterable alreadyExists = await reader(misskeyProvider(account)).drive.files.find( @@ -53,6 +52,7 @@ class ImportExportRepository extends ChangeNotifier { ), ); + if (!context.mounted) return; if (alreadyExists.isEmpty) { await SimpleMessageDialog.show(context, "ここにMiriaの設定ファイルあれへんかったわ"); return; @@ -121,17 +121,16 @@ class ImportExportRepository extends ChangeNotifier { } Future export(BuildContext context, Account account) async { - final folder = await showDialog( - barrierDismissible: false, + final result = await showDialog( context: context, - builder: (context2) => WillPopScope( - onWillPop: () async => false, - child: FolderSelectDialog( - account: account, - fileShowTarget: const ["miria.json", "miria.json.unknown"], - ), + builder: (context2) => FolderSelectDialog( + account: account, + fileShowTarget: const ["miria.json", "miria.json.unknown"], ), ); + if (result == null) return; + + final folder = result.folder; final alreadyExists = await reader(misskeyProvider(account)).drive.files.find( diff --git a/lib/view/settings_page/import_export_page/folder_select_dialog.dart b/lib/view/settings_page/import_export_page/folder_select_dialog.dart index 7786fa67f..a3e6f4b27 100644 --- a/lib/view/settings_page/import_export_page/folder_select_dialog.dart +++ b/lib/view/settings_page/import_export_page/folder_select_dialog.dart @@ -6,6 +6,12 @@ import 'package:miria/view/common/futable_list_builder.dart'; import 'package:miria/view/common/pushable_listview.dart'; import 'package:misskey_dart/misskey_dart.dart'; +class FolderResult { + const FolderResult(this.folder); + + final DriveFolder? folder; +} + class FolderSelectDialog extends ConsumerStatefulWidget { final Account account; final List? fileShowTarget; @@ -123,7 +129,7 @@ class FolderSelectDialogState extends ConsumerState { actions: [ ElevatedButton( onPressed: () { - Navigator.of(context).pop(path.lastOrNull); + Navigator.of(context).pop(FolderResult(path.lastOrNull)); }, child: const Text("このフォルダーに保存する"), ) From 84529993c6637047a702f37d49633b5387a81f74 Mon Sep 17 00:00:00 2001 From: poppingmoon <63451158+poppingmoon@users.noreply.github.com> Date: Sat, 29 Jul 2023 00:28:29 +0900 Subject: [PATCH 3/3] =?UTF-8?q?=E3=82=A4=E3=83=B3=E3=83=9D=E3=83=BC?= =?UTF-8?q?=E3=83=88=E6=99=82=E3=81=AE=E3=83=80=E3=82=A4=E3=82=A2=E3=83=AD?= =?UTF-8?q?=E3=82=B0=E3=81=AE=E3=83=A1=E3=83=83=E3=82=BB=E3=83=BC=E3=82=B8?= =?UTF-8?q?=E3=82=92=E4=BF=AE=E6=AD=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- lib/repository/import_export_repository.dart | 2 ++ .../import_export_page/folder_select_dialog.dart | 6 ++++-- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/lib/repository/import_export_repository.dart b/lib/repository/import_export_repository.dart index 647428028..b2891e688 100644 --- a/lib/repository/import_export_repository.dart +++ b/lib/repository/import_export_repository.dart @@ -29,6 +29,7 @@ class ImportExportRepository extends ChangeNotifier { builder: (context2) => FolderSelectDialog( account: account, fileShowTarget: const ["miria.json", "miria.json.unknown"], + confirmationText: "このフォルダーからインポートする", ), ); if (result == null) return; @@ -126,6 +127,7 @@ class ImportExportRepository extends ChangeNotifier { builder: (context2) => FolderSelectDialog( account: account, fileShowTarget: const ["miria.json", "miria.json.unknown"], + confirmationText: "このフォルダーに保存する", ), ); if (result == null) return; diff --git a/lib/view/settings_page/import_export_page/folder_select_dialog.dart b/lib/view/settings_page/import_export_page/folder_select_dialog.dart index a3e6f4b27..39871bc9d 100644 --- a/lib/view/settings_page/import_export_page/folder_select_dialog.dart +++ b/lib/view/settings_page/import_export_page/folder_select_dialog.dart @@ -15,11 +15,13 @@ class FolderResult { class FolderSelectDialog extends ConsumerStatefulWidget { final Account account; final List? fileShowTarget; + final String confirmationText; const FolderSelectDialog({ super.key, required this.account, required this.fileShowTarget, + required this.confirmationText, }); @override @@ -35,7 +37,7 @@ class FolderSelectDialogState extends ConsumerState { return AlertDialog( title: Column( children: [ - const Text("フォルダ選択"), + const Text("フォルダー選択"), Row( children: [ if (path.isNotEmpty) @@ -131,7 +133,7 @@ class FolderSelectDialogState extends ConsumerState { onPressed: () { Navigator.of(context).pop(FolderResult(path.lastOrNull)); }, - child: const Text("このフォルダーに保存する"), + child: Text(widget.confirmationText), ) ], );