Skip to content

Commit

Permalink
TW-1429: change Clipboard to TwakeClipboard
Browse files Browse the repository at this point in the history
  • Loading branch information
sherlockvn committed Feb 6, 2024
1 parent b2e913b commit 6c57616
Show file tree
Hide file tree
Showing 8 changed files with 21 additions and 22 deletions.
2 changes: 1 addition & 1 deletion lib/pages/chat/input_bar/input_bar.dart
Original file line number Diff line number Diff line change
Expand Up @@ -320,7 +320,7 @@ class InputBar extends StatelessWidget with PasteImageMixin {
}

Future<void> 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();
Expand Down
2 changes: 1 addition & 1 deletion lib/pages/chat_details/chat_details.dart
Original file line number Diff line number Diff line change
Expand Up @@ -314,7 +314,7 @@ class ChatDetailsController extends State<ChatDetails>
}

void onTapInviteLink(BuildContext context, String inviteLink) async {
await Clipboard.instance.copyText(inviteLink);
await TwakeClipboard.instance.copyText(inviteLink);
TwakeSnackBar.show(
context,
L10n.of(context)!.copiedToClipboard,
Expand Down
4 changes: 2 additions & 2 deletions lib/pages/chat_profile_info/chat_profile_info_view.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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);
},
),
Expand Down Expand Up @@ -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);
},
),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,9 @@ extension TextEdittingControllerExtension on TextEditingController {
Future<void> 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;
Expand All @@ -30,15 +30,15 @@ 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));
}
}

Future<void> cutText() async {
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);
}
Expand Down
2 changes: 1 addition & 1 deletion lib/presentation/mixins/handle_clipboard_action_mixin.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
4 changes: 2 additions & 2 deletions lib/presentation/mixins/paste_image_mixin.dart
Original file line number Diff line number Diff line change
Expand Up @@ -13,15 +13,15 @@ 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');
return;
}
List<MatrixFile?>? matrixFiles;
if (PlatformInfos.isWeb) {
matrixFiles = await Clipboard.instance
matrixFiles = await TwakeClipboard.instance
.pasteImagesUsingBytes(reader: clipboardReader);
}
if (matrixFiles == null || matrixFiles.isEmpty) {
Expand Down
13 changes: 6 additions & 7 deletions lib/utils/clipboard.dart
Original file line number Diff line number Diff line change
@@ -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,
Expand All @@ -26,7 +25,7 @@ class Clipboard {
];

Future<void> copyText(String text) async {
flutter.Clipboard.setData(flutter.ClipboardData(text: text));
Clipboard.setData(ClipboardData(text: text));
}

Future<void> copyImageAsStream(File image, {String? mimeType}) async {
Expand Down
6 changes: 3 additions & 3 deletions lib/utils/matrix_sdk_extensions/event_extension.dart
Original file line number Diff line number Diff line change
Expand Up @@ -182,12 +182,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,
);
Expand All @@ -204,7 +204,7 @@ extension LocalizedBody on Event {
}

Future<void> copyTextEvent(BuildContext context, Timeline timeline) async {
await Clipboard.instance
await TwakeClipboard.instance
.copyText(getSelectedEventString(context, timeline));
}

Expand Down

0 comments on commit 6c57616

Please sign in to comment.