Skip to content

Commit 569c752

Browse files
committed
Rebase PR #206 from kaysavps
2 parents b46f4ca + d0d95e5 commit 569c752

12 files changed

Lines changed: 158 additions & 24 deletions

File tree

android/app/src/main/AndroidManifest.xml

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,16 @@
3737
<action android:name="android.intent.action.MAIN"/>
3838
<category android:name="android.intent.category.LAUNCHER"/>
3939
</intent-filter>
40+
<intent-filter>
41+
<action android:name="android.intent.action.SEND" />
42+
<category android:name="android.intent.category.DEFAULT" />
43+
<data android:mimeType="image/*" />
44+
</intent-filter>
45+
<intent-filter>
46+
<action android:name="android.intent.action.SEND_MULTIPLE" />
47+
<category android:name="android.intent.category.DEFAULT" />
48+
<data android:mimeType="image/*" />
49+
</intent-filter>
4050
</activity>
4151

4252
<!-- Don't delete the meta-data below.

l10n/app_en.arb

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -313,6 +313,16 @@
313313
"moveCategoryError_title": "Move Fail",
314314
"moveCategoryError_message": "Failed to move your album",
315315

316+
"selectCategory": "Select Album",
317+
"selectCategory_select": "Please select an album or sub-album.",
318+
"selectCategory_message": "{count, plural, =1{Are you sure you want to upload the image into the album {parent} ?} other{Are you sure you want to upload the images into the album {parent} ?}}",
319+
"@selectCategory_message" : {
320+
"placeholders": {
321+
"count": {},
322+
"parent": {}
323+
}
324+
},
325+
316326

317327
"categoryPrivacy": "Manage Permissions",
318328
"categoryPrivacy_subtitle": "Manage access permissions of \"{album_name}\".",

lib/app.dart

Lines changed: 50 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import 'package:flutter_localizations/flutter_localizations.dart';
44
import 'package:image_picker/image_picker.dart';
55
import 'package:piwigo_ng/services/app_providers.dart';
66
import 'package:piwigo_ng/services/preferences_service.dart';
7+
import 'package:piwigo_ng/services/receive_sharing.dart';
78
import 'package:piwigo_ng/utils/overscroll_behavior.dart';
89
import 'package:piwigo_ng/utils/themes.dart';
910
import 'package:piwigo_ng/views/album/album_page.dart';
@@ -92,10 +93,9 @@ class App extends StatelessWidget {
9293
}
9394

9495
Route<dynamic> generateRoute(RouteSettings settings) {
96+
String? routeName;
9597
Map<String, dynamic> arguments = {};
96-
if (settings.arguments != null) {
97-
arguments = settings.arguments as Map<String, dynamic>;
98-
}
98+
bool externalAppSharedFiles = SharedIntent.sharedFiles != null && SharedIntent.sharedFiles!.isNotEmpty;
9999

100100
bool isAdmin = appPreferences.getBool(Preferences.isAdminKey) ?? false;
101101

@@ -107,7 +107,14 @@ Route<dynamic> generateRoute(RouteSettings settings) {
107107
);
108108
}
109109

