Skip to content

Commit f52d5f3

Browse files
committed
move or assign image
1 parent ea49608 commit f52d5f3

11 files changed

Lines changed: 531 additions & 362 deletions

lib/api/images.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -306,7 +306,7 @@ Future<int> moveImages(List<ImageModel> images, int oldAlbumId, int newAlbumId)
306306
int nbMoved = 0;
307307
for (var image in images) {
308308
bool response = await moveImage(image, oldAlbumId, newAlbumId);
309-
if (response == false) {
309+
if (response) {
310310
nbMoved++;
311311
}
312312
}

lib/app.dart

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -127,6 +127,7 @@ Route<dynamic> generateRoute(RouteSettings settings) {
127127
images: arguments['images'] ?? [],
128128
startId: arguments['startId'],
129129
album: arguments['album'],
130+
isAdmin: arguments['isAdmin'] ?? isAdmin,
130131
),
131132
settings: settings,
132133
);

lib/components/modals/choose_camera_picker_modal.dart

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ class ChooseCameraPickerModal extends StatelessWidget {
88
@override
99
Widget build(BuildContext context) {
1010
return PiwigoModal(
11+
title: appStrings.categoryUpload_images,
1112
content: Padding(
1213
padding: const EdgeInsets.symmetric(vertical: 8.0),
1314
child: Column(
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
import 'package:flutter/material.dart';
2+
import 'package:piwigo_ng/components/modals/piwigo_modal.dart';
3+
import 'package:piwigo_ng/utils/localizations.dart';
4+
5+
class ChooseMoveOptionModal extends StatelessWidget {
6+
const ChooseMoveOptionModal({Key? key}) : super(key: key);
7+
8+
@override
9+
Widget build(BuildContext context) {
10+
return PiwigoModal(
11+
title: appStrings.moveImage_title,
12+
content: Padding(
13+
padding: const EdgeInsets.symmetric(vertical: 8.0),
14+
child: Column(
15+
children: [
16+
ListTile(
17+
minLeadingWidth: 24,
18+
leading: Icon(Icons.drive_file_move, color: Theme.of(context).primaryColor),
19+
title: Text(appStrings.moveImage_title),
20+
onTap: () => Navigator.of(context).pop(0),
21+
),
22+
ListTile(
23+
minLeadingWidth: 24,
24+
leading: Icon(Icons.copy, color: Theme.of(context).primaryColor),
25+
title: Text(appStrings.copyImage_title),
26+
onTap: () => Navigator.of(context).pop(1),
27+
),
28+
],
29+
),
30+
),
31+
);
32+
}
33+
}

lib/components/modals/move_or_copy_modal.dart

Lines changed: 20 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
import 'package:flutter/material.dart';
22
import 'package:piwigo_ng/api/albums.dart';
33
import 'package:piwigo_ng/api/api_error.dart';
4-
import 'package:piwigo_ng/components/dialogs/confirm_dialog.dart';
54
import 'package:piwigo_ng/models/album_model.dart';
65
import 'package:piwigo_ng/utils/localizations.dart';
76

@@ -19,7 +18,7 @@ class MoveOrCopyModal extends StatefulWidget {
1918
final bool isImage;
2019
final String? title;
2120
final String? subtitle;
22-
final Function(AlbumModel)? onSelected;
21+
final Future<dynamic> Function(AlbumModel)? onSelected;
2322

2423
@override
2524
_MoveOrCopyModalState createState() => _MoveOrCopyModalState();
@@ -46,22 +45,8 @@ class _MoveOrCopyModalState extends State<MoveOrCopyModal> {
4645
}
4746

4847
Future<void> _onTapAlbum(AlbumModel album) async {
49-
if (!await showConfirmDialog(
50-
context,
51-
title: appStrings.moveCategory,
52-
message: appStrings.moveCategory_message(
53-
widget.album.name,
54-
album.name,
55-
),
56-
)) return;
57-
ApiResult<bool> result = await moveAlbum(
58-
widget.album.id,
59-
album.id,
60-
);
61-
62-
if (result.hasData && result.data == true) {
63-
Navigator.of(context).pop();
64-
}
48+
bool? result = await widget.onSelected?.call(album);
49+
Navigator.of(context).pop(result ?? false);
6550
}
6651

6752
@override
@@ -77,20 +62,7 @@ class _MoveOrCopyModalState extends State<MoveOrCopyModal> {
7762
),
7863
builder: (context) => Scaffold(
7964
backgroundColor: Colors.transparent,
80-
appBar: AppBar(
81-
shape: const RoundedRectangleBorder(
82-
borderRadius: BorderRadius.vertical(
83-
top: Radius.circular(15.0),
84-
),
85-
),
86-
elevation: 0.0,
87-
scrolledUnderElevation: 5.0,
88-
leading: IconButton(
89-
icon: Icon(Icons.close),
90-
onPressed: () => Navigator.of(context).pop(),
91-
),
92-
title: Text(widget.title ?? ''),
93-
),
65+
appBar: _appBar,
9466
body: Theme(
9567
data: Theme.of(context).copyWith(
9668
scrollbarTheme: ScrollbarThemeData(
@@ -136,6 +108,22 @@ class _MoveOrCopyModalState extends State<MoveOrCopyModal> {
136108
);
137109
}
138110

111+
PreferredSizeWidget get _appBar => AppBar(
112+
shape: const RoundedRectangleBorder(
113+
borderRadius: BorderRadius.vertical(
114+
top: Radius.circular(15.0),
115+
),
116+
),
117+
elevation: 0.0,
118+
scrolledUnderElevation: 5.0,
119+
centerTitle: true,
120+
leading: IconButton(
121+
icon: Icon(Icons.close),
122+
onPressed: () => Navigator.of(context).pop(),
123+
),
124+
title: Text(widget.title ?? ''),
125+
);
126+
139127
Widget get _albumTreeList => DecoratedBox(
140128
decoration: BoxDecoration(
141129
color: Theme.of(context).inputDecorationTheme.fillColor,

lib/main.dart

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,9 +27,9 @@ void main() async {
2727

2828
void _clearUnusedStorage() async {
2929
SharedPreferences prefs = await SharedPreferences.getInstance();
30-
if (!prefs.containsKey('STORAGE_VERSION') && prefs.getString('STORAGE_VERSION') != "2.0.0") {
30+
if (!prefs.containsKey('STORAGE_VERSION') && prefs.getString('STORAGE_VERSION') != '2.0.0') {
3131
prefs.clear();
3232
const FlutterSecureStorage().deleteAll();
33-
prefs.setString('STORAGE_VERSION', "2.0.0");
33+
prefs.setString('STORAGE_VERSION', '2.0.0');
3434
}
3535
}

lib/utils/album_actions.dart

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -56,15 +56,13 @@ Future<void> onMoveAlbum(BuildContext context, AlbumModel album) async {
5656
album.name,
5757
selectedAlbum.name,
5858
),
59-
)) return;
59+
)) return false;
6060
ApiResult<bool> result = await moveAlbum(
6161
album.id,
6262
selectedAlbum.id,
6363
);
6464

65-
if (result.hasData && result.data == true) {
66-
Navigator.of(context).pop();
67-
}
65+
return result.hasData && result.data == true;
6866
},
6967
),
7068
),

lib/utils/image_actions.dart

Lines changed: 53 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,9 @@ import 'package:piwigo_ng/api/images.dart';
66
import 'package:piwigo_ng/api/users.dart';
77
import 'package:piwigo_ng/components/dialogs/confirm_dialog.dart';
88
import 'package:piwigo_ng/components/modals/choose_camera_picker_modal.dart';
9+
import 'package:piwigo_ng/components/modals/choose_move_option_modal.dart';
910
import 'package:piwigo_ng/components/modals/delete_images_modal.dart';
11+
import 'package:piwigo_ng/components/modals/move_or_copy_modal.dart';
1012
import 'package:piwigo_ng/components/snackbars.dart';
1113
import 'package:piwigo_ng/models/album_model.dart';
1214
import 'package:piwigo_ng/models/image_model.dart';
@@ -57,6 +59,47 @@ Future<bool?> onEditPhotos(BuildContext context, List<ImageModel> images) async
5759
});
5860
}
5961

62+
Future<dynamic> onMovePhotos(BuildContext context, List<ImageModel> images, AlbumModel album) async {
63+
return showModalBottomSheet<dynamic>(
64+
context: context,
65+
isScrollControlled: true,
66+
builder: (_) => Padding(
67+
padding: MediaQuery.of(context).padding,
68+
child: MoveOrCopyModal(
69+
title: appStrings.moveImage_title,
70+
subtitle: appStrings.moveImage_selectAlbum(images.length, images.first),
71+
isImage: true,
72+
album: album,
73+
onSelected: (selectedAlbum) async {
74+
final int? choice = await showModalBottomSheet<int>(
75+
context: context,
76+
builder: (context) => ChooseMoveOptionModal(),
77+
);
78+
if (choice == null ||
79+
!await showConfirmDialog(
80+
context,
81+
title: appStrings.moveImage_title,
82+
message: appStrings.moveImage_message(images.length, images.first, selectedAlbum.name),
83+
)) return false;
84+
int results = 0;
85+
switch (choice) {
86+
case 0:
87+
results = await moveImages(images, album.id, selectedAlbum.id);
88+
break;
89+
case 1:
90+
results = await assignImages(images, selectedAlbum.id);
91+
break;
92+
}
93+
if (results > 0) {
94+
return choice;
95+
}
96+
return -1;
97+
},
98+
),
99+
),
100+
);
101+
}
102+
60103
Future<bool> onDeletePhotos(BuildContext context, List<ImageModel> images, AlbumModel album) async {
61104
final DeleteAlbumModes? mode = await showModalBottomSheet<DeleteAlbumModes>(
62105
context: context,
@@ -94,10 +137,17 @@ Future<bool> onDeletePhotos(BuildContext context, List<ImageModel> images, Album
94137
return false;
95138
}
96139

97-
Future<void> onLikePhotos(List<ImageModel> images, bool hasNonFavorites) async {
140+
Future<bool?> onLikePhotos(List<ImageModel> images, bool hasNonFavorites) async {
98141
if (hasNonFavorites) {
99-
await addFavorites(images.where((image) => !image.favorite).toList());
142+
int success = await addFavorites(images.where((image) => !image.favorite).toList());
143+
if (success > 0) {
144+
return true;
145+
}
100146
} else {
101-
await removeFavorites(images);
147+
int success = await removeFavorites(images);
148+
if (success > 0) {
149+
return false;
150+
}
102151
}
152+
return null;
103153
}

0 commit comments

Comments
 (0)