switch from timestamps to event sequence for events
This commit is contained in:
+4
-2
@@ -22,11 +22,13 @@ package eu.weblibre.simple_intent_receiver
|
||||
import io.flutter.plugin.common.BinaryMessenger
|
||||
import eu.weblibre.simple_intent_receiver.pigeons.IntentEvents
|
||||
import eu.weblibre.simple_intent_receiver.pigeons.Intent as PigeonIntent
|
||||
import eu.weblibre.flutter_mozilla_components.ext.EventSequence
|
||||
|
||||
class IntentReceiver(messenger: BinaryMessenger) {
|
||||
private val intentEvents: IntentEvents = IntentEvents(messenger)
|
||||
|
||||
fun sendIntent(timestamp: Long, intent: PigeonIntent) {
|
||||
intentEvents.onIntentReceived(timestamp, intent) { }
|
||||
fun sendIntent(intent: PigeonIntent) {
|
||||
intentEvents.onIntentReceived(EventSequence.next(), intent) { }
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
+1
-1
@@ -114,7 +114,7 @@ class SimpleIntentReceiverPlugin: FlutterPlugin, ActivityAware, PluginRegistry.N
|
||||
}
|
||||
|
||||
val pigeonIntent = convertToPigeonIntent(intent)
|
||||
intentReceiver?.sendIntent(System.currentTimeMillis(), pigeonIntent)
|
||||
intentReceiver?.sendIntent(pigeonIntent)
|
||||
return true
|
||||
}
|
||||
|
||||
|
||||
+2
-2
@@ -133,12 +133,12 @@ class IntentEvents(private val binaryMessenger: BinaryMessenger, private val mes
|
||||
IntentPigeonCodec()
|
||||
}
|
||||
}
|
||||
fun onIntentReceived(timestampArg: Long, intentArg: Intent, callback: (Result<Unit>) -> Unit)
|
||||
fun onIntentReceived(sequenceArg: Long, intentArg: Intent, callback: (Result<Unit>) -> Unit)
|
||||
{
|
||||
val separatedMessageChannelSuffix = if (messageChannelSuffix.isNotEmpty()) ".$messageChannelSuffix" else ""
|
||||
val channelName = "dev.flutter.pigeon.simple_intent_receiver.IntentEvents.onIntentReceived$separatedMessageChannelSuffix"
|
||||
val channel = BasicMessageChannel<Any?>(binaryMessenger, channelName, codec)
|
||||
channel.send(listOf(timestampArg, intentArg)) {
|
||||
channel.send(listOf(sequenceArg, intentArg)) {
|
||||
if (it is List<*>) {
|
||||
if (it.size > 1) {
|
||||
callback(Result.failure(FlutterError(it[0] as String, it[1] as String, it[2] as String?)))
|
||||
|
||||
@@ -29,8 +29,8 @@ class IntentReceiver extends IntentEvents {
|
||||
Stream<Intent> get events => _controller.stream;
|
||||
|
||||
@override
|
||||
void onIntentReceived(int timestamp, Intent intent) {
|
||||
if (_lastAdded == null || timestamp > _lastAdded!) {
|
||||
void onIntentReceived(int sequence, Intent intent) {
|
||||
if (_lastAdded == null || sequence > _lastAdded!) {
|
||||
_controller.add(intent);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -128,7 +128,7 @@ class _PigeonCodec extends StandardMessageCodec {
|
||||
abstract class IntentEvents {
|
||||
static const MessageCodec<Object?> pigeonChannelCodec = _PigeonCodec();
|
||||
|
||||
void onIntentReceived(int timestamp, Intent intent);
|
||||
void onIntentReceived(int sequence, Intent intent);
|
||||
|
||||
static void setUp(IntentEvents? api, {BinaryMessenger? binaryMessenger, String messageChannelSuffix = '',}) {
|
||||
messageChannelSuffix = messageChannelSuffix.isNotEmpty ? '.$messageChannelSuffix' : '';
|
||||
@@ -143,14 +143,14 @@ abstract class IntentEvents {
|
||||
assert(message != null,
|
||||
'Argument for dev.flutter.pigeon.simple_intent_receiver.IntentEvents.onIntentReceived was null.');
|
||||
final List<Object?> args = (message as List<Object?>?)!;
|
||||
final int? arg_timestamp = (args[0] as int?);
|
||||
assert(arg_timestamp != null,
|
||||
final int? arg_sequence = (args[0] as int?);
|
||||
assert(arg_sequence != null,
|
||||
'Argument for dev.flutter.pigeon.simple_intent_receiver.IntentEvents.onIntentReceived was null, expected non-null int.');
|
||||
final Intent? arg_intent = (args[1] as Intent?);
|
||||
assert(arg_intent != null,
|
||||
'Argument for dev.flutter.pigeon.simple_intent_receiver.IntentEvents.onIntentReceived was null, expected non-null Intent.');
|
||||
try {
|
||||
api.onIntentReceived(arg_timestamp!, arg_intent!);
|
||||
api.onIntentReceived(arg_sequence!, arg_intent!);
|
||||
return wrapResponse(empty: true);
|
||||
} on PlatformException catch (e) {
|
||||
return wrapResponse(error: e);
|
||||
|
||||
@@ -51,5 +51,5 @@ class Intent {
|
||||
)
|
||||
@FlutterApi()
|
||||
abstract class IntentEvents {
|
||||
void onIntentReceived(int timestamp, Intent intent);
|
||||
void onIntentReceived(int sequence, Intent intent);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user