From c9c514a6391aea5e7d0c26e932def99d9a6ae07d Mon Sep 17 00:00:00 2001 From: CodeDoctorDE Date: Fri, 17 Nov 2023 18:57:17 +0100 Subject: [PATCH] Remove restriction of bfly files on import in files view --- app/lib/api/open.dart | 12 ++++++--- app/lib/dialogs/load.dart | 27 +++++++++---------- app/lib/dialogs/packs/dialog.dart | 2 +- app/lib/handlers/asset.dart | 8 +++--- app/lib/handlers/handler.dart | 1 - app/lib/services/import.dart | 1 + app/lib/views/files/view.dart | 16 +++++------ app/lib/visualizer/property.dart | 12 ++++----- .../metadata/android/en-US/changelogs/80.txt | 6 ++++- 9 files changed, 44 insertions(+), 41 deletions(-) diff --git a/app/lib/api/open.dart b/app/lib/api/open.dart index 3305ef6e2e4f..e9145c7f6688 100644 --- a/app/lib/api/open.dart +++ b/app/lib/api/open.dart @@ -18,17 +18,21 @@ Future openHelp(List pageLocation, [String? fragment]) { mode: LaunchMode.externalApplication); } -Future openBfly() async { +Future<(Uint8List?, String?)> openSupported( + [List? fileExtension]) async { final isMobile = !kIsWeb && (Platform.isAndroid || Platform.isIOS); final files = await FilePicker.platform.pickFiles( type: isMobile ? FileType.any : FileType.custom, - allowedExtensions: isMobile ? null : ['bfly'], + allowedExtensions: isMobile + ? null + : (fileExtension ?? + AssetFileType.values.expand((e) => e.getFileExtensions()).toList()), allowMultiple: false, withData: true, ); - if (files?.files.isEmpty ?? true) return null; + if (files?.files.isEmpty ?? true) return (null, null); var e = files!.files.first; - return e.bytes; + return (e.bytes, e.extension); } void openFile(BuildContext context, AssetLocation location, [Object? data]) { diff --git a/app/lib/dialogs/load.dart b/app/lib/dialogs/load.dart index 4042e7298e2b..764b391ff1dc 100644 --- a/app/lib/dialogs/load.dart +++ b/app/lib/dialogs/load.dart @@ -1,21 +1,23 @@ import 'package:flutter/material.dart'; import 'package:flutter_gen/gen_l10n/app_localizations.dart'; -mixin LoadingDialogHandler { - void setProgress(double progress) {} - void close() {} +class LoadingDialogHandler { + final GlobalKey<_LoadingDialogState> _key; + + const LoadingDialogHandler._(this._key); + + void setProgress(double progress) => _key.currentState?.setProgress(progress); + void close() => _key.currentState?.close(); } -_LoadingDialogState? showLoadingDialog(BuildContext context) { +LoadingDialogHandler? showLoadingDialog(BuildContext context) { final key = GlobalKey<_LoadingDialogState>(); showDialog( context: context, barrierDismissible: false, - builder: (BuildContext context) { - return LoadingDialog(key: key); - }, + builder: (_) => LoadingDialog(key: key), ); - return key.currentState; + return LoadingDialogHandler._(key); } class LoadingDialog extends StatefulWidget { @@ -25,19 +27,14 @@ class LoadingDialog extends StatefulWidget { State createState() => _LoadingDialogState(); } -class _LoadingDialogState extends State - with LoadingDialogHandler { +class _LoadingDialogState extends State { double _progress = 0.0; - @override void setProgress(double progress) => setState(() { _progress = progress; }); - @override - void close() { - Navigator.of(context).pop(); - } + void close() => Navigator.of(context).pop(); @override Widget build(BuildContext context) { diff --git a/app/lib/dialogs/packs/dialog.dart b/app/lib/dialogs/packs/dialog.dart index b86da9209ab1..b4c63c23001e 100644 --- a/app/lib/dialogs/packs/dialog.dart +++ b/app/lib/dialogs/packs/dialog.dart @@ -337,7 +337,7 @@ class _PacksDialogState extends State PhosphorIconsLight.arrowSquareIn), onTap: () async { Navigator.of(ctx).pop(); - final data = await openBfly(); + final (data, _) = await openSupported(['bfly']); if (data == null) return; final pack = NoteData.fromData(data); final metadata = pack.getMetadata(); diff --git a/app/lib/handlers/asset.dart b/app/lib/handlers/asset.dart index c8c34dceb540..e6240397ae7f 100644 --- a/app/lib/handlers/asset.dart +++ b/app/lib/handlers/asset.dart @@ -76,9 +76,11 @@ Future showImportAssetWizard(ImportType type, BuildContext context, allowedExtensions: ['pdf'], ); case ImportType.document: - final data = await openBfly(); - if (data == null) return; - return importAsset(AssetFileType.note, data); + return importWithDialog( + AssetFileType.note, + type: FileType.custom, + allowedExtensions: ['bfly'], + ); case ImportType.markdown: return importWithDialog( AssetFileType.markdown, diff --git a/app/lib/handlers/handler.dart b/app/lib/handlers/handler.dart index 2b4bffa5ac47..3194f525e1fe 100644 --- a/app/lib/handlers/handler.dart +++ b/app/lib/handlers/handler.dart @@ -34,7 +34,6 @@ import 'package:share_plus/share_plus.dart'; import '../actions/paste.dart'; import '../actions/select.dart'; -import '../api/open.dart'; import '../api/save_data.dart'; import '../cubits/current_index.dart'; import '../dialogs/import/camera.dart'; diff --git a/app/lib/services/import.dart b/app/lib/services/import.dart index 744ec00260a7..a6baa6cfe4c3 100644 --- a/app/lib/services/import.dart +++ b/app/lib/services/import.dart @@ -504,6 +504,7 @@ class ImportService { ?..add(ElementsCreated(elements)) ..add(AreasCreated(areas)); } + page = page.copyWith(content: [...page.content, ...elements]); document = document.setPage(page); return document; } diff --git a/app/lib/views/files/view.dart b/app/lib/views/files/view.dart index 834f2d5a0b8a..ef6de17140e2 100644 --- a/app/lib/views/files/view.dart +++ b/app/lib/views/files/view.dart @@ -305,9 +305,13 @@ class _FilesViewState extends State { onPressed: () async { final router = GoRouter.of(context); final importService = context.read(); - final result = await openBfly(); + final (result, extension) = await openSupported(); if (result == null) return; - final model = await importService.importBfly(result, + final model = await importService.import( + AssetFileTypeHelper.fromFileExtension(extension) ?? + AssetFileType.note, + result, + DocumentDefaults.createDocument(), advanced: false); if (model == null) return; const route = '/native?name=document.bfly&type=note'; @@ -316,13 +320,7 @@ class _FilesViewState extends State { _reloadFileSystem(); } }, - child: Column( - children: [ - Text(AppLocalizations.of(context).import), - Text('.bfly', - style: Theme.of(context).textTheme.bodySmall), - ], - ), + child: Text(AppLocalizations.of(context).import), ), if (settings.flags.contains('collaboration')) MenuItemButton( diff --git a/app/lib/visualizer/property.dart b/app/lib/visualizer/property.dart index a69b35d31b94..777aab5e3c09 100644 --- a/app/lib/visualizer/property.dart +++ b/app/lib/visualizer/property.dart @@ -5,13 +5,11 @@ import 'package:phosphor_flutter/phosphor_flutter.dart'; import 'package:flutter_gen/gen_l10n/app_localizations.dart'; extension PathShapeVisualizer on PathShape { - IconGetter get icon { - return map( - circle: (_) => PhosphorIcons.circle, - rectangle: (_) => PhosphorIcons.square, - line: (_) => PhosphorIcons.lineSegment, - ); - } + IconGetter get icon => map( + circle: (_) => PhosphorIcons.circle, + rectangle: (_) => PhosphorIcons.square, + line: (_) => PhosphorIcons.lineSegment, + ); String getLocalizedName(BuildContext context) { final loc = AppLocalizations.of(context); diff --git a/fastlane/metadata/android/en-US/changelogs/80.txt b/fastlane/metadata/android/en-US/changelogs/80.txt index 90a8b6886128..6b98bab81347 100644 --- a/fastlane/metadata/android/en-US/changelogs/80.txt +++ b/fastlane/metadata/android/en-US/changelogs/80.txt @@ -1,3 +1,7 @@ +* Add experiments settings in nightly version +* Add collaboration support (experimental) using websockets +* Remove restriction of bfly files on import in files view * Fix android mimetype +* Fix global importing -View all changes in the blog: https://linwood.dev/butterfly/2.0.0-beta.15 \ No newline at end of file +View all changes in the blog: https://linwood.dev/butterfly/2.0.0-beta.16 \ No newline at end of file