add functionality for delete on BottomActionBar
This commit is contained in:
parent
472c618ed0
commit
0c592fa509
|
@ -1,12 +1,15 @@
|
|||
import 'dart:ui';
|
||||
|
||||
import 'package:expandable/expandable.dart';
|
||||
import 'package:flutter/cupertino.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:photos/models/selected_files.dart';
|
||||
import 'package:photos/theme/effects.dart';
|
||||
import 'package:photos/theme/ente_theme.dart';
|
||||
import 'package:photos/ui/components/bottom_action_bar/action_bar_widget.dart';
|
||||
import 'package:photos/ui/components/icon_button_widget.dart';
|
||||
import 'package:photos/utils/delete_file_util.dart';
|
||||
import 'package:photos/utils/toast_util.dart';
|
||||
|
||||
class BottomActionBarWidget extends StatelessWidget {
|
||||
final String? text;
|
||||
|
@ -59,7 +62,7 @@ class BottomActionBarWidget extends StatelessWidget {
|
|||
child: ActionBarWidget(
|
||||
selectedFiles: selectedFiles,
|
||||
text: text,
|
||||
iconButtons: _iconButtons(),
|
||||
iconButtons: _iconButtons(context),
|
||||
),
|
||||
),
|
||||
expanded: expandedMenu,
|
||||
|
@ -96,15 +99,124 @@ class BottomActionBarWidget extends StatelessWidget {
|
|||
);
|
||||
}
|
||||
|
||||
List<Widget> _iconButtons() {
|
||||
List<Widget> _iconButtons(BuildContext context) {
|
||||
final iconButtonsWithExpansionIcon = <Widget?>[
|
||||
...?iconButtons,
|
||||
IconButtonWidget(
|
||||
icon: Icons.delete_outlined,
|
||||
iconButtonType: IconButtonType.primary,
|
||||
onTap: () => _showDeleteSheet(context),
|
||||
),
|
||||
IconButtonWidget(
|
||||
icon: Icons.ios_share_outlined,
|
||||
iconButtonType: IconButtonType.primary,
|
||||
onTap: () {},
|
||||
),
|
||||
ExpansionIconWidget(expandableController: _expandableController)
|
||||
];
|
||||
iconButtonsWithExpansionIcon.removeWhere((element) => element == null);
|
||||
return iconButtonsWithExpansionIcon as List<Widget>;
|
||||
}
|
||||
|
||||
void _showDeleteSheet(BuildContext context) {
|
||||
final count = selectedFiles!.files.length;
|
||||
bool containsUploadedFile = false, containsLocalFile = false;
|
||||
for (final file in selectedFiles!.files) {
|
||||
if (file.uploadedFileID != null) {
|
||||
containsUploadedFile = true;
|
||||
}
|
||||
if (file.localID != null) {
|
||||
containsLocalFile = true;
|
||||
}
|
||||
}
|
||||
final actions = <Widget>[];
|
||||
if (containsUploadedFile && containsLocalFile) {
|
||||
actions.add(
|
||||
CupertinoActionSheetAction(
|
||||
isDestructiveAction: true,
|
||||
onPressed: () async {
|
||||
Navigator.of(context, rootNavigator: true).pop();
|
||||
await deleteFilesOnDeviceOnly(
|
||||
context,
|
||||
selectedFiles!.files.toList(),
|
||||
);
|
||||
_clearSelectedFiles();
|
||||
showToast(context, "Files deleted from device");
|
||||
},
|
||||
child: const Text("Device"),
|
||||
),
|
||||
);
|
||||
actions.add(
|
||||
CupertinoActionSheetAction(
|
||||
isDestructiveAction: true,
|
||||
onPressed: () async {
|
||||
Navigator.of(context, rootNavigator: true).pop();
|
||||
await deleteFilesFromRemoteOnly(
|
||||
context,
|
||||
selectedFiles!.files.toList(),
|
||||
);
|
||||
_clearSelectedFiles();
|
||||
showShortToast(context, "Moved to trash");
|
||||
},
|
||||
child: const Text("ente"),
|
||||
),
|
||||
);
|
||||
actions.add(
|
||||
CupertinoActionSheetAction(
|
||||
isDestructiveAction: true,
|
||||
onPressed: () async {
|
||||
Navigator.of(context, rootNavigator: true).pop();
|
||||
await deleteFilesFromEverywhere(
|
||||
context,
|
||||
selectedFiles!.files.toList(),
|
||||
);
|
||||
_clearSelectedFiles();
|
||||
},
|
||||
child: const Text("Everywhere"),
|
||||
),
|
||||
);
|
||||
} else {
|
||||
actions.add(
|
||||
CupertinoActionSheetAction(
|
||||
isDestructiveAction: true,
|
||||
onPressed: () async {
|
||||
Navigator.of(context, rootNavigator: true).pop();
|
||||
await deleteFilesFromEverywhere(
|
||||
context,
|
||||
selectedFiles!.files.toList(),
|
||||
);
|
||||
_clearSelectedFiles();
|
||||
},
|
||||
child: const Text("Delete"),
|
||||
),
|
||||
);
|
||||
}
|
||||
final action = CupertinoActionSheet(
|
||||
title: Text(
|
||||
"Delete " +
|
||||
count.toString() +
|
||||
" file" +
|
||||
(count == 1 ? "" : "s") +
|
||||
(containsUploadedFile && containsLocalFile ? " from" : "?"),
|
||||
),
|
||||
actions: actions,
|
||||
cancelButton: CupertinoActionSheetAction(
|
||||
child: const Text("Cancel"),
|
||||
onPressed: () {
|
||||
Navigator.of(context, rootNavigator: true).pop();
|
||||
},
|
||||
),
|
||||
);
|
||||
showCupertinoModalPopup(
|
||||
context: context,
|
||||
builder: (_) => action,
|
||||
barrierColor: Colors.black.withOpacity(0.75),
|
||||
);
|
||||
}
|
||||
|
||||
void _clearSelectedFiles() {
|
||||
selectedFiles!.clearAll();
|
||||
}
|
||||
|
||||
ExpandableThemeData _getExpandableTheme() {
|
||||
return const ExpandableThemeData(
|
||||
hasIcon: false,
|
||||
|
|
|
@ -10,8 +10,10 @@ import 'package:photos/models/file_load_result.dart';
|
|||
import 'package:photos/models/gallery_type.dart';
|
||||
import 'package:photos/models/selected_files.dart';
|
||||
import 'package:photos/services/ignored_files_service.dart';
|
||||
import 'package:photos/theme/ente_theme.dart';
|
||||
import 'package:photos/ui/components/blur_menu_item_widget.dart';
|
||||
import 'package:photos/ui/components/bottom_action_bar/bottom_action_bar_widget.dart';
|
||||
import 'package:photos/ui/components/icon_button_widget.dart';
|
||||
import 'package:photos/ui/components/bottom_action_bar/expanded_menu_widget.dart';
|
||||
import 'package:photos/ui/viewer/gallery/empty_state.dart';
|
||||
import 'package:photos/ui/viewer/gallery/gallery.dart';
|
||||
import 'package:photos/ui/viewer/gallery/gallery_app_bar_widget.dart';
|
||||
|
@ -111,6 +113,7 @@ class _CollectionPageState extends State<CollectionPage> {
|
|||
ValueListenableBuilder(
|
||||
valueListenable: _bottomPosition,
|
||||
builder: (context, value, child) {
|
||||
final colorScheme = getEnteColorScheme(context);
|
||||
return AnimatedPositioned(
|
||||
curve: Curves.easeInOutExpo,
|
||||
bottom: _bottomPosition.value,
|
||||
|
@ -119,23 +122,24 @@ class _CollectionPageState extends State<CollectionPage> {
|
|||
duration: const Duration(milliseconds: 400),
|
||||
child: BottomActionBarWidget(
|
||||
selectedFiles: _selectedFiles,
|
||||
expandedMenu: const SizedBox(height: 150),
|
||||
expandedMenu: ExpandedMenuWidget(
|
||||
items: [
|
||||
BlurMenuItemWidget(
|
||||
leadingIcon: Icons.add_outlined,
|
||||
labelText: "One",
|
||||
menuItemColor: colorScheme.fillFaint,
|
||||
),
|
||||
],
|
||||
groupingOrder: const [
|
||||
1,
|
||||
],
|
||||
),
|
||||
text: _selectedFiles.files.length.toString() + ' selected',
|
||||
onCancel: () {
|
||||
if (_selectedFiles.files.isNotEmpty) {
|
||||
_selectedFiles.clearAll();
|
||||
}
|
||||
},
|
||||
iconButtons: const [
|
||||
IconButtonWidget(
|
||||
icon: Icons.delete_outlined,
|
||||
iconButtonType: IconButtonType.primary,
|
||||
),
|
||||
IconButtonWidget(
|
||||
icon: Icons.ios_share_outlined,
|
||||
iconButtonType: IconButtonType.primary,
|
||||
),
|
||||
],
|
||||
),
|
||||
);
|
||||
},
|
||||
|
|
Loading…
Reference in a new issue