@@ -7,6 +7,7 @@ import 'package:dio/dio.dart';
77import 'package:dio_cookie_manager/dio_cookie_manager.dart' ;
88import 'package:flutter/foundation.dart' ;
99import 'package:flutter_secure_storage/flutter_secure_storage.dart' ;
10+ import 'package:heic_to_jpg/heic_to_jpg.dart' ;
1011import 'package:image_picker/image_picker.dart' ;
1112import 'package:piwigo_ng/models/album_model.dart' ;
1213import 'package:piwigo_ng/models/status_model.dart' ;
@@ -71,22 +72,44 @@ class AutoUploadManager {
7172
7273 Future <bool > autoUpload () async {
7374 SharedPreferences prefs = await SharedPreferences .getInstance ();
75+
76+ // Check upload on WiFi only setting
7477 if (prefs.getBool (Preferences .wifiUploadKey) ?? false ) {
75- print ('Check wifi only' );
78+ debugPrint ('Check wifi only' );
7679 var connectivity = await Connectivity ().checkConnectivity ();
7780 if (connectivity != ConnectivityResult .wifi) {
78- print ('No wifi' );
81+ debugPrint ('No wifi' );
7982 return false ;
8083 }
81- print ('Has wifi' );
84+ debugPrint ('Has wifi' );
8285 }
86+
8387 final Directory ? appDocDir = await getUploadDirectory ();
8488 if (appDocDir == null ) return false ;
85- List <FileSystemEntity > dirFiles = appDocDir.listSync ();
89+
90+ // Get source folder content
91+ List <FileSystemEntity > dirFiles = appDocDir.listSync (recursive: true );
92+
93+ // Remove folders and links
8694 List <File > files = dirFiles
8795 .where ((file) => file is File )
8896 .map <File >((e) => e as File )
8997 .toList ();
98+
99+ // Convert .heic files to .jpg
100+ for (File file in files) {
101+ if (file.path.endsWith ('.heic' )) {
102+ debugPrint ("${file .path } is Heic !" );
103+ String ? jpgPath = await HeicToJpg .convert (
104+ file.path,
105+ );
106+ debugPrint ("From ${file .path }...\n to $jpgPath " );
107+ if (jpgPath != null ) {
108+ files.remove (file);
109+ files.add (File (jpgPath));
110+ }
111+ }
112+ }
90113 debugPrint ("List files: ${files .toString ()}" );
91114 await autoUploadPhotos (files);
92115 return true ;
@@ -192,10 +215,8 @@ class AutoUploadManager {
192215 // If no changes, end task iteration
193216 if (result.isEmpty) return ;
194217
195- // Send notifications
196218 await showAutoUploadNotification (nbError, result.length);
197219
198- // Empty lunge
199220 await _emptyLunge (result, destination.id);
200221 }
201222
0 commit comments