110-
switch (settings.name) {
110+
if (externalAppSharedFiles) {
111+
routeName = UploadPage.routeName;
112+
} else {
113+
routeName = settings.name;
114+
arguments = _extractArguments(settings);
115+
}
116+
117+
switch (routeName) {
111118
case LoginPage.routeName:
112119
return MaterialPageRoute(
113120
builder: (_) => const LoginPage(),
@@ -164,13 +171,7 @@ Route<dynamic> generateRoute(RouteSettings settings) {
164171
settings: settings,
165172
);
166173
case UploadPage.routeName:
167-
return MaterialPageRoute(
168-
builder: (_) => UploadPage(
169-
imageList: arguments["images"] ?? <XFile>[],
170-
albumId: arguments["category"],
171-
),
172-
settings: settings,
173-
);
174+
return _createUploadPageRoute(settings, externalAppSharedFiles);
174175
case UploadStatusPage.routeName:
175176
return MaterialPageRoute(
176177
builder: (_) => UploadStatusPage(),
@@ -228,3 +229,41 @@ Route<dynamic> generateRoute(RouteSettings settings) {
228229
);
229230
}
230231
}
232+
233+
Map<String, dynamic> _extractArguments(RouteSettings settings) {
234+
if (settings.arguments != null) {
235+
return settings.arguments as Map<String, dynamic>;
236+
}
237+
return {};
238+
}
239+
240+
MaterialPageRoute<dynamic> _createUploadPageRoute(RouteSettings settings, bool externalAppSharedFiles) {
241+
Map<String, dynamic> arguments = {};
242+
243+
if (externalAppSharedFiles) {
244+
arguments['images'] = SharedIntent.sharedFiles;
245+
SharedIntent.cleanupSharedFiles();
246+
247+
// Create new RouteSettings with updated arguments
248+
return MaterialPageRoute(
249+
builder: (_) => UploadPage(
250+
imageList: arguments["images"] ?? <XFile>[],
251+
albumId: arguments["category"],
252+
),
253+
settings: RouteSettings( // Create new RouteSettings here
254+
name: UploadPage.routeName,
255+
arguments: arguments,
256+
),
257+
);
258+
} else {
259+
// For other cases, use original settings
260+
arguments = _extractArguments(settings);
261+
return MaterialPageRoute(
262+
builder: (_) => UploadPage(
263+
imageList: arguments["images"] ?? <XFile>[],
264+
albumId: arguments["category"],
265+
),
266+
settings: settings,
267+
);
268+
}
269+
}

lib/components/modals/move_or_copy_modal.dart renamed to lib/components/modals/select_move_or_copy_modal.dart

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,8 @@ import 'package:piwigo_ng/network/albums.dart';
55
import 'package:piwigo_ng/network/api_error.dart';
66
import 'package:piwigo_ng/utils/localizations.dart';
77

8-
class MoveOrCopyModal extends StatefulWidget {
9-
const MoveOrCopyModal({
8+
class SelectMoveOrCopyModal extends StatefulWidget {
9+
const SelectMoveOrCopyModal({
1010
Key? key,
1111
this.album,
1212
this.isImage = false,
@@ -22,10 +22,10 @@ class MoveOrCopyModal extends StatefulWidget {
2222
final Future<dynamic> Function(AlbumModel)? onSelected;
2323

2424
@override
25-
_MoveOrCopyModalState createState() => _MoveOrCopyModalState();
25+
_SelectMoveOrCopyModalState createState() => _SelectMoveOrCopyModalState();
2626
}
2727

28-
class _MoveOrCopyModalState extends State<MoveOrCopyModal> {
28+
class _SelectMoveOrCopyModalState extends State<SelectMoveOrCopyModal> {
2929
late final Future<ApiResponse<List<AlbumModel>>> _albumFuture;
3030
late final List<int> _disabledAlbums;
3131

lib/main.dart

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,12 +8,14 @@ import 'package:piwigo_ng/network/api_client.dart';
88
import 'package:piwigo_ng/services/auto_upload_manager.dart';
99
import 'package:piwigo_ng/services/notification_service.dart';
1010
import 'package:piwigo_ng/services/preferences_service.dart';
11+
import 'package:piwigo_ng/services/receive_sharing.dart';
1112
import 'package:piwigo_ng/services/theme_provider.dart';
1213
import 'package:shared_preferences/shared_preferences.dart';
1314

1415
void main() async {
1516
WidgetsFlutterBinding.ensureInitialized();
1617
_setUITheme();
18+
await SharedIntent.receiveSharedData();
1719
HttpOverrides.global = SSLHttpOverrides();
1820
appPreferences = await SharedPreferences.getInstance();
1921
runApp(const App());

lib/services/receive_sharing.dart

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
import 'package:image_picker/image_picker.dart';
2+
import 'package:receive_sharing_intent/receive_sharing_intent.dart';
3+
4+
5+
class SharedIntent {
6+
static List<XFile>? sharedFiles;
7+
static Future<List<XFile>?> receiveSharedData() async {
8+
try {
9+
// Get the instance of ReceiveSharingIntent
10+
ReceiveSharingIntent receiveSharingIntent = await ReceiveSharingIntent.instance;
11+
12+
// Get the initial shared data
13+
List<SharedMediaFile> receivedFiles = await receiveSharingIntent.getInitialMedia();
14+
15+
if (receivedFiles.isNotEmpty) {
16+
// Transform SharedMediaFile to XFile
17+
sharedFiles = receivedFiles.map((sharedFile) => XFile(sharedFile.path)).toList();
18+
return sharedFiles;
19+
} else {
20+
return null;
21+
}
22+
} catch (e) {
23+
print('Error receiving shared data: $e');
24+
return null;
25+
}
26+
}
27+
static void cleanupSharedFiles() {
28+
sharedFiles = null;
29+
}
30+
}

lib/utils/album_actions.dart

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import 'package:piwigo_ng/components/dialogs/confirm_dialog.dart';
33
import 'package:piwigo_ng/components/modals/create_album_modal.dart';
44
import 'package:piwigo_ng/components/modals/delete_album_mode_modal.dart';
55
import 'package:piwigo_ng/components/modals/edit_album_modal.dart';
6-
import 'package:piwigo_ng/components/modals/move_or_copy_modal.dart';
6+
import 'package:piwigo_ng/components/modals/select_move_or_copy_modal.dart';
77
import 'package:piwigo_ng/components/modals/piwigo_modal.dart';
88
import 'package:piwigo_ng/components/snackbars.dart';
99
import 'package:piwigo_ng/models/album_model.dart';
@@ -43,7 +43,7 @@ Future<void> onEditAlbum(BuildContext context, AlbumModel album) async {
4343
Future<void> onMoveAlbum(BuildContext context, AlbumModel album) async {
4444
await showPiwigoModal(
4545
context: context,
46-
builder: (_) => MoveOrCopyModal(
46+
builder: (_) => SelectMoveOrCopyModal(
4747
title: appStrings.moveCategory,
4848
subtitle: appStrings.moveCategory_select(album.name),
4949
album: album,

lib/utils/image_actions.dart

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ import 'package:piwigo_ng/components/dialogs/confirm_dialog.dart';
99
import 'package:piwigo_ng/components/modals/choose_camera_picker_modal.dart';
1010
import 'package:piwigo_ng/components/modals/choose_move_option_modal.dart';
1111
import 'package:piwigo_ng/components/modals/delete_images_modal.dart';
12-
import 'package:piwigo_ng/components/modals/move_or_copy_modal.dart';
12+
import 'package:piwigo_ng/components/modals/select_move_or_copy_modal.dart';
1313
import 'package:piwigo_ng/components/modals/piwigo_modal.dart';
1414
import 'package:piwigo_ng/components/snackbars.dart';
1515
import 'package:piwigo_ng/models/album_model.dart';
@@ -139,7 +139,7 @@ Future<dynamic> onMovePhotos(BuildContext context, List<ImageModel> images,
139139
}
140140
return showPiwigoModal(
141141
context: context,
142-
builder: (_) => MoveOrCopyModal(
142+
builder: (_) => SelectMoveOrCopyModal(
143143
title: appStrings.moveImage_title,
144144
subtitle: appStrings.moveImage_selectAlbum(
145145
images.length,

lib/views/settings/auto_upload_page.dart

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import 'package:flutter/material.dart';
2-
import 'package:piwigo_ng/components/modals/move_or_copy_modal.dart';
2+
import 'package:piwigo_ng/components/modals/select_move_or_copy_modal.dart';
33
import 'package:piwigo_ng/components/modals/piwigo_modal.dart';
44
import 'package:piwigo_ng/components/sections/settings_section.dart';
55
import 'package:piwigo_ng/models/album_model.dart';
@@ -96,7 +96,7 @@ class _AutoUploadPageState extends State<AutoUploadPage> {
9696
onPressed: () async {
9797
await showPiwigoModal(
9898
context: context,
99-
builder: (_) => MoveOrCopyModal(
99+
builder: (_) => SelectMoveOrCopyModal(
100100
title: appStrings.settings_autoUploadDestination,
101101
subtitle: appStrings.settings_autoUploadDestinationInfo,
102102
isImage: true,

lib/views/upload/upload_page.dart

Lines changed: 37 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,10 @@ import 'package:mime_type/mime_type.dart';
88
import 'package:piwigo_ng/components/buttons/animated_piwigo_button.dart';
99
import 'package:piwigo_ng/components/cards/image_details_card.dart';
1010
import 'package:piwigo_ng/components/cards/piwigo_chip.dart';
11+
import 'package:piwigo_ng/components/dialogs/confirm_dialog.dart';
1112
import 'package:piwigo_ng/components/fields/app_field.dart';
13+
import 'package:piwigo_ng/components/modals/select_move_or_copy_modal.dart';
14+
import 'package:piwigo_ng/components/modals/piwigo_modal.dart';
1215
import 'package:piwigo_ng/components/modals/select_tags_modal.dart';
1316
import 'package:piwigo_ng/components/sections/form_section.dart';
1417
import 'package:piwigo_ng/models/tag_model.dart';
@@ -22,11 +25,11 @@ import 'package:rounded_loading_button/rounded_loading_button.dart';
2225
import 'package:video_player/video_player.dart';
2326

2427
class UploadPage extends StatefulWidget {
25-
const UploadPage({Key? key, required this.imageList, required this.albumId}) : super(key: key);
28+
const UploadPage({Key? key, required this.imageList, this.albumId}) : super(key: key);
2629

2730
static const String routeName = '/upload';
2831
final List<XFile> imageList;
29-
final int albumId;
32+
final int? albumId;
3033

3134
@override
3235
State<UploadPage> createState() => _UploadGalleryViewPage();
@@ -45,12 +48,38 @@ class _UploadGalleryViewPage extends State<UploadPage> with SingleTickerProvider
4548
List<XFile> _imageList = [];
4649
List<String> _imageExistList = [];
4750
int? _privacyLevel;
51+
late int _albumDestination;
52+
53+
Future<void> _selectAlbum() async {
54+
await showPiwigoModal(
55+
context: context,
56+
builder: (_) => SelectMoveOrCopyModal(
57+
title: appStrings.selectCategory,
58+
subtitle: appStrings.selectCategory_select,
59+
isImage: true,
60+
onSelected: (album) async {
61+
if (!await showConfirmDialog(context,
62+
title: appStrings.selectCategory,
63+
message: appStrings.selectCategory_message(
64+
widget.imageList.length,
65+
album.name,
66+
),
67+
)) return false;
68+
setState(() {
69+
_albumDestination = album.id;
70+
});
71+
return true;
72+
},
73+
),
74+
);
75+
}
4876

4977
@override
5078
void initState() {
5179
_imageList = List.from(widget.imageList);
5280
_authorController = TextEditingController(text: Preferences.getUploadAuthor);
5381
super.initState();
82+
5483
WidgetsBinding.instance.addPostFrameCallback((_) async {
5584
setState(() {
5685
PrivacyLevel.values.forEach((privacy) {
@@ -63,6 +92,11 @@ class _UploadGalleryViewPage extends State<UploadPage> with SingleTickerProvider
6392
));
6493
});
6594
});
95+
if (widget.albumId != null) {
96+
_albumDestination = widget.albumId!;
97+
} else {
98+
_selectAlbum();
99+
}
66100
checkImageExist();
67101
});
68102
}
@@ -126,7 +160,7 @@ class _UploadGalleryViewPage extends State<UploadPage> with SingleTickerProvider
126160
_btnController.start();
127161
List<int> tagIds = _tags.map<int>((tag) => tag.id).toList();
128162
List<XFile> filesToUpload = _imageList.where((e) => !_imageExistList.contains(e.path)).toList();
129-
var result = await uploadPhotos(filesToUpload, widget.albumId, info: {
163+
var result = await uploadPhotos(filesToUpload, _albumDestination, info: {
130164
'name': _titleController.text,
131165
'comment': _descriptionController.text,
132166
'author': _authorController.text,

0 commit comments

Comments
 (0)