Skip to content

armgit / ente

Public Imported from GitHub
0

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

Refactor share link functionality by removing redundant dialog methods and integrating share link dialog directly in FileRowWidget

AmanRajSinghMourya587d2014942d
diff --git a/mobile/apps/locker/lib/ui/components/file_row_widget.dart b/mobile/apps/locker/lib/ui/components/file_row_widget.dart
index 69cf9d6647..7c46752455 100644
--- a/mobile/apps/locker/lib/ui/components/file_row_widget.dart
+++ b/mobile/apps/locker/lib/ui/components/file_row_widget.dart
@@ -5,7 +5,6 @@ import "package:ente_ui/components/buttons/icon_button_widget.dart";
import "package:ente_ui/components/buttons/models/button_type.dart";
import "package:ente_ui/theme/ente_theme.dart";
import "package:ente_ui/utils/dialog_util.dart";
-import "package:ente_utils/share_utils.dart";
import "package:flutter/material.dart";
import "package:locker/l10n/l10n.dart";
import "package:locker/models/selected_files.dart";
@@ -16,9 +15,9 @@ import "package:locker/services/files/download/file_downloader.dart";
import "package:locker/services/files/links/links_service.dart";
import "package:locker/services/files/sync/metadata_updater_service.dart";
import "package:locker/services/files/sync/models/file.dart";
-import "package:locker/ui/components/button/copy_button.dart";
import "package:locker/ui/components/file_edit_dialog.dart";
import "package:locker/ui/components/item_list_view.dart";
+import "package:locker/ui/components/share_link_dialog.dart";
import "package:locker/utils/data_util.dart";
import "package:locker/utils/date_time_util.dart";
import "package:locker/utils/file_icon_utils.dart";
@@ -273,10 +272,11 @@ class FileRowWidget extends StatelessWidget {
// Show the link dialog with copy and delete options
if (context.mounted) {
- await _showShareLinkDialog(
+ await showShareLinkDialog(
context,
shareableLink.fullURL!,
shareableLink.linkID,
+ file,
);
}
} catch (e) {
@@ -291,133 +291,6 @@ class FileRowWidget extends StatelessWidget {
}
}
- Future<void> _showShareLinkDialog(
- BuildContext context,
- String url,
- String linkID,
- ) async {
- final colorScheme = getEnteColorScheme(context);
- final textTheme = getEnteTextTheme(context);
- // Capture the root context (with Scaffold) before showing dialog
- final rootContext = context;
-
- await showDialog<void>(
- context: context,
- builder: (BuildContext dialogContext) {
- return StatefulBuilder(
- builder: (context, setState) {
- return AlertDialog(
- title: Text(
- dialogContext.l10n.share,
- style: textTheme.largeBold,
- ),
- content: Column(
- mainAxisSize: MainAxisSize.min,
- crossAxisAlignment: CrossAxisAlignment.start,
- children: [
- Text(
- dialogContext.l10n.shareThisLink,
- style: textTheme.body,
- ),
- const SizedBox(height: 20),
- Container(
- padding: const EdgeInsets.all(12),
- decoration: BoxDecoration(
- color: colorScheme.fillFaint,
- borderRadius: BorderRadius.circular(8),
- border: Border.all(color: colorScheme.strokeFaint),
- ),
- child: Row(
- children: [
- Expanded(
- child: SelectableText(
- url,
- style: textTheme.small,
- ),
- ),
- const SizedBox(width: 8),
- CopyButton(url: url),
- ],
- ),
- ),
- ],
- ),
- actions: [
- TextButton(
- onPressed: () async {
- Navigator.of(context).pop();
- await _deleteShareLink(rootContext, file.uploadedFileID!);
- },
- child: Text(
- dialogContext.l10n.deleteLink,
- style:
- textTheme.body.copyWith(color: colorScheme.warning500),
- ),
- ),
- TextButton(
- onPressed: () async {
- Navigator.of(dialogContext).pop();
- // Use system share sheet to share the URL
- await shareText(
- url,
- context: rootContext,
- );
- },
- child: Text(
- dialogContext.l10n.shareLink,
- style:
- textTheme.body.copyWith(color: colorScheme.primary500),
- ),
- ),
- ],
- );
- },
- );
- },
- );
- }
-
- Future<void> _deleteShareLink(BuildContext context, int fileID) async {
- final result = await showChoiceDialog(
- context,
- title: context.l10n.deleteShareLinkDialogTitle,
- body: context.l10n.deleteShareLinkConfirmation,
- firstButtonLabel: context.l10n.delete,
- secondButtonLabel: context.l10n.cancel,
- firstButtonType: ButtonType.critical,
- isCritical: true,
- );
- if (result?.action == ButtonAction.first && context.mounted) {
- final dialog = createProgressDialog(
- context,
- context.l10n.deletingShareLink,
- isDismissible: false,
- );
-
- try {
- await dialog.show();
- await LinksService.instance.deleteLink(fileID);
- await dialog.hide();
-
- if (context.mounted) {
- SnackBarUtils.showInfoSnackBar(
- context,
- context.l10n.shareLinkDeletedSuccessfully,
- );
- }
- } catch (e) {
- await dialog.hide();
-
- if (context.mounted) {
- SnackBarUtils.showWarningSnackBar(
- context,
- '${context.l10n.failedToDeleteShareLink}: ${e.toString()}',
- );
- }
- }
- }
- }
-
Future<void> _showDeleteConfirmationDialog(BuildContext context) async {
final result = await showChoiceDialog(
context,