From bdf317a1bc939e37a91f5b41d84ff8c9a0b699f7 Mon Sep 17 00:00:00 2001 From: IllusionMan1212 Date: Sat, 26 Feb 2022 19:53:07 +0200 Subject: [PATCH] fix/feat: fix some exceptions and add album art to notification --- android/app/src/main/AndroidManifest.xml | 2 +- .../lyricsgrabbr/lyricsgrabbr/MainActivity.kt | 11 +++++++-- .../lyricsgrabbr/NotificationListener.kt | 24 ++++++++++++------- .../lyricsgrabbr/NotificationStreamHandler.kt | 6 +++-- lib/main.dart | 8 +++---- lib/notification_listener.dart | 4 ---- 6 files changed, 32 insertions(+), 23 deletions(-) diff --git a/android/app/src/main/AndroidManifest.xml b/android/app/src/main/AndroidManifest.xml index 103811b..00b3eb0 100644 --- a/android/app/src/main/AndroidManifest.xml +++ b/android/app/src/main/AndroidManifest.xml @@ -1,7 +1,7 @@ with WidgetsBindingObserver { @override void initState() { WidgetsBinding.instance?.addObserver(this); - initPlatformState(); super.initState(); + initPlatformState(); } @override @@ -103,7 +103,6 @@ class _HomePageState extends State with WidgetsBindingObserver { SystemNavigator.pop(); return Future.value(false); }, - child: Expanded( child: AlertDialog( title: const Text( 'Notifications Access Permission', @@ -122,7 +121,6 @@ class _HomePageState extends State with WidgetsBindingObserver { child: const Text("OK")), ], ), - ), ); }); } @@ -159,7 +157,7 @@ class _HomePageState extends State with WidgetsBindingObserver { showWhen: false, ongoing: true, playSound: false, - largeIcon: ByteArrayAndroidBitmap.fromBase64String(notification.art), + largeIcon: FilePathAndroidBitmap(notification.art), ); final NotificationDetails notificationDetails = @@ -167,7 +165,7 @@ class _HomePageState extends State with WidgetsBindingObserver { await flutterLocalNotificationsPlugin.show( notificationId, - '${notification.songTitle} - ${notification.artist}', + 'Playing [${notification.songTitle}] By [${notification.artist}]', 'Tap to get lyrics', notificationDetails, ); diff --git a/lib/notification_listener.dart b/lib/notification_listener.dart index cb1f2cb..c745704 100644 --- a/lib/notification_listener.dart +++ b/lib/notification_listener.dart @@ -22,7 +22,6 @@ abstract class PlaybackState { class NotificationEvent { final String artist; final String packageName; - final String packageExtra; final String songTitle; final String art; final int playbackState; @@ -34,7 +33,6 @@ class NotificationEvent { required this.packageName, required this.artist, required this.timeStamp, - required this.packageExtra, required this.songTitle, required this.art, required this.playbackState, @@ -46,7 +44,6 @@ class NotificationEvent { String name = map['packageName']; String message = map['packageMessage']; String text = map['packageText']; - String extra = map['packageExtra']; String icon = map['packageArt']; int playbackState = map['packagePlaybackState']; int duration = map['packageDuration']; @@ -56,7 +53,6 @@ class NotificationEvent { artist: message, timeStamp: time, songTitle: text, - packageExtra: extra, art: icon, playbackState: playbackState, duration: duration