chore: Crop shortcut file on android and cache it
This commit is contained in:
parent
a74c00f41c
commit
1305171219
3 changed files with 50 additions and 14 deletions
|
|
@ -4,7 +4,6 @@ import 'package:flutter_gen/gen_l10n/l10n.dart';
|
||||||
import 'package:go_router/go_router.dart';
|
import 'package:go_router/go_router.dart';
|
||||||
import 'package:matrix/matrix.dart';
|
import 'package:matrix/matrix.dart';
|
||||||
|
|
||||||
import 'package:fluffychat/config/themes.dart';
|
|
||||||
import 'package:fluffychat/widgets/adaptive_dialogs/show_ok_cancel_alert_dialog.dart';
|
import 'package:fluffychat/widgets/adaptive_dialogs/show_ok_cancel_alert_dialog.dart';
|
||||||
import 'package:fluffychat/widgets/avatar.dart';
|
import 'package:fluffychat/widgets/avatar.dart';
|
||||||
import 'package:fluffychat/widgets/matrix.dart';
|
import 'package:fluffychat/widgets/matrix.dart';
|
||||||
|
|
@ -67,17 +66,16 @@ class ClientChooserButton extends StatelessWidget {
|
||||||
],
|
],
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
if (!FluffyThemes.isColumnMode(context))
|
PopupMenuItem(
|
||||||
PopupMenuItem(
|
value: SettingsAction.settings,
|
||||||
value: SettingsAction.settings,
|
child: Row(
|
||||||
child: Row(
|
children: [
|
||||||
children: [
|
const Icon(Icons.settings_outlined),
|
||||||
const Icon(Icons.settings_outlined),
|
const SizedBox(width: 18),
|
||||||
const SizedBox(width: 18),
|
Text(L10n.of(context).settings),
|
||||||
Text(L10n.of(context).settings),
|
],
|
||||||
],
|
|
||||||
),
|
|
||||||
),
|
),
|
||||||
|
),
|
||||||
const PopupMenuDivider(),
|
const PopupMenuDivider(),
|
||||||
for (final bundle in bundles) ...[
|
for (final bundle in bundles) ...[
|
||||||
if (matrix.accountBundles[bundle]!.length != 1 ||
|
if (matrix.accountBundles[bundle]!.length != 1 ||
|
||||||
|
|
|
||||||
|
|
@ -15,6 +15,7 @@ import 'package:fluffychat/utils/client_download_content_extension.dart';
|
||||||
import 'package:fluffychat/utils/client_manager.dart';
|
import 'package:fluffychat/utils/client_manager.dart';
|
||||||
import 'package:fluffychat/utils/matrix_sdk_extensions/matrix_locals.dart';
|
import 'package:fluffychat/utils/matrix_sdk_extensions/matrix_locals.dart';
|
||||||
import 'package:fluffychat/utils/platform_infos.dart';
|
import 'package:fluffychat/utils/platform_infos.dart';
|
||||||
|
import 'package:fluffychat/utils/shortcut_memory_icon.dart';
|
||||||
|
|
||||||
Future<void> pushHelper(
|
Future<void> pushHelper(
|
||||||
PushNotification notification, {
|
PushNotification notification, {
|
||||||
|
|
@ -312,9 +313,10 @@ Future<void> _setShortcut(
|
||||||
action: AppConfig.inviteLinkPrefix + event.room.id,
|
action: AppConfig.inviteLinkPrefix + event.room.id,
|
||||||
shortLabel: title,
|
shortLabel: title,
|
||||||
conversationShortcut: true,
|
conversationShortcut: true,
|
||||||
icon: avatarFile == null
|
icon: await avatarFile?.toShortcutMemoryIcon(
|
||||||
? null
|
event.room.id,
|
||||||
: ShortcutMemoryIcon(jpegImage: avatarFile).toString(),
|
event.room.client.database,
|
||||||
|
),
|
||||||
shortcutIconAsset: avatarFile == null
|
shortcutIconAsset: avatarFile == null
|
||||||
? ShortcutIconAsset.androidAsset
|
? ShortcutIconAsset.androidAsset
|
||||||
: ShortcutIconAsset.memoryAsset,
|
: ShortcutIconAsset.memoryAsset,
|
||||||
|
|
|
||||||
36
lib/utils/shortcut_memory_icon.dart
Normal file
36
lib/utils/shortcut_memory_icon.dart
Normal file
|
|
@ -0,0 +1,36 @@
|
||||||
|
import 'dart:convert';
|
||||||
|
import 'dart:typed_data';
|
||||||
|
|
||||||
|
import 'package:image/image.dart';
|
||||||
|
import 'package:matrix/matrix.dart';
|
||||||
|
|
||||||
|
extension ShortcutMemoryIcon on Uint8List {
|
||||||
|
Future<String?> toShortcutMemoryIcon(
|
||||||
|
String roomId,
|
||||||
|
DatabaseApi? database,
|
||||||
|
) async {
|
||||||
|
final cacheKey = Uri.parse('im.fluffychat://shortcuts/$roomId');
|
||||||
|
final cachedFile = await database?.getFile(cacheKey);
|
||||||
|
if (cachedFile != null) return base64Encode(cachedFile);
|
||||||
|
|
||||||
|
final image = decodeImage(this);
|
||||||
|
if (image == null) return null;
|
||||||
|
|
||||||
|
final size = image.width < image.height ? image.width : image.height;
|
||||||
|
final x = (image.width - size) ~/ 2;
|
||||||
|
final y = (image.height - size) ~/ 2;
|
||||||
|
|
||||||
|
final croppedImage = copyCrop(
|
||||||
|
image,
|
||||||
|
x: x,
|
||||||
|
y: y,
|
||||||
|
width: size,
|
||||||
|
height: size,
|
||||||
|
);
|
||||||
|
|
||||||
|
final bytes = croppedImage.toUint8List();
|
||||||
|
await database?.storeFile(cacheKey, bytes, 0);
|
||||||
|
|
||||||
|
return base64Encode(croppedImage.toUint8List());
|
||||||
|
}
|
||||||
|
}
|
||||||
Loading…
Add table
Add a link
Reference in a new issue