From 8b5a5b4fb817313b1edbdedd5edbc4abd5fea173 Mon Sep 17 00:00:00 2001 From: S1m Date: Tue, 5 Apr 2022 05:49:28 +0000 Subject: [PATCH] chore: Upgrade unifiedpush to 4.0.0 --- android/app/build.gradle | 1 - android/app/src/main/AndroidManifest.xml | 16 +++++---- .../chat/fluffy/fluffychat/MainActivity.kt | 9 +---- .../fluffy/fluffychat/UnifiedPushService.kt | 33 ++++++------------- lib/utils/background_push.dart | 20 +++++------ pubspec.yaml | 2 +- 6 files changed, 32 insertions(+), 49 deletions(-) diff --git a/android/app/build.gradle b/android/app/build.gradle index 3fe911a0..ad9ffb87 100644 --- a/android/app/build.gradle +++ b/android/app/build.gradle @@ -86,7 +86,6 @@ dependencies { testImplementation 'junit:junit:4.12' androidTestImplementation 'androidx.test:runner:1.1.1' androidTestImplementation 'androidx.test.espresso:espresso-core:3.1.1' - implementation 'com.github.UnifiedPush:android-connector:1.2.3' // needed for unifiedpush implementation 'androidx.multidex:multidex:2.0.1' } diff --git a/android/app/src/main/AndroidManifest.xml b/android/app/src/main/AndroidManifest.xml index fe8afab8..e219194d 100644 --- a/android/app/src/main/AndroidManifest.xml +++ b/android/app/src/main/AndroidManifest.xml @@ -110,13 +110,17 @@ - + + + + - - - - - + + + + diff --git a/android/app/src/main/kotlin/chat/fluffy/fluffychat/MainActivity.kt b/android/app/src/main/kotlin/chat/fluffy/fluffychat/MainActivity.kt index a181acae..894d1571 100644 --- a/android/app/src/main/kotlin/chat/fluffy/fluffychat/MainActivity.kt +++ b/android/app/src/main/kotlin/chat/fluffy/fluffychat/MainActivity.kt @@ -4,9 +4,6 @@ import io.flutter.embedding.android.FlutterActivity import io.flutter.embedding.engine.FlutterEngine import android.content.Context -import android.os.Bundle -import android.util.Log -import android.view.WindowManager import androidx.multidex.MultiDex class MainActivity : FlutterActivity() { @@ -15,10 +12,6 @@ class MainActivity : FlutterActivity() { MultiDex.install(this) } - override fun onCreate(savedInstanceState: Bundle?) { - super.onCreate(savedInstanceState) - }; - override fun provideFlutterEngine(context: Context): FlutterEngine? { return provideEngine(this) } @@ -30,7 +23,7 @@ class MainActivity : FlutterActivity() { companion object { var engine: FlutterEngine? = null fun provideEngine(context: Context): FlutterEngine { - var eng = engine ?: FlutterEngine(context, emptyArray(), true, false) + val eng = engine ?: FlutterEngine(context, emptyArray(), true, false) engine = eng return eng } diff --git a/android/app/src/main/kotlin/chat/fluffy/fluffychat/UnifiedPushService.kt b/android/app/src/main/kotlin/chat/fluffy/fluffychat/UnifiedPushService.kt index 02304cb1..c5d4ba9d 100644 --- a/android/app/src/main/kotlin/chat/fluffy/fluffychat/UnifiedPushService.kt +++ b/android/app/src/main/kotlin/chat/fluffy/fluffychat/UnifiedPushService.kt @@ -1,36 +1,23 @@ package chat.fluffy.fluffychat -import org.unifiedpush.flutter.connector.UnifiedPushHandler - -import chat.fluffy.fluffychat.MainActivity - -import io.flutter.embedding.android.FlutterActivity import io.flutter.embedding.engine.FlutterEngine -import io.flutter.view.FlutterMain -import io.flutter.embedding.engine.dart.DartExecutor.DartEntrypoint -import org.unifiedpush.android.connector.MessagingReceiver +import io.flutter.embedding.engine.dart.DartExecutor +import org.unifiedpush.flutter.connector.UnifiedPushReceiver import android.content.Context -import android.os.Bundle -import android.util.Log -import android.view.WindowManager -val receiverHandler = object : UnifiedPushHandler() { +class UnifiedPushReceiver : UnifiedPushReceiver() { override fun getEngine(context: Context): FlutterEngine { - return provideEngine(context) - } - - fun provideEngine(context: Context): FlutterEngine { var engine = MainActivity.engine if (engine == null) { engine = MainActivity.provideEngine(context) - engine.getLocalizationPlugin().sendLocalesToFlutter( - context.getResources().getConfiguration()) - engine.getDartExecutor().executeDartEntrypoint( - DartEntrypoint.createDefault()) + engine.localizationPlugin.sendLocalesToFlutter( + context.resources.configuration + ) + engine.dartExecutor.executeDartEntrypoint( + DartExecutor.DartEntrypoint.createDefault() + ) } return engine } -} - -class UnifiedPushReceiver : MessagingReceiver(receiverHandler) +} \ No newline at end of file diff --git a/lib/utils/background_push.dart b/lib/utils/background_push.dart index 0e465896..f9a937e1 100644 --- a/lib/utils/background_push.dart +++ b/lib/utils/background_push.dart @@ -20,6 +20,7 @@ import 'dart:async'; import 'dart:convert'; import 'dart:io'; +import 'dart:typed_data'; import 'dart:ui'; import 'package:flutter/material.dart'; @@ -29,7 +30,7 @@ import 'package:flutter_gen/gen_l10n/l10n.dart'; import 'package:flutter_local_notifications/flutter_local_notifications.dart'; import 'package:http/http.dart' as http; import 'package:matrix/matrix.dart'; -import 'package:unifiedpush/unifiedpush.dart' hide Message; +import 'package:unifiedpush/unifiedpush.dart'; import 'package:vrouter/vrouter.dart'; import 'package:fluffychat/utils/matrix_sdk_extensions.dart/client_stories_extension.dart'; @@ -80,10 +81,9 @@ class BackgroundPush { onNewToken: _newFcmToken, ); if (Platform.isAndroid) { - UnifiedPush.initializeWithReceiver( + UnifiedPush.initialize( onNewEndpoint: _newUpEndpoint, onRegistrationFailed: _upUnregistered, - onRegistrationRefused: _upUnregistered, onUnregistered: _upUnregistered, onMessage: _onUpMessage, ); @@ -329,7 +329,7 @@ class BackgroundPush { } Future setupUp() async { - await UnifiedPush.registerAppWithDialog(); + await UnifiedPush.registerAppWithDialog(context!); } Future _onFcmMessage(Map message) async { @@ -343,10 +343,10 @@ class BackgroundPush { } } - Future _newUpEndpoint(String newEndpoint) async { + Future _newUpEndpoint(String newEndpoint, String i) async { upAction = true; if (newEndpoint.isEmpty) { - await _upUnregistered(); + await _upUnregistered(i); return; } var endpoint = @@ -387,7 +387,7 @@ class BackgroundPush { await store.setItemBool(SettingKeys.unifiedPushRegistered, true); } - Future _upUnregistered() async { + Future _upUnregistered(String i) async { upAction = true; Logs().i('[Push] Removing UnifiedPush endpoint...'); final oldEndpoint = await store.getItem(SettingKeys.unifiedPushEndpoint); @@ -401,10 +401,10 @@ class BackgroundPush { } } - Future _onUpMessage(String message) async { + Future _onUpMessage(Uint8List message, String i) async { upAction = true; - final data = - Map.from(json.decode(message)['notification']); + final data = Map.from( + json.decode(utf8.decode(message))['notification']); try { await _onMessage(data); } catch (e, s) { diff --git a/pubspec.yaml b/pubspec.yaml index 776b1d52..6a0148ac 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -79,7 +79,7 @@ dependencies: slugify: ^2.0.0 swipe_to_action: ^0.2.0 uni_links: ^0.5.1 - unifiedpush: ^3.0.1 + unifiedpush: ^4.0.0 universal_html: ^2.0.8 url_launcher: ^6.0.20 video_compress: ^3.1.0