Basic stuff

This commit is contained in:
2023-07-27 20:45:09 +02:00
parent 17642f9fab
commit 1771c0e1b6
26 changed files with 1100 additions and 16 deletions

View File

@@ -9,4 +9,7 @@ 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/service.dart';

View File

@@ -6,6 +6,8 @@ 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:plugin_platform_interface/plugin_platform_interface.dart';
abstract class MoxplatformInterface extends PlatformInterface {
@@ -17,6 +19,7 @@ abstract class MoxplatformInterface extends PlatformInterface {
static MediaScannerImplementation media = StubMediaScannerImplementation();
static CryptographyImplementation crypto = StubCryptographyImplementation();
static ContactsImplementation contacts = StubContactsImplementation();
static NotificationsImplementation notifications = StubNotificationsImplementation();
/// Return the current platform name.
Future<String?> getPlatformName();

View File

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

View File

@@ -0,0 +1,216 @@
// Autogenerated from Pigeon (v10.1.4), do not edit directly.
// See also: https://pub.dev/packages/pigeon
// ignore_for_file: public_member_api_docs, non_constant_identifier_names, avoid_as, unused_import, unnecessary_parenthesis, prefer_null_aware_operators, omit_local_variable_types, unused_shown_name, unnecessary_import
import 'dart:async';
import 'dart:typed_data' show Float64List, Int32List, Int64List, Uint8List;
import 'package:flutter/foundation.dart' show ReadBuffer, WriteBuffer;
import 'package:flutter/services.dart';
class NotificationMessageContent {
NotificationMessageContent({
this.body,
this.mime,
this.path,
});
/// The textual body of the message.
String? body;
/// The path and mime type of the media to show.
String? mime;
String? path;
Object encode() {
return <Object?>[
body,
mime,
path,
];
}
static NotificationMessageContent decode(Object result) {
result as List<Object?>;
return NotificationMessageContent(
body: result[0] as String?,
mime: result[1] as String?,
path: result[2] as String?,
);
}
}
class NotificationMessage {
NotificationMessage({
required this.sender,
required this.jid,
required this.content,
required this.timestamp,
this.avatarPath,
});
/// The sender of the message.
String sender;
/// The jid of the sender.
String jid;
/// The body of the message.
NotificationMessageContent content;
/// Milliseconds since epoch.
int timestamp;
/// The path to the avatar to use
String? avatarPath;
Object encode() {
return <Object?>[
sender,
jid,
content.encode(),
timestamp,
avatarPath,
];
}
static NotificationMessage decode(Object result) {
result as List<Object?>;
return NotificationMessage(
sender: result[0]! as String,
jid: result[1]! as String,
content: NotificationMessageContent.decode(result[2]! as List<Object?>),
timestamp: result[3]! as int,
avatarPath: result[4] as String?,
);
}
}
class MessagingNotification {
MessagingNotification({
required this.title,
required this.id,
required this.channelId,
required this.messages,
});
/// The title of the conversation.
String title;
/// The id of the notification.
int id;
/// The id of the notification channel the notification should appear on.
String channelId;
/// Messages to show.
List<NotificationMessage?> messages;
Object encode() {
return <Object?>[
title,
id,
channelId,
messages,
];
}
static MessagingNotification decode(Object result) {
result as List<Object?>;
return MessagingNotification(
title: result[0]! as String,
id: result[1]! as int,
channelId: result[2]! as String,
messages: (result[3] as List<Object?>?)!.cast<NotificationMessage?>(),
);
}
}
class _NotificationsImplementationApiCodec extends StandardMessageCodec {
const _NotificationsImplementationApiCodec();
@override
void writeValue(WriteBuffer buffer, Object? value) {
if (value is MessagingNotification) {
buffer.putUint8(128);
writeValue(buffer, value.encode());
} else if (value is NotificationMessage) {
buffer.putUint8(129);
writeValue(buffer, value.encode());
} else if (value is NotificationMessageContent) {
buffer.putUint8(130);
writeValue(buffer, value.encode());
} else {
super.writeValue(buffer, value);
}
}
@override
Object? readValueOfType(int type, ReadBuffer buffer) {
switch (type) {
case 128:
return MessagingNotification.decode(readValue(buffer)!);
case 129:
return NotificationMessage.decode(readValue(buffer)!);
case 130:
return NotificationMessageContent.decode(readValue(buffer)!);
default:
return super.readValueOfType(type, buffer);
}
}
}
class NotificationsImplementationApi {
/// Constructor for [NotificationsImplementationApi]. 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})
: _binaryMessenger = binaryMessenger;
final BinaryMessenger? _binaryMessenger;
static const MessageCodec<Object?> codec = _NotificationsImplementationApiCodec();
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,
binaryMessenger: _binaryMessenger);
final List<Object?>? replyList =
await channel.send(<Object?>[arg_title, arg_id, arg_urgent]) 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 {
return;
}
}
Future<void> showMessagingNotification(MessagingNotification arg_notification) async {
final BasicMessageChannel<Object?> channel = BasicMessageChannel<Object?>(
'dev.flutter.pigeon.moxplatform_platform_interface.NotificationsImplementationApi.showMessagingNotification', codec,
binaryMessenger: _binaryMessenger);
final List<Object?>? replyList =
await channel.send(<Object?>[arg_notification]) 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 {
return;
}
}
}

View File

@@ -0,0 +1,10 @@
import 'package:moxplatform_platform_interface/src/notifications.g.dart';
import 'package:moxplatform_platform_interface/src/notifications.dart';
class StubNotificationsImplementation extends NotificationsImplementation {
@override
Future<void> createNotificationChannel(String title, String id, bool urgent) async {}
@override
Future<void> showMessagingNotification(MessagingNotification notification) async {}
}