Skip to content

armgit / ente

Public Imported from GitHub
0

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

Fix sharing actions

AmanRajSinghMourya7a84ec8dc4cc
diff --git a/mobile/apps/locker/lib/ui/components/collection_popup_menu_widget.dart b/mobile/apps/locker/lib/ui/components/collection_popup_menu_widget.dart
index 1c3dfc8bf3..2429f17f8b 100644
--- a/mobile/apps/locker/lib/ui/components/collection_popup_menu_widget.dart
+++ b/mobile/apps/locker/lib/ui/components/collection_popup_menu_widget.dart
@@ -37,6 +37,7 @@ class CollectionPopupMenuWidget extends StatelessWidget {
color: colorScheme.backdropBase,
surfaceTintColor: Colors.transparent,
elevation: 15,
+ offset: const Offset(-24, 24),
shadowColor: Colors.black.withValues(alpha: 0.08),
child: child ??
HugeIcon(
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 f0101c41ed..106b23bb1c 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
@@ -38,6 +38,7 @@ class FilePopupMenuWidget extends StatelessWidget {
borderRadius: BorderRadius.circular(16),
side: BorderSide(color: colorScheme.strokeFaint),
),
+ offset: const Offset(-24, 24),
color: colorScheme.backdropBase,
surfaceTintColor: Colors.transparent,
padding: EdgeInsets.zero,
diff --git a/mobile/apps/locker/lib/ui/components/recents_section_widget.dart b/mobile/apps/locker/lib/ui/components/recents_section_widget.dart
index 50f153a001..0bc8487339 100644
--- a/mobile/apps/locker/lib/ui/components/recents_section_widget.dart
+++ b/mobile/apps/locker/lib/ui/components/recents_section_widget.dart
@@ -94,7 +94,6 @@ class _RecentsSectionWidgetState extends State<RecentsSectionWidget> {
Widget _buildRecentsHeader() {
final colorScheme = getEnteColorScheme(context);
return SectionOptions(
- onTap: () {},
body: context.l10n.items(_displayedFiles.length),
SectionTitle(title: context.l10n.recents),
trailingWidget: GestureDetector(
diff --git a/mobile/apps/locker/lib/ui/pages/home_page.dart b/mobile/apps/locker/lib/ui/pages/home_page.dart
index 1e39c26ab9..ab556364e5 100644
--- a/mobile/apps/locker/lib/ui/pages/home_page.dart
+++ b/mobile/apps/locker/lib/ui/pages/home_page.dart
@@ -59,6 +59,9 @@ class CustomLockerAppBar extends StatelessWidget
Widget build(BuildContext context) {
final colorScheme = getEnteColorScheme(context);
final textTheme = getEnteTextTheme(context);
+ final hasQuery = searchController.text.isNotEmpty;
+ final showClearIcon = isSearchActive || hasQuery;
+ final clearIconColor = colorScheme.primary700;
return Container(
decoration: BoxDecoration(
@@ -147,24 +150,21 @@ class CustomLockerAppBar extends StatelessWidget
minWidth: 44,
minHeight: 24,
),
- suffixIcon:
- (isSearchActive || searchController.text.isNotEmpty)
- ? GestureDetector(
- onTap: onClearSearch,
- child: Padding(
- padding:
- const EdgeInsets.only(right: 16, left: 8),
- child: HugeIcon(
- icon: HugeIcons.strokeRoundedCancel01,
- color: colorScheme.textBase,
- size: 20,
- ),
- ),
- )
- : null,
+ suffixIcon: showClearIcon
+ ? IconButton(
+ onPressed: onClearSearch,
+ splashRadius: 20,
+ padding: const EdgeInsets.only(right: 16, left: 8),
+ icon: HugeIcon(
+ icon: HugeIcons.strokeRoundedCancel01,
+ color: clearIconColor,
+ size: 20,
+ ),
+ )
+ : null,
suffixIconConstraints: const BoxConstraints(
minWidth: 44,
- minHeight: 24,
+ minHeight: 44,
),
),
style: TextStyle(
@@ -618,6 +618,7 @@ class _HomePageState extends UploaderPageState<HomePage>
if (isSearchActive) {
return SingleChildScrollView(
physics: const AlwaysScrollableScrollPhysics(),
+ padding: const EdgeInsets.symmetric(vertical: 24.0),
child: SearchResultView(
collections: _filteredCollections,
files: _filteredFiles,
diff --git a/mobile/apps/locker/lib/ui/sharing/advanced_sharing_bottom_sheet.dart b/mobile/apps/locker/lib/ui/sharing/advanced_sharing_bottom_sheet.dart
index c08f4069e9..3f3c9bac0d 100644
--- a/mobile/apps/locker/lib/ui/sharing/advanced_sharing_bottom_sheet.dart
+++ b/mobile/apps/locker/lib/ui/sharing/advanced_sharing_bottom_sheet.dart
@@ -1,13 +1,20 @@
+import "dart:convert";
+
+import "package:ente_crypto_dart/ente_crypto_dart.dart";
import "package:ente_ui/components/captioned_text_widget.dart";
import "package:ente_ui/components/menu_item_widget.dart";
import "package:ente_ui/components/toggle_switch_widget.dart";
import "package:ente_ui/theme/ente_theme.dart";
import "package:ente_ui/utils/dialog_util.dart";
+import "package:ente_ui/utils/toast_util.dart";
+import "package:ente_utils/navigation_util.dart";
import "package:flutter/material.dart";
import "package:locker/l10n/l10n.dart";
import "package:locker/services/collections/collections_api_client.dart";
import "package:locker/services/collections/models/collection.dart";
import "package:locker/services/collections/models/public_url.dart";
+import "package:locker/ui/sharing/pickers/device_limit_picker_page.dart";
+import "package:locker/ui/sharing/pickers/link_expiry_picker_page.dart";
import "package:locker/utils/collection_actions.dart";
/// A bottom sheet widget for advanced sharing options.
@@ -47,6 +54,13 @@ class _AdvancedSharingBottomSheetState
final textTheme = getEnteTextTheme(context);
final shareText = context.l10n.shareWithPeopleSectionTitle(_shareeCount);
+ final isDownloadEnabled =
+ widget.collection.publicURLs.firstOrNull?.enableDownload ?? true;
+ final isCollectEnabled =
+ widget.collection.publicURLs.firstOrNull?.enableCollect ?? false;
+ final isPasswordEnabled =
+ widget.collection.publicURLs.firstOrNull?.passwordEnabled ?? false;
+
return Container(
decoration: BoxDecoration(
color: colorScheme.backdropBase,
@@ -117,9 +131,7 @@ class _AdvancedSharingBottomSheetState
leadingSpace: leadingSpace,
trailingWidget: ToggleSwitchWidget(
value: () => _shareeCount > 0 || _hasPublicLink,
- onChanged: () async {
- // No action - just display current state
- },
+ onChanged: () async {},
),
isGestureDetectorDisabled: true,
),
@@ -131,15 +143,22 @@ class _AdvancedSharingBottomSheetState
menuItemColor: colorScheme.backgroundElevated2,
leadingSpace: leadingSpace,
trailingWidget: ToggleSwitchWidget(
- value: () => _publicUrl?.enableDownload ?? true,
+ value: () => isDownloadEnabled,
onChanged: _publicUrl != null
? () async {
await _updatePublicUrlSettings(
{
- 'enableDownload':
- !_publicUrl!.enableDownload,
+ 'enableDownload': !isDownloadEnabled,
},
);
+ if (isDownloadEnabled) {
+ // ignore: unawaited_futures
+ showErrorDialog(
+ context,
+ "Please note",
+ "Viewers can still take screenshots or save a copy of your photos using external tools",
+ );
+ }
}
: () async {},
),
@@ -173,25 +192,6 @@ class _AdvancedSharingBottomSheetState
),
if (_hasPublicLink && _publicUrl != null) ...[
const SizedBox(height: 8),
-
- MenuItemWidget(
- captionedTextWidget: const CaptionedTextWidget(
- title: "Allow downloads",
- ),
- menuItemColor: colorScheme.backgroundElevated2,
- leadingSpace: leadingSpace,
- trailingWidget: ToggleSwitchWidget(
- value: () => _publicUrl!.enableDownload,
- onChanged: () async {
- await _updatePublicUrlSettings(
- {'enableDownload': !_publicUrl!.enableDownload},
- );
- },
- ),
- isGestureDetectorDisabled: true,
- ),
- const SizedBox(height: 8),
-
MenuItemWidget(
captionedTextWidget: const CaptionedTextWidget(
title: "Allow uploads",
@@ -199,18 +199,16 @@ class _AdvancedSharingBottomSheetState
menuItemColor: colorScheme.backgroundElevated2,
leadingSpace: leadingSpace,
trailingWidget: ToggleSwitchWidget(
- value: () => _publicUrl!.enableCollect,
+ value: () => isCollectEnabled,
onChanged: () async {
await _updatePublicUrlSettings(
- {'enableCollect': !_publicUrl!.enableCollect},
+ {'enableCollect': !isCollectEnabled},
);
},
),
isGestureDetectorDisabled: true,
),
const SizedBox(height: 8),
-
- // Password lock
MenuItemWidget(
captionedTextWidget: const CaptionedTextWidget(
title: "Password lock",
@@ -218,9 +216,9 @@ class _AdvancedSharingBottomSheetState
menuItemColor: colorScheme.backgroundElevated2,
leadingSpace: leadingSpace,
trailingWidget: ToggleSwitchWidget(
- value: () => _publicUrl!.passwordEnabled,
+ value: () => isPasswordEnabled,
onChanged: () async {
- if (!_publicUrl!.passwordEnabled) {
+ if (!isPasswordEnabled) {
await _showPasswordDialog();
} else {
await _updatePublicUrlSettings(
@@ -231,15 +229,13 @@ class _AdvancedSharingBottomSheetState
),
isGestureDetectorDisabled: true,
),
-
const SizedBox(height: 8),
-
MenuItemWidget(
captionedTextWidget: CaptionedTextWidget(
title: "Device limit",
subTitle: _publicUrl!.deviceLimit == 0
? "None"
- : "${_publicUrl!.deviceLimit} devices",
+ : "${_publicUrl!.deviceLimit}",
),
menuItemColor: colorScheme.backgroundElevated2,
leadingSpace: leadingSpace,
@@ -249,17 +245,22 @@ class _AdvancedSharingBottomSheetState
size: 24,
),
onTap: () async {
- // TODO: Navigate to device limit picker
+ await routeToPage(
+ context,
+ DeviceLimitPickerPage(widget.collection),
+ ).then((value) {
+ setState(() {});
+ });
},
),
const SizedBox(height: 8),
-
- // Link Expiry
MenuItemWidget(
captionedTextWidget: CaptionedTextWidget(
title: "Link Expiry",
subTitle: _publicUrl!.hasExpiry
- ? (_publicUrl!.isExpired ? "Expired" : "Active")
+ ? (_publicUrl!.isExpired
+ ? "Expired"
+ : "Enabled")
: "Never",
),
menuItemColor: colorScheme.backgroundElevated2,
@@ -270,7 +271,12 @@ class _AdvancedSharingBottomSheetState
size: 24,
),
onTap: () async {
- // TODO: Navigate to link expiry picker
+ await routeToPage(
+ context,
+ LinkExpiryPickerPage(widget.collection),
+ ).then((value) {
+ setState(() {});
+ });
},
),
],
@@ -297,132 +303,79 @@ class _AdvancedSharingBottomSheetState
}
Future<void> _disablePublicLink() async {
- final confirmed = await showDialog<bool>(
- context: context,
- builder: (context) => AlertDialog(
- title: const Text("Disable public link"),
- content: const Text(
- "Are you sure you want to disable the public link? People with this link will no longer be able to access your collection.",
- ),
- actions: [
- TextButton(
- onPressed: () => Navigator.pop(context, false),
- child: const Text("Cancel"),
- ),
- TextButton(
- onPressed: () => Navigator.pop(context, true),
- child: const Text("Disable"),
- ),
- ],
- ),
- );
-
- if (confirmed == true) {
- try {
- await CollectionActions.disableUrl(
- context,
- widget.collection,
- );
- if (mounted) {
- setState(() {});
- }
- } catch (e) {
- if (mounted) {
- await showGenericErrorDialog(context: context, error: e);
- }
+ try {
+ await CollectionActions.disableUrl(
+ context,
+ widget.collection,
+ );
+ if (mounted) {
+ setState(() {});
+ }
+ } catch (e) {
+ if (mounted) {
+ await showGenericErrorDialog(context: context, error: e);
}
}
}
Future<void> _updatePublicUrlSettings(
- Map<String, dynamic> updates,
- ) async {
+ Map<String, dynamic> updates, {
+ bool showProgressDialog = true,
+ }) async {
+ final dialog = showProgressDialog
+ ? createProgressDialog(context, "Please wait...")
+ : null;
+ await dialog?.show();
try {
await CollectionApiClient.instance.updateShareUrl(
widget.collection,
updates,
);
+ await dialog?.hide();
+ showShortToast(context, "Collection updated");
if (mounted) {
setState(() {});
}
} catch (e) {
if (mounted) {
+ await dialog?.hide();
await showGenericErrorDialog(context: context, error: e);
+ rethrow;
}
}
}
Future<void> _showPasswordDialog() async {
- final colorScheme = getEnteColorScheme(context);
- final textTheme = getEnteTextTheme(context);
- final passwordController = TextEditingController();
+ await showTextInputDialog(
+ context,
+ title: context.l10n.setAPassword,
+ submitButtonLabel: context.l10n.lockButtonLabel,
+ hintText: context.l10n.enterPassword,
+ isPasswordInput: true,
+ alwaysShowSuccessState: true,
+ onSubmit: (String password) async {
+ if (password.trim().isNotEmpty) {
+ final propToUpdate = await _getEncryptedPassword(password);
+ await _updatePublicUrlSettings(
+ propToUpdate,
+ showProgressDialog: false,
+ );
+ }
+ },
+ );
+ }
- await showDialog(
- context: context,
- builder: (dialogContext) => Dialog(
- backgroundColor: colorScheme.backgroundElevated,
- shape: RoundedRectangleBorder(
- borderRadius: BorderRadius.circular(16),
- ),
- child: Padding(
- padding: const EdgeInsets.all(24),
- child: Column(
- mainAxisSize: MainAxisSize.min,
- crossAxisAlignment: CrossAxisAlignment.start,
- children: [
- Text(
- "Set password",
- style: textTheme.h3,
- ),
- const SizedBox(height: 16),
- TextField(
- controller: passwordController,
- decoration: InputDecoration(
- hintText: "Enter password",
- hintStyle: textTheme.body.copyWith(
- color: colorScheme.textMuted,
- ),
- filled: true,
- fillColor: colorScheme.backgroundElevated2,
- border: OutlineInputBorder(
- borderRadius: BorderRadius.circular(8),
- borderSide: BorderSide.none,
- ),
- ),
- obscureText: true,
- autofocus: true,
- ),
- const SizedBox(height: 24),
- Row(
- mainAxisAlignment: MainAxisAlignment.end,
- children: [
- TextButton(
- onPressed: () => Navigator.pop(dialogContext),
- child: Text(
- "Cancel",
- style: textTheme.body,
- ),
- ),
- const SizedBox(width: 12),
- ElevatedButton(
- onPressed: () async {
- final password = passwordController.text.trim();
- if (password.isNotEmpty) {
- Navigator.pop(dialogContext);
- // TODO: Implement password encryption and update
- await _updatePublicUrlSettings({
- 'passwordEnabled': true,
- });
- }
- },
- child: const Text("Set"),
- ),
- ],
- ),
- ],
- ),
- ),
- ),
+ Future<Map<String, dynamic>> _getEncryptedPassword(String pass) async {
+ final kekSalt = CryptoUtil.getSaltToDeriveKey();
+ final result = await CryptoUtil.deriveInteractiveKey(
+ utf8.encode(pass),
+ kekSalt,
);
+ return {
+ 'passHash': CryptoUtil.bin2base64(result.key),
+ 'nonce': CryptoUtil.bin2base64(kekSalt),
+ 'memLimit': result.memLimit,
+ 'opsLimit': result.opsLimit,
+ };
}
}
diff --git a/mobile/apps/locker/lib/ui/sharing/share_collection_bottom_sheet.dart b/mobile/apps/locker/lib/ui/sharing/share_collection_bottom_sheet.dart
index 715ecb5f60..e5c60ec6d9 100644
--- a/mobile/apps/locker/lib/ui/sharing/share_collection_bottom_sheet.dart
+++ b/mobile/apps/locker/lib/ui/sharing/share_collection_bottom_sheet.dart
@@ -237,15 +237,6 @@ class _ShareCollectionBottomSheetState
EnteColorScheme colorScheme,
EnteTextTheme textTheme,
) {
- if (_shareeCount == 0) {
- return Text(
- context.l10n.shareWithPeopleSectionTitle(0),
- style: textTheme.body.copyWith(
- color: colorScheme.textBase,
- ),
- );
- }
-
return SizedBox(
height: 44,
child: AlbumSharesIcons(
@@ -518,6 +509,10 @@ class _ShareCollectionBottomSheetState
EnteTextTheme textTheme,
) {
final publicUrl = _publicUrl;
+
+ final isCollectEnabled =
+ widget.collection.publicURLs.firstOrNull?.enableCollect ?? false;
+
if (publicUrl == null) {
return const SizedBox.shrink();
}
@@ -564,11 +559,12 @@ class _ShareCollectionBottomSheetState
const SizedBox(height: 8),
_buildToggleRow(
label: "Allow uploads",
- value: publicUrl.enableCollect,
+ value: isCollectEnabled,
onChanged: _isOwner
? () async {
await _updatePublicUrlSettings(
- {'enableCollect': !publicUrl.enableCollect},
+ {'enableCollect': !isCollectEnabled},
+ showProgressDialog: true,
);
}
: null,
@@ -878,6 +874,7 @@ class _ShareCollectionBottomSheetState
);
if (result && mounted) {
+ user.role = newRole.toString();
setState(() {});
}
}
@@ -917,19 +914,28 @@ class _ShareCollectionBottomSheetState
}
Future<void> _updatePublicUrlSettings(
- Map<String, dynamic> updates,
- ) async {
+ Map<String, dynamic> updates, {
+ bool showProgressDialog = true,
+ }) async {
+ final dialog = showProgressDialog
+ ? createProgressDialog(context, "Please wait...")
+ : null;
+ await dialog?.show();
try {
await CollectionApiClient.instance.updateShareUrl(
widget.collection,
updates,
);
+ await dialog?.hide();
+ showShortToast(context, "Collection updated");
if (mounted) {
setState(() {});
}
} catch (e) {
if (mounted) {
+ await dialog?.hide();
await showGenericErrorDialog(context: context, error: e);
+ rethrow;
}
}
}
diff --git a/mobile/packages/sharing/lib/collection_sharing_service.dart b/mobile/packages/sharing/lib/collection_sharing_service.dart
index 827f95424f..d6e4467dd5 100644
--- a/mobile/packages/sharing/lib/collection_sharing_service.dart
+++ b/mobile/packages/sharing/lib/collection_sharing_service.dart
@@ -76,7 +76,7 @@ class CollectionSharingService {
) async {
try {
final response = await _enteDio.post(
- '/collection/share-url',
+ '/collections/share-url',
data: {
'collectionID': collectionID,
'enableCollect': enableCollect,