1
0
mirror of https://gitlab.com/comunic/comunicmobile synced 2024-11-22 12:59:21 +00:00

Integrate Firebase

This commit is contained in:
Pierre HUBERT 2021-04-15 13:34:49 +02:00
parent 0c75575a70
commit f0f2f06ec2
9 changed files with 196 additions and 5 deletions

View File

@ -104,3 +104,5 @@ dependencies {
androidTestImplementation 'androidx.test.ext:junit:1.1.1' androidTestImplementation 'androidx.test.ext:junit:1.1.1'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.2.0' androidTestImplementation 'androidx.test.espresso:espresso-core:3.2.0'
} }
apply plugin: 'com.google.gms.google-services'

View File

@ -0,0 +1,39 @@
{
"project_info": {
"project_number": "1007877315904",
"project_id": "comunic-ae92c",
"storage_bucket": "comunic-ae92c.appspot.com"
},
"client": [
{
"client_info": {
"mobilesdk_app_id": "1:1007877315904:android:d1db6417ef236d850aeea5",
"android_client_info": {
"package_name": "org.communiquons.beta"
}
},
"oauth_client": [
{
"client_id": "1007877315904-6l6lj4d93tf7btckjpjear0js45mvuj5.apps.googleusercontent.com",
"client_type": 3
}
],
"api_key": [
{
"current_key": "AIzaSyAfhNbEhHkmVYPQK200rJGxH9hc7qHlcwU"
}
],
"services": {
"appinvite_service": {
"other_platform_oauth_client": [
{
"client_id": "1007877315904-6l6lj4d93tf7btckjpjear0js45mvuj5.apps.googleusercontent.com",
"client_type": 3
}
]
}
}
}
],
"configuration_version": "1"
}

View File

@ -0,0 +1,68 @@
{
"project_info": {
"project_number": "1007877315904",
"project_id": "comunic-ae92c",
"storage_bucket": "comunic-ae92c.appspot.com"
},
"client": [
{
"client_info": {
"mobilesdk_app_id": "1:1007877315904:android:d1db6417ef236d850aeea5",
"android_client_info": {
"package_name": "org.communiquons.beta"
}
},
"oauth_client": [
{
"client_id": "1007877315904-6l6lj4d93tf7btckjpjear0js45mvuj5.apps.googleusercontent.com",
"client_type": 3
}
],
"api_key": [
{
"current_key": "AIzaSyAfhNbEhHkmVYPQK200rJGxH9hc7qHlcwU"
}
],
"services": {
"appinvite_service": {
"other_platform_oauth_client": [
{
"client_id": "1007877315904-6l6lj4d93tf7btckjpjear0js45mvuj5.apps.googleusercontent.com",
"client_type": 3
}
]
}
}
},
{
"client_info": {
"mobilesdk_app_id": "1:1007877315904:android:c30eb760a5ffca750aeea5",
"android_client_info": {
"package_name": "org.communiquons.comunic"
}
},
"oauth_client": [
{
"client_id": "1007877315904-6l6lj4d93tf7btckjpjear0js45mvuj5.apps.googleusercontent.com",
"client_type": 3
}
],
"api_key": [
{
"current_key": "AIzaSyAfhNbEhHkmVYPQK200rJGxH9hc7qHlcwU"
}
],
"services": {
"appinvite_service": {
"other_platform_oauth_client": [
{
"client_id": "1007877315904-6l6lj4d93tf7btckjpjear0js45mvuj5.apps.googleusercontent.com",
"client_type": 3
}
]
}
}
}
],
"configuration_version": "1"
}

View File

@ -6,6 +6,9 @@ buildscript {
dependencies { dependencies {
classpath 'com.android.tools.build:gradle:3.5.4' classpath 'com.android.tools.build:gradle:3.5.4'
// Firebase
classpath 'com.google.gms:google-services:4.3.5'
} }
} }

View File

@ -5,16 +5,19 @@
// 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:firebase_core_web/firebase_core_web.dart';
import 'package:firebase_messaging_web/firebase_messaging_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);
FirebaseCoreWeb.registerWith(registrar);
FirebaseMessagingWeb.registerWith(registrar);
SharedPreferencesPlugin.registerWith(registrar); SharedPreferencesPlugin.registerWith(registrar);
UrlLauncherPlugin.registerWith(registrar); UrlLauncherPlugin.registerWith(registrar);
VideoPlayerPlugin.registerWith(registrar); VideoPlayerPlugin.registerWith(registrar);

