From d0e6ad70641dcfd7548651ff08d989bf5e6178a5 Mon Sep 17 00:00:00 2001 From: sherlock Date: Wed, 31 Jan 2024 14:37:12 +0700 Subject: [PATCH] TW-1429: change Clipboard to TwakeClipboard --- lib/pages/chat/input_bar/input_bar.dart | 2 +- lib/pages/chat_details/chat_details.dart | 2 +- .../chat_profile_info/chat_profile_info_view.dart | 4 ++-- .../text_editting_controller_extension.dart | 10 +++++----- .../mixins/handle_clipboard_action_mixin.dart | 2 +- lib/presentation/mixins/paste_image_mixin.dart | 4 ++-- lib/utils/clipboard.dart | 13 ++++++------- .../matrix_sdk_extensions/event_extension.dart | 6 +++--- 8 files changed, 21 insertions(+), 22 deletions(-) diff --git a/lib/pages/chat/input_bar/input_bar.dart b/lib/pages/chat/input_bar/input_bar.dart index 26b48e88d1..1d4147dc5f 100644 --- a/lib/pages/chat/input_bar/input_bar.dart +++ b/lib/pages/chat/input_bar/input_bar.dart @@ -320,7 +320,7 @@ class InputBar extends StatelessWidget with PasteImageMixin { } Future handlePaste(BuildContext context) async { - if (await Clipboard.instance.isReadableImageFormat() && room != null) { + if (await TwakeClipboard.instance.isReadableImageFormat() && room != null) { await pasteImage(context, room!); } else { await controller?.pasteText(); diff --git a/lib/pages/chat_details/chat_details.dart b/lib/pages/chat_details/chat_details.dart index 9b1ef1b054..cab25f7ffa 100644 --- a/lib/pages/chat_details/chat_details.dart +++ b/lib/pages/chat_details/chat_details.dart @@ -314,7 +314,7 @@ class ChatDetailsController extends State } void onTapInviteLink(BuildContext context, String inviteLink) async { - await Clipboard.instance.copyText(inviteLink); + await TwakeClipboard.instance.copyText(inviteLink); TwakeSnackBar.show( context, L10n.of(context)!.copiedToClipboard, diff --git a/lib/pages/chat_profile_info/chat_profile_info_view.dart b/lib/pages/chat_profile_info/chat_profile_info_view.dart index 9e972b8aee..cd1963c82b 100644 --- a/lib/pages/chat_profile_info/chat_profile_info_view.dart +++ b/lib/pages/chat_profile_info/chat_profile_info_view.dart @@ -317,7 +317,7 @@ class _CopiableRowWithMaterialIcon extends StatelessWidget { ), color: LinagoraRefColors.material().tertiary[40], onPressed: () { - Clipboard.instance.copyText(text); + TwakeClipboard.instance.copyText(text); TwakeSnackBar.show(context, L10n.of(context)!.copiedToClipboard); }, ), @@ -373,7 +373,7 @@ class _CopiableRowWithSvgIcon extends StatelessWidget { color: LinagoraRefColors.material().tertiary[40], focusColor: Theme.of(context).primaryColor, onPressed: () { - Clipboard.instance.copyText(text); + TwakeClipboard.instance.copyText(text); TwakeSnackBar.show(context, L10n.of(context)!.copiedToClipboard); }, ), diff --git a/lib/presentation/extensions/text_editting_controller_extension.dart b/lib/presentation/extensions/text_editting_controller_extension.dart index 92e98dc6b2..5e4f8db48f 100644 --- a/lib/presentation/extensions/text_editting_controller_extension.dart +++ b/lib/presentation/extensions/text_editting_controller_extension.dart @@ -6,9 +6,9 @@ extension TextEdittingControllerExtension on TextEditingController { Future pasteText({ClipboardReader? clipboardReader}) async { final start = selection.start; final end = selection.end; - Clipboard.instance.initReader(); - final pastedText = - await Clipboard.instance.pasteText(clipboardReader: clipboardReader); + TwakeClipboard.instance.initReader(); + final pastedText = await TwakeClipboard.instance + .pasteText(clipboardReader: clipboardReader); if (pastedText != null) { if (start == -1 || end == -1) { text = pastedText + text; @@ -30,7 +30,7 @@ extension TextEdittingControllerExtension on TextEditingController { final start = selection.start; final end = selection.end; if (start < end) { - await Clipboard.instance.copyText(text.substring(start, end)); + await TwakeClipboard.instance.copyText(text.substring(start, end)); } } @@ -38,7 +38,7 @@ extension TextEdittingControllerExtension on TextEditingController { final start = selection.start; final end = selection.end; if (start < end) { - await Clipboard.instance.copyText(text.substring(start, end)); + await TwakeClipboard.instance.copyText(text.substring(start, end)); text = text.replaceRange(start, end, ""); selection = TextSelection.collapsed(offset: start); } diff --git a/lib/presentation/mixins/handle_clipboard_action_mixin.dart b/lib/presentation/mixins/handle_clipboard_action_mixin.dart index c524e8d5b9..c203eb39b3 100644 --- a/lib/presentation/mixins/handle_clipboard_action_mixin.dart +++ b/lib/presentation/mixins/handle_clipboard_action_mixin.dart @@ -27,7 +27,7 @@ mixin HandleClipboardActionMixin on PasteImageMixin { return; } final clipboardReader = await event.getClipboardReader(); - if (await Clipboard.instance + if (await TwakeClipboard.instance .isReadableImageFormat(clipboardReader: clipboardReader) && room != null) { await pasteImage(context, room!, clipboardReader: clipboardReader); diff --git a/lib/presentation/mixins/paste_image_mixin.dart b/lib/presentation/mixins/paste_image_mixin.dart index 7c1f47551d..7dff5f4421 100644 --- a/lib/presentation/mixins/paste_image_mixin.dart +++ b/lib/presentation/mixins/paste_image_mixin.dart @@ -13,7 +13,7 @@ mixin PasteImageMixin { Room room, { ClipboardReader? clipboardReader, }) async { - if (!(await Clipboard.instance + if (!(await TwakeClipboard.instance .isReadableImageFormat(clipboardReader: clipboardReader))) { TwakeSnackBar.show(context, L10n.of(context)!.fileFormatNotSupported); Logs().e('PasteImageMixin::pasteImage(): not readable image format'); @@ -21,7 +21,7 @@ mixin PasteImageMixin { } List? matrixFiles; if (PlatformInfos.isWeb) { - matrixFiles = await Clipboard.instance + matrixFiles = await TwakeClipboard.instance .pasteImagesUsingBytes(reader: clipboardReader); } if (matrixFiles == null || matrixFiles.isEmpty) { diff --git a/lib/utils/clipboard.dart b/lib/utils/clipboard.dart index 06f844fffb..74f9a50417 100644 --- a/lib/utils/clipboard.dart +++ b/lib/utils/clipboard.dart @@ -1,21 +1,20 @@ import 'dart:async'; import 'dart:io'; -import 'dart:typed_data'; import 'package:fluffychat/presentation/model/clipboard/clipboard_image_info.dart'; -import 'package:flutter/services.dart' as flutter; +import 'package:flutter/services.dart'; import 'package:matrix/matrix.dart'; import 'package:mime/mime.dart'; import 'package:super_clipboard/super_clipboard.dart'; -class Clipboard { - static final _clipboard = Clipboard._(); +class TwakeClipboard { + static final _clipboard = TwakeClipboard._(); - Clipboard._(); + TwakeClipboard._(); ClipboardReader? _reader; - static Clipboard get instance => _clipboard; + static TwakeClipboard get instance => _clipboard; static const allImageFormatsSupported = [ Formats.png, @@ -26,7 +25,7 @@ class Clipboard { ]; Future copyText(String text) async { - flutter.Clipboard.setData(flutter.ClipboardData(text: text)); + Clipboard.setData(ClipboardData(text: text)); } Future copyImageAsStream(File image, {String? mimeType}) async { diff --git a/lib/utils/matrix_sdk_extensions/event_extension.dart b/lib/utils/matrix_sdk_extensions/event_extension.dart index a3984f137a..4a95631900 100644 --- a/lib/utils/matrix_sdk_extensions/event_extension.dart +++ b/lib/utils/matrix_sdk_extensions/event_extension.dart @@ -179,12 +179,12 @@ extension LocalizedBody on Event { ); try { if (matrixFile.filePath != null) { - await Clipboard.instance.copyImageAsStream( + await TwakeClipboard.instance.copyImageAsStream( File(matrixFile.filePath!), mimeType: mimeType, ); } else if (matrixFile.bytes != null) { - await Clipboard.instance.copyImageAsBytes( + await TwakeClipboard.instance.copyImageAsBytes( matrixFile.bytes!, mimeType: mimeType, ); @@ -201,7 +201,7 @@ extension LocalizedBody on Event { } Future copyTextEvent(BuildContext context, Timeline timeline) async { - await Clipboard.instance + await TwakeClipboard.instance .copyText(getSelectedEventString(context, timeline)); }