2023-02-15 01:50:51 +00:00
|
|
|
import "dart:async";
|
2023-01-20 11:22:46 +00:00
|
|
|
import 'dart:math';
|
|
|
|
|
2022-09-16 04:45:32 +00:00
|
|
|
import 'package:collection/collection.dart';
|
2020-10-28 12:03:28 +00:00
|
|
|
import 'package:flutter/material.dart';
|
2023-01-19 10:53:23 +00:00
|
|
|
import 'package:modal_bottom_sheet/modal_bottom_sheet.dart';
|
2023-03-07 14:04:35 +00:00
|
|
|
import "package:photos/core/configuration.dart";
|
2023-04-07 04:27:53 +00:00
|
|
|
import "package:photos/generated/l10n.dart";
|
2020-10-28 12:03:28 +00:00
|
|
|
import 'package:photos/models/collection.dart';
|
2020-10-29 00:30:02 +00:00
|
|
|
import 'package:photos/models/collection_items.dart';
|
|
|
|
import 'package:photos/models/selected_files.dart';
|
2020-10-28 12:03:28 +00:00
|
|
|
import 'package:photos/services/collections_service.dart';
|
2023-01-20 05:28:10 +00:00
|
|
|
import 'package:photos/theme/colors.dart';
|
|
|
|
import 'package:photos/theme/ente_theme.dart';
|
2023-03-07 14:04:35 +00:00
|
|
|
import "package:photos/ui/collections_list_widget.dart";
|
2022-07-01 14:18:05 +00:00
|
|
|
import 'package:photos/ui/common/loading_widget.dart';
|
2023-01-19 10:53:23 +00:00
|
|
|
import 'package:photos/ui/components/bottom_of_title_bar_widget.dart';
|
2023-03-10 08:08:51 +00:00
|
|
|
import 'package:photos/ui/components/buttons/button_widget.dart';
|
2023-01-21 02:11:59 +00:00
|
|
|
import 'package:photos/ui/components/models/button_type.dart';
|
2023-03-07 11:56:21 +00:00
|
|
|
import "package:photos/ui/components/text_input_widget.dart";
|
2023-01-19 10:53:23 +00:00
|
|
|
import 'package:photos/ui/components/title_bar_title_widget.dart';
|
2021-07-22 10:28:07 +00:00
|
|
|
import 'package:receive_sharing_intent/receive_sharing_intent.dart';
|
2020-10-28 12:03:28 +00:00
|
|
|
|
2023-02-15 01:50:51 +00:00
|
|
|
enum CollectionActionType {
|
|
|
|
addFiles,
|
|
|
|
moveFiles,
|
|
|
|
restoreFiles,
|
|
|
|
unHide,
|
2023-02-15 06:31:07 +00:00
|
|
|
shareCollection,
|
|
|
|
collectPhotos,
|
2023-02-15 01:50:51 +00:00
|
|
|
}
|
2021-10-13 17:22:17 +00:00
|
|
|
|
2023-04-07 04:27:53 +00:00
|
|
|
String _actionName(
|
|
|
|
BuildContext context,
|
|
|
|
CollectionActionType type,
|
|
|
|
int fileCount,
|
|
|
|
) {
|
2021-10-13 17:22:17 +00:00
|
|
|
String text = "";
|
|
|
|
switch (type) {
|
|
|
|
case CollectionActionType.addFiles:
|
2023-04-07 04:27:53 +00:00
|
|
|
text = S.of(context).addItem(fileCount);
|
2021-10-13 17:22:17 +00:00
|
|
|
break;
|
|
|
|
case CollectionActionType.moveFiles:
|
2023-04-07 04:27:53 +00:00
|
|
|
text = S.of(context).moveItem(fileCount);
|
2021-10-13 17:22:17 +00:00
|
|
|
break;
|
|
|
|
case CollectionActionType.restoreFiles:
|
2023-04-07 04:27:53 +00:00
|
|
|
text = S.of(context).restoreToAlbum;
|
2021-10-13 17:22:17 +00:00
|
|
|
break;
|
2022-10-27 07:23:45 +00:00
|
|
|
case CollectionActionType.unHide:
|
2023-04-07 04:27:53 +00:00
|
|
|
text = S.of(context).unhideToAlbum;
|
2022-10-27 07:23:45 +00:00
|
|
|
break;
|
2023-02-15 01:50:51 +00:00
|
|
|
case CollectionActionType.shareCollection:
|
2023-04-07 04:27:53 +00:00
|
|
|
text = S.of(context).share;
|
2023-02-15 06:31:07 +00:00
|
|
|
break;
|
|
|
|
case CollectionActionType.collectPhotos:
|
2023-04-07 04:27:53 +00:00
|
|
|
text = S.of(context).share;
|
2023-02-15 01:50:51 +00:00
|
|
|
break;
|
2021-10-13 17:22:17 +00:00
|
|
|
}
|
2023-04-07 04:27:53 +00:00
|
|
|
return text;
|
2021-10-13 17:22:17 +00:00
|
|
|
}
|
2021-09-13 03:57:57 +00:00
|
|
|
|
2023-02-14 10:13:34 +00:00
|
|
|
void showCollectionActionSheet(
|
|
|
|
BuildContext context, {
|
2023-01-19 10:53:23 +00:00
|
|
|
SelectedFiles? selectedFiles,
|
|
|
|
List<SharedMediaFile>? sharedFiles,
|
|
|
|
CollectionActionType actionType = CollectionActionType.addFiles,
|
2023-01-24 06:35:37 +00:00
|
|
|
bool showOptionToCreateNewAlbum = true,
|
2023-01-19 10:53:23 +00:00
|
|
|
}) {
|
|
|
|
showBarModalBottomSheet(
|
|
|
|
context: context,
|
|
|
|
builder: (context) {
|
2023-02-14 10:13:34 +00:00
|
|
|
return CollectionActionSheet(
|
2023-01-19 10:53:23 +00:00
|
|
|
selectedFiles: selectedFiles,
|
|
|
|
sharedFiles: sharedFiles,
|
|
|
|
actionType: actionType,
|
2023-01-24 06:35:37 +00:00
|
|
|
showOptionToCreateNewAlbum: showOptionToCreateNewAlbum,
|
2023-01-19 10:53:23 +00:00
|
|
|
);
|
|
|
|
},
|
|
|
|
shape: const RoundedRectangleBorder(
|
|
|
|
side: BorderSide(width: 0),
|
2023-01-20 11:54:14 +00:00
|
|
|
borderRadius: BorderRadius.vertical(
|
|
|
|
top: Radius.circular(5),
|
2023-01-19 10:53:23 +00:00
|
|
|
),
|
|
|
|
),
|
|
|
|
topControl: const SizedBox.shrink(),
|
2023-01-20 05:28:10 +00:00
|
|
|
backgroundColor: getEnteColorScheme(context).backgroundElevated,
|
|
|
|
barrierColor: backdropFaintDark,
|
2023-01-21 02:11:59 +00:00
|
|
|
enableDrag: false,
|
2023-01-19 10:53:23 +00:00
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2023-02-14 10:13:34 +00:00
|
|
|
class CollectionActionSheet extends StatefulWidget {
|
2022-12-30 12:10:17 +00:00
|
|
|
final SelectedFiles? selectedFiles;
|
|
|
|
final List<SharedMediaFile>? sharedFiles;
|
2021-09-13 03:57:57 +00:00
|
|
|
final CollectionActionType actionType;
|
2023-01-24 06:35:37 +00:00
|
|
|
final bool showOptionToCreateNewAlbum;
|
2023-02-14 10:13:34 +00:00
|
|
|
const CollectionActionSheet({
|
2023-01-19 10:53:23 +00:00
|
|
|
required this.selectedFiles,
|
|
|
|
required this.sharedFiles,
|
|
|
|
required this.actionType,
|
2023-01-24 06:35:37 +00:00
|
|
|
required this.showOptionToCreateNewAlbum,
|
2023-01-19 10:53:23 +00:00
|
|
|
super.key,
|
|
|
|
});
|
2020-10-28 12:03:28 +00:00
|
|
|
|
|
|
|
@override
|
2023-02-14 10:13:34 +00:00
|
|
|
State<CollectionActionSheet> createState() => _CollectionActionSheetState();
|
2020-10-28 12:03:28 +00:00
|
|
|
}
|
|
|
|
|
2023-02-14 10:13:34 +00:00
|
|
|
class _CollectionActionSheetState extends State<CollectionActionSheet> {
|
2023-03-07 12:43:29 +00:00
|
|
|
static const int cancelButtonSize = 80;
|
2023-03-07 11:56:21 +00:00
|
|
|
String _searchQuery = "";
|
2020-10-28 12:03:28 +00:00
|
|
|
|
|
|
|
@override
|
|
|
|
Widget build(BuildContext context) {
|
2021-09-24 07:49:28 +00:00
|
|
|
final filesCount = widget.sharedFiles != null
|
2022-12-30 12:10:17 +00:00
|
|
|
? widget.sharedFiles!.length
|
2023-02-15 01:50:51 +00:00
|
|
|
: widget.selectedFiles?.files.length ?? 0;
|
2023-03-07 12:43:29 +00:00
|
|
|
final bottomInset = MediaQuery.of(context).viewInsets.bottom;
|
|
|
|
final isKeyboardUp = bottomInset > 100;
|
|
|
|
return Padding(
|
|
|
|
padding: EdgeInsets.only(
|
|
|
|
bottom: isKeyboardUp ? bottomInset - cancelButtonSize : 0,
|
|
|
|
),
|
|
|
|
child: Row(
|
|
|
|
mainAxisAlignment: MainAxisAlignment.center,
|
|
|
|
children: [
|
|
|
|
ConstrainedBox(
|
|
|
|
constraints: BoxConstraints(
|
|
|
|
maxWidth: min(428, MediaQuery.of(context).size.width),
|
|
|
|
),
|
|
|
|
child: Padding(
|
|
|
|
padding: const EdgeInsets.fromLTRB(0, 32, 0, 8),
|
|
|
|
child: Column(
|
|
|
|
mainAxisSize: MainAxisSize.max,
|
|
|
|
children: [
|
|
|
|
Expanded(
|
|
|
|
child: Column(
|
|
|
|
children: [
|
|
|
|
BottomOfTitleBarWidget(
|
|
|
|
title: TitleBarTitleWidget(
|
2023-04-07 04:27:53 +00:00
|
|
|
title: _actionName(
|
|
|
|
context, widget.actionType, filesCount),
|
2023-03-07 12:43:29 +00:00
|
|
|
),
|
|
|
|
caption: widget.showOptionToCreateNewAlbum
|
2023-04-07 04:27:53 +00:00
|
|
|
? S.of(context).createOrSelectAlbum
|
|
|
|
: S.of(context).selectAlbum,
|
2023-03-07 11:56:21 +00:00
|
|
|
),
|
2023-03-07 12:43:29 +00:00
|
|
|
Padding(
|
|
|
|
padding: const EdgeInsets.only(
|
2023-03-07 12:43:41 +00:00
|
|
|
top: 16,
|
|
|
|
left: 16,
|
|
|
|
right: 16,
|
|
|
|
),
|
2023-03-07 12:43:29 +00:00
|
|
|
child: TextInputWidget(
|
2023-04-07 04:27:53 +00:00
|
|
|
hintText: S.of(context).searchByAlbumNameHint,
|
2023-03-07 12:43:29 +00:00
|
|
|
prefixIcon: Icons.search_rounded,
|
|
|
|
onChange: (value) {
|
2023-03-14 12:17:08 +00:00
|
|
|
setState(() {
|
|
|
|
_searchQuery = value;
|
|
|
|
});
|
2023-03-07 12:43:29 +00:00
|
|
|
},
|
2023-03-24 20:14:07 +00:00
|
|
|
isClearable: true,
|
|
|
|
shouldUnfocusOnClearOrSubmit: true,
|
2023-03-20 08:30:19 +00:00
|
|
|
borderRadius: 2,
|
2023-03-07 12:43:29 +00:00
|
|
|
),
|
2023-03-07 11:56:21 +00:00
|
|
|
),
|
2023-03-07 12:43:29 +00:00
|
|
|
_getCollectionItems(filesCount),
|
|
|
|
],
|
|
|
|
),
|
2023-01-19 10:53:23 +00:00
|
|
|
),
|
2023-03-07 12:43:29 +00:00
|
|
|
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,
|
|
|
|
),
|
2023-03-07 11:56:21 +00:00
|
|
|
),
|
|
|
|
),
|
2023-04-07 04:27:53 +00:00
|
|
|
child: ButtonWidget(
|
2023-03-07 12:43:29 +00:00
|
|
|
buttonType: ButtonType.secondary,
|
|
|
|
buttonAction: ButtonAction.cancel,
|
|
|
|
isInAlert: true,
|
2023-04-07 04:27:53 +00:00
|
|
|
labelText: S.of(context).cancel,
|
2023-03-07 12:43:29 +00:00
|
|
|
),
|
2023-03-07 11:56:21 +00:00
|
|
|
),
|
2023-03-07 12:43:29 +00:00
|
|
|
)
|
|
|
|
],
|
|
|
|
),
|
2020-10-29 00:30:02 +00:00
|
|
|
),
|
2023-01-19 10:53:23 +00:00
|
|
|
),
|
2023-03-07 12:43:29 +00:00
|
|
|
],
|
|
|
|
),
|
2020-10-29 00:30:02 +00:00
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2023-03-07 12:26:01 +00:00
|
|
|
Flexible _getCollectionItems(int filesCount) {
|
|
|
|
return Flexible(
|
|
|
|
child: Padding(
|
|
|
|
padding: const EdgeInsets.fromLTRB(16, 24, 4, 0),
|
2023-03-10 07:41:39 +00:00
|
|
|
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>;
|
|
|
|
_removeIncomingCollections(collectionsWithThumbnail);
|
|
|
|
final shouldShowCreateAlbum =
|
|
|
|
widget.showOptionToCreateNewAlbum && _searchQuery.isEmpty;
|
|
|
|
final searchResults = _searchQuery.isNotEmpty
|
|
|
|
? collectionsWithThumbnail
|
|
|
|
.where(
|
|
|
|
(element) => element.collection.name!
|
|
|
|
.toLowerCase()
|
|
|
|
.contains(_searchQuery),
|
|
|
|
)
|
|
|
|
.toList()
|
|
|
|
: collectionsWithThumbnail;
|
|
|
|
return Scrollbar(
|
|
|
|
thumbVisibility: true,
|
|
|
|
radius: const Radius.circular(2),
|
|
|
|
child: Padding(
|
|
|
|
padding: const EdgeInsets.only(right: 12),
|
|
|
|
child: CollectionsListWidget(
|
2023-03-07 14:04:35 +00:00
|
|
|
searchResults,
|
|
|
|
widget.actionType,
|
|
|
|
widget.selectedFiles,
|
|
|
|
widget.sharedFiles,
|
|
|
|
_searchQuery,
|
|
|
|
shouldShowCreateAlbum,
|
2023-03-10 07:41:39 +00:00
|
|
|
),
|
|
|
|
),
|
|
|
|
);
|
|
|
|
} else {
|
|
|
|
return const EnteLoadingWidget();
|
|
|
|
}
|
|
|
|
},
|
2023-03-07 12:26:01 +00:00
|
|
|
),
|
|
|
|
),
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2023-01-19 10:53:23 +00:00
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
2023-03-07 14:04:35 +00:00
|
|
|
void _removeIncomingCollections(List<CollectionWithThumbnail> items) {
|
2023-02-15 07:31:26 +00:00
|
|
|
if (widget.actionType == CollectionActionType.shareCollection ||
|
|
|
|
widget.actionType == CollectionActionType.collectPhotos) {
|
|
|
|
final ownerID = Configuration.instance.getUserID();
|
|
|
|
items.removeWhere(
|
|
|
|
(e) => !e.collection.isOwner(ownerID!),
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|
2020-10-28 12:03:28 +00:00
|
|
|
}
|