From 3e18eca25cfa91932fce171dfcc6c9605b872e1f Mon Sep 17 00:00:00 2001 From: sonle Date: Tue, 26 Dec 2023 16:34:45 +0700 Subject: [PATCH] chore: create common to avoid duplicating --- lib/data_models/enums/group_card_state.dart | 2 +- lib/data_models/menu_item.dart | 2 +- lib/desktop_routes/desktop_route_names.dart | 18 +- lib/desktop_routes/desktop_routes.dart | 28 - .../dektop_custom_person_tile.dart | 88 -- .../desktop_custom_input_field.dart | 99 --- .../desktop_custom_vertical_tile.dart | 81 -- .../desktop_header.dart | 78 -- .../desktop_person_vertical_tile.dart | 134 ---- .../desktop_selected_contacts.dart | 77 -- .../desktop_selected_files.dart | 131 --- .../desktop_switch_atsign.dart | 189 ----- .../person_vertical_tile.dart | 164 ---- .../desktop_download_all_file.dart | 211 ----- .../desktop_history/desktop_history.dart | 430 ---------- .../desktop_received_file_details.dart | 546 ------------- .../desktop_received_file_list_tile.dart | 755 ------------------ .../widgets/desktop_sent_file_details.dart | 258 ------ .../widgets/desktop_sent_file_list_tile.dart | 632 --------------- .../widgets/desktop_transfer_overlapping.dart | 199 ----- .../desktop_trusted_sender.dart | 309 ------- .../widgets/desktop_empty_trusted_sender.dart | 158 ---- .../widgets/desktop_custom_app_bar.dart | 103 +-- .../widgets/desktop_filter_option_item.dart | 4 +- .../my_files_screen/utils/file_category.dart | 2 +- .../desktop_trusted.dart | 92 +-- .../welcome_screen/widgets/sidebar_item.dart | 6 +- .../common_widgets/custom_circle_avatar.dart | 1 - lib/screens/common_widgets/search_widget.dart | 4 +- .../widget/contact_attachment_card.dart | 228 +----- .../widgets/group_contact_list_tile.dart | 1 - .../history/widgets/filter_option_item.dart | 2 +- .../history/widgets/history_card_item.dart | 2 +- .../history/widgets/history_file_item.dart | 308 +------ lib/screens/my_files/files_detail_screen.dart | 164 ++-- .../welcome_screen/welcome_screen.dart | 7 +- lib/services/common_utility_functions.dart | 266 +++++- lib/services/file_transfer_service.dart | 7 +- lib/services/local_notification_service.dart | 3 +- lib/services/overlay_service.dart | 3 +- lib/utils/file_utils.dart | 40 +- lib/utils/images.dart | 2 +- .../welcome_screen_view_model.dart | 2 +- 43 files changed, 482 insertions(+), 5354 deletions(-) delete mode 100644 lib/desktop_screens/desktop_common_widgets/dektop_custom_person_tile.dart delete mode 100644 lib/desktop_screens/desktop_common_widgets/desktop_custom_input_field.dart delete mode 100644 lib/desktop_screens/desktop_common_widgets/desktop_custom_vertical_tile.dart delete mode 100644 lib/desktop_screens/desktop_common_widgets/desktop_header.dart delete mode 100644 lib/desktop_screens/desktop_common_widgets/desktop_person_vertical_tile.dart delete mode 100644 lib/desktop_screens/desktop_common_widgets/desktop_selected_contacts.dart delete mode 100644 lib/desktop_screens/desktop_common_widgets/desktop_selected_files.dart delete mode 100644 lib/desktop_screens/desktop_common_widgets/desktop_switch_atsign.dart delete mode 100644 lib/desktop_screens/desktop_common_widgets/person_vertical_tile.dart delete mode 100644 lib/desktop_screens/desktop_download_all_files/desktop_download_all_file.dart delete mode 100644 lib/desktop_screens/desktop_history/desktop_history.dart delete mode 100644 lib/desktop_screens/desktop_history/widgets/desktop_received_file_details.dart delete mode 100644 lib/desktop_screens/desktop_history/widgets/desktop_received_file_list_tile.dart delete mode 100644 lib/desktop_screens/desktop_history/widgets/desktop_sent_file_details.dart delete mode 100644 lib/desktop_screens/desktop_history/widgets/desktop_sent_file_list_tile.dart delete mode 100644 lib/desktop_screens/desktop_history/widgets/desktop_transfer_overlapping.dart delete mode 100644 lib/desktop_screens/trusted_sender/desktop_trusted_sender.dart delete mode 100644 lib/desktop_screens/trusted_sender/widgets/desktop_empty_trusted_sender.dart diff --git a/lib/data_models/enums/group_card_state.dart b/lib/data_models/enums/group_card_state.dart index fcba5e06..eaed74b2 100644 --- a/lib/data_models/enums/group_card_state.dart +++ b/lib/data_models/enums/group_card_state.dart @@ -1 +1 @@ -enum GroupCardState {disable, expanded, add} \ No newline at end of file +enum GroupCardState { disable, expanded, add } diff --git a/lib/data_models/menu_item.dart b/lib/data_models/menu_item.dart index f1a6f6f4..c417e4a2 100644 --- a/lib/data_models/menu_item.dart +++ b/lib/data_models/menu_item.dart @@ -14,4 +14,4 @@ class MenuItem { this.isUrl, this.isEmail, }); -} \ No newline at end of file +} diff --git a/lib/desktop_routes/desktop_route_names.dart b/lib/desktop_routes/desktop_route_names.dart index 4d0fd7b2..1e2d56d3 100644 --- a/lib/desktop_routes/desktop_route_names.dart +++ b/lib/desktop_routes/desktop_route_names.dart @@ -7,24 +7,8 @@ class DesktopRoutes { static const String DEKSTOP_MYFILES = 'desktop_my_files'; static const String DESKTOP_CATEGORY_FILES = 'desktop_category_files'; static const String DEKSTOP_CONTACTS_SCREEN = 'desktop_contacts_screen'; - static const String DEKSTOP_BLOCKED_CONTACTS_SCREEN = - 'desktop_blocked_contacts_screen'; + static const String DESKTOP_TRUSTED_SENDER = 'desktop_trusted_sender'; - static const String DESKTOP_EMPTY_TRUSTED_SENDER = - 'desktop_empty_trusted_sender'; static const DESKTOP_GROUP = 'desktop_group'; - static const DESKTOP_GROUP_VIEW = 'desktop_group_view'; - static const DESKT_FAQ = 'desktop_faq'; - static const DESKTOP_DOWNLOAD_ALL = 'desktop_download_all_files'; static const String DESKTOP_SETTINGS = 'desktop_settings'; - - /// Group left half routes - static const String DESKTOP_GROUP_LEFT_INITIAL = 'desktop_group_left_initial'; - static const String DESKTOP_GROUP_LIST = 'desktop_group_list'; - - /// Group right half routes - static const String DESKTOP_GROUP_RIGHT_INITIAL = - 'desktop_group_right_initial'; - static const String DESKTOP_NEW_GROUP = 'desktop_new_group'; - static const String DESKTOP_GROUP_DETAIL = 'desktop_group_detail'; } diff --git a/lib/desktop_routes/desktop_routes.dart b/lib/desktop_routes/desktop_routes.dart index 9b463115..96712132 100644 --- a/lib/desktop_routes/desktop_routes.dart +++ b/lib/desktop_routes/desktop_routes.dart @@ -1,12 +1,9 @@ import 'package:at_contacts_group_flutter/services/group_service.dart'; import 'package:atsign_atmosphere_pro/data_models/file_modal.dart'; import 'package:atsign_atmosphere_pro/desktop_routes/desktop_route_names.dart'; -import 'package:atsign_atmosphere_pro/desktop_screens/desktop_download_all_files/desktop_download_all_file.dart'; import 'package:atsign_atmosphere_pro/desktop_screens/desktop_home/desktop_home.dart'; -import 'package:atsign_atmosphere_pro/desktop_screens/trusted_sender/widgets/desktop_empty_trusted_sender.dart'; import 'package:atsign_atmosphere_pro/desktop_screens_new/contacts_screen/desktop_contact_screen.dart'; import 'package:atsign_atmosphere_pro/desktop_screens_new/groups_screen/desktop_groups_screen.dart'; -import 'package:atsign_atmosphere_pro/desktop_screens_new/settings_screen/blocked_contacts.dart'; import 'package:atsign_atmosphere_pro/desktop_screens_new/settings_screen/settings_desktop.dart'; import 'package:atsign_atmosphere_pro/desktop_screens_new/my_files_screen/desktop_myfiles.dart'; import 'package:atsign_atmosphere_pro/desktop_screens_new/my_files_screen/widgets/category_screen.dart'; @@ -14,12 +11,10 @@ import 'package:atsign_atmosphere_pro/desktop_screens_new/history_screen/history import 'package:atsign_atmosphere_pro/desktop_screens_new/trusted_senders_screen/desktop_trusted.dart'; import 'package:atsign_atmosphere_pro/desktop_screens_new/transfer_screen/file_transfer_screen.dart'; import 'package:atsign_atmosphere_pro/desktop_screens_new/welcome_screen/desktop_home_screen.dart'; -import 'package:atsign_atmosphere_pro/screens/common_widgets/website_webview.dart'; import 'package:flutter/material.dart'; import 'package:atsign_atmosphere_pro/services/navigation_service.dart'; import 'package:provider/provider.dart'; import 'package:atsign_atmosphere_pro/view_models/base_model.dart'; -import 'package:atsign_atmosphere_pro/utils/constants.dart'; class DesktopSetupRoutes { static String initialRoute = DesktopRoutes.DESKTOP_HOME; @@ -36,16 +31,6 @@ class DesktopSetupRoutes { }; } - // // ignore: missing_return - // static MaterialPageRoute nested_routes(name) { - // switch (name) { - // case DesktopRoutes.DESKTOP_HOME_NESTED_INITIAL: - // return MaterialPageRoute(builder: (context) => DesktopWelcomeScreen()); - // case DesktopRoutes.DESKTOP_HISTORY: - // return MaterialPageRoute(builder: (context) => DesktopHistoryScreen()); - // } - // } - static Map routeBuilders( BuildContext context, RouteSettings routeSettings) { return { @@ -71,23 +56,10 @@ class DesktopSetupRoutes { DesktopRoutes.DEKSTOP_CONTACTS_SCREEN: (context) { return DesktopContactScreen(); }, - DesktopRoutes.DESKTOP_DOWNLOAD_ALL: (context) { - return DesktopDownloadAllFiles(); - }, - DesktopRoutes.DEKSTOP_BLOCKED_CONTACTS_SCREEN: (context) { - return DesktopBlockedContacts(); - }, DesktopRoutes.DESKTOP_SETTINGS: (context) => SettingsScreenDesktop(), DesktopRoutes.DESKTOP_TRUSTED_SENDER: (context) => DesktopTrustedScreen(), - DesktopRoutes.DESKTOP_EMPTY_TRUSTED_SENDER: (context) => - DesktopEmptySender(), DesktopRoutes.DESKTOP_GROUP: (context) => DesktopGroupsScreen(), // => DesktopEmptyGroup(), - - DesktopRoutes.DESKT_FAQ: (context) => WebsiteScreen( - title: 'FAQ', - url: '${MixedConstants.WEBSITE_URL}/faqs', - ), }; } diff --git a/lib/desktop_screens/desktop_common_widgets/dektop_custom_person_tile.dart b/lib/desktop_screens/desktop_common_widgets/dektop_custom_person_tile.dart deleted file mode 100644 index 7a3eb714..00000000 --- a/lib/desktop_screens/desktop_common_widgets/dektop_custom_person_tile.dart +++ /dev/null @@ -1,88 +0,0 @@ -import 'dart:typed_data'; - -import 'package:atsign_atmosphere_pro/screens/common_widgets/contact_initial.dart'; -import 'package:atsign_atmosphere_pro/utils/text_styles.dart'; -import 'package:flutter/material.dart'; -import 'package:at_common_flutter/services/size_config.dart'; - -class DesktopCustomPersonVerticalTile extends StatelessWidget { - final String? title, subTitle; - final bool showCancelIcon, showImage; - final Uint8List? image; - final double size; - - DesktopCustomPersonVerticalTile( - {required this.title, - required this.subTitle, - this.showCancelIcon = true, - this.showImage = false, - this.image, - this.size = 50}); - @override - Widget build(BuildContext context) { - return Column( - mainAxisSize: MainAxisSize.min, - crossAxisAlignment: CrossAxisAlignment.center, - children: [ - Stack( - children: [ - showImage - ? CircleAvatar( - radius: (size / 2).toFont, - backgroundColor: Colors.transparent, - backgroundImage: Image.memory( - image!, - errorBuilder: (BuildContext _context, _, __) { - return Container( - child: Icon( - Icons.image, - size: 30.toFont, - ), - ); - }, - ).image, - ) - : ContactInitial( - initials: title ?? ' ', - size: 50, - maxSize: (80.0 - 30.0), - minSize: 50, - ), - showCancelIcon - ? Positioned( - top: 0, - right: 0, - child: Icon(Icons.cancel), - ) - : SizedBox(), - ], - ), - SizedBox(width: 10.toHeight), - Container( - padding: EdgeInsets.symmetric(vertical: 10), - child: Column( - mainAxisAlignment: MainAxisAlignment.center, - crossAxisAlignment: CrossAxisAlignment.center, - children: [ - Text( - title!, - style: CustomTextStyles.desktopPrimaryRegular14, - maxLines: 1, - overflow: TextOverflow.ellipsis, - ), - SizedBox(height: 5.toHeight), - subTitle != null - ? Text( - subTitle!, - style: CustomTextStyles.secondaryRegular12, - maxLines: 1, - overflow: TextOverflow.ellipsis, - ) - : SizedBox(), - ], - ), - ) - ], - ); - } -} diff --git a/lib/desktop_screens/desktop_common_widgets/desktop_custom_input_field.dart b/lib/desktop_screens/desktop_common_widgets/desktop_custom_input_field.dart deleted file mode 100644 index e114f6e4..00000000 --- a/lib/desktop_screens/desktop_common_widgets/desktop_custom_input_field.dart +++ /dev/null @@ -1,99 +0,0 @@ -import 'package:atsign_atmosphere_pro/utils/colors.dart'; -import 'package:flutter/material.dart'; -import 'package:at_common_flutter/services/size_config.dart'; - -// ignore: must_be_immutable -class DesktopCustomInputField extends StatelessWidget { - final String hintText, initialValue; - final double width, height; - final IconData? icon; - final Function? onTap, onIconTap, onSubmitted; - final Color? iconColor, backgroundColor; - final ValueChanged? value; - final bool isReadOnly; - - TextEditingController textController = TextEditingController(); - - DesktopCustomInputField( - {this.hintText = '', - this.height = 50, - this.width = 300, - this.iconColor, - this.icon, - this.onTap, - this.onIconTap, - this.value, - this.initialValue = '', - this.onSubmitted, - this.backgroundColor, - this.isReadOnly = false}); - - @override - Widget build(BuildContext context) { - textController = TextEditingController.fromValue( - TextEditingValue( - text: initialValue, - selection: TextSelection.collapsed(offset: initialValue.length), - ), - ); - return Container( - width: width.toWidth, - height: height, - decoration: BoxDecoration( - color: backgroundColor ?? ColorConstants.inputFieldColor, - borderRadius: BorderRadius.circular(5), - border: Border.all(color: ColorConstants.light_grey)), - padding: EdgeInsets.fromLTRB(10.toWidth, 0, 10.toWidth, 0), - child: Padding( - padding: const EdgeInsets.only(bottom: 5.0), - child: Row( - mainAxisAlignment: MainAxisAlignment.center, - children: [ - Expanded( - child: TextField( - readOnly: isReadOnly, - style: TextStyle( - fontSize: 15.toFont, - fontWeight: FontWeight.normal, - ), - decoration: InputDecoration( - hintText: hintText, - enabledBorder: InputBorder.none, - border: InputBorder.none, - hintStyle: TextStyle( - color: ColorConstants.light_grey, - fontSize: 15.toFont, - fontWeight: FontWeight.normal, - ), - ), - onTap: onTap as void Function()? ?? () {}, - onChanged: (val) { - value!(val); - }, - controller: textController, - onSubmitted: (str) { - if (onSubmitted != null) { - onSubmitted!(str); - } - }, - ), - ), - icon != null - ? InkWell( - onTap: onIconTap as void Function()? ?? - onTap as void Function()?, - child: Padding( - padding: const EdgeInsets.only(top: 5), - child: Icon( - icon, - color: iconColor ?? ColorConstants.fadedText, - ), - ), - ) - : SizedBox() - ], - ), - ), - ); - } -} diff --git a/lib/desktop_screens/desktop_common_widgets/desktop_custom_vertical_tile.dart b/lib/desktop_screens/desktop_common_widgets/desktop_custom_vertical_tile.dart deleted file mode 100644 index ed2eaa24..00000000 --- a/lib/desktop_screens/desktop_common_widgets/desktop_custom_vertical_tile.dart +++ /dev/null @@ -1,81 +0,0 @@ -import 'package:atsign_atmosphere_pro/screens/common_widgets/contact_initial.dart'; -import 'package:atsign_atmosphere_pro/services/navigation_service.dart'; -import 'package:atsign_atmosphere_pro/utils/text_styles.dart'; -import 'package:atsign_atmosphere_pro/view_models/file_transfer_provider.dart'; -import 'package:flutter/material.dart'; -import 'package:at_common_flutter/services/size_config.dart'; -import 'package:provider/provider.dart'; - -class CustomPersonVerticalTile extends StatelessWidget { - final String title; - final String? subTitle; - final Function onCancel; - - const CustomPersonVerticalTile({ - required this.title, - this.subTitle, - required this.onCancel, - }); - - @override - Widget build(BuildContext context) { - bool isCancelIcon = !Provider.of( - NavService.navKey.currentContext!, - listen: false) - .isFileSending; - return Column( - mainAxisSize: MainAxisSize.min, - crossAxisAlignment: CrossAxisAlignment.center, - children: [ - InkWell( - onTap: () {}, - child: Stack( - children: [ - ContactInitial( - initials: title, - size: 50, - maxSize: (80.0 - 30.0), - minSize: 50, - ), - Positioned( - top: 0, - right: 0, - child: InkWell( - onTap: () { - onCancel.call(); - }, - child: isCancelIcon ? Icon(Icons.cancel) : SizedBox(), - ), - ), - ], - ), - ), - SizedBox(width: 10.toHeight), - Container( - padding: EdgeInsets.symmetric(vertical: 10), - child: Column( - mainAxisAlignment: MainAxisAlignment.center, - crossAxisAlignment: CrossAxisAlignment.center, - children: [ - Text( - title, - style: CustomTextStyles.desktopPrimaryRegular14, - maxLines: 1, - overflow: TextOverflow.ellipsis, - ), - SizedBox(height: 5.toHeight), - subTitle != null - ? Text( - subTitle!, - style: CustomTextStyles.secondaryRegular12, - maxLines: 1, - overflow: TextOverflow.ellipsis, - ) - : SizedBox(), - ], - ), - ) - ], - ); - } -} diff --git a/lib/desktop_screens/desktop_common_widgets/desktop_header.dart b/lib/desktop_screens/desktop_common_widgets/desktop_header.dart deleted file mode 100644 index 4882f6b1..00000000 --- a/lib/desktop_screens/desktop_common_widgets/desktop_header.dart +++ /dev/null @@ -1,78 +0,0 @@ -import 'package:at_common_flutter/at_common_flutter.dart'; -import 'package:atsign_atmosphere_pro/desktop_routes/desktop_routes.dart'; -import 'package:atsign_atmosphere_pro/utils/text_styles.dart'; -import 'package:flutter/material.dart'; - -class DesktopHeader extends StatelessWidget { - final String? title; - final ValueChanged? onFilter; - final List? actions; - final List options = [ - 'By type', - 'By name', - 'By size', - 'By date', - 'add-btn' - ]; - final bool showBackIcon, isTitleCentered; - - DesktopHeader({ - this.title, - this.showBackIcon = true, - this.onFilter, - this.actions, - this.isTitleCentered = false, - }); - - @override - Widget build(BuildContext context) { - return Container( - child: Row( - children: [ - SizedBox(width: 20.toWidth), - showBackIcon - ? InkWell( - onTap: () { - DesktopSetupRoutes.nested_pop(); - }, - child: Icon(Icons.arrow_back), - ) - : SizedBox(), - SizedBox(width: 15.toWidth), - title != null && isTitleCentered - ? Expanded( - child: Padding( - padding: EdgeInsets.only(left: 20.toWidth), - child: Center( - child: Text( - title!, - style: CustomTextStyles.primaryRegular20, - maxLines: 2, - ), - ), - ), - ) - : SizedBox(), - title != null && !isTitleCentered - ? Container( - child: Center( - child: Text( - title!, - style: CustomTextStyles.primaryRegular20, - maxLines: 2, - ), - ), - ) - : SizedBox(), - SizedBox(width: 15.toWidth), - !isTitleCentered ? Expanded(child: SizedBox()) : SizedBox(), - actions != null - ? Row( - children: actions!, - ) - : SizedBox() - ], - ), - ); - } -} diff --git a/lib/desktop_screens/desktop_common_widgets/desktop_person_vertical_tile.dart b/lib/desktop_screens/desktop_common_widgets/desktop_person_vertical_tile.dart deleted file mode 100644 index be90d240..00000000 --- a/lib/desktop_screens/desktop_common_widgets/desktop_person_vertical_tile.dart +++ /dev/null @@ -1,134 +0,0 @@ -import 'dart:typed_data'; -import 'package:at_contacts_group_flutter/widgets/custom_circle_avatar.dart'; -import 'package:atsign_atmosphere_pro/screens/common_widgets/contact_initial.dart'; -import 'package:atsign_atmosphere_pro/utils/text_styles.dart'; -import 'package:flutter/material.dart'; - -// ignore: import_of_legacy_library_into_null_safe -import 'package:at_common_flutter/services/size_config.dart'; - -class DesktopCustomPersonVerticalTile extends StatefulWidget { - final String? imageLocation, title, subTitle, atSign; - final bool isTopRight, isAssetImage; - final IconData? icon; - final Function? onCrossPressed; - final Uint8List? imageIntList; - - DesktopCustomPersonVerticalTile( - {this.imageLocation, - this.title, - this.subTitle, - this.isTopRight = false, - this.icon, - this.onCrossPressed, - this.isAssetImage = true, - this.imageIntList, - this.atSign}); - - @override - _DesktopCustomPersonVerticalTileState createState() => - _DesktopCustomPersonVerticalTileState(); -} - -class _DesktopCustomPersonVerticalTileState - extends State { - Uint8List? image; - String? contactName; - - @override - void initState() { - super.initState(); - // getAtsignImage(); - } - - @override - Widget build(BuildContext context) { - return Container( - padding: EdgeInsets.only(top: 10), - child: Column( - children: [ - Stack( - children: [ - SizedBox( - height: 60.toHeight, - width: 60.toHeight, - child: widget.isAssetImage && widget.imageLocation != null - ? CustomCircleAvatar( - size: 60.toHeight, - image: widget.imageLocation, - ) - : image != null - ? ClipRRect( - borderRadius: - BorderRadius.all(Radius.circular(30.toFont)), - child: Image.memory( - image!, - width: 50.toFont, - height: 50.toFont, - fit: BoxFit.fill, - errorBuilder: (BuildContext _context, _, __) { - return Container( - child: Icon( - Icons.image, - size: 30.toFont, - ), - ); - }, - ), - ) - : ContactInitial( - initials: widget.subTitle ?? ' ', - ), - ), - widget.icon != null - ? Positioned( - top: widget.isTopRight ? 0 : null, - bottom: !widget.isTopRight ? 0 : null, - right: 0, - child: GestureDetector( - onTap: widget.onCrossPressed as void Function()?, - child: Container( - height: 20.toHeight, - width: 20.toHeight, - decoration: BoxDecoration( - color: Colors.black, shape: BoxShape.circle), - child: Icon( - Icons.close, - size: 15.toHeight, - color: Colors.white, - ), - ), - ), - ) - : SizedBox(), - ], - ), - SizedBox(height: 2), - contactName != null - ? Text( - contactName!, - style: CustomTextStyles.greyText16, - maxLines: 1, - overflow: TextOverflow.ellipsis, - textAlign: TextAlign.center, - ) - : SizedBox(), - SizedBox(height: 2), - widget.subTitle != null - ? SizedBox( - width: 120, - child: Text( - widget.subTitle!, - style: CustomTextStyles.greyText15, - maxLines: 1, - overflow: TextOverflow.ellipsis, - textAlign: TextAlign.center, - ), - ) - : SizedBox(), - SizedBox(height: 2), - ], - ), - ); - } -} diff --git a/lib/desktop_screens/desktop_common_widgets/desktop_selected_contacts.dart b/lib/desktop_screens/desktop_common_widgets/desktop_selected_contacts.dart deleted file mode 100644 index 0add7422..00000000 --- a/lib/desktop_screens/desktop_common_widgets/desktop_selected_contacts.dart +++ /dev/null @@ -1,77 +0,0 @@ -import 'package:at_contacts_group_flutter/at_contacts_group_flutter.dart'; -import 'package:atsign_atmosphere_pro/desktop_screens/desktop_common_widgets/desktop_custom_vertical_tile.dart'; -import 'package:atsign_atmosphere_pro/services/navigation_service.dart'; -import 'package:atsign_atmosphere_pro/utils/text_styles.dart'; -import 'package:atsign_atmosphere_pro/view_models/welcome_screen_view_model.dart'; -import 'package:flutter/material.dart'; -import 'package:provider/provider.dart'; - -class DesktopSelectedContacts extends StatefulWidget { - final ValueChanged onChange; - final bool showCancelIcon; - - DesktopSelectedContacts(this.onChange, {this.showCancelIcon = false}); - - @override - _DesktopSelectedContactsState createState() => - _DesktopSelectedContactsState(); -} - -class _DesktopSelectedContactsState extends State { - WelcomeScreenProvider welcomeScreenProvider = WelcomeScreenProvider(); - late List selectedContacts; - - @override - void initState() { - welcomeScreenProvider = Provider.of( - NavService.navKey.currentContext!, - listen: false); - selectedContacts = welcomeScreenProvider.selectedContacts; - super.initState(); - } - - @override - Widget build(BuildContext context) { - return Column(crossAxisAlignment: CrossAxisAlignment.start, children: [ - RichText( - text: TextSpan( - text: 'Selected person', - style: CustomTextStyles.desktopPrimaryBold18, - children: [ - TextSpan( - // text: ' ${selectedContacts.length} people selected', - text: selectedContacts.length == 1 - ? ' ${selectedContacts.length} person selected' - : ' ${selectedContacts.length} people selected', - style: CustomTextStyles.desktopSecondaryRegular18, - ) - ], - ), - ), - SizedBox( - height: 30, - ), - Align( - alignment: Alignment.center, - child: Wrap( - alignment: WrapAlignment.start, - runAlignment: WrapAlignment.start, - runSpacing: 10.0, - spacing: 30.0, - children: List.generate(selectedContacts.length, (index) { - return CustomPersonVerticalTile( - title: selectedContacts[index]!.contact!.atSign!, - subTitle: selectedContacts[index]!.contact!.atSign, - onCancel: () { - welcomeScreenProvider.removeContacts(selectedContacts[index]); - welcomeScreenProvider.isSelectionItemChanged = true; - widget.onChange(true); - setState(() {}); - }, - ); - }), - ), - ), - ]); - } -} diff --git a/lib/desktop_screens/desktop_common_widgets/desktop_selected_files.dart b/lib/desktop_screens/desktop_common_widgets/desktop_selected_files.dart deleted file mode 100644 index 52979a28..00000000 --- a/lib/desktop_screens/desktop_common_widgets/desktop_selected_files.dart +++ /dev/null @@ -1,131 +0,0 @@ -import 'package:atsign_atmosphere_pro/services/common_utility_functions.dart'; -import 'package:atsign_atmosphere_pro/services/navigation_service.dart'; -import 'package:at_common_flutter/services/size_config.dart'; -import 'package:atsign_atmosphere_pro/utils/colors.dart'; -import 'package:atsign_atmosphere_pro/utils/text_styles.dart'; -import 'package:atsign_atmosphere_pro/view_models/file_transfer_provider.dart'; -import 'package:atsign_atmosphere_pro/view_models/welcome_screen_view_model.dart'; -import 'package:flutter/material.dart'; -import 'package:provider/provider.dart'; -import 'package:atsign_atmosphere_pro/utils/text_strings.dart'; - -class DesktopSelectedFiles extends StatefulWidget { - final ValueChanged onChange; - final bool showCancelIcon; - - DesktopSelectedFiles( - this.onChange, { - this.showCancelIcon = true, - }); - - @override - _DesktopSelectedFilesState createState() => _DesktopSelectedFilesState(); -} - -class _DesktopSelectedFilesState extends State { - late WelcomeScreenProvider welcomeScreenProvider; - - @override - void initState() { - welcomeScreenProvider = Provider.of( - NavService.navKey.currentContext!, - listen: false); - super.initState(); - } - - @override - Widget build(BuildContext context) { - return Container( - child: Column( - crossAxisAlignment: CrossAxisAlignment.start, - children: [ - Text(TextStrings().selectedFiles, - style: CustomTextStyles.desktopPrimaryBold18), - SizedBox( - height: 30, - ), - Consumer(builder: (context, provider, _) { - if (provider.selectedFiles.isEmpty) { - return SizedBox(); - } - return Align( - alignment: Alignment.topLeft, - child: Wrap( - alignment: WrapAlignment.start, - runAlignment: WrapAlignment.start, - runSpacing: 10.0, - spacing: 20.0, - children: List.generate(provider.selectedFiles.length, (index) { - return Container( - decoration: BoxDecoration( - border: Border( - bottom: BorderSide( - color: ColorConstants.dividerColor.withOpacity(0.1), - width: 1.toHeight, - ), - ), - ), - child: Container( - width: 230, - child: Stack(children: [ - widget.showCancelIcon - ? Positioned( - top: 0, - right: 0, - child: GestureDetector( - onTap: () { - provider.selectedFiles.removeAt(index); - provider.calculateSize(); - welcomeScreenProvider - .isSelectionItemChanged = true; - widget.onChange(true); - }, - child: Icon(Icons.cancel), - ), - ) - : SizedBox(), - IgnorePointer( - child: ListTile( - onTap: null, - title: Text( - provider.selectedFiles[index].name, - style: TextStyle( - color: Colors.black, - fontSize: 14.toFont, - fontWeight: FontWeight.normal, - ), - maxLines: 1, - ), - subtitle: Text( - double.parse(provider.selectedFiles[index].size - .toString()) <= - 1024 - ? '${provider.selectedFiles[index].size} Kb' + - ' . ${provider.selectedFiles[index].extension}' - : '${(provider.selectedFiles[index].size / (1024 * 1024)).toStringAsFixed(2)} Mb' + - ' . ${provider.selectedFiles[index].extension}', - style: TextStyle( - color: ColorConstants.fadedText, - fontSize: 14.toFont, - fontWeight: FontWeight.normal, - ), - ), - leading: CommonUtilityFunctions().thumbnail( - provider.selectedFiles[index].extension - .toString(), - provider.selectedFiles[index].path.toString()), - trailing: SizedBox(), - ), - ), - ]), - ), - ); - }), - ), - ); - }), - ], - ), - ); - } -} diff --git a/lib/desktop_screens/desktop_common_widgets/desktop_switch_atsign.dart b/lib/desktop_screens/desktop_common_widgets/desktop_switch_atsign.dart deleted file mode 100644 index 50ccf36b..00000000 --- a/lib/desktop_screens/desktop_common_widgets/desktop_switch_atsign.dart +++ /dev/null @@ -1,189 +0,0 @@ -import 'dart:typed_data'; - -import 'package:at_client_mobile/at_client_mobile.dart'; -import 'package:atsign_atmosphere_pro/screens/common_widgets/contact_initial.dart'; -import 'package:atsign_atmosphere_pro/screens/common_widgets/custom_circle_avatar.dart'; -import 'package:atsign_atmosphere_pro/services/backend_service.dart'; -import 'package:atsign_atmosphere_pro/services/common_utility_functions.dart'; -import 'package:atsign_atmosphere_pro/services/navigation_service.dart'; -import 'package:atsign_atmosphere_pro/utils/colors.dart'; -import 'package:atsign_atmosphere_pro/utils/text_strings.dart'; -import 'package:atsign_atmosphere_pro/utils/text_styles.dart'; -import 'package:flutter/material.dart'; - -class DesktopSwitchAtSign extends StatefulWidget { - final String atSign; - - DesktopSwitchAtSign({ - Key? key, - required this.atSign, - }) : super(key: key); - - @override - State createState() => _DesktopSwitchAtSignState(); -} - -class _DesktopSwitchAtSignState extends State { - BackendService backendService = BackendService.getInstance(); - bool isCurrentAtSign = false; - var atClientPreference; - AtClient atClient = AtClientManager.getInstance().atClient; - String? atSignName = ''; - - @override - void initState() { - if (widget.atSign == atClient.getCurrentAtSign()) { - isCurrentAtSign = true; - } - getAtSignDetails(); - super.initState(); - } - - getAtSignDetails() { - atSignName = CommonUtilityFunctions().getCachedContactName(widget.atSign); - setState(() {}); - } - - @override - Widget build(BuildContext context) { - if (widget.atSign == TextStrings().addNewAtSign) { - return addNewContactRow(); - } else if (widget.atSign == TextStrings().saveBackupKey) { - return saveBackupKeyRow(); - } else { - return _contactRow(widget.atSign, atSignName ?? '', - isCurrentAtSign: isCurrentAtSign); - } - } - - Widget _contactRow(String _atSign, String _name, - {bool isCurrentAtSign = false}) { - Uint8List? image = - CommonUtilityFunctions().getCachedContactImage(widget.atSign); - - return Row( - children: [ - image != null - ? CustomCircleAvatar( - byteImage: image, - nonAsset: true, - size: isCurrentAtSign ? 40 : 40, - ) - : ContactInitial( - initials: _atSign, - size: isCurrentAtSign ? 40 : 40, - maxSize: isCurrentAtSign ? 50 : 40, - minSize: isCurrentAtSign ? 40 : 30, - ), - SizedBox(width: 10), - Container( - child: Tooltip( - message: _atSign, - child: Column( - mainAxisAlignment: MainAxisAlignment.center, - crossAxisAlignment: CrossAxisAlignment.start, - children: [ - SizedBox( - width: 180, - child: Text( - _atSign, - style: isCurrentAtSign - ? CustomTextStyles.blackBold() - : CustomTextStyles.desktopSecondaryRegular14, - maxLines: 1, - overflow: TextOverflow.ellipsis, - ), - ), - SizedBox(height: 5), - _name.isNotEmpty - ? SizedBox( - width: 180, - child: Text( - _name, - style: isCurrentAtSign - ? CustomTextStyles.greyText16 - : CustomTextStyles.desktopSecondaryRegular14, - maxLines: 1, - overflow: TextOverflow.ellipsis, - ), - ) - : SizedBox(), - ], - ), - ), - ), - Expanded( - child: Align( - alignment: Alignment.centerRight, - child: GestureDetector( - onTap: () { - Navigator.of(NavService.navKey.currentContext!) - .pop(); // this is to close the popup menu button - CommonUtilityFunctions().deleteAtSign(widget.atSign); - }, - child: Icon(Icons.delete))), - ) - ], - ); - } - - Widget addNewContactRow() { - return Padding( - padding: EdgeInsets.symmetric(vertical: 10), - child: Row( - children: [ - Container( - height: 40, - width: 40, - decoration: BoxDecoration( - color: Colors.white, - border: Border.all(), - shape: BoxShape.circle, - ), - child: Icon( - Icons.add, - color: ColorConstants.fadedText, - size: 35, - ), - ), - SizedBox( - width: 10, - ), - Text( - 'Add', - style: CustomTextStyles.desktopSecondaryRegular14, - ) - ], - ), - ); - } - - Widget saveBackupKeyRow() { - return Column( - children: [ - Divider(height: 1), - Container( - height: 50, - child: Row( - children: [ - Icon(Icons.file_copy), - SizedBox(width: 10), - Expanded( - child: Text( - 'Backup your keys', - softWrap: true, - style: TextStyle( - color: ColorConstants.fadedText, - letterSpacing: 0.1, - fontSize: 14, - fontWeight: FontWeight.normal, - ), - ), - ) - ], - ), - ), - ], - ); - } -} diff --git a/lib/desktop_screens/desktop_common_widgets/person_vertical_tile.dart b/lib/desktop_screens/desktop_common_widgets/person_vertical_tile.dart deleted file mode 100644 index 5c91dfde..00000000 --- a/lib/desktop_screens/desktop_common_widgets/person_vertical_tile.dart +++ /dev/null @@ -1,164 +0,0 @@ -import 'dart:typed_data'; - -import 'package:at_contacts_flutter/at_contacts_flutter.dart'; -import 'package:atsign_atmosphere_pro/data_models/file_transfer.dart'; -import 'package:atsign_atmosphere_pro/screens/common_widgets/contact_initial.dart'; -import 'package:atsign_atmosphere_pro/screens/common_widgets/triple_dot_loading.dart'; -import 'package:atsign_atmosphere_pro/services/common_utility_functions.dart'; - -// import 'package:atsign_atmosphere_pro/services/size_config.dart' ; -import 'package:atsign_atmosphere_pro/utils/text_styles.dart'; -import 'package:atsign_atmosphere_pro/view_models/file_transfer_provider.dart'; -import 'package:flutter/material.dart'; -import 'package:provider/provider.dart'; - -class CustomPersonVerticalTile extends StatefulWidget { - final ShareStatus shareStatus; - final bool isFailedAtSignList; - final FileHistory? fileHistory; - @override - final Key? key; - - CustomPersonVerticalTile( - {this.key, - required this.shareStatus, - required this.fileHistory, - this.isFailedAtSignList = false}); - - @override - _CustomPersonVerticalTileState createState() => - _CustomPersonVerticalTileState(); -} - -class _CustomPersonVerticalTileState extends State { - Uint8List? image; - String? contactName; - - @override - void initState() { - super.initState(); - getAtSignImage(); - } - - // ignore: always_declare_return_types - getAtSignImage() async { - if (widget.shareStatus.atsign == null) return; - var contact = await getAtSignDetails(widget.shareStatus.atsign!); - - // ignore: unnecessary_null_comparison - if (contact != null) { - if (mounted) { - setState(() { - image = CommonUtilityFunctions().getContactImage(contact); - }); - } - - if (contact.tags != null && contact.tags!['name'] != null) { - if (mounted) { - setState(() { - contactName = contact.tags!['name']; - }); - } - } - } - } - - @override - Widget build(BuildContext context) { - SizeConfig().init(context); - return Container( - padding: EdgeInsets.only(top: 10), - child: Column( - children: [ - Stack( - children: [ - Stack( - children: [ - SizedBox( - height: 50.toHeight, - width: 50.toHeight, - child: image != null - ? ClipRRect( - borderRadius: - BorderRadius.all(Radius.circular(30.toFont)), - child: Image.memory( - image!, - width: 50.toFont, - height: 50.toFont, - fit: BoxFit.fill, - errorBuilder: (BuildContext _context, _, __) { - return Container( - child: Icon( - Icons.image, - size: 30.toFont, - ), - ); - }, - ), - ) - : ContactInitial( - initials: widget.shareStatus.atsign ?? ' ', - ), - ), - widget.isFailedAtSignList - ? Positioned( - child: Container( - height: 50.toHeight, - width: 50.toHeight, - decoration: BoxDecoration( - color: Colors.black.withOpacity(0.5), - borderRadius: BorderRadius.circular(50.toWidth), - ), - child: InkWell( - onTap: () async { - print( - 'selectedFileHistory : ${widget.fileHistory!.fileTransferObject!.transferId}, atSign: ${widget.shareStatus.atsign}'); - - await Provider.of(context, - listen: false) - .reSendFileNotification(widget.fileHistory!, - widget.shareStatus.atsign!); - }, - child: widget.shareStatus.isSendingNotification! - ? TypingIndicator(showIndicator: true) - : Icon(Icons.refresh, - color: Colors.white, size: 30.toHeight), - ), - )) - : SizedBox(), - ], - ), - ], - ), - SizedBox(height: 2), - contactName != null - ? SizedBox( - width: 100.toFont, - child: Text( - contactName!, - style: CustomTextStyles.grey15, - maxLines: 1, - overflow: TextOverflow.ellipsis, - textAlign: TextAlign.center, - ), - ) - : SizedBox(), - SizedBox(height: 2), - widget.shareStatus.atsign != null - ? SizedBox( - width: 100.toFont, - child: Text( - widget.shareStatus.atsign!, - style: CustomTextStyles.grey13, - maxLines: 1, - overflow: TextOverflow.ellipsis, - textAlign: TextAlign.center, - ), - ) - : SizedBox(), - SizedBox(height: 2), - ], - ), - ); - } -} diff --git a/lib/desktop_screens/desktop_download_all_files/desktop_download_all_file.dart b/lib/desktop_screens/desktop_download_all_files/desktop_download_all_file.dart deleted file mode 100644 index da952c9f..00000000 --- a/lib/desktop_screens/desktop_download_all_files/desktop_download_all_file.dart +++ /dev/null @@ -1,211 +0,0 @@ -import 'dart:io'; - -import 'package:at_common_flutter/services/size_config.dart'; -import 'package:atsign_atmosphere_pro/data_models/file_transfer.dart'; -import 'package:atsign_atmosphere_pro/utils/colors.dart'; -import 'package:atsign_atmosphere_pro/utils/text_strings.dart'; -import 'package:atsign_atmosphere_pro/view_models/history_provider.dart'; -import 'package:file_selector/file_selector.dart'; -import 'package:flutter/material.dart'; -import 'package:provider/provider.dart'; - -class DesktopDownloadAllFiles extends StatefulWidget { - @override - _DesktopDownloadAllFilesState createState() => - _DesktopDownloadAllFilesState(); -} - -class _DesktopDownloadAllFilesState extends State { - String downloadFolder = Platform.pathSeparator; - bool isDownloading = false, isDownloadComplete = false; - double downloadProgress = 0; - - @override - void initState() { - super.initState(); - } - - @override - Widget build(BuildContext context) { - return Scaffold( - body: Container( - padding: EdgeInsets.symmetric( - vertical: 100.toHeight, horizontal: 20.toWidth), - child: Center( - child: Column( - children: [ - Text( - TextStrings().receivedFileDownloadMsg, - style: TextStyle( - fontSize: 20.toFont, - fontWeight: FontWeight.bold, - color: ColorConstants.greyText), - ), - SizedBox(height: 20.toHeight), - Container( - padding: EdgeInsets.all(5.0), - color: Colors.green, - child: RichText( - textAlign: TextAlign.center, - text: TextSpan(children: [ - TextSpan( - text: TextStrings().selectedDownloadFolder, - style: TextStyle(fontWeight: FontWeight.bold)), - TextSpan(text: downloadFolder), - ])), - ), - SizedBox(height: 20.toHeight), - TextButton( - onPressed: _setDownloadFolder, - child: const Text( - TextStrings.selectDownloadFolder, - style: TextStyle( - fontSize: 16, - fontWeight: FontWeight.normal, - ), - ), - ), - SizedBox(height: 10.toHeight), - TextButton( - onPressed: _fetchFiles, - child: Text( - isDownloading - ? TextStrings().downloadingFiles - : TextStrings().downloadAllFiles, - style: TextStyle( - fontSize: 16, - fontWeight: FontWeight.normal, - ), - ), - ), - isDownloading - ? SizedBox( - width: 350.toWidth, - child: LinearProgressIndicator( - value: downloadProgress, - minHeight: 10, - ), - ) - : SizedBox(), - isDownloadComplete - ? SizedBox( - width: 150, - child: Row( - children: [ - Text(TextStrings().downloadComplete, - style: TextStyle( - color: Colors.green, - fontWeight: FontWeight.normal, - )), - Icon( - Icons.download_done, - color: Colors.green, - ) - ], - ), - ) - : SizedBox() - ], - ), - )), - ); - } - - _setDownloadFolder() async { - String path = (await getSaveLocation())?.path ?? Platform.pathSeparator; - if (mounted) { - setState(() { - downloadFolder = path; - isDownloadComplete = false; - }); - } - await checkIfFolderExists(downloadFolder); - } - - _fetchFiles() async { - if (downloadFolder == Platform.pathSeparator) { - ScaffoldMessenger.of(context).showSnackBar( - SnackBar(content: Text(TextStrings().selectFolderToDownload)), - ); - return; - } - - if (isDownloading) { - ScaffoldMessenger.of(context).showSnackBar( - SnackBar(content: Text(TextStrings().downloadInProgress)), - ); - return; - } - - if (mounted) { - setState(() { - isDownloading = true; - isDownloadComplete = false; - }); - } - - var historyProvider = Provider.of(context, listen: false); - List fileTransfer = getValidFileTransfers(); - - for (int i = 0; i < fileTransfer.length; i++) { - var atsignDownloadPath = - downloadFolder + Platform.pathSeparator + fileTransfer[i].sender!; - - await checkIfFolderExists(atsignDownloadPath); - - var res = await historyProvider.downloadFiles( - fileTransfer[i].key, fileTransfer[i].sender!, false, - downloadPath: atsignDownloadPath); - - if (res is bool && !res) { - ScaffoldMessenger.of(context).showSnackBar( - SnackBar( - content: Text( - '${TextStrings().failedToDownload} ${fileTransfer[i].files!.length} ${TextStrings().filesFrom} ${fileTransfer[i].sender}'), - ), - ); - } - - // increasing progress indicator percentage. - if (mounted) { - setState(() { - downloadProgress = ((i + 1) / fileTransfer.length); - }); - } - } - - if (mounted) { - setState(() { - isDownloading = false; - isDownloadComplete = true; - downloadProgress = 0; - }); - } - } - - List getValidFileTransfers() { - var historyProvider = Provider.of(context, listen: false); - List fileTransfer = []; - for (int i = 0; i < historyProvider.receivedHistoryLogs.length; i++) { - var expiryDate = historyProvider.receivedHistoryLogs[i].date!.add( - Duration(days: 6), - ); - - if (expiryDate.difference(DateTime.now()) < Duration(seconds: 0)) { - continue; - } else { - fileTransfer.add(historyProvider.receivedHistoryLogs[i]); - } - } - - return fileTransfer; - } - - checkIfFolderExists(String path) async { - final directory = Directory(path); - - if (!(await directory.exists())) { - await directory.create(); - } - } -} diff --git a/lib/desktop_screens/desktop_history/desktop_history.dart b/lib/desktop_screens/desktop_history/desktop_history.dart deleted file mode 100644 index f2585aa1..00000000 --- a/lib/desktop_screens/desktop_history/desktop_history.dart +++ /dev/null @@ -1,430 +0,0 @@ -import 'package:atsign_atmosphere_pro/data_models/file_transfer.dart'; -import 'package:atsign_atmosphere_pro/desktop_screens/desktop_history/widgets/desktop_received_file_details.dart'; -import 'package:atsign_atmosphere_pro/desktop_screens/desktop_history/widgets/desktop_received_file_list_tile.dart'; -import 'package:atsign_atmosphere_pro/desktop_screens/desktop_history/widgets/desktop_sent_file_details.dart'; -import 'package:atsign_atmosphere_pro/desktop_screens/desktop_history/widgets/desktop_sent_file_list_tile.dart'; -import 'package:atsign_atmosphere_pro/screens/common_widgets/provider_handler.dart'; -import 'package:at_common_flutter/services/size_config.dart'; -import 'package:atsign_atmosphere_pro/services/navigation_service.dart'; -import 'package:atsign_atmosphere_pro/utils/colors.dart'; -import 'package:atsign_atmosphere_pro/utils/text_strings.dart'; -import 'package:atsign_atmosphere_pro/utils/text_styles.dart'; -import 'package:atsign_atmosphere_pro/view_models/base_model.dart'; -import 'package:atsign_atmosphere_pro/view_models/history_provider.dart'; -import 'package:flutter/material.dart'; -import 'package:provider/provider.dart'; - -class DesktopHistoryScreen extends StatefulWidget { - final int tabIndex; - - DesktopHistoryScreen({ - Key? key, - this.tabIndex = 0, - }); - - @override - _DesktopHistoryScreenState createState() => _DesktopHistoryScreenState(); -} - -class _DesktopHistoryScreenState extends State - with SingleTickerProviderStateMixin { - TabController? _controller; - late HistoryProvider historyProvider; - int sentSelectedIndex = 0; - String? receivedSelectedFileId; - FileHistory? selectedSentFileData; - FileTransfer? receivedFileData; - bool isSentTab = false, _showSearchField = false; - late TextEditingController _textController; - - @override - void initState() { - historyProvider = - Provider.of(NavService.navKey.currentContext!); - _textController = TextEditingController(); - super.initState(); - } - - @override - void didChangeDependencies() async { - _controller = - TabController(length: 2, vsync: this, initialIndex: widget.tabIndex); - _controller!.addListener(onTabChanged); - - if (historyProvider.sentHistory.isNotEmpty) { - selectedSentFileData = historyProvider.sentHistory[0]; - } - if (historyProvider.receivedHistoryLogs.isNotEmpty) { - receivedFileData = historyProvider.receivedHistoryLogs[0]; - } - - super.didChangeDependencies(); - } - - @override - void didUpdateWidget(covariant DesktopHistoryScreen oldWidget) { - var i = historyProvider.sentHistory.indexWhere((element) => - element.fileTransferObject?.transferId == - selectedSentFileData?.fileTransferObject?.transferId); - if (i == -1 && historyProvider.sentHistory.isNotEmpty) { - selectedSentFileData = historyProvider.sentHistory[0]; - sentSelectedIndex = 0; - } - - var j = historyProvider.receivedHistoryLogs - .indexWhere((element) => element.key == receivedFileData?.key); - if (j == -1 && historyProvider.receivedHistoryLogs.isNotEmpty) { - receivedFileData = historyProvider.receivedHistoryLogs[0]; - receivedSelectedFileId = historyProvider.receivedHistoryLogs[0].key; - } - - setState(() {}); - super.didUpdateWidget(oldWidget); - } - - @override - void dispose() { - _controller!.removeListener(onTabChanged); - _textController.dispose(); - WidgetsBinding.instance.addPostFrameCallback((timeStamp) { - historyProvider.setHistorySearchText = ''; - }); - super.dispose(); - } - - onTabChanged({int? index}) { - if (index == null) { - index = _controller!.index; - } - if (index == 0) { - isSentTab = true; - } else if (index == 1) { - isSentTab = false; - } - setState(() {}); - } - - @override - Widget build(BuildContext context) { - historyProvider = Provider.of(context); - SizeConfig().init(context); - return Scaffold( - backgroundColor: ColorConstants.scaffoldColor, - body: SingleChildScrollView( - child: Row( - children: [ - Expanded( - child: Container( - color: ColorConstants.fadedBlue, - height: SizeConfig().screenHeight - 80, - child: Column( - children: [ - Stack( - children: [ - Container( - height: 80, - padding: EdgeInsets.symmetric(vertical: 20), - child: TabBar( - labelColor: ColorConstants.fontPrimary, - indicatorWeight: 5, - indicatorColor: Colors.black, - indicatorSize: TabBarIndicatorSize.label, - labelStyle: CustomTextStyles.primaryBold14, - unselectedLabelStyle: - CustomTextStyles.secondaryRegular14, - controller: _controller, - tabs: [ - Text( - TextStrings().sent, - style: TextStyle( - letterSpacing: 0.1, - fontSize: 20, - fontWeight: FontWeight.normal, - ), - ), - Text( - TextStrings().received, - style: TextStyle( - letterSpacing: 0.1, - fontSize: 20, - fontWeight: FontWeight.normal, - ), - ) - ], - ), - ), - Positioned( - right: 15, - top: 25, - child: InkWell( - onTap: refreshHistoryScreen, - child: Icon(Icons.refresh)), - ), - Positioned( - right: 45, - top: 25, - child: InkWell( - onTap: () { - setState(() { - _showSearchField = true; - }); - }, - child: Icon(Icons.search)), - ), - ], - ), - _showSearchField ? searchHistoryField() : SizedBox(), - Expanded( - child: TabBarView( - controller: _controller, - children: [ - ProviderHandler( - functionName: historyProvider.SENT_HISTORY, - showError: false, - successBuilder: (provider) { - if ((provider.sentHistory.isEmpty)) { - return Center( - child: Text(TextStrings().noFilesSent, - style: TextStyle( - fontSize: 15.toFont, - fontWeight: FontWeight.normal, - )), - ); - } else { - List filteredSentHistory = []; - provider.sentHistory.forEach((element) { - if (element.sharedWith!.any( - (ShareStatus sharedStatus) => sharedStatus - .atsign! - .contains(provider.getSearchText), - ) || - (element.groupName != null && - element.groupName! - .toLowerCase() - .contains(provider.getSearchText - .toLowerCase()))) { - filteredSentHistory.add(element); - } - }); - if (filteredSentHistory.isNotEmpty) { - return getSentHistory(filteredSentHistory); - } else { - return Center( - child: Text('No results found'), - ); - } - } - }, - errorBuilder: (provider) => Center( - child: Text(TextStrings().errorOccurred), - ), - load: (provider) async { - provider.getSentHistory(); - }, - ), - ProviderHandler( - functionName: historyProvider.RECEIVED_HISTORY, - load: (provider) async { - await provider.getReceivedHistory(); - }, - showError: false, - successBuilder: (provider) { - if (provider.receivedHistoryLogs.isNotEmpty && - receivedSelectedFileId == null) { - receivedSelectedFileId = - provider.receivedHistoryLogs[0].key; - receivedFileData = - provider.receivedHistoryLogs[0]; - } - - if ((provider.receivedHistoryLogs.isEmpty)) { - return Center( - child: Text( - TextStrings().noFilesRecieved, - style: TextStyle( - fontSize: 15.toFont, - fontWeight: FontWeight.normal, - ), - ), - ); - } else { - List filteredReceivedList = []; - provider.receivedHistoryLogs.forEach((element) { - if (element.sender!.contains( - provider.getSearchText, - )) { - filteredReceivedList.add(element); - } - }); - - if (filteredReceivedList.isNotEmpty) { - return getReceivedTiles(filteredReceivedList); - } else { - return Center(child: Text('No results found')); - } - } - }, - errorBuilder: (provider) => Center( - child: Text(TextStrings().errorOccurred), - ), - ), - ], - ), - ) - ], - ), - ), - ), - Expanded( - child: Container( - height: SizeConfig().screenHeight - 80, - child: isSentTab - ? selectedSentFileData == null - ? SizedBox() - : Consumer( - builder: (context, provider, _) { - if (provider.sentHistory.isEmpty) { - return SizedBox(); - } - - return DesktopSentFileDetails( - key: Key(selectedSentFileData! - .fileTransferObject!.transferId), - selectedFileData: selectedSentFileData, - ); - }, - ) - : receivedFileData == null - ? SizedBox() - : Consumer( - builder: (context, provider, _) { - if (provider.receivedHistoryLogs.isEmpty) { - return SizedBox(); - } - - return DesktopReceivedFileDetails( - key: Key(receivedFileData!.key), - fileTransfer: receivedFileData, - ); - }, - ), - ), - ) - ], - )), - ); - } - - refreshHistoryScreen() async { - if (historyProvider.status[historyProvider.PERIODIC_REFRESH] == - Status.Loading) { - return; - } - if (historyProvider.status[historyProvider.SENT_HISTORY] != - Status.Loading) { - await historyProvider.getSentHistory(); - } - - if (historyProvider.status[historyProvider.RECEIVED_HISTORY] != - Status.Loading) { - await historyProvider.getReceivedHistory(); - } - } - - searchHistoryField() { - return Container( - height: 50.toHeight, - decoration: BoxDecoration( - borderRadius: BorderRadius.circular(5), - color: ColorConstants.receivedSelectedTileColor, - ), - padding: EdgeInsets.fromLTRB(10, 3, 10, 5), - margin: EdgeInsets.fromLTRB(10, 3, 10, 5), - child: Row( - children: [ - Expanded( - child: TextField( - autofocus: true, - controller: _textController, - style: TextStyle(fontSize: 12), - onChanged: (String txt) { - historyProvider.setHistorySearchText = txt; - }, - decoration: InputDecoration( - border: InputBorder.none, - hintText: 'Search history by atsign'), - ), - ), - InkWell( - onTap: () { - setState(() { - _showSearchField = false; - historyProvider.setHistorySearchText = ""; - }); - }, - child: Icon(Icons.close), - ) - ], - ), - ); - } - - Widget getReceivedTiles(List filteredReceivedList) { - return ListView.separated( - padding: EdgeInsets.only(bottom: 170.toHeight), - physics: AlwaysScrollableScrollPhysics(), - separatorBuilder: (context, index) => Divider( - indent: 16.toWidth, - ), - itemCount: filteredReceivedList.length, - itemBuilder: (context, index) => Padding( - padding: const EdgeInsets.all(8.0), - child: InkWell( - onTap: () { - receivedFileData = filteredReceivedList[index]; - - setState(() { - receivedSelectedFileId = filteredReceivedList[index].key; - }); - }, - child: DesktopReceivedFilesListTile( - key: Key(filteredReceivedList[index].key), - receivedHistory: filteredReceivedList[index], - isSelected: - receivedSelectedFileId == filteredReceivedList[index].key - ? true - : false, - ), - ), - ), - ); - } - - getSentHistory(List filteredSentHistory) { - return ListView.separated( - padding: EdgeInsets.only(bottom: 170.toHeight), - physics: AlwaysScrollableScrollPhysics(), - separatorBuilder: (context, index) { - return Divider( - indent: 16.toWidth, - ); - }, - itemCount: filteredSentHistory.length, - itemBuilder: (context, index) { - return InkWell( - onTap: () { - setState(() { - sentSelectedIndex = index; - selectedSentFileData = filteredSentHistory[index]; - }); - }, - child: DesktopSentFilesListTile( - sentHistory: filteredSentHistory[index], - key: Key(filteredSentHistory[index].fileDetails!.key), - isSelected: index == sentSelectedIndex ? true : false, - ), - ); - }, - ); - } -} diff --git a/lib/desktop_screens/desktop_history/widgets/desktop_received_file_details.dart b/lib/desktop_screens/desktop_history/widgets/desktop_received_file_details.dart deleted file mode 100644 index 362debdf..00000000 --- a/lib/desktop_screens/desktop_history/widgets/desktop_received_file_details.dart +++ /dev/null @@ -1,546 +0,0 @@ -import 'dart:io'; - -import 'package:atsign_atmosphere_pro/data_models/file_transfer.dart'; -import 'package:atsign_atmosphere_pro/screens/common_widgets/labelled_circular_progress.dart'; -import 'package:atsign_atmosphere_pro/services/backend_service.dart'; -import 'package:atsign_atmosphere_pro/services/common_utility_functions.dart'; -import 'package:atsign_atmosphere_pro/services/navigation_service.dart'; -import 'package:atsign_atmosphere_pro/services/snackbar_service.dart'; -import 'package:atsign_atmosphere_pro/utils/colors.dart'; -import 'package:atsign_atmosphere_pro/utils/constants.dart'; -import 'package:atsign_atmosphere_pro/utils/text_strings.dart'; -import 'package:atsign_atmosphere_pro/utils/text_styles.dart'; -import 'package:atsign_atmosphere_pro/view_models/file_progress_provider.dart'; -import 'package:atsign_atmosphere_pro/view_models/history_provider.dart'; -import 'package:atsign_atmosphere_pro/view_models/my_files_provider.dart'; -import 'package:flutter/material.dart'; -import 'package:at_common_flutter/services/size_config.dart'; -import 'package:intl/intl.dart'; -import 'package:open_file/open_file.dart'; -import 'package:provider/provider.dart'; - -class DesktopReceivedFileDetails extends StatefulWidget { - final FileTransfer? fileTransfer; - final Key? key; - DesktopReceivedFileDetails({this.fileTransfer, this.key}); - - @override - _DesktopReceivedFileDetailsState createState() => - _DesktopReceivedFileDetailsState(); -} - -class _DesktopReceivedFileDetailsState - extends State { - int fileCount = 0, fileSize = 0; - bool isDownloadAvailable = false, - isDownloaded = false, - isFilesAvailableOffline = true, - isOverwrite = false; - List existingFileNamesToOverwrite = []; - Map _futureBuilder = {}; - - @override - void initState() { - super.initState(); - - fileCount = widget.fileTransfer!.files!.length; - widget.fileTransfer!.files!.forEach((element) { - fileSize += element.size!; - }); - - var expiryDate = widget.fileTransfer!.date!.add(Duration(days: 6)); - if (expiryDate.difference(DateTime.now()) > Duration(seconds: 0)) { - isDownloadAvailable = true; - } - - getFutureBuilders(); - isFilesAlreadyDownloaded(); - } - - String getDownloadDirectory(String name) { - return MixedConstants.RECEIVED_FILE_DIRECTORY + - Platform.pathSeparator + - widget.fileTransfer!.sender! + - Platform.pathSeparator + - name; - } - - getFutureBuilders() { - widget.fileTransfer!.files!.forEach((element) { - _futureBuilder[element.name] = CommonUtilityFunctions().isFilePresent( - getDownloadDirectory(element.name!), - ); - }); - } - - isFilesAlreadyDownloaded() async { - widget.fileTransfer!.files!.forEach((element) async { - String path = MixedConstants.RECEIVED_FILE_DIRECTORY + - Platform.pathSeparator + - (widget.fileTransfer!.sender ?? '') + - Platform.pathSeparator + - (element.name ?? ''); - File test = File(path); - bool fileExists = await test.exists(); - if (fileExists == false) { - if (mounted) { - setState(() { - isFilesAvailableOffline = false; - }); - } - } else { - var fileLatsModified = await test.lastModified(); - if (fileLatsModified.isBefore(widget.fileTransfer!.date!)) { - existingFileNamesToOverwrite.add(element.name); - if (mounted) { - setState(() { - isOverwrite = true; - }); - } - } - } - }); - } - - @override - Widget build(BuildContext context) { - return Container( - color: ColorConstants.selago, - height: SizeConfig().screenHeight, - width: SizeConfig().screenWidth * 0.45, - padding: EdgeInsets.only(left: 15, right: 15, top: 15), - child: SingleChildScrollView( - child: Column( - crossAxisAlignment: CrossAxisAlignment.start, - mainAxisAlignment: MainAxisAlignment.start, - children: [ - Row( - mainAxisAlignment: MainAxisAlignment.spaceBetween, - children: [ - Text( - TextStrings().details, - style: TextStyle(fontWeight: FontWeight.bold, fontSize: 20), - ), - Spacer(), - Column( - mainAxisAlignment: MainAxisAlignment.end, - crossAxisAlignment: CrossAxisAlignment.end, - children: [ - InkWell( - onTap: () async { - var _downloadPath = - (MixedConstants.ApplicationDocumentsDirectory ?? - '') + - Platform.pathSeparator + - (widget.fileTransfer!.sender ?? ''); - BackendService.getInstance() - .doesDirectoryExist(path: _downloadPath); - - await OpenFile.open(_downloadPath); - }, - child: Row( - children: [ - Icon(Icons.save_alt_outlined, color: Colors.black), - SizedBox(width: 10), - Text(TextStrings().downloadsFolder, - style: TextStyle( - color: Colors.black, - fontSize: 12, - fontWeight: FontWeight.normal, - )), - ], - ), - ), - SizedBox(height: 5), - Padding( - padding: const EdgeInsets.only(right: 10.0), - child: Consumer( - builder: (_c, provider, _) { - var fileTransferProgress = provider - .receivedFileProgress[widget.fileTransfer!.key]; - - return fileTransferProgress != null - ? getDownloadStatus(fileTransferProgress) - : isDownloadAvailable - ? Padding( - padding: const EdgeInsets.only(right: 10.0), - child: IconButton( - icon: ((isDownloaded || - isFilesAvailableOffline) && - !isOverwrite) - ? Icon( - Icons.done, - color: Color(0xFF08CB21), - size: 25.toFont, - ) - : Icon( - Icons.download, - color: Color(0xFF08CB21), - size: 30, - ), - onPressed: () async { - if (isOverwrite) { - overwriteDialog(); - return; - } - - downloadFiles(); - }, - ), - ) - : SizedBox(); - }), - ) - ], - ), - ], - ), - SizedBox(height: 15.toHeight), - Column( - children: [ - Align( - alignment: Alignment.topLeft, - child: Wrap( - alignment: WrapAlignment.start, - runAlignment: WrapAlignment.start, - runSpacing: 10.0, - spacing: 20.0, - children: List.generate(widget.fileTransfer!.files!.length, - (index) { - return Container( - width: 250, - child: ListTile( - title: Text( - widget.fileTransfer!.files![index].name!, - maxLines: 2, - overflow: TextOverflow.ellipsis, - style: TextStyle( - color: Colors.black, - fontSize: 14.toFont, - fontWeight: FontWeight.normal, - ), - ), - subtitle: Text( - double.parse(widget - .fileTransfer!.files![index].size - .toString()) <= - 1024 - ? '${widget.fileTransfer!.files![index].size} ${TextStrings().kb}' + - ' . ${widget.fileTransfer!.files![index].name!.split('.').last}' - : '${(widget.fileTransfer!.files![index].size! / (1024 * 1024)).toStringAsFixed(2)} ${TextStrings().mb}' + - ' . ${widget.fileTransfer!.files![index].name!.split('.').last}', - style: TextStyle( - color: ColorConstants.fadedText, - fontSize: 14.toFont, - fontWeight: FontWeight.normal, - ), - ), - leading: FutureBuilder( - key: Key( - widget.fileTransfer!.files![index].name!), - future: _futureBuilder[ - widget.fileTransfer!.files![index].name], - builder: (context, snapshot) { - return snapshot.connectionState == - ConnectionState.done && - snapshot.data != null - ? InkWell( - onTap: () { - handleFileCLick( - widget.fileTransfer!.files![index] - .name!, - ); - }, - child: CommonUtilityFunctions() - .thumbnail( - widget.fileTransfer! - .files![index].name - ?.split('.') - .last, - getDownloadDirectory( - widget.fileTransfer! - .files![index].name!), - isFilePresent: isOverwrite - ? false - : snapshot.data as bool), - ) - : SizedBox(); - }), - trailing: SizedBox()), - ); - }), - ), - ) - ], - ), - SizedBox(height: 15.toHeight), - Row( - children: [ - Text( - '${fileCount} File(s) . ', - style: CustomTextStyles.greyText15, - ), - fileSize > 1024 - ? Text( - '${(fileSize / (1024 * 1024)).toStringAsFixed(2)} ${TextStrings().mb}', - style: CustomTextStyles.greyText15) - : Text( - '${(fileSize).toStringAsFixed(2)} ${TextStrings().mb}', - style: CustomTextStyles.greyText15), - ], - ), - SizedBox(height: 15.toHeight), - Consumer( - builder: (_context, provider, _widget) { - var fileTransferProgress = - provider.receivedFileProgress[widget.fileTransfer!.key]; - return Text.rich( - TextSpan( - text: - '${DateFormat("MM-dd-yyyy").format(widget.fileTransfer!.date!)} | ${DateFormat('kk:mm').format(widget.fileTransfer!.date!)} ', - style: CustomTextStyles.greyText15, - children: [ - fileTransferProgress != null - ? TextSpan( - text: - '${getFileStateMessage(fileTransferProgress)}', - style: CustomTextStyles.blueRegular14) - : TextSpan(text: ''), - ]), - ); - }, - ), - SizedBox(height: 15.toHeight), - widget.fileTransfer!.notes != null && - widget.fileTransfer!.notes!.isNotEmpty - ? RichText( - text: TextSpan( - text: 'Note: ', - style: CustomTextStyles.primaryMedium14, - children: [ - TextSpan( - text: '${widget.fileTransfer!.notes}', - style: CustomTextStyles.redSmall12, - ) - ], - ), - ) - : SizedBox(), - SizedBox(height: 15.toHeight), - SizedBox(height: 15.toHeight), - ], - ), - ), - ); - } - - overwriteDialog() { - showDialog( - context: NavService.navKey.currentContext!, - builder: (context) { - return AlertDialog( - shape: RoundedRectangleBorder( - borderRadius: BorderRadius.circular(10.toWidth), - ), - content: Container( - width: 300.toWidth, - padding: EdgeInsets.all(15.toFont), - child: SingleChildScrollView( - child: Column( - crossAxisAlignment: CrossAxisAlignment.start, - children: [ - RichText( - text: TextSpan( - children: getOverwriteMessage(), - ), - ), - SizedBox( - height: 10.toHeight, - ), - Row( - mainAxisAlignment: MainAxisAlignment.spaceBetween, - children: [ - TextButton( - onPressed: () async { - Navigator.of(context).pop(); - await downloadFiles(); - }, - child: Text(TextStrings().yes, - style: TextStyle(fontSize: 16.toFont))), - TextButton( - onPressed: () { - Navigator.of(context).pop(); - }, - child: Text(TextStrings().buttonCancel, - style: TextStyle( - fontSize: 16.toFont, - fontWeight: FontWeight.normal, - ))) - ], - ) - ], - ), - ), - ), - ); - }); - } - - handleFileCLick(String fileName) async { - String filePath = getDownloadDirectory(fileName); - File test = File(filePath); - bool fileExists = await test.exists(); - if (fileExists) { - await OpenFile.open(filePath); - } - } - - List getOverwriteMessage() { - List textSpansMessage = []; - if (existingFileNamesToOverwrite.length == 1) { - textSpansMessage.add( - TextSpan( - children: [ - TextSpan( - text: TextStrings().fileNamed, - style: TextStyle( - color: Colors.black, - fontSize: 15.toFont, - fontWeight: FontWeight.normal, - )), - TextSpan( - text: '${existingFileNamesToOverwrite[0]}', - style: TextStyle( - color: Colors.black, - fontSize: 15.toFont, - fontWeight: FontWeight.bold)), - TextSpan( - text: TextStrings().alreadyExistsMsg, - style: TextStyle( - color: Colors.black, - fontSize: 15.toFont, - fontWeight: FontWeight.normal, - )), - ], - ), - ); - } else if (existingFileNamesToOverwrite.length > 1) { - textSpansMessage.add(TextSpan( - text: TextStrings().fileExists, - style: TextStyle( - color: Colors.black, - fontSize: 15.toFont, - fontWeight: FontWeight.normal, - ), - )); - - existingFileNamesToOverwrite.forEach((element) { - textSpansMessage.add( - TextSpan( - text: '\n$element', - style: TextStyle( - color: Colors.black, - fontSize: 13.toFont, - fontWeight: FontWeight.bold, - height: 1.5), - ), - ); - }); - - textSpansMessage.add( - TextSpan( - text: TextStrings().overWriteMsg, - style: TextStyle( - color: Colors.black, - fontSize: 15.toFont, - height: 2, - fontWeight: FontWeight.normal, - )), - ); - } - return textSpansMessage; - } - - downloadFiles() async { - var res = await Provider.of( - NavService.navKey.currentContext!, - listen: false) - .downloadFiles( - widget.fileTransfer!.key, - widget.fileTransfer!.sender!, - false, - ); - - if (res) { - if (mounted) { - getFutureBuilders(); - setState(() { - isDownloaded = true; - isOverwrite = false; - isFilesAvailableOffline = true; - }); - } - - SnackBarService().showSnackBar( - NavService.navKey.currentContext!, - TextStrings().fileDownload, - bgColor: ColorConstants.successGreen, - ); - - await Provider.of(NavService.navKey.currentContext!, - listen: false) - .saveNewDataInMyFiles(widget.fileTransfer!); - - await Provider.of(NavService.navKey.currentContext!, - listen: false) - .sendFileDownloadAcknowledgement(widget.fileTransfer!); - } else { - SnackBarService().showSnackBar( - NavService.navKey.currentContext!, - TextStrings().downloadFailed, - bgColor: ColorConstants.redAlert, - ); - } - } - - String getFileStateMessage(FileTransferProgress? fileTransferProgress) { - if (fileTransferProgress == null) { - return ''; - } - - var index = widget.fileTransfer!.files! - .indexWhere((element) => element.name == fileTransferProgress.fileName); - String fileState = ''; - if (fileTransferProgress.fileState == FileState.download) { - fileState = 'Downloading'; - } else if (fileTransferProgress.fileState == FileState.decrypt) { - fileState = 'Decrypting'; - } - - if (index != -1) { - fileState = - '${fileState} ${index + 1} of ${widget.fileTransfer!.files!.length} File(s)'; - } - return fileState; - } - - Widget getDownloadStatus(FileTransferProgress? fileTransferProgress) { - Widget spinner = CircularProgressIndicator( - valueColor: AlwaysStoppedAnimation( - ColorConstants.orange, - ), - ); - - if (fileTransferProgress == null) { - return spinner; - } - - if (fileTransferProgress.fileState == FileState.download && - fileTransferProgress.percent != null) { - spinner = LabelledCircularProgressIndicator( - value: (fileTransferProgress.percent! / 100)); - } - - return spinner; - } -} diff --git a/lib/desktop_screens/desktop_history/widgets/desktop_received_file_list_tile.dart b/lib/desktop_screens/desktop_history/widgets/desktop_received_file_list_tile.dart deleted file mode 100644 index 1cca30a0..00000000 --- a/lib/desktop_screens/desktop_history/widgets/desktop_received_file_list_tile.dart +++ /dev/null @@ -1,755 +0,0 @@ -import 'dart:io'; -import 'dart:typed_data'; -import 'package:at_contact/at_contact.dart'; -import 'package:at_contacts_flutter/utils/init_contacts_service.dart'; -import 'package:at_contacts_flutter/services/contact_service.dart'; -import 'package:atsign_atmosphere_pro/data_models/file_transfer.dart'; -import 'package:atsign_atmosphere_pro/screens/common_widgets/add_contact.dart'; -import 'package:atsign_atmosphere_pro/screens/common_widgets/confirmation_dialog.dart'; -import 'package:atsign_atmosphere_pro/screens/common_widgets/contact_initial.dart'; -import 'package:atsign_atmosphere_pro/screens/common_widgets/custom_button.dart'; -import 'package:atsign_atmosphere_pro/screens/common_widgets/custom_circle_avatar.dart'; -import 'package:atsign_atmosphere_pro/screens/common_widgets/triple_dot_loading.dart'; -import 'package:atsign_atmosphere_pro/services/common_utility_functions.dart'; -import 'package:atsign_atmosphere_pro/services/navigation_service.dart'; -import 'package:atsign_atmosphere_pro/services/snackbar_service.dart'; -import 'package:atsign_atmosphere_pro/utils/colors.dart'; -import 'package:atsign_atmosphere_pro/utils/constants.dart'; -import 'package:atsign_atmosphere_pro/utils/file_types.dart'; -import 'package:atsign_atmosphere_pro/utils/images.dart'; -import 'package:atsign_atmosphere_pro/utils/text_strings.dart'; -import 'package:atsign_atmosphere_pro/utils/text_styles.dart'; -import 'package:atsign_atmosphere_pro/view_models/history_provider.dart'; -import 'package:atsign_atmosphere_pro/view_models/my_files_provider.dart'; -import 'package:flutter/material.dart'; -import 'package:at_common_flutter/services/size_config.dart'; -import 'package:intl/intl.dart'; -import 'package:open_file/open_file.dart'; -import 'package:provider/provider.dart'; -import 'dart:math' as math; -import 'package:video_thumbnail/video_thumbnail.dart'; - -class DesktopReceivedFilesListTile extends StatefulWidget { - final FileTransfer? receivedHistory; - final bool isSelected; - - const DesktopReceivedFilesListTile({ - Key? key, - this.receivedHistory, - this.isSelected = false, - }) : super(key: key); - - @override - _DesktopReceivedFilesListTileState createState() => - _DesktopReceivedFilesListTileState(); -} - -class _DesktopReceivedFilesListTileState - extends State { - int fileLength = 0, fileSize = 0; - List? filesList = []; - late List contactList; - bool isOpen = false; - bool isDeepOpen = false; - Uint8List? videoThumbnail, firstContactImage; - String? contactName; - List fileResending = []; - bool isResendingToFirstContact = false, showDownloadIndicator = false; - - @override - void initState() { - super.initState(); - // isWidgetRebuilt = true; - fileLength = widget.receivedHistory!.files!.length; - fileResending = List.generate(fileLength, (i) => false); - contactList = [widget.receivedHistory!.sender]; - - filesList = widget.receivedHistory!.files; - - widget.receivedHistory!.files!.forEach((element) { - fileSize += element.size!; - }); - - getContactImage(); - } - - getContactImage() { - AtContact? contact; - - if (contactList[0] != null) { - contactName = CommonUtilityFunctions().getContactName(contactList[0]!); - contact = checkForCachedContactDetail(contactList[0]!); - } - if (contact != null) { - if (mounted) { - setState(() { - firstContactImage = - CommonUtilityFunctions().getContactImage(contact!); - }); - } - } - } - - Future videoThumbnailBuilder(String path) async { - videoThumbnail = await VideoThumbnail.thumbnailData( - video: path, - imageFormat: ImageFormat.JPEG, - maxWidth: 50, - // specify the width of the thumbnail, let the height auto-scaled to keep the source aspect ratio - quality: 100, - ); - return videoThumbnail; - } - - checkIfDownloadAvailable() async { - bool isExpired = true; - var expiryDate = widget.receivedHistory!.date!.add(Duration(days: 6)); - if (expiryDate.difference(DateTime.now()) > Duration(seconds: 0)) { - isExpired = false; - } - - if (isExpired) { - if (mounted) { - setState(() { - showDownloadIndicator = false; - }); - } - return; - } - - widget.receivedHistory!.files!.forEach((element) async { - String path = MixedConstants.RECEIVED_FILE_DIRECTORY + - Platform.pathSeparator + - (widget.receivedHistory!.sender ?? '') + - Platform.pathSeparator + - (element.name ?? ''); - File test = File(path); - bool fileExists = await test.exists(); - if (fileExists == false) { - showDownloadIndicator = true; - } else { - showDownloadIndicator = false; - } - }); - - if (mounted) { - setState(() {}); - } - } - - @override - void didUpdateWidget(covariant DesktopReceivedFilesListTile oldWidget) { - WidgetsBinding.instance.addPostFrameCallback((timeStamp) async { - await checkIfDownloadAvailable(); - }); - super.didUpdateWidget(oldWidget); - } - - @override - void didChangeDependencies() { - WidgetsBinding.instance.addPostFrameCallback((timeStamp) async { - await checkIfDownloadAvailable(); - }); - super.didChangeDependencies(); - } - - @override - Widget build(BuildContext context) { - double deviceTextFactor = MediaQuery.of(context).textScaleFactor; - - return Column( - children: [ - Container( - color: (widget.isSelected) - ? ColorConstants.receivedSelectedTileColor - : null, - child: ListTile( - leading: contactList.isNotEmpty - ? isResendingToFirstContact - ? TypingIndicator( - showIndicator: true, - flashingCircleBrightColor: ColorConstants.dullText, - flashingCircleDarkColor: ColorConstants.fadedText, - ) - : Stack( - children: [ - Container( - width: 50, - height: 50, - child: firstContactImage != null - ? CustomCircleAvatar( - byteImage: firstContactImage, - nonAsset: true) - : ContactInitial( - initials: contactList[0], - size: 50, - ), - ), - showDownloadIndicator - ? Positioned( - right: 1, - child: Container( - decoration: BoxDecoration( - color: Colors.white, - shape: BoxShape.circle, - ), - padding: EdgeInsets.all(1.toHeight), - child: CircleAvatar( - backgroundColor: - ColorConstants.orangeColor, - radius: 5.toWidth, - ), - ), - ) - : SizedBox(), - widget.receivedHistory!.sender != null - ? Positioned( - right: 0, - child: GestureDetector( - onTap: ((widget.receivedHistory!.sender != - null) && - (ContactService() - .contactList - .indexWhere((element) => - element.atSign == - widget.receivedHistory! - .sender) == - -1)) - ? () async { - await showDialog( - context: context, - barrierDismissible: true, - builder: (BuildContext context) { - return AddContact( - atSignName: widget - .receivedHistory!.sender, - image: firstContactImage, - ); - }, - ); - if (mounted) { - setState(() {}); - } - } - : null, - child: ((widget.receivedHistory!.sender != - null) && - (ContactService() - .contactList - .indexWhere((element) => - element.atSign == - widget.receivedHistory! - .sender) == - -1)) - ? Container( - height: 20, - width: 20, - decoration: BoxDecoration( - shape: BoxShape.circle, - color: Colors.white, - ), - child: Icon( - Icons.person_add, - size: 15.toFont, - ), - ) - : SizedBox(), - ), - ) - : SizedBox(), - ], - ) - : SizedBox(), - title: Column( - crossAxisAlignment: CrossAxisAlignment.start, - children: [ - Row( - mainAxisAlignment: MainAxisAlignment.spaceBetween, - children: [ - Expanded( - child: Column( - crossAxisAlignment: CrossAxisAlignment.start, - children: [ - contactName != null - ? Text( - contactName ?? '', - style: CustomTextStyles.primaryRegularBold18, - ) - : SizedBox(), - SizedBox(height: 10), - contactList.isNotEmpty - ? Text( - contactList[0]!, - style: CustomTextStyles.primaryRegular18, - ) - : SizedBox(), - ], - )), - ], - ), - SizedBox(height: 13.toHeight), - Container( - child: Column( - children: [ - Row( - mainAxisAlignment: MainAxisAlignment.start, - children: [ - Text( - '${fileLength} File(s)', - style: CustomTextStyles.secondaryRegular14, - ), - SizedBox(width: 10.toHeight), - Text( - '.', - style: CustomTextStyles.secondaryRegular14, - ), - SizedBox(width: 10.toHeight), - Text( - double.parse(fileSize.toString()) <= 1024 - ? '${fileSize} Kb ' - : '${(fileSize / (1024 * 1024)).toStringAsFixed(2)} Mb', - style: CustomTextStyles.secondaryRegular14, - ), - Expanded( - child: Row( - mainAxisAlignment: MainAxisAlignment.end, - children: [ - widget.isSelected - ? InkWell( - onTap: deleteReceivedItem, - child: Icon(Icons.delete), - ) - : Transform.rotate( - angle: 180 * math.pi / 340, - child: Icon(Icons.keyboard_arrow_up), - ), - ], - ), - ) - ], - ), - ], - ), - ), - SizedBox( - height: 20.toHeight, - ), - Container( - child: Row( - mainAxisAlignment: MainAxisAlignment.start, - children: [ - widget.receivedHistory!.date != null - ? Text( - '${DateFormat("MM-dd-yyyy").format(widget.receivedHistory!.date!)}', - style: CustomTextStyles.secondaryRegular14, - maxLines: 1, - overflow: TextOverflow.ellipsis, - ) - : SizedBox(), - SizedBox(width: 10.toHeight), - Container( - color: ColorConstants.fontSecondary, - height: 14.toHeight, - width: 1.toWidth, - ), - SizedBox(width: 10.toHeight), - widget.receivedHistory!.date != null - ? Text( - '${DateFormat('kk:mm').format(widget.receivedHistory!.date!)}', - style: CustomTextStyles.secondaryRegular14, - maxLines: 1, - overflow: TextOverflow.ellipsis, - ) - : SizedBox(), - ], - ), - ), - SizedBox(height: 3.toHeight), - ], - ), - ), - ), - (isOpen) - ? Container( - color: Color(0xffF86060).withAlpha(50), - child: Column( - crossAxisAlignment: CrossAxisAlignment.start, - children: [ - Container( - height: 70.0 * widget.receivedHistory!.files!.length, - child: ListView.separated( - separatorBuilder: (context, index) => Divider( - indent: 80.toWidth, - ), - itemCount: fileLength, - physics: NeverScrollableScrollPhysics(), - itemBuilder: (context, index) { - if (FileTypes.VIDEO_TYPES.contains( - filesList![index].name?.split('.').last)) { - videoThumbnailBuilder(filesList![index].path!); - } - return ListTile( - onTap: () async { - String _path = - MixedConstants.SENT_FILE_DIRECTORY + - Platform.pathSeparator + - (filesList![index].name ?? ''); - File test = File(_path); - bool fileExists = await test.exists(); - print( - 'test file: ${test}, fileExists: ${fileExists}'); - if (fileExists) { - await OpenFile.open(_path); - } else { - _showNoFileDialog(deviceTextFactor); - } - }, - leading: Container( - height: 50.toHeight, - width: 50.toHeight, - child: FutureBuilder( - future: isFilePresent( - MixedConstants.SENT_FILE_DIRECTORY + - Platform.pathSeparator + - (filesList![index].name ?? '')), - builder: (context, snapshot) { - return snapshot.connectionState == - ConnectionState.done && - snapshot.data != null - ? thumbnail( - filesList![index] - .name - ?.split('.') - .last, - MixedConstants - .SENT_FILE_DIRECTORY + - Platform.pathSeparator + - (filesList![index].name ?? - ''), - isFilePresent: - snapshot.data as bool) - : SizedBox(); - }), - ), - title: Column( - crossAxisAlignment: CrossAxisAlignment.start, - children: [ - Row( - children: [ - Expanded( - child: Text( - filesList![index].name.toString(), - style: - CustomTextStyles.primaryRegular16, - ), - ), - Container( - child: filesList![index].isUploaded != - null && - filesList![index].isUploaded! - ? Icon( - Icons.done, - color: Color(0xFF08CB21), - size: 25.toFont, - ) - : fileResending[index] - ? TypingIndicator( - showIndicator: true, - flashingCircleBrightColor: - ColorConstants.dullText, - flashingCircleDarkColor: - ColorConstants - .fadedText, - ) - : InkWell( - onTap: () async { - setState(() { - fileResending[index] = - true; - }); - - fileResending[index] = - false; - }, - child: Icon( - Icons.refresh, - color: Color(0xFFF86061), - size: 25.toFont, - ), - ), - ) - ], - ), - SizedBox(width: 10.toHeight), - Container( - child: Row( - mainAxisAlignment: - MainAxisAlignment.start, - children: [ - Text( - double.parse(filesList![index] - .size - .toString()) <= - 1024 - ? '${filesList![index].size} Kb ' - : '${(filesList![index].size! / (1024 * 1024)).toStringAsFixed(2)} Mb', - style: CustomTextStyles - .secondaryRegular14, - ), - SizedBox(width: 10.toHeight), - Text( - '.', - style: CustomTextStyles - .secondaryRegular14, - ), - SizedBox(width: 10.toHeight), - ], - ), - ) - ], - ), - ); - }), - ), - (contactList.length < 2) - ? Container() - : SizedBox( - height: 10.toHeight, - ), - (contactList.length < 2) - ? Container() - : Row( - children: [ - Expanded( - child: Container( - padding: EdgeInsets.only(left: 20.toWidth), - child: Text( - 'Delivered to', - style: CustomTextStyles.primaryRegular16, - ), - ), - ), - ], - ), - GestureDetector( - onTap: () { - setState(() { - isOpen = !isOpen; - }); - }, - child: Container( - margin: EdgeInsets.only(left: 20.toWidth), - child: Row( - children: [ - Text( - 'Lesser Details', - style: CustomTextStyles.primaryBold14, - ), - Container( - width: 22.toWidth, - height: 22.toWidth, - child: Center( - child: Icon( - Icons.keyboard_arrow_up, - color: Colors.black, - ), - ), - ) - ], - ), - ), - ), - ], - ), - ) - : Container() - ], - ); - } - - Widget thumbnail(String? extension, String path, - {bool? isFilePresent = true}) { - return FileTypes.IMAGE_TYPES.contains(extension) - ? ClipRRect( - borderRadius: BorderRadius.circular(10.toHeight), - child: Container( - height: 50.toHeight, - width: 50.toWidth, - child: isFilePresent! - ? Image.file( - File(path), - fit: BoxFit.cover, - errorBuilder: (BuildContext _context, _, __) { - return Container( - child: Icon( - Icons.image, - size: 30.toFont, - ), - ); - }, - ) - : Icon( - Icons.image, - size: 30.toFont, - ), - ), - ) - : FileTypes.VIDEO_TYPES.contains(extension) - ? FutureBuilder( - future: videoThumbnailBuilder(path), - builder: (context, snapshot) => ClipRRect( - borderRadius: BorderRadius.circular(10.toHeight), - child: Container( - padding: EdgeInsets.only(left: 10), - height: 50.toHeight, - width: 50.toWidth, - child: (snapshot.data == null) - ? Image.asset( - ImageConstants.videoLogo, - fit: BoxFit.cover, - ) - : Image.memory( - videoThumbnail!, - fit: BoxFit.cover, - errorBuilder: (BuildContext _context, _, __) { - return Container( - child: Icon( - Icons.image, - size: 30.toFont, - ), - ); - }, - ), - ), - ), - ) - : ClipRRect( - borderRadius: BorderRadius.circular(10.toHeight), - child: Container( - padding: EdgeInsets.only(left: 10), - height: 50.toHeight, - width: 50.toWidth, - child: Image.asset( - FileTypes.PDF_TYPES.contains(extension) - ? ImageConstants.pdfLogo - : FileTypes.AUDIO_TYPES.contains(extension) - ? ImageConstants.musicLogo - : FileTypes.WORD_TYPES.contains(extension) - ? ImageConstants.wordLogo - : FileTypes.EXEL_TYPES.contains(extension) - ? ImageConstants.exelLogo - : FileTypes.TEXT_TYPES.contains(extension) - ? ImageConstants.txtLogo - : ImageConstants.unknownLogo, - fit: BoxFit.cover, - ), - ), - ); - } - - void _showNoFileDialog(double deviceTextFactor) { - showDialog( - context: context, - builder: (BuildContext context) { - return Dialog( - shape: RoundedRectangleBorder( - borderRadius: BorderRadius.circular(12.0)), - child: Container( - height: 200.0, - width: 300.0, - child: Column( - mainAxisAlignment: MainAxisAlignment.center, - children: [ - Padding(padding: EdgeInsets.only(top: 15.0)), - Text( - TextStrings().noFileFound, - style: CustomTextStyles.primaryBold16, - ), - Padding(padding: EdgeInsets.only(top: 30.0)), - Row( - mainAxisAlignment: MainAxisAlignment.center, - children: [ - CustomButton( - height: 50.toHeight * deviceTextFactor, - isInverted: false, - buttonText: TextStrings().buttonClose, - onPressed: () => Navigator.pop(context), - ) - ], - ), - ], - ), - ), - ); - }); - } - - Future isFilePresent(String filePath) async { - File file = File(filePath); - bool fileExists = await file.exists(); - return fileExists; - } - - deleteReceivedItem() async { - await showDialog( - context: NavService.navKey.currentContext!, - builder: (context) { - return AlertDialog( - shape: RoundedRectangleBorder( - borderRadius: BorderRadius.circular(10.toWidth), - ), - content: ConfirmationDialog(TextStrings.deleteFileConfirmationMsg, - () async { - var res = - await Provider.of(context, listen: false) - .deleteReceivedItem(widget.receivedHistory!); - - if (res) { - SnackBarService().showSnackBar( - NavService.navKey.currentContext!, - 'Removed from received items list', - bgColor: ColorConstants.successGreen); - await deleteFileWhenRecevedItemRemoved(); - } else { - SnackBarService().showSnackBar( - NavService.navKey.currentContext!, 'Failed', - bgColor: ColorConstants.redAlert); - } - })); - }); - } - - deleteFileWhenRecevedItemRemoved() async { - await showDialog( - context: NavService.navKey.currentContext!, - builder: (context) { - return AlertDialog( - shape: RoundedRectangleBorder( - borderRadius: BorderRadius.circular(10.toWidth), - ), - content: ConfirmationDialog( - TextStrings.deleteDownloadedFileMessage, () async { - await Future.forEach(widget.receivedHistory!.files!, - (FileData element) async { - String filePath = MixedConstants.RECEIVED_FILE_DIRECTORY + - Platform.pathSeparator + - (widget.receivedHistory!.sender ?? '') + - Platform.pathSeparator + - (element.name ?? ''); - - if (await CommonUtilityFunctions().isFilePresent(filePath)) { - var file = File(filePath); - if (await file.existsSync()) { - file.deleteSync(); - } - } - }); - - await Provider.of( - NavService.navKey.currentContext!, - listen: false) - .deleteMyFileRecord(widget.receivedHistory!.key); - })); - }); - } -} diff --git a/lib/desktop_screens/desktop_history/widgets/desktop_sent_file_details.dart b/lib/desktop_screens/desktop_history/widgets/desktop_sent_file_details.dart deleted file mode 100644 index a2448bb4..00000000 --- a/lib/desktop_screens/desktop_history/widgets/desktop_sent_file_details.dart +++ /dev/null @@ -1,258 +0,0 @@ -import 'dart:io'; - -import 'package:atsign_atmosphere_pro/data_models/file_transfer.dart'; -import 'package:atsign_atmosphere_pro/desktop_screens/desktop_history/widgets/desktop_transfer_overlapping.dart'; -import 'package:atsign_atmosphere_pro/screens/common_widgets/triple_dot_loading.dart'; -import 'package:atsign_atmosphere_pro/services/common_utility_functions.dart'; -import 'package:atsign_atmosphere_pro/utils/colors.dart'; -import 'package:atsign_atmosphere_pro/utils/constants.dart'; -import 'package:atsign_atmosphere_pro/utils/text_styles.dart'; -import 'package:atsign_atmosphere_pro/view_models/file_transfer_provider.dart'; -import 'package:flutter/material.dart'; -import 'package:at_common_flutter/services/size_config.dart'; -import 'package:intl/intl.dart'; -import 'package:open_file/open_file.dart'; -import 'package:provider/provider.dart'; -import 'package:atsign_atmosphere_pro/utils/text_strings.dart'; - -class DesktopSentFileDetails extends StatefulWidget { - final FileHistory? selectedFileData; - - DesktopSentFileDetails({ - Key? key, - this.selectedFileData, - }); - - @override - _DesktopSentFileDetailsState createState() => _DesktopSentFileDetailsState(); -} - -class _DesktopSentFileDetailsState extends State { - int fileCount = 0, fileSize = 0; - Map _futureBuilder = {}; - - @override - void initState() { - super.initState(); - fileCount = widget.selectedFileData!.fileDetails!.files!.length; - widget.selectedFileData!.fileDetails!.files!.forEach((element) { - fileSize += element.size!; - }); - getFutureBuilders(); - } - - getFutureBuilders() { - widget.selectedFileData!.fileDetails!.files!.forEach((element) { - _futureBuilder[element.name] = CommonUtilityFunctions() - .isFilePresent(MixedConstants.SENT_FILE_DIRECTORY + element.name!); - }); - } - - @override - Widget build(BuildContext context) { - return Container( - color: ColorConstants.selago, - height: SizeConfig().screenHeight - MixedConstants.APPBAR_HEIGHT, - width: SizeConfig().screenWidth * 0.45, - padding: EdgeInsets.only(left: 15, right: 15, top: 15), - child: SingleChildScrollView( - child: Column( - crossAxisAlignment: CrossAxisAlignment.start, - children: [ - Text(TextStrings().details, - style: TextStyle(fontWeight: FontWeight.bold, fontSize: 20)), - SizedBox(height: 15.toHeight), - Column( - children: [ - Align( - alignment: Alignment.topLeft, - child: Wrap( - alignment: WrapAlignment.start, - runAlignment: WrapAlignment.start, - runSpacing: 10.0, - spacing: 20.0, - children: List.generate( - widget.selectedFileData!.fileDetails!.files!.length, - (index) { - return Container( - width: 250, - child: ListTile( - title: Text( - widget.selectedFileData!.fileDetails!.files![index] - .name!, - style: TextStyle( - color: Colors.black, - fontSize: 14.toFont, - fontWeight: FontWeight.normal, - ), - maxLines: 3, - overflow: TextOverflow.ellipsis, - ), - subtitle: Text( - double.parse(widget.selectedFileData!.fileDetails! - .files![index].size - .toString()) <= - 1024 - ? '${widget.selectedFileData!.fileDetails!.files![index].size} ${TextStrings().kb}' + - ' . ${widget.selectedFileData!.fileDetails!.files![index].name!.split('.').last}' - : '${(widget.selectedFileData!.fileDetails!.files![index].size! / (1024 * 1024)).toStringAsFixed(2)} ${TextStrings().mb}' + - ' . ${widget.selectedFileData!.fileDetails!.files![index].name!.split('.').last} ', - style: TextStyle( - color: ColorConstants.fadedText, - fontSize: 14.toFont, - fontWeight: FontWeight.normal, - ), - ), - leading: InkWell( - onTap: () async { - String filePath = - MixedConstants.DESKTOP_SENT_DIR + - widget.selectedFileData!.fileDetails! - .files![index].name!; - - await OpenFile.open(filePath); - }, - child: FutureBuilder( - key: Key(widget.selectedFileData!.fileDetails! - .files![index].name!), - future: _futureBuilder[widget - .selectedFileData! - .fileDetails! - .files![index] - .name], - builder: (context, snapshot) { - return snapshot.connectionState == - ConnectionState.done && - snapshot.data != null - ? InkWell( - onTap: () async { - String filePath = MixedConstants - .DESKTOP_SENT_DIR + - widget - .selectedFileData! - .fileDetails! - .files![index] - .name!; - - if (await File(filePath) - .exists()) { - await OpenFile.open(filePath); - } - }, - child: CommonUtilityFunctions() - .thumbnail( - widget - .selectedFileData! - .fileDetails! - .files![index] - .name - ?.split('.') - .last, - MixedConstants - .DESKTOP_SENT_DIR + - widget - .selectedFileData! - .fileDetails! - .files![index] - .name!, - isFilePresent: - snapshot.data as bool), - ) - : SizedBox(); - })), - trailing: IconButton( - icon: (widget.selectedFileData!.fileDetails! - .files![index].isUploaded != - null && - widget.selectedFileData!.fileDetails! - .files![index].isUploaded!) - ? SizedBox() - : (widget.selectedFileData!.fileDetails! - .files![index].isUploading != - null && - widget.selectedFileData!.fileDetails! - .files![index].isUploading!) - ? TypingIndicator( - showIndicator: true, - flashingCircleBrightColor: - ColorConstants.dullText, - flashingCircleDarkColor: - ColorConstants.fadedText, - ) - : Icon( - Icons.refresh, - color: ColorConstants.redAlert, - ), - onPressed: () async { - await Provider.of(context, - listen: false) - .reUploadFiles( - widget.selectedFileData!.fileDetails! - .files!, - index, - widget.selectedFileData!); - }, - ), - ), - ); - }), - ), - ) - ], - ), - SizedBox(height: 15.toHeight), - Row( - children: [ - Text( - '${fileCount.toString()} ${TextStrings().file_s}', - style: CustomTextStyles.greyText15, - ), - fileSize > 1024 - ? Text( - '${(fileSize / (1024 * 1024)).toStringAsFixed(2)} ${TextStrings().mb}', - style: CustomTextStyles.greyText15) - : Text('${fileSize.toStringAsFixed(2)} ${TextStrings().kb}', - style: CustomTextStyles.greyText15), - ], - ), - // SizedBox(height: 15.toHeight), - // Text('Successfully transfered', style: CustomTextStyles.greyText15), - SizedBox(height: 15.toHeight), - Text( - '${DateFormat("MM-dd-yyyy").format(widget.selectedFileData!.fileDetails!.date!)} | ${DateFormat('kk:mm').format(widget.selectedFileData!.fileDetails!.date!)}', - style: CustomTextStyles.greyText15), - SizedBox(height: 15.toHeight), - // Text('To', style: CustomTextStyles.greyText15), - // Container( - // padding: EdgeInsets.symmetric(horizontal: 20.toHeight), - // child: Divider(height: 5), - // ), - widget.selectedFileData!.notes != null && - widget.selectedFileData!.notes!.isNotEmpty - ? RichText( - text: TextSpan( - text: 'Note: ', - style: CustomTextStyles.primaryMedium14, - children: [ - TextSpan( - text: '${widget.selectedFileData!.notes}', - style: CustomTextStyles.redSmall12, - ) - ], - ), - ) - : SizedBox(), - SizedBox(height: 15.toHeight), - widget.selectedFileData != null - ? DesktopTransferOverlappingContacts( - key: Key(widget - .selectedFileData!.fileTransferObject!.transferId), - selectedList: widget.selectedFileData!.sharedWith, - fileHistory: widget.selectedFileData) - : SizedBox() - ], - ), - ), - ); - } -} diff --git a/lib/desktop_screens/desktop_history/widgets/desktop_sent_file_list_tile.dart b/lib/desktop_screens/desktop_history/widgets/desktop_sent_file_list_tile.dart deleted file mode 100644 index d1ee3f94..00000000 --- a/lib/desktop_screens/desktop_history/widgets/desktop_sent_file_list_tile.dart +++ /dev/null @@ -1,632 +0,0 @@ -import 'dart:io'; -import 'dart:typed_data'; -import 'package:at_contact/at_contact.dart'; -import 'package:at_contacts_flutter/utils/init_contacts_service.dart'; -import 'package:atsign_atmosphere_pro/data_models/file_transfer.dart'; -import 'package:atsign_atmosphere_pro/screens/common_widgets/confirmation_dialog.dart'; -import 'package:atsign_atmosphere_pro/screens/common_widgets/contact_initial.dart'; -import 'package:atsign_atmosphere_pro/screens/common_widgets/custom_button.dart'; -import 'package:atsign_atmosphere_pro/screens/common_widgets/custom_circle_avatar.dart'; -import 'package:atsign_atmosphere_pro/screens/common_widgets/triple_dot_loading.dart'; -import 'package:atsign_atmosphere_pro/services/common_utility_functions.dart'; -import 'package:atsign_atmosphere_pro/services/navigation_service.dart'; -import 'package:atsign_atmosphere_pro/utils/colors.dart'; -import 'package:atsign_atmosphere_pro/utils/constants.dart'; -import 'package:atsign_atmosphere_pro/utils/file_types.dart'; -import 'package:atsign_atmosphere_pro/utils/images.dart'; -import 'package:atsign_atmosphere_pro/utils/text_strings.dart'; -import 'package:atsign_atmosphere_pro/utils/text_styles.dart'; -import 'package:atsign_atmosphere_pro/view_models/file_transfer_provider.dart'; -import 'package:atsign_atmosphere_pro/view_models/history_provider.dart'; -import 'package:flutter/material.dart'; -import 'package:at_common_flutter/services/size_config.dart'; -import 'package:intl/intl.dart'; -import 'package:open_file/open_file.dart'; -import 'package:provider/provider.dart'; -import 'dart:math' as math; -import 'package:video_thumbnail/video_thumbnail.dart'; - -class DesktopSentFilesListTile extends StatefulWidget { - final FileHistory? sentHistory; - final bool isSelected; - - const DesktopSentFilesListTile( - {Key? key, this.sentHistory, this.isSelected = false}) - : super(key: key); - @override - _DesktopSentFilesListTileState createState() => - _DesktopSentFilesListTileState(); -} - -class _DesktopSentFilesListTileState extends State { - int fileLength = 0, fileSize = 0; - List? filesList = []; - late List contactList; - bool isOpen = false; - bool isDeepOpen = false; - Uint8List? videoThumbnail, firstContactImage; - List fileResending = []; - bool isResendingToFirstContact = false, isFileSharedToGroup = false; - String? contactName; - - @override - void initState() { - super.initState(); - fileLength = widget.sentHistory!.fileDetails!.files!.length; - fileResending = List.generate(fileLength, (i) => false); - if (widget.sentHistory!.sharedWith != null) { - contactList = - widget.sentHistory!.sharedWith!.map((e) => e.atsign).toList(); - } else { - contactList = []; - } - filesList = widget.sentHistory!.fileDetails!.files; - - widget.sentHistory!.fileDetails!.files!.forEach((element) { - fileSize += element.size!; - }); - - if (widget.sentHistory!.sharedWith!.isNotEmpty) { - contactName = CommonUtilityFunctions() - .getContactName(widget.sentHistory!.sharedWith![0].atsign!); - } - - getContactImage(); - if (widget.sentHistory!.groupName != null) { - isFileSharedToGroup = true; - } - } - - getContactImage() { - AtContact? contact; - if (contactList[0] != null) { - contact = checkForCachedContactDetail(contactList[0]!); - } - if (contact != null) { - if (mounted) { - setState(() { - firstContactImage = - CommonUtilityFunctions().getContactImage(contact!); - }); - } - } - } - - Future videoThumbnailBuilder(String path) async { - videoThumbnail = await VideoThumbnail.thumbnailData( - video: path, - imageFormat: ImageFormat.JPEG, - maxWidth: - 50, // specify the width of the thumbnail, let the height auto-scaled to keep the source aspect ratio - quality: 100, - ); - return videoThumbnail; - } - - @override - Widget build(BuildContext context) { - double deviceTextFactor = MediaQuery.of(context).textScaleFactor; - - return Column( - children: [ - Container( - color: (widget.isSelected) ? ColorConstants.selected_list : null, - child: ListTile( - leading: contactList.isNotEmpty - ? (firstContactImage != null && !isFileSharedToGroup) - ? CustomCircleAvatar( - byteImage: firstContactImage, nonAsset: true) - : Container( - width: 45.toHeight, - height: 45.toHeight, - child: isResendingToFirstContact - ? TypingIndicator( - showIndicator: true, - flashingCircleBrightColor: - ColorConstants.dullText, - flashingCircleDarkColor: - ColorConstants.fadedText, - ) - : Stack( - children: [ - Container( - width: 100.toHeight, - height: 100.toHeight, - child: (firstContactImage != null && - !isFileSharedToGroup) - ? CustomCircleAvatar( - byteImage: firstContactImage, - nonAsset: true, - ) - : ContactInitial( - initials: isFileSharedToGroup - ? widget.sentHistory!.groupName - : contactList[0], - size: 45, - ), - ), - ], - ), - ) - : SizedBox(), - title: Column( - crossAxisAlignment: CrossAxisAlignment.start, - children: [ - isFileSharedToGroup == false - ? Row( - mainAxisAlignment: MainAxisAlignment.spaceBetween, - children: [ - Expanded( - child: Column( - crossAxisAlignment: CrossAxisAlignment.start, - children: [ - contactList.isNotEmpty - ? contactName != null - ? Text( - contactName!, - style: CustomTextStyles - .primaryRegularBold18, - ) - : SizedBox() - : SizedBox(), - SizedBox(height: 10), - contactList.isNotEmpty - ? Text( - contactList[0]!, - style: CustomTextStyles.primaryRegular18, - ) - : SizedBox(), - ], - )), - ], - ) - : Row( - mainAxisAlignment: MainAxisAlignment.spaceBetween, - children: [ - Expanded( - child: InkWell( - child: Text( - widget.sentHistory!.groupName!, - style: CustomTextStyles.primaryRegularBold18, - )), - ) - ], - ), - SizedBox(height: 5.toHeight), - SizedBox( - height: 8.toHeight, - ), - Container( - child: Column( - children: [ - Row( - mainAxisAlignment: MainAxisAlignment.start, - children: [ - Text( - '${fileLength} Files', - style: CustomTextStyles.secondaryRegular14, - ), - SizedBox(width: 10.toHeight), - Text( - '.', - style: CustomTextStyles.secondaryRegular14, - ), - SizedBox(width: 10.toHeight), - Text( - double.parse(fileSize.toString()) <= 1024 - ? '${fileSize} Kb ' - : '${(fileSize / (1024 * 1024)).toStringAsFixed(2)} Mb', - style: CustomTextStyles.secondaryRegular14, - ), - Expanded( - child: Row( - mainAxisAlignment: MainAxisAlignment.end, - children: [ - widget.isSelected - ? InkWell( - onTap: deleteSentItem, - child: Icon(Icons.delete), - ) - : Transform.rotate( - angle: 180 * math.pi / 340, - child: Icon(Icons.keyboard_arrow_up), - ), - ], - ), - ) - ], - ), - ], - ), - ), - SizedBox( - height: 20.toHeight, - ), - Container( - child: Row( - mainAxisAlignment: MainAxisAlignment.start, - children: [ - widget.sentHistory!.fileDetails!.date != null - ? Text( - '${DateFormat("MM-dd-yyyy").format(widget.sentHistory!.fileDetails!.date!)}', - style: CustomTextStyles.secondaryRegular14, - maxLines: 1, - overflow: TextOverflow.ellipsis, - ) - : SizedBox(), - SizedBox(width: 10.toHeight), - Container( - color: ColorConstants.fontSecondary, - height: 14.toHeight, - width: 1.toWidth, - ), - SizedBox(width: 10.toHeight), - widget.sentHistory!.fileDetails!.date != null - ? Text( - '${DateFormat('kk:mm').format(widget.sentHistory!.fileDetails!.date!)}', - style: CustomTextStyles.secondaryRegular14, - maxLines: 1, - overflow: TextOverflow.ellipsis, - ) - : SizedBox(), - ], - ), - ), - SizedBox(height: 3.toHeight), - ], - ), - ), - ), - (isOpen) - ? Container( - color: Color(0xffF86060).withAlpha(50), - child: Column( - crossAxisAlignment: CrossAxisAlignment.start, - children: [ - Container( - height: - 70.0 * widget.sentHistory!.fileDetails!.files!.length, - child: ListView.separated( - separatorBuilder: (context, index) => Divider( - indent: 80.toWidth, - ), - itemCount: fileLength, - physics: NeverScrollableScrollPhysics(), - itemBuilder: (context, index) { - if (FileTypes.VIDEO_TYPES.contains( - filesList![index].name?.split('.').last)) { - videoThumbnailBuilder(filesList![index].path!); - } - return ListTile( - onTap: () async { - String _path = - MixedConstants.SENT_FILE_DIRECTORY + - Platform.pathSeparator + - (filesList![index].name ?? ''); - File test = File(_path); - bool fileExists = await test.exists(); - print( - 'test file: ${test}, fileExists: ${fileExists}'); - if (fileExists) { - await OpenFile.open(_path); - } else { - _showNoFileDialog(deviceTextFactor); - } - }, - leading: Container( - height: 50.toHeight, - width: 50.toHeight, - child: FutureBuilder( - future: isFilePresent( - MixedConstants.SENT_FILE_DIRECTORY + - Platform.pathSeparator + - (filesList![index].name ?? '')), - builder: (context, snapshot) { - return snapshot.connectionState == - ConnectionState.done && - snapshot.data != null - ? thumbnail( - filesList![index] - .name - ?.split('.') - .last, - MixedConstants - .SENT_FILE_DIRECTORY + - Platform.pathSeparator + - (filesList![index].name ?? - ''), - isFilePresent: - snapshot.data as bool) - : SizedBox(); - })), - title: Column( - crossAxisAlignment: CrossAxisAlignment.start, - children: [ - Row( - children: [ - Expanded( - child: Text( - filesList![index].name.toString(), - style: - CustomTextStyles.primaryRegular16, - ), - ), - Container( - child: filesList![index].isUploaded != - null && - filesList![index].isUploaded! - ? Icon( - Icons.done, - color: Color(0xFF08CB21), - size: 25.toFont, - ) - : fileResending[index] - ? TypingIndicator( - showIndicator: true, - flashingCircleBrightColor: - ColorConstants.dullText, - flashingCircleDarkColor: - ColorConstants - .fadedText, - ) - : InkWell( - onTap: () async { - setState(() { - fileResending[index] = - true; - }); - await Provider.of< - FileTransferProvider>( - context, - listen: false) - .reUploadFiles( - filesList!, - index, - widget - .sentHistory!); - - // isWidgetRebuilt = true; - fileResending[index] = - false; - }, - child: Icon( - Icons.refresh, - color: Color(0xFFF86061), - size: 25.toFont, - ), - ), - ) - ], - ), - SizedBox(width: 10.toHeight), - Container( - child: Row( - mainAxisAlignment: - MainAxisAlignment.start, - children: [ - Text( - double.parse(filesList![index] - .size - .toString()) <= - 1024 - ? '${filesList![index].size} Kb ' - : '${(filesList![index].size! / (1024 * 1024)).toStringAsFixed(2)} Mb', - style: CustomTextStyles - .secondaryRegular14, - ), - SizedBox(width: 10.toHeight), - Text( - '.', - style: CustomTextStyles - .secondaryRegular14, - ), - SizedBox(width: 10.toHeight), - ], - ), - ) - ], - ), - ); - }), - ), - (contactList.length < 2) - ? Container() - : SizedBox( - height: 10.toHeight, - ), - (contactList.length < 2) - ? Container() - : Row( - children: [ - Expanded( - child: Container( - padding: EdgeInsets.only(left: 20.toWidth), - child: Text( - 'Delivered to', - style: CustomTextStyles.primaryRegular16, - ), - ), - ), - ], - ), - // (contactList.length < 2) - // ? Container() - // : TranferOverlappingContacts( - // selectedList: widget.sentHistory.sharedWith.sublist( - // 1, widget.sentHistory.sharedWith.length), - // fileHistory: widget.sentHistory), - GestureDetector( - onTap: () { - setState(() { - isOpen = !isOpen; - }); - }, - child: Container( - margin: EdgeInsets.only(left: 20.toWidth), - child: Row( - children: [ - Text( - 'Lesser Details', - style: CustomTextStyles.primaryBold14, - ), - Container( - width: 22.toWidth, - height: 22.toWidth, - child: Center( - child: Icon( - Icons.keyboard_arrow_up, - color: Colors.black, - ), - ), - ) - ], - ), - ), - ), - ], - ), - ) - : Container() - ], - ); - } - - Widget thumbnail(String? extension, String path, - {bool? isFilePresent = true}) { - return FileTypes.IMAGE_TYPES.contains(extension) - ? ClipRRect( - borderRadius: BorderRadius.circular(10.toHeight), - child: Container( - height: 50.toHeight, - width: 50.toWidth, - child: isFilePresent! - ? Image.file( - File(path), - fit: BoxFit.cover, - errorBuilder: (BuildContext _context, _, __) { - return Container( - child: Icon( - Icons.image, - size: 30.toFont, - ), - ); - }, - ) - : Icon( - Icons.image, - size: 30.toFont, - ), - ), - ) - : FileTypes.VIDEO_TYPES.contains(extension) - ? FutureBuilder( - future: videoThumbnailBuilder(path), - builder: (context, snapshot) => ClipRRect( - borderRadius: BorderRadius.circular(10.toHeight), - child: Container( - padding: EdgeInsets.only(left: 10), - height: 50.toHeight, - width: 50.toWidth, - child: (snapshot.data == null) - ? Image.asset( - ImageConstants.videoLogo, - fit: BoxFit.cover, - ) - : Image.memory( - videoThumbnail!, - fit: BoxFit.cover, - errorBuilder: (BuildContext _context, _, __) { - return Container( - child: Icon( - Icons.image, - size: 30.toFont, - ), - ); - }, - ), - ), - ), - ) - : ClipRRect( - borderRadius: BorderRadius.circular(10.toHeight), - child: Container( - padding: EdgeInsets.only(left: 10), - height: 50.toHeight, - width: 50.toWidth, - child: Image.asset( - FileTypes.PDF_TYPES.contains(extension) - ? ImageConstants.pdfLogo - : FileTypes.AUDIO_TYPES.contains(extension) - ? ImageConstants.musicLogo - : FileTypes.WORD_TYPES.contains(extension) - ? ImageConstants.wordLogo - : FileTypes.EXEL_TYPES.contains(extension) - ? ImageConstants.exelLogo - : FileTypes.TEXT_TYPES.contains(extension) - ? ImageConstants.txtLogo - : ImageConstants.unknownLogo, - fit: BoxFit.cover, - ), - ), - ); - } - - void _showNoFileDialog(double deviceTextFactor) { - showDialog( - context: context, - builder: (BuildContext context) { - return Dialog( - shape: RoundedRectangleBorder( - borderRadius: BorderRadius.circular(12.0)), - child: Container( - height: 200.0, - width: 300.0, - child: Column( - mainAxisAlignment: MainAxisAlignment.center, - children: [ - Padding(padding: EdgeInsets.only(top: 15.0)), - Text( - TextStrings().noFileFound, - style: CustomTextStyles.primaryBold16, - ), - Padding(padding: EdgeInsets.only(top: 30.0)), - Row( - mainAxisAlignment: MainAxisAlignment.center, - children: [ - CustomButton( - height: 50.toHeight * deviceTextFactor, - isInverted: false, - buttonText: TextStrings().buttonClose, - onPressed: () => Navigator.pop(context), - ) - ], - ), - ], - ), - ), - ); - }); - } - - deleteSentItem() async { - await showDialog( - context: NavService.navKey.currentContext!, - builder: (context) { - return AlertDialog( - shape: RoundedRectangleBorder( - borderRadius: BorderRadius.circular(10.toWidth), - ), - content: ConfirmationDialog( - TextStrings.deleteFileConfirmationMsgMyFiles, () async { - await Provider.of(context, listen: false) - .deleteSentItem(widget.sentHistory!.fileDetails!.key); - })); - }); - } - - Future isFilePresent(String filePath) async { - File file = File(filePath); - bool fileExists = await file.exists(); - return fileExists; - } -} diff --git a/lib/desktop_screens/desktop_history/widgets/desktop_transfer_overlapping.dart b/lib/desktop_screens/desktop_history/widgets/desktop_transfer_overlapping.dart deleted file mode 100644 index 3b51a83a..00000000 --- a/lib/desktop_screens/desktop_history/widgets/desktop_transfer_overlapping.dart +++ /dev/null @@ -1,199 +0,0 @@ -import 'package:atsign_atmosphere_pro/data_models/file_transfer.dart'; -import 'package:atsign_atmosphere_pro/desktop_screens/desktop_common_widgets/person_vertical_tile.dart'; -import 'package:atsign_atmosphere_pro/utils/colors.dart'; -import 'package:atsign_atmosphere_pro/utils/text_strings.dart'; -import 'package:atsign_atmosphere_pro/view_models/history_provider.dart'; -import 'package:flutter/material.dart'; -import 'package:at_common_flutter/services/size_config.dart'; -import 'package:atsign_atmosphere_pro/utils/text_styles.dart'; -import 'package:provider/provider.dart'; - -class DesktopTransferOverlappingContacts extends StatefulWidget { - final List? selectedList; - final FileHistory? fileHistory; - - const DesktopTransferOverlappingContacts( - {Key? key, this.selectedList, this.fileHistory}) - : super(key: key); - - @override - _DesktopTransferOverlappingContactsState createState() => - _DesktopTransferOverlappingContactsState(); -} - -class _DesktopTransferOverlappingContactsState - extends State { - bool isExpanded = false; - int noOfContactsRow = 0; - List atSignReSharing = []; - List deliveredToList = []; - List downloadedByList = []; - List filedInDeliveringList = []; - - @override - void initState() { - atSignReSharing = - List.generate(widget.selectedList!.length, (i) => false); - noOfContactsRow = (widget.selectedList!.length / 5).ceil(); - sortAtSigns(); - super.initState(); - } - - sortAtSigns() { - deliveredToList = []; - downloadedByList = []; - filedInDeliveringList = []; - - widget.selectedList!.forEach((element) { - if (element.isNotificationSend!) { - deliveredToList.add(element); - } else { - filedInDeliveringList.add(element); - } - - if (element.isFileDownloaded!) { - downloadedByList.add(element); - } - }); - } - - @override - Widget build(BuildContext context) { - return Container( - padding: - EdgeInsets.symmetric(horizontal: 20.toHeight, vertical: 5.toHeight), - child: Consumer( - builder: (context, provider, _) { - sortAtSigns(); - return Column( - crossAxisAlignment: CrossAxisAlignment.start, - children: [ - downloadedByList.isNotEmpty - ? Row( - children: [ - Icon( - Icons.check_circle, - color: ColorConstants.blueText, - size: 15.toFont, - ), - SizedBox(width: 5), - Text(TextStrings().downloadedBy, - style: CustomTextStyles.grey15), - ], - ) - : SizedBox(), - downloadedByList.isNotEmpty - ? SizedBox(height: 15.toHeight) - : SizedBox(), - Align( - alignment: Alignment.topLeft, - child: Wrap( - alignment: WrapAlignment.start, - runAlignment: WrapAlignment.start, - runSpacing: 10.0, - spacing: 15.0, - children: List.generate(downloadedByList.length, (index) { - return Container( - child: CustomPersonVerticalTile( - key: Key(downloadedByList[index].atsign!), - shareStatus: downloadedByList[index], - fileHistory: widget.fileHistory, - ), - ); - }), - ), - ), - downloadedByList.isNotEmpty ? Divider() : SizedBox(), - SizedBox(height: 18.toHeight), - deliveredToList.isNotEmpty - ? Row( - children: [ - Icon( - Icons.check_circle, - color: Color(0xFF0ACB21), - size: 15.toFont, - ), - SizedBox(width: 5), - Text(TextStrings().deliveredTo, - style: CustomTextStyles.grey15), - ], - ) - : SizedBox(), - deliveredToList.isNotEmpty - ? SizedBox(height: 15.toHeight) - : SizedBox(), - Align( - alignment: Alignment.topLeft, - child: Wrap( - alignment: WrapAlignment.start, - runAlignment: WrapAlignment.start, - runSpacing: 10.0, - spacing: 15.0, - children: List.generate(deliveredToList.length, (index) { - return Container( - child: CustomPersonVerticalTile( - key: Key(deliveredToList[index].atsign!), - shareStatus: deliveredToList[index], - fileHistory: widget.fileHistory, - ), - ); - }), - ), - ), - deliveredToList.isNotEmpty ? Divider() : SizedBox(), - SizedBox(height: 18.toHeight), - filedInDeliveringList.isNotEmpty - ? Row( - mainAxisAlignment: MainAxisAlignment.spaceBetween, - children: [ - Row( - children: [ - Icon( - Icons.error, - color: ColorConstants.redAlert, - size: 15.toFont, - ), - SizedBox(width: 5), - Text( - TextStrings().failedToSend, - style: CustomTextStyles.grey15, - ), - ], - ), - Text( - '${TextStrings().retry}(${filedInDeliveringList.length})', - style: CustomTextStyles.red15, - ), - ], - ) - : SizedBox(), - filedInDeliveringList.isNotEmpty - ? SizedBox(height: 15.toHeight) - : SizedBox(), - Align( - alignment: Alignment.topLeft, - child: Wrap( - alignment: WrapAlignment.start, - runAlignment: WrapAlignment.start, - runSpacing: 10.0, - spacing: 15.0, - children: - List.generate(filedInDeliveringList.length, (index) { - return Container( - child: CustomPersonVerticalTile( - key: Key(filedInDeliveringList[index].atsign!), - shareStatus: filedInDeliveringList[index], - fileHistory: widget.fileHistory, - isFailedAtSignList: true), - ); - }), - ), - ), - filedInDeliveringList.isNotEmpty ? Divider() : SizedBox(), - ], - ); - }, - ), - ); - } -} diff --git a/lib/desktop_screens/trusted_sender/desktop_trusted_sender.dart b/lib/desktop_screens/trusted_sender/desktop_trusted_sender.dart deleted file mode 100644 index 07f5a42c..00000000 --- a/lib/desktop_screens/trusted_sender/desktop_trusted_sender.dart +++ /dev/null @@ -1,309 +0,0 @@ -import 'dart:typed_data'; - -import 'package:at_contacts_group_flutter/at_contacts_group_flutter.dart'; -import 'package:at_contacts_group_flutter/screens/group_contact_view/group_contact_view.dart'; -import 'package:atsign_atmosphere_pro/desktop_screens/desktop_common_widgets/dektop_custom_person_tile.dart'; -import 'package:atsign_atmosphere_pro/desktop_screens/desktop_common_widgets/desktop_custom_input_field.dart'; -import 'package:atsign_atmosphere_pro/desktop_screens/desktop_common_widgets/desktop_header.dart'; -import 'package:atsign_atmosphere_pro/screens/common_widgets/error_dialog.dart'; -import 'package:atsign_atmosphere_pro/screens/common_widgets/provider_callback.dart'; -import 'package:atsign_atmosphere_pro/screens/common_widgets/provider_handler.dart'; -import 'package:atsign_atmosphere_pro/desktop_screens_new/trusted_senders_screen/widgets/remove_trusted_contact_dialog.dart'; -import 'package:at_common_flutter/services/size_config.dart'; -import 'package:atsign_atmosphere_pro/services/common_utility_functions.dart'; -import 'package:atsign_atmosphere_pro/utils/colors.dart'; -import 'package:atsign_atmosphere_pro/utils/text_strings.dart'; -import 'package:atsign_atmosphere_pro/view_models/trusted_sender_view_model.dart'; -import 'package:flutter/material.dart'; -import 'package:at_contact/at_contact.dart'; - -class DesktopTrustedSender extends StatefulWidget { - @override - _DesktopTrustedSenderState createState() => _DesktopTrustedSenderState(); -} - -class _DesktopTrustedSenderState extends State { - bool _isFilterOption = false, isContactSelection = false; - List trustedContacts = []; - String searchText = ''; - TrustedContactProvider? trustedContact; - - @override - void initState() { - super.initState(); - } - - @override - Widget build(BuildContext context) { - SizeConfig().init(context); - return Container( - padding: EdgeInsets.all(20), - color: ColorConstants.fadedBlue, - child: ProviderHandler( - functionName: 'get_trusted_contacts', - load: (provider) async { - await provider.getTrustedContact(); - await provider.migrateTrustedContact(); - }, - showError: false, - errorBuilder: (provider) => Center( - child: Text(TextStrings().somethingWentWrong), - ), - successBuilder: (provider) { - return Stack( - children: [ - Row( - children: [ - Expanded( - child: Column( - crossAxisAlignment: CrossAxisAlignment.start, - children: [ - SizedBox(height: 20), - DesktopHeader( - title: TextStrings().trustedSenders, - isTitleCentered: true, - showBackIcon: false, - onFilter: (val) {}, - actions: [ - DesktopCustomInputField( - backgroundColor: Colors.white, - hintText: TextStrings().search, - icon: Icons.search, - height: 45, - iconColor: ColorConstants.greyText, - initialValue: searchText, - value: (String s) { - setState(() { - searchText = s; - }); - }), - SizedBox(width: 15.toWidth), - TextButton( - onPressed: () { - setState(() { - isContactSelection = !isContactSelection; - }); - }, - style: ButtonStyle(backgroundColor: - MaterialStateProperty.resolveWith( - (Set states) { - return ColorConstants.orangeColor; - }, - ), fixedSize: - MaterialStateProperty.resolveWith( - (Set states) { - return Size(100, 40); - }, - )), - child: Text( - TextStrings().add, - style: TextStyle( - color: Colors.white, - fontWeight: FontWeight.normal, - ), - ), - ), - SizedBox(width: 15.toWidth), - ], - ), - SizedBox(height: 20), - Align( - alignment: Alignment.topLeft, - child: Wrap( - alignment: WrapAlignment.start, - runAlignment: WrapAlignment.start, - runSpacing: 10.0, - spacing: 30.0, - children: List.generate( - provider.trustedContacts.length, (index) { - Uint8List? byteImage = CommonUtilityFunctions() - .getCachedContactImage( - provider.trustedContacts[index].atSign!, - ); - if (provider.trustedContacts[index].atSign! - .contains(searchText)) { - return InkWell( - onTap: () { - showDialog( - context: context, - barrierDismissible: false, - builder: (context) => - RemoveTrustedContact( - TextStrings().removeTrustedSender, - image: byteImage, - contact: AtContact( - atSign: provider - .trustedContacts[index] - .atSign), - ), - ); - }, - child: DesktopCustomPersonVerticalTile( - title: provider - .trustedContacts[index].atSign, - subTitle: provider - .trustedContacts[index].atSign, - showCancelIcon: false, - showImage: - byteImage != null ? true : false, - image: byteImage, - ), - ); - } else { - return SizedBox(); - } - }), - ), - ), - ], - ), - ), - isContactSelection - ? Expanded( - child: GroupContactView( - asSelectionScreen: true, - singleSelection: false, - showGroups: false, - showContacts: true, - isDesktop: true, - contactSelectedHistory: provider.trustedContacts - .map((e) => GroupContactsModel(contact: e)) - .toList(), - selectedList: (_list) { - providerCallback( - context, - task: (provider) async { - _list.forEach((element) async { - if (element!.contact != null) { - await provider.addTrustedContacts( - element.contact!); - } - }); - - isContactSelection = false; - }, - taskName: (provider) => - provider.AddTrustedContacts, - onSuccess: (provider) {}, - onError: (err) => ErrorDialog().show( - err.toString(), - context: context)); - }, - onBackArrowTap: (selectedGroupContacts) { - if (mounted) { - setState(() { - isContactSelection = !isContactSelection; - }); - } - }, - onDoneTap: () {}, - ), - ) - : SizedBox() - ], - ), - _isFilterOption - ? Positioned( - right: 15, - top: 55, - child: Container( - width: 150, - padding: EdgeInsets.only( - right: 10, left: 10, top: 10, bottom: 10), - decoration: BoxDecoration( - color: Colors.white, - border: Border.all( - color: ColorConstants.light_grey, width: 1), - borderRadius: BorderRadius.circular(10)), - child: Column( - children: [ - Row( - mainAxisAlignment: - MainAxisAlignment.spaceBetween, - children: [ - Text( - TextStrings().sortBy, - style: TextStyle( - fontSize: 20, - fontWeight: FontWeight.bold), - ), - InkWell( - onTap: () { - setState(() { - _isFilterOption = !_isFilterOption; - }); - }, - child: Icon(Icons.close, size: 18), - ), - ], - ), - Divider( - height: 10, - color: ColorConstants.greyText, - ), - getFilterOptionWidget(TextStrings().byName, true), - getFilterOptionWidget( - TextStrings().byDate, false), - SizedBox(height: 15), - TextButton( - onPressed: () {}, - style: ButtonStyle(backgroundColor: - MaterialStateProperty.resolveWith( - (Set states) { - return ColorConstants.orangeColor; - }, - ), fixedSize: - MaterialStateProperty.resolveWith( - (Set states) { - return Size(120, 40); - }, - )), - child: Text( - TextStrings().apply, - style: TextStyle( - color: Colors.white, - fontWeight: FontWeight.normal, - ), - ), - ), - ], - ), - ), - ) - : SizedBox(), - ], - ); - }), - ); - } - - Widget underline({double height = 2, double width = 70}) { - return Container( - height: height, - width: width, - color: Colors.black, - ); - } - - Widget getFilterOptionWidget(String title, bool isSelected) { - return Row( - mainAxisAlignment: MainAxisAlignment.spaceBetween, - children: [ - Text( - title, - style: TextStyle(fontSize: 14, fontWeight: FontWeight.bold), - ), - Checkbox( - value: isSelected, - onChanged: (value) {}, - activeColor: Colors.black, - shape: RoundedRectangleBorder( - borderRadius: BorderRadius.all( - Radius.circular(15), - ), - ), - ), - ], - ); - } -} diff --git a/lib/desktop_screens/trusted_sender/widgets/desktop_empty_trusted_sender.dart b/lib/desktop_screens/trusted_sender/widgets/desktop_empty_trusted_sender.dart deleted file mode 100644 index f7a704d5..00000000 --- a/lib/desktop_screens/trusted_sender/widgets/desktop_empty_trusted_sender.dart +++ /dev/null @@ -1,158 +0,0 @@ -import 'package:at_contact/at_contact.dart'; -import 'package:at_contacts_group_flutter/screens/group_contact_view/group_contact_view.dart'; -import 'package:atsign_atmosphere_pro/desktop_screens/trusted_sender/desktop_trusted_sender.dart'; -import 'package:atsign_atmosphere_pro/screens/common_widgets/error_dialog.dart'; -import 'package:atsign_atmosphere_pro/screens/common_widgets/provider_callback.dart'; -import 'package:atsign_atmosphere_pro/screens/common_widgets/provider_handler.dart'; -import 'package:atsign_atmosphere_pro/utils/colors.dart'; -import 'package:atsign_atmosphere_pro/utils/images.dart'; -import 'package:atsign_atmosphere_pro/utils/text_styles.dart'; -import 'package:atsign_atmosphere_pro/view_models/trusted_sender_view_model.dart'; -import 'package:flutter/material.dart'; -import 'package:at_common_flutter/services/size_config.dart'; -import 'package:atsign_atmosphere_pro/utils/text_strings.dart' - as pro_text_strings; -import 'package:provider/provider.dart'; - -class DesktopEmptySender extends StatefulWidget { - @override - _DesktopEmptySenderState createState() => _DesktopEmptySenderState(); -} - -class _DesktopEmptySenderState extends State { - bool isContactSelection = false, isLoading = true; - List trustedContacts = []; - - @override - void initState() { - super.initState(); - } - - getTrustedSenderList() async { - await Provider.of(context, listen: false) - .getTrustedContact(); - trustedContacts = - await Provider.of(context, listen: false) - .trustedContacts; - - if (mounted) { - setState(() { - isLoading = false; - }); - } - } - - @override - Widget build(BuildContext context) { - return ProviderHandler( - functionName: 'get_trusted_contacts', - load: (provider) async => await provider.getTrustedContact(), - showError: false, - errorBuilder: (provider) => Container(), - successBuilder: (provider) { - if (provider.trustedContacts.isNotEmpty) { - return DesktopTrustedSender(); - } - return Container( - child: Row( - mainAxisAlignment: MainAxisAlignment.center, - children: [ - Expanded( - child: Container( - child: Column( - mainAxisAlignment: MainAxisAlignment.center, - crossAxisAlignment: CrossAxisAlignment.center, - children: [ - Center( - child: Container( - padding: EdgeInsets.all(20.0), - decoration: BoxDecoration( - color: Color(0xffFCF9F9), - borderRadius: BorderRadius.circular(80.toHeight)), - height: 160.toHeight, - width: 160.toHeight, - child: Image.asset(ImageConstants.emptyTrustedSenders), - ), - ), - SizedBox(height: 20.toHeight), - Text( - pro_text_strings.TextStrings().noTrustedSenders, - style: CustomTextStyles.primaryBold18, - ), - SizedBox(height: 10.toHeight), - Text( - pro_text_strings.TextStrings().addTrustedSender, - style: CustomTextStyles.secondaryRegular16, - ), - SizedBox( - height: 25.toHeight, - ), - TextButton( - onPressed: () { - setState(() { - isContactSelection = !isContactSelection; - }); - }, - style: ButtonStyle(backgroundColor: - MaterialStateProperty.resolveWith( - (Set states) { - return ColorConstants.orangeColor; - }, - ), fixedSize: MaterialStateProperty.resolveWith( - (Set states) { - return Size(160, 40); - }, - )), - child: Text( - 'Add', - style: TextStyle( - color: Colors.white, - fontWeight: FontWeight.normal, - ), - ), - ), - ], - ), - ), - ), - isContactSelection - ? Expanded( - child: GroupContactView( - asSelectionScreen: true, - singleSelection: false, - showGroups: false, - showContacts: true, - isDesktop: true, - selectedList: (_list) { - providerCallback(context, - task: (provider) async { - _list.forEach((element) async { - if (element!.contact != null) { - await provider - .addTrustedContacts(element.contact!); - } - }); - isContactSelection = false; - }, - taskName: (provider) => provider.AddTrustedContacts, - onSuccess: (provider) {}, - onError: (err) => ErrorDialog() - .show(err.toString(), context: context)); - }, - onBackArrowTap: (selectedGroupContacts) { - if (mounted) { - setState(() { - isContactSelection = !isContactSelection; - }); - } - }, - onDoneTap: () {}, - ), - ) - : SizedBox() - ], - )); - }, - ); - } -} diff --git a/lib/desktop_screens_new/groups_screen/widgets/desktop_custom_app_bar.dart b/lib/desktop_screens_new/groups_screen/widgets/desktop_custom_app_bar.dart index a85c044e..5f3d0abb 100644 --- a/lib/desktop_screens_new/groups_screen/widgets/desktop_custom_app_bar.dart +++ b/lib/desktop_screens_new/groups_screen/widgets/desktop_custom_app_bar.dart @@ -7,7 +7,8 @@ import 'package:at_common_flutter/services/size_config.dart'; /// This is a custom app bar. /// /// used to reduce the common widgets that are passed to the material appbar. -class DesktopCustomAppBar extends StatelessWidget implements PreferredSizeWidget { +class DesktopCustomAppBar extends StatelessWidget + implements PreferredSizeWidget { /// A string to display the title of the appbar. final String? titleText; @@ -92,18 +93,18 @@ class DesktopCustomAppBar extends StatelessWidget implements PreferredSizeWidget leadingWidth: 90, leading: (showLeadingIcon) ? (showBackButton) - ? IconButton( - icon: Icon( - Icons.arrow_back, - color: ColorConstants.fontPrimary, - size: 25.toFont, - ), - onPressed: () { - if (onLeadingIconPressed != null) { - onLeadingIconPressed!(); - } - }) - : leadingIcon + ? IconButton( + icon: Icon( + Icons.arrow_back, + color: ColorConstants.fontPrimary, + size: 25.toFont, + ), + onPressed: () { + if (onLeadingIconPressed != null) { + onLeadingIconPressed!(); + } + }) + : leadingIcon : Container(), title: Row( children: [ @@ -124,17 +125,17 @@ class DesktopCustomAppBar extends StatelessWidget implements PreferredSizeWidget Expanded( child: (showTitle) ? centerTitle - ? Center( - child: Text( - titleText!, - style: - titleTextStyle ?? CustomTextStyles.primaryBold18, - ), - ) - : Text( - titleText!, - style: titleTextStyle ?? CustomTextStyles.primaryBold18, - ) + ? Center( + child: Text( + titleText!, + style: + titleTextStyle ?? CustomTextStyles.primaryBold18, + ), + ) + : Text( + titleText!, + style: titleTextStyle ?? CustomTextStyles.primaryBold18, + ) : Container(), ), ], @@ -142,35 +143,35 @@ class DesktopCustomAppBar extends StatelessWidget implements PreferredSizeWidget actions: [ (closeOnRight) ? Center( - child: Container( - padding: EdgeInsets.only(right: 20.toHeight), - child: MaterialButton( - padding: EdgeInsets.zero, - child: Text( - TextStrings().buttonClose, - style: backTextStyle ?? - TextStyle( - color: Colors.black, - fontFamily: 'HelveticaNeu', - fontSize: 22.toFont, - fontWeight: FontWeight.normal, + child: Container( + padding: EdgeInsets.only(right: 20.toHeight), + child: MaterialButton( + padding: EdgeInsets.zero, + child: Text( + TextStrings().buttonClose, + style: backTextStyle ?? + TextStyle( + color: Colors.black, + fontFamily: 'HelveticaNeu', + fontSize: 22.toFont, + fontWeight: FontWeight.normal, + ), ), - ), - onPressed: () { - Navigator.pop(context); - }, - ), - ), - ) + onPressed: () { + Navigator.pop(context); + }, + ), + ), + ) : (showTrailingIcon) - ? MaterialButton( - padding: EdgeInsets.zero, - onPressed: () { - onTrailingIconPressed?.call(); - }, - child: trailingIcon, - ) - : Container() + ? MaterialButton( + padding: EdgeInsets.zero, + onPressed: () { + onTrailingIconPressed?.call(); + }, + child: trailingIcon, + ) + : Container() ], automaticallyImplyLeading: false, backgroundColor: appBarColor ?? ColorConstants.appBarColor, diff --git a/lib/desktop_screens_new/history_screen/widgets/desktop_filter_option_item.dart b/lib/desktop_screens_new/history_screen/widgets/desktop_filter_option_item.dart index 7c2c855a..9a2d2d63 100644 --- a/lib/desktop_screens_new/history_screen/widgets/desktop_filter_option_item.dart +++ b/lib/desktop_screens_new/history_screen/widgets/desktop_filter_option_item.dart @@ -68,8 +68,8 @@ class DesktopFilterOptionItem extends StatelessWidget { isCheck ? AppVectors.icChecked : isAllOption - ? AppVectors.icUncheckedAll - : AppVectors.icUnchecked, + ? AppVectors.icUncheckedAll + : AppVectors.icUnchecked, width: 16, height: 16, color: isAllOption ? Colors.white : Colors.black, diff --git a/lib/desktop_screens_new/my_files_screen/utils/file_category.dart b/lib/desktop_screens_new/my_files_screen/utils/file_category.dart index 207679a0..df7da642 100644 --- a/lib/desktop_screens_new/my_files_screen/utils/file_category.dart +++ b/lib/desktop_screens_new/my_files_screen/utils/file_category.dart @@ -6,4 +6,4 @@ enum FileCategory { Audios, AllFiles, Others, -} \ No newline at end of file +} diff --git a/lib/desktop_screens_new/trusted_senders_screen/desktop_trusted.dart b/lib/desktop_screens_new/trusted_senders_screen/desktop_trusted.dart index 0ae7b795..1610d41f 100644 --- a/lib/desktop_screens_new/trusted_senders_screen/desktop_trusted.dart +++ b/lib/desktop_screens_new/trusted_senders_screen/desktop_trusted.dart @@ -65,58 +65,58 @@ class _DesktopTrustedScreenState extends State { Spacer(), isSearchActive ? ClipRRect( - borderRadius: BorderRadius.circular(40), - child: Container( - height: 40, - width: 308, - color: Colors.white, - child: TextField( - controller: searchController, - autofocus: true, - onChanged: (value) { - setState(() { - searchText = value; - }); - }, - style: const TextStyle( - color: Colors.black, - fontSize: 15, - fontWeight: FontWeight.w500, - ), - decoration: InputDecoration( - contentPadding: const EdgeInsets.symmetric( - horizontal: 28, vertical: 8), - border: InputBorder.none, - hintText: 'Search', - hintStyle: TextStyle( - color: ColorConstants.grey, + borderRadius: BorderRadius.circular(40), + child: Container( + height: 40, + width: 308, + color: Colors.white, + child: TextField( + controller: searchController, + autofocus: true, + onChanged: (value) { + setState(() { + searchText = value; + }); + }, + style: const TextStyle( + color: Colors.black, fontSize: 15, fontWeight: FontWeight.w500, ), - suffixIcon: InkWell( - onTap: () { - searchText.isEmpty - ? setState(() { - isSearchActive = false; - }) - : setState(() { - searchText = ''; - searchController.clear(); - }); - }, - child: const Icon(Icons.close)), + decoration: InputDecoration( + contentPadding: const EdgeInsets.symmetric( + horizontal: 28, vertical: 8), + border: InputBorder.none, + hintText: 'Search', + hintStyle: TextStyle( + color: ColorConstants.grey, + fontSize: 15, + fontWeight: FontWeight.w500, + ), + suffixIcon: InkWell( + onTap: () { + searchText.isEmpty + ? setState(() { + isSearchActive = false; + }) + : setState(() { + searchText = ''; + searchController.clear(); + }); + }, + child: const Icon(Icons.close)), + ), ), ), - ), - ) + ) : IconButtonWidget( - icon: AppVectors.icSearch, - onTap: () { - setState(() { - isSearchActive = true; - }); - }, - ), + icon: AppVectors.icSearch, + onTap: () { + setState(() { + isSearchActive = true; + }); + }, + ), SizedBox( width: 10, ), diff --git a/lib/desktop_screens_new/welcome_screen/widgets/sidebar_item.dart b/lib/desktop_screens_new/welcome_screen/widgets/sidebar_item.dart index 5390ea15..9a5a173a 100644 --- a/lib/desktop_screens_new/welcome_screen/widgets/sidebar_item.dart +++ b/lib/desktop_screens_new/welcome_screen/widgets/sidebar_item.dart @@ -115,8 +115,7 @@ class SidebarItem extends StatelessWidget { padding: EdgeInsets.symmetric(vertical: 4), shrinkWrap: true, itemBuilder: (context, index) { - final MenuItem item = - menuItem.children![index]; + final MenuItem item = menuItem.children![index]; return Container( color: ColorConstants.raisinBlack, child: Padding( @@ -128,8 +127,7 @@ class SidebarItem extends StatelessWidget { child: BuildSidebarIconTitle( image: item.image, route: item.routeName ?? "", - isSidebarExpanded: - isSidebarExpanded, + isSidebarExpanded: isSidebarExpanded, isChildTile: true, title: item.title, nestedProvider: nestedProvider, diff --git a/lib/screens/common_widgets/custom_circle_avatar.dart b/lib/screens/common_widgets/custom_circle_avatar.dart index fcb805ce..84fed56b 100644 --- a/lib/screens/common_widgets/custom_circle_avatar.dart +++ b/lib/screens/common_widgets/custom_circle_avatar.dart @@ -46,4 +46,3 @@ class CustomCircleAvatar extends StatelessWidget { ); } } - diff --git a/lib/screens/common_widgets/search_widget.dart b/lib/screens/common_widgets/search_widget.dart index caad7be7..f4758f5e 100644 --- a/lib/screens/common_widgets/search_widget.dart +++ b/lib/screens/common_widgets/search_widget.dart @@ -22,7 +22,9 @@ class SearchWidget extends StatelessWidget { this.hintStyle, this.margin, this.onChange, - this.readOnly, this.onTap, this.autoFocus, + this.readOnly, + this.onTap, + this.autoFocus, }) : super(key: key); @override diff --git a/lib/screens/contact_new_version/widget/contact_attachment_card.dart b/lib/screens/contact_new_version/widget/contact_attachment_card.dart index 07f7d4fd..67f02b24 100644 --- a/lib/screens/contact_new_version/widget/contact_attachment_card.dart +++ b/lib/screens/contact_new_version/widget/contact_attachment_card.dart @@ -1,7 +1,5 @@ -import 'dart:convert'; import 'dart:io'; -import 'package:at_contacts_group_flutter/services/group_service.dart'; import 'package:atsign_atmosphere_pro/data_models/file_transfer.dart'; import 'package:atsign_atmosphere_pro/desktop_routes/desktop_routes.dart'; import 'package:atsign_atmosphere_pro/screens/my_files/widgets/recent.dart'; @@ -20,11 +18,8 @@ import 'package:atsign_atmosphere_pro/view_models/history_provider.dart'; import 'package:atsign_atmosphere_pro/view_models/internet_connectivity_checker.dart'; import 'package:atsign_atmosphere_pro/view_models/my_files_provider.dart'; import 'package:file_picker/file_picker.dart'; -import 'package:flutter/foundation.dart'; import 'package:flutter/material.dart'; import 'package:flutter_svg/flutter_svg.dart'; -import 'package:intl/intl.dart'; -import 'package:open_file/open_file.dart'; import 'package:provider/provider.dart'; class ContactAttachmentCard extends StatefulWidget { @@ -99,7 +94,16 @@ class _ContactAttachmentCardState extends State : () async { bool isExist = await isFilePresent(widget.singleFile.name ?? ''); if (isExist) { - await openPreview(); + await CommonUtilityFunctions().openPreview( + context: context, + size: widget.singleFile.size ?? 0, + sender: widget.fileTransfer.sender ?? '', + note: widget.fileTransfer.notes ?? '', + filePath: filePath, + fileName: widget.singleFile.name ?? '', + date: widget.fileTransfer.date ?? DateTime.now(), + key: widget.fileTransfer.key, + ); } }, child: Container( @@ -424,216 +428,4 @@ class _ContactAttachmentCardState extends State } } } - - Future openPreview() async { - if (FileTypes.IMAGE_TYPES - .contains(widget.singleFile.name?.split(".").last)) { - String nickname = ""; - Uint8List imageBytes = base64Decode(await imageToBase64(filePath)); - final date = (widget.fileTransfer.date ?? DateTime.now()).toLocal(); - final shortDate = DateFormat('dd/MM/yy').format(date); - final time = DateFormat('HH:mm').format(date); - for (var contact in GroupService().allContacts) { - if (contact?.contact?.atSign == widget.fileTransfer.sender) { - nickname = contact?.contact?.tags?["nickname"] ?? ""; - break; - } - } - await showDialog( - context: NavService.navKey.currentContext!, - builder: (context) => Material( - type: MaterialType.transparency, - child: Padding( - padding: const EdgeInsets.all(32), - child: Column( - children: [ - SizedBox( - height: 10, - ), - Align( - alignment: Alignment.centerLeft, - child: Padding( - padding: const EdgeInsets.only(left: 32), - child: InkWell( - onTap: () { - Navigator.pop(NavService.navKey.currentContext!); - }, - child: Icon( - Icons.clear, - color: Colors.white, - size: 24, - ), - ), - ), - ), - SizedBox( - height: 10, - ), - Expanded( - child: InkWell( - onTap: () async { - await OpenFile.open(filePath); - }, - child: Container( - decoration: BoxDecoration( - borderRadius: BorderRadius.circular(10), - image: DecorationImage( - image: MemoryImage( - imageBytes, - ), - fit: BoxFit.cover, - ), - ), - ), - ), - ), - SizedBox( - height: 40, - ), - Row( - mainAxisAlignment: MainAxisAlignment.center, - children: [ - Padding( - padding: const EdgeInsets.only(left: 6.0), - child: SvgPicture.asset( - AppVectors.icCloudDownloaded, - height: 50, - width: 50, - ), - ), - SizedBox( - width: 10, - ), - Padding( - padding: const EdgeInsets.only(right: 6.0), - child: GestureDetector( - onTap: () async { - Navigator.pop(context); - await moveToTransferScreen(); - }, - child: SvgPicture.asset( - AppVectors.icSendFile, - height: 50, - width: 50, - ), - ), - ), - ], - ), - SizedBox( - height: 40, - ), - Container( - decoration: BoxDecoration( - color: Colors.white, - borderRadius: BorderRadius.circular(5), - ), - padding: EdgeInsets.all(20), - width: double.infinity, - child: SingleChildScrollView( - child: Column( - crossAxisAlignment: CrossAxisAlignment.start, - children: [ - Align( - alignment: Alignment.topRight, - child: Row( - mainAxisSize: MainAxisSize.min, - children: [ - Text( - "$shortDate", - style: TextStyle( - fontSize: 10, - color: ColorConstants.oldSliver, - ), - ), - Container( - width: 1, - height: 8, - color: Color(0xFFD7D7D7), - margin: EdgeInsets.symmetric( - horizontal: 3, - ), - ), - Text( - "$time", - style: TextStyle( - fontSize: 10, - color: ColorConstants.oldSliver, - ), - ), - ], - ), - ), - SizedBox(height: 12), - Text( - (widget.singleFile.name ?? ''), - style: TextStyle( - fontSize: 16, fontWeight: FontWeight.bold), - ), - SizedBox(height: 5), - Text( - double.parse(widget.singleFile.size.toString()) <= - 1024 - ? '${widget.singleFile.size} ' + TextStrings().kb - : '${(widget.singleFile.size! / (1024 * 1024)).toStringAsFixed(2)} ' + - TextStrings().mb, - style: TextStyle( - color: ColorConstants.grey, - fontSize: 10, - ), - textAlign: TextAlign.left, - ), - SizedBox(height: 10), - nickname.isNotEmpty - ? Text( - nickname, - style: TextStyle( - fontSize: 14, fontWeight: FontWeight.bold), - ) - : SizedBox(), - SizedBox(height: 5), - Text( - widget.fileTransfer.sender ?? '', - style: TextStyle( - fontSize: 12, - ), - ), - if ((widget.fileTransfer.notes ?? '').isNotEmpty) ...[ - SizedBox(height: 10), - Text( - "Message", - style: TextStyle( - fontSize: 12, - color: Colors.grey, - ), - ), - // : SizedBox(), - SizedBox(height: 5), - Text( - widget.fileTransfer.notes ?? "", - style: TextStyle( - fontSize: 12, - ), - ), - ] - ], - ), - ), - ), - ], - ), - ), - ), - ); - } else { - await OpenFile.open(filePath); - } - } - - Future imageToBase64(String imagePath) async { - File imageFile = File(imagePath); - List imageBytes = await imageFile.readAsBytes(); - String base64Image = base64Encode(imageBytes); - return base64Image; - } } diff --git a/lib/screens/group_contacts_screen/widgets/group_contact_list_tile.dart b/lib/screens/group_contacts_screen/widgets/group_contact_list_tile.dart index 652f0c9f..e66951c8 100644 --- a/lib/screens/group_contacts_screen/widgets/group_contact_list_tile.dart +++ b/lib/screens/group_contacts_screen/widgets/group_contact_list_tile.dart @@ -94,7 +94,6 @@ class _ContactListTileState extends State { ], ), ), - InkWell( onTap: () { widget.onRemove.call(); diff --git a/lib/screens/history/widgets/filter_option_item.dart b/lib/screens/history/widgets/filter_option_item.dart index 5c73cc55..fb755b63 100644 --- a/lib/screens/history/widgets/filter_option_item.dart +++ b/lib/screens/history/widgets/filter_option_item.dart @@ -69,7 +69,7 @@ class FilterOptionItem extends StatelessWidget { ? AppVectors.icChecked : isAllOption ? AppVectors.icUncheckedAll - : AppVectors.icUnchecked, + : AppVectors.icUnchecked, width: 16, height: 16, color: isAllOption ? Colors.white : Colors.black, diff --git a/lib/screens/history/widgets/history_card_item.dart b/lib/screens/history/widgets/history_card_item.dart index 460c4268..24e1ca82 100644 --- a/lib/screens/history/widgets/history_card_item.dart +++ b/lib/screens/history/widgets/history_card_item.dart @@ -186,7 +186,7 @@ class _HistoryCardItemState extends State { }); SnackBarService().showSnackBar( context, - "Successfully deleted the file", + "Successfully deleted the file(s)", bgColor: ColorConstants.successColor, ); Provider.of(context, listen: false).notify(); diff --git a/lib/screens/history/widgets/history_file_item.dart b/lib/screens/history/widgets/history_file_item.dart index 98d51323..6f541ef0 100644 --- a/lib/screens/history/widgets/history_file_item.dart +++ b/lib/screens/history/widgets/history_file_item.dart @@ -1,11 +1,7 @@ -import 'dart:convert'; import 'dart:io'; -import 'package:at_common_flutter/services/size_config.dart'; -import 'package:at_contacts_group_flutter/services/group_service.dart'; import 'package:atsign_atmosphere_pro/data_models/file_modal.dart'; import 'package:atsign_atmosphere_pro/data_models/file_transfer.dart'; -import 'package:atsign_atmosphere_pro/screens/common_widgets/custom_button.dart'; import 'package:atsign_atmosphere_pro/screens/my_files/widgets/recent.dart'; import 'package:atsign_atmosphere_pro/services/backend_service.dart'; import 'package:atsign_atmosphere_pro/services/common_utility_functions.dart'; @@ -14,7 +10,6 @@ import 'package:atsign_atmosphere_pro/services/snackbar_service.dart'; import 'package:atsign_atmosphere_pro/utils/colors.dart'; import 'package:atsign_atmosphere_pro/utils/constants.dart'; import 'package:atsign_atmosphere_pro/utils/file_types.dart'; -import 'package:atsign_atmosphere_pro/utils/file_utils.dart'; import 'package:atsign_atmosphere_pro/utils/images.dart'; import 'package:atsign_atmosphere_pro/utils/text_strings.dart'; import 'package:atsign_atmosphere_pro/utils/text_styles.dart'; @@ -27,11 +22,8 @@ import 'package:atsign_atmosphere_pro/view_models/my_files_provider.dart'; import 'package:atsign_atmosphere_pro/view_models/welcome_screen_view_model.dart'; import 'package:file_picker/file_picker.dart'; import 'package:flutter/material.dart'; -import 'package:flutter/services.dart'; import 'package:flutter_slidable/flutter_slidable.dart'; import 'package:flutter_svg/flutter_svg.dart'; -import 'package:intl/intl.dart'; -import 'package:open_file/open_file.dart'; import 'package:provider/provider.dart'; class HistoryFileItem extends StatefulWidget { @@ -73,290 +65,6 @@ class _HistoryFileItemState extends State { setState(() {}); } - Future imageToBase64(String imagePath) async { - File imageFile = File(imagePath); - List imageBytes = await imageFile.readAsBytes(); - String base64Image = base64Encode(imageBytes); - return base64Image; - } - - Future openPreview() async { - if (FileTypes.IMAGE_TYPES.contains(widget.data.name?.split(".").last)) { - String nickname = ""; - String filePath = path; - Uint8List imageBytes = base64Decode(await imageToBase64(filePath)); - final date = (widget.fileTransfer?.date ?? DateTime.now()).toLocal(); - final shortDate = DateFormat('dd/MM/yy').format(date); - final time = DateFormat('HH:mm').format(date); - for (var contact in GroupService().allContacts) { - if (contact?.contact?.atSign == widget.fileTransfer?.sender) { - nickname = contact?.contact?.tags?["nickname"] ?? ""; - break; - } - } - await showDialog( - context: NavService.navKey.currentContext!, - builder: (_) => Material( - type: MaterialType.transparency, - child: Column( - children: [ - SizedBox( - height: 10, - ), - Align( - alignment: Alignment.centerLeft, - child: Padding( - padding: const EdgeInsets.only(left: 32), - child: InkWell( - onTap: () { - Navigator.pop(NavService.navKey.currentContext!); - }, - child: Icon( - Icons.clear, - color: Colors.white, - size: 24, - ), - ), - ), - ), - SizedBox( - height: 10, - ), - Expanded( - child: InkWell( - onTap: () async { - await OpenFile.open( - BackendService.getInstance().downloadDirectory!.path + - Platform.pathSeparator + - (widget.data.name ?? ''), - ); - }, - child: Container( - margin: EdgeInsets.symmetric(horizontal: 33), - decoration: BoxDecoration( - borderRadius: BorderRadius.circular(10), - image: DecorationImage( - image: MemoryImage( - imageBytes, - ), - fit: BoxFit.cover, - ), - ), - ), - ), - ), - SizedBox( - height: 40, - ), - Row( - mainAxisAlignment: MainAxisAlignment.center, - children: [ - Padding( - padding: const EdgeInsets.only(left: 6.0), - child: SvgPicture.asset( - AppVectors.icCloudDownloaded, - height: 50, - width: 50, - ), - ), - SizedBox( - width: 10, - ), - Padding( - padding: const EdgeInsets.only(left: 6.0), - child: GestureDetector( - onTap: () async { - Navigator.pop(context); - await FileUtils.moveToSendFile( - BackendService.getInstance() - .downloadDirectory! - .path + - Platform.pathSeparator + - widget.data.name!); - }, - child: SvgPicture.asset( - AppVectors.icSendFile, - height: 50, - width: 50, - ), - ), - ), - SizedBox( - width: 10, - ), - Padding( - padding: const EdgeInsets.only(left: 6.0), - child: GestureDetector( - onTap: () async { - await FileUtils.deleteFile( - filePath, - fileTransferId: widget.fileTransfer?.key, - onComplete: () { - if (mounted) { - Navigator.pop(context); - } - }, - ); - }, - child: SvgPicture.asset( - AppVectors.icDeleteFile, - height: 50, - width: 50, - ), - ), - ), - ], - ), - SizedBox( - height: 40, - ), - Container( - decoration: BoxDecoration( - color: Colors.white, - borderRadius: BorderRadius.circular(5), - ), - padding: EdgeInsets.all(20), - margin: EdgeInsets.symmetric(horizontal: 25), - width: double.infinity, - child: SingleChildScrollView( - child: Column( - crossAxisAlignment: CrossAxisAlignment.start, - children: [ - Align( - alignment: Alignment.topRight, - child: Row( - mainAxisSize: MainAxisSize.min, - children: [ - Text( - "$shortDate", - style: TextStyle( - fontSize: 11, - color: ColorConstants.oldSliver, - ), - ), - Container( - width: 1, - height: 8, - color: Color(0xFFD7D7D7), - margin: EdgeInsets.symmetric( - horizontal: 3, - ), - ), - Text( - "$time", - style: TextStyle( - fontSize: 11, - color: ColorConstants.oldSliver, - ), - ), - ], - ), - ), - SizedBox(height: 12), - Text( - (widget.data.name ?? ''), - style: TextStyle( - fontSize: 17, fontWeight: FontWeight.bold), - ), - SizedBox(height: 5), - Text( - double.parse(widget.data.size.toString()) <= 1024 - ? '${widget.data.size} ' + TextStrings().kb - : '${(widget.data.size! / (1024 * 1024)).toStringAsFixed(2)} ' + - TextStrings().mb, - style: TextStyle( - color: ColorConstants.grey, - fontSize: 11, - ), - textAlign: TextAlign.left, - ), - SizedBox(height: 10), - nickname.isNotEmpty - ? Text( - nickname, - style: TextStyle( - fontSize: 15, fontWeight: FontWeight.bold), - ) - : SizedBox(), - SizedBox(height: 5), - Text( - widget.fileTransfer?.sender ?? '', - style: TextStyle( - fontSize: 13, - ), - ), - SizedBox(height: 10), - // fileDetail.message.isNotNull - // ? - if ((widget.fileTransfer?.notes ?? '').isNotEmpty) ...[ - Text( - "Message", - style: TextStyle( - fontSize: 13, - color: Colors.grey, - ), - ), - // : SizedBox(), - SizedBox(height: 5), - Text( - widget.fileTransfer?.notes ?? "", - style: TextStyle( - fontSize: 13, - ), - ), - ] - ], - ), - ), - ), - ], - ), - ), - ); - } else { - await OpenFile.open(BackendService.getInstance().downloadDirectory!.path + - Platform.pathSeparator + - (widget.data.name ?? '')); - } - } - - void showNoFileDialog(double deviceTextFactor) { - showDialog( - context: context, - builder: (BuildContext context) { - return Dialog( - shape: RoundedRectangleBorder( - borderRadius: BorderRadius.circular(12.0)), - child: Container( - height: 200.0.toHeight, - width: 300.0.toWidth, - child: Column( - mainAxisAlignment: MainAxisAlignment.center, - children: [ - Padding(padding: EdgeInsets.only(top: 15.0)), - Text( - TextStrings().fileNotDownload, - style: CustomTextStyles.primaryBold17, - ), - Padding(padding: EdgeInsets.only(top: 30.0)), - Row( - mainAxisAlignment: MainAxisAlignment.center, - children: [ - CustomButton( - height: 50.toHeight * deviceTextFactor, - isInverted: false, - buttonText: TextStrings().buttonClose, - onPressed: () => Navigator.pop(context), - ) - ], - ), - ], - ), - ), - ); - }); - } - @override Widget build(BuildContext context) { final String fileFormat = '.${widget.data.name?.split('.').last}'; @@ -389,9 +97,21 @@ class _HistoryFileItemState extends State { child: InkWell( onTap: () async { if (File(path).existsSync()) { - await openPreview(); + await CommonUtilityFunctions().openPreview( + context: context, + date: widget.fileTransfer?.date ?? DateTime.now(), + fileName: widget.data.name ?? '', + filePath: path, + key: widget.fileTransfer?.key ?? '', + note: widget.fileTransfer?.notes ?? '', + sender: widget.fileTransfer?.sender ?? '', + size: widget.data.size ?? 0, + ); } else { - showNoFileDialog(MediaQuery.of(context).textScaleFactor); + CommonUtilityFunctions().showNoFileDialog( + deviceTextFactor: MediaQuery.of(context).textScaleFactor, + isFileNotFound: false, + ); } }, child: Stack( diff --git a/lib/screens/my_files/files_detail_screen.dart b/lib/screens/my_files/files_detail_screen.dart index 82d461eb..4c05926e 100644 --- a/lib/screens/my_files/files_detail_screen.dart +++ b/lib/screens/my_files/files_detail_screen.dart @@ -227,12 +227,12 @@ class _FilesDetailScreenState extends State { fileTransferId: files[index].fileTransferId, onComplete: () { files.removeAt(index); + setState(() {}); }, ); if (mounted) { Navigator.pop(context); } - setState(() {}); }, ), ), @@ -268,16 +268,6 @@ class _FilesDetailScreenState extends State { final shortDate = DateFormat('MM/dd/yy').format(date); final time = DateFormat('kk:mm').format(date); - // late FileTransfer fileTransfer; - // bool isDownloaded = false; - - // for (var filetransfer in provider.myFiles) { - // if (filetransfer.key == files[index].fileTransferId) { - // fileTransfer = filetransfer; - // break; - // } - // } - return Slidable( key: UniqueKey(), endActionPane: ActionPane( @@ -309,9 +299,9 @@ class _FilesDetailScreenState extends State { fileTransferId: files[index].fileTransferId, onComplete: () { files.removeAt(index); + setState(() {}); }, ); - setState(() {}); }, child: SvgPicture.asset( AppVectors.icDeleteFile, @@ -319,103 +309,67 @@ class _FilesDetailScreenState extends State { ), ), ], - ) - - // Consumer( - // builder: (_c, provider, _) { - // var fileTransferProgress = - // provider.receivedFileProgress[fileTransfer.key]; - - // return CommonUtilityFunctions() - // .checkForDownloadAvailability(fileTransfer) - // ? fileTransferProgress != null - // ? CommonUtilityFunctions().getDownloadStatus( - // fileTransferProgress, - // ) - // : isDownloaded - // ? SvgPicture.asset(AppVectors.icCloudDownloaded) - // : InkWell( - // onTap: () async { - // var res = await downloadFiles( - // fileTransfer, - // fileName: files[index].fileName, - // ); - - // setState(() { - // isDownloaded = res; - // }); - // }, - // child: SvgPicture.asset( - // AppVectors.icDownloadFile, - // ), - // ) - // : SizedBox(); - // }, - // ), - // Padding( - // padding: const EdgeInsets.only(left: 6.0), - // child: SvgPicture.asset( - // AppVectors.icDownloadFile, - // ), - // ), - - , - child: InkWell( - onTap: () async { - await FileUtils.openFile( - path: BackendService.getInstance().downloadDirectory!.path + - Platform.pathSeparator + - files[index].fileName!, - extension: files[index].fileName?.split(".").last ?? "", - onDelete: () async { - await FileUtils.deleteFile( - BackendService.getInstance().downloadDirectory!.path + - Platform.pathSeparator + - files[index].fileName!); - if (mounted) { - Navigator.pop(context); - } - setState(() {}); - }, - fileDetail: files[index], - ); - }, - child: Container( - key: UniqueKey(), - padding: EdgeInsets.all(16), - decoration: BoxDecoration( - color: Colors.white, - borderRadius: BorderRadius.circular(10), - ), - child: Row( - children: [ - Container( - height: 49, - width: 38, - decoration: BoxDecoration( - borderRadius: BorderRadius.circular(5), - ), - child: Center( - child: CommonUtilityFunctions().interactThumbnail( - files[index].fileName?.split(".").last ?? "", - BackendService.getInstance().downloadDirectory!.path + - Platform.pathSeparator + - files[index].fileName!, - files[index], () async { - await FileUtils.deleteFile( - BackendService.getInstance().downloadDirectory!.path + - Platform.pathSeparator + - files[index].fileName!, - fileTransferId: files[index].fileTransferId, - onComplete: () { - files.removeAt(index); - }, - ); + ), + child: InkWell( + onTap: () async { + await FileUtils.openFile( + path: BackendService.getInstance().downloadDirectory!.path + + Platform.pathSeparator + + files[index].fileName!, + extension: files[index].fileName?.split(".").last ?? "", + onDelete: () async { + await FileUtils.deleteFile( + BackendService.getInstance().downloadDirectory!.path + + Platform.pathSeparator + + files[index].fileName!); + if (mounted) { + Navigator.pop(context); + } + setState(() {}); + }, + fileDetail: files[index], + ); + }, + child: Container( + key: UniqueKey(), + padding: EdgeInsets.all(16), + decoration: BoxDecoration( + color: Colors.white, + borderRadius: BorderRadius.circular(10), + ), + child: Row( + children: [ + Container( + height: 49, + width: 38, + decoration: BoxDecoration( + borderRadius: BorderRadius.circular(5), + ), + child: Center( + child: CommonUtilityFunctions().interactThumbnail( + files[index].fileName?.split(".").last ?? "", + BackendService.getInstance() + .downloadDirectory! + .path + + Platform.pathSeparator + + files[index].fileName!, + files[index], () async { + await FileUtils.deleteFile( + BackendService.getInstance() + .downloadDirectory! + .path + + Platform.pathSeparator + + files[index].fileName!, + fileTransferId: files[index].fileTransferId, + onComplete: () { + files.removeAt(index); + setState(() {}); + }, + ); if (mounted) { Navigator.pop(context); } - setState(() {}); }), ), ), diff --git a/lib/screens/welcome_screen/welcome_screen.dart b/lib/screens/welcome_screen/welcome_screen.dart index 73b223b9..b7080ab9 100644 --- a/lib/screens/welcome_screen/welcome_screen.dart +++ b/lib/screens/welcome_screen/welcome_screen.dart @@ -213,11 +213,10 @@ class _WelcomeScreenState extends State { stream: FileTransferProvider() .flushBarStatusStream, builder: (context, snapshot) { - final flushbarStatus = snapshot.data ?? - FlushBarStatus.SENDING; + final flushbarStatus = + snapshot.data ?? FlushBarStatus.SENDING; - if (flushbarStatus == - FlushBarStatus.DONE) { + if (flushbarStatus == FlushBarStatus.DONE) { Future.delayed( const Duration(seconds: 3), () { diff --git a/lib/services/common_utility_functions.dart b/lib/services/common_utility_functions.dart index 3af60e6d..7cc67b98 100644 --- a/lib/services/common_utility_functions.dart +++ b/lib/services/common_utility_functions.dart @@ -1,3 +1,4 @@ +import 'dart:convert'; import 'dart:io'; import 'dart:typed_data'; import 'package:at_client_mobile/at_client_mobile.dart'; @@ -26,6 +27,7 @@ import 'package:atsign_atmosphere_pro/utils/vectors.dart'; import 'package:flutter/material.dart'; import 'package:flutter_svg/svg.dart'; import 'package:intl/intl.dart'; +import 'package:open_file/open_file.dart'; import 'package:showcaseview/showcaseview.dart'; import 'package:video_thumbnail/video_thumbnail.dart'; @@ -1107,7 +1109,10 @@ class CommonUtilityFunctions { ); } - void showNoFileDialog({double deviceTextFactor = 1}) { + void showNoFileDialog({ + double deviceTextFactor = 1, + bool isFileNotFound = true, + }) { showDialog( context: NavService.navKey.currentContext!, builder: (BuildContext context) { @@ -1122,7 +1127,9 @@ class CommonUtilityFunctions { children: [ Padding(padding: EdgeInsets.only(top: 15.0)), Text( - TextStrings().noFileFound, + isFileNotFound + ? TextStrings().noFileFound + : TextStrings().fileNotDownload, style: CustomTextStyles.primaryBold16, ), Padding(padding: EdgeInsets.only(top: 30.0)), @@ -1143,4 +1150,259 @@ class CommonUtilityFunctions { ); }); } + + Future openPreview({ + required BuildContext context, + required String fileName, + required String filePath, + required DateTime date, + required String sender, + required String key, + required int size, + required String note, + }) async { + if (FileTypes.IMAGE_TYPES.contains(fileName.split(".").last)) { + String nickname = ""; + Uint8List imageBytes = base64Decode(await imageToBase64(filePath)); + final localDate = date.toLocal(); + final shortDate = DateFormat('dd/MM/yy').format(localDate); + final time = DateFormat('HH:mm').format(localDate); + for (var contact in GroupService().allContacts) { + if (contact?.contact?.atSign == sender) { + nickname = contact?.contact?.tags?["nickname"] ?? ""; + break; + } + } + await showDialog( + context: NavService.navKey.currentContext!, + builder: (_) => Material( + type: MaterialType.transparency, + child: Column( + children: [ + SizedBox( + height: 10, + ), + Align( + alignment: Alignment.centerLeft, + child: Padding( + padding: const EdgeInsets.only(left: 32), + child: InkWell( + onTap: () { + Navigator.pop(NavService.navKey.currentContext!); + }, + child: Icon( + Icons.clear, + color: Colors.white, + size: 24, + ), + ), + ), + ), + SizedBox( + height: 10, + ), + Expanded( + child: InkWell( + onTap: () async { + await OpenFile.open( + BackendService.getInstance().downloadDirectory!.path + + Platform.pathSeparator + + fileName, + ); + }, + child: Container( + margin: EdgeInsets.symmetric(horizontal: 33), + decoration: BoxDecoration( + borderRadius: BorderRadius.circular(10), + image: DecorationImage( + image: MemoryImage( + imageBytes, + ), + fit: BoxFit.cover, + ), + ), + ), + ), + ), + SizedBox( + height: 40, + ), + Row( + mainAxisAlignment: MainAxisAlignment.center, + children: [ + Padding( + padding: const EdgeInsets.only(left: 6.0), + child: SvgPicture.asset( + AppVectors.icCloudDownloaded, + height: 50, + width: 50, + ), + ), + SizedBox( + width: 10, + ), + Padding( + padding: const EdgeInsets.only(left: 6.0), + child: GestureDetector( + onTap: () async { + Navigator.pop(context); + await FileUtils.moveToSendFile( + BackendService.getInstance() + .downloadDirectory! + .path + + Platform.pathSeparator + + fileName); + }, + child: SvgPicture.asset( + AppVectors.icSendFile, + height: 50, + width: 50, + ), + ), + ), + SizedBox( + width: 10, + ), + Padding( + padding: const EdgeInsets.only(left: 6.0), + child: GestureDetector( + onTap: () async { + await FileUtils.deleteFile( + filePath, + fileTransferId: key, + onComplete: () { + if (context.mounted) { + Navigator.pop(context); + } + }, + ); + }, + child: SvgPicture.asset( + AppVectors.icDeleteFile, + height: 50, + width: 50, + ), + ), + ), + ], + ), + SizedBox( + height: 40, + ), + Container( + decoration: BoxDecoration( + color: Colors.white, + borderRadius: BorderRadius.circular(5), + ), + padding: EdgeInsets.all(20), + margin: EdgeInsets.symmetric(horizontal: 25), + width: double.infinity, + child: SingleChildScrollView( + child: Column( + crossAxisAlignment: CrossAxisAlignment.start, + children: [ + Align( + alignment: Alignment.topRight, + child: Row( + mainAxisSize: MainAxisSize.min, + children: [ + Text( + "$shortDate", + style: TextStyle( + fontSize: 11, + color: ColorConstants.oldSliver, + ), + ), + Container( + width: 1, + height: 8, + color: Color(0xFFD7D7D7), + margin: EdgeInsets.symmetric( + horizontal: 3, + ), + ), + Text( + "$time", + style: TextStyle( + fontSize: 11, + color: ColorConstants.oldSliver, + ), + ), + ], + ), + ), + SizedBox(height: 12), + Text( + fileName, + style: TextStyle( + fontSize: 17, fontWeight: FontWeight.bold), + ), + SizedBox(height: 5), + Text( + double.parse(size.toString()) <= 1024 + ? '${size} ' + TextStrings().kb + : '${(size / (1024 * 1024)).toStringAsFixed(2)} ' + + TextStrings().mb, + style: TextStyle( + color: ColorConstants.grey, + fontSize: 11, + ), + textAlign: TextAlign.left, + ), + SizedBox(height: 10), + nickname.isNotEmpty + ? Text( + nickname, + style: TextStyle( + fontSize: 15, fontWeight: FontWeight.bold), + ) + : SizedBox(), + SizedBox(height: 5), + Text( + sender, + style: TextStyle( + fontSize: 13, + ), + ), + SizedBox(height: 10), + // fileDetail.message.isNotNull + // ? + if (note.isNotEmpty) ...[ + Text( + "Message", + style: TextStyle( + fontSize: 13, + color: Colors.grey, + ), + ), + // : SizedBox(), + SizedBox(height: 5), + Text( + note, + style: TextStyle( + fontSize: 13, + ), + ), + ] + ], + ), + ), + ), + ], + ), + ), + ); + } else { + await OpenFile.open(BackendService.getInstance().downloadDirectory!.path + + Platform.pathSeparator + + fileName); + } + } + + Future imageToBase64(String imagePath) async { + File imageFile = File(imagePath); + List imageBytes = await imageFile.readAsBytes(); + String base64Image = base64Encode(imageBytes); + return base64Image; + } } diff --git a/lib/services/file_transfer_service.dart b/lib/services/file_transfer_service.dart index ca107f30..44245e92 100644 --- a/lib/services/file_transfer_service.dart +++ b/lib/services/file_transfer_service.dart @@ -258,8 +258,8 @@ class FileTransferService { ..sharedBy = sharedByAtSign; var result = await AtClientManager.getInstance().atClient.get(atKey).catchError( - (e) => ExceptionService.instance.showGetExceptionOverlay(e), - ); + (e) => ExceptionService.instance.showGetExceptionOverlay(e), + ); FileTransferObject fileTransferObject; try { @@ -281,7 +281,8 @@ class FileTransferService { if (fileDownloadResponse.isError) { throw Exception('download fail'); } - var encryptedFileList = Directory(fileDownloadResponse.filePath!).listSync(); + var encryptedFileList = + Directory(fileDownloadResponse.filePath!).listSync(); try { for (var encryptedFile in encryptedFileList) { updateFileTransferState( diff --git a/lib/services/local_notification_service.dart b/lib/services/local_notification_service.dart index 3bd6407e..cfea5597 100644 --- a/lib/services/local_notification_service.dart +++ b/lib/services/local_notification_service.dart @@ -8,8 +8,7 @@ class LocalNotificationService { LocalNotificationService._() { init(); } - static LocalNotificationService _instance = - LocalNotificationService._(); + static LocalNotificationService _instance = LocalNotificationService._(); factory LocalNotificationService() => _instance; late FlutterLocalNotificationsPlugin _notificationsPlugin; late InitializationSettings initializationSettings; diff --git a/lib/services/overlay_service.dart b/lib/services/overlay_service.dart index 55d6de5d..1674c893 100644 --- a/lib/services/overlay_service.dart +++ b/lib/services/overlay_service.dart @@ -71,8 +71,7 @@ class OverlayService { child: InkWell( onTap: () { hideOverlay(); - if (flushBarStatus != - FlushBarStatus.DONE && + if (flushBarStatus != FlushBarStatus.DONE && flushBarStatus != FlushBarStatus.FAILED) { WelcomeScreenProvider() diff --git a/lib/utils/file_utils.dart b/lib/utils/file_utils.dart index 04219124..64b17292 100644 --- a/lib/utils/file_utils.dart +++ b/lib/utils/file_utils.dart @@ -2,15 +2,15 @@ import 'dart:io'; import 'package:at_contacts_group_flutter/services/group_service.dart'; import 'package:atsign_atmosphere_pro/data_models/file_modal.dart'; -import 'package:atsign_atmosphere_pro/screens/history/widgets/edit_bottomsheet.dart'; import 'package:atsign_atmosphere_pro/screens/my_files/widgets/downloads_folders.dart'; +import 'package:atsign_atmosphere_pro/services/common_utility_functions.dart'; import 'package:atsign_atmosphere_pro/services/navigation_service.dart'; +import 'package:atsign_atmosphere_pro/services/snackbar_service.dart'; import 'package:atsign_atmosphere_pro/utils/colors.dart'; import 'package:atsign_atmosphere_pro/utils/file_types.dart'; import 'package:atsign_atmosphere_pro/utils/text_strings.dart'; import 'package:atsign_atmosphere_pro/utils/vectors.dart'; import 'package:atsign_atmosphere_pro/view_models/file_transfer_provider.dart'; -import 'package:atsign_atmosphere_pro/view_models/my_files_provider.dart'; import 'package:atsign_atmosphere_pro/view_models/welcome_screen_view_model.dart'; import 'package:file_picker/file_picker.dart'; import 'package:flutter/material.dart'; @@ -25,31 +25,17 @@ class FileUtils { String? fileTransferId, Function()? onComplete, }) async { - await showModalBottomSheet( - context: NavService.navKey.currentContext!, - backgroundColor: Colors.white, - builder: (context) => EditBottomSheet( - onConfirmation: () async { - var file = File(filePath); - if (await file.exists()) { - await file.delete(); - } - if (fileTransferId != null) { - await Provider.of( - NavService.navKey.currentContext!, - listen: false) - .removeParticularFile(fileTransferId, - filePath.split(Platform.pathSeparator).last); - - await Provider.of( - NavService.navKey.currentContext!, - listen: false) - .getAllFiles(); - } - onComplete?.call(); - }, - deleteMessage: TextStrings.deleteFileConfirmationMsgMyFiles, - ), + CommonUtilityFunctions().showConfirmationDialog( + () { + File(filePath).deleteSync(); + SnackBarService().showSnackBar( + NavService.navKey.currentContext!, + "Successfully deleted the file(s)", + bgColor: ColorConstants.successColor, + ); + onComplete?.call(); + }, + 'Are you sure you want to delete the file(s)?', ); } diff --git a/lib/utils/images.dart b/lib/utils/images.dart index 63f6df3a..c80f4c61 100644 --- a/lib/utils/images.dart +++ b/lib/utils/images.dart @@ -106,7 +106,7 @@ class ImageConstants { static String icListType = '$_basePath/ic_list_type.png'; static String icCloudDownloading = '$_basePath/ic_cloud_downloading.png'; - // New UI tranfer screen + // New UI tranfer screen static String uploadFile = '$_basePath/upload_file.png'; static String transferHistory = '$_basePath/transfer_history.png'; static String icGroups = '$_basePath/ic_groups.png'; diff --git a/lib/view_models/welcome_screen_view_model.dart b/lib/view_models/welcome_screen_view_model.dart index d15882de..d94fd5de 100644 --- a/lib/view_models/welcome_screen_view_model.dart +++ b/lib/view_models/welcome_screen_view_model.dart @@ -31,7 +31,7 @@ class WelcomeScreenProvider extends BaseModel { } void _addToContactsList(GroupContactsModel _obj) { - selectedContacts.add(_obj); + selectedContacts.add(_obj); } updateSelectedContacts(List updatedList,