2023-06-22 10:51:56 +00:00
|
|
|
import "dart:math";
|
|
|
|
|
|
|
|
import "package:flutter/material.dart";
|
|
|
|
import "package:modal_bottom_sheet/modal_bottom_sheet.dart";
|
2023-06-27 09:15:25 +00:00
|
|
|
import "package:photos/core/configuration.dart";
|
2023-06-22 10:51:56 +00:00
|
|
|
import "package:photos/db/files_db.dart";
|
|
|
|
import "package:photos/generated/l10n.dart";
|
|
|
|
import "package:photos/models/collection.dart";
|
|
|
|
import "package:photos/models/file.dart";
|
|
|
|
import "package:photos/models/selected_files.dart";
|
2023-06-27 09:15:25 +00:00
|
|
|
import "package:photos/services/collections_service.dart";
|
|
|
|
import "package:photos/services/filter/db_filters.dart";
|
2023-06-22 10:51:56 +00:00
|
|
|
import "package:photos/theme/colors.dart";
|
|
|
|
import "package:photos/theme/ente_theme.dart";
|
|
|
|
import "package:photos/ui/components/bottom_of_title_bar_widget.dart";
|
|
|
|
import "package:photos/ui/components/buttons/button_widget.dart";
|
|
|
|
import "package:photos/ui/components/models/button_type.dart";
|
|
|
|
import "package:photos/ui/components/title_bar_title_widget.dart";
|
|
|
|
import "package:photos/ui/viewer/gallery/gallery.dart";
|
|
|
|
|
2023-06-27 09:15:25 +00:00
|
|
|
Future<List<File>?> showAddPhotosSheet(
|
2023-06-22 10:51:56 +00:00
|
|
|
BuildContext context,
|
|
|
|
Collection collection,
|
|
|
|
) async {
|
|
|
|
return await showBarModalBottomSheet(
|
|
|
|
context: context,
|
|
|
|
builder: (context) {
|
2023-06-27 09:15:25 +00:00
|
|
|
return AddPhotosPhotoWidget(collection);
|
2023-06-22 10:51:56 +00:00
|
|
|
},
|
|
|
|
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,
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2023-06-27 09:15:25 +00:00
|
|
|
class AddPhotosPhotoWidget extends StatelessWidget {
|
2023-06-22 10:51:56 +00:00
|
|
|
final Collection collection;
|
|
|
|
|
2023-06-27 09:15:25 +00:00
|
|
|
const AddPhotosPhotoWidget(
|
2023-06-22 10:51:56 +00:00
|
|
|
this.collection, {
|
|
|
|
super.key,
|
|
|
|
});
|
|
|
|
|
|
|
|
@override
|
|
|
|
Widget build(BuildContext context) {
|
|
|
|
final ValueNotifier<bool> isFileSelected = ValueNotifier(false);
|
|
|
|
final selectedFiles = SelectedFiles();
|
|
|
|
selectedFiles.addListener(() {
|
|
|
|
isFileSelected.value = selectedFiles.files.isNotEmpty;
|
|
|
|
});
|
2023-06-27 09:15:25 +00:00
|
|
|
final Set<int> hiddenCollectionIDs =
|
|
|
|
CollectionsService.instance.getHiddenCollections();
|
2023-06-22 10:51:56 +00:00
|
|
|
|
|
|
|
return Padding(
|
|
|
|
padding: const EdgeInsets.all(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(
|
2023-06-27 09:15:25 +00:00
|
|
|
title: TitleBarTitleWidget(
|
|
|
|
title: S.of(context).addMore,
|
2023-06-22 10:51:56 +00:00
|
|
|
),
|
2023-06-27 09:15:25 +00:00
|
|
|
caption: S.of(context).selectItemsToAdd,
|
2023-06-22 10:51:56 +00:00
|
|
|
),
|
|
|
|
Expanded(
|
|
|
|
child: Gallery(
|
2023-06-27 10:13:39 +00:00
|
|
|
inSelectionMode: true,
|
2023-06-22 10:51:56 +00:00
|
|
|
asyncLoader: (
|
|
|
|
creationStartTime,
|
|
|
|
creationEndTime, {
|
|
|
|
limit,
|
|
|
|
asc,
|
2023-06-27 09:15:25 +00:00
|
|
|
}) {
|
|
|
|
return FilesDB.instance
|
|
|
|
.getAllPendingOrUploadedFiles(
|
2023-06-22 10:51:56 +00:00
|
|
|
creationStartTime,
|
|
|
|
creationEndTime,
|
2023-06-27 09:15:25 +00:00
|
|
|
Configuration.instance.getUserID()!,
|
2023-06-22 10:51:56 +00:00
|
|
|
limit: limit,
|
|
|
|
asc: asc,
|
2023-06-27 09:15:25 +00:00
|
|
|
filterOptions: DBFilterOptions(
|
|
|
|
hideIgnoredForUpload: true,
|
|
|
|
dedupeUploadID: true,
|
|
|
|
ignoredCollectionIDs: hiddenCollectionIDs,
|
|
|
|
),
|
|
|
|
applyOwnerCheck: true,
|
2023-06-22 10:51:56 +00:00
|
|
|
);
|
|
|
|
},
|
2023-06-27 09:15:25 +00:00
|
|
|
tagPrefix: "pick_add_photos_gallery",
|
2023-06-22 10:51:56 +00:00
|
|
|
selectedFiles: selectedFiles,
|
2023-06-27 09:15:25 +00:00
|
|
|
showSelectAllByDefault: true,
|
2023-06-22 10:51:56 +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,
|
|
|
|
),
|
|
|
|
),
|
|
|
|
),
|
|
|
|
child: Column(
|
|
|
|
children: [
|
|
|
|
ValueListenableBuilder(
|
|
|
|
valueListenable: isFileSelected,
|
|
|
|
builder: (context, bool value, _) {
|
|
|
|
return AnimatedSwitcher(
|
|
|
|
duration: const Duration(milliseconds: 300),
|
|
|
|
switchInCurve: Curves.easeInOutExpo,
|
|
|
|
switchOutCurve: Curves.easeInOutExpo,
|
|
|
|
child: ButtonWidget(
|
|
|
|
key: ValueKey(value),
|
|
|
|
isDisabled: !value,
|
|
|
|
buttonType: ButtonType.neutral,
|
2023-06-27 09:15:25 +00:00
|
|
|
labelText: S.of(context).addSelected,
|
2023-06-22 10:51:56 +00:00
|
|
|
onTap: () async {
|
2023-06-27 09:15:25 +00:00
|
|
|
final selectedFile = selectedFiles.files;
|
2023-06-22 10:51:56 +00:00
|
|
|
Navigator.pop(context, selectedFile);
|
|
|
|
},
|
|
|
|
),
|
|
|
|
);
|
|
|
|
},
|
|
|
|
),
|
|
|
|
const SizedBox(height: 8),
|
|
|
|
ButtonWidget(
|
|
|
|
buttonType: ButtonType.secondary,
|
|
|
|
buttonAction: ButtonAction.cancel,
|
|
|
|
labelText: S.of(context).cancel,
|
|
|
|
onTap: () async {
|
|
|
|
Navigator.of(context).pop();
|
|
|
|
},
|
|
|
|
),
|
|
|
|
],
|
|
|
|
),
|
|
|
|
),
|
|
|
|
)
|
|
|
|
],
|
|
|
|
),
|
|
|
|
),
|
|
|
|
),
|
|
|
|
],
|
|
|
|
),
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|