|
@@ -1,8 +1,10 @@
|
|
|
+import 'dart:math';
|
|
|
+
|
|
|
import 'package:collection/collection.dart';
|
|
|
import 'package:flutter/material.dart';
|
|
|
import 'package:logging/logging.dart';
|
|
|
+import 'package:modal_bottom_sheet/modal_bottom_sheet.dart';
|
|
|
import 'package:photos/db/files_db.dart';
|
|
|
-import 'package:photos/ente_theme_data.dart';
|
|
|
import 'package:photos/models/collection.dart';
|
|
|
import 'package:photos/models/collection_items.dart';
|
|
|
import 'package:photos/models/file.dart';
|
|
@@ -10,10 +12,15 @@ import 'package:photos/models/selected_files.dart';
|
|
|
import 'package:photos/services/collections_service.dart';
|
|
|
import 'package:photos/services/ignored_files_service.dart';
|
|
|
import 'package:photos/services/remote_sync_service.dart';
|
|
|
-import 'package:photos/ui/common/gradient_button.dart';
|
|
|
+import 'package:photos/theme/colors.dart';
|
|
|
+import 'package:photos/theme/ente_theme.dart';
|
|
|
import 'package:photos/ui/common/loading_widget.dart';
|
|
|
-import 'package:photos/ui/viewer/file/no_thumbnail_widget.dart';
|
|
|
-import 'package:photos/ui/viewer/file/thumbnail_widget.dart';
|
|
|
+import 'package:photos/ui/components/album_list_item_widget.dart';
|
|
|
+import 'package:photos/ui/components/bottom_of_title_bar_widget.dart';
|
|
|
+import 'package:photos/ui/components/button_widget.dart';
|
|
|
+import 'package:photos/ui/components/models/button_type.dart';
|
|
|
+import 'package:photos/ui/components/new_album_list_widget.dart';
|
|
|
+import 'package:photos/ui/components/title_bar_title_widget.dart';
|
|
|
import 'package:photos/ui/viewer/gallery/collection_page.dart';
|
|
|
import 'package:photos/utils/dialog_util.dart';
|
|
|
import 'package:photos/utils/navigation_util.dart';
|
|
@@ -24,197 +31,201 @@ import 'package:receive_sharing_intent/receive_sharing_intent.dart';
|
|
|
enum CollectionActionType { addFiles, moveFiles, restoreFiles, unHide }
|
|
|
|
|
|
String _actionName(CollectionActionType type, bool plural) {
|
|
|
+ bool addTitleSuffix = false;
|
|
|
final titleSuffix = (plural ? "s" : "");
|
|
|
String text = "";
|
|
|
switch (type) {
|
|
|
case CollectionActionType.addFiles:
|
|
|
- text = "Add file";
|
|
|
+ text = "Add item";
|
|
|
+ addTitleSuffix = true;
|
|
|
break;
|
|
|
case CollectionActionType.moveFiles:
|
|
|
- text = "Move file";
|
|
|
+ text = "Move item";
|
|
|
+ addTitleSuffix = true;
|
|
|
break;
|
|
|
case CollectionActionType.restoreFiles:
|
|
|
- text = "Restore file";
|
|
|
+ text = "Restore to album";
|
|
|
break;
|
|
|
case CollectionActionType.unHide:
|
|
|
- text = "Unhide file";
|
|
|
+ text = "Unhide to album";
|
|
|
break;
|
|
|
}
|
|
|
- return text + titleSuffix;
|
|
|
+ return addTitleSuffix ? text + titleSuffix : text;
|
|
|
}
|
|
|
|
|
|
-class CreateCollectionPage extends StatefulWidget {
|
|
|
+void createCollectionSheet(
|
|
|
+ SelectedFiles? selectedFiles,
|
|
|
+ List<SharedMediaFile>? sharedFiles,
|
|
|
+ BuildContext context, {
|
|
|
+ CollectionActionType actionType = CollectionActionType.addFiles,
|
|
|
+ bool showOptionToCreateNewAlbum = true,
|
|
|
+}) {
|
|
|
+ showBarModalBottomSheet(
|
|
|
+ context: context,
|
|
|
+ builder: (context) {
|
|
|
+ return CreateCollectionSheet(
|
|
|
+ selectedFiles: selectedFiles,
|
|
|
+ sharedFiles: sharedFiles,
|
|
|
+ actionType: actionType,
|
|
|
+ showOptionToCreateNewAlbum: showOptionToCreateNewAlbum,
|
|
|
+ );
|
|
|
+ },
|
|
|
+ shape: const RoundedRectangleBorder(
|
|
|
+ side: BorderSide(width: 0),
|
|
|
+ borderRadius: BorderRadius.vertical(
|
|
|
+ top: Radius.circular(5),
|
|
|
+ ),
|
|
|
+ ),
|
|
|
+ topControl: const SizedBox.shrink(),
|
|
|
+ backgroundColor: getEnteColorScheme(context).backgroundElevated,
|
|
|
+ barrierColor: backdropFaintDark,
|
|
|
+ enableDrag: false,
|
|
|
+ );
|
|
|
+}
|
|
|
+
|
|
|
+class CreateCollectionSheet extends StatefulWidget {
|
|
|
final SelectedFiles? selectedFiles;
|
|
|
final List<SharedMediaFile>? sharedFiles;
|
|
|
final CollectionActionType actionType;
|
|
|
-
|
|
|
- const CreateCollectionPage(
|
|
|
- this.selectedFiles,
|
|
|
- this.sharedFiles, {
|
|
|
- Key? key,
|
|
|
- this.actionType = CollectionActionType.addFiles,
|
|
|
- }) : super(key: key);
|
|
|
+ final bool showOptionToCreateNewAlbum;
|
|
|
+ const CreateCollectionSheet({
|
|
|
+ required this.selectedFiles,
|
|
|
+ required this.sharedFiles,
|
|
|
+ required this.actionType,
|
|
|
+ required this.showOptionToCreateNewAlbum,
|
|
|
+ super.key,
|
|
|
+ });
|
|
|
|
|
|
@override
|
|
|
- State<CreateCollectionPage> createState() => _CreateCollectionPageState();
|
|
|
+ State<CreateCollectionSheet> createState() => _CreateCollectionSheetState();
|
|
|
}
|
|
|
|
|
|
-class _CreateCollectionPageState extends State<CreateCollectionPage> {
|
|
|
- final _logger = Logger((_CreateCollectionPageState).toString());
|
|
|
- late String _albumName;
|
|
|
+class _CreateCollectionSheetState extends State<CreateCollectionSheet> {
|
|
|
+ final _logger = Logger((_CreateCollectionSheetState).toString());
|
|
|
|
|
|
@override
|
|
|
Widget build(BuildContext context) {
|
|
|
final filesCount = widget.sharedFiles != null
|
|
|
? widget.sharedFiles!.length
|
|
|
: widget.selectedFiles!.files.length;
|
|
|
- return Scaffold(
|
|
|
- appBar: AppBar(
|
|
|
- title: Text(_actionName(widget.actionType, filesCount > 1)),
|
|
|
- ),
|
|
|
- body: _getBody(context),
|
|
|
- );
|
|
|
- }
|
|
|
-
|
|
|
- Widget _getBody(BuildContext context) {
|
|
|
- return SingleChildScrollView(
|
|
|
- child: Column(
|
|
|
- mainAxisSize: MainAxisSize.min,
|
|
|
- children: [
|
|
|
- Row(
|
|
|
- children: [
|
|
|
- Expanded(
|
|
|
- child: Padding(
|
|
|
- padding: const EdgeInsets.only(
|
|
|
- top: 30,
|
|
|
- bottom: 12,
|
|
|
- left: 40,
|
|
|
- right: 40,
|
|
|
- ),
|
|
|
- child: GradientButton(
|
|
|
- onTap: () async {
|
|
|
- _showNameAlbumDialog();
|
|
|
- },
|
|
|
- iconData: Icons.create_new_folder_outlined,
|
|
|
- text: "To a new album",
|
|
|
- ),
|
|
|
- ),
|
|
|
- ),
|
|
|
- ],
|
|
|
+ return Row(
|
|
|
+ mainAxisAlignment: MainAxisAlignment.center,
|
|
|
+ children: [
|
|
|
+ ConstrainedBox(
|
|
|
+ constraints: BoxConstraints(
|
|
|
+ maxWidth: min(428, MediaQuery.of(context).size.width),
|
|
|
),
|
|
|
- const Padding(
|
|
|
- padding: EdgeInsets.fromLTRB(40, 24, 40, 20),
|
|
|
- child: Align(
|
|
|
- alignment: Alignment.centerLeft,
|
|
|
- child: Text(
|
|
|
- "To an existing album",
|
|
|
- style: TextStyle(
|
|
|
- fontWeight: FontWeight.bold,
|
|
|
+ child: Padding(
|
|
|
+ padding: const EdgeInsets.fromLTRB(0, 32, 0, 8),
|
|
|
+ child: Column(
|
|
|
+ mainAxisSize: MainAxisSize.min,
|
|
|
+ children: [
|
|
|
+ BottomOfTitleBarWidget(
|
|
|
+ title: TitleBarTitleWidget(
|
|
|
+ title: _actionName(widget.actionType, filesCount > 1),
|
|
|
+ ),
|
|
|
+ caption: "Create or select album",
|
|
|
),
|
|
|
- ),
|
|
|
- ),
|
|
|
- ),
|
|
|
- Padding(
|
|
|
- padding: const EdgeInsets.fromLTRB(20, 4, 20, 0),
|
|
|
- child: _getExistingCollectionsWidget(),
|
|
|
- ),
|
|
|
- ],
|
|
|
- ),
|
|
|
- );
|
|
|
- }
|
|
|
-
|
|
|
- Widget _getExistingCollectionsWidget() {
|
|
|
- return FutureBuilder<List<CollectionWithThumbnail>>(
|
|
|
- future: _getCollectionsWithThumbnail(),
|
|
|
- builder: (context, snapshot) {
|
|
|
- if (snapshot.hasError) {
|
|
|
- return Text(snapshot.error.toString());
|
|
|
- } else if (snapshot.hasData) {
|
|
|
- return ListView.builder(
|
|
|
- itemBuilder: (context, index) {
|
|
|
- return _buildCollectionItem(snapshot.data![index]);
|
|
|
- },
|
|
|
- itemCount: snapshot.data!.length,
|
|
|
- shrinkWrap: true,
|
|
|
- physics: const NeverScrollableScrollPhysics(),
|
|
|
- );
|
|
|
- } else {
|
|
|
- return const EnteLoadingWidget();
|
|
|
- }
|
|
|
- },
|
|
|
- );
|
|
|
- }
|
|
|
-
|
|
|
- Widget _buildCollectionItem(CollectionWithThumbnail item) {
|
|
|
- return Container(
|
|
|
- padding: const EdgeInsets.only(left: 24, bottom: 16),
|
|
|
- child: GestureDetector(
|
|
|
- behavior: HitTestBehavior.translucent,
|
|
|
- child: Row(
|
|
|
- children: <Widget>[
|
|
|
- ClipRRect(
|
|
|
- borderRadius: BorderRadius.circular(2.0),
|
|
|
- child: SizedBox(
|
|
|
- height: 64,
|
|
|
- width: 64,
|
|
|
- key: Key("collection_item:" + (item.thumbnail?.tag ?? "")),
|
|
|
- child: item.thumbnail != null
|
|
|
- ? ThumbnailWidget(
|
|
|
- item.thumbnail,
|
|
|
- showFavForAlbumOnly: true,
|
|
|
+ Flexible(
|
|
|
+ child: Column(
|
|
|
+ mainAxisSize: MainAxisSize.min,
|
|
|
+ children: [
|
|
|
+ Flexible(
|
|
|
+ child: Padding(
|
|
|
+ padding: const EdgeInsets.fromLTRB(16, 24, 4, 0),
|
|
|
+ child: Scrollbar(
|
|
|
+ radius: const Radius.circular(2),
|
|
|
+ child: Padding(
|
|
|
+ padding: const EdgeInsets.only(right: 12),
|
|
|
+ child: FutureBuilder(
|
|
|
+ future: _getCollectionsWithThumbnail(),
|
|
|
+ builder: (context, snapshot) {
|
|
|
+ if (snapshot.hasError) {
|
|
|
+ //Need to show an error on the UI here
|
|
|
+ return const SizedBox.shrink();
|
|
|
+ } else if (snapshot.hasData) {
|
|
|
+ final collectionsWithThumbnail = snapshot
|
|
|
+ .data as List<CollectionWithThumbnail>;
|
|
|
+ return ListView.separated(
|
|
|
+ itemBuilder: (context, index) {
|
|
|
+ if (index == 0 &&
|
|
|
+ widget.showOptionToCreateNewAlbum) {
|
|
|
+ return GestureDetector(
|
|
|
+ onTap: () {
|
|
|
+ _showNameAlbumDialog();
|
|
|
+ },
|
|
|
+ behavior: HitTestBehavior.opaque,
|
|
|
+ child:
|
|
|
+ const NewAlbumListItemWidget(),
|
|
|
+ );
|
|
|
+ }
|
|
|
+ final item = collectionsWithThumbnail[
|
|
|
+ index -
|
|
|
+ (widget.showOptionToCreateNewAlbum
|
|
|
+ ? 1
|
|
|
+ : 0)];
|
|
|
+ return GestureDetector(
|
|
|
+ behavior: HitTestBehavior.opaque,
|
|
|
+ onTap: () =>
|
|
|
+ _albumListItemOnTap(item),
|
|
|
+ child: AlbumListItemWidget(
|
|
|
+ item,
|
|
|
+ ),
|
|
|
+ );
|
|
|
+ },
|
|
|
+ separatorBuilder: (context, index) =>
|
|
|
+ const SizedBox(
|
|
|
+ height: 8,
|
|
|
+ ),
|
|
|
+ itemCount:
|
|
|
+ collectionsWithThumbnail.length +
|
|
|
+ (widget.showOptionToCreateNewAlbum
|
|
|
+ ? 1
|
|
|
+ : 0),
|
|
|
+ shrinkWrap: true,
|
|
|
+ physics: const BouncingScrollPhysics(),
|
|
|
+ );
|
|
|
+ } else {
|
|
|
+ return const EnteLoadingWidget();
|
|
|
+ }
|
|
|
+ },
|
|
|
+ ),
|
|
|
+ ),
|
|
|
+ ),
|
|
|
+ ),
|
|
|
+ ),
|
|
|
+ SafeArea(
|
|
|
+ child: Container(
|
|
|
+ //inner stroke of 1pt + 15 pts of top padding = 16 pts
|
|
|
+ padding: const EdgeInsets.fromLTRB(16, 15, 16, 8),
|
|
|
+ decoration: BoxDecoration(
|
|
|
+ border: Border(
|
|
|
+ top: BorderSide(
|
|
|
+ color: getEnteColorScheme(context).strokeFaint,
|
|
|
+ ),
|
|
|
+ ),
|
|
|
+ ),
|
|
|
+ child: const ButtonWidget(
|
|
|
+ buttonType: ButtonType.secondary,
|
|
|
+ buttonAction: ButtonAction.cancel,
|
|
|
+ isInAlert: true,
|
|
|
+ labelText: "Cancel",
|
|
|
+ ),
|
|
|
+ ),
|
|
|
)
|
|
|
- : const NoThumbnailWidget(),
|
|
|
- ),
|
|
|
- ),
|
|
|
- const Padding(padding: EdgeInsets.all(8)),
|
|
|
- Expanded(
|
|
|
- child: Text(
|
|
|
- item.collection.name!,
|
|
|
- style: const TextStyle(
|
|
|
- fontSize: 16,
|
|
|
+ ],
|
|
|
+ ),
|
|
|
),
|
|
|
- ),
|
|
|
+ ],
|
|
|
),
|
|
|
- ],
|
|
|
+ ),
|
|
|
),
|
|
|
- onTap: () async {
|
|
|
- if (await _runCollectionAction(item.collection.id)) {
|
|
|
- showShortToast(
|
|
|
- context,
|
|
|
- widget.actionType == CollectionActionType.addFiles
|
|
|
- ? "Added successfully to " + item.collection.name!
|
|
|
- : "Moved successfully to " + item.collection.name!,
|
|
|
- );
|
|
|
- _navigateToCollection(item.collection);
|
|
|
- }
|
|
|
- },
|
|
|
- ),
|
|
|
+ ],
|
|
|
);
|
|
|
}
|
|
|
|
|
|
- Future<List<CollectionWithThumbnail>> _getCollectionsWithThumbnail() async {
|
|
|
- final List<CollectionWithThumbnail> collectionsWithThumbnail =
|
|
|
- await CollectionsService.instance.getCollectionsWithThumbnails(
|
|
|
- // in collections where user is a collaborator, only addTo and remove
|
|
|
- // action can to be performed
|
|
|
- includeCollabCollections:
|
|
|
- widget.actionType == CollectionActionType.addFiles,
|
|
|
- );
|
|
|
- collectionsWithThumbnail.removeWhere(
|
|
|
- (element) => (element.collection.type == CollectionType.favorites ||
|
|
|
- element.collection.type == CollectionType.uncategorized ||
|
|
|
- element.collection.isSharedFilesCollection()),
|
|
|
- );
|
|
|
- collectionsWithThumbnail.sort((first, second) {
|
|
|
- return compareAsciiLowerCaseNatural(
|
|
|
- first.collection.name ?? "",
|
|
|
- second.collection.name ?? "",
|
|
|
- );
|
|
|
- });
|
|
|
- return collectionsWithThumbnail;
|
|
|
- }
|
|
|
-
|
|
|
void _showNameAlbumDialog() async {
|
|
|
+ String? albumName;
|
|
|
final AlertDialog alert = AlertDialog(
|
|
|
title: const Text("Album title"),
|
|
|
content: TextFormField(
|
|
@@ -223,9 +234,7 @@ class _CreateCollectionPageState extends State<CreateCollectionPage> {
|
|
|
contentPadding: EdgeInsets.all(8),
|
|
|
),
|
|
|
onChanged: (value) {
|
|
|
- setState(() {
|
|
|
- _albumName = value;
|
|
|
- });
|
|
|
+ albumName = value;
|
|
|
},
|
|
|
autofocus: true,
|
|
|
keyboardType: TextInputType.text,
|
|
@@ -236,26 +245,28 @@ class _CreateCollectionPageState extends State<CreateCollectionPage> {
|
|
|
child: Text(
|
|
|
"Ok",
|
|
|
style: TextStyle(
|
|
|
- color: Theme.of(context).colorScheme.greenAlternative,
|
|
|
+ color: getEnteColorScheme(context).primary500,
|
|
|
),
|
|
|
),
|
|
|
onPressed: () async {
|
|
|
- Navigator.of(context, rootNavigator: true).pop('dialog');
|
|
|
- final collection = await _createAlbum(_albumName);
|
|
|
- if (collection != null) {
|
|
|
- if (await _runCollectionAction(collection.id)) {
|
|
|
- if (widget.actionType == CollectionActionType.restoreFiles) {
|
|
|
- showShortToast(
|
|
|
- context,
|
|
|
- 'Restored files to album ' + _albumName,
|
|
|
- );
|
|
|
- } else {
|
|
|
- showShortToast(
|
|
|
- context,
|
|
|
- "Album '" + _albumName + "' created.",
|
|
|
- );
|
|
|
+ if (albumName != null && albumName!.isNotEmpty) {
|
|
|
+ Navigator.of(context, rootNavigator: true).pop('dialog');
|
|
|
+ final collection = await _createAlbum(albumName!);
|
|
|
+ if (collection != null) {
|
|
|
+ if (await _runCollectionAction(collection.id)) {
|
|
|
+ if (widget.actionType == CollectionActionType.restoreFiles) {
|
|
|
+ showShortToast(
|
|
|
+ context,
|
|
|
+ 'Restored files to album ' + albumName!,
|
|
|
+ );
|
|
|
+ } else {
|
|
|
+ showShortToast(
|
|
|
+ context,
|
|
|
+ "Album '" + albumName! + "' created.",
|
|
|
+ );
|
|
|
+ }
|
|
|
+ _navigateToCollection(collection);
|
|
|
}
|
|
|
- _navigateToCollection(collection);
|
|
|
}
|
|
|
}
|
|
|
},
|
|
@@ -271,6 +282,60 @@ class _CreateCollectionPageState extends State<CreateCollectionPage> {
|
|
|
);
|
|
|
}
|
|
|
|
|
|
+ Future<Collection?> _createAlbum(String albumName) async {
|
|
|
+ Collection? collection;
|
|
|
+ final dialog = createProgressDialog(context, "Creating album...");
|
|
|
+ await dialog.show();
|
|
|
+ try {
|
|
|
+ collection = await CollectionsService.instance.createAlbum(albumName);
|
|
|
+ } catch (e, s) {
|
|
|
+ _logger.severe(e, s);
|
|
|
+ await dialog.hide();
|
|
|
+ showGenericErrorDialog(context: context);
|
|
|
+ } finally {
|
|
|
+ await dialog.hide();
|
|
|
+ }
|
|
|
+ return collection;
|
|
|
+ }
|
|
|
+
|
|
|
+ Future<void> _albumListItemOnTap(CollectionWithThumbnail item) async {
|
|
|
+ if (await _runCollectionAction(
|
|
|
+ item.collection.id,
|
|
|
+ )) {
|
|
|
+ showShortToast(
|
|
|
+ context,
|
|
|
+ widget.actionType == CollectionActionType.addFiles
|
|
|
+ ? "Added successfully to " + item.collection.name!
|
|
|
+ : "Moved successfully to " + item.collection.name!,
|
|
|
+ );
|
|
|
+ _navigateToCollection(
|
|
|
+ item.collection,
|
|
|
+ );
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ Future<List<CollectionWithThumbnail>> _getCollectionsWithThumbnail() async {
|
|
|
+ final List<CollectionWithThumbnail> collectionsWithThumbnail =
|
|
|
+ await CollectionsService.instance.getCollectionsWithThumbnails(
|
|
|
+ // in collections where user is a collaborator, only addTo and remove
|
|
|
+ // action can to be performed
|
|
|
+ includeCollabCollections:
|
|
|
+ widget.actionType == CollectionActionType.addFiles,
|
|
|
+ );
|
|
|
+ collectionsWithThumbnail.removeWhere(
|
|
|
+ (element) => (element.collection.type == CollectionType.favorites ||
|
|
|
+ element.collection.type == CollectionType.uncategorized ||
|
|
|
+ element.collection.isSharedFilesCollection()),
|
|
|
+ );
|
|
|
+ collectionsWithThumbnail.sort((first, second) {
|
|
|
+ return compareAsciiLowerCaseNatural(
|
|
|
+ first.collection.name ?? "",
|
|
|
+ second.collection.name ?? "",
|
|
|
+ );
|
|
|
+ });
|
|
|
+ return collectionsWithThumbnail;
|
|
|
+ }
|
|
|
+
|
|
|
void _navigateToCollection(Collection collection) {
|
|
|
Navigator.pop(context);
|
|
|
routeToPage(
|
|
@@ -294,59 +359,6 @@ class _CreateCollectionPageState extends State<CreateCollectionPage> {
|
|
|
}
|
|
|
}
|
|
|
|
|
|
- Future<bool> _moveFilesToCollection(int toCollectionID) async {
|
|
|
- final String message = widget.actionType == CollectionActionType.moveFiles
|
|
|
- ? "Moving files to album..."
|
|
|
- : "Unhiding files to album";
|
|
|
- final dialog = createProgressDialog(context, message);
|
|
|
- await dialog.show();
|
|
|
- try {
|
|
|
- final int fromCollectionID =
|
|
|
- widget.selectedFiles!.files.first.collectionID!;
|
|
|
- await CollectionsService.instance.move(
|
|
|
- toCollectionID,
|
|
|
- fromCollectionID,
|
|
|
- widget.selectedFiles!.files.toList(),
|
|
|
- );
|
|
|
- await dialog.hide();
|
|
|
- RemoteSyncService.instance.sync(silently: true);
|
|
|
- widget.selectedFiles?.clearAll();
|
|
|
-
|
|
|
- return true;
|
|
|
- } on AssertionError catch (e) {
|
|
|
- await dialog.hide();
|
|
|
- showErrorDialog(context, "Oops", e.message as String?);
|
|
|
- return false;
|
|
|
- } catch (e, s) {
|
|
|
- _logger.severe("Could not move to album", e, s);
|
|
|
- await dialog.hide();
|
|
|
- showGenericErrorDialog(context: context);
|
|
|
- return false;
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- Future<bool> _restoreFilesToCollection(int toCollectionID) async {
|
|
|
- final dialog = createProgressDialog(context, "Restoring files...");
|
|
|
- await dialog.show();
|
|
|
- try {
|
|
|
- await CollectionsService.instance
|
|
|
- .restore(toCollectionID, widget.selectedFiles!.files.toList());
|
|
|
- RemoteSyncService.instance.sync(silently: true);
|
|
|
- widget.selectedFiles?.clearAll();
|
|
|
- await dialog.hide();
|
|
|
- return true;
|
|
|
- } on AssertionError catch (e) {
|
|
|
- await dialog.hide();
|
|
|
- showErrorDialog(context, "Oops", e.message as String?);
|
|
|
- return false;
|
|
|
- } catch (e, s) {
|
|
|
- _logger.severe("Could not move to album", e, s);
|
|
|
- await dialog.hide();
|
|
|
- showGenericErrorDialog(context: context);
|
|
|
- return false;
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
Future<bool> _addToCollection(int collectionID) async {
|
|
|
final dialog = createProgressDialog(context, "Uploading files to album...");
|
|
|
await dialog.show();
|
|
@@ -407,19 +419,56 @@ class _CreateCollectionPageState extends State<CreateCollectionPage> {
|
|
|
return false;
|
|
|
}
|
|
|
|
|
|
- Future<Collection?> _createAlbum(String albumName) async {
|
|
|
- Collection? collection;
|
|
|
- final dialog = createProgressDialog(context, "Creating album...");
|
|
|
+ Future<bool> _moveFilesToCollection(int toCollectionID) async {
|
|
|
+ final String message = widget.actionType == CollectionActionType.moveFiles
|
|
|
+ ? "Moving files to album..."
|
|
|
+ : "Unhiding files to album";
|
|
|
+ final dialog = createProgressDialog(context, message);
|
|
|
await dialog.show();
|
|
|
try {
|
|
|
- collection = await CollectionsService.instance.createAlbum(albumName);
|
|
|
+ final int fromCollectionID =
|
|
|
+ widget.selectedFiles!.files.first.collectionID!;
|
|
|
+ await CollectionsService.instance.move(
|
|
|
+ toCollectionID,
|
|
|
+ fromCollectionID,
|
|
|
+ widget.selectedFiles!.files.toList(),
|
|
|
+ );
|
|
|
+ await dialog.hide();
|
|
|
+ RemoteSyncService.instance.sync(silently: true);
|
|
|
+ widget.selectedFiles?.clearAll();
|
|
|
+
|
|
|
+ return true;
|
|
|
+ } on AssertionError catch (e) {
|
|
|
+ await dialog.hide();
|
|
|
+ showErrorDialog(context, "Oops", e.message as String?);
|
|
|
+ return false;
|
|
|
} catch (e, s) {
|
|
|
- _logger.severe(e, s);
|
|
|
+ _logger.severe("Could not move to album", e, s);
|
|
|
await dialog.hide();
|
|
|
showGenericErrorDialog(context: context);
|
|
|
- } finally {
|
|
|
+ return false;
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ Future<bool> _restoreFilesToCollection(int toCollectionID) async {
|
|
|
+ final dialog = createProgressDialog(context, "Restoring files...");
|
|
|
+ await dialog.show();
|
|
|
+ try {
|
|
|
+ await CollectionsService.instance
|
|
|
+ .restore(toCollectionID, widget.selectedFiles!.files.toList());
|
|
|
+ RemoteSyncService.instance.sync(silently: true);
|
|
|
+ widget.selectedFiles?.clearAll();
|
|
|
+ await dialog.hide();
|
|
|
+ return true;
|
|
|
+ } on AssertionError catch (e) {
|
|
|
+ await dialog.hide();
|
|
|
+ showErrorDialog(context, "Oops", e.message as String?);
|
|
|
+ return false;
|
|
|
+ } catch (e, s) {
|
|
|
+ _logger.severe("Could not move to album", e, s);
|
|
|
await dialog.hide();
|
|
|
+ showGenericErrorDialog(context: context);
|
|
|
+ return false;
|
|
|
}
|
|
|
- return collection;
|
|
|
}
|
|
|
}
|