View File

@ -0,0 +1,26 @@
import 'package:firebase_core/firebase_core.dart';
import 'package:firebase_messaging/firebase_messaging.dart';
/// Firebase messaging helper
///
/// @author Pierre Hubert
bool _isFirebaseReady = false;
class FirebaseMessagingHelper {
/// Pre configure notifications
static Future<void> preConfigure() async {
if (!_isFirebaseReady) await Firebase.initializeApp();
_isFirebaseReady = true;
final settings = await FirebaseMessaging.instance.requestPermission();
if (settings.authorizationStatus != AuthorizationStatus.authorized)
throw new Exception("The user did not authorize notifications!");
}
/// Get a Firebase access token
static Future<String> getToken() async {
return await FirebaseMessaging.instance.getToken();
}
}

View File

@ -1,3 +1,4 @@
import 'package:comunic/helpers/firebase_messaging_helper.dart';
import 'package:comunic/helpers/independent_push_notifications_helper.dart'; 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';
@ -111,13 +112,15 @@ class _PushNotificationsConfigurationRouteState
Future<void> _submit() async { Future<void> _submit() async {
try { try {
String firebaseToken = "";
switch (currStatus) { switch (currStatus) {
case PushNotificationsStatus.DISABLED: case PushNotificationsStatus.DISABLED:
break; break;
case PushNotificationsStatus.FIREBASE: case PushNotificationsStatus.FIREBASE:
// TODO: Handle this case. await FirebaseMessagingHelper.preConfigure();
throw new Exception("Firebase not supported yet!"); firebaseToken = await FirebaseMessagingHelper.getToken();
break; break;
case PushNotificationsStatus.INDEPENDENT: case PushNotificationsStatus.INDEPENDENT:
@ -130,7 +133,8 @@ class _PushNotificationsConfigurationRouteState
} }
await PushNotificationsHelper.clearLocalStatus(); await PushNotificationsHelper.clearLocalStatus();
await PushNotificationsHelper.setNewStatus(currStatus); await PushNotificationsHelper.setNewStatus(currStatus,
firebaseToken: firebaseToken);
await PushNotificationsHelper.refreshLocalStatus(); await PushNotificationsHelper.refreshLocalStatus();
Navigator.of(context).pop(); Navigator.of(context).pop();

View File

@ -190,6 +190,48 @@ packages:
url: "https://pub.dartlang.org" url: "https://pub.dartlang.org"
source: hosted source: hosted
version: "1.0.4" version: "1.0.4"
firebase_core:
dependency: "direct main"
description:
name: firebase_core
url: "https://pub.dartlang.org"
source: hosted
version: "1.0.1"
firebase_core_platform_interface:
dependency: transitive
description:
name: firebase_core_platform_interface
url: "https://pub.dartlang.org"
source: hosted
version: "4.0.0"
firebase_core_web:
dependency: transitive
description:
name: firebase_core_web
url: "https://pub.dartlang.org"
source: hosted
version: "1.0.1"
firebase_messaging:
dependency: "direct main"
description:
name: firebase_messaging
url: "https://pub.dartlang.org"
source: hosted
version: "9.0.0"
firebase_messaging_platform_interface:
dependency: transitive
description:
name: firebase_messaging_platform_interface
url: "https://pub.dartlang.org"
source: hosted
version: "2.0.0"
firebase_messaging_web:
dependency: transitive
description:
name: firebase_messaging_web
url: "https://pub.dartlang.org"
source: hosted
version: "1.0.1"
flutter: flutter:
dependency: "direct main" dependency: "direct main"
description: flutter description: flutter

View File

@ -126,6 +126,10 @@ dependencies:
# Image cropper # Image cropper
image_cropper: ^1.4.0 image_cropper: ^1.4.0
# Firebase cloud messaging (for push notifications)
firebase_core: ^1.0.1
firebase_messaging: ^9.0.0
dev_dependencies: dev_dependencies:
flutter_test: flutter_test:
sdk: flutter sdk: flutter