1
0
mirror of https://gitlab.com/comunic/comunicmobile synced 2024-11-25 22:39:22 +00:00

Ready to pre-configure independent notifications service

This commit is contained in:
Pierre HUBERT 2021-04-13 17:56:55 +02:00
parent 7e9a594bae
commit 1400bbbeb7
6 changed files with 73 additions and 6 deletions

View File

@ -1,6 +1,23 @@
package org.communiquons.comunic; package org.communiquons.comunic;
import androidx.annotation.NonNull;
import org.communiquons.comunic.independentnotifications.NotificationsChannel;
import io.flutter.embedding.android.FlutterActivity; import io.flutter.embedding.android.FlutterActivity;
import io.flutter.embedding.engine.FlutterEngine;
import io.flutter.plugin.common.MethodChannel;
public class MainActivity extends FlutterActivity { 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());
}
} }

View File

@ -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 !");
}
}

View File

@ -5,12 +5,13 @@
// ignore_for_file: lines_longer_than_80_chars // ignore_for_file: lines_longer_than_80_chars
import 'package:file_picker/src/file_picker_web.dart'; 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:shared_preferences_web/shared_preferences_web.dart';
import 'package:url_launcher_web/url_launcher_web.dart'; import 'package:url_launcher_web/url_launcher_web.dart';
import 'package:video_player_web/video_player_web.dart'; import 'package:video_player_web/video_player_web.dart';
import 'package:wakelock_web/wakelock_web.dart'; import 'package:wakelock_web/wakelock_web.dart';
import 'package:flutter_web_plugins/flutter_web_plugins.dart';
// ignore: public_member_api_docs // ignore: public_member_api_docs
void registerPlugins(Registrar registrar) { void registerPlugins(Registrar registrar) {
FilePickerWeb.registerWith(registrar); FilePickerWeb.registerWith(registrar);

View 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");
}
}

View File

@ -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/push_notifications_helper.dart';
import 'package:comunic/helpers/server_config_helper.dart'; import 'package:comunic/helpers/server_config_helper.dart';
import 'package:comunic/models/config.dart'; import 'package:comunic/models/config.dart';
@ -15,8 +16,7 @@ import 'package:flutter/material.dart';
Future<void> showInitialPushNotificationsConfiguration( Future<void> showInitialPushNotificationsConfiguration(
BuildContext context) async { BuildContext context) async {
// Check if no notifications service are available // Check if no notifications service are available
if (!PushNotificationsHelper.arePushNotificationsAvailable) if (!PushNotificationsHelper.arePushNotificationsAvailable) return;
return;
await Navigator.of(context).push( await Navigator.of(context).push(
MaterialPageRoute(builder: (c) => PushNotificationsConfigurationRoute())); MaterialPageRoute(builder: (c) => PushNotificationsConfigurationRoute()));
@ -118,9 +118,9 @@ class _PushNotificationsConfigurationRouteState
// TODO: Handle this case. // TODO: Handle this case.
throw new Exception("Firebase not supported yet!"); throw new Exception("Firebase not supported yet!");
break; break;
case PushNotificationsStatus.INDEPENDENT: case PushNotificationsStatus.INDEPENDENT:
// TODO: Handle this case. await IndependentPushNotificationsHelper.preConfigure();
throw new Exception("Independent not supported yet!");
break; break;
default: default: