Compare commits

...

2 commits

Author SHA1 Message Date
Aman Raj Singh Mourya acf7b3a865 Merge branch 'main' into placeholder_for_link 2024-05-27 14:39:37 +05:30
Aman Raj Singh Mourya 8f1119525b [mob][photos] placeholder for link 1st draft 2024-05-27 14:38:48 +05:30
6 changed files with 918 additions and 1 deletions

View file

@ -0,0 +1,65 @@
// import "dart:typed_data";
// import 'dart:ui' as ui;
// import 'package:flutter/material.dart';
// import 'package:flutter/rendering.dart';
// class Captures {
// static Future<Uint8List> capture(GlobalKey key) async {
// final double pixelRatio =
// MediaQuery.of(key.currentContext!).devicePixelRatio;
// final RenderRepaintBoundary boundary =
// key.currentContext!.findRenderObject()! as RenderRepaintBoundary;
// final ui.Image image = await boundary.toImage(pixelRatio: pixelRatio);
// final ByteData? byteData =
// await image.toByteData(format: ui.ImageByteFormat.png);
// final Uint8List pngBytes = byteData!.buffer.asUint8List();
// print("PNG BYTES ====== ${pngBytes}");
// return pngBytes;
// }
// }
import "dart:io";
import 'dart:typed_data';
import 'dart:ui' as ui;
import 'package:flutter/material.dart';
import 'package:flutter/rendering.dart';
import "package:path_provider/path_provider.dart";
class Captures {
Future<Uint8List?> capture(GlobalKey key) async {
try {
final double pixelRatio =
MediaQuery.of(key.currentContext!).devicePixelRatio;
final RenderRepaintBoundary boundary =
key.currentContext!.findRenderObject()! as RenderRepaintBoundary;
final ui.Image image = await boundary.toImage(pixelRatio: pixelRatio);
final ByteData? byteData =
await image.toByteData(format: ui.ImageByteFormat.png);
final Uint8List pngBytes = byteData!.buffer.asUint8List();
print("PNG BYTES ====== ${pngBytes}");
return pngBytes;
} catch (e) {
print(e);
}
return null;
}
Future<String> saveImage(GlobalKey key) async {
String path = "";
try {
final Uint8List? bytes = await capture(key);
final Directory root = await getTemporaryDirectory();
final String directoryPath = '${root.path}/enteTempFiles';
// Create the directory if it doesn't exist
final DateTime timeStamp = DateTime.now();
await Directory(directoryPath).create(recursive: true);
final String filePath = '$directoryPath/$timeStamp.jpg';
final file = await File(filePath).writeAsBytes(bytes!);
path = file.path;
} catch (e) {
debugPrint(e.toString());
}
return path;
}
}

View file

