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: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/avatar.dart';
|
||||
import 'package:fluffychat/widgets/matrix.dart';
|
||||
|
|
@ -67,17 +66,16 @@ class ClientChooserButton extends StatelessWidget {
|
|||
],
|
||||
),
|
||||
),
|
||||
if (!FluffyThemes.isColumnMode(context))
|
||||
PopupMenuItem(
|
||||
value: SettingsAction.settings,
|
||||
child: Row(
|
||||
children: [
|
||||
const Icon(Icons.settings_outlined),
|
||||
const SizedBox(width: 18),
|
||||
Text(L10n.of(context).settings),
|
||||
],
|
||||
),
|
||||
PopupMenuItem(
|
||||
value: SettingsAction.settings,
|
||||
child: Row(
|
||||
children: [
|
||||
const Icon(Icons.settings_outlined),
|
||||
const SizedBox(width: 18),
|
||||
Text(L10n.of(context).settings),
|
||||
],
|
||||
),
|
||||
),
|
||||
const PopupMenuDivider(),
|
||||
for (final bundle in bundles) ...[
|
||||
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/matrix_sdk_extensions/matrix_locals.dart';
|
||||
import 'package:fluffychat/utils/platform_infos.dart';
|
||||
import 'package:fluffychat/utils/shortcut_memory_icon.dart';
|
||||
|
||||
Future<void> pushHelper(
|
||||
PushNotification notification, {
|
||||
|
|
@ -312,9 +313,10 @@ Future<void> _setShortcut(
|
|||
action: AppConfig.inviteLinkPrefix + event.room.id,
|
||||
shortLabel: title,
|
||||
conversationShortcut: true,
|
||||
icon: avatarFile == null
|
||||
? null
|
||||
: ShortcutMemoryIcon(jpegImage: avatarFile).toString(),
|
||||
icon: await avatarFile?.toShortcutMemoryIcon(
|
||||
event.room.id,
|
||||
event.room.client.database,
|
||||
),
|
||||
shortcutIconAsset: avatarFile == null
|
||||
? ShortcutIconAsset.androidAsset
|
||||
: 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
Reference in a new issue