|
|
@ -76,15 +76,43 @@ class PushUtils { |
|
|
|
final cache = Cache(platform); |
|
|
|
final cache = Cache(platform); |
|
|
|
await cache.init(); |
|
|
|
await cache.init(); |
|
|
|
|
|
|
|
|
|
|
|
NextcloudNotificationsNotification? notification; |
|
|
|
|
|
|
|
var accounts = <Account>[]; |
|
|
|
var accounts = <Account>[]; |
|
|
|
Account? account; |
|
|
|
Account? account; |
|
|
|
|
|
|
|
NextcloudNotificationsNotification? notification; |
|
|
|
|
|
|
|
AndroidBitmap<Object>? largeIconBitmap; |
|
|
|
try { |
|
|
|
try { |
|
|
|
accounts = loadAccounts(AppStorage('accounts', sharedPreferences)); |
|
|
|
accounts = loadAccounts(AppStorage('accounts', sharedPreferences)); |
|
|
|
account = accounts.find(instance); |
|
|
|
account = accounts.find(instance); |
|
|
|
if (account != null) { |
|
|
|
if (account != null) { |
|
|
|
notification = |
|
|
|
notification = |
|
|
|
(await account.client.notifications.getNotification(id: pushNotification.subject.nid!)).ocs.data; |
|
|
|
(await account.client.notifications.getNotification(id: pushNotification.subject.nid!)).ocs.data; |
|
|
|
|
|
|
|
if (notification.icon?.endsWith('.svg') ?? false) { |
|
|
|
|
|
|
|
// Only SVG icons are supported right now (should be most of them) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
final cacheManager = DefaultCacheManager(); |
|
|
|
|
|
|
|
final file = await cacheManager.getSingleFile(notification.icon!); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
final pictureInfo = await vg.loadPicture(SvgFileLoader(file), null); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
const largeIconSize = 256; |
|
|
|
|
|
|
|
final scale = min(largeIconSize / pictureInfo.size.width, largeIconSize / pictureInfo.size.height); |
|
|
|
|
|
|
|
final scaledWidth = (pictureInfo.size.width * scale).toInt(); |
|
|
|
|
|
|
|
final scaledHeight = (pictureInfo.size.height * scale).toInt(); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
final recorder = PictureRecorder(); |
|
|
|
|
|
|
|
Canvas(recorder) |
|
|
|
|
|
|
|
..scale(scale) |
|
|
|
|
|
|
|
..drawPicture(pictureInfo.picture) |
|
|
|
|
|
|
|
..drawColor(themePrimaryColor, BlendMode.srcIn); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
pictureInfo.picture.dispose(); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
final image = recorder.endRecording().toImageSync(scaledWidth, scaledHeight); |
|
|
|
|
|
|
|
final bytes = await image.toByteData(format: ImageByteFormat.png); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
final bitmap = await Bitmap.fromProvider(MemoryImage(bytes!.buffer.asUint8List())); |
|
|
|
|
|
|
|
largeIconBitmap = ByteArrayAndroidBitmap(bitmap.buildHeaded()); |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} catch (e, s) { |
|
|
|
} catch (e, s) { |
|
|
|
debugPrint(e.toString()); |
|
|
|
debugPrint(e.toString()); |
|
|
@ -113,6 +141,7 @@ class PushUtils { |
|
|
|
subText: accounts.length > 1 && account != null ? account.client.humanReadableID : null, |
|
|
|
subText: accounts.length > 1 && account != null ? account.client.humanReadableID : null, |
|
|
|
groupKey: 'app_$appID', |
|
|
|
groupKey: 'app_$appID', |
|
|
|
icon: '@mipmap/ic_launcher', |
|
|
|
icon: '@mipmap/ic_launcher', |
|
|
|
|
|
|
|
largeIcon: largeIconBitmap, |
|
|
|
when: when?.millisecondsSinceEpoch, |
|
|
|
when: when?.millisecondsSinceEpoch, |
|
|
|
color: themePrimaryColor, |
|
|
|
color: themePrimaryColor, |
|
|
|
category: pushNotification.type == 'voip' ? AndroidNotificationCategory.call : null, |
|
|
|
category: pushNotification.type == 'voip' ? AndroidNotificationCategory.call : null, |
|
|
|