@ -0,0 +1,790 @@
import "dart:ui";
import "package:figma_squircle/figma_squircle.dart";
import "package:flutter/material.dart";
import "package:photos/models/file/file.dart";
import "package:photos/ui/TEMP/captureImage.dart";
import "package:photos/ui/TEMP/widget_to_image.dart";
import "package:photos/ui/viewer/file/thumbnail_widget.dart";
class ShowImagePreviewFromTap extends StatefulWidget {
const ShowImagePreviewFromTap({
required this.tempEnteFile,
super.key,
});
final List<EnteFile> tempEnteFile;
@override
State<ShowImagePreviewFromTap> createState() =>
_ShowImagePreviewFromTapState();
}
class _ShowImagePreviewFromTapState extends State<ShowImagePreviewFromTap> {
// late String tempImagePath;
// final ValueNotifier<Uint8List?> bytesNotifier =
// ValueNotifier<Uint8List?>(null);
late GlobalKey _widgetImageKey;
final ValueNotifier<String?> tempImagePath = ValueNotifier<String?>(null);
@override
void initState() {
super.initState();
WidgetsBinding.instance.addPostFrameCallback((_) async {
//delay of 1 second before capturing the image
await Future.delayed(const Duration(milliseconds: 100));
tempImagePath.value = await Captures().saveImage(_widgetImageKey);
Navigator.of(context).pop(tempImagePath.value);
});
}
@override
Widget build(BuildContext context) {
final int length = widget.tempEnteFile.length;
Widget placeholderWidget = const SizedBox(
height: 250,
width: 250,
);
if (length == 1) {
placeholderWidget = BackDrop(
backDropImage: widget.tempEnteFile[0],
children: [
Padding(
padding: const EdgeInsets.all(18.0),
child: ClipSmoothRect(
radius: SmoothBorderRadius(
cornerRadius: 7.5,
cornerSmoothing: 1,
),
child: ThumbnailWidget(
widget.tempEnteFile[0],
shouldShowArchiveStatus: false,
shouldShowSyncStatus: false,
),
),
),
],
);
} else if (length == 2) {
placeholderWidget = BackDrop(
backDropImage: widget.tempEnteFile[0],
children: [
Positioned(
top: 65,
left: 90,
child: CustomImage(
height: 100,
width: 100,
collages: widget.tempEnteFile[0],
zIndex: 0.2,
),
),
Positioned(
top: 20,
left: 0,
child: CustomImage(
height: 100,
width: 100,
collages: widget.tempEnteFile[1],
zIndex: -0.2,
),
),
],
);
} else if (length == 3) {
placeholderWidget = BackDrop(
backDropImage: widget.tempEnteFile[0],
children: [
Positioned(
top: 30,
left: 0,
child: CustomImage(
height: 80,
width: 80,
collages: widget.tempEnteFile[1],
zIndex: -0.4,
),
),
Positioned(
top: 80,
left: 110,
child: CustomImage(
height: 80,
width: 80,
collages: widget.tempEnteFile[2],
zIndex: 0.4,
),
),
Positioned(
top: 40,
left: 40,
child: CustomImage(
height: 100,
width: 100,
collages: widget.tempEnteFile[0],
zIndex: 0.0,
),
),
],
);
} else if (length > 3) {
placeholderWidget = BackDrop(
backDropImage: widget.tempEnteFile[0],
children: [
Positioned(
top: 10,
left: 10,
child: CustomImage(
height: 80,
width: 80,
collages: widget.tempEnteFile[1],
zIndex: 0,
),
),
Positioned(
top: 95,
left: 30,
child: CustomImage(
height: 80,
width: 80,
collages: widget.tempEnteFile[2],
zIndex: 0,
),
),
Positioned(
top: 35,
left: 60,
child: CustomImage(
height: 100,
width: 100,
collages: widget.tempEnteFile[0],
zIndex: 0.0,
),
),
Positioned(
top: 15,
left: 140,
child: Container(
padding: const EdgeInsets.all(8),
decoration: BoxDecoration(
color: Colors.white,
borderRadius: BorderRadius.circular(12),
),
child: Text(
"+" "$length",
style: const TextStyle(
fontWeight: FontWeight.w600,
color: Colors.black,
),
),
),
),
],
);
}
return Offstage(
offstage: false,
child: Center(
child: Column(
children: [
WidgetToImage(
builder: (key) {
_widgetImageKey = key;
return placeholderWidget;
},
),
],
),
),
);
}
}
class BackDrop extends StatelessWidget {
const BackDrop({
super.key,
required this.backDropImage,
required this.children,
});
final List<Widget> children;
final EnteFile backDropImage;
@override
Widget build(BuildContext context) {
return Container(
padding: const EdgeInsets.all(4.0),
height: 200,
width: 200,
child: Stack(
children: [
ClipSmoothRect(
radius: SmoothBorderRadius(
cornerRadius: 7.5,
cornerSmoothing: 1,
),
child: ThumbnailWidget(
backDropImage,
shouldShowArchiveStatus: false,
shouldShowSyncStatus: false,
),
),
BackdropFilter(
filter: ImageFilter.blur(sigmaX: 5, sigmaY: 5),
child: Container(
color: Colors.transparent,
),
),
...children,
],
),
);
}
}
class CustomImage extends StatelessWidget {
const CustomImage({
required this.width,
required this.height,
super.key,
required this.collages,
required this.zIndex,
});
final EnteFile collages;
final double zIndex;
final double height;
final double width;
@override
Widget build(BuildContext context) {
return Container(
transform: Matrix4.rotationZ(zIndex),
height: height,
width: width,
child: ClipSmoothRect(
radius: SmoothBorderRadius(
cornerRadius: 7.5,
cornerSmoothing: 1,
),
clipBehavior: Clip.antiAliasWithSaveLayer,
child: ThumbnailWidget(
collages,
shouldShowArchiveStatus: false,
shouldShowSyncStatus: false,
),
),
);
}
}
// import "dart:ui";
// import "package:figma_squircle/figma_squircle.dart";
// import "package:flutter/material.dart";
// import "package:photos/models/file/file.dart";
// import "package:photos/ui/TEMP/captureImage.dart";
// import "package:photos/ui/TEMP/widget_to_image.dart";
// import "package:photos/ui/viewer/file/thumbnail_widget.dart";
// class ShowImagePrev {
// late GlobalKey _widgetImageKey;
// final ValueNotifier<String?> tempImagePath = ValueNotifier<String?>(null);
// Future<String?> imageToWidgetFunction(List<EnteFile> tempEnteFile) async {
// showImagePreviewFromTap(tempEnteFile);
// await Future.delayed(const Duration(milliseconds: 100));
// tempImagePath.value = await Captures().saveImage(_widgetImageKey);
// print("VALUE IS ==================${tempImagePath.value}");
// if (tempImagePath.value != null) {
// return tempImagePath.value;
// }
// return null;
// }
// Widget showImagePreviewFromTap(List<EnteFile> tempEnteFile) {
// final int length = tempEnteFile.length;
// Widget placeholderWidget = const SizedBox(
// height: 250,
// width: 250,
// );
// if (length == 1) {
// placeholderWidget = BackDrop(
// backDropImage: tempEnteFile[0],
// children: [
// Padding(
// padding: const EdgeInsets.all(18.0),
// child: ClipSmoothRect(
// radius: SmoothBorderRadius(
// cornerRadius: 7.5,
// cornerSmoothing: 1,
// ),
// child: ThumbnailWidget(
// tempEnteFile[0],
// shouldShowArchiveStatus: false,
// shouldShowSyncStatus: false,
// ),
// ),
// ),
// ],
// );
// } else if (length == 2) {
// placeholderWidget = BackDrop(
// backDropImage: tempEnteFile[0],
// children: [
// Positioned(
// top: 65,
// left: 90,
// child: CustomImage(
// height: 100,
// width: 100,
// collages: tempEnteFile[0],
// zIndex: 0.2,
// ),
// ),
// Positioned(
// top: 20,
// left: 0,
// child: CustomImage(
// height: 100,
// width: 100,
// collages: tempEnteFile[1],
// zIndex: -0.2,
// ),
// ),
// ],
// );
// } else if (length == 3) {
// placeholderWidget = BackDrop(
// backDropImage: tempEnteFile[0],
// children: [
// Positioned(
// top: 30,
// left: 0,
// child: CustomImage(
// height: 80,
// width: 80,
// collages: tempEnteFile[1],
// zIndex: -0.4,
// ),
// ),
// Positioned(
// top: 80,
// left: 110,
// child: CustomImage(
// height: 80,
// width: 80,
// collages: tempEnteFile[2],
// zIndex: 0.4,
// ),
// ),
// Positioned(
// top: 40,
// left: 40,
// child: CustomImage(
// height: 100,
// width: 100,
// collages: tempEnteFile[0],
// zIndex: 0.0,
// ),
// ),
// ],
// );
// } else if (length > 3) {
// placeholderWidget = BackDrop(
// backDropImage: tempEnteFile[0],
// children: [
// Positioned(
// top: 10,
// left: 10,
// child: CustomImage(
// height: 80,
// width: 80,
// collages: tempEnteFile[1],
// zIndex: 0,
// ),
// ),
// Positioned(
// top: 95,
// left: 30,
// child: CustomImage(
// height: 80,
// width: 80,
// collages: tempEnteFile[2],
// zIndex: 0,
// ),
// ),
// Positioned(
// top: 35,
// left: 60,
// child: CustomImage(
// height: 100,
// width: 100,
// collages: tempEnteFile[0],
// zIndex: 0.0,
// ),
// ),
// Positioned(
// top: 15,
// left: 140,
// child: Container(
// padding: const EdgeInsets.all(8),
// decoration: BoxDecoration(
// color: Colors.white,
// borderRadius: BorderRadius.circular(12),
// ),
// child: Text(
// "+ $length",
// style: const TextStyle(
// fontWeight: FontWeight.w600,
// color: Colors.black,
// ),
// ),
// ),
// ),
// ],
// );
// }
// return Center(
// child: WidgetToImage(
// builder: (key) {
// _widgetImageKey = key;
// return placeholderWidget;
// },
// ),
// );
// }
// }
// class BackDrop extends StatelessWidget {
// const BackDrop({
// super.key,
// required this.backDropImage,
// required this.children,
// });
// final List<Widget> children;
// final EnteFile backDropImage;
// @override
// Widget build(BuildContext context) {
// return Container(
// padding: const EdgeInsets.all(4.0),
// height: 200,
// width: 200,
// child: Stack(
// children: [
// ClipSmoothRect(
// radius: SmoothBorderRadius(
// cornerRadius: 7.5,
// cornerSmoothing: 1,
// ),
// child: ThumbnailWidget(
// backDropImage,
// shouldShowArchiveStatus: false,
// shouldShowSyncStatus: false,
// ),
// ),
// BackdropFilter(
// filter: ImageFilter.blur(sigmaX: 5, sigmaY: 5),
// child: Container(
// color: Colors.transparent,
// ),
// ),
// ...children,
// ],
// ),
// );
// }
// }
// class CustomImage extends StatelessWidget {
// const CustomImage({
// required this.width,
// required this.height,
// super.key,
// required this.collages,
// required this.zIndex,
// });
// final EnteFile collages;
// final double zIndex;
// final double height;
// final double width;
// @override
// Widget build(BuildContext context) {
// return Container(
// transform: Matrix4.rotationZ(zIndex),
// height: height,
// width: width,
// child: ClipSmoothRect(
// radius: SmoothBorderRadius(
// cornerRadius: 7.5,
// cornerSmoothing: 1,
// ),
// clipBehavior: Clip.antiAliasWithSaveLayer,
// child: ThumbnailWidget(
// collages,
// shouldShowArchiveStatus: false,
// shouldShowSyncStatus: false,
// ),
// ),
// );
// }
// }
// import "dart:ui";
// import "package:figma_squircle/figma_squircle.dart";
// import "package:flutter/material.dart";
// import "package:photos/models/file/file.dart";
// import "package:photos/ui/TEMP/captureImage.dart";
// import "package:photos/ui/TEMP/widget_to_image.dart";
// import "package:photos/ui/viewer/file/thumbnail_widget.dart";
// class ShowImagePrev {
// late GlobalKey _widgetImageKey;
// final ValueNotifier<String?> tempImagePath = ValueNotifier<String?>(null);
// ShowImagePrev() {
// _widgetImageKey = GlobalKey();
// }
// Future<String?> imageToWidgetFunction(List<EnteFile> tempEnteFile) async {
// showImagePreviewFromTap(tempEnteFile);
// // Build the widget to ensure the GlobalKey is assigned correctly
// WidgetsBinding.instance.addPostFrameCallback((_) async {
// await Future.delayed(const Duration(milliseconds: 100));
// tempImagePath.value = await Captures().saveImage(_widgetImageKey);
// print("VALUE IS ==================${tempImagePath.value}");
// });
// return tempImagePath.value;
// }
// Widget showImagePreviewFromTap(List<EnteFile> tempEnteFile) {
// final int length = tempEnteFile.length;
// Widget placeholderWidget = const SizedBox(
// height: 250,
// width: 250,
// );
// if (length == 1) {
// placeholderWidget = BackDrop(
// backDropImage: tempEnteFile[0],
// children: [
// Padding(
// padding: const EdgeInsets.all(18.0),
// child: ClipSmoothRect(
// radius: SmoothBorderRadius(
// cornerRadius: 7.5,
// cornerSmoothing: 1,
// ),
// child: ThumbnailWidget(
// tempEnteFile[0],
// shouldShowArchiveStatus: false,
// shouldShowSyncStatus: false,
// ),
// ),
// ),
// ],
// );
// } else if (length == 2) {
// placeholderWidget = BackDrop(
// backDropImage: tempEnteFile[0],
// children: [
// Positioned(
// top: 65,
// left: 90,
// child: CustomImage(
// height: 100,
// width: 100,
// collages: tempEnteFile[0],
// zIndex: 0.2,
// ),
// ),
// Positioned(
// top: 20,
// left: 0,
// child: CustomImage(
// height: 100,
// width: 100,
// collages: tempEnteFile[1],
// zIndex: -0.2,
// ),
// ),
// ],
// );
// } else if (length == 3) {
// placeholderWidget = BackDrop(
// backDropImage: tempEnteFile[0],
// children: [
// Positioned(
// top: 30,
// left: 0,
// child: CustomImage(
// height: 80,
// width: 80,
// collages: tempEnteFile[1],
// zIndex: -0.4,
// ),
// ),
// Positioned(
// top: 80,
// left: 110,
// child: CustomImage(
// height: 80,
// width: 80,
// collages: tempEnteFile[2],
// zIndex: 0.4,
// ),
// ),
// Positioned(
// top: 40,
// left: 40,
// child: CustomImage(
// height: 100,
// width: 100,
// collages: tempEnteFile[0],
// zIndex: 0.0,
// ),
// ),
// ],
// );
// } else if (length > 3) {
// placeholderWidget = BackDrop(
// backDropImage: tempEnteFile[0],
// children: [
// Positioned(
// top: 10,
// left: 10,
// child: CustomImage(
// height: 80,
// width: 80,
// collages: tempEnteFile[1],
// zIndex: 0,
// ),
// ),
// Positioned(
// top: 95,
// left: 30,
// child: CustomImage(
// height: 80,
// width: 80,
// collages: tempEnteFile[2],
// zIndex: 0,
// ),
// ),
// Positioned(
// top: 35,
// left: 60,
// child: CustomImage(
// height: 100,
// width: 100,
// collages: tempEnteFile[0],
// zIndex: 0.0,
// ),
// ),
// Positioned(
// top: 15,
// left: 140,
// child: Container(
// padding: const EdgeInsets.all(8),
// decoration: BoxDecoration(
// color: Colors.white,
// borderRadius: BorderRadius.circular(12),
// ),
// child: Text(
// "+ $length",
// style: const TextStyle(
// fontWeight: FontWeight.w600,
// color: Colors.black,
// ),
// ),
// ),
// ),
// ],
// );
// }
// return Center(
// child: WidgetToImage(
// builder: (key) {
// _widgetImageKey = key;
// return placeholderWidget;
// },
// ),
// );
// }
// }
// class BackDrop extends StatelessWidget {
// const BackDrop({
// super.key,
// required this.backDropImage,
// required this.children,
// });
// final List<Widget> children;
// final EnteFile backDropImage;
// @override
// Widget build(BuildContext context) {
// return Container(
// padding: const EdgeInsets.all(4.0),
// height: 200,
// width: 200,
// child: Stack(
// children: [
// ClipSmoothRect(
// radius: SmoothBorderRadius(
// cornerRadius: 7.5,
// cornerSmoothing: 1,
// ),
// child: ThumbnailWidget(
// backDropImage,
// shouldShowArchiveStatus: false,
// shouldShowSyncStatus: false,
// ),
// ),
// BackdropFilter(
// filter: ImageFilter.blur(sigmaX: 5, sigmaY: 5),
// child: Container(
// color: Colors.transparent,
// ),
// ),
// ...children,
// ],
// ),
// );
// }
// }
// class CustomImage extends StatelessWidget {
// const CustomImage({
// required this.width,
// required this.height,
// super.key,
// required this.collages,
// required this.zIndex,
// });
// final EnteFile collages;
// final double zIndex;
// final double height;
// final double width;
// @override
// Widget build(BuildContext context) {
// return Container(
// transform: Matrix4.rotationZ(zIndex),
// height: height,
// width: width,
// child: ClipSmoothRect(
// radius: SmoothBorderRadius(
// cornerRadius: 7.5,
// cornerSmoothing: 1,
// ),
// clipBehavior: Clip.antiAliasWithSaveLayer,
// child: ThumbnailWidget(
// collages,
// shouldShowArchiveStatus: false,
// shouldShowSyncStatus: false,
// ),
// ),
// );
// }
// }

