-
Notifications
You must be signed in to change notification settings - Fork 11
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
chore: initialize native android sdk in flutter #159
Merged
mrehan27
merged 3 commits into
feature/data-pipelines-support
from
rehan/mbl-620-sdk-init-android
Nov 6, 2024
Merged
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -7,15 +7,13 @@ import androidx.annotation.NonNull | |
import io.customer.customer_io.constant.Keys | ||
import io.customer.customer_io.messaginginapp.CustomerIOInAppMessaging | ||
import io.customer.customer_io.messagingpush.CustomerIOPushMessaging | ||
import io.customer.messaginginapp.MessagingInAppModuleConfig | ||
import io.customer.messaginginapp.ModuleMessagingInApp | ||
import io.customer.messaginginapp.type.InAppEventListener | ||
import io.customer.messaginginapp.type.InAppMessage | ||
import io.customer.messagingpush.MessagingPushModuleConfig | ||
import io.customer.messagingpush.ModuleMessagingPushFCM | ||
import io.customer.messagingpush.config.PushClickBehavior | ||
import io.customer.sdk.CustomerIO | ||
import io.customer.sdk.CustomerIOBuilder | ||
import io.customer.sdk.core.di.SDKComponent | ||
import io.customer.sdk.core.util.CioLogLevel | ||
import io.customer.sdk.core.util.Logger | ||
import io.customer.sdk.data.model.Region | ||
import io.flutter.embedding.engine.plugins.FlutterPlugin | ||
|
@@ -239,57 +237,42 @@ class CustomerIoPlugin : FlutterPlugin, MethodCallHandler, ActivityAware { | |
*/ | ||
} | ||
|
||
private fun initialize(configData: Map<String, Any>) { | ||
// TODO: Fix initialize implementation | ||
/* | ||
private fun initialize(args: Map<String, Any>): kotlin.Result<Unit> = runCatching { | ||
val application: Application = context.applicationContext as Application | ||
val siteId = configData.getString(Keys.Environment.SITE_ID) | ||
val apiKey = configData.getString(Keys.Environment.API_KEY) | ||
val region = configData.getProperty<String>( | ||
Keys.Environment.REGION | ||
)?.takeIfNotBlank() | ||
val enableInApp = configData.getProperty<Boolean>( | ||
Keys.Environment.ENABLE_IN_APP | ||
) | ||
val cdpApiKey = requireNotNull(args.getAsTypeOrNull<String>("cdpApiKey")) { | ||
"CDP API Key is required to initialize Customer.io" | ||
} | ||
|
||
// Checks if SDK was initialized before, which means lifecycle callbacks are already | ||
// registered as well | ||
val isLifecycleCallbacksRegistered = kotlin.runCatching { CustomerIO.instance() }.isSuccess | ||
val logLevelRawValue = args.getAsTypeOrNull<String>("logLevel") | ||
val regionRawValue = args.getAsTypeOrNull<String>("region") | ||
val givenRegion = regionRawValue.let { Region.getRegion(it) } | ||
|
||
val customerIO = CustomerIO.Builder( | ||
siteId = siteId, | ||
apiKey = apiKey, | ||
region = Region.getRegion(region), | ||
appContext = application, | ||
config = configData | ||
CustomerIOBuilder( | ||
applicationContext = application, | ||
cdpApiKey = cdpApiKey | ||
).apply { | ||
addCustomerIOModule(module = configureModuleMessagingPushFCM(configData)) | ||
if (enableInApp == true) { | ||
addCustomerIOModule( | ||
module = ModuleMessagingInApp( | ||
config = MessagingInAppModuleConfig.Builder() | ||
.setEventListener(CustomerIOInAppEventListener { method, args -> | ||
[email protected]?.get()?.runOnUiThread { | ||
flutterCommunicationChannel.invokeMethod(method, args) | ||
} | ||
}).build(), | ||
) | ||
) | ||
} | ||
logLevelRawValue?.let { logLevel(CioLogLevel.getLogLevel(it)) } | ||
regionRawValue?.let { region(givenRegion) } | ||
|
||
args.getAsTypeOrNull<String>("migrationSiteId")?.let(::migrationSiteId) | ||
args.getAsTypeOrNull<Boolean>("autoTrackDeviceAttributes") | ||
?.let(::autoTrackDeviceAttributes) | ||
args.getAsTypeOrNull<Boolean>("trackApplicationLifecycleEvents") | ||
?.let(::trackApplicationLifecycleEvents) | ||
|
||
args.getAsTypeOrNull<Int>("flushAt")?.let(::flushAt) | ||
args.getAsTypeOrNull<Int>("flushInterval")?.let(::flushInterval) | ||
|
||
args.getAsTypeOrNull<String>("apiHost")?.let(::apiHost) | ||
args.getAsTypeOrNull<String>("cdnHost")?.let(::cdnHost) | ||
|
||
// TODO: Initialize in-app module with given config | ||
// TODO: Initialize push module with given config | ||
}.build() | ||
logger.info("Customer.io instance initialized successfully") | ||
|
||
// Request lifecycle events for first initialization only as relaunching app | ||
// in wrapper SDKs may result in reinitialization of SDK and lifecycle listener | ||
// will already be attached in this case as they are registered to application object. | ||
if (!isLifecycleCallbacksRegistered) { | ||
activity?.get()?.let { activity -> | ||
logger.info("Requesting delayed activity lifecycle events") | ||
val lifecycleCallbacks = customerIO.diGraph.activityLifecycleCallbacks | ||
lifecycleCallbacks.postDelayedEventsForNonNativeActivity(activity) | ||
} | ||
} | ||
*/ | ||
|
||
logger.info("Customer.io instance initialized successfully from app") | ||
}.onFailure { ex -> | ||
logger.error("Failed to initialize Customer.io instance from app, ${ex.message}") | ||
} | ||
|
||
private fun configureModuleMessagingPushFCM(config: Map<String, Any?>?): ModuleMessagingPushFCM { | ||
|
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
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I used hardcoded strings for keys instead because the constants aren't reused outside this function, so I felt they weren't adding much value. That said, I'm open to moving them back to constants if anyone thinks it would improve clarity or maintainability.