Skip to content

Commit 7698e58

Browse files
committed
added download settings
1 parent b341936 commit 7698e58

4 files changed

Lines changed: 86 additions & 31 deletions

File tree

lib/api/ImageAPI.dart

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import 'dart:convert';
2+
import 'dart:io';
23

34
import 'package:dio/dio.dart';
45
import 'package:file_picker/file_picker.dart';
@@ -82,10 +83,11 @@ Future<bool> _requestPermissions() async {
8283

8384
return permission == PermissionStatus.granted;
8485
}
85-
Future<String> _pickDirectoryPath() async {
86+
Future<String> pickDirectoryPath() async {
8687
return await FilePicker.platform.getDirectoryPath();
8788
}
8889
Future<void> _showNotification({bool success = true, String payload}) async {
90+
if(!(API.prefs.getBool('download_notification') ?? true)) return;
8991
final android = AndroidNotificationDetails(
9092
'id',
9193
'Piwigo NG Download',
@@ -120,9 +122,14 @@ Future<List<String>> downloadImages(List<dynamic> images, {bool showNotification
120122
final isPermissionStatusGranted = await _requestPermissions();
121123
if (!isPermissionStatusGranted) return null;
122124

123-
final dirPath = cached
124-
? (await getTemporaryDirectory()).path
125-
: await _pickDirectoryPath();
125+
String dirPath = (await getTemporaryDirectory()).path;
126+
if(!cached) {
127+
if(API.prefs.getString('download_destination') != null) {
128+
dirPath = API.prefs.getString('download_destination');
129+
} else {
130+
dirPath = await pickDirectoryPath();
131+
}
132+
}
126133
if(dirPath == null) return null;
127134

128135
final List<String> filesPath = [];
@@ -151,16 +158,15 @@ Future<List<String>> downloadImages(List<dynamic> images, {bool showNotification
151158
return filesPath;
152159
}
153160
Future<String> downloadImage(String dirPath, String url, String file) async {
154-
155-
var localPath = path.join(dirPath, file);
161+
String localPath = path.join(dirPath, file);
156162
try {
157163
Response response = await API().dio.download(
158164
url,
159165
localPath,
160166
);
161167
return localPath;
162168
} catch (e) {
163-
print(e);
169+
print("Download error: $e");
164170
return null;
165171
}
166172
}

lib/l10n/app_en.arb

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -841,6 +841,8 @@
841841
"settings_wifiOnly": "Wi-Fi Only",
842842
"settings_deleteImage": "Delete After Upload",
843843
"settings_uploadNotification": "Upload Notification",
844+
"settings_downloadNotification": "Download Notification",
845+
"settings_downloadDestination": "Download Folder",
844846

845847

846848
"settings_autoUpload": "Auto Upload",

lib/services/upload/Uploader.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ class Uploader {
2525
Uploader(this.mainContext);
2626

2727
Future<void> _showUploadNotification({bool success = true}) async {
28-
if(!(API.prefs.getBool('upload_notification') ?? false)) return;
28+
if(!(API.prefs.getBool('upload_notification') ?? true)) return;
2929
final android = AndroidNotificationDetails(
3030
'piwigo-ng-upload',
3131
'Piwigo NG Upload',

lib/views/SettingsViewPage.dart

Lines changed: 70 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import 'package:flutter/material.dart';
22
import 'package:font_awesome_flutter/font_awesome_flutter.dart';
33
import 'package:package_info_plus/package_info_plus.dart';
4+
import 'package:piwigo_ng/api/ImageAPI.dart';
45
import 'package:piwigo_ng/constants/SettingsConstants.dart';
56
import 'package:piwigo_ng/views/LoginViewPage.dart';
67
import 'package:piwigo_ng/api/API.dart';
@@ -32,6 +33,10 @@ class _SettingsPageState extends State<SettingsPage> {
3233
_thumbnailDerivative = API.prefs.getString('thumbnail_size');
3334
}
3435

36+
String _parseFilePath(String path) {
37+
return path.replaceFirst(RegExp(r'/storage/emulated/0'), '');
38+
}
39+
3540
@override
3641
Widget build(BuildContext context) {
3742
ThemeData _theme = Theme.of(context);
@@ -195,32 +200,74 @@ class _SettingsPageState extends State<SettingsPage> {
195200
),
196201
),
197202
SectionItem(
198-
Text(appStrings(context).defaultImageSize320px, style: TextStyle(color: Colors.black, fontSize: 16)),
199-
Row(
200-
mainAxisAlignment: MainAxisAlignment.end,
201-
children: [
202-
DropdownButton<String>(
203-
value: _fsDerivative == null ? API.prefs.getString('full_screen_image_size') : _fsDerivative,
204-
style: TextStyle(color: Colors.grey.shade600, fontSize: 14),
205-
underline: Container(),
206-
icon: Icon(Icons.chevron_right, color: Colors.grey.shade600, size: 20),
207-
onChanged: (String newValue) {
203+
Expanded(
204+
child: Text(appStrings(context).defaultImageSize320px,
205+
style: TextStyle(color: Colors.black, fontSize: 16),
206+
),
207+
),
208+
DropdownButton<String>(
209+
value: _fsDerivative == null ? API.prefs.getString('full_screen_image_size') : _fsDerivative,
210+
style: TextStyle(color: Colors.grey.shade600, fontSize: 14),
211+
underline: const SizedBox(),
212+
icon: Icon(Icons.chevron_right, color: Colors.grey.shade600, size: 20),
213+
onChanged: (String newValue) {
214+
setState(() {
215+
_fsDerivative = newValue;
216+
API.prefs.setString('full_screen_image_size', _fsDerivative);
217+
});
218+
},
219+
items: API.prefs.getStringList('available_sizes').map<DropdownMenuItem<String>>((
220+
String value) {
221+
return DropdownMenuItem<String>(
222+
value: value,
223+
alignment: AlignmentDirectional.centerStart,
224+
child: Text(photoSize(context, value)),
225+
);
226+
}).toList(),
227+
),
228+
),
229+
SectionItem(
230+
Text(appStrings(context).settings_downloadDestination, style: TextStyle(color: Colors.black, fontSize: 16)),
231+
Expanded(
232+
child: GestureDetector(
233+
behavior: HitTestBehavior.opaque,
234+
onTap: () async {
235+
String path = await pickDirectoryPath();
236+
if(path != null) {
208237
setState(() {
209-
_fsDerivative = newValue;
210-
API.prefs.setString('full_screen_image_size', _fsDerivative);
238+
API.prefs.setString('download_destination', path);
211239
});
212-
},
213-
items: API.prefs.getStringList('available_sizes').map<DropdownMenuItem<String>>((
214-
String value) {
215-
return DropdownMenuItem<String>(
216-
value: value,
217-
child: Text(photoSize(context, value)),
218-
);
219-
}).toList(),
240+
}
241+
},
242+
child: Row(
243+
children: [
244+
Expanded(
245+
child: Text(
246+
_parseFilePath(API.prefs.getString('download_destination') ?? appStrings(context).none),
247+
textAlign: TextAlign.end,
248+
style: TextStyle(color: Colors.grey.shade600, fontSize: 14),
249+
),
250+
),
251+
Padding(
252+
padding: const EdgeInsets.only(left: 8),
253+
child: Icon(Icons.chevron_right, color: Colors.grey.shade600, size: 20),
254+
),
255+
],
220256
),
221-
],
257+
),
258+
),
259+
),
260+
SectionItem(
261+
Text(appStrings(context).settings_downloadNotification, style: TextStyle(color: Colors.black, fontSize: 16)),
262+
Switch(
263+
value: API.prefs.getBool('download_notification') ?? true,
264+
activeColor: Theme.of(context).colorScheme.primary,
265+
onChanged: (bool) {
266+
setState(() {
267+
API.prefs.setBool('download_notification', bool);
268+
});
269+
},
222270
),
223-
isEnd: true,
224271
),
225272
],
226273
),
@@ -259,7 +306,7 @@ class _SettingsPageState extends State<SettingsPage> {
259306
SectionItem(
260307
Text(appStrings(context).settings_uploadNotification, style: TextStyle(color: Colors.black, fontSize: 16)),
261308
Switch(
262-
value: API.prefs.getBool('upload_notification') ?? false,
309+
value: API.prefs.getBool('upload_notification') ?? true,
263310
activeColor: Theme.of(context).colorScheme.primary,
264311
onChanged: (bool) {
265312
setState(() {

0 commit comments

Comments
 (0)