Skip to content

Commit

Permalink
added support for unity
Browse files Browse the repository at this point in the history
  • Loading branch information
mrehan27 committed Sep 20, 2023
1 parent a317698 commit 6d35e77
Show file tree
Hide file tree
Showing 8 changed files with 43 additions and 1 deletion.
2 changes: 2 additions & 0 deletions messaginginapp/api/messaginginapp.api
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,11 @@ public final class io/customer/messaginginapp/ModuleMessagingInApp : io/customer
public synthetic fun getModuleConfig ()Lio/customer/sdk/module/CustomerIOModuleConfig;
public fun getModuleName ()Ljava/lang/String;
public fun initialize ()V
public static final fun unityInstance ()Lio/customer/messaginginapp/ModuleMessagingInApp;
}

public final class io/customer/messaginginapp/ModuleMessagingInApp$Companion {
public final fun unityInstance ()Lio/customer/messaginginapp/ModuleMessagingInApp;
}

public final class io/customer/messaginginapp/databinding/ActivityGistBinding : androidx/viewbinding/ViewBinding {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,9 @@ internal constructor(

companion object {
const val moduleName: String = "MessagingInApp"

@JvmStatic
fun unityInstance() = ModuleMessagingInApp()
}

fun dismissMessage() {
Expand Down
2 changes: 2 additions & 0 deletions messagingpush/api/messagingpush.api
Original file line number Diff line number Diff line change
Expand Up @@ -53,9 +53,11 @@ public final class io/customer/messagingpush/ModuleMessagingPushFCM : io/custome
public synthetic fun getModuleConfig ()Lio/customer/sdk/module/CustomerIOModuleConfig;
public fun getModuleName ()Ljava/lang/String;
public fun initialize ()V
public static final fun unityInstance ()Lio/customer/messagingpush/ModuleMessagingPushFCM;
}

public final class io/customer/messagingpush/ModuleMessagingPushFCM$Companion {
public final fun unityInstance ()Lio/customer/messagingpush/ModuleMessagingPushFCM;
}

public abstract interface class io/customer/messagingpush/data/communication/CustomerIOPushNotificationCallback {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import android.content.BroadcastReceiver
import android.content.Context
import android.content.Intent
import com.google.android.gms.cloudmessaging.CloudMessagingReceiver
import com.google.firebase.messaging.RemoteMessage
import io.customer.messagingpush.di.pushMessageProcessor
import io.customer.messagingpush.extensions.getSDKInstanceOrNull
import io.customer.messagingpush.processor.PushMessageProcessor
Expand All @@ -30,5 +31,7 @@ class CustomerIOCloudMessagingReceiver : BroadcastReceiver() {
val sdkInstance = context.getSDKInstanceOrNull() ?: return

sdkInstance.diGraph.pushMessageProcessor.processGCMMessageIntent(intent = intent)

CustomerIOFirebaseMessagingService.onMessageReceived(context, RemoteMessage(intent.extras))
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -62,5 +62,8 @@ internal constructor(

companion object {
internal const val MODULE_NAME = "MessagingPushFCM"

@JvmStatic
fun unityInstance() = ModuleMessagingPushFCM()
}
}
5 changes: 5 additions & 0 deletions sdk/api/sdk.api
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@ public final class io/customer/sdk/CustomerIO : io/customer/sdk/CustomerIOInstan
public fun track (Ljava/lang/String;)V
public fun track (Ljava/lang/String;Ljava/util/Map;)V
public fun trackMetric (Ljava/lang/String;Lio/customer/sdk/data/request/MetricEvent;Ljava/lang/String;)V
public static final fun unityInstance (Landroid/content/Context;Ljava/lang/String;Ljava/lang/String;)Lio/customer/sdk/CustomerIO;
public static final fun unityInstance (Landroid/content/Context;Ljava/lang/String;Ljava/lang/String;Ljava/util/List;)Lio/customer/sdk/CustomerIO;
}

public final class io/customer/sdk/CustomerIO$Builder {
Expand All @@ -46,6 +48,9 @@ public final class io/customer/sdk/CustomerIO$Builder {

public final class io/customer/sdk/CustomerIO$Companion {
public final fun instance ()Lio/customer/sdk/CustomerIO;
public final fun unityInstance (Landroid/content/Context;Ljava/lang/String;Ljava/lang/String;)Lio/customer/sdk/CustomerIO;
public final fun unityInstance (Landroid/content/Context;Ljava/lang/String;Ljava/lang/String;Ljava/util/List;)Lio/customer/sdk/CustomerIO;
public static synthetic fun unityInstance$default (Lio/customer/sdk/CustomerIO$Companion;Landroid/content/Context;Ljava/lang/String;Ljava/lang/String;Ljava/util/List;ILjava/lang/Object;)Lio/customer/sdk/CustomerIO;
}

public final class io/customer/sdk/CustomerIOActivityLifecycleCallbacks : android/app/Application$ActivityLifecycleCallbacks {
Expand Down
24 changes: 24 additions & 0 deletions sdk/src/main/java/io/customer/sdk/CustomerIO.kt
Original file line number Diff line number Diff line change
Expand Up @@ -176,6 +176,29 @@ class CustomerIO internal constructor(
return instance
?: throw IllegalStateException("CustomerIO.Builder::build() must be called before obtaining CustomerIO instance")
}

@JvmStatic
@JvmOverloads
fun unityInstance(
context: Context,
siteId: String,
apiKey: String,
modules: List<CustomerIOModule<*>> = emptyList()
): CustomerIO {
return try {
instance()
} catch (ex: Exception) {
Builder(
siteId = siteId,
apiKey = apiKey,
appContext = context.applicationContext as Application
).apply {
for (module in modules) {
addCustomerIOModule(module)
}
}.build()
}
}
}

class Builder @JvmOverloads constructor(
Expand Down Expand Up @@ -371,6 +394,7 @@ class CustomerIO internal constructor(

client.postInitialize()

diGraph.logger.debug("[DEV] CustomerIO build with siteId: $siteId, apiKey: $apiKey, modules: ${modules.size}")
return client
}
}
Expand Down
2 changes: 1 addition & 1 deletion sdk/src/main/java/io/customer/sdk/CustomerIOConfig.kt
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ data class CustomerIOConfig(
* SDK constants to avoid repetitive configuration values
*/
object SDKConstants {
val LOG_LEVEL_DEFAULT = CioLogLevel.ERROR
val LOG_LEVEL_DEFAULT = CioLogLevel.DEBUG
}

/**
Expand Down

0 comments on commit 6d35e77

Please sign in to comment.