diff --git a/evently/lib/repository/repository.dart b/evently/lib/repository/repository.dart index cbb7639995..74176fa944 100644 --- a/evently/lib/repository/repository.dart +++ b/evently/lib/repository/repository.dart @@ -1,6 +1,13 @@ +import 'package:evently/utils/file_utils_helper.dart'; import 'package:injectable/injectable.dart'; abstract class Repository {} @LazySingleton(as: Repository) -class RepositoryImp implements Repository {} +class RepositoryImp implements Repository { + + RepositoryImp({required this.fileUtilsHelper}); + + final FileUtilsHelper fileUtilsHelper; + +} diff --git a/evently/lib/utils/constants.dart b/evently/lib/utils/constants.dart index a0cc943487..26c719db33 100644 --- a/evently/lib/utils/constants.dart +++ b/evently/lib/utils/constants.dart @@ -26,6 +26,9 @@ const kMaxPriceLength = 14; const int kBigIntBase = 1000000; const int kEthIntBase = 1000000000000000000; +final List imageAllowedExts = ["png", "jpg", "jpeg", "heif"]; +const kPylons = "Pylons"; + /// ```SVG assets class SVGUtils { static const kSvgSplash = 'assets/images/svg/splash.svg'; @@ -48,6 +51,7 @@ class PngUtils { static const kIconDenomUsd = 'assets/images/denom_usd.png'; static const kIconDenomPylon = 'assets/images/denom_pylon.png'; static const kHostPreview = "assets/images/host_preview.png"; + /// will remove this variable for ui dev /// i need this variable to be used static const kPhantom = "assets/images/phantom.png"; diff --git a/evently/lib/utils/file_utils_helper.dart b/evently/lib/utils/file_utils_helper.dart index a09f9f18bb..ea6a92027e 100644 --- a/evently/lib/utils/file_utils_helper.dart +++ b/evently/lib/utils/file_utils_helper.dart @@ -1,39 +1,17 @@ -import 'dart:io'; -import 'dart:math'; - import 'package:evently/models/picked_file_model.dart'; - -import '../generated/locale_keys.g.dart'; - +import 'package:evently/utils/constants.dart'; +import 'package:evently/utils/evently_app_theme.dart'; +import 'package:file_picker/file_picker.dart'; +import 'package:flutter/material.dart'; +import 'package:image_cropper/image_cropper.dart'; +import 'package:injectable/injectable.dart'; + +@lazySingleton abstract class FileUtilsHelper { /// This function picks a file with the given format from device storage /// Input: [format] it is the file format which needs to be picked from local storage /// returns [PlatformFile] the selected file or null if aborted Future pickFile(); - - /// This function is used to get the file size in String format - /// Input: [fileLength] the file length in bytes and [precision] - /// Output: [String] returns the file size in String format - String getFileSizeString({required int fileLength, required int precision}); - - /// This function is used to generate the NFT link to be shared with others after publishing - /// Input: [recipeId] and [cookbookId] used in the link generation as query parameters - /// Output: [String] returns the generated NFTs link to be shared with others - String generateEaselLinkForShare({required String recipeId, required String cookbookId}); - - /// This function is used to generate the NFT link to be open in the pylons wallet - /// Input: [recipeId] and [cookbookId] used in the link generation as query parameters - /// Output: [String] returns the generated NFTs link to be shared with others - String generateEventlyLinkForOpeningInPylonsApp({required String recipeId, required String cookbookId}); - - /// This function is used to launch the link generated and open the link in external source platform - /// Input: [url] is the link to be launched by the launcher - Future launchMyUrl({required String url}); - - /// This function will copy the file to internal memory returns the updated path - /// Input: [filePickerResult] is the filePickerResult instance of the file to be copied - /// Output: [String] This will return the updated filePath - Future copyFileToInternal({required FilePickerResult filePickerResult}); } class FileUtilsHelperImpl implements FileUtilsHelper { @@ -44,36 +22,7 @@ class FileUtilsHelperImpl implements FileUtilsHelper { @override Future pickFile() async { - FileType type; - List? allowedExtensions; - switch (format.format) { - case NFTTypes.image: - if (Platform.isAndroid) { - type = FileType.custom; - allowedExtensions = imageAllowedExts; - break; - } - type = FileType.image; - break; - - case NFTTypes.video: - type = FileType.video; - break; - - case NFTTypes.audio: - if (!Platform.isAndroid) { - type = FileType.custom; - allowedExtensions = audioAllowedExts; - } else { - type = FileType.audio; - } - break; - default: - type = FileType.any; - break; - } - - final FilePickerResult? result = await filePicker.pickFiles(type: type, allowedExtensions: allowedExtensions); + final FilePickerResult? result = await filePicker.pickFiles(type: FileType.image, allowedExtensions: imageAllowedExts); if (result == null) { return PickedFileModel( @@ -83,15 +32,7 @@ class FileUtilsHelperImpl implements FileUtilsHelper { ); } - if (format.format == NFTTypes.threeD && result.files.single.path != null) { - final newFile = await copyFileToInternal(filePickerResult: result); - return PickedFileModel( - path: newFile.path, - fileName: newFile.path.split('/').last, - extension: result.files.single.extension ?? "", - ); - } - if (format.format == NFTTypes.image && result.files.single.path != null && result.files.single.extension != 'gif') { + if (result.files.single.path != null) { final cropperImage = await cropImage(filePath: result.files.single.path!); return PickedFileModel( path: cropperImage, @@ -107,34 +48,13 @@ class FileUtilsHelperImpl implements FileUtilsHelper { ); } - @override - String getFileSizeString({required int fileLength, required int precision}) { - final i = (log(fileLength) / log(1024)).floor(); - return ((fileLength / pow(1024, i)).toStringAsFixed(precision)) + suffixes[i]; - } - - @override - String generateEaselLinkForShare({required String recipeId, required String cookbookId}) { - return "$kWalletWebLink/?action=purchase_nft&recipe_id=$recipeId&cookbook_id=$cookbookId"; - } - - @override - Future launchMyUrl({required String url}) async { - final canLaunch = await canLaunchUrlString(url); - if (canLaunch) { - launchUrlString(url, mode: LaunchMode.externalApplication); - } else { - throw LocaleKeys.cannot_launch_url.tr(); - } - } - Future cropImage({required String filePath}) async { try { final CroppedFile? croppedFile = await imageCropper.cropImage( sourcePath: filePath, aspectRatioPresets: [CropAspectRatioPreset.square, CropAspectRatioPreset.ratio3x2, CropAspectRatioPreset.original, CropAspectRatioPreset.ratio4x3, CropAspectRatioPreset.ratio16x9], uiSettings: [ - AndroidUiSettings(toolbarTitle: kPylons, toolbarColor: EaselAppTheme.kBlue, toolbarWidgetColor: Colors.white, initAspectRatio: CropAspectRatioPreset.original, lockAspectRatio: false), + AndroidUiSettings(toolbarTitle: kPylons, toolbarColor: EventlyAppTheme.kBlue, toolbarWidgetColor: Colors.white, initAspectRatio: CropAspectRatioPreset.original, lockAspectRatio: false), IOSUiSettings( title: kPylons, ), @@ -145,36 +65,4 @@ class FileUtilsHelperImpl implements FileUtilsHelper { return ""; } } - - @override - String generateEventlyLinkForOpeningInPylonsApp({required String recipeId, required String cookbookId}) { - return Uri.https('pylons.page.link', "/", { - kAmvKey: "1", - kApnKey: "tech.pylons.wallet", - kIbiKey: "xyz.pylons.wallet", - kImvKey: "1", - kLinkKey: "https://wallet.pylons.tech/?action=purchase_nft&recipe_id=$recipeId&cookbook_id=$cookbookId&nft_amount=1" - }).toString(); - } - - @override - Future copyFileToInternal({required FilePickerResult filePickerResult}) async { - await deleteFilesIfAlreadyPresent(); - final tempDirectory = await getTemporaryDirectory(); - return File(filePickerResult.files.single.path.toString()).copySync('${tempDirectory.path}/$k3dFileName.${filePickerResult.files.single.extension}'); - } - - Future deleteFilesIfAlreadyPresent() async { - final tempDirectory = await getTemporaryDirectory(); - - final fileRef1 = File('${tempDirectory.path}/$k3dFileName.${threedAllowedExts[0]}'); - final fileRef2 = File('${tempDirectory.path}/$k3dFileName.${threedAllowedExts[1]}'); - - if (fileRef1.existsSync()) { - fileRef1.deleteSync(); - } - if (fileRef2.existsSync()) { - fileRef2.deleteSync(); - } - } }