Skip to content

Commit 01534f5

Browse files
authored
refactor: code optimizations (#56)
1 parent 2ed3ab0 commit 01534f5

File tree

6 files changed

+22
-26
lines changed

6 files changed

+22
-26
lines changed
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
distributionBase=GRADLE_USER_HOME
2+
distributionPath=wrapper/dists
3+
distributionUrl=https\://services.gradle.org/distributions/gradle-7.4-bin.zip
4+
zipStoreBase=GRADLE_USER_HOME
5+
zipStorePath=wrapper/dists
Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,29 +1,39 @@
11
package io.customer.customer_io
22

33
import io.flutter.embedding.engine.plugins.FlutterPlugin
4+
import io.flutter.plugin.common.MethodChannel
45

56
/**
67
* Module class corresponds to modules concept in native SDKs. Any module added to native SDKs
78
* should be treated as module in Flutter SDK and should be used to hold all relevant methods at
89
* single place.
910
*/
10-
internal interface CustomerIOPluginModule {
11+
internal interface CustomerIOPluginModule : MethodChannel.MethodCallHandler {
1112
/**
1213
* Unique name of module to identify between other modules
1314
*/
1415
val moduleName: String
1516

17+
/**
18+
* Flutter communication channel to communicate with Native SDK
19+
*/
20+
val flutterCommunicationChannel: MethodChannel
21+
1622
/**
1723
* Called whenever root FlutterPlugin has been associated with a FlutterEngine instance.
1824
*
1925
* @see [FlutterPlugin.onAttachedToEngine] for more details
2026
*/
21-
fun onAttachedToEngine()
27+
fun onAttachedToEngine() {
28+
flutterCommunicationChannel.setMethodCallHandler(this)
29+
}
2230

2331
/**
2432
* Called whenever root FlutterPlugin has been removed from a FlutterEngine instance.
2533
*
2634
* @see [FlutterPlugin.onDetachedFromEngine] for more details
2735
*/
28-
fun onDetachedFromEngine()
36+
fun onDetachedFromEngine() {
37+
flutterCommunicationChannel.setMethodCallHandler(null)
38+
}
2939
}

android/src/main/kotlin/io/customer/customer_io/messaginginapp/CustomerIOInAppMessaging.kt

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -17,17 +17,9 @@ internal class CustomerIOInAppMessaging(
1717
pluginBinding: FlutterPlugin.FlutterPluginBinding,
1818
) : CustomerIOPluginModule, MethodChannel.MethodCallHandler {
1919
override val moduleName: String = "InAppMessaging"
20-
private val flutterCommunicationChannel: MethodChannel =
20+
override val flutterCommunicationChannel: MethodChannel =
2121
MethodChannel(pluginBinding.binaryMessenger, "customer_io_messaging_in_app")
2222

23-
override fun onAttachedToEngine() {
24-
flutterCommunicationChannel.setMethodCallHandler(this)
25-
}
26-
27-
override fun onDetachedFromEngine() {
28-
flutterCommunicationChannel.setMethodCallHandler(null)
29-
}
30-
3123
override fun onMethodCall(call: MethodCall, result: MethodChannel.Result) {
3224
when (call.method) {
3325
Keys.Methods.DISMISS_MESSAGE -> {

android/src/main/kotlin/io/customer/customer_io/messagingpush/CustomerIOPushMessaging.kt

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -23,19 +23,11 @@ internal class CustomerIOPushMessaging(
2323
) : CustomerIOPluginModule, MethodChannel.MethodCallHandler {
2424
override val moduleName: String = "PushMessaging"
2525
private val applicationContext: Context = pluginBinding.applicationContext
26-
private val flutterCommunicationChannel: MethodChannel =
26+
override val flutterCommunicationChannel: MethodChannel =
2727
MethodChannel(pluginBinding.binaryMessenger, "customer_io_messaging_push")
2828
private val logger: Logger
2929
get() = CustomerIOShared.instance().diStaticGraph.logger
3030

31-
override fun onAttachedToEngine() {
32-
flutterCommunicationChannel.setMethodCallHandler(this)
33-
}
34-
35-
override fun onDetachedFromEngine() {
36-
flutterCommunicationChannel.setMethodCallHandler(null)
37-
}
38-
3931
override fun onMethodCall(call: MethodCall, result: MethodChannel.Result) {
4032
when (call.method) {
4133
Keys.Methods.ON_MESSAGE_RECEIVED -> {

example/lib/main.dart

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,16 +6,14 @@ import 'package:customer_io/customer_io_enums.dart';
66
import 'package:customer_io/customer_io_inapp.dart';
77
import 'package:flutter/foundation.dart';
88
import 'package:flutter/material.dart';
9-
import 'package:flutter_dotenv/flutter_dotenv.dart';
109

1110
void main() async {
1211
WidgetsFlutterBinding.ensureInitialized();
1312

14-
await dotenv.load(fileName: "credentials.env");
1513
await CustomerIO.initialize(
1614
config: CustomerIOConfig(
17-
siteId: dotenv.get('siteId', fallback: 'YOUR_SITE_ID'),
18-
apiKey: dotenv.get('apiKey', fallback: 'YOUR_API_KEY'),
15+
siteId: "SITE_ID",
16+
apiKey: "API_KEY",
1917
logLevel: CioLogLevel.debug,
2018
enableInApp: true,
2119
autoTrackDeviceAttributes: true,

example/pubspec.yaml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@ environment:
1717
dependencies:
1818
flutter:
1919
sdk: flutter
20-
flutter_dotenv: ^5.0.2
2120

2221
customer_io:
2322
# When depending on this package from a real application you should use:

0 commit comments

Comments
 (0)