From 11cca4d044d729099ea2d470fe814c2c7efa744b Mon Sep 17 00:00:00 2001 From: Thomas Fransolet Date: Tue, 1 Aug 2023 16:49:34 +0200 Subject: [PATCH] wip notif --- android/app/build.gradle | 18 ++++++++++++++++- android/app/version.properties | 4 ++-- lib/Helpers/PushNotificationService.dart | 25 +++++++++++++++++------- lib/Screens/Main/MainPage.dart | 3 +++ lib/main.dart | 9 +++++---- 5 files changed, 45 insertions(+), 14 deletions(-) diff --git a/android/app/build.gradle b/android/app/build.gradle index 94e78f6..a8d39ed 100644 --- a/android/app/build.gradle +++ b/android/app/build.gradle @@ -6,6 +6,12 @@ if (localPropertiesFile.exists()) { } } +def keystoreProperties = new Properties() +def keystorePropertiesFile = rootProject.file('key.properties') +if (keystorePropertiesFile.exists()) { + keystoreProperties.load(new FileInputStream(keystorePropertiesFile)) +} + def flutterRoot = localProperties.getProperty('flutter.sdk') if (flutterRoot == null) { throw new GradleException("Flutter SDK not found. Define location with flutter.sdk in the local.properties file.") @@ -93,11 +99,20 @@ android { */ + signingConfigs { + release { + keyAlias keystoreProperties['keyAlias'] + keyPassword keystoreProperties['keyPassword'] + storeFile keystoreProperties['storeFile'] ? file(keystoreProperties['storeFile']) : null + storePassword keystoreProperties['storePassword'] + } + } + buildTypes { release { // TODO: Add your own signing config for the release build. // Signing with the debug keys for now, so `flutter run --release` works. - signingConfig signingConfigs.debug + signingConfig signingConfigs.release minifyEnabled true shrinkResources true debuggable false @@ -118,6 +133,7 @@ dependencies { // When using the BoM, don't specify versions in Firebase dependencies implementation 'com.google.firebase:firebase-analytics' implementation 'com.google.firebase:firebase-messaging' + implementation 'com.google.firebase:firebase-messaging-directboot' // Add the dependencies for any other desired Firebase products // https://firebase.google.com/docs/android/setup#available-libraries diff --git a/android/app/version.properties b/android/app/version.properties index fa580ae..59dc9ee 100644 --- a/android/app/version.properties +++ b/android/app/version.properties @@ -1,5 +1,5 @@ -#Mon Jul 31 16:50:59 CEST 2023 -VERSION_BUILD=43 +#Tue Aug 01 16:05:42 CEST 2023 +VERSION_BUILD=59 VERSION_MAJOR=1 VERSION_MINOR=0 VERSION_PATCH=0 diff --git a/lib/Helpers/PushNotificationService.dart b/lib/Helpers/PushNotificationService.dart index bac922f..67c34c6 100644 --- a/lib/Helpers/PushNotificationService.dart +++ b/lib/Helpers/PushNotificationService.dart @@ -10,10 +10,6 @@ import 'package:myhomie_app/Models/homieContext.dart'; import '../constants.dart'; class PushNotificationService { - //final FirebaseMessaging _fcm; - - PushNotificationService(); //this._fcm - goToPage(Map message) { var notification = PushNotificationMessage( title: message['notification']['title'], @@ -36,12 +32,22 @@ class PushNotificationService { ); } - Future initialise(HomieAppContext? homieAppContext, {required BuildContext context}) async { + Future initialise(HomieAppContext? homieAppContext, BuildContext context, [bool inMain = false]) async { if (Platform.isIOS) { //_fcm.requestPermission(); // IosNotificationSettings FirebaseMessaging.instance.requestPermission(); } + NotificationSettings settings = await FirebaseMessaging.instance.requestPermission( + alert: true, + announcement: false, + badge: true, + carPlay: false, + criticalAlert: false, + provisional: false, + sound: true, + ); + //_fcm.subscribeToTopic("main"); FirebaseMessaging.instance.subscribeToTopic("main"); @@ -95,13 +101,17 @@ class PushNotificationService { ); }*/ - NotificationManager.handleNotificationMsg(notification, context); - // show notification UI here + if(!inMain) { + // show notification UI here + NotificationManager.handleNotificationMsg(notification, context); + } }); FirebaseMessaging.onMessageOpenedApp.listen((RemoteMessage message) { print('A new onMessageOpenedApp event was published!'); + // TODO navigate somewhere in the app depending the coming message + /*Navigator.pushNamed( context, '/message', @@ -149,6 +159,7 @@ class DataNotification { }); } +@pragma('vm:entry-point') Future firebaseMessagingBackgroundHandler(RemoteMessage message) async { print("Handling a background message"); } diff --git a/lib/Screens/Main/MainPage.dart b/lib/Screens/Main/MainPage.dart index 38b99d1..16098d8 100644 --- a/lib/Screens/Main/MainPage.dart +++ b/lib/Screens/Main/MainPage.dart @@ -5,6 +5,7 @@ import 'package:myhomie_app/Components/Custom_Navigation_Bar/custom_app_bar.dart import 'package:myhomie_app/Components/Custom_Navigation_Bar/custom_bottom_navigation_bar.dart'; import 'package:myhomie_app/Components/Custom_Navigation_Bar/custom_nav_item.dart'; import 'package:myhomie_app/Helpers/MQTTHelper.dart'; +import 'package:myhomie_app/Helpers/PushNotificationService.dart'; import 'package:myhomie_app/Screens/Debug/DebugPage.dart'; import 'package:myhomie_app/Screens/Main/Automations/automations.dart'; import 'package:myhomie_app/Screens/Main/Devices/devices.dart'; @@ -50,6 +51,8 @@ class _MainPageState extends State { print("MQTT NOT INSTANTIATED"); MQTTHelper.instance.connect(appContext); } + final pushNotificationService = PushNotificationService(); + pushNotificationService.initialise(homieAppContext, context); return ChangeNotifierProvider( create: (_) => Index(0, appContext.getContext()), diff --git a/lib/main.dart b/lib/main.dart index 752ecb6..249bef0 100644 --- a/lib/main.dart +++ b/lib/main.dart @@ -58,13 +58,14 @@ class _MyAppState extends State { @override Widget build(BuildContext context) { - final pushNotificationService = PushNotificationService(); - pushNotificationService.initialise(widget.homieAppContext, context: context); + /*final pushNotificationService = PushNotificationService(); + pushNotificationService.initialise(widget.homieAppContext, context, true);*/ + return ChangeNotifierProvider( create: (_) => AppContext(widget.homieAppContext), child: MaterialApp( debugShowCheckedModeBanner: false, - title: 'MyHomie App Demo', + title: 'MyHomie App', initialRoute: widget.initialRoute, /*supportedLocales: [ const Locale('en', 'US'), @@ -74,7 +75,7 @@ class _MyAppState extends State { primarySwatch: Colors.blue, scaffoldBackgroundColor: kBackgroundColor, //fontFamily: "Vollkorn", - textTheme: TextTheme(bodyText1: TextStyle(color: kBodyTextColor)), + textTheme: TextTheme(bodyLarge: TextStyle(color: kBodyTextColor)), visualDensity: VisualDensity.adaptivePlatformDensity, ), routes: {