π End-to-end encrypted cloud for everything.
Dart 2faandroidauthye2eeencryptionend-to-end-encryptionfluttergolanggoogle-photosgoogle-photos-alternativeiosopensourcephotosprivacyprivacy-toolstypescriptzero-knowledge
[mob][photos] Moving code to share_util.dart
Aman Raj Singh Mourya509b7bda67a2
diff --git a/mobile/lib/ui/sharing/manage_links_widget.dart b/mobile/lib/ui/sharing/manage_links_widget.dartindex d0d71865b8..6c50e80008 100644--- a/mobile/lib/ui/sharing/manage_links_widget.dart+++ b/mobile/lib/ui/sharing/manage_links_widget.dart@@ -4,12 +4,9 @@ import 'package:collection/collection.dart';import "package:fast_base58/fast_base58.dart";import 'package:flutter/material.dart';import "package:flutter/services.dart";-import "package:photos/core/constants.dart";-import "package:photos/db/files_db.dart";import "package:photos/generated/l10n.dart";import "package:photos/models/api/collection/public_url.dart";import 'package:photos/models/collection/collection.dart';-import "package:photos/models/file/file.dart";import 'package:photos/services/collections_service.dart';import 'package:photos/theme/colors.dart';import 'package:photos/theme/ente_theme.dart';@@ -21,14 +18,12 @@ import 'package:photos/ui/components/menu_section_description_widget.dart';import "package:photos/ui/components/toggle_switch_widget.dart";import 'package:photos/ui/sharing/pickers/device_limit_picker_page.dart';import 'package:photos/ui/sharing/pickers/link_expiry_picker_page.dart';-import "package:photos/ui/sharing/show_images_prevew.dart";import 'package:photos/utils/crypto_util.dart';import 'package:photos/utils/date_time_util.dart';import 'package:photos/utils/dialog_util.dart';import 'package:photos/utils/navigation_util.dart';import "package:photos/utils/share_util.dart";import 'package:photos/utils/toast_util.dart';-import "package:screenshot/screenshot.dart";class ManageSharedLinkWidget extends StatefulWidget {final Collection? collection;@@ -42,7 +37,6 @@ class ManageSharedLinkWidget extends StatefulWidget {class _ManageSharedLinkWidgetState extends State<ManageSharedLinkWidget> {final CollectionActions sharingActions =CollectionActions(CollectionsService.instance);- final ScreenshotController screenshotController = ScreenshotController();final GlobalKey sendLinkButtonKey = GlobalKey();@override@@ -287,10 +281,11 @@ class _ManageSharedLinkWidgetState extends State<ManageSharedLinkWidget> {menuItemColor: getEnteColorScheme(context).fillFaint,onTap: () async {// ignore: unawaited_futures- _shareAlbumLink(+ await shareAlbumLinkWithPlaceholder(context,widget.collection!,urlValue,+ sendLinkButtonKey,);},isTopBorderRadiusRemoved: true,@@ -330,52 +325,6 @@ class _ManageSharedLinkWidgetState extends State<ManageSharedLinkWidget> {);}- Future<Uint8List> _createAlbumPlaceholder(- List<EnteFile> ownedSelectedFiles,- ) async {- final Widget imageWidget = LinkPlaceholder(- files: ownedSelectedFiles,- );- final double pixelRatio = MediaQuery.devicePixelRatioOf(context);- final bytesOfImageToWidget = await screenshotController.captureFromWidget(- imageWidget,- pixelRatio: pixelRatio,- targetSize: MediaQuery.sizeOf(context),- delay: const Duration(milliseconds: 300),- );- return bytesOfImageToWidget;- }-- Future<void> _shareAlbumLink(- BuildContext context,- Collection collection,- String url,- ) async {- final dialog = createProgressDialog(- context,- S.of(context).creatingLink,- isDismissible: true,- );- await dialog.show();- final List<EnteFile> filesInCollection =- (await FilesDB.instance.getFilesInCollection(- collection.id,- galleryLoadStartTime,- galleryLoadEndTime,- ))- .files;-- final placeholderBytes = await _createAlbumPlaceholder(filesInCollection);- await dialog.hide();-- await shareImageAndUrl(- placeholderBytes,- url,- context: context,- key: sendLinkButtonKey,- );- }-Future<Map<String, dynamic>> _getEncryptedPassword(String pass) async {final kekSalt = CryptoUtil.getSaltToDeriveKey();final result = await CryptoUtil.deriveInteractiveKey(diff --git a/mobile/lib/ui/sharing/share_collection_page.dart b/mobile/lib/ui/sharing/share_collection_page.dartindex aef8acf3f2..26e19b33eb 100644--- a/mobile/lib/ui/sharing/share_collection_page.dart+++ b/mobile/lib/ui/sharing/share_collection_page.dart@@ -2,12 +2,9 @@ import 'package:collection/collection.dart';import 'package:fast_base58/fast_base58.dart';import 'package:flutter/material.dart';import 'package:flutter/services.dart';-import "package:photos/core/constants.dart";-import "package:photos/db/files_db.dart";import "package:photos/generated/l10n.dart";import "package:photos/models/api/collection/user.dart";import 'package:photos/models/collection/collection.dart';-import "package:photos/models/file/file.dart";import 'package:photos/services/collections_service.dart';import 'package:photos/theme/ente_theme.dart';import 'package:photos/ui/actions/collection/collection_sharing_actions.dart';@@ -21,13 +18,10 @@ import 'package:photos/ui/sharing/album_participants_page.dart';import "package:photos/ui/sharing/album_share_info_widget.dart";import "package:photos/ui/sharing/manage_album_participant.dart";import 'package:photos/ui/sharing/manage_links_widget.dart';-import "package:photos/ui/sharing/show_images_prevew.dart";import 'package:photos/ui/sharing/user_avator_widget.dart';-import "package:photos/utils/dialog_util.dart";import 'package:photos/utils/navigation_util.dart';import 'package:photos/utils/share_util.dart';import 'package:photos/utils/toast_util.dart';-import "package:screenshot/screenshot.dart";class ShareCollectionPage extends StatefulWidget {final Collection collection;@@ -42,56 +36,8 @@ class _ShareCollectionPageState extends State<ShareCollectionPage> {late List<User?> _sharees;final CollectionActions collectionActions =CollectionActions(CollectionsService.instance);- final ScreenshotController screenshotController = ScreenshotController();final GlobalKey sendLinkButtonKey = GlobalKey();- Future<Uint8List> _createAlbumPlaceholder(- List<EnteFile> ownedSelectedFiles,- ) async {- final Widget imageWidget = LinkPlaceholder(- files: ownedSelectedFiles,- );- final double pixelRatio = MediaQuery.devicePixelRatioOf(context);- final bytesOfImageToWidget = await screenshotController.captureFromWidget(- imageWidget,- pixelRatio: pixelRatio,- targetSize: MediaQuery.sizeOf(context),- delay: const Duration(milliseconds: 300),- );- return bytesOfImageToWidget;- }-- Future<void> _shareAlbumLink(- BuildContext context,- Collection collection,- String url,- ) async {- final dialog = createProgressDialog(- context,- S.of(context).creatingLink,- isDismissible: true,- );- await dialog.show();-- final List<EnteFile> filesInCollection =- (await FilesDB.instance.getFilesInCollection(- collection.id,- galleryLoadStartTime,- galleryLoadEndTime,- ))- .files;-- final placeholderBytes = await _createAlbumPlaceholder(filesInCollection);- await dialog.hide();-- await shareImageAndUrl(- placeholderBytes,- url,- context: context,- key: sendLinkButtonKey,- );- }-Future<void> _navigateToManageUser() async {if (_sharees.length == 1) {await routeToPage(@@ -250,10 +196,11 @@ class _ShareCollectionPageState extends State<ShareCollectionPage> {menuItemColor: getEnteColorScheme(context).fillFaint,onTap: () async {// ignore: unawaited_futures- _shareAlbumLink(+ await shareAlbumLinkWithPlaceholder(context,widget.collection,url,+ sendLinkButtonKey,);},isTopBorderRadiusRemoved: true,diff --git a/mobile/lib/utils/share_util.dart b/mobile/lib/utils/share_util.dartindex ab39fedf11..4a97b3c98b 100644--- a/mobile/lib/utils/share_util.dart+++ b/mobile/lib/utils/share_util.dart@@ -8,13 +8,19 @@ import 'package:path/path.dart';import "package:photo_manager/photo_manager.dart";import 'package:photos/core/configuration.dart';import 'package:photos/core/constants.dart';+import "package:photos/db/files_db.dart";+import "package:photos/generated/l10n.dart";+import "package:photos/models/collection/collection.dart";import 'package:photos/models/file/file.dart';import 'package:photos/models/file/file_type.dart';+import "package:photos/services/collections_service.dart";+import "package:photos/ui/sharing/show_images_prevew.dart";import 'package:photos/utils/date_time_util.dart';import 'package:photos/utils/dialog_util.dart';import 'package:photos/utils/exif_util.dart';import 'package:photos/utils/file_util.dart';import 'package:receive_sharing_intent/receive_sharing_intent.dart';+import "package:screenshot/screenshot.dart";import 'package:share_plus/share_plus.dart';import "package:uuid/uuid.dart";@@ -261,3 +267,70 @@ Rect _sharePosOrigin(BuildContext? context, GlobalKey? key) {}return rect;}++/// The [ScreenshotController] is used to capture the image of a widget that serves as+/// a placeholder for an album link. The placeholder is then shared along with the album link.+final ScreenshotController screenshotController = ScreenshotController();++Future<Uint8List> _createAlbumPlaceholder(+ List<EnteFile> files,+ ScreenshotController screenshotController,+ BuildContext context,+) async {+ final Widget imageWidget = LinkPlaceholder(+ files: files,+ );+ final double pixelRatio = MediaQuery.devicePixelRatioOf(context);+ final bytesOfImageToWidget = await screenshotController.captureFromWidget(+ imageWidget,+ pixelRatio: pixelRatio,+ targetSize: MediaQuery.sizeOf(context),+ delay: const Duration(milliseconds: 300),+ );+ return bytesOfImageToWidget;+}++Future<void> shareAlbumLinkWithPlaceholder(+ BuildContext context,+ Collection collection,+ String url,+ GlobalKey key,+) async {+ final int fileCount =+ await CollectionsService.instance.getFileCount(collection);++ final dialog = createProgressDialog(+ context,+ S.of(context).creatingLink,+ isDismissible: true,+ );+ await dialog.show();++ if (fileCount == 0) {+ await dialog.hide();+ await shareText(url);+ return;+ } else {+ final List<EnteFile> filesInCollection =+ (await FilesDB.instance.getFilesInCollection(+ collection.id,+ galleryLoadStartTime,+ galleryLoadEndTime,+ ))+ .files;++ final placeholderBytes = await _createAlbumPlaceholder(+ filesInCollection,+ screenshotController,+ context,+ );+ await dialog.hide();++ await shareImageAndUrl(+ placeholderBytes,+ url,+ context: context,+ key: key,+ );+ }+}