From a36a886fbcd6d3d206d159e787ec6f01dd90c321 Mon Sep 17 00:00:00 2001 From: CodeDoctorDE Date: Fri, 28 Jul 2023 10:34:40 +0200 Subject: [PATCH] Save deleted images in cache, closes #465 --- app/lib/services/asset.dart | 13 +++++++++---- fastlane/metadata/android/en-US/changelogs/70.txt | 6 ++++-- 2 files changed, 13 insertions(+), 6 deletions(-) diff --git a/app/lib/services/asset.dart b/app/lib/services/asset.dart index b80373f9249f..1091cf149919 100644 --- a/app/lib/services/asset.dart +++ b/app/lib/services/asset.dart @@ -7,6 +7,7 @@ import '../helpers/element_helper.dart'; class AssetService { final NoteData document; + final Map _cached = {}; final Map _images = {}; AssetService(this.document); @@ -15,11 +16,15 @@ class AssetService { if (_images.containsKey(path)) { return _images[path]!.clone(); } - final data = await getDataFromSource(document, path); - if (data == null) { - return null; + var listData = await getDataFromSource(document, path); + if (listData == null) { + listData = _cached[path]; + if (listData == null) return null; + document.setAsset(Uri.parse(path).path, listData); } - final codec = await ui.instantiateImageCodec(Uint8List.fromList(data)); + final data = Uint8List.fromList(listData); + _cached[path] = data; + final codec = await ui.instantiateImageCodec(data); final frameInfo = await codec.getNextFrame(); final image = frameInfo.image; _images[path] = image; diff --git a/fastlane/metadata/android/en-US/changelogs/70.txt b/fastlane/metadata/android/en-US/changelogs/70.txt index bb35860c0251..69be98152ddc 100644 --- a/fastlane/metadata/android/en-US/changelogs/70.txt +++ b/fastlane/metadata/android/en-US/changelogs/70.txt @@ -1,11 +1,13 @@ * Add sort order ([#469](https://github.com/LinwoodDev/Butterfly/issues/469)) * Save sort state ([#469](https://github.com/LinwoodDev/Butterfly/issues/469)) +* Save deleted images in cache + * Fix pasting images not working ([#465](https://github.com/LinwoodDev/Butterfly/issues/465)) * Improve save state icons * Improve import painter position * Improve hit calculation on single point pen elements * Improve performance of quick start view in home page ([#459](https://github.com/LinwoodDev/Butterfly/issues/459)) -* Set position to clicked when pasting ([#465](https://github.com/LinwoodDev/Butterfly/issues/465)) +* Set position to clicked when pasting ([#468](https://github.com/LinwoodDev/Butterfly/issues/468)) * Fix native title bar error on mobile devices * Fix internet problems on android ([#457](https://github.com/LinwoodDev/Butterfly/issues/457)) -* Fix position when pasting elements ([#465](https://github.com/LinwoodDev/Butterfly/issues/465)) +* Fix position when pasting elements ([#468](https://github.com/LinwoodDev/Butterfly/issues/468)) * Fix corner hit detection on hand tool when zoomed \ No newline at end of file