From ca8906344c5dafe81a27cb4f62217cbb6812c1d0 Mon Sep 17 00:00:00 2001 From: remartin Date: Fri, 5 Jul 2024 17:06:41 +0200 Subject: [PATCH 1/4] fix: share and download dependencies and permissions --- lib/network/images.dart | 3 ++- pubspec.yaml | 8 ++++---- 2 files changed, 6 insertions(+), 5 deletions(-) diff --git a/lib/network/images.dart b/lib/network/images.dart index 033a7a6..bd682cf 100644 --- a/lib/network/images.dart +++ b/lib/network/images.dart @@ -7,12 +7,12 @@ import 'package:file_picker/file_picker.dart'; import 'package:flutter/foundation.dart'; import 'package:flutter_local_notifications/flutter_local_notifications.dart'; import 'package:image_gallery_saver/image_gallery_saver.dart'; -import 'package:image_picker/image_picker.dart'; import 'package:path/path.dart' as path; import 'package:path_provider/path_provider.dart'; import 'package:piwigo_ng/models/album_model.dart'; import 'package:piwigo_ng/models/image_model.dart'; import 'package:piwigo_ng/network/api_error.dart'; +import 'package:piwigo_ng/network/upload.dart'; import 'package:piwigo_ng/services/chunked_uploader.dart'; import 'package:piwigo_ng/services/notification_service.dart'; import 'package:piwigo_ng/services/preferences_service.dart'; @@ -292,6 +292,7 @@ Future downloadImage( ImageModel image, ) async { String localPath = path.join(dirPath, image.file); + if (!await askMediaPermission()) return null; try { await ApiClient.download( path: image.elementUrl, diff --git a/pubspec.yaml b/pubspec.yaml index b7a4120..24c7c09 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -40,7 +40,7 @@ dependencies: flutter_easyloading: ^3.0.5 # Show loading dialog # Storage - package_info_plus: ^3.1.2 # Get project info (version) + package_info_plus: ^8.0.0 # Get project info (version) path_provider: ^2.0.11 # Get application documents shared_preferences: ^2.0.15 # Base local storage flutter_secure_storage: ^6.0.0 # Local storage secured for logins @@ -48,7 +48,7 @@ dependencies: file_picker: ^5.2.5 # Pick images and videos at a time for upload # Device - device_info_plus: ^8.2.0 # Get device info (version) + device_info_plus: ^10.1.0 # Get device info (version) flutter_local_notifications: ^17.2.0 # Throws notifications on download or upload open_filex: ^4.3.2 # Open files with devices apps workmanager: ^0.5.0 # Background processes (auto upload) @@ -57,10 +57,10 @@ dependencies: # Utils mime_type: ^1.0.0 # Check mime type of files (differentiate photos from videos) video_player: ^2.4.7 # Read video files in fullscreen mode - chewie: ^1.5.0 # Video player with options + chewie: ^1.8.1 # Video player with options flutter_image_compress: ^1.1.3 # Remove metadata permission_handler: ^10.2.0 # Check and asks for permissions - share_plus: ^4.4.0 # Share files + share_plus: ^9.0.0 # Share files flutter_cache_manager: ^3.3.0 # Handles network image cache heic_to_jpg: ^0.2.0 # Convert heic files to jpg provider: ^6.0.3 # Notifiers for theme and language changes From 0b6e3eff7db13db0e1e02a21c1337191c5e14ae1 Mon Sep 17 00:00:00 2001 From: remartin Date: Fri, 5 Jul 2024 20:18:14 +0200 Subject: [PATCH 2/4] fix: pop scope not working --- lib/views/album/album_page.dart | 5 ++++- lib/views/image/image_favorites_page.dart | 5 ++++- lib/views/image/image_page.dart | 3 ++- lib/views/image/image_search_page.dart | 5 ++++- lib/views/image/image_tags_page.dart | 5 ++++- 5 files changed, 18 insertions(+), 5 deletions(-) diff --git a/lib/views/album/album_page.dart b/lib/views/album/album_page.dart index 6e3a59b..b09a40e 100644 --- a/lib/views/album/album_page.dart +++ b/lib/views/album/album_page.dart @@ -198,17 +198,20 @@ class _AlbumPageState extends State { } void _onWillPop(bool pop) { + if (pop) return; if (_selectedList.isNotEmpty) { setState(() { _selectedList.clear(); }); + } else { + Navigator.of(context).pop(); } } @override Widget build(BuildContext context) { return PopScope( - canPop: _selectedList.isEmpty, + canPop: false, onPopInvoked: _onWillPop, child: Scaffold( body: SafeArea( diff --git a/lib/views/image/image_favorites_page.dart b/lib/views/image/image_favorites_page.dart index 5ea6f64..b1526e5 100644 --- a/lib/views/image/image_favorites_page.dart +++ b/lib/views/image/image_favorites_page.dart @@ -61,10 +61,13 @@ class _ImageFavoritesPageState extends State { bool get _hasNonFavorites => _selectedList.where((image) => !image.favorite).isNotEmpty; void _onWillPop(bool pop) async { + if (pop) return; if (_selectedList.isNotEmpty) { setState(() { _selectedList.clear(); }); + } else { + Navigator.of(context).pop(); } } @@ -141,7 +144,7 @@ class _ImageFavoritesPageState extends State { @override Widget build(BuildContext context) { return PopScope( - canPop: _selectedList.isEmpty, + canPop: false, onPopInvoked: _onWillPop, child: Scaffold( body: SafeArea( diff --git a/lib/views/image/image_page.dart b/lib/views/image/image_page.dart index d883f00..990bcb2 100644 --- a/lib/views/image/image_page.dart +++ b/lib/views/image/image_page.dart @@ -178,6 +178,7 @@ class _ImagePageState extends State { /// * If overlay is hidden, show it. /// * Otherwise, close the page. void _onWillPop(bool pop) { + if (pop) return; if (!_showOverlay) { setState(() { _showOverlay = true; @@ -282,7 +283,7 @@ class _ImagePageState extends State { @override Widget build(BuildContext context) { return PopScope( - canPop: !_showOverlay, + canPop: false, onPopInvoked: _onWillPop, child: Scaffold( backgroundColor: Colors.black, diff --git a/lib/views/image/image_search_page.dart b/lib/views/image/image_search_page.dart index 41aa507..6ded3dd 100644 --- a/lib/views/image/image_search_page.dart +++ b/lib/views/image/image_search_page.dart @@ -64,10 +64,13 @@ class _ImageSearchPageState extends State { bool get _hasNonFavorites => _selectedList.where((image) => !image.favorite).isNotEmpty; void _onWillPop(bool pop) { + if (pop) return; if (_selectedList.isNotEmpty) { setState(() { _selectedList.clear(); }); + } else { + Navigator.of(context).pop(); } } @@ -148,7 +151,7 @@ class _ImageSearchPageState extends State { @override Widget build(BuildContext context) { return PopScope( - canPop: _selectedList.isEmpty, + canPop: false, onPopInvoked: _onWillPop, child: Scaffold( body: SafeArea( diff --git a/lib/views/image/image_tags_page.dart b/lib/views/image/image_tags_page.dart index f909f17..88bf3c2 100644 --- a/lib/views/image/image_tags_page.dart +++ b/lib/views/image/image_tags_page.dart @@ -63,10 +63,13 @@ class _ImageTagsPageState extends State { bool get _hasNonFavorites => _selectedList.where((image) => !image.favorite).isNotEmpty; void _onWillPop(bool pop) { + if (pop) return null; if (_selectedList.isNotEmpty) { setState(() { _selectedList.clear(); }); + } else { + Navigator.of(context).pop(); } } @@ -143,7 +146,7 @@ class _ImageTagsPageState extends State { @override Widget build(BuildContext context) { return PopScope( - canPop: _selectedList.isEmpty, + canPop: false, onPopInvoked: _onWillPop, child: Scaffold( body: SafeArea( From 19441f7bd5639c5e86cef0e7d5be09a9077831d8 Mon Sep 17 00:00:00 2001 From: remartin Date: Fri, 5 Jul 2024 17:06:41 +0200 Subject: [PATCH 3/4] fix: share and download dependencies and permissions --- lib/network/images.dart | 3 ++- pubspec.yaml | 8 ++++---- 2 files changed, 6 insertions(+), 5 deletions(-) diff --git a/lib/network/images.dart b/lib/network/images.dart index 033a7a6..bd682cf 100644 --- a/lib/network/images.dart +++ b/lib/network/images.dart @@ -7,12 +7,12 @@ import 'package:file_picker/file_picker.dart'; import 'package:flutter/foundation.dart'; import 'package:flutter_local_notifications/flutter_local_notifications.dart'; import 'package:image_gallery_saver/image_gallery_saver.dart'; -import 'package:image_picker/image_picker.dart'; import 'package:path/path.dart' as path; import 'package:path_provider/path_provider.dart'; import 'package:piwigo_ng/models/album_model.dart'; import 'package:piwigo_ng/models/image_model.dart'; import 'package:piwigo_ng/network/api_error.dart'; +import 'package:piwigo_ng/network/upload.dart'; import 'package:piwigo_ng/services/chunked_uploader.dart'; import 'package:piwigo_ng/services/notification_service.dart'; import 'package:piwigo_ng/services/preferences_service.dart'; @@ -292,6 +292,7 @@ Future downloadImage( ImageModel image, ) async { String localPath = path.join(dirPath, image.file); + if (!await askMediaPermission()) return null; try { await ApiClient.download( path: image.elementUrl, diff --git a/pubspec.yaml b/pubspec.yaml index b7a4120..24c7c09 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -40,7 +40,7 @@ dependencies: flutter_easyloading: ^3.0.5 # Show loading dialog # Storage - package_info_plus: ^3.1.2 # Get project info (version) + package_info_plus: ^8.0.0 # Get project info (version) path_provider: ^2.0.11 # Get application documents shared_preferences: ^2.0.15 # Base local storage flutter_secure_storage: ^6.0.0 # Local storage secured for logins @@ -48,7 +48,7 @@ dependencies: file_picker: ^5.2.5 # Pick images and videos at a time for upload # Device - device_info_plus: ^8.2.0 # Get device info (version) + device_info_plus: ^10.1.0 # Get device info (version) flutter_local_notifications: ^17.2.0 # Throws notifications on download or upload open_filex: ^4.3.2 # Open files with devices apps workmanager: ^0.5.0 # Background processes (auto upload) @@ -57,10 +57,10 @@ dependencies: # Utils mime_type: ^1.0.0 # Check mime type of files (differentiate photos from videos) video_player: ^2.4.7 # Read video files in fullscreen mode - chewie: ^1.5.0 # Video player with options + chewie: ^1.8.1 # Video player with options flutter_image_compress: ^1.1.3 # Remove metadata permission_handler: ^10.2.0 # Check and asks for permissions - share_plus: ^4.4.0 # Share files + share_plus: ^9.0.0 # Share files flutter_cache_manager: ^3.3.0 # Handles network image cache heic_to_jpg: ^0.2.0 # Convert heic files to jpg provider: ^6.0.3 # Notifiers for theme and language changes From fe7bdecd2d85f26ceee8d4494ed95e71ffe634bb Mon Sep 17 00:00:00 2001 From: remartin Date: Sat, 13 Jul 2024 10:50:04 +0200 Subject: [PATCH 4/4] fix: changed download url to action.php --- lib/components/lists/image_grid_view.dart | 12 ++++++------ lib/network/images.dart | 6 +++++- pubspec.yaml | 2 +- 3 files changed, 12 insertions(+), 8 deletions(-) diff --git a/lib/components/lists/image_grid_view.dart b/lib/components/lists/image_grid_view.dart index bc63023..bfe91ab 100644 --- a/lib/components/lists/image_grid_view.dart +++ b/lib/components/lists/image_grid_view.dart @@ -31,11 +31,11 @@ class _ImageGridViewState extends State { void _onTapImage(ImageModel image) { final bool selected = widget.selectedList.contains(image); if (widget.selectedList.isNotEmpty && !selected) { - if (widget.onSelectImage != null) widget.onSelectImage!(image); + widget.onSelectImage?.call(image); } else if (selected) { - if (widget.onDeselectImage != null) widget.onDeselectImage!(image); + widget.onDeselectImage?.call(image); } else { - if (widget.onTapImage != null) widget.onTapImage!(image); + widget.onTapImage?.call(image); } } @@ -43,8 +43,9 @@ class _ImageGridViewState extends State { if (widget.selectedList.isEmpty) { HapticFeedback.mediumImpact(); } + if (widget.selectedList.contains(image)) return; setState(() { - if (widget.onSelectImage != null) widget.onSelectImage!(image); + widget.onSelectImage?.call(image); }); } @@ -69,8 +70,7 @@ class _ImageGridViewState extends State { return ClipRRect( borderRadius: index == widget.imageList.length - 1 ? BorderRadius.only( - topRight: widget.imageList.length < - Settings.getImageCrossAxisCount(context) + topRight: widget.imageList.length < Settings.getImageCrossAxisCount(context) ? Radius.circular(10.0) : Radius.zero, bottomRight: Radius.circular(10.0), diff --git a/lib/network/images.dart b/lib/network/images.dart index bd682cf..abce81b 100644 --- a/lib/network/images.dart +++ b/lib/network/images.dart @@ -295,7 +295,11 @@ Future downloadImage( if (!await askMediaPermission()) return null; try { await ApiClient.download( - path: image.elementUrl, + path: 'action.php', + queryParameters: { + 'id': image.id, + 'part': 'e', + }, outputPath: localPath, ); await ImageGallerySaver.saveFile( diff --git a/pubspec.yaml b/pubspec.yaml index 24c7c09..6e46c34 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -50,7 +50,7 @@ dependencies: # Device device_info_plus: ^10.1.0 # Get device info (version) flutter_local_notifications: ^17.2.0 # Throws notifications on download or upload - open_filex: ^4.3.2 # Open files with devices apps + open_filex: ^4.4.0 # Open files with devices apps workmanager: ^0.5.0 # Background processes (auto upload) image_gallery_saver: ^2.0.3 # Download images