diff --git a/app/lib/common/utils/utils.dart b/app/lib/common/utils/utils.dart index 156c2c81464b..644a494af46c 100644 --- a/app/lib/common/utils/utils.dart +++ b/app/lib/common/utils/utils.dart @@ -165,7 +165,7 @@ Future openLink(String target, BuildContext context) async { } } -String getFileSize(int bytes) { +String getHumanReadableFileSize(int bytes) { if (bytes <= 0) return '0 B'; const suffixes = ['B', 'KB', 'MB', 'GB', 'TB', 'PB', 'EB', 'ZB', 'YB']; var i = (log(bytes) / log(1024)).floor(); diff --git a/app/lib/common/widgets/spaces/select_space_form_field.dart b/app/lib/common/widgets/spaces/select_space_form_field.dart index 9aad9e8e01e4..3fa49b8963b5 100644 --- a/app/lib/common/widgets/spaces/select_space_form_field.dart +++ b/app/lib/common/widgets/spaces/select_space_form_field.dart @@ -15,7 +15,7 @@ class SelectSpaceFormField extends ConsumerWidget { final String? emptyText; final String canCheck; final bool mandatory; - final bool isCompactView; + final bool useCompatView; const SelectSpaceFormField({ super.key, @@ -24,18 +24,17 @@ class SelectSpaceFormField extends ConsumerWidget { this.emptyText, this.mandatory = true, required this.canCheck, - this.isCompactView = false, + this.useCompatView = false, }); void selectSpace(BuildContext context, WidgetRef ref) async { - final spaceNotifier = ref.watch(selectedSpaceIdProvider.notifier); final newSelectedSpaceId = await selectSpaceDrawer( context: context, currentSpaceId: ref.read(selectedSpaceIdProvider), canCheck: canCheck, title: Text(selectTitle ?? L10n.of(context).selectSpace), ); - spaceNotifier.state = newSelectedSpaceId; + ref.read(selectedSpaceIdProvider.notifier).state = newSelectedSpaceId; } @override @@ -57,7 +56,7 @@ class SelectSpaceFormField extends ConsumerWidget { child: Column( crossAxisAlignment: CrossAxisAlignment.start, children: [ - if (!isCompactView) + if (!useCompatView) Text( title ?? L10n.of(context).space, style: Theme.of(context).textTheme.bodyMedium, @@ -99,9 +98,9 @@ class SelectSpaceFormField extends ConsumerWidget { ? SpaceChip( space: space, onTapOpenSpaceDetail: false, - isCompactView: isCompactView, + useCompatView: useCompatView, onTapSelectSpace: () => - isCompactView ? selectSpace(context, ref) : null, + useCompatView ? selectSpace(context, ref) : null, ) : Text(currentSelectedSpace!), error: (e, s) => Text(L10n.of(context).errorLoading(e)), diff --git a/app/lib/features/attachments/widgets/attachment_item.dart b/app/lib/features/attachments/widgets/attachment_item.dart index 951b0044672c..e6ea54c01bb9 100644 --- a/app/lib/features/attachments/widgets/attachment_item.dart +++ b/app/lib/features/attachments/widgets/attachment_item.dart @@ -91,7 +91,7 @@ class AttachmentItem extends ConsumerWidget { final fileNameSplit = fileName.split('.'); final title = fileNameSplit.first; final fileExtension = fileNameSplit.last; - String fileSize = getFileSize(msgContent.size() ?? 0); + String fileSize = getHumanReadableFileSize(msgContent.size() ?? 0); return Column( crossAxisAlignment: CrossAxisAlignment.start, children: [ @@ -135,10 +135,8 @@ class AttachmentItem extends ConsumerWidget { // Open attachment link if (attachmentType == AttachmentType.link) { openLink(attachment.link() ?? '', context); - } - - // If attachment is media then check media is downloaded - else if (mediaState.mediaFile == null) { + } else if (mediaState.mediaFile == null) { + // If attachment is media then check media is downloaded // If attachment not downloaded ref .read(attachmentMediaStateProvider(attachment).notifier) diff --git a/app/lib/features/attachments/widgets/attachment_section.dart b/app/lib/features/attachments/widgets/attachment_section.dart index c0cd6551016a..5cd90dca4316 100644 --- a/app/lib/features/attachments/widgets/attachment_section.dart +++ b/app/lib/features/attachments/widgets/attachment_section.dart @@ -100,9 +100,8 @@ class FoundAttachmentSectionWidget extends ConsumerWidget { spacing: 5.0, runSpacing: 10.0, children: [ - if (list.isNotEmpty) - for (var item in list) - _buildAttachmentItem(context, item, canEdit), + for (var item in list) + _buildAttachmentItem(context, item, canEdit), ], ), ], diff --git a/app/lib/features/home/widgets/space_chip.dart b/app/lib/features/home/widgets/space_chip.dart index fbcf6ee5522a..c8bec38528e5 100644 --- a/app/lib/features/home/widgets/space_chip.dart +++ b/app/lib/features/home/widgets/space_chip.dart @@ -11,7 +11,7 @@ class SpaceChip extends ConsumerWidget { final SpaceItem? space; final String? spaceId; final bool onTapOpenSpaceDetail; - final bool isCompactView; + final bool useCompatView; final VoidCallback? onTapSelectSpace; const SpaceChip({ @@ -19,7 +19,7 @@ class SpaceChip extends ConsumerWidget { this.space, this.spaceId, this.onTapOpenSpaceDetail = true, - this.isCompactView = false, + this.useCompatView = false, this.onTapSelectSpace, }); @@ -64,7 +64,7 @@ class SpaceChip extends ConsumerWidget { return InkWell( onTap: onTapOpenSpaceDetail ? () => goToSpace(context, space.roomId) : null, - child: isCompactView + child: useCompatView ? Row( children: [ const Text('In'), diff --git a/app/lib/features/pins/actions/attachment_leading_icon.dart b/app/lib/features/pins/actions/attachment_leading_icon.dart index f136069bf645..4d7936d9b58b 100644 --- a/app/lib/features/pins/actions/attachment_leading_icon.dart +++ b/app/lib/features/pins/actions/attachment_leading_icon.dart @@ -3,18 +3,13 @@ import 'package:atlas_icons/atlas_icons.dart'; import 'package:flutter/material.dart'; Widget attachmentLeadingIcon(AttachmentType pinAttachmentType) { - switch (pinAttachmentType) { - case AttachmentType.link: - return const Icon(Atlas.link); - case AttachmentType.image: - return const Icon(Atlas.image_gallery); - case AttachmentType.video: - return const Icon(Atlas.video_camera); - case AttachmentType.audio: - return const Icon(Atlas.audio_headphones); - case AttachmentType.file: - return const Icon(Atlas.file); - default: - return const SizedBox.shrink(); - } + return switch (pinAttachmentType) { + AttachmentType.link => const Icon(Atlas.link), + AttachmentType.image => const Icon(Atlas.image_gallery), + AttachmentType.video => const Icon(Atlas.video_camera), + AttachmentType.audio => const Icon(Atlas.audio_headphones), + AttachmentType.file => const Icon(Atlas.file), + AttachmentType.camera => const Icon(Atlas.camera), + AttachmentType.location => const Icon(Atlas.location) + }; } diff --git a/app/lib/features/pins/actions/select_pin_attachments.dart b/app/lib/features/pins/actions/select_pin_attachments.dart index 264820066af9..def5c81727a0 100644 --- a/app/lib/features/pins/actions/select_pin_attachments.dart +++ b/app/lib/features/pins/actions/select_pin_attachments.dart @@ -11,18 +11,13 @@ import 'package:logging/logging.dart'; final _log = Logger('a3::pins::select::attachment'); FileType attachmentFileType(AttachmentType pinAttachmentType) { - switch (pinAttachmentType) { - case AttachmentType.image: - return FileType.image; - case AttachmentType.video: - return FileType.video; - case AttachmentType.audio: - return FileType.audio; - case AttachmentType.file: - return FileType.custom; - default: - return FileType.any; - } + return switch (pinAttachmentType) { + AttachmentType.image => FileType.image, + AttachmentType.video => FileType.video, + AttachmentType.audio => FileType.audio, + AttachmentType.file => FileType.custom, + _ => FileType.any + }; } //Select Attachment @@ -31,14 +26,10 @@ Future selectAttachment( AttachmentType attachmentType, ) async { try { - final fileType = attachmentFileType(attachmentType); - FilePickerResult? result = await FilePicker.platform.pickFiles( - type: fileType, - allowedExtensions: fileType == FileType.custom ? ['pdf', 'txt'] : null, - ); + FilePickerResult? result = await FilePicker.platform.pickFiles(); if (result != null && result.files.isNotEmpty) { final file = result.files.first; - String fileSize = getFileSize(file.size); + String fileSize = getHumanReadableFileSize(file.size); final fileNameSplit = file.name.split('.'); final title = fileNameSplit.first; final fileExtension = fileNameSplit.last; @@ -53,6 +44,6 @@ Future selectAttachment( } } catch (e, st) { debugPrint('Error => $e'); - _log.severe('Error => $e', st); + _log.severe('Error selecting attachment', e, st); } } diff --git a/app/lib/features/pins/pages/create_pin.dart b/app/lib/features/pins/pages/create_pin.dart index 5c8b86eb87ee..b98c87c69507 100644 --- a/app/lib/features/pins/pages/create_pin.dart +++ b/app/lib/features/pins/pages/create_pin.dart @@ -96,7 +96,7 @@ class _CreatePinConsumerState extends ConsumerState { alignment: Alignment.centerLeft, child: SelectSpaceFormField( canCheck: 'CanPostPin', - isCompactView: true, + useCompatView: true, ), ), const SizedBox(height: 14), diff --git a/app/lib/features/pins/providers/notifiers/create_pin_notifier.dart b/app/lib/features/pins/providers/notifiers/create_pin_notifier.dart index 06cf47b11f5b..62d81989bd74 100644 --- a/app/lib/features/pins/providers/notifiers/create_pin_notifier.dart +++ b/app/lib/features/pins/providers/notifiers/create_pin_notifier.dart @@ -3,9 +3,7 @@ import 'package:acter/features/pins/models/create_pin_state/pin_attachment_model import 'package:flutter_riverpod/flutter_riverpod.dart'; class CreatePinNotifier extends StateNotifier { - final Ref ref; - - CreatePinNotifier({required this.ref}) : super(const CreatePinState()); + CreatePinNotifier() : super(const CreatePinState()); void setPinTitleValue(String title) { state = state.copyWith(pinTitle: title); diff --git a/app/lib/features/pins/providers/pins_provider.dart b/app/lib/features/pins/providers/pins_provider.dart index 9952e0bd69e2..b1962b4d5463 100644 --- a/app/lib/features/pins/providers/pins_provider.dart +++ b/app/lib/features/pins/providers/pins_provider.dart @@ -43,5 +43,5 @@ final pinEditProvider = StateNotifierProvider.family // Create Pin State final createPinStateProvider = StateNotifierProvider.autoDispose( - (ref) => CreatePinNotifier(ref: ref), -); \ No newline at end of file + (ref) => CreatePinNotifier(), +); diff --git a/app/lib/features/pins/widgets/pin_attachment_options.dart b/app/lib/features/pins/widgets/pin_attachment_options.dart index 7ab5ae0e32b5..5531bcf167ec 100644 --- a/app/lib/features/pins/widgets/pin_attachment_options.dart +++ b/app/lib/features/pins/widgets/pin_attachment_options.dart @@ -8,6 +8,7 @@ import 'package:acter/features/pins/providers/pins_provider.dart'; import 'package:atlas_icons/atlas_icons.dart'; import 'package:flutter/material.dart'; import 'package:flutter_riverpod/flutter_riverpod.dart'; +import 'package:flutter_gen/gen_l10n/l10n.dart'; class PinAttachmentOptions extends ConsumerWidget { final bool isBottomSheetOpen; @@ -28,7 +29,7 @@ class PinAttachmentOptions extends ConsumerWidget { children: [ _pinAttachmentOptionItem( context: context, - title: 'Text', + title: L10n.of(context).text, iconData: Atlas.text, onTap: () { showEditPinDescriptionBottomSheet( @@ -44,7 +45,7 @@ class PinAttachmentOptions extends ConsumerWidget { ), _pinAttachmentOptionItem( context: context, - title: 'Link', + title: L10n.of(context).link, iconData: Atlas.link, onTap: () => showAddPinLinkBottomSheet( context: context, @@ -54,7 +55,7 @@ class PinAttachmentOptions extends ConsumerWidget { ), _pinAttachmentOptionItem( context: context, - title: 'File', + title: L10n.of(context).file, iconData: Atlas.file, onTap: () => selectAttachmentOnTap( ref, @@ -69,7 +70,7 @@ class PinAttachmentOptions extends ConsumerWidget { children: [ _pinAttachmentOptionItem( context: context, - title: 'Image', + title: L10n.of(context).image, iconData: Atlas.image_gallery, onTap: () => selectAttachmentOnTap( ref, @@ -79,7 +80,7 @@ class PinAttachmentOptions extends ConsumerWidget { ), _pinAttachmentOptionItem( context: context, - title: 'Video', + title: L10n.of(context).video, iconData: Atlas.video_camera, onTap: () => selectAttachmentOnTap( ref, @@ -89,7 +90,7 @@ class PinAttachmentOptions extends ConsumerWidget { ), _pinAttachmentOptionItem( context: context, - title: 'Audio', + title: L10n.of(context).audio, iconData: Atlas.audio_headphones, onTap: () => selectAttachmentOnTap( ref, diff --git a/app/lib/l10n/app_en.arb b/app/lib/l10n/app_en.arb index 6d69abbbd4c9..c89e52f797eb 100644 --- a/app/lib/l10n/app_en.arb +++ b/app/lib/l10n/app_en.arb @@ -2065,5 +2065,7 @@ "pleaseEnterALink": "Please enter a link", "pleaseEnterAValidLink": "Please enter a valid link", "addLink": "Add Link", - "attachmentEmptyStateTitle": "No attachments found." + "attachmentEmptyStateTitle": "No attachments found.", + "text": "text", + "audio": "Audio" }