Skip to content

armgit / ente

Public Imported from GitHub
0

πŸ’š End-to-end encrypted cloud for everything.

Refactor file popup menu to use MenuItemWidget

AmanRajSinghMourya91a09ae71a0e
diff --git a/mobile/apps/locker/lib/ui/components/file_popup_menu_widget.dart b/mobile/apps/locker/lib/ui/components/file_popup_menu_widget.dart
index b013f5a728..f65490d941 100644
--- a/mobile/apps/locker/lib/ui/components/file_popup_menu_widget.dart
+++ b/mobile/apps/locker/lib/ui/components/file_popup_menu_widget.dart
@@ -12,6 +12,7 @@ import "package:locker/services/files/sync/metadata_updater_service.dart";
import "package:locker/services/files/sync/models/file.dart";
import "package:locker/ui/components/file_edit_dialog.dart";
import "package:locker/ui/components/item_list_view.dart";
+import "package:locker/ui/components/menu_item_widget.dart";
import "package:locker/ui/components/share_link_dialog.dart";
import "package:locker/utils/snack_bar_utils.dart";
@@ -29,12 +30,21 @@ class FilePopupMenuWidget extends StatelessWidget {
@override
Widget build(BuildContext context) {
+ final colorScheme = getEnteColorScheme(context);
+
return PopupMenuButton<String>(
onSelected: (value) => _handleMenuAction(context, value),
+ shape: RoundedRectangleBorder(
+ borderRadius: BorderRadius.circular(16),
+ side: BorderSide(color: colorScheme.strokeFaint),
+ ),
+ color: colorScheme.backgroundElevated,
+ elevation: 15,
+ shadowColor: Colors.black.withValues(alpha: 0.08),
child: child ??
HugeIcon(
icon: HugeIcons.strokeRoundedMoreVertical,
- color: getEnteColorScheme(context).iconColor,
+ color: colorScheme.iconColor,
),
itemBuilder: (BuildContext context) {
return _buildPopupMenuItems(context);
@@ -43,64 +53,74 @@ class FilePopupMenuWidget extends StatelessWidget {
}
List<PopupMenuItem<String>> _buildPopupMenuItems(BuildContext context) {
+ final colorScheme = getEnteColorScheme(context);
+
if (overflowActions != null && overflowActions!.isNotEmpty) {
- return overflowActions!
- .map(
- (action) => PopupMenuItem<String>(
- value: action.id,
- child: Row(
- children: [
- Icon(
- action.icon,
- size: 16,
- ),
- const SizedBox(width: 8),
- Text(action.label),
- ],
+ final items = <PopupMenuItem<String>>[];
+ for (int i = 0; i < overflowActions!.length; i++) {
+ final action = overflowActions![i];
+ items.add(
+ PopupMenuItem<String>(
+ value: action.id,
+ padding: EdgeInsets.zero,
+ child: MenuItemWidget(
+ icon: Icon(
+ action.icon,
+ color: colorScheme.iconColor,
+ size: 20,
),
+ label: action.label,
+ isFirst: i == 0,
+ isLast: i == overflowActions!.length - 1,
),
- )
- .toList();
+ ),
+ );
+ }
+ return items;
}
return [
PopupMenuItem<String>(
value: 'edit',
- child: Row(
- children: [
- const HugeIcon(
- icon: HugeIcons.strokeRoundedEdit02,
- size: 16,
- ),
- const SizedBox(width: 8),
- Text(context.l10n.edit),
- ],
+ padding: EdgeInsets.zero,
+ child: MenuItemWidget(
+ icon: HugeIcon(
+ icon: HugeIcons.strokeRoundedPencilEdit02,
+ color: colorScheme.iconColor,
+ size: 20,
+ ),
+ label: context.l10n.edit,
+ isFirst: true,
+ isLast: false,
),
),
PopupMenuItem<String>(
value: 'share_link',
- child: Row(
- children: [
- const HugeIcon(
- icon: HugeIcons.strokeRoundedShare03,
- size: 16,
- ),
- const SizedBox(width: 8),
- Text(context.l10n.share),
- ],
+ padding: EdgeInsets.zero,
+ child: MenuItemWidget(
+ icon: HugeIcon(
+ icon: HugeIcons.strokeRoundedShare08,
+ color: colorScheme.iconColor,
+ size: 20,
+ ),
+ label: context.l10n.share,
+ isFirst: false,
+ isLast: false,
),
),
PopupMenuItem<String>(
value: 'delete',
- child: Row(
- children: [
- const HugeIcon(
- icon: HugeIcons.strokeRoundedDelete01,
- size: 16,
- ),
- const SizedBox(width: 8),
- Text(context.l10n.delete),
- ],
+ padding: EdgeInsets.zero,
+ child: MenuItemWidget(
+ icon: HugeIcon(
+ icon: HugeIcons.strokeRoundedDelete02,
+ color: colorScheme.warning500,
+ size: 20,
+ ),
+ label: context.l10n.delete,
+ isFirst: false,
+ isLast: true,
+ isDelete: true,
),
),
];
diff --git a/mobile/apps/locker/lib/ui/components/menu_item_widget.dart b/mobile/apps/locker/lib/ui/components/menu_item_widget.dart
new file mode 100644
index 0000000000..92c841d521
--- /dev/null
+++ b/mobile/apps/locker/lib/ui/components/menu_item_widget.dart
@@ -0,0 +1,77 @@
+import "package:ente_ui/theme/ente_theme.dart";
+import "package:flutter/material.dart";
+
+class MenuItemWidget extends StatelessWidget {
+ final Widget icon;
+ final String label;
+ final bool isFirst;
+ final bool isLast;
+ final bool isDelete;
+ final bool isWarning;
+
+ const MenuItemWidget({
+ super.key,
+ required this.icon,
+ required this.label,
+ this.isFirst = false,
+ this.isLast = false,
+ this.isDelete = false,
+ this.isWarning = false,
+ });
+
+ @override
+ Widget build(BuildContext context) {
+ final colorScheme = getEnteColorScheme(context);
+ final textTheme = getEnteTextTheme(context);
+
+ return Column(
+ mainAxisSize: MainAxisSize.min,
+ children: [
+ Material(
+ color: Colors.transparent,
+ borderRadius: BorderRadius.only(
+ topLeft: isFirst ? const Radius.circular(15) : Radius.zero,
+ topRight: isFirst ? const Radius.circular(15) : Radius.zero,
+ bottomLeft: isLast ? const Radius.circular(15) : Radius.zero,
+ bottomRight: isLast ? const Radius.circular(15) : Radius.zero,
+ ),
+ child: InkWell(
+ borderRadius: BorderRadius.only(
+ topLeft: isFirst ? const Radius.circular(15) : Radius.zero,
+ topRight: isFirst ? const Radius.circular(15) : Radius.zero,
+ bottomLeft: isLast ? const Radius.circular(15) : Radius.zero,
+ bottomRight: isLast ? const Radius.circular(15) : Radius.zero,
+ ),
+ child: Padding(
+ padding: const EdgeInsets.symmetric(
+ horizontal: 16,
+ vertical: 16,
+ ),
+ child: Row(
+ children: [
+ icon,
+ const SizedBox(width: 12),
+ Expanded(
+ child: Text(
+ label,
+ style: (isDelete || isWarning)
+ ? textTheme.body
+ .copyWith(color: colorScheme.warning500)
+ : textTheme.body,
+ ),
+ ),
+ ],
+ ),
+ ),
+ ),
+ ),
+ if (!isLast)
+ Divider(
+ height: 1,
+ thickness: 1,
+ color: colorScheme.strokeFaint,
+ ),
+ ],
+ );
+ }
+}
diff --git a/mobile/apps/locker/lib/ui/pages/collection_page.dart b/mobile/apps/locker/lib/ui/pages/collection_page.dart
index b0fd693a7a..2f2a018b5d 100644
--- a/mobile/apps/locker/lib/ui/pages/collection_page.dart
+++ b/mobile/apps/locker/lib/ui/pages/collection_page.dart
@@ -17,6 +17,7 @@ import "package:locker/services/collections/models/collection_view_type.dart";
import "package:locker/services/configuration.dart";
import 'package:locker/services/files/sync/models/file.dart';
import 'package:locker/ui/components/item_list_view.dart';
+import "package:locker/ui/components/menu_item_widget.dart";
import 'package:locker/ui/components/search_result_view.dart';
import 'package:locker/ui/mixins/search_mixin.dart';
import 'package:locker/ui/pages/home_page.dart';
@@ -51,7 +52,6 @@ class _CollectionPageState extends UploaderPageState<CollectionPage>
List<EnteFile> _filteredFiles = [];
late CollectionViewType collectionViewType;
bool isQuickLink = false;
- bool showFAB = true;
final _selectedFiles = SelectedFiles();
@@ -135,10 +135,6 @@ class _CollectionPageState extends UploaderPageState<CollectionPage>
_collection,
Configuration.instance.getUserID()!,
);
-
- showFAB = collectionViewType == CollectionViewType.ownedCollection ||
- collectionViewType == CollectionViewType.hiddenOwnedCollection ||
- collectionViewType == CollectionViewType.quickLink;
}
Future<void> _initializeData(Collection collection) async {
@@ -226,8 +222,6 @@ class _CollectionPageState extends UploaderPageState<CollectionPage>
),
backgroundColor: getEnteColorScheme(context).backgroundBase,
body: _buildBody(),
- floatingActionButton:
- isSearchActive ? const SizedBox.shrink() : _buildFAB(),
bottomNavigationBar: ListenableBuilder(
listenable: _selectedFiles,
builder: (context, _) {
@@ -270,8 +264,29 @@ class _CollectionPageState extends UploaderPageState<CollectionPage>
}
Widget _buildMenuButton() {
+ final colorScheme = getEnteColorScheme(context);
+
return PopupMenuButton<String>(
- icon: const Icon(Icons.more_vert),
+ shape: RoundedRectangleBorder(
+ borderRadius: BorderRadius.circular(16),
+ side: BorderSide(color: colorScheme.strokeFaint),
+ ),
+ color: colorScheme.backgroundElevated,
+ elevation: 15,
+ shadowColor: Colors.black.withValues(alpha: 0.08),
+ child: Container(
+ height: 48,
+ width: 48,
+ decoration: BoxDecoration(
+ borderRadius: BorderRadius.circular(12),
+ color: colorScheme.backdropBase,
+ ),
+ padding: const EdgeInsets.all(12),
+ child: HugeIcon(
+ icon: HugeIcons.strokeRoundedMoreVertical,
+ color: colorScheme.iconColor,
+ ),
+ ),
onSelected: (value) {
switch (value) {
case 'edit':
@@ -286,48 +301,78 @@ class _CollectionPageState extends UploaderPageState<CollectionPage>
}
},
itemBuilder: (BuildContext context) {
- return [
- if (collectionViewType == CollectionViewType.ownedCollection ||
- collectionViewType == CollectionViewType.hiddenOwnedCollection ||
- collectionViewType == CollectionViewType.quickLink)
+ final items = <PopupMenuItem<String>>[];
+ var itemIndex = 0;
+ var totalItems = 0;
+
+ if (collectionViewType == CollectionViewType.ownedCollection ||
+ collectionViewType == CollectionViewType.hiddenOwnedCollection ||
+ collectionViewType == CollectionViewType.quickLink) {
+ totalItems = 2;
+ } else if (collectionViewType == CollectionViewType.sharedCollection) {
+ totalItems = 1;
+ }
+
+ if (collectionViewType == CollectionViewType.ownedCollection ||
+ collectionViewType == CollectionViewType.hiddenOwnedCollection ||
+ collectionViewType == CollectionViewType.quickLink) {
+ items.add(
PopupMenuItem<String>(
- value: 'edit',
- child: Row(
- children: [
- const Icon(Icons.edit),
- const SizedBox(width: 12),
- Text(context.l10n.edit),
- ],
+ value: 'rename',
+ padding: EdgeInsets.zero,
+ child: MenuItemWidget(
+ icon: HugeIcon(
+ icon: HugeIcons.strokeRoundedPencilEdit02,
+ color: colorScheme.iconColor,
+ size: 20,
+ ),
+ label: context.l10n.edit,
+ isFirst: itemIndex == 0,
+ isLast: itemIndex == totalItems - 1,
),
),
- if (collectionViewType == CollectionViewType.ownedCollection ||
- collectionViewType == CollectionViewType.hiddenOwnedCollection ||
- collectionViewType == CollectionViewType.quickLink)
+ );
+ itemIndex++;
+
+ items.add(
PopupMenuItem<String>(
value: 'delete',
- child: Row(
- children: [
- const Icon(Icons.delete, color: Colors.red),
- const SizedBox(width: 12),
- Text(
- context.l10n.delete,
- style: const TextStyle(color: Colors.red),
- ),
- ],
+ padding: EdgeInsets.zero,
+ child: MenuItemWidget(
+ icon: HugeIcon(
+ icon: HugeIcons.strokeRoundedDelete02,
+ color: colorScheme.warning500,
+ size: 20,
+ ),
+ isDelete: true,
+ label: context.l10n.delete,
+ isFirst: itemIndex == 0,
+ isLast: itemIndex == totalItems - 1,
),
),
- if (collectionViewType == CollectionViewType.sharedCollection)
+ );
+ }
+
+ if (collectionViewType == CollectionViewType.sharedCollection) {
+ items.add(
PopupMenuItem<String>(
value: 'leave_collection',
- child: Row(
- children: [
- const Icon(Icons.logout),
- const SizedBox(width: 12),
- Text(context.l10n.leaveCollection),
- ],
+ padding: EdgeInsets.zero,
+ child: MenuItemWidget(
+ icon: HugeIcon(
+ icon: HugeIcons.strokeRoundedDelete02,
+ color: colorScheme.iconColor,
+ size: 20,
+ ),
+ label: context.l10n.leaveCollection,
+ isFirst: true,
+ isLast: true,
),
),
- ];
+ );
+ }
+
+ return items;
},
);
}
@@ -354,33 +399,26 @@ class _CollectionPageState extends UploaderPageState<CollectionPage>
TitleBarTitleWidget(
title: _collection.name ?? context.l10n.untitled,
trailingWidgets: [
- Container(
- height: 48,
- width: 48,
- decoration: BoxDecoration(
- borderRadius: BorderRadius.circular(12),
- color: getEnteColorScheme(context).backdropBase,
- ),
- padding: const EdgeInsets.all(12),
- child: HugeIcon(
- icon: HugeIcons.strokeRoundedShare08,
- color: getEnteColorScheme(context).iconColor,
+ GestureDetector(
+ onTap: () async {
+ await _shareCollection();
+ },
+ child: Container(
+ height: 48,
+ width: 48,
+ decoration: BoxDecoration(
+ borderRadius: BorderRadius.circular(12),
+ color: getEnteColorScheme(context).backdropBase,
+ ),
+ padding: const EdgeInsets.all(12),
+ child: HugeIcon(
+ icon: HugeIcons.strokeRoundedShare08,
+ color: getEnteColorScheme(context).iconColor,
+ ),
),
),
const SizedBox(width: 8),
- Container(
- height: 48,
- width: 48,
- decoration: BoxDecoration(
- borderRadius: BorderRadius.circular(12),
- color: getEnteColorScheme(context).backdropBase,
- ),
- padding: const EdgeInsets.all(12),
- child: HugeIcon(
- icon: HugeIcons.strokeRoundedMoreVertical,
- color: getEnteColorScheme(context).iconColor,
- ),
- ),
+ _buildMenuButton(),
],
),
Text(
@@ -453,14 +491,4 @@ class _CollectionPageState extends UploaderPageState<CollectionPage>
(route) => false,
);
}
-
- Widget _buildFAB() {
- return showFAB
- ? FloatingActionButton(
- onPressed: addFile,
- tooltip: context.l10n.addFiles,
- child: const Icon(Icons.add),
- )
- : const SizedBox.shrink();
- }
}