Rewrite the notification code in Kotlin

This commit is contained in:
2023-07-28 00:46:19 +02:00
parent 1771c0e1b6
commit 864b868f45
25 changed files with 318 additions and 129 deletions

View File

@@ -1,5 +1,6 @@
library moxplatform_platform_interface;
export 'src/api.g.dart';
export 'src/contacts.dart';
export 'src/contacts_stub.dart';
export 'src/crypto.dart';
@@ -7,9 +8,8 @@ export 'src/crypto_stub.dart';
export 'src/interface.dart';
export 'src/isolate.dart';
export 'src/isolate_stub.dart';
export 'src/media.dart';
export 'src/media_stub.dart';
export 'src/notifications.dart';
export 'src/notifications.g.dart';
export 'src/notifications_stub.dart';
export 'src/platform.dart';
export 'src/platform_stub.dart';
export 'src/service.dart';

View File

@@ -127,8 +127,8 @@ class MessagingNotification {
}
}
class _NotificationsImplementationApiCodec extends StandardMessageCodec {
const _NotificationsImplementationApiCodec();
class _MoxplatformApiCodec extends StandardMessageCodec {
const _MoxplatformApiCodec();
@override
void writeValue(WriteBuffer buffer, Object? value) {
if (value is MessagingNotification) {
@@ -160,19 +160,19 @@ class _NotificationsImplementationApiCodec extends StandardMessageCodec {
}
}
class NotificationsImplementationApi {
/// Constructor for [NotificationsImplementationApi]. The [binaryMessenger] named argument is
class MoxplatformApi {
/// Constructor for [MoxplatformApi]. The [binaryMessenger] named argument is
/// available for dependency injection. If it is left null, the default
/// BinaryMessenger will be used which routes to the host platform.
NotificationsImplementationApi({BinaryMessenger? binaryMessenger})
MoxplatformApi({BinaryMessenger? binaryMessenger})
: _binaryMessenger = binaryMessenger;
final BinaryMessenger? _binaryMessenger;
static const MessageCodec<Object?> codec = _NotificationsImplementationApiCodec();
static const MessageCodec<Object?> codec = _MoxplatformApiCodec();
Future<void> createNotificationChannel(String arg_title, String arg_id, bool arg_urgent) async {
final BasicMessageChannel<Object?> channel = BasicMessageChannel<Object?>(
'dev.flutter.pigeon.moxplatform_platform_interface.NotificationsImplementationApi.createNotificationChannel', codec,
'dev.flutter.pigeon.moxplatform_platform_interface.MoxplatformApi.createNotificationChannel', codec,
binaryMessenger: _binaryMessenger);
final List<Object?>? replyList =
await channel.send(<Object?>[arg_title, arg_id, arg_urgent]) as List<Object?>?;
@@ -194,7 +194,7 @@ class NotificationsImplementationApi {
Future<void> showMessagingNotification(MessagingNotification arg_notification) async {
final BasicMessageChannel<Object?> channel = BasicMessageChannel<Object?>(
'dev.flutter.pigeon.moxplatform_platform_interface.NotificationsImplementationApi.showMessagingNotification', codec,
'dev.flutter.pigeon.moxplatform_platform_interface.MoxplatformApi.showMessagingNotification', codec,
binaryMessenger: _binaryMessenger);
final List<Object?>? replyList =
await channel.send(<Object?>[arg_notification]) as List<Object?>?;
@@ -213,4 +213,58 @@ class NotificationsImplementationApi {
return;
}
}
Future<String> getPersistentDataPath() async {
final BasicMessageChannel<Object?> channel = BasicMessageChannel<Object?>(
'dev.flutter.pigeon.moxplatform_platform_interface.MoxplatformApi.getPersistentDataPath', codec,
binaryMessenger: _binaryMessenger);
final List<Object?>? replyList =
await channel.send(null) as List<Object?>?;
if (replyList == null) {
throw PlatformException(
code: 'channel-error',
message: 'Unable to establish connection on channel.',
);
} else if (replyList.length > 1) {
throw PlatformException(
code: replyList[0]! as String,
message: replyList[1] as String?,
details: replyList[2],
);
} else if (replyList[0] == null) {
throw PlatformException(
code: 'null-error',
message: 'Host platform returned null value for non-null return value.',
);
} else {
return (replyList[0] as String?)!;
}
}
Future<String> getCacheDataPath() async {
final BasicMessageChannel<Object?> channel = BasicMessageChannel<Object?>(
'dev.flutter.pigeon.moxplatform_platform_interface.MoxplatformApi.getCacheDataPath', codec,
binaryMessenger: _binaryMessenger);
final List<Object?>? replyList =
await channel.send(null) as List<Object?>?;
if (replyList == null) {
throw PlatformException(
code: 'channel-error',
message: 'Unable to establish connection on channel.',
);
} else if (replyList.length > 1) {
throw PlatformException(
code: replyList[0]! as String,
message: replyList[1] as String?,
details: replyList[2],
);
} else if (replyList[0] == null) {
throw PlatformException(
code: 'null-error',
message: 'Host platform returned null value for non-null return value.',
);
} else {
return (replyList[0] as String?)!;
}
}
}

View File

@@ -1,13 +1,14 @@
import 'package:moxplatform_platform_interface/src/api.g.dart';
import 'package:moxplatform_platform_interface/src/contacts.dart';
import 'package:moxplatform_platform_interface/src/contacts_stub.dart';
import 'package:moxplatform_platform_interface/src/crypto.dart';
import 'package:moxplatform_platform_interface/src/crypto_stub.dart';
import 'package:moxplatform_platform_interface/src/isolate.dart';
import 'package:moxplatform_platform_interface/src/isolate_stub.dart';
import 'package:moxplatform_platform_interface/src/media.dart';
import 'package:moxplatform_platform_interface/src/media_stub.dart';
import 'package:moxplatform_platform_interface/src/notifications.dart';
import 'package:moxplatform_platform_interface/src/notifications_stub.dart';
import 'package:moxplatform_platform_interface/src/platform.dart';
import 'package:moxplatform_platform_interface/src/platform_stub.dart';
import 'package:plugin_platform_interface/plugin_platform_interface.dart';
abstract class MoxplatformInterface extends PlatformInterface {
@@ -15,11 +16,13 @@ abstract class MoxplatformInterface extends PlatformInterface {
static final Object _token = Object();
static MoxplatformApi api = MoxplatformApi();
static IsolateHandler handler = StubIsolateHandler();
static MediaScannerImplementation media = StubMediaScannerImplementation();
static CryptographyImplementation crypto = StubCryptographyImplementation();
static ContactsImplementation contacts = StubContactsImplementation();
static NotificationsImplementation notifications = StubNotificationsImplementation();
static PlatformImplementation platform = StubPlatformImplementation();
/// Return the current platform name.
Future<String?> getPlatformName();

View File

@@ -1,6 +0,0 @@
/// Wrapper around platform-specific media scanning
// ignore: one_member_abstracts
abstract class MediaScannerImplementation {
/// Let the platform-specific media scanner scan the file at [path].
void scanFile(String path);
}

View File

@@ -1,6 +0,0 @@
import 'package:moxplatform_platform_interface/src/media.dart';
class StubMediaScannerImplementation extends MediaScannerImplementation {
@override
void scanFile(String path) {}
}

View File

@@ -1,4 +1,4 @@
import 'package:moxplatform_platform_interface/src/notifications.g.dart';
import 'package:moxplatform_platform_interface/src/api.g.dart';
abstract class NotificationsImplementation {
Future<void> createNotificationChannel(String title, String id, bool urgent);

View File

@@ -1,4 +1,4 @@
import 'package:moxplatform_platform_interface/src/notifications.g.dart';
import 'package:moxplatform_platform_interface/src/api.g.dart';
import 'package:moxplatform_platform_interface/src/notifications.dart';
class StubNotificationsImplementation extends NotificationsImplementation {

View File

@@ -0,0 +1,7 @@
abstract class PlatformImplementation {
/// Returns the path where persistent data should be stored.
Future<String> getPersistentDataPath();
/// Returns the path where cache data should be stored.
Future<String> getCacheDataPath();
}

View File

@@ -0,0 +1,9 @@
import 'package:moxplatform_platform_interface/src/platform.dart';
class StubPlatformImplementation extends PlatformImplementation {
/// Returns the path where persistent data should be stored.
Future<String> getPersistentDataPath() async => "";
/// Returns the path where cache data should be stored.
Future<String> getCacheDataPath() async => "";
}