View file

@ -0,0 +1,19 @@
import "package:flutter/material.dart";
class WidgetToImage extends StatefulWidget {
const WidgetToImage({super.key, required this.builder});
final Function(GlobalKey key) builder;
@override
State<WidgetToImage> createState() => _WidgetToImageState();
}
class _WidgetToImageState extends State<WidgetToImage> {
final globalKey = GlobalKey();
@override
Widget build(BuildContext context) {
return RepaintBoundary(
key: globalKey,
child: widget.builder(globalKey),
);
}
}

View file

@ -110,6 +110,7 @@ class CollectionActions {
BuildContext context,
List<EnteFile> files,
) async {
print("CREATED LINK");
final dialog = createProgressDialog(
context,
S.of(context).creatingLink,

View file

@ -25,6 +25,7 @@ import 'package:photos/services/machine_learning/face_ml/feedback/cluster_feedba
import "package:photos/services/machine_learning/face_ml/person/person_service.dart";
import "package:photos/theme/colors.dart";
import "package:photos/theme/ente_theme.dart";
import "package:photos/ui/TEMP/show_images_prevew.dart";
import 'package:photos/ui/actions/collection/collection_file_actions.dart';
import 'package:photos/ui/actions/collection/collection_sharing_actions.dart';
import 'package:photos/ui/collections/collection_action_sheet.dart';
@ -602,6 +603,25 @@ class _FileSelectionActionsWidgetState
}
}
ValueNotifier<String?> generatedPathNotifier = ValueNotifier<String?>(null);
//Future function to go to next page
Future<String?> _nextPageForTesting(List<EnteFile> tempfile) async {
final String? tempImagePath = await Navigator.of(context).push(
MaterialPageRoute(
builder: (context) => ShowImagePreviewFromTap(
tempEnteFile: tempfile,
),
),
);
if (tempImagePath != null) {
print("Temp image path: $tempImagePath");
return tempImagePath;
}
return tempImagePath;
}
Future<void> _onCreatedSharedLinkClicked() async {
if (split.ownedByCurrentUser.isEmpty) {
showShortToast(
@ -612,16 +632,26 @@ class _FileSelectionActionsWidgetState
}
_cachedCollectionForSharedLink ??= await collectionActions
.createSharedCollectionLink(context, split.ownedByCurrentUser);
final List<EnteFile> tempEnteFile = split.ownedByCurrentUser;
final actionResult = await showActionSheet(
context: context,
buttons: [
ButtonWidget(
labelText: S.of(context).copyLink,
labelText: S.of(context).shareLink,
buttonType: ButtonType.neutral,
buttonSize: ButtonSize.large,
shouldStickToDarkTheme: true,
buttonAction: ButtonAction.first,
isInAlert: true,
// onTap: () async {
// // Add a return statement at the end of the function
// generatedPathNotifier.value =
// await _nextPageForTesting(tempEnteFile);
// await shareText(generatedPathNotifier.value!);
// return Future<void>.value();
// },
),
ButtonWidget(
labelText: S.of(context).manageLink,
@ -646,6 +676,7 @@ class _FileSelectionActionsWidgetState
);
if (actionResult?.action != null) {
if (actionResult!.action == ButtonAction.first) {
//generatedPathNotifier.value = await _nextPageForTesting(tempEnteFile);
await _copyLink();
}
if (actionResult.action == ButtonAction.second) {
@ -757,6 +788,7 @@ class _FileSelectionActionsWidgetState
}
Future<void> _copyLink() async {
print("INSIDE COPY LINK");
if (_cachedCollectionForSharedLink != null) {
final String collectionKey = Base58Encode(
CollectionsService.instance
@ -764,6 +796,8 @@ class _FileSelectionActionsWidgetState
);
final String url =
"${_cachedCollectionForSharedLink!.publicURLs?.first?.url}#$collectionKey";
await shareText(url);
//await shareImageAndUrl(context, generatedPathNotifier.value!, url);
await Clipboard.setData(ClipboardData(text: url));
showShortToast(context, S.of(context).linkCopiedToClipboard);
}

View file

@ -218,3 +218,11 @@ void shareSelected(
shareButtonKey: shareButtonKey,
);
}
Future<void> shareImageAndUrl(
BuildContext context,
String imagePath,
String url,
) async {
await Share.shareFiles([imagePath], text: url);
}