-
Notifications
You must be signed in to change notification settings - Fork 11
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
14 changed files
with
216 additions
and
45 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
45 changes: 45 additions & 0 deletions
45
android/src/main/kotlin/io/customer/customer_io/messaginginapp/CustomerIOInAppMessaging.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
package io.customer.customer_io.messaginginapp | ||
|
||
import io.customer.customer_io.CustomerIOPluginModule | ||
import io.customer.customer_io.constant.Keys | ||
import io.customer.customer_io.invokeNative | ||
import io.customer.messaginginapp.di.inAppMessaging | ||
import io.customer.sdk.CustomerIO | ||
import io.flutter.embedding.engine.plugins.FlutterPlugin | ||
import io.flutter.plugin.common.MethodCall | ||
import io.flutter.plugin.common.MethodChannel | ||
|
||
/** | ||
* Flutter module implementation for messaging in-app module in native SDKs. All functionality | ||
* linked with the module should be placed here. | ||
*/ | ||
internal class CustomerIOInAppMessaging( | ||
pluginBinding: FlutterPlugin.FlutterPluginBinding, | ||
) : CustomerIOPluginModule, MethodChannel.MethodCallHandler { | ||
override val moduleName: String = "InAppMessaging" | ||
private val flutterCommunicationChannel: MethodChannel = | ||
MethodChannel(pluginBinding.binaryMessenger, "customer_io_messaging_in_app") | ||
|
||
override fun onAttachedToEngine() { | ||
flutterCommunicationChannel.setMethodCallHandler(this) | ||
} | ||
|
||
override fun onDetachedFromEngine() { | ||
flutterCommunicationChannel.setMethodCallHandler(null) | ||
} | ||
|
||
override fun onMethodCall(call: MethodCall, result: MethodChannel.Result) { | ||
when (call.method) { | ||
Keys.Methods.DISMISS_MESSAGE -> { | ||
call.invokeNative(result) { | ||
CustomerIO.instance().inAppMessaging().dismissMessage() | ||
} | ||
} | ||
|
||
else -> { | ||
result.notImplemented() | ||
} | ||
} | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -46,6 +46,7 @@ internal class CustomerIOPushMessaging( | |
) | ||
} | ||
} | ||
|
||
else -> { | ||
result.notImplemented() | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
import Foundation | ||
import Flutter | ||
import CioMessagingInApp | ||
|
||
public class CusomterIOInAppMessaging: NSObject, FlutterPlugin { | ||
|
||
private var methodChannel: FlutterMethodChannel! | ||
|
||
public static func register(with registrar: FlutterPluginRegistrar) { | ||
} | ||
|
||
init(with registrar: FlutterPluginRegistrar) { | ||
super.init() | ||
|
||
methodChannel = FlutterMethodChannel(name: "customer_io_messaging_in_app", binaryMessenger: registrar.messenger()) | ||
registrar.addMethodCallDelegate(self, channel: methodChannel) | ||
} | ||
|
||
|
||
deinit { | ||
methodChannel.setMethodCallHandler(nil) | ||
} | ||
|
||
public func handle(_ call: FlutterMethodCall, result: @escaping FlutterResult) { | ||
// Handle method calls for this method channel | ||
switch(call.method) { | ||
case Keys.Methods.dismissMessage: | ||
MessagingInApp.shared.dismissMessage() | ||
default: | ||
result(FlutterMethodNotImplemented) | ||
} | ||
} | ||
|
||
func detachFromEngine() { | ||
methodChannel.setMethodCallHandler(nil) | ||
methodChannel = nil | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,2 @@ | ||
// Don't modify this line - it's automatically updated | ||
const version = "1.1.2"; | ||
const version = "1.2.0"; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
import 'package:flutter/foundation.dart'; | ||
import 'package:flutter/services.dart'; | ||
|
||
import '../customer_io_const.dart'; | ||
import 'platform_interface.dart'; | ||
|
||
/// An implementation of [CustomerIOMessagingInAppPlatform] that uses method | ||
/// channels. | ||
class CustomerIOMessagingInAppMethodChannel | ||
extends CustomerIOMessagingInAppPlatform { | ||
/// The method channel used to interact with the native platform. | ||
@visibleForTesting | ||
final methodChannel = const MethodChannel('customer_io_messaging_in_app'); | ||
|
||
@override | ||
void dismissMessage() async { | ||
try { | ||
methodChannel.invokeMethod(MethodConsts.dismissMessage); | ||
} on PlatformException catch (e) { | ||
handleException(e); | ||
} | ||
} | ||
|
||
void handleException(PlatformException exception) { | ||
if (kDebugMode) { | ||
print(exception); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
import 'package:plugin_platform_interface/plugin_platform_interface.dart'; | ||
|
||
import 'method_channel.dart'; | ||
|
||
/// The default instance of [CustomerIOMessagingInAppPlatform] to use | ||
/// | ||
/// Platform-specific plugins should override this with their own | ||
/// platform-specific class that extends [CustomerIOMessagingInAppPlatform] | ||
/// when they register themselves. | ||
/// | ||
/// Defaults to [CustomerIOMessagingInAppMethodChannel] | ||
abstract class CustomerIOMessagingInAppPlatform extends PlatformInterface { | ||
CustomerIOMessagingInAppPlatform() : super(token: _token); | ||
|
||
static final Object _token = Object(); | ||
|
||
static CustomerIOMessagingInAppPlatform _instance = | ||
CustomerIOMessagingInAppMethodChannel(); | ||
|
||
static CustomerIOMessagingInAppPlatform get instance => _instance; | ||
|
||
static set instance(CustomerIOMessagingInAppPlatform instance) { | ||
PlatformInterface.verifyToken(instance, _token); | ||
_instance = instance; | ||
} | ||
|
||
void dismissMessage() { | ||
throw UnimplementedError('dismissMessage() has not been implemented.'); | ||
} | ||
} |