mirror of
				https://gitlab.com/comunic/comunicmobile
				synced 2025-10-31 18:24:23 +00:00 
			
		
		
		
	Ready to pre-configure independent notifications service
This commit is contained in:
		| @@ -1,6 +1,23 @@ | ||||
| package org.communiquons.comunic; | ||||
|  | ||||
|  | ||||
| import androidx.annotation.NonNull; | ||||
|  | ||||
| import org.communiquons.comunic.independentnotifications.NotificationsChannel; | ||||
|  | ||||
| import io.flutter.embedding.android.FlutterActivity; | ||||
| import io.flutter.embedding.engine.FlutterEngine; | ||||
| import io.flutter.plugin.common.MethodChannel; | ||||
|  | ||||
| public class MainActivity extends FlutterActivity { | ||||
|  | ||||
|     private static final String INDEPENDENT_NOTIFICATIONS_CHANNEL = "org.communiquons.comunic/independent-push-notifications-service"; | ||||
|  | ||||
|     @Override | ||||
|     public void configureFlutterEngine(@NonNull FlutterEngine flutterEngine) { | ||||
|         super.configureFlutterEngine(flutterEngine); | ||||
|  | ||||
|         new MethodChannel(flutterEngine.getDartExecutor().getBinaryMessenger(), INDEPENDENT_NOTIFICATIONS_CHANNEL) | ||||
|         .setMethodCallHandler(new NotificationsChannel()); | ||||
|     } | ||||
| } | ||||
|   | ||||
| @@ -0,0 +1,31 @@ | ||||
| package org.communiquons.comunic.independentnotifications; | ||||
|  | ||||
| import androidx.annotation.NonNull; | ||||
|  | ||||
| import io.flutter.plugin.common.MethodCall; | ||||
| import io.flutter.plugin.common.MethodChannel; | ||||
|  | ||||
| public class NotificationsChannel implements MethodChannel.MethodCallHandler { | ||||
|     @Override | ||||
|     public void onMethodCall(@NonNull MethodCall call, @NonNull MethodChannel.Result result) { | ||||
|         try { | ||||
|  | ||||
|             if (call.method.equals("preConfigure")) | ||||
|                 preConfigure(result); | ||||
|  | ||||
|             else | ||||
|                 result.notImplemented(); | ||||
|         } catch (Exception e) { | ||||
|             e.printStackTrace(); | ||||
|             result.error("Failed to execute native code!", e.getMessage(), null); | ||||
|         } | ||||
|  | ||||
|     } | ||||
|  | ||||
|     /** | ||||
|      * Pre-configure notifications service | ||||
|      */ | ||||
|     private static void preConfigure(@NonNull MethodChannel.Result result) throws Exception { | ||||
|         System.out.println("Ready to pre-configure !"); | ||||
|     } | ||||
| } | ||||
| @@ -26,4 +26,4 @@ subprojects { | ||||
|  | ||||
| task clean(type: Delete) { | ||||
|     delete rootProject.buildDir | ||||
| } | ||||
| } | ||||
| @@ -5,12 +5,13 @@ | ||||
| // ignore_for_file: lines_longer_than_80_chars | ||||
|  | ||||
| import 'package:file_picker/src/file_picker_web.dart'; | ||||
| import 'package:flutter_web_plugins/flutter_web_plugins.dart'; | ||||
| import 'package:shared_preferences_web/shared_preferences_web.dart'; | ||||
| import 'package:url_launcher_web/url_launcher_web.dart'; | ||||
| import 'package:video_player_web/video_player_web.dart'; | ||||
| import 'package:wakelock_web/wakelock_web.dart'; | ||||
|  | ||||
| import 'package:flutter_web_plugins/flutter_web_plugins.dart'; | ||||
|  | ||||
| // ignore: public_member_api_docs | ||||
| void registerPlugins(Registrar registrar) { | ||||
|   FilePickerWeb.registerWith(registrar); | ||||
|   | ||||
							
								
								
									
										18
									
								
								lib/helpers/independent_push_notifications_helper.dart
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										18
									
								
								lib/helpers/independent_push_notifications_helper.dart
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,18 @@ | ||||
| import 'package:flutter/services.dart'; | ||||
|  | ||||
| /// Independent push notifications helper | ||||
| /// | ||||
| /// @author Pierre Hubert | ||||
|  | ||||
| class IndependentPushNotificationsHelper { | ||||
|   static const platform = const MethodChannel( | ||||
|       "org.communiquons.comunic/independent-push-notifications-service"); | ||||
|  | ||||
|   /// Call this method to prepare the application for background refresh by | ||||
|   /// requesting appropriate permissions, configuring battery optimization... | ||||
|   /// | ||||
|   /// Throws an Exception in case of failure | ||||
|   static Future<void> preConfigure() async { | ||||
|     await platform.invokeMethod("preConfigure"); | ||||
|   } | ||||
| } | ||||
| @@ -1,3 +1,4 @@ | ||||
| import 'package:comunic/helpers/independent_push_notifications_helper.dart'; | ||||
| import 'package:comunic/helpers/push_notifications_helper.dart'; | ||||
| import 'package:comunic/helpers/server_config_helper.dart'; | ||||
| import 'package:comunic/models/config.dart'; | ||||
| @@ -15,8 +16,7 @@ import 'package:flutter/material.dart'; | ||||
| Future<void> showInitialPushNotificationsConfiguration( | ||||
|     BuildContext context) async { | ||||
|   // Check if no notifications service are available | ||||
|   if (!PushNotificationsHelper.arePushNotificationsAvailable) | ||||
|     return; | ||||
|   if (!PushNotificationsHelper.arePushNotificationsAvailable) return; | ||||
|  | ||||
|   await Navigator.of(context).push( | ||||
|       MaterialPageRoute(builder: (c) => PushNotificationsConfigurationRoute())); | ||||
| @@ -118,9 +118,9 @@ class _PushNotificationsConfigurationRouteState | ||||
|           // TODO: Handle this case. | ||||
|           throw new Exception("Firebase not supported yet!"); | ||||
|           break; | ||||
|  | ||||
|         case PushNotificationsStatus.INDEPENDENT: | ||||
|           // TODO: Handle this case. | ||||
|           throw new Exception("Independent not supported yet!"); | ||||
|           await IndependentPushNotificationsHelper.preConfigure(); | ||||
|           break; | ||||
|  | ||||
|         default: | ||||
|   | ||||
		Reference in New Issue
	
	Block a user