From d2dd2d83f9e4bc77bc038f786a77984f6c70d744 Mon Sep 17 00:00:00 2001 From: markvdouw Date: Mon, 27 Feb 2023 12:19:06 -0300 Subject: [PATCH 1/9] Adding modernization interfaces --- .../com/mparticle/modernization/MParticle.kt | 26 +++++++++++ .../modernization/MParticleCallback.kt | 18 ++++++++ .../modernization/MParticleComponent.kt | 4 ++ .../modernization/MParticleMediator.kt | 36 +++++++++++++++ .../java/com/mparticle/modernization/Test.kt | 8 ++++ .../data_uploader/MParticleDataUploading.kt | 8 ++++ .../MParticleFakeDataUploadingImpl.kt | 4 ++ .../event_logging/MParticleEventLogging.kt | 14 ++++++ .../MParticleFakeEventLoggingImpl.kt | 40 +++++++++++++++++ .../identity/IdentityCallback.kt | 6 +++ .../identity/MParticleFakeIdentityImpl.kt | 44 +++++++++++++++++++ .../identity/MParticleIdentity.kt | 23 ++++++++++ .../modernization/kit/MParticleKit.kt | 14 ++++++ .../modernization/kit/MParticleKitManager.kt | 6 +++ .../kit/MParticleKitManagerImpl.kt | 38 ++++++++++++++++ .../com/mparticle/modernization/kit/MpKit.kt | 35 +++++++++++++++ .../com/mparticle/modernization/kit/XKit.kt | 35 +++++++++++++++ build.gradle | 2 +- 18 files changed, 360 insertions(+), 1 deletion(-) create mode 100644 android-core/src/main/java/com/mparticle/modernization/MParticle.kt create mode 100644 android-core/src/main/java/com/mparticle/modernization/MParticleCallback.kt create mode 100644 android-core/src/main/java/com/mparticle/modernization/MParticleComponent.kt create mode 100644 android-core/src/main/java/com/mparticle/modernization/MParticleMediator.kt create mode 100644 android-core/src/main/java/com/mparticle/modernization/Test.kt create mode 100644 android-core/src/main/java/com/mparticle/modernization/data_uploader/MParticleDataUploading.kt create mode 100644 android-core/src/main/java/com/mparticle/modernization/data_uploader/MParticleFakeDataUploadingImpl.kt create mode 100644 android-core/src/main/java/com/mparticle/modernization/event_logging/MParticleEventLogging.kt create mode 100644 android-core/src/main/java/com/mparticle/modernization/event_logging/MParticleFakeEventLoggingImpl.kt create mode 100644 android-core/src/main/java/com/mparticle/modernization/identity/IdentityCallback.kt create mode 100644 android-core/src/main/java/com/mparticle/modernization/identity/MParticleFakeIdentityImpl.kt create mode 100644 android-core/src/main/java/com/mparticle/modernization/identity/MParticleIdentity.kt create mode 100644 android-core/src/main/java/com/mparticle/modernization/kit/MParticleKit.kt create mode 100644 android-core/src/main/java/com/mparticle/modernization/kit/MParticleKitManager.kt create mode 100644 android-core/src/main/java/com/mparticle/modernization/kit/MParticleKitManagerImpl.kt create mode 100644 android-core/src/main/java/com/mparticle/modernization/kit/MpKit.kt create mode 100644 android-core/src/main/java/com/mparticle/modernization/kit/XKit.kt diff --git a/android-core/src/main/java/com/mparticle/modernization/MParticle.kt b/android-core/src/main/java/com/mparticle/modernization/MParticle.kt new file mode 100644 index 000000000..67a6720ed --- /dev/null +++ b/android-core/src/main/java/com/mparticle/modernization/MParticle.kt @@ -0,0 +1,26 @@ +package com.mparticle.modernization + +import com.mparticle.MParticleOptions +import com.mparticle.internal.KitManager +import com.mparticle.modernization.event_logging.MParticleEventLogging + +class MParticle private constructor(private val options: MParticleOptions) { + private var mediator: MParticleMediator = MParticleMediator() + + init { + mediator.configure(options) + } + + companion object { + private var _instance: MParticle? = null + fun getInstance(): MParticle? = _instance + + fun start(options: MParticleOptions) { + _instance = MParticle(options) + } + } + + fun KitManager(): KitManager? = mediator.kitManager as KitManager? + fun Identity(): MParticleIdentity? = mediator.identity as MParticleIdentity? + fun EventLogging(): MParticleEventLogging? = mediator.eventLogging +} \ No newline at end of file diff --git a/android-core/src/main/java/com/mparticle/modernization/MParticleCallback.kt b/android-core/src/main/java/com/mparticle/modernization/MParticleCallback.kt new file mode 100644 index 000000000..9e61274bb --- /dev/null +++ b/android-core/src/main/java/com/mparticle/modernization/MParticleCallback.kt @@ -0,0 +1,18 @@ +package com.mparticle.modernization + +import com.mparticle.identity.IdentityApiResult + +abstract class MParticleCallback { + var isSuccessFul : Boolean = false + var isCompleted : Boolean = false + + fun onSuccess(result : S) { + isSuccessFul = true + isCompleted = true + } + + fun onError(error : E){ + isSuccessFul = false + isCompleted = true + } +} diff --git a/android-core/src/main/java/com/mparticle/modernization/MParticleComponent.kt b/android-core/src/main/java/com/mparticle/modernization/MParticleComponent.kt new file mode 100644 index 000000000..01b1f77fc --- /dev/null +++ b/android-core/src/main/java/com/mparticle/modernization/MParticleComponent.kt @@ -0,0 +1,4 @@ +package com.mparticle.modernization + +interface MParticleComponent { +} \ No newline at end of file diff --git a/android-core/src/main/java/com/mparticle/modernization/MParticleMediator.kt b/android-core/src/main/java/com/mparticle/modernization/MParticleMediator.kt new file mode 100644 index 000000000..d721f2a53 --- /dev/null +++ b/android-core/src/main/java/com/mparticle/modernization/MParticleMediator.kt @@ -0,0 +1,36 @@ +package com.mparticle.modernization + +import com.mparticle.MParticleOptions +import com.mparticle.modernization.event_logging.MParticleEventLogging +import com.mparticle.modernization.event_logging.MParticleFakeEventLoggingImpl +import com.mparticle.modernization.identity.MParticleFakeIdentityImpl +import com.mparticle.modernization.kit.KitManagerInternal +import com.mparticle.modernization.kit.MParticleKit +import com.mparticle.modernization.kit.MParticleKitManagerImpl +import com.mparticle.modernization.kit.MpKit + +class MParticleMediator { + var eventLogging: MParticleEventLogging? = null + internal var identity: InternalIdentity? = null + var kitManager: KitManagerInternal? = null + + private var kits: MutableList = mutableListOf() + + fun configure(options: MParticleOptions) { + kits = registerKits(options) + registerComponent(MParticleKitManagerImpl(kits)) + registerComponent(MParticleFakeIdentityImpl(this)) + registerComponent(MParticleFakeEventLoggingImpl(this)) + } + + private fun registerKits(options: MParticleOptions): MutableList = + mutableListOf(MpKit(this)) + + private fun registerComponent(component: MParticleComponent) { + when (component) { + is InternalIdentity -> identity = component + is KitManagerInternal -> kitManager = component + is MParticleEventLogging -> eventLogging = component + } + } +} \ No newline at end of file diff --git a/android-core/src/main/java/com/mparticle/modernization/Test.kt b/android-core/src/main/java/com/mparticle/modernization/Test.kt new file mode 100644 index 000000000..fbeb9a1d2 --- /dev/null +++ b/android-core/src/main/java/com/mparticle/modernization/Test.kt @@ -0,0 +1,8 @@ +package com.mparticle.modernization + +class Test { + + fun test(){ + MParticle.getInstance()?.EventLogging()?.leaveBreadcrumb("as") + } +} \ No newline at end of file diff --git a/android-core/src/main/java/com/mparticle/modernization/data_uploader/MParticleDataUploading.kt b/android-core/src/main/java/com/mparticle/modernization/data_uploader/MParticleDataUploading.kt new file mode 100644 index 000000000..9c87d1cef --- /dev/null +++ b/android-core/src/main/java/com/mparticle/modernization/data_uploader/MParticleDataUploading.kt @@ -0,0 +1,8 @@ +package com.mparticle.modernization.data_uploader + +import com.mparticle.modernization.MParticleComponent + +interface MParticleDataUploading : MParticleComponent { + + fun upload() {} +} \ No newline at end of file diff --git a/android-core/src/main/java/com/mparticle/modernization/data_uploader/MParticleFakeDataUploadingImpl.kt b/android-core/src/main/java/com/mparticle/modernization/data_uploader/MParticleFakeDataUploadingImpl.kt new file mode 100644 index 000000000..48e765148 --- /dev/null +++ b/android-core/src/main/java/com/mparticle/modernization/data_uploader/MParticleFakeDataUploadingImpl.kt @@ -0,0 +1,4 @@ +package com.mparticle.modernization.data_uploader + +class MParticleFakeDataUploadingImpl : MParticleDataUploading { +} \ No newline at end of file diff --git a/android-core/src/main/java/com/mparticle/modernization/event_logging/MParticleEventLogging.kt b/android-core/src/main/java/com/mparticle/modernization/event_logging/MParticleEventLogging.kt new file mode 100644 index 000000000..19d76276e --- /dev/null +++ b/android-core/src/main/java/com/mparticle/modernization/event_logging/MParticleEventLogging.kt @@ -0,0 +1,14 @@ +package com.mparticle.modernization.event_logging + +import com.mparticle.BaseEvent +import com.mparticle.modernization.MParticleComponent +import java.math.BigDecimal + +interface MParticleEventLogging : MParticleComponent { + //All common, commerce, screen, pushRegistration, notification, notificationOpened and NetworkPerformance events should be logged with the same function + fun logEvent(event: BaseEvent) + fun leaveBreadcrumb(breadcrumb: String) + fun logError(message: String, params: Map? = null) + fun logLtvIncrease(valueIncreased: BigDecimal, eventName: String? = null, params: Map? = null) + fun logException(exception: Exception, message: String? = null, params: Map? = null) +} \ No newline at end of file diff --git a/android-core/src/main/java/com/mparticle/modernization/event_logging/MParticleFakeEventLoggingImpl.kt b/android-core/src/main/java/com/mparticle/modernization/event_logging/MParticleFakeEventLoggingImpl.kt new file mode 100644 index 000000000..5ecad50d9 --- /dev/null +++ b/android-core/src/main/java/com/mparticle/modernization/event_logging/MParticleFakeEventLoggingImpl.kt @@ -0,0 +1,40 @@ +package com.mparticle.modernization.event_logging + +import com.mparticle.BaseEvent +import com.mparticle.MParticleOptions +import com.mparticle.internal.KitManager +import com.mparticle.modernization.MParticleMediator +import com.mparticle.modernization.identity.IdentityCallback +import com.mparticle.modernization.kit.MParticleKit +import java.math.BigDecimal + +internal class MParticleFakeEventLoggingImpl(private val mediator: MParticleMediator, ) : MParticleEventLogging { + + override fun logEvent(event: BaseEvent) { + TODO("Not yet implemented") + } + + override fun leaveBreadcrumb(breadcrumb: String) { + mediator.kitManager?.leaveBreadcrumb(breadcrumb) + } + + override fun logError(message: String, params: Map?) { + TODO("Not yet implemented") + } + + override fun logLtvIncrease( + valueIncreased: BigDecimal, + eventName: String?, + params: Map? + ) { + TODO("Not yet implemented") + } + + override fun logException( + exception: Exception, + message: String?, + params: Map? + ) { + TODO("Not yet implemented") + } +} \ No newline at end of file diff --git a/android-core/src/main/java/com/mparticle/modernization/identity/IdentityCallback.kt b/android-core/src/main/java/com/mparticle/modernization/identity/IdentityCallback.kt new file mode 100644 index 000000000..1bb038696 --- /dev/null +++ b/android-core/src/main/java/com/mparticle/modernization/identity/IdentityCallback.kt @@ -0,0 +1,6 @@ +package com.mparticle.modernization.identity + +import com.mparticle.identity.IdentityApiResult +import com.mparticle.modernization.MParticleCallback + +open class IdentityCallback : MParticleCallback() \ No newline at end of file diff --git a/android-core/src/main/java/com/mparticle/modernization/identity/MParticleFakeIdentityImpl.kt b/android-core/src/main/java/com/mparticle/modernization/identity/MParticleFakeIdentityImpl.kt new file mode 100644 index 000000000..b39cf2422 --- /dev/null +++ b/android-core/src/main/java/com/mparticle/modernization/identity/MParticleFakeIdentityImpl.kt @@ -0,0 +1,44 @@ +package com.mparticle.modernization.identity + +import com.mparticle.MParticleOptions +import com.mparticle.identity.IdentityApiRequest +import com.mparticle.identity.MParticleUser +import com.mparticle.modernization.InternalIdentity +import com.mparticle.modernization.MParticleCallback +import com.mparticle.modernization.MParticleMediator +import java.math.BigDecimal + +internal class MParticleFakeIdentityImpl(private val mediator : MParticleMediator) : InternalIdentity { + override fun identify(request: IdentityApiRequest, callback: IdentityCallback) { + TODO("Not yet implemented") + } + + override fun modify(request: IdentityApiRequest, callback: IdentityCallback) { + TODO("Not yet implemented") + } + + override fun logout(request: IdentityApiRequest, callback: IdentityCallback) { + TODO("Not yet implemented") + } + + override fun logout(callback: IdentityCallback) { + TODO("Not yet implemented") + } + + override fun login(request: IdentityApiRequest, callback: IdentityCallback) { + TODO("Not yet implemented") + } + + override fun login(callback: IdentityCallback) { + TODO("Not yet implemented") + } + + override fun getUser(mpId: Long?, callback: IdentityCallback) { + TODO("Not yet implemented") + } + + override fun getUsers(callback: MParticleCallback, Unit>) { + TODO("Not yet implemented") + } + +} \ No newline at end of file diff --git a/android-core/src/main/java/com/mparticle/modernization/identity/MParticleIdentity.kt b/android-core/src/main/java/com/mparticle/modernization/identity/MParticleIdentity.kt new file mode 100644 index 000000000..755f8fc87 --- /dev/null +++ b/android-core/src/main/java/com/mparticle/modernization/identity/MParticleIdentity.kt @@ -0,0 +1,23 @@ +package com.mparticle.modernization + +import com.mparticle.identity.IdentityApiRequest +import com.mparticle.identity.MParticleUser +import com.mparticle.modernization.identity.IdentityCallback + +interface MParticleIdentity : MParticleComponent { + + fun login(callback: IdentityCallback) + fun logout(callback: IdentityCallback) + + //Will return the user with id or current user + fun getUser(mpId: Long?, callback: IdentityCallback) + fun getUsers(callback: MParticleCallback, Unit>) +} + +internal interface InternalIdentity : MParticleIdentity { + fun identify(request: IdentityApiRequest, callback: IdentityCallback) + fun modify(request: IdentityApiRequest, callback: IdentityCallback) + + fun logout(request: IdentityApiRequest, callback: IdentityCallback) + fun login(request: IdentityApiRequest, callback: IdentityCallback) +} \ No newline at end of file diff --git a/android-core/src/main/java/com/mparticle/modernization/kit/MParticleKit.kt b/android-core/src/main/java/com/mparticle/modernization/kit/MParticleKit.kt new file mode 100644 index 000000000..a21c0075e --- /dev/null +++ b/android-core/src/main/java/com/mparticle/modernization/kit/MParticleKit.kt @@ -0,0 +1,14 @@ +package com.mparticle.modernization.kit + +import com.mparticle.BaseEvent +import java.math.BigDecimal + +interface MParticleKit { + fun logEvent(event: BaseEvent) + fun leaveBreadcrumb(breadcrumb: String) + fun logError(message: String, params: Map? = null) + fun logLtvIncrease(valueIncreased: BigDecimal, eventName: String? = null, params: Map? = null) + fun logException(exception: Exception, message: String? = null, params: Map? = null) +} + +interface MParticleKitInternal : MParticleKit \ No newline at end of file diff --git a/android-core/src/main/java/com/mparticle/modernization/kit/MParticleKitManager.kt b/android-core/src/main/java/com/mparticle/modernization/kit/MParticleKitManager.kt new file mode 100644 index 000000000..6a0bff788 --- /dev/null +++ b/android-core/src/main/java/com/mparticle/modernization/kit/MParticleKitManager.kt @@ -0,0 +1,6 @@ +package com.mparticle.modernization.kit + +import com.mparticle.modernization.MParticleComponent + +interface MParticleKitManager : MParticleKit +interface KitManagerInternal : MParticleKitManager, MParticleComponent \ No newline at end of file diff --git a/android-core/src/main/java/com/mparticle/modernization/kit/MParticleKitManagerImpl.kt b/android-core/src/main/java/com/mparticle/modernization/kit/MParticleKitManagerImpl.kt new file mode 100644 index 000000000..f8098af38 --- /dev/null +++ b/android-core/src/main/java/com/mparticle/modernization/kit/MParticleKitManagerImpl.kt @@ -0,0 +1,38 @@ +package com.mparticle.modernization.kit + +import com.mparticle.BaseEvent +import com.mparticle.modernization.MParticleMediator +import java.math.BigDecimal + +internal class MParticleKitManagerImpl( + private val kits: MutableList +) : KitManagerInternal { + + override fun logEvent(event: BaseEvent) { + TODO("Not yet implemented") + } + + override fun leaveBreadcrumb(breadcrumb: String) { + kits.forEach { it.leaveBreadcrumb(breadcrumb) } + } + + override fun logError(message: String, params: Map?) { + TODO("Not yet implemented") + } + + override fun logLtvIncrease( + valueIncreased: BigDecimal, + eventName: String?, + params: Map? + ) { + TODO("Not yet implemented") + } + + override fun logException( + exception: Exception, + message: String?, + params: Map? + ) { + TODO("Not yet implemented") + } +} \ No newline at end of file diff --git a/android-core/src/main/java/com/mparticle/modernization/kit/MpKit.kt b/android-core/src/main/java/com/mparticle/modernization/kit/MpKit.kt new file mode 100644 index 000000000..d0966c8f3 --- /dev/null +++ b/android-core/src/main/java/com/mparticle/modernization/kit/MpKit.kt @@ -0,0 +1,35 @@ +package com.mparticle.modernization.kit + +import com.mparticle.BaseEvent +import com.mparticle.modernization.MParticleMediator +import java.math.BigDecimal + + class MpKit(private val mediator: MParticleMediator) : MParticleKitInternal{ + override fun logEvent(event: BaseEvent) { + TODO("Not yet implemented") + } + + override fun leaveBreadcrumb(breadcrumb: String) { + TODO("Not yet implemented") + } + + override fun logError(message: String, params: Map?) { + TODO("Not yet implemented") + } + + override fun logLtvIncrease( + valueIncreased: BigDecimal, + eventName: String?, + params: Map? + ) { + TODO("Not yet implemented") + } + + override fun logException( + exception: Exception, + message: String?, + params: Map? + ) { + TODO("Not yet implemented") + } +} \ No newline at end of file diff --git a/android-core/src/main/java/com/mparticle/modernization/kit/XKit.kt b/android-core/src/main/java/com/mparticle/modernization/kit/XKit.kt new file mode 100644 index 000000000..791a92a61 --- /dev/null +++ b/android-core/src/main/java/com/mparticle/modernization/kit/XKit.kt @@ -0,0 +1,35 @@ +package com.mparticle.modernization.kit + +import com.mparticle.BaseEvent +import com.mparticle.modernization.MParticleMediator +import java.math.BigDecimal + +class XKit(private val mediator: MParticleMediator) : MParticleKitInternal{ + override fun logEvent(event: BaseEvent) { + TODO("Not yet implemented") + } + + override fun leaveBreadcrumb(breadcrumb: String) { + TODO("Not yet implemented") + } + + override fun logError(message: String, params: Map?) { + TODO("Not yet implemented") + } + + override fun logLtvIncrease( + valueIncreased: BigDecimal, + eventName: String?, + params: Map? + ) { + TODO("Not yet implemented") + } + + override fun logException( + exception: Exception, + message: String?, + params: Map? + ) { + TODO("Not yet implemented") + } +} \ No newline at end of file diff --git a/build.gradle b/build.gradle index 6dcef199e..ddd06c55a 100644 --- a/build.gradle +++ b/build.gradle @@ -13,7 +13,7 @@ buildscript { } plugins { - id "org.sonarqube" version "3.5.0.2730" + id "org.sonarqube" version "4.0.0.2929" id "org.jlleitschuh.gradle.ktlint" version "11.1.0" } From 630bbcbe2d06c9a60a091c6068246e34c7f1e897 Mon Sep 17 00:00:00 2001 From: markvdouw Date: Tue, 28 Feb 2023 16:38:06 -0300 Subject: [PATCH 2/9] Changes to accomodate interfaces --- .../com/mparticle/modernization/MParticle.kt | 11 +++++-- .../modernization/MParticleException.kt | 5 +++ .../modernization/MParticleMediator.kt | 9 ++++-- .../java/com/mparticle/modernization/Test.kt | 8 ----- .../MParticleBroadcastReceiver.kt | 14 +++++++++ .../data_uploader/MParticleDataRepository.kt | 4 +++ ...aUploading.kt => MParticleDataUploader.kt} | 2 +- .../MParticleDataUploadingStrategy.kt | 4 +++ .../MParticleFakeDataUploadingImpl.kt | 4 ++- .../MParticleHistoryUploadingStrategy.kt | 4 +++ .../MParticleUploadingStrategy.kt | 4 +++ .../MParticleFakeEventLoggingImpl.kt | 2 +- .../identity/MParticleFakeIdentityImpl.kt | 31 ++++++++++++++----- .../identity/MParticleIdentity.kt | 21 ++++++++----- .../modernization/kit/MParticleKit.kt | 25 ++++++++++----- .../modernization/kit/MParticleKitManager.kt | 5 +-- .../kit/MParticleKitManagerImpl.kt | 2 +- .../com/mparticle/modernization/kit/MpKit.kt | 2 +- .../com/mparticle/modernization/kit/XKit.kt | 25 +-------------- 19 files changed, 116 insertions(+), 66 deletions(-) create mode 100644 android-core/src/main/java/com/mparticle/modernization/MParticleException.kt delete mode 100644 android-core/src/main/java/com/mparticle/modernization/Test.kt create mode 100644 android-core/src/main/java/com/mparticle/modernization/data_uploader/MParticleBroadcastReceiver.kt create mode 100644 android-core/src/main/java/com/mparticle/modernization/data_uploader/MParticleDataRepository.kt rename android-core/src/main/java/com/mparticle/modernization/data_uploader/{MParticleDataUploading.kt => MParticleDataUploader.kt} (69%) create mode 100644 android-core/src/main/java/com/mparticle/modernization/data_uploader/MParticleDataUploadingStrategy.kt create mode 100644 android-core/src/main/java/com/mparticle/modernization/data_uploader/MParticleHistoryUploadingStrategy.kt create mode 100644 android-core/src/main/java/com/mparticle/modernization/data_uploader/MParticleUploadingStrategy.kt diff --git a/android-core/src/main/java/com/mparticle/modernization/MParticle.kt b/android-core/src/main/java/com/mparticle/modernization/MParticle.kt index 67a6720ed..b63bd13e8 100644 --- a/android-core/src/main/java/com/mparticle/modernization/MParticle.kt +++ b/android-core/src/main/java/com/mparticle/modernization/MParticle.kt @@ -1,8 +1,10 @@ package com.mparticle.modernization import com.mparticle.MParticleOptions -import com.mparticle.internal.KitManager +import com.mparticle.modernization.data_uploader.MParticleDataUploader import com.mparticle.modernization.event_logging.MParticleEventLogging +import com.mparticle.modernization.identity.MParticleIdentity +import com.mparticle.modernization.kit.MParticleKitManager class MParticle private constructor(private val options: MParticleOptions) { private var mediator: MParticleMediator = MParticleMediator() @@ -13,14 +15,17 @@ class MParticle private constructor(private val options: MParticleOptions) { companion object { private var _instance: MParticle? = null - fun getInstance(): MParticle? = _instance + + @Throws(MParticleInitializationException::class) + fun getInstance(): MParticle = _instance ?: throw MParticleInitializationException() fun start(options: MParticleOptions) { _instance = MParticle(options) } } - fun KitManager(): KitManager? = mediator.kitManager as KitManager? + fun KitManager(): MParticleKitManager? = mediator.kitManager as MParticleKitManager? fun Identity(): MParticleIdentity? = mediator.identity as MParticleIdentity? fun EventLogging(): MParticleEventLogging? = mediator.eventLogging + fun DataUploading() : MParticleDataUploader? = mediator.dataUploader } \ No newline at end of file diff --git a/android-core/src/main/java/com/mparticle/modernization/MParticleException.kt b/android-core/src/main/java/com/mparticle/modernization/MParticleException.kt new file mode 100644 index 000000000..60656b83f --- /dev/null +++ b/android-core/src/main/java/com/mparticle/modernization/MParticleException.kt @@ -0,0 +1,5 @@ +package com.mparticle.modernization + +abstract class MParticleException(message : String, throwable: Throwable? = null) : RuntimeException() + +class MParticleInitializationException(message: String = "MParticle must be started before obtaining an instance, please call MParticle.start() first") : MParticleException(message) \ No newline at end of file diff --git a/android-core/src/main/java/com/mparticle/modernization/MParticleMediator.kt b/android-core/src/main/java/com/mparticle/modernization/MParticleMediator.kt index d721f2a53..116364cf7 100644 --- a/android-core/src/main/java/com/mparticle/modernization/MParticleMediator.kt +++ b/android-core/src/main/java/com/mparticle/modernization/MParticleMediator.kt @@ -1,8 +1,11 @@ package com.mparticle.modernization import com.mparticle.MParticleOptions +import com.mparticle.modernization.data_uploader.MParticleDataUploader +import com.mparticle.modernization.data_uploader.MParticleFakeDataUploadingImpl import com.mparticle.modernization.event_logging.MParticleEventLogging import com.mparticle.modernization.event_logging.MParticleFakeEventLoggingImpl +import com.mparticle.modernization.identity.InternalIdentity import com.mparticle.modernization.identity.MParticleFakeIdentityImpl import com.mparticle.modernization.kit.KitManagerInternal import com.mparticle.modernization.kit.MParticleKit @@ -10,9 +13,10 @@ import com.mparticle.modernization.kit.MParticleKitManagerImpl import com.mparticle.modernization.kit.MpKit class MParticleMediator { - var eventLogging: MParticleEventLogging? = null + internal var eventLogging: MParticleEventLogging? = null internal var identity: InternalIdentity? = null - var kitManager: KitManagerInternal? = null + internal var kitManager: KitManagerInternal? = null + internal var dataUploader : MParticleDataUploader? = null private var kits: MutableList = mutableListOf() @@ -21,6 +25,7 @@ class MParticleMediator { registerComponent(MParticleKitManagerImpl(kits)) registerComponent(MParticleFakeIdentityImpl(this)) registerComponent(MParticleFakeEventLoggingImpl(this)) + registerComponent(MParticleFakeDataUploadingImpl(this)) } private fun registerKits(options: MParticleOptions): MutableList = diff --git a/android-core/src/main/java/com/mparticle/modernization/Test.kt b/android-core/src/main/java/com/mparticle/modernization/Test.kt deleted file mode 100644 index fbeb9a1d2..000000000 --- a/android-core/src/main/java/com/mparticle/modernization/Test.kt +++ /dev/null @@ -1,8 +0,0 @@ -package com.mparticle.modernization - -class Test { - - fun test(){ - MParticle.getInstance()?.EventLogging()?.leaveBreadcrumb("as") - } -} \ No newline at end of file diff --git a/android-core/src/main/java/com/mparticle/modernization/data_uploader/MParticleBroadcastReceiver.kt b/android-core/src/main/java/com/mparticle/modernization/data_uploader/MParticleBroadcastReceiver.kt new file mode 100644 index 000000000..9ffce0ddc --- /dev/null +++ b/android-core/src/main/java/com/mparticle/modernization/data_uploader/MParticleBroadcastReceiver.kt @@ -0,0 +1,14 @@ +package com.mparticle.modernization.data_uploader + +import android.content.BroadcastReceiver +import android.content.Context +import android.content.Intent +import com.mparticle.modernization.MParticle + +class MParticleBroadcastReceiver : BroadcastReceiver(){ + val uploader : MParticleDataUploader? = MParticle.getInstance().DataUploading() + + override fun onReceive(context: Context?, intent: Intent?) { + + } +} \ No newline at end of file diff --git a/android-core/src/main/java/com/mparticle/modernization/data_uploader/MParticleDataRepository.kt b/android-core/src/main/java/com/mparticle/modernization/data_uploader/MParticleDataRepository.kt new file mode 100644 index 000000000..26cb97285 --- /dev/null +++ b/android-core/src/main/java/com/mparticle/modernization/data_uploader/MParticleDataRepository.kt @@ -0,0 +1,4 @@ +package com.mparticle.modernization.data_uploader + +class MParticleDataRepository { +} \ No newline at end of file diff --git a/android-core/src/main/java/com/mparticle/modernization/data_uploader/MParticleDataUploading.kt b/android-core/src/main/java/com/mparticle/modernization/data_uploader/MParticleDataUploader.kt similarity index 69% rename from android-core/src/main/java/com/mparticle/modernization/data_uploader/MParticleDataUploading.kt rename to android-core/src/main/java/com/mparticle/modernization/data_uploader/MParticleDataUploader.kt index 9c87d1cef..64f0a13e0 100644 --- a/android-core/src/main/java/com/mparticle/modernization/data_uploader/MParticleDataUploading.kt +++ b/android-core/src/main/java/com/mparticle/modernization/data_uploader/MParticleDataUploader.kt @@ -2,7 +2,7 @@ package com.mparticle.modernization.data_uploader import com.mparticle.modernization.MParticleComponent -interface MParticleDataUploading : MParticleComponent { +interface MParticleDataUploader : MParticleComponent { fun upload() {} } \ No newline at end of file diff --git a/android-core/src/main/java/com/mparticle/modernization/data_uploader/MParticleDataUploadingStrategy.kt b/android-core/src/main/java/com/mparticle/modernization/data_uploader/MParticleDataUploadingStrategy.kt new file mode 100644 index 000000000..b8e7ae44f --- /dev/null +++ b/android-core/src/main/java/com/mparticle/modernization/data_uploader/MParticleDataUploadingStrategy.kt @@ -0,0 +1,4 @@ +package com.mparticle.modernization.data_uploader + +class MParticleDataUploadingStrategy { +} \ No newline at end of file diff --git a/android-core/src/main/java/com/mparticle/modernization/data_uploader/MParticleFakeDataUploadingImpl.kt b/android-core/src/main/java/com/mparticle/modernization/data_uploader/MParticleFakeDataUploadingImpl.kt index 48e765148..21c78fe58 100644 --- a/android-core/src/main/java/com/mparticle/modernization/data_uploader/MParticleFakeDataUploadingImpl.kt +++ b/android-core/src/main/java/com/mparticle/modernization/data_uploader/MParticleFakeDataUploadingImpl.kt @@ -1,4 +1,6 @@ package com.mparticle.modernization.data_uploader -class MParticleFakeDataUploadingImpl : MParticleDataUploading { +import com.mparticle.modernization.MParticleMediator + +internal class MParticleFakeDataUploadingImpl(private val mediator : MParticleMediator) : MParticleDataUploader { } \ No newline at end of file diff --git a/android-core/src/main/java/com/mparticle/modernization/data_uploader/MParticleHistoryUploadingStrategy.kt b/android-core/src/main/java/com/mparticle/modernization/data_uploader/MParticleHistoryUploadingStrategy.kt new file mode 100644 index 000000000..be35e506a --- /dev/null +++ b/android-core/src/main/java/com/mparticle/modernization/data_uploader/MParticleHistoryUploadingStrategy.kt @@ -0,0 +1,4 @@ +package com.mparticle.modernization.data_uploader + +class MParticleHistoryUploadingStrategy { +} \ No newline at end of file diff --git a/android-core/src/main/java/com/mparticle/modernization/data_uploader/MParticleUploadingStrategy.kt b/android-core/src/main/java/com/mparticle/modernization/data_uploader/MParticleUploadingStrategy.kt new file mode 100644 index 000000000..8792a86ef --- /dev/null +++ b/android-core/src/main/java/com/mparticle/modernization/data_uploader/MParticleUploadingStrategy.kt @@ -0,0 +1,4 @@ +package com.mparticle.modernization.data_uploader + +interface MParticleUploadingStrategy { +} \ No newline at end of file diff --git a/android-core/src/main/java/com/mparticle/modernization/event_logging/MParticleFakeEventLoggingImpl.kt b/android-core/src/main/java/com/mparticle/modernization/event_logging/MParticleFakeEventLoggingImpl.kt index 5ecad50d9..3f2760a37 100644 --- a/android-core/src/main/java/com/mparticle/modernization/event_logging/MParticleFakeEventLoggingImpl.kt +++ b/android-core/src/main/java/com/mparticle/modernization/event_logging/MParticleFakeEventLoggingImpl.kt @@ -8,7 +8,7 @@ import com.mparticle.modernization.identity.IdentityCallback import com.mparticle.modernization.kit.MParticleKit import java.math.BigDecimal -internal class MParticleFakeEventLoggingImpl(private val mediator: MParticleMediator, ) : MParticleEventLogging { +internal class MParticleFakeEventLoggingImpl(private val mediator: MParticleMediator ) : MParticleEventLogging { override fun logEvent(event: BaseEvent) { TODO("Not yet implemented") diff --git a/android-core/src/main/java/com/mparticle/modernization/identity/MParticleFakeIdentityImpl.kt b/android-core/src/main/java/com/mparticle/modernization/identity/MParticleFakeIdentityImpl.kt index b39cf2422..ba904f280 100644 --- a/android-core/src/main/java/com/mparticle/modernization/identity/MParticleFakeIdentityImpl.kt +++ b/android-core/src/main/java/com/mparticle/modernization/identity/MParticleFakeIdentityImpl.kt @@ -1,23 +1,22 @@ package com.mparticle.modernization.identity -import com.mparticle.MParticleOptions import com.mparticle.identity.IdentityApiRequest +import com.mparticle.identity.IdentityApiResult import com.mparticle.identity.MParticleUser -import com.mparticle.modernization.InternalIdentity import com.mparticle.modernization.MParticleCallback import com.mparticle.modernization.MParticleMediator -import java.math.BigDecimal -internal class MParticleFakeIdentityImpl(private val mediator : MParticleMediator) : InternalIdentity { - override fun identify(request: IdentityApiRequest, callback: IdentityCallback) { +internal class MParticleFakeIdentityImpl(private val mediator : MParticleMediator) : + InternalIdentity { + override suspend fun identify(request: IdentityApiRequest): IdentityApiResult { TODO("Not yet implemented") } - override fun modify(request: IdentityApiRequest, callback: IdentityCallback) { + override suspend fun modify(request: IdentityApiRequest): IdentityApiResult { TODO("Not yet implemented") } - override fun logout(request: IdentityApiRequest, callback: IdentityCallback) { + override suspend fun logout(request: IdentityApiRequest): IdentityApiResult { TODO("Not yet implemented") } @@ -25,7 +24,11 @@ internal class MParticleFakeIdentityImpl(private val mediator : MParticleMediato TODO("Not yet implemented") } - override fun login(request: IdentityApiRequest, callback: IdentityCallback) { + override suspend fun logout(): IdentityApiResult { + TODO("Not yet implemented") + } + + override suspend fun login(request: IdentityApiRequest): IdentityApiResult { TODO("Not yet implemented") } @@ -33,12 +36,24 @@ internal class MParticleFakeIdentityImpl(private val mediator : MParticleMediato TODO("Not yet implemented") } + override suspend fun login(): IdentityApiResult { + TODO("Not yet implemented") + } + override fun getUser(mpId: Long?, callback: IdentityCallback) { TODO("Not yet implemented") } + override suspend fun getUser(mpId: Long): IdentityApiResult { + TODO("Not yet implemented") + } + override fun getUsers(callback: MParticleCallback, Unit>) { TODO("Not yet implemented") } + override suspend fun getUsers(): List { + TODO("Not yet implemented") + } + } \ No newline at end of file diff --git a/android-core/src/main/java/com/mparticle/modernization/identity/MParticleIdentity.kt b/android-core/src/main/java/com/mparticle/modernization/identity/MParticleIdentity.kt index 755f8fc87..37cc7ce84 100644 --- a/android-core/src/main/java/com/mparticle/modernization/identity/MParticleIdentity.kt +++ b/android-core/src/main/java/com/mparticle/modernization/identity/MParticleIdentity.kt @@ -1,8 +1,10 @@ -package com.mparticle.modernization +package com.mparticle.modernization.identity import com.mparticle.identity.IdentityApiRequest +import com.mparticle.identity.IdentityApiResult import com.mparticle.identity.MParticleUser -import com.mparticle.modernization.identity.IdentityCallback +import com.mparticle.modernization.MParticleCallback +import com.mparticle.modernization.MParticleComponent interface MParticleIdentity : MParticleComponent { @@ -12,12 +14,17 @@ interface MParticleIdentity : MParticleComponent { //Will return the user with id or current user fun getUser(mpId: Long?, callback: IdentityCallback) fun getUsers(callback: MParticleCallback, Unit>) + + //Coroutines + suspend fun getUser(mpId: Long) : IdentityApiResult + suspend fun getUsers(): List + suspend fun login(): IdentityApiResult + suspend fun logout(): IdentityApiResult } internal interface InternalIdentity : MParticleIdentity { - fun identify(request: IdentityApiRequest, callback: IdentityCallback) - fun modify(request: IdentityApiRequest, callback: IdentityCallback) - - fun logout(request: IdentityApiRequest, callback: IdentityCallback) - fun login(request: IdentityApiRequest, callback: IdentityCallback) + suspend fun identify(request: IdentityApiRequest): IdentityApiResult + suspend fun modify(request: IdentityApiRequest): IdentityApiResult + suspend fun logout(request: IdentityApiRequest): IdentityApiResult + suspend fun login(request: IdentityApiRequest): IdentityApiResult } \ No newline at end of file diff --git a/android-core/src/main/java/com/mparticle/modernization/kit/MParticleKit.kt b/android-core/src/main/java/com/mparticle/modernization/kit/MParticleKit.kt index a21c0075e..9a1b48e4d 100644 --- a/android-core/src/main/java/com/mparticle/modernization/kit/MParticleKit.kt +++ b/android-core/src/main/java/com/mparticle/modernization/kit/MParticleKit.kt @@ -3,12 +3,23 @@ package com.mparticle.modernization.kit import com.mparticle.BaseEvent import java.math.BigDecimal -interface MParticleKit { - fun logEvent(event: BaseEvent) - fun leaveBreadcrumb(breadcrumb: String) - fun logError(message: String, params: Map? = null) - fun logLtvIncrease(valueIncreased: BigDecimal, eventName: String? = null, params: Map? = null) - fun logException(exception: Exception, message: String? = null, params: Map? = null) +abstract class MParticleKit { + open fun logEvent(event: BaseEvent) {} + open fun leaveBreadcrumb(breadcrumb: String) {} + open fun logError(message: String, params: Map? = null) {} + open fun logLtvIncrease( + valueIncreased: BigDecimal, + eventName: String? = null, + params: Map? = null + ) { + } + + open fun logException( + exception: Exception, + message: String? = null, + params: Map? = null + ) { + } } -interface MParticleKitInternal : MParticleKit \ No newline at end of file + abstract class MParticleKitInternal : MParticleKit() \ No newline at end of file diff --git a/android-core/src/main/java/com/mparticle/modernization/kit/MParticleKitManager.kt b/android-core/src/main/java/com/mparticle/modernization/kit/MParticleKitManager.kt index 6a0bff788..3a8c6c216 100644 --- a/android-core/src/main/java/com/mparticle/modernization/kit/MParticleKitManager.kt +++ b/android-core/src/main/java/com/mparticle/modernization/kit/MParticleKitManager.kt @@ -2,5 +2,6 @@ package com.mparticle.modernization.kit import com.mparticle.modernization.MParticleComponent -interface MParticleKitManager : MParticleKit -interface KitManagerInternal : MParticleKitManager, MParticleComponent \ No newline at end of file +abstract class MParticleKitManager : MParticleKit() { +} +abstract class KitManagerInternal : MParticleKitManager(), MParticleComponent \ No newline at end of file diff --git a/android-core/src/main/java/com/mparticle/modernization/kit/MParticleKitManagerImpl.kt b/android-core/src/main/java/com/mparticle/modernization/kit/MParticleKitManagerImpl.kt index f8098af38..1f0f82a1d 100644 --- a/android-core/src/main/java/com/mparticle/modernization/kit/MParticleKitManagerImpl.kt +++ b/android-core/src/main/java/com/mparticle/modernization/kit/MParticleKitManagerImpl.kt @@ -6,7 +6,7 @@ import java.math.BigDecimal internal class MParticleKitManagerImpl( private val kits: MutableList -) : KitManagerInternal { +) : KitManagerInternal() { override fun logEvent(event: BaseEvent) { TODO("Not yet implemented") diff --git a/android-core/src/main/java/com/mparticle/modernization/kit/MpKit.kt b/android-core/src/main/java/com/mparticle/modernization/kit/MpKit.kt index d0966c8f3..335e49ec2 100644 --- a/android-core/src/main/java/com/mparticle/modernization/kit/MpKit.kt +++ b/android-core/src/main/java/com/mparticle/modernization/kit/MpKit.kt @@ -4,7 +4,7 @@ import com.mparticle.BaseEvent import com.mparticle.modernization.MParticleMediator import java.math.BigDecimal - class MpKit(private val mediator: MParticleMediator) : MParticleKitInternal{ + class MpKit(private val mediator: MParticleMediator) : MParticleKitInternal(){ override fun logEvent(event: BaseEvent) { TODO("Not yet implemented") } diff --git a/android-core/src/main/java/com/mparticle/modernization/kit/XKit.kt b/android-core/src/main/java/com/mparticle/modernization/kit/XKit.kt index 791a92a61..aa13a8529 100644 --- a/android-core/src/main/java/com/mparticle/modernization/kit/XKit.kt +++ b/android-core/src/main/java/com/mparticle/modernization/kit/XKit.kt @@ -4,32 +4,9 @@ import com.mparticle.BaseEvent import com.mparticle.modernization.MParticleMediator import java.math.BigDecimal -class XKit(private val mediator: MParticleMediator) : MParticleKitInternal{ +class XKit(private val mediator: MParticleMediator) : MParticleKitInternal(){ override fun logEvent(event: BaseEvent) { TODO("Not yet implemented") } - override fun leaveBreadcrumb(breadcrumb: String) { - TODO("Not yet implemented") - } - - override fun logError(message: String, params: Map?) { - TODO("Not yet implemented") - } - - override fun logLtvIncrease( - valueIncreased: BigDecimal, - eventName: String?, - params: Map? - ) { - TODO("Not yet implemented") - } - - override fun logException( - exception: Exception, - message: String?, - params: Map? - ) { - TODO("Not yet implemented") - } } \ No newline at end of file From 8718cd30a1cb4e15c8b9a0ef016e6618684de051 Mon Sep 17 00:00:00 2001 From: markvdouw Date: Tue, 28 Feb 2023 21:04:38 -0300 Subject: [PATCH 3/9] Reorganizing structure Adding changes to include suspend fun for internal usage with dispatchers and scope in mediator Adding repository Adding uploading component, strategies, types, etc. --- android-core/build.gradle | 2 + .../modernization/MParticleCallback.kt | 24 +++-- .../modernization/MParticleComponent.kt | 4 - .../modernization/MParticleException.kt | 5 -- .../modernization/MParticleMediator.kt | 41 --------- .../java/com/mparticle/modernization/Utils.kt | 9 ++ .../config/UploadingConfiguration.kt | 3 + .../modernization/{ => core}/MParticle.kt | 4 +- .../modernization/core/MParticleComponent.kt | 3 + .../modernization/core/MParticleException.kt | 7 ++ .../modernization/core/MParticleMediator.kt | 53 +++++++++++ .../data/MParticleDataRepository.kt | 10 +++ .../MParticleBroadcastReceiver.kt | 14 --- .../data_uploader/MParticleDataRepository.kt | 4 - .../data_uploader/MParticleDataUploader.kt | 22 ++++- .../MParticleDataUploaderImpl.kt | 27 ++++++ .../MParticleDataUploadingStrategy.kt | 4 - .../MParticleFakeDataUploadingImpl.kt | 6 -- .../MParticleHistoryUploadingStrategy.kt | 4 - .../MParticleUploadingStrategy.kt | 25 ++++++ .../MParticleBreadcrumbUploading.kt | 42 +++++++++ .../example_impl/MParticleUploaderTypes.kt | 5 ++ .../event_logging/MParticleEventLogging.kt | 51 +++++++++-- .../MParticleFakeEventLoggingImpl.kt | 40 --------- .../MParticleEventLoggingImpl.kt} | 11 ++- .../identity/MParticleIdentity.kt | 90 ++++++++++++++++--- .../MParticleIdentityImpl.kt} | 10 ++- .../modernization/kit/MParticleKit.kt | 34 ++++--- .../modernization/kit/MParticleKitManager.kt | 6 +- .../kit/MParticleKitManagerImpl.kt | 30 +------ .../kit/example_impl/CustomKit.kt | 11 +++ .../modernization/kit/example_impl/MpKit.kt | 16 ++++ .../kit/{ => example_impl}/XKit.kt | 8 +- 33 files changed, 409 insertions(+), 216 deletions(-) delete mode 100644 android-core/src/main/java/com/mparticle/modernization/MParticleComponent.kt delete mode 100644 android-core/src/main/java/com/mparticle/modernization/MParticleException.kt delete mode 100644 android-core/src/main/java/com/mparticle/modernization/MParticleMediator.kt create mode 100644 android-core/src/main/java/com/mparticle/modernization/Utils.kt create mode 100644 android-core/src/main/java/com/mparticle/modernization/config/UploadingConfiguration.kt rename android-core/src/main/java/com/mparticle/modernization/{ => core}/MParticle.kt (90%) create mode 100644 android-core/src/main/java/com/mparticle/modernization/core/MParticleComponent.kt create mode 100644 android-core/src/main/java/com/mparticle/modernization/core/MParticleException.kt create mode 100644 android-core/src/main/java/com/mparticle/modernization/core/MParticleMediator.kt create mode 100644 android-core/src/main/java/com/mparticle/modernization/data/MParticleDataRepository.kt delete mode 100644 android-core/src/main/java/com/mparticle/modernization/data_uploader/MParticleBroadcastReceiver.kt delete mode 100644 android-core/src/main/java/com/mparticle/modernization/data_uploader/MParticleDataRepository.kt create mode 100644 android-core/src/main/java/com/mparticle/modernization/data_uploader/MParticleDataUploaderImpl.kt delete mode 100644 android-core/src/main/java/com/mparticle/modernization/data_uploader/MParticleDataUploadingStrategy.kt delete mode 100644 android-core/src/main/java/com/mparticle/modernization/data_uploader/MParticleFakeDataUploadingImpl.kt delete mode 100644 android-core/src/main/java/com/mparticle/modernization/data_uploader/MParticleHistoryUploadingStrategy.kt create mode 100644 android-core/src/main/java/com/mparticle/modernization/data_uploader/example_impl/MParticleBreadcrumbUploading.kt create mode 100644 android-core/src/main/java/com/mparticle/modernization/data_uploader/example_impl/MParticleUploaderTypes.kt delete mode 100644 android-core/src/main/java/com/mparticle/modernization/event_logging/MParticleFakeEventLoggingImpl.kt rename android-core/src/main/java/com/mparticle/modernization/{kit/MpKit.kt => event_logging/example_impl/MParticleEventLoggingImpl.kt} (65%) rename android-core/src/main/java/com/mparticle/modernization/identity/{MParticleFakeIdentityImpl.kt => example_impl/MParticleIdentityImpl.kt} (79%) create mode 100644 android-core/src/main/java/com/mparticle/modernization/kit/example_impl/CustomKit.kt create mode 100644 android-core/src/main/java/com/mparticle/modernization/kit/example_impl/MpKit.kt rename android-core/src/main/java/com/mparticle/modernization/kit/{ => example_impl}/XKit.kt (50%) diff --git a/android-core/build.gradle b/android-core/build.gradle index e92819e43..6a2194119 100644 --- a/android-core/build.gradle +++ b/android-core/build.gradle @@ -135,6 +135,8 @@ dependencies { api 'androidx.annotation:annotation:[1.0.0,)' compileOnly 'androidx.core:core:[1.3.2, )' + implementation 'org.jetbrains.kotlinx:kotlinx-coroutines-core:1.6.4' + api 'androidx.localbroadcastmanager:localbroadcastmanager:1.1.0' lintPublish project( path: ':tooling:custom-lint-rules', configuration: 'lintBuild') diff --git a/android-core/src/main/java/com/mparticle/modernization/MParticleCallback.kt b/android-core/src/main/java/com/mparticle/modernization/MParticleCallback.kt index 9e61274bb..217a6630e 100644 --- a/android-core/src/main/java/com/mparticle/modernization/MParticleCallback.kt +++ b/android-core/src/main/java/com/mparticle/modernization/MParticleCallback.kt @@ -1,18 +1,16 @@ package com.mparticle.modernization -import com.mparticle.identity.IdentityApiResult +abstract class MParticleCallback { + var isSuccessFul: Boolean = false + var isCompleted: Boolean = false -abstract class MParticleCallback { - var isSuccessFul : Boolean = false - var isCompleted : Boolean = false + fun onSuccess(result: S) { + isSuccessFul = true + isCompleted = true + } - fun onSuccess(result : S) { - isSuccessFul = true - isCompleted = true - } - - fun onError(error : E){ - isSuccessFul = false - isCompleted = true - } + fun onError(error: E) { + isSuccessFul = false + isCompleted = true + } } diff --git a/android-core/src/main/java/com/mparticle/modernization/MParticleComponent.kt b/android-core/src/main/java/com/mparticle/modernization/MParticleComponent.kt deleted file mode 100644 index 01b1f77fc..000000000 --- a/android-core/src/main/java/com/mparticle/modernization/MParticleComponent.kt +++ /dev/null @@ -1,4 +0,0 @@ -package com.mparticle.modernization - -interface MParticleComponent { -} \ No newline at end of file diff --git a/android-core/src/main/java/com/mparticle/modernization/MParticleException.kt b/android-core/src/main/java/com/mparticle/modernization/MParticleException.kt deleted file mode 100644 index 60656b83f..000000000 --- a/android-core/src/main/java/com/mparticle/modernization/MParticleException.kt +++ /dev/null @@ -1,5 +0,0 @@ -package com.mparticle.modernization - -abstract class MParticleException(message : String, throwable: Throwable? = null) : RuntimeException() - -class MParticleInitializationException(message: String = "MParticle must be started before obtaining an instance, please call MParticle.start() first") : MParticleException(message) \ No newline at end of file diff --git a/android-core/src/main/java/com/mparticle/modernization/MParticleMediator.kt b/android-core/src/main/java/com/mparticle/modernization/MParticleMediator.kt deleted file mode 100644 index 116364cf7..000000000 --- a/android-core/src/main/java/com/mparticle/modernization/MParticleMediator.kt +++ /dev/null @@ -1,41 +0,0 @@ -package com.mparticle.modernization - -import com.mparticle.MParticleOptions -import com.mparticle.modernization.data_uploader.MParticleDataUploader -import com.mparticle.modernization.data_uploader.MParticleFakeDataUploadingImpl -import com.mparticle.modernization.event_logging.MParticleEventLogging -import com.mparticle.modernization.event_logging.MParticleFakeEventLoggingImpl -import com.mparticle.modernization.identity.InternalIdentity -import com.mparticle.modernization.identity.MParticleFakeIdentityImpl -import com.mparticle.modernization.kit.KitManagerInternal -import com.mparticle.modernization.kit.MParticleKit -import com.mparticle.modernization.kit.MParticleKitManagerImpl -import com.mparticle.modernization.kit.MpKit - -class MParticleMediator { - internal var eventLogging: MParticleEventLogging? = null - internal var identity: InternalIdentity? = null - internal var kitManager: KitManagerInternal? = null - internal var dataUploader : MParticleDataUploader? = null - - private var kits: MutableList = mutableListOf() - - fun configure(options: MParticleOptions) { - kits = registerKits(options) - registerComponent(MParticleKitManagerImpl(kits)) - registerComponent(MParticleFakeIdentityImpl(this)) - registerComponent(MParticleFakeEventLoggingImpl(this)) - registerComponent(MParticleFakeDataUploadingImpl(this)) - } - - private fun registerKits(options: MParticleOptions): MutableList = - mutableListOf(MpKit(this)) - - private fun registerComponent(component: MParticleComponent) { - when (component) { - is InternalIdentity -> identity = component - is KitManagerInternal -> kitManager = component - is MParticleEventLogging -> eventLogging = component - } - } -} \ No newline at end of file diff --git a/android-core/src/main/java/com/mparticle/modernization/Utils.kt b/android-core/src/main/java/com/mparticle/modernization/Utils.kt new file mode 100644 index 000000000..bf4912f50 --- /dev/null +++ b/android-core/src/main/java/com/mparticle/modernization/Utils.kt @@ -0,0 +1,9 @@ +package com.mparticle.modernization + +import com.mparticle.modernization.core.MParticleMediator +import kotlinx.coroutines.CoroutineScope +import kotlinx.coroutines.launch + +fun MParticleMediator.launch(block: suspend CoroutineScope.() -> Unit) { + this.coroutineScope.launch(this.coroutineDispatcher) { block } +} \ No newline at end of file diff --git a/android-core/src/main/java/com/mparticle/modernization/config/UploadingConfiguration.kt b/android-core/src/main/java/com/mparticle/modernization/config/UploadingConfiguration.kt new file mode 100644 index 000000000..5816c232c --- /dev/null +++ b/android-core/src/main/java/com/mparticle/modernization/config/UploadingConfiguration.kt @@ -0,0 +1,3 @@ +package com.mparticle.modernization.config + +interface UploadingConfiguration \ No newline at end of file diff --git a/android-core/src/main/java/com/mparticle/modernization/MParticle.kt b/android-core/src/main/java/com/mparticle/modernization/core/MParticle.kt similarity index 90% rename from android-core/src/main/java/com/mparticle/modernization/MParticle.kt rename to android-core/src/main/java/com/mparticle/modernization/core/MParticle.kt index b63bd13e8..627a6a539 100644 --- a/android-core/src/main/java/com/mparticle/modernization/MParticle.kt +++ b/android-core/src/main/java/com/mparticle/modernization/core/MParticle.kt @@ -1,4 +1,4 @@ -package com.mparticle.modernization +package com.mparticle.modernization.core import com.mparticle.MParticleOptions import com.mparticle.modernization.data_uploader.MParticleDataUploader @@ -27,5 +27,5 @@ class MParticle private constructor(private val options: MParticleOptions) { fun KitManager(): MParticleKitManager? = mediator.kitManager as MParticleKitManager? fun Identity(): MParticleIdentity? = mediator.identity as MParticleIdentity? fun EventLogging(): MParticleEventLogging? = mediator.eventLogging - fun DataUploading() : MParticleDataUploader? = mediator.dataUploader + fun DataUploading(): MParticleDataUploader? = mediator.dataUploader } \ No newline at end of file diff --git a/android-core/src/main/java/com/mparticle/modernization/core/MParticleComponent.kt b/android-core/src/main/java/com/mparticle/modernization/core/MParticleComponent.kt new file mode 100644 index 000000000..2ef459394 --- /dev/null +++ b/android-core/src/main/java/com/mparticle/modernization/core/MParticleComponent.kt @@ -0,0 +1,3 @@ +package com.mparticle.modernization.core + +interface MParticleComponent \ No newline at end of file diff --git a/android-core/src/main/java/com/mparticle/modernization/core/MParticleException.kt b/android-core/src/main/java/com/mparticle/modernization/core/MParticleException.kt new file mode 100644 index 000000000..3403fb68e --- /dev/null +++ b/android-core/src/main/java/com/mparticle/modernization/core/MParticleException.kt @@ -0,0 +1,7 @@ +package com.mparticle.modernization.core + +abstract class MParticleException(message: String, throwable: Throwable? = null) : + RuntimeException() + +class MParticleInitializationException(message: String = "MParticle must be started before obtaining an instance, please call MParticle.start() first") : + MParticleException(message) \ No newline at end of file diff --git a/android-core/src/main/java/com/mparticle/modernization/core/MParticleMediator.kt b/android-core/src/main/java/com/mparticle/modernization/core/MParticleMediator.kt new file mode 100644 index 000000000..5ca432917 --- /dev/null +++ b/android-core/src/main/java/com/mparticle/modernization/core/MParticleMediator.kt @@ -0,0 +1,53 @@ +package com.mparticle.modernization.core + +import com.mparticle.MParticleOptions +import com.mparticle.modernization.data_uploader.MParticleDataUploader +import com.mparticle.modernization.data_uploader.MParticleDataUploaderImpl +import com.mparticle.modernization.data_uploader.MParticleUploadingStrategy +import com.mparticle.modernization.event_logging.MParticleEventLogging +import com.mparticle.modernization.event_logging.example_impl.MParticleEventLoggingImpl +import com.mparticle.modernization.identity.InternalIdentity +import com.mparticle.modernization.identity.example_impl.MParticleIdentityImpl +import com.mparticle.modernization.kit.KitManagerInternal +import com.mparticle.modernization.kit.MParticleKit +import com.mparticle.modernization.kit.MParticleKitManagerImpl +import com.mparticle.modernization.kit.example_impl.MpKit +import kotlinx.coroutines.CloseableCoroutineDispatcher +import kotlinx.coroutines.CoroutineScope +import kotlinx.coroutines.SupervisorJob +import kotlinx.coroutines.asCoroutineDispatcher +import java.util.concurrent.Executors + +class MParticleMediator { + internal var eventLogging: MParticleEventLogging? = null + internal var identity: InternalIdentity? = null + internal var kitManager: KitManagerInternal? = null + internal var dataUploader: MParticleDataUploader? = null + + private var kits: MutableList = mutableListOf() + private var mParticleUploadingStrategies: List = listOf() + + internal lateinit var coroutineScope: CoroutineScope + internal lateinit var coroutineDispatcher: CloseableCoroutineDispatcher + + fun configure(options: MParticleOptions) { + coroutineScope = CoroutineScope(SupervisorJob()) + coroutineDispatcher = Executors.newCachedThreadPool().asCoroutineDispatcher() + kits = registerKits(options) + registerComponent(MParticleKitManagerImpl(kits)) + registerComponent(MParticleIdentityImpl(this)) + registerComponent(MParticleEventLoggingImpl(this)) + registerComponent(MParticleDataUploaderImpl(this, mParticleUploadingStrategies, null)) + } + + private fun registerKits(options: MParticleOptions): MutableList = + mutableListOf(MpKit(this)) + + private fun registerComponent(component: MParticleComponent) { + when (component) { + is InternalIdentity -> identity = component + is KitManagerInternal -> kitManager = component + is MParticleEventLogging -> eventLogging = component + } + } +} \ No newline at end of file diff --git a/android-core/src/main/java/com/mparticle/modernization/data/MParticleDataRepository.kt b/android-core/src/main/java/com/mparticle/modernization/data/MParticleDataRepository.kt new file mode 100644 index 000000000..5245d280c --- /dev/null +++ b/android-core/src/main/java/com/mparticle/modernization/data/MParticleDataRepository.kt @@ -0,0 +1,10 @@ +package com.mparticle.modernization.data + +import com.mparticle.internal.messages.BaseMPMessage + +class MParticleDataRepository { + + suspend fun updateSession(data : BaseMPMessage) {} + + suspend fun insertBreadcrumb(data : BaseMPMessage) {} +} \ No newline at end of file diff --git a/android-core/src/main/java/com/mparticle/modernization/data_uploader/MParticleBroadcastReceiver.kt b/android-core/src/main/java/com/mparticle/modernization/data_uploader/MParticleBroadcastReceiver.kt deleted file mode 100644 index 9ffce0ddc..000000000 --- a/android-core/src/main/java/com/mparticle/modernization/data_uploader/MParticleBroadcastReceiver.kt +++ /dev/null @@ -1,14 +0,0 @@ -package com.mparticle.modernization.data_uploader - -import android.content.BroadcastReceiver -import android.content.Context -import android.content.Intent -import com.mparticle.modernization.MParticle - -class MParticleBroadcastReceiver : BroadcastReceiver(){ - val uploader : MParticleDataUploader? = MParticle.getInstance().DataUploading() - - override fun onReceive(context: Context?, intent: Intent?) { - - } -} \ No newline at end of file diff --git a/android-core/src/main/java/com/mparticle/modernization/data_uploader/MParticleDataRepository.kt b/android-core/src/main/java/com/mparticle/modernization/data_uploader/MParticleDataRepository.kt deleted file mode 100644 index 26cb97285..000000000 --- a/android-core/src/main/java/com/mparticle/modernization/data_uploader/MParticleDataRepository.kt +++ /dev/null @@ -1,4 +0,0 @@ -package com.mparticle.modernization.data_uploader - -class MParticleDataRepository { -} \ No newline at end of file diff --git a/android-core/src/main/java/com/mparticle/modernization/data_uploader/MParticleDataUploader.kt b/android-core/src/main/java/com/mparticle/modernization/data_uploader/MParticleDataUploader.kt index 64f0a13e0..d288b80f0 100644 --- a/android-core/src/main/java/com/mparticle/modernization/data_uploader/MParticleDataUploader.kt +++ b/android-core/src/main/java/com/mparticle/modernization/data_uploader/MParticleDataUploader.kt @@ -1,8 +1,24 @@ package com.mparticle.modernization.data_uploader -import com.mparticle.modernization.MParticleComponent +import com.mparticle.modernization.core.MParticleComponent +import org.jetbrains.annotations.NotNull interface MParticleDataUploader : MParticleComponent { + /** + * Upload set of data using provided strategies. Decision made base on [type] + * + * @param data any type of data. Each strategy is responsible of converting and handling the data + * @param type an int (we recommend creating an enum class defining the types, each with and Int value + * @param immediateUpload true or false depending if we want to force immediate data upload. By + * default this is false + */ + suspend fun upload( + @NotNull data: Any, @NotNull type: Int, @NotNull immediateUpload: Boolean = false + ) - fun upload() {} -} \ No newline at end of file + /** + * Trigger data uploader configuration. Called on DataUploader initialization + */ + suspend fun configure() {} + +} diff --git a/android-core/src/main/java/com/mparticle/modernization/data_uploader/MParticleDataUploaderImpl.kt b/android-core/src/main/java/com/mparticle/modernization/data_uploader/MParticleDataUploaderImpl.kt new file mode 100644 index 000000000..222ccc35b --- /dev/null +++ b/android-core/src/main/java/com/mparticle/modernization/data_uploader/MParticleDataUploaderImpl.kt @@ -0,0 +1,27 @@ +package com.mparticle.modernization.data_uploader + +import com.mparticle.modernization.core.MParticleMediator +import com.mparticle.modernization.config.UploadingConfiguration +import com.mparticle.modernization.launch + +internal class MParticleDataUploaderImpl( + private val mediator: MParticleMediator, + private val strategies: List, + private val uploadingConfiguration: UploadingConfiguration? = null +) : MParticleDataUploader { + init { + mediator.launch { configure() } + } + + override suspend fun upload(data: Any, type: Int, immediateUpload: Boolean) { + type.getStrategy()?.upload(data, immediateUpload, uploadingConfiguration) + } + + override suspend fun configure() { + //setup uploading every X based on uploadingConfiguration rules and server settings we might inject + } + + private fun Int.getStrategy(): MParticleUploadingStrategy? = + strategies.firstOrNull { it.type() == this } + +} \ No newline at end of file diff --git a/android-core/src/main/java/com/mparticle/modernization/data_uploader/MParticleDataUploadingStrategy.kt b/android-core/src/main/java/com/mparticle/modernization/data_uploader/MParticleDataUploadingStrategy.kt deleted file mode 100644 index b8e7ae44f..000000000 --- a/android-core/src/main/java/com/mparticle/modernization/data_uploader/MParticleDataUploadingStrategy.kt +++ /dev/null @@ -1,4 +0,0 @@ -package com.mparticle.modernization.data_uploader - -class MParticleDataUploadingStrategy { -} \ No newline at end of file diff --git a/android-core/src/main/java/com/mparticle/modernization/data_uploader/MParticleFakeDataUploadingImpl.kt b/android-core/src/main/java/com/mparticle/modernization/data_uploader/MParticleFakeDataUploadingImpl.kt deleted file mode 100644 index 21c78fe58..000000000 --- a/android-core/src/main/java/com/mparticle/modernization/data_uploader/MParticleFakeDataUploadingImpl.kt +++ /dev/null @@ -1,6 +0,0 @@ -package com.mparticle.modernization.data_uploader - -import com.mparticle.modernization.MParticleMediator - -internal class MParticleFakeDataUploadingImpl(private val mediator : MParticleMediator) : MParticleDataUploader { -} \ No newline at end of file diff --git a/android-core/src/main/java/com/mparticle/modernization/data_uploader/MParticleHistoryUploadingStrategy.kt b/android-core/src/main/java/com/mparticle/modernization/data_uploader/MParticleHistoryUploadingStrategy.kt deleted file mode 100644 index be35e506a..000000000 --- a/android-core/src/main/java/com/mparticle/modernization/data_uploader/MParticleHistoryUploadingStrategy.kt +++ /dev/null @@ -1,4 +0,0 @@ -package com.mparticle.modernization.data_uploader - -class MParticleHistoryUploadingStrategy { -} \ No newline at end of file diff --git a/android-core/src/main/java/com/mparticle/modernization/data_uploader/MParticleUploadingStrategy.kt b/android-core/src/main/java/com/mparticle/modernization/data_uploader/MParticleUploadingStrategy.kt index 8792a86ef..120258ae5 100644 --- a/android-core/src/main/java/com/mparticle/modernization/data_uploader/MParticleUploadingStrategy.kt +++ b/android-core/src/main/java/com/mparticle/modernization/data_uploader/MParticleUploadingStrategy.kt @@ -1,4 +1,29 @@ package com.mparticle.modernization.data_uploader +import com.mparticle.modernization.config.UploadingConfiguration +import org.jetbrains.annotations.NotNull +import org.jetbrains.annotations.Nullable + +/** + * Data uploading strategies for different data types + */ interface MParticleUploadingStrategy { + /** Upload set of data + * + * @param data any type of data to upload + * @param immediateUpload true or false depending if we want to force immediate data upload. By + * default this is false + * @param uploadingConfiguration to handle auto-data uploads or other custom implementation based + * on a configuration. + */ + suspend fun upload( + @NotNull data: Any, + @NotNull immediateUpload: Boolean, + @Nullable uploadingConfiguration: UploadingConfiguration? + ) + + /** + * @return strategy id + */ + fun type(): Int } \ No newline at end of file diff --git a/android-core/src/main/java/com/mparticle/modernization/data_uploader/example_impl/MParticleBreadcrumbUploading.kt b/android-core/src/main/java/com/mparticle/modernization/data_uploader/example_impl/MParticleBreadcrumbUploading.kt new file mode 100644 index 000000000..c94d768d6 --- /dev/null +++ b/android-core/src/main/java/com/mparticle/modernization/data_uploader/example_impl/MParticleBreadcrumbUploading.kt @@ -0,0 +1,42 @@ +package com.mparticle.modernization.data_uploader.example_impl + +import com.mparticle.internal.messages.BaseMPMessage +import com.mparticle.modernization.config.UploadingConfiguration +import com.mparticle.modernization.data.MParticleDataRepository +import com.mparticle.modernization.data_uploader.MParticleUploadingStrategy + +class MParticleBreadcrumbUploading(private val dataRepository: MParticleDataRepository) : + MParticleUploadingStrategy { + override suspend fun upload( + data: Any, + immediateUpload: Boolean, + uploadingConfiguration: UploadingConfiguration? + ) { + data.convert()?.let { + with(dataRepository) { + updateSession(it) + it.addBreadcurmbData()?.let { insertBreadcrumb(it) } + } + } + if(immediateUpload){ sendData()} + } + + private suspend fun sendData(){} + + private fun BaseMPMessage?.addBreadcurmbData(): BaseMPMessage? = null + private fun Any.convert(): BaseMPMessage? { +// val message = BaseMPMessage.Builder(Constants.MessageType.BREADCRUMB). +// .timestamp(mAppStateManager.getSession().mLastEventTime) +// .build(mAppStateManager.getSession(), mLocation, mConfigManager.getMpid()) +// +// message.put(MessageKey.EVENT_START_TIME, mAppStateManager.getSession().mLastEventTime) +// message.put( +// MessageKey.BREADCRUMB_SESSION_COUNTER, +// mConfigManager.getUserStorage().getCurrentSessionCounter() +// ) +// message.put(MessageKey.BREADCRUMB_LABEL, breadcrumb) + return null + } + + override fun type(): Int = MParticleUploaderTypes.BREADCRUMB.type +} \ No newline at end of file diff --git a/android-core/src/main/java/com/mparticle/modernization/data_uploader/example_impl/MParticleUploaderTypes.kt b/android-core/src/main/java/com/mparticle/modernization/data_uploader/example_impl/MParticleUploaderTypes.kt new file mode 100644 index 000000000..6df721bcb --- /dev/null +++ b/android-core/src/main/java/com/mparticle/modernization/data_uploader/example_impl/MParticleUploaderTypes.kt @@ -0,0 +1,5 @@ +package com.mparticle.modernization.data_uploader.example_impl + +enum class MParticleUploaderTypes(val type: Int) { + EVENT(1), BREADCRUMB(2), DEFAULT(-1); +} \ No newline at end of file diff --git a/android-core/src/main/java/com/mparticle/modernization/event_logging/MParticleEventLogging.kt b/android-core/src/main/java/com/mparticle/modernization/event_logging/MParticleEventLogging.kt index 19d76276e..af71dba76 100644 --- a/android-core/src/main/java/com/mparticle/modernization/event_logging/MParticleEventLogging.kt +++ b/android-core/src/main/java/com/mparticle/modernization/event_logging/MParticleEventLogging.kt @@ -1,14 +1,53 @@ package com.mparticle.modernization.event_logging import com.mparticle.BaseEvent -import com.mparticle.modernization.MParticleComponent +import com.mparticle.modernization.core.MParticleComponent +import org.jetbrains.annotations.NotNull +import org.jetbrains.annotations.Nullable import java.math.BigDecimal interface MParticleEventLogging : MParticleComponent { //All common, commerce, screen, pushRegistration, notification, notificationOpened and NetworkPerformance events should be logged with the same function - fun logEvent(event: BaseEvent) - fun leaveBreadcrumb(breadcrumb: String) - fun logError(message: String, params: Map? = null) - fun logLtvIncrease(valueIncreased: BigDecimal, eventName: String? = null, params: Map? = null) - fun logException(exception: Exception, message: String? = null, params: Map? = null) + /** + * Log an event - TODO review EventBuilder to be able to build all type of events + * @param event to log + */ + fun logEvent(@NotNull event: BaseEvent) + + /** + * Leave breadcrumb + * @param breadcrumb + */ + fun leaveBreadcrumb(@NotNull breadcrumb: String) + + /** + * Log an error + * @param message + * @param params optional by default null + */ + fun logError(@NotNull message: String, @Nullable params: Map? = null) + + /** + * Log lifetime value increase + * @param valueIncreased + * @param eventName optional by default null + * @param params optional by default null + */ + fun logLtvIncrease( + @NotNull valueIncreased: BigDecimal, + @Nullable eventName: String? = null, + @Nullable params: Map? = null + ) + + /** + * Log exception + * @param exception + * @param message optional by default null + * @param params optional by default null + */ + fun logException( + @NotNull exception: Exception, + @Nullable message: String? = null, + @Nullable params: Map? = null + ) } \ No newline at end of file diff --git a/android-core/src/main/java/com/mparticle/modernization/event_logging/MParticleFakeEventLoggingImpl.kt b/android-core/src/main/java/com/mparticle/modernization/event_logging/MParticleFakeEventLoggingImpl.kt deleted file mode 100644 index 3f2760a37..000000000 --- a/android-core/src/main/java/com/mparticle/modernization/event_logging/MParticleFakeEventLoggingImpl.kt +++ /dev/null @@ -1,40 +0,0 @@ -package com.mparticle.modernization.event_logging - -import com.mparticle.BaseEvent -import com.mparticle.MParticleOptions -import com.mparticle.internal.KitManager -import com.mparticle.modernization.MParticleMediator -import com.mparticle.modernization.identity.IdentityCallback -import com.mparticle.modernization.kit.MParticleKit -import java.math.BigDecimal - -internal class MParticleFakeEventLoggingImpl(private val mediator: MParticleMediator ) : MParticleEventLogging { - - override fun logEvent(event: BaseEvent) { - TODO("Not yet implemented") - } - - override fun leaveBreadcrumb(breadcrumb: String) { - mediator.kitManager?.leaveBreadcrumb(breadcrumb) - } - - override fun logError(message: String, params: Map?) { - TODO("Not yet implemented") - } - - override fun logLtvIncrease( - valueIncreased: BigDecimal, - eventName: String?, - params: Map? - ) { - TODO("Not yet implemented") - } - - override fun logException( - exception: Exception, - message: String?, - params: Map? - ) { - TODO("Not yet implemented") - } -} \ No newline at end of file diff --git a/android-core/src/main/java/com/mparticle/modernization/kit/MpKit.kt b/android-core/src/main/java/com/mparticle/modernization/event_logging/example_impl/MParticleEventLoggingImpl.kt similarity index 65% rename from android-core/src/main/java/com/mparticle/modernization/kit/MpKit.kt rename to android-core/src/main/java/com/mparticle/modernization/event_logging/example_impl/MParticleEventLoggingImpl.kt index 335e49ec2..a0778987d 100644 --- a/android-core/src/main/java/com/mparticle/modernization/kit/MpKit.kt +++ b/android-core/src/main/java/com/mparticle/modernization/event_logging/example_impl/MParticleEventLoggingImpl.kt @@ -1,16 +1,19 @@ -package com.mparticle.modernization.kit +package com.mparticle.modernization.event_logging.example_impl import com.mparticle.BaseEvent -import com.mparticle.modernization.MParticleMediator +import com.mparticle.modernization.core.MParticleMediator +import com.mparticle.modernization.event_logging.MParticleEventLogging import java.math.BigDecimal - class MpKit(private val mediator: MParticleMediator) : MParticleKitInternal(){ +internal class MParticleEventLoggingImpl(private val mediator: MParticleMediator) : + MParticleEventLogging { + override fun logEvent(event: BaseEvent) { TODO("Not yet implemented") } override fun leaveBreadcrumb(breadcrumb: String) { - TODO("Not yet implemented") + mediator.kitManager?.leaveBreadcrumb(breadcrumb) } override fun logError(message: String, params: Map?) { diff --git a/android-core/src/main/java/com/mparticle/modernization/identity/MParticleIdentity.kt b/android-core/src/main/java/com/mparticle/modernization/identity/MParticleIdentity.kt index 37cc7ce84..c0f73b589 100644 --- a/android-core/src/main/java/com/mparticle/modernization/identity/MParticleIdentity.kt +++ b/android-core/src/main/java/com/mparticle/modernization/identity/MParticleIdentity.kt @@ -4,27 +4,91 @@ import com.mparticle.identity.IdentityApiRequest import com.mparticle.identity.IdentityApiResult import com.mparticle.identity.MParticleUser import com.mparticle.modernization.MParticleCallback -import com.mparticle.modernization.MParticleComponent +import com.mparticle.modernization.core.MParticleComponent +import org.jetbrains.annotations.NotNull +import org.jetbrains.annotations.Nullable interface MParticleIdentity : MParticleComponent { - fun login(callback: IdentityCallback) - fun logout(callback: IdentityCallback) + /** + * Login + * @param callback + */ + fun login(@NotNull callback: IdentityCallback) - //Will return the user with id or current user - fun getUser(mpId: Long?, callback: IdentityCallback) - fun getUsers(callback: MParticleCallback, Unit>) + /** + * Logout + * @param callback + */ + fun logout(@NotNull callback: IdentityCallback) - //Coroutines - suspend fun getUser(mpId: Long) : IdentityApiResult + /** + * Returns the user by id or the current user if [mpId] is null + * @param mpId if null returns the current user, if not the user by id + * @param callback + */ + fun getUser(@Nullable mpId: Long?, @NotNull callback: IdentityCallback) + + /** + * Return all users + * @param callback + */ + fun getUsers(@NotNull callback: MParticleCallback, Unit>) + + /** + * Returns the user by id or the current user if [mpId] is null + * @param mpId if null returns the current user, if not the user by id + * @return identityApiResult + */ + suspend fun getUser(@Nullable mpId: Long?): IdentityApiResult + + /** + * Return all users + * @return mParicleUsers in a list + */ suspend fun getUsers(): List + + /** + * Login + * @return identityApiResult + */ suspend fun login(): IdentityApiResult + + /** + * Logout + * @return identityApiResult + */ suspend fun logout(): IdentityApiResult } internal interface InternalIdentity : MParticleIdentity { - suspend fun identify(request: IdentityApiRequest): IdentityApiResult - suspend fun modify(request: IdentityApiRequest): IdentityApiResult - suspend fun logout(request: IdentityApiRequest): IdentityApiResult - suspend fun login(request: IdentityApiRequest): IdentityApiResult -} \ No newline at end of file + /** + * Identify api request call + * @param request + * @return identityApiResult + */ + suspend fun identify(@NotNull request: IdentityApiRequest): IdentityApiResult + + /** + * Modify api request call + * @param request + * @return identityApiResult + */ + suspend fun modify(@NotNull request: IdentityApiRequest): IdentityApiResult + + /** + * Logout api request call + * @param request + * @return identityApiResult + */ + suspend fun logout(@NotNull request: IdentityApiRequest): IdentityApiResult + + /** + * Login api request call + * @param request + * @return identityApiResult + */ + suspend fun login(@NotNull request: IdentityApiRequest): IdentityApiResult +} + +interface IdentityListener \ No newline at end of file diff --git a/android-core/src/main/java/com/mparticle/modernization/identity/MParticleFakeIdentityImpl.kt b/android-core/src/main/java/com/mparticle/modernization/identity/example_impl/MParticleIdentityImpl.kt similarity index 79% rename from android-core/src/main/java/com/mparticle/modernization/identity/MParticleFakeIdentityImpl.kt rename to android-core/src/main/java/com/mparticle/modernization/identity/example_impl/MParticleIdentityImpl.kt index ba904f280..5bbea6740 100644 --- a/android-core/src/main/java/com/mparticle/modernization/identity/MParticleFakeIdentityImpl.kt +++ b/android-core/src/main/java/com/mparticle/modernization/identity/example_impl/MParticleIdentityImpl.kt @@ -1,12 +1,14 @@ -package com.mparticle.modernization.identity +package com.mparticle.modernization.identity.example_impl import com.mparticle.identity.IdentityApiRequest import com.mparticle.identity.IdentityApiResult import com.mparticle.identity.MParticleUser import com.mparticle.modernization.MParticleCallback -import com.mparticle.modernization.MParticleMediator +import com.mparticle.modernization.core.MParticleMediator +import com.mparticle.modernization.identity.IdentityCallback +import com.mparticle.modernization.identity.InternalIdentity -internal class MParticleFakeIdentityImpl(private val mediator : MParticleMediator) : +internal class MParticleIdentityImpl(private val mediator: MParticleMediator) : InternalIdentity { override suspend fun identify(request: IdentityApiRequest): IdentityApiResult { TODO("Not yet implemented") @@ -44,7 +46,7 @@ internal class MParticleFakeIdentityImpl(private val mediator : MParticleMediato TODO("Not yet implemented") } - override suspend fun getUser(mpId: Long): IdentityApiResult { + override suspend fun getUser(mpId: Long?): IdentityApiResult { TODO("Not yet implemented") } diff --git a/android-core/src/main/java/com/mparticle/modernization/kit/MParticleKit.kt b/android-core/src/main/java/com/mparticle/modernization/kit/MParticleKit.kt index 9a1b48e4d..50ac2f287 100644 --- a/android-core/src/main/java/com/mparticle/modernization/kit/MParticleKit.kt +++ b/android-core/src/main/java/com/mparticle/modernization/kit/MParticleKit.kt @@ -1,25 +1,33 @@ package com.mparticle.modernization.kit import com.mparticle.BaseEvent +import com.mparticle.modernization.event_logging.MParticleEventLogging import java.math.BigDecimal -abstract class MParticleKit { - open fun logEvent(event: BaseEvent) {} - open fun leaveBreadcrumb(breadcrumb: String) {} - open fun logError(message: String, params: Map? = null) {} - open fun logLtvIncrease( - valueIncreased: BigDecimal, - eventName: String? = null, - params: Map? = null - ) { +abstract class MParticleKit : MParticleEventLogging { + + override fun logEvent(event: BaseEvent) { } - open fun logException( + override fun leaveBreadcrumb(breadcrumb: String) { + } + + override fun logError(message: String, params: Map?) { + } + + override fun logException( exception: Exception, - message: String? = null, - params: Map? = null + message: String?, + params: Map? + ) { + } + + override fun logLtvIncrease( + valueIncreased: BigDecimal, + eventName: String?, + params: Map? ) { } } - abstract class MParticleKitInternal : MParticleKit() \ No newline at end of file +abstract class MParticleKitInternal : MParticleKit() \ No newline at end of file diff --git a/android-core/src/main/java/com/mparticle/modernization/kit/MParticleKitManager.kt b/android-core/src/main/java/com/mparticle/modernization/kit/MParticleKitManager.kt index 3a8c6c216..887d9c5a1 100644 --- a/android-core/src/main/java/com/mparticle/modernization/kit/MParticleKitManager.kt +++ b/android-core/src/main/java/com/mparticle/modernization/kit/MParticleKitManager.kt @@ -1,7 +1,7 @@ package com.mparticle.modernization.kit -import com.mparticle.modernization.MParticleComponent +import com.mparticle.modernization.core.MParticleComponent + +abstract class MParticleKitManager : MParticleKit() -abstract class MParticleKitManager : MParticleKit() { -} abstract class KitManagerInternal : MParticleKitManager(), MParticleComponent \ No newline at end of file diff --git a/android-core/src/main/java/com/mparticle/modernization/kit/MParticleKitManagerImpl.kt b/android-core/src/main/java/com/mparticle/modernization/kit/MParticleKitManagerImpl.kt index 1f0f82a1d..b7d5115a9 100644 --- a/android-core/src/main/java/com/mparticle/modernization/kit/MParticleKitManagerImpl.kt +++ b/android-core/src/main/java/com/mparticle/modernization/kit/MParticleKitManagerImpl.kt @@ -1,38 +1,10 @@ package com.mparticle.modernization.kit -import com.mparticle.BaseEvent -import com.mparticle.modernization.MParticleMediator -import java.math.BigDecimal - internal class MParticleKitManagerImpl( private val kits: MutableList ) : KitManagerInternal() { - override fun logEvent(event: BaseEvent) { - TODO("Not yet implemented") - } - override fun leaveBreadcrumb(breadcrumb: String) { - kits.forEach { it.leaveBreadcrumb(breadcrumb) } - } - - override fun logError(message: String, params: Map?) { - TODO("Not yet implemented") - } - - override fun logLtvIncrease( - valueIncreased: BigDecimal, - eventName: String?, - params: Map? - ) { - TODO("Not yet implemented") - } - - override fun logException( - exception: Exception, - message: String?, - params: Map? - ) { - TODO("Not yet implemented") + kits.forEach { it.leaveBreadcrumb(breadcrumb) } } } \ No newline at end of file diff --git a/android-core/src/main/java/com/mparticle/modernization/kit/example_impl/CustomKit.kt b/android-core/src/main/java/com/mparticle/modernization/kit/example_impl/CustomKit.kt new file mode 100644 index 000000000..e58c4803c --- /dev/null +++ b/android-core/src/main/java/com/mparticle/modernization/kit/example_impl/CustomKit.kt @@ -0,0 +1,11 @@ +package com.mparticle.modernization.kit.example_impl + +import android.util.Log +import com.mparticle.BaseEvent +import com.mparticle.modernization.kit.MParticleKit + +class CustomKit : MParticleKit() { + override fun logEvent(event: BaseEvent) { + Log.d("CUSTOM_LOG", event.toString()) + } +} \ No newline at end of file diff --git a/android-core/src/main/java/com/mparticle/modernization/kit/example_impl/MpKit.kt b/android-core/src/main/java/com/mparticle/modernization/kit/example_impl/MpKit.kt new file mode 100644 index 000000000..5ec113eb4 --- /dev/null +++ b/android-core/src/main/java/com/mparticle/modernization/kit/example_impl/MpKit.kt @@ -0,0 +1,16 @@ +package com.mparticle.modernization.kit.example_impl + +import com.mparticle.modernization.core.MParticleMediator +import com.mparticle.modernization.data_uploader.example_impl.MParticleUploaderTypes +import com.mparticle.modernization.kit.MParticleKitInternal +import com.mparticle.modernization.launch + +class MpKit(private val mediator: MParticleMediator) : MParticleKitInternal() { + + override fun leaveBreadcrumb(breadcrumb: String) { + mediator.launch { + mediator.dataUploader?.upload(breadcrumb, MParticleUploaderTypes.BREADCRUMB.type) + } + } + +} \ No newline at end of file diff --git a/android-core/src/main/java/com/mparticle/modernization/kit/XKit.kt b/android-core/src/main/java/com/mparticle/modernization/kit/example_impl/XKit.kt similarity index 50% rename from android-core/src/main/java/com/mparticle/modernization/kit/XKit.kt rename to android-core/src/main/java/com/mparticle/modernization/kit/example_impl/XKit.kt index aa13a8529..b0fc09edd 100644 --- a/android-core/src/main/java/com/mparticle/modernization/kit/XKit.kt +++ b/android-core/src/main/java/com/mparticle/modernization/kit/example_impl/XKit.kt @@ -1,10 +1,10 @@ -package com.mparticle.modernization.kit +package com.mparticle.modernization.kit.example_impl import com.mparticle.BaseEvent -import com.mparticle.modernization.MParticleMediator -import java.math.BigDecimal +import com.mparticle.modernization.core.MParticleMediator +import com.mparticle.modernization.kit.MParticleKitInternal -class XKit(private val mediator: MParticleMediator) : MParticleKitInternal(){ +class XKit(private val mediator: MParticleMediator) : MParticleKitInternal() { override fun logEvent(event: BaseEvent) { TODO("Not yet implemented") } From 82802fe8d6a000a5fb8cdf492d9fd1942be719da Mon Sep 17 00:00:00 2001 From: markvdouw Date: Tue, 28 Feb 2023 21:09:30 -0300 Subject: [PATCH 4/9] KtlintFormat --- .../src/main/java/com/mparticle/modernization/Utils.kt | 2 +- .../modernization/config/UploadingConfiguration.kt | 2 +- .../java/com/mparticle/modernization/core/MParticle.kt | 2 +- .../com/mparticle/modernization/core/MParticleComponent.kt | 2 +- .../com/mparticle/modernization/core/MParticleException.kt | 2 +- .../com/mparticle/modernization/core/MParticleMediator.kt | 2 +- .../modernization/data/MParticleDataRepository.kt | 6 +++--- .../modernization/data_uploader/MParticleDataUploader.kt | 5 +++-- .../data_uploader/MParticleDataUploaderImpl.kt | 7 +++---- .../data_uploader/MParticleUploadingStrategy.kt | 2 +- .../example_impl/MParticleBreadcrumbUploading.kt | 6 +++--- .../data_uploader/example_impl/MParticleUploaderTypes.kt | 2 +- .../modernization/event_logging/MParticleEventLogging.kt | 4 ++-- .../example_impl/MParticleEventLoggingImpl.kt | 2 +- .../mparticle/modernization/identity/IdentityCallback.kt | 2 +- .../mparticle/modernization/identity/MParticleIdentity.kt | 2 +- .../identity/example_impl/MParticleIdentityImpl.kt | 3 +-- .../java/com/mparticle/modernization/kit/MParticleKit.kt | 2 +- .../com/mparticle/modernization/kit/MParticleKitManager.kt | 2 +- .../mparticle/modernization/kit/MParticleKitManagerImpl.kt | 2 +- .../mparticle/modernization/kit/example_impl/CustomKit.kt | 2 +- .../com/mparticle/modernization/kit/example_impl/MpKit.kt | 3 +-- .../com/mparticle/modernization/kit/example_impl/XKit.kt | 3 +-- 23 files changed, 32 insertions(+), 35 deletions(-) diff --git a/android-core/src/main/java/com/mparticle/modernization/Utils.kt b/android-core/src/main/java/com/mparticle/modernization/Utils.kt index bf4912f50..2ccea77f3 100644 --- a/android-core/src/main/java/com/mparticle/modernization/Utils.kt +++ b/android-core/src/main/java/com/mparticle/modernization/Utils.kt @@ -6,4 +6,4 @@ import kotlinx.coroutines.launch fun MParticleMediator.launch(block: suspend CoroutineScope.() -> Unit) { this.coroutineScope.launch(this.coroutineDispatcher) { block } -} \ No newline at end of file +} diff --git a/android-core/src/main/java/com/mparticle/modernization/config/UploadingConfiguration.kt b/android-core/src/main/java/com/mparticle/modernization/config/UploadingConfiguration.kt index 5816c232c..63627ba37 100644 --- a/android-core/src/main/java/com/mparticle/modernization/config/UploadingConfiguration.kt +++ b/android-core/src/main/java/com/mparticle/modernization/config/UploadingConfiguration.kt @@ -1,3 +1,3 @@ package com.mparticle.modernization.config -interface UploadingConfiguration \ No newline at end of file +interface UploadingConfiguration diff --git a/android-core/src/main/java/com/mparticle/modernization/core/MParticle.kt b/android-core/src/main/java/com/mparticle/modernization/core/MParticle.kt index 627a6a539..1db79850d 100644 --- a/android-core/src/main/java/com/mparticle/modernization/core/MParticle.kt +++ b/android-core/src/main/java/com/mparticle/modernization/core/MParticle.kt @@ -28,4 +28,4 @@ class MParticle private constructor(private val options: MParticleOptions) { fun Identity(): MParticleIdentity? = mediator.identity as MParticleIdentity? fun EventLogging(): MParticleEventLogging? = mediator.eventLogging fun DataUploading(): MParticleDataUploader? = mediator.dataUploader -} \ No newline at end of file +} diff --git a/android-core/src/main/java/com/mparticle/modernization/core/MParticleComponent.kt b/android-core/src/main/java/com/mparticle/modernization/core/MParticleComponent.kt index 2ef459394..e8b9e6d5d 100644 --- a/android-core/src/main/java/com/mparticle/modernization/core/MParticleComponent.kt +++ b/android-core/src/main/java/com/mparticle/modernization/core/MParticleComponent.kt @@ -1,3 +1,3 @@ package com.mparticle.modernization.core -interface MParticleComponent \ No newline at end of file +interface MParticleComponent diff --git a/android-core/src/main/java/com/mparticle/modernization/core/MParticleException.kt b/android-core/src/main/java/com/mparticle/modernization/core/MParticleException.kt index 3403fb68e..d5f0363a0 100644 --- a/android-core/src/main/java/com/mparticle/modernization/core/MParticleException.kt +++ b/android-core/src/main/java/com/mparticle/modernization/core/MParticleException.kt @@ -4,4 +4,4 @@ abstract class MParticleException(message: String, throwable: Throwable? = null) RuntimeException() class MParticleInitializationException(message: String = "MParticle must be started before obtaining an instance, please call MParticle.start() first") : - MParticleException(message) \ No newline at end of file + MParticleException(message) diff --git a/android-core/src/main/java/com/mparticle/modernization/core/MParticleMediator.kt b/android-core/src/main/java/com/mparticle/modernization/core/MParticleMediator.kt index 5ca432917..f636edf43 100644 --- a/android-core/src/main/java/com/mparticle/modernization/core/MParticleMediator.kt +++ b/android-core/src/main/java/com/mparticle/modernization/core/MParticleMediator.kt @@ -50,4 +50,4 @@ class MParticleMediator { is MParticleEventLogging -> eventLogging = component } } -} \ No newline at end of file +} diff --git a/android-core/src/main/java/com/mparticle/modernization/data/MParticleDataRepository.kt b/android-core/src/main/java/com/mparticle/modernization/data/MParticleDataRepository.kt index 5245d280c..0ab555939 100644 --- a/android-core/src/main/java/com/mparticle/modernization/data/MParticleDataRepository.kt +++ b/android-core/src/main/java/com/mparticle/modernization/data/MParticleDataRepository.kt @@ -4,7 +4,7 @@ import com.mparticle.internal.messages.BaseMPMessage class MParticleDataRepository { - suspend fun updateSession(data : BaseMPMessage) {} + suspend fun updateSession(data: BaseMPMessage) {} - suspend fun insertBreadcrumb(data : BaseMPMessage) {} -} \ No newline at end of file + suspend fun insertBreadcrumb(data: BaseMPMessage) {} +} diff --git a/android-core/src/main/java/com/mparticle/modernization/data_uploader/MParticleDataUploader.kt b/android-core/src/main/java/com/mparticle/modernization/data_uploader/MParticleDataUploader.kt index d288b80f0..2cac28a07 100644 --- a/android-core/src/main/java/com/mparticle/modernization/data_uploader/MParticleDataUploader.kt +++ b/android-core/src/main/java/com/mparticle/modernization/data_uploader/MParticleDataUploader.kt @@ -13,12 +13,13 @@ interface MParticleDataUploader : MParticleComponent { * default this is false */ suspend fun upload( - @NotNull data: Any, @NotNull type: Int, @NotNull immediateUpload: Boolean = false + @NotNull data: Any, + @NotNull type: Int, + @NotNull immediateUpload: Boolean = false ) /** * Trigger data uploader configuration. Called on DataUploader initialization */ suspend fun configure() {} - } diff --git a/android-core/src/main/java/com/mparticle/modernization/data_uploader/MParticleDataUploaderImpl.kt b/android-core/src/main/java/com/mparticle/modernization/data_uploader/MParticleDataUploaderImpl.kt index 222ccc35b..56a3d2681 100644 --- a/android-core/src/main/java/com/mparticle/modernization/data_uploader/MParticleDataUploaderImpl.kt +++ b/android-core/src/main/java/com/mparticle/modernization/data_uploader/MParticleDataUploaderImpl.kt @@ -1,7 +1,7 @@ package com.mparticle.modernization.data_uploader -import com.mparticle.modernization.core.MParticleMediator import com.mparticle.modernization.config.UploadingConfiguration +import com.mparticle.modernization.core.MParticleMediator import com.mparticle.modernization.launch internal class MParticleDataUploaderImpl( @@ -18,10 +18,9 @@ internal class MParticleDataUploaderImpl( } override suspend fun configure() { - //setup uploading every X based on uploadingConfiguration rules and server settings we might inject + // setup uploading every X based on uploadingConfiguration rules and server settings we might inject } private fun Int.getStrategy(): MParticleUploadingStrategy? = strategies.firstOrNull { it.type() == this } - -} \ No newline at end of file +} diff --git a/android-core/src/main/java/com/mparticle/modernization/data_uploader/MParticleUploadingStrategy.kt b/android-core/src/main/java/com/mparticle/modernization/data_uploader/MParticleUploadingStrategy.kt index 120258ae5..4017045be 100644 --- a/android-core/src/main/java/com/mparticle/modernization/data_uploader/MParticleUploadingStrategy.kt +++ b/android-core/src/main/java/com/mparticle/modernization/data_uploader/MParticleUploadingStrategy.kt @@ -26,4 +26,4 @@ interface MParticleUploadingStrategy { * @return strategy id */ fun type(): Int -} \ No newline at end of file +} diff --git a/android-core/src/main/java/com/mparticle/modernization/data_uploader/example_impl/MParticleBreadcrumbUploading.kt b/android-core/src/main/java/com/mparticle/modernization/data_uploader/example_impl/MParticleBreadcrumbUploading.kt index c94d768d6..8aab5f474 100644 --- a/android-core/src/main/java/com/mparticle/modernization/data_uploader/example_impl/MParticleBreadcrumbUploading.kt +++ b/android-core/src/main/java/com/mparticle/modernization/data_uploader/example_impl/MParticleBreadcrumbUploading.kt @@ -18,10 +18,10 @@ class MParticleBreadcrumbUploading(private val dataRepository: MParticleDataRepo it.addBreadcurmbData()?.let { insertBreadcrumb(it) } } } - if(immediateUpload){ sendData()} + if (immediateUpload) { sendData() } } - private suspend fun sendData(){} + private suspend fun sendData() {} private fun BaseMPMessage?.addBreadcurmbData(): BaseMPMessage? = null private fun Any.convert(): BaseMPMessage? { @@ -39,4 +39,4 @@ class MParticleBreadcrumbUploading(private val dataRepository: MParticleDataRepo } override fun type(): Int = MParticleUploaderTypes.BREADCRUMB.type -} \ No newline at end of file +} diff --git a/android-core/src/main/java/com/mparticle/modernization/data_uploader/example_impl/MParticleUploaderTypes.kt b/android-core/src/main/java/com/mparticle/modernization/data_uploader/example_impl/MParticleUploaderTypes.kt index 6df721bcb..eb85cfbfb 100644 --- a/android-core/src/main/java/com/mparticle/modernization/data_uploader/example_impl/MParticleUploaderTypes.kt +++ b/android-core/src/main/java/com/mparticle/modernization/data_uploader/example_impl/MParticleUploaderTypes.kt @@ -2,4 +2,4 @@ package com.mparticle.modernization.data_uploader.example_impl enum class MParticleUploaderTypes(val type: Int) { EVENT(1), BREADCRUMB(2), DEFAULT(-1); -} \ No newline at end of file +} diff --git a/android-core/src/main/java/com/mparticle/modernization/event_logging/MParticleEventLogging.kt b/android-core/src/main/java/com/mparticle/modernization/event_logging/MParticleEventLogging.kt index af71dba76..5d8bc79c2 100644 --- a/android-core/src/main/java/com/mparticle/modernization/event_logging/MParticleEventLogging.kt +++ b/android-core/src/main/java/com/mparticle/modernization/event_logging/MParticleEventLogging.kt @@ -7,7 +7,7 @@ import org.jetbrains.annotations.Nullable import java.math.BigDecimal interface MParticleEventLogging : MParticleComponent { - //All common, commerce, screen, pushRegistration, notification, notificationOpened and NetworkPerformance events should be logged with the same function + // All common, commerce, screen, pushRegistration, notification, notificationOpened and NetworkPerformance events should be logged with the same function /** * Log an event - TODO review EventBuilder to be able to build all type of events * @param event to log @@ -50,4 +50,4 @@ interface MParticleEventLogging : MParticleComponent { @Nullable message: String? = null, @Nullable params: Map? = null ) -} \ No newline at end of file +} diff --git a/android-core/src/main/java/com/mparticle/modernization/event_logging/example_impl/MParticleEventLoggingImpl.kt b/android-core/src/main/java/com/mparticle/modernization/event_logging/example_impl/MParticleEventLoggingImpl.kt index a0778987d..dd0ecd866 100644 --- a/android-core/src/main/java/com/mparticle/modernization/event_logging/example_impl/MParticleEventLoggingImpl.kt +++ b/android-core/src/main/java/com/mparticle/modernization/event_logging/example_impl/MParticleEventLoggingImpl.kt @@ -35,4 +35,4 @@ internal class MParticleEventLoggingImpl(private val mediator: MParticleMediator ) { TODO("Not yet implemented") } -} \ No newline at end of file +} diff --git a/android-core/src/main/java/com/mparticle/modernization/identity/IdentityCallback.kt b/android-core/src/main/java/com/mparticle/modernization/identity/IdentityCallback.kt index 1bb038696..5fb310d3d 100644 --- a/android-core/src/main/java/com/mparticle/modernization/identity/IdentityCallback.kt +++ b/android-core/src/main/java/com/mparticle/modernization/identity/IdentityCallback.kt @@ -3,4 +3,4 @@ package com.mparticle.modernization.identity import com.mparticle.identity.IdentityApiResult import com.mparticle.modernization.MParticleCallback -open class IdentityCallback : MParticleCallback() \ No newline at end of file +open class IdentityCallback : MParticleCallback() diff --git a/android-core/src/main/java/com/mparticle/modernization/identity/MParticleIdentity.kt b/android-core/src/main/java/com/mparticle/modernization/identity/MParticleIdentity.kt index c0f73b589..acccdf7d3 100644 --- a/android-core/src/main/java/com/mparticle/modernization/identity/MParticleIdentity.kt +++ b/android-core/src/main/java/com/mparticle/modernization/identity/MParticleIdentity.kt @@ -91,4 +91,4 @@ internal interface InternalIdentity : MParticleIdentity { suspend fun login(@NotNull request: IdentityApiRequest): IdentityApiResult } -interface IdentityListener \ No newline at end of file +interface IdentityListener diff --git a/android-core/src/main/java/com/mparticle/modernization/identity/example_impl/MParticleIdentityImpl.kt b/android-core/src/main/java/com/mparticle/modernization/identity/example_impl/MParticleIdentityImpl.kt index 5bbea6740..ba3a72722 100644 --- a/android-core/src/main/java/com/mparticle/modernization/identity/example_impl/MParticleIdentityImpl.kt +++ b/android-core/src/main/java/com/mparticle/modernization/identity/example_impl/MParticleIdentityImpl.kt @@ -57,5 +57,4 @@ internal class MParticleIdentityImpl(private val mediator: MParticleMediator) : override suspend fun getUsers(): List { TODO("Not yet implemented") } - -} \ No newline at end of file +} diff --git a/android-core/src/main/java/com/mparticle/modernization/kit/MParticleKit.kt b/android-core/src/main/java/com/mparticle/modernization/kit/MParticleKit.kt index 50ac2f287..7b9fb93cc 100644 --- a/android-core/src/main/java/com/mparticle/modernization/kit/MParticleKit.kt +++ b/android-core/src/main/java/com/mparticle/modernization/kit/MParticleKit.kt @@ -30,4 +30,4 @@ abstract class MParticleKit : MParticleEventLogging { } } -abstract class MParticleKitInternal : MParticleKit() \ No newline at end of file +abstract class MParticleKitInternal : MParticleKit() diff --git a/android-core/src/main/java/com/mparticle/modernization/kit/MParticleKitManager.kt b/android-core/src/main/java/com/mparticle/modernization/kit/MParticleKitManager.kt index 887d9c5a1..f3b9b848d 100644 --- a/android-core/src/main/java/com/mparticle/modernization/kit/MParticleKitManager.kt +++ b/android-core/src/main/java/com/mparticle/modernization/kit/MParticleKitManager.kt @@ -4,4 +4,4 @@ import com.mparticle.modernization.core.MParticleComponent abstract class MParticleKitManager : MParticleKit() -abstract class KitManagerInternal : MParticleKitManager(), MParticleComponent \ No newline at end of file +abstract class KitManagerInternal : MParticleKitManager(), MParticleComponent diff --git a/android-core/src/main/java/com/mparticle/modernization/kit/MParticleKitManagerImpl.kt b/android-core/src/main/java/com/mparticle/modernization/kit/MParticleKitManagerImpl.kt index b7d5115a9..96b892f21 100644 --- a/android-core/src/main/java/com/mparticle/modernization/kit/MParticleKitManagerImpl.kt +++ b/android-core/src/main/java/com/mparticle/modernization/kit/MParticleKitManagerImpl.kt @@ -7,4 +7,4 @@ internal class MParticleKitManagerImpl( override fun leaveBreadcrumb(breadcrumb: String) { kits.forEach { it.leaveBreadcrumb(breadcrumb) } } -} \ No newline at end of file +} diff --git a/android-core/src/main/java/com/mparticle/modernization/kit/example_impl/CustomKit.kt b/android-core/src/main/java/com/mparticle/modernization/kit/example_impl/CustomKit.kt index e58c4803c..1b809e716 100644 --- a/android-core/src/main/java/com/mparticle/modernization/kit/example_impl/CustomKit.kt +++ b/android-core/src/main/java/com/mparticle/modernization/kit/example_impl/CustomKit.kt @@ -8,4 +8,4 @@ class CustomKit : MParticleKit() { override fun logEvent(event: BaseEvent) { Log.d("CUSTOM_LOG", event.toString()) } -} \ No newline at end of file +} diff --git a/android-core/src/main/java/com/mparticle/modernization/kit/example_impl/MpKit.kt b/android-core/src/main/java/com/mparticle/modernization/kit/example_impl/MpKit.kt index 5ec113eb4..6ed80ce51 100644 --- a/android-core/src/main/java/com/mparticle/modernization/kit/example_impl/MpKit.kt +++ b/android-core/src/main/java/com/mparticle/modernization/kit/example_impl/MpKit.kt @@ -12,5 +12,4 @@ class MpKit(private val mediator: MParticleMediator) : MParticleKitInternal() { mediator.dataUploader?.upload(breadcrumb, MParticleUploaderTypes.BREADCRUMB.type) } } - -} \ No newline at end of file +} diff --git a/android-core/src/main/java/com/mparticle/modernization/kit/example_impl/XKit.kt b/android-core/src/main/java/com/mparticle/modernization/kit/example_impl/XKit.kt index b0fc09edd..d08917910 100644 --- a/android-core/src/main/java/com/mparticle/modernization/kit/example_impl/XKit.kt +++ b/android-core/src/main/java/com/mparticle/modernization/kit/example_impl/XKit.kt @@ -8,5 +8,4 @@ class XKit(private val mediator: MParticleMediator) : MParticleKitInternal() { override fun logEvent(event: BaseEvent) { TODO("Not yet implemented") } - -} \ No newline at end of file +} From c0a97029ee58aada14fe85e60e3a6275e49a634f Mon Sep 17 00:00:00 2001 From: markvdouw Date: Thu, 2 Mar 2023 13:23:31 -0300 Subject: [PATCH 5/9] Ktlint format --- .../com/mparticle/modernization/core/MParticle.kt | 4 ++-- .../modernization/core/MParticleMediator.kt | 14 +++++++------- .../MParticleEventLogging.kt | 2 +- .../example}/MParticleEventLoggingImpl.kt | 4 ++-- .../MParticleIdentityImpl.kt | 2 +- .../mparticle/modernization/kit/MParticleKit.kt | 2 +- .../kit/{example_impl => example}/CustomKit.kt | 2 +- .../kit/{example_impl => example}/MpKit.kt | 4 ++-- .../kit/{example_impl => example}/XKit.kt | 2 +- .../MParticleDataUploader.kt | 2 +- .../MParticleDataUploaderImpl.kt | 2 +- .../MParticleUploadingStrategy.kt | 2 +- .../example}/MParticleBreadcrumbUploading.kt | 4 ++-- .../example}/MParticleUploaderTypes.kt | 2 +- 14 files changed, 24 insertions(+), 24 deletions(-) rename android-core/src/main/java/com/mparticle/modernization/{event_logging => eventlogging}/MParticleEventLogging.kt (96%) rename android-core/src/main/java/com/mparticle/modernization/{event_logging/example_impl => eventlogging/example}/MParticleEventLoggingImpl.kt (87%) rename android-core/src/main/java/com/mparticle/modernization/identity/{example_impl => example}/MParticleIdentityImpl.kt (96%) rename android-core/src/main/java/com/mparticle/modernization/kit/{example_impl => example}/CustomKit.kt (82%) rename android-core/src/main/java/com/mparticle/modernization/kit/{example_impl => example}/MpKit.kt (75%) rename android-core/src/main/java/com/mparticle/modernization/kit/{example_impl => example}/XKit.kt (85%) rename android-core/src/main/java/com/mparticle/modernization/{data_uploader => uploading}/MParticleDataUploader.kt (94%) rename android-core/src/main/java/com/mparticle/modernization/{data_uploader => uploading}/MParticleDataUploaderImpl.kt (94%) rename android-core/src/main/java/com/mparticle/modernization/{data_uploader => uploading}/MParticleUploadingStrategy.kt (94%) rename android-core/src/main/java/com/mparticle/modernization/{data_uploader/example_impl => uploading/example}/MParticleBreadcrumbUploading.kt (91%) rename android-core/src/main/java/com/mparticle/modernization/{data_uploader/example_impl => uploading/example}/MParticleUploaderTypes.kt (60%) diff --git a/android-core/src/main/java/com/mparticle/modernization/core/MParticle.kt b/android-core/src/main/java/com/mparticle/modernization/core/MParticle.kt index 1db79850d..9552b5782 100644 --- a/android-core/src/main/java/com/mparticle/modernization/core/MParticle.kt +++ b/android-core/src/main/java/com/mparticle/modernization/core/MParticle.kt @@ -1,10 +1,10 @@ package com.mparticle.modernization.core import com.mparticle.MParticleOptions -import com.mparticle.modernization.data_uploader.MParticleDataUploader -import com.mparticle.modernization.event_logging.MParticleEventLogging +import com.mparticle.modernization.eventlogging.MParticleEventLogging import com.mparticle.modernization.identity.MParticleIdentity import com.mparticle.modernization.kit.MParticleKitManager +import com.mparticle.modernization.uploading.MParticleDataUploader class MParticle private constructor(private val options: MParticleOptions) { private var mediator: MParticleMediator = MParticleMediator() diff --git a/android-core/src/main/java/com/mparticle/modernization/core/MParticleMediator.kt b/android-core/src/main/java/com/mparticle/modernization/core/MParticleMediator.kt index f636edf43..0909020df 100644 --- a/android-core/src/main/java/com/mparticle/modernization/core/MParticleMediator.kt +++ b/android-core/src/main/java/com/mparticle/modernization/core/MParticleMediator.kt @@ -1,17 +1,17 @@ package com.mparticle.modernization.core import com.mparticle.MParticleOptions -import com.mparticle.modernization.data_uploader.MParticleDataUploader -import com.mparticle.modernization.data_uploader.MParticleDataUploaderImpl -import com.mparticle.modernization.data_uploader.MParticleUploadingStrategy -import com.mparticle.modernization.event_logging.MParticleEventLogging -import com.mparticle.modernization.event_logging.example_impl.MParticleEventLoggingImpl +import com.mparticle.modernization.eventlogging.MParticleEventLogging +import com.mparticle.modernization.eventlogging.example.MParticleEventLoggingImpl import com.mparticle.modernization.identity.InternalIdentity -import com.mparticle.modernization.identity.example_impl.MParticleIdentityImpl +import com.mparticle.modernization.identity.example.MParticleIdentityImpl import com.mparticle.modernization.kit.KitManagerInternal import com.mparticle.modernization.kit.MParticleKit import com.mparticle.modernization.kit.MParticleKitManagerImpl -import com.mparticle.modernization.kit.example_impl.MpKit +import com.mparticle.modernization.kit.example.MpKit +import com.mparticle.modernization.uploading.MParticleDataUploader +import com.mparticle.modernization.uploading.MParticleDataUploaderImpl +import com.mparticle.modernization.uploading.MParticleUploadingStrategy import kotlinx.coroutines.CloseableCoroutineDispatcher import kotlinx.coroutines.CoroutineScope import kotlinx.coroutines.SupervisorJob diff --git a/android-core/src/main/java/com/mparticle/modernization/event_logging/MParticleEventLogging.kt b/android-core/src/main/java/com/mparticle/modernization/eventlogging/MParticleEventLogging.kt similarity index 96% rename from android-core/src/main/java/com/mparticle/modernization/event_logging/MParticleEventLogging.kt rename to android-core/src/main/java/com/mparticle/modernization/eventlogging/MParticleEventLogging.kt index 5d8bc79c2..bf2245a8e 100644 --- a/android-core/src/main/java/com/mparticle/modernization/event_logging/MParticleEventLogging.kt +++ b/android-core/src/main/java/com/mparticle/modernization/eventlogging/MParticleEventLogging.kt @@ -1,4 +1,4 @@ -package com.mparticle.modernization.event_logging +package com.mparticle.modernization.eventlogging import com.mparticle.BaseEvent import com.mparticle.modernization.core.MParticleComponent diff --git a/android-core/src/main/java/com/mparticle/modernization/event_logging/example_impl/MParticleEventLoggingImpl.kt b/android-core/src/main/java/com/mparticle/modernization/eventlogging/example/MParticleEventLoggingImpl.kt similarity index 87% rename from android-core/src/main/java/com/mparticle/modernization/event_logging/example_impl/MParticleEventLoggingImpl.kt rename to android-core/src/main/java/com/mparticle/modernization/eventlogging/example/MParticleEventLoggingImpl.kt index dd0ecd866..6d031e7de 100644 --- a/android-core/src/main/java/com/mparticle/modernization/event_logging/example_impl/MParticleEventLoggingImpl.kt +++ b/android-core/src/main/java/com/mparticle/modernization/eventlogging/example/MParticleEventLoggingImpl.kt @@ -1,8 +1,8 @@ -package com.mparticle.modernization.event_logging.example_impl +package com.mparticle.modernization.eventlogging.example import com.mparticle.BaseEvent import com.mparticle.modernization.core.MParticleMediator -import com.mparticle.modernization.event_logging.MParticleEventLogging +import com.mparticle.modernization.eventlogging.MParticleEventLogging import java.math.BigDecimal internal class MParticleEventLoggingImpl(private val mediator: MParticleMediator) : diff --git a/android-core/src/main/java/com/mparticle/modernization/identity/example_impl/MParticleIdentityImpl.kt b/android-core/src/main/java/com/mparticle/modernization/identity/example/MParticleIdentityImpl.kt similarity index 96% rename from android-core/src/main/java/com/mparticle/modernization/identity/example_impl/MParticleIdentityImpl.kt rename to android-core/src/main/java/com/mparticle/modernization/identity/example/MParticleIdentityImpl.kt index ba3a72722..fc9fa0844 100644 --- a/android-core/src/main/java/com/mparticle/modernization/identity/example_impl/MParticleIdentityImpl.kt +++ b/android-core/src/main/java/com/mparticle/modernization/identity/example/MParticleIdentityImpl.kt @@ -1,4 +1,4 @@ -package com.mparticle.modernization.identity.example_impl +package com.mparticle.modernization.identity.example import com.mparticle.identity.IdentityApiRequest import com.mparticle.identity.IdentityApiResult diff --git a/android-core/src/main/java/com/mparticle/modernization/kit/MParticleKit.kt b/android-core/src/main/java/com/mparticle/modernization/kit/MParticleKit.kt index 7b9fb93cc..3e9391763 100644 --- a/android-core/src/main/java/com/mparticle/modernization/kit/MParticleKit.kt +++ b/android-core/src/main/java/com/mparticle/modernization/kit/MParticleKit.kt @@ -1,7 +1,7 @@ package com.mparticle.modernization.kit import com.mparticle.BaseEvent -import com.mparticle.modernization.event_logging.MParticleEventLogging +import com.mparticle.modernization.eventlogging.MParticleEventLogging import java.math.BigDecimal abstract class MParticleKit : MParticleEventLogging { diff --git a/android-core/src/main/java/com/mparticle/modernization/kit/example_impl/CustomKit.kt b/android-core/src/main/java/com/mparticle/modernization/kit/example/CustomKit.kt similarity index 82% rename from android-core/src/main/java/com/mparticle/modernization/kit/example_impl/CustomKit.kt rename to android-core/src/main/java/com/mparticle/modernization/kit/example/CustomKit.kt index 1b809e716..862db1dad 100644 --- a/android-core/src/main/java/com/mparticle/modernization/kit/example_impl/CustomKit.kt +++ b/android-core/src/main/java/com/mparticle/modernization/kit/example/CustomKit.kt @@ -1,4 +1,4 @@ -package com.mparticle.modernization.kit.example_impl +package com.mparticle.modernization.kit.example import android.util.Log import com.mparticle.BaseEvent diff --git a/android-core/src/main/java/com/mparticle/modernization/kit/example_impl/MpKit.kt b/android-core/src/main/java/com/mparticle/modernization/kit/example/MpKit.kt similarity index 75% rename from android-core/src/main/java/com/mparticle/modernization/kit/example_impl/MpKit.kt rename to android-core/src/main/java/com/mparticle/modernization/kit/example/MpKit.kt index 6ed80ce51..095c7634f 100644 --- a/android-core/src/main/java/com/mparticle/modernization/kit/example_impl/MpKit.kt +++ b/android-core/src/main/java/com/mparticle/modernization/kit/example/MpKit.kt @@ -1,9 +1,9 @@ -package com.mparticle.modernization.kit.example_impl +package com.mparticle.modernization.kit.example import com.mparticle.modernization.core.MParticleMediator -import com.mparticle.modernization.data_uploader.example_impl.MParticleUploaderTypes import com.mparticle.modernization.kit.MParticleKitInternal import com.mparticle.modernization.launch +import com.mparticle.modernization.uploading.example.MParticleUploaderTypes class MpKit(private val mediator: MParticleMediator) : MParticleKitInternal() { diff --git a/android-core/src/main/java/com/mparticle/modernization/kit/example_impl/XKit.kt b/android-core/src/main/java/com/mparticle/modernization/kit/example/XKit.kt similarity index 85% rename from android-core/src/main/java/com/mparticle/modernization/kit/example_impl/XKit.kt rename to android-core/src/main/java/com/mparticle/modernization/kit/example/XKit.kt index d08917910..91ec3b070 100644 --- a/android-core/src/main/java/com/mparticle/modernization/kit/example_impl/XKit.kt +++ b/android-core/src/main/java/com/mparticle/modernization/kit/example/XKit.kt @@ -1,4 +1,4 @@ -package com.mparticle.modernization.kit.example_impl +package com.mparticle.modernization.kit.example import com.mparticle.BaseEvent import com.mparticle.modernization.core.MParticleMediator diff --git a/android-core/src/main/java/com/mparticle/modernization/data_uploader/MParticleDataUploader.kt b/android-core/src/main/java/com/mparticle/modernization/uploading/MParticleDataUploader.kt similarity index 94% rename from android-core/src/main/java/com/mparticle/modernization/data_uploader/MParticleDataUploader.kt rename to android-core/src/main/java/com/mparticle/modernization/uploading/MParticleDataUploader.kt index 2cac28a07..102bc34a5 100644 --- a/android-core/src/main/java/com/mparticle/modernization/data_uploader/MParticleDataUploader.kt +++ b/android-core/src/main/java/com/mparticle/modernization/uploading/MParticleDataUploader.kt @@ -1,4 +1,4 @@ -package com.mparticle.modernization.data_uploader +package com.mparticle.modernization.uploading import com.mparticle.modernization.core.MParticleComponent import org.jetbrains.annotations.NotNull diff --git a/android-core/src/main/java/com/mparticle/modernization/data_uploader/MParticleDataUploaderImpl.kt b/android-core/src/main/java/com/mparticle/modernization/uploading/MParticleDataUploaderImpl.kt similarity index 94% rename from android-core/src/main/java/com/mparticle/modernization/data_uploader/MParticleDataUploaderImpl.kt rename to android-core/src/main/java/com/mparticle/modernization/uploading/MParticleDataUploaderImpl.kt index 56a3d2681..58f33f3a8 100644 --- a/android-core/src/main/java/com/mparticle/modernization/data_uploader/MParticleDataUploaderImpl.kt +++ b/android-core/src/main/java/com/mparticle/modernization/uploading/MParticleDataUploaderImpl.kt @@ -1,4 +1,4 @@ -package com.mparticle.modernization.data_uploader +package com.mparticle.modernization.uploading import com.mparticle.modernization.config.UploadingConfiguration import com.mparticle.modernization.core.MParticleMediator diff --git a/android-core/src/main/java/com/mparticle/modernization/data_uploader/MParticleUploadingStrategy.kt b/android-core/src/main/java/com/mparticle/modernization/uploading/MParticleUploadingStrategy.kt similarity index 94% rename from android-core/src/main/java/com/mparticle/modernization/data_uploader/MParticleUploadingStrategy.kt rename to android-core/src/main/java/com/mparticle/modernization/uploading/MParticleUploadingStrategy.kt index 4017045be..3ff5591de 100644 --- a/android-core/src/main/java/com/mparticle/modernization/data_uploader/MParticleUploadingStrategy.kt +++ b/android-core/src/main/java/com/mparticle/modernization/uploading/MParticleUploadingStrategy.kt @@ -1,4 +1,4 @@ -package com.mparticle.modernization.data_uploader +package com.mparticle.modernization.uploading import com.mparticle.modernization.config.UploadingConfiguration import org.jetbrains.annotations.NotNull diff --git a/android-core/src/main/java/com/mparticle/modernization/data_uploader/example_impl/MParticleBreadcrumbUploading.kt b/android-core/src/main/java/com/mparticle/modernization/uploading/example/MParticleBreadcrumbUploading.kt similarity index 91% rename from android-core/src/main/java/com/mparticle/modernization/data_uploader/example_impl/MParticleBreadcrumbUploading.kt rename to android-core/src/main/java/com/mparticle/modernization/uploading/example/MParticleBreadcrumbUploading.kt index 8aab5f474..0ce05eb71 100644 --- a/android-core/src/main/java/com/mparticle/modernization/data_uploader/example_impl/MParticleBreadcrumbUploading.kt +++ b/android-core/src/main/java/com/mparticle/modernization/uploading/example/MParticleBreadcrumbUploading.kt @@ -1,9 +1,9 @@ -package com.mparticle.modernization.data_uploader.example_impl +package com.mparticle.modernization.uploading.example import com.mparticle.internal.messages.BaseMPMessage import com.mparticle.modernization.config.UploadingConfiguration import com.mparticle.modernization.data.MParticleDataRepository -import com.mparticle.modernization.data_uploader.MParticleUploadingStrategy +import com.mparticle.modernization.uploading.MParticleUploadingStrategy class MParticleBreadcrumbUploading(private val dataRepository: MParticleDataRepository) : MParticleUploadingStrategy { diff --git a/android-core/src/main/java/com/mparticle/modernization/data_uploader/example_impl/MParticleUploaderTypes.kt b/android-core/src/main/java/com/mparticle/modernization/uploading/example/MParticleUploaderTypes.kt similarity index 60% rename from android-core/src/main/java/com/mparticle/modernization/data_uploader/example_impl/MParticleUploaderTypes.kt rename to android-core/src/main/java/com/mparticle/modernization/uploading/example/MParticleUploaderTypes.kt index eb85cfbfb..e710b2af4 100644 --- a/android-core/src/main/java/com/mparticle/modernization/data_uploader/example_impl/MParticleUploaderTypes.kt +++ b/android-core/src/main/java/com/mparticle/modernization/uploading/example/MParticleUploaderTypes.kt @@ -1,4 +1,4 @@ -package com.mparticle.modernization.data_uploader.example_impl +package com.mparticle.modernization.uploading.example enum class MParticleUploaderTypes(val type: Int) { EVENT(1), BREADCRUMB(2), DEFAULT(-1); From 972dc520ae15fcb89a8d5987bfd7c525f7331887 Mon Sep 17 00:00:00 2001 From: markvdouw Date: Thu, 6 Apr 2023 11:39:02 -0300 Subject: [PATCH 6/9] Making everything internal as of now --- .../java/com/mparticle/modernization/MParticleCallback.kt | 2 +- .../src/main/java/com/mparticle/modernization/Utils.kt | 2 +- .../mparticle/modernization/config/UploadingConfiguration.kt | 2 +- .../main/java/com/mparticle/modernization/core/MParticle.kt | 2 +- .../com/mparticle/modernization/core/MParticleComponent.kt | 2 +- .../com/mparticle/modernization/core/MParticleException.kt | 4 ++-- .../com/mparticle/modernization/core/MParticleMediator.kt | 2 +- .../mparticle/modernization/data/MParticleDataRepository.kt | 2 +- .../modernization/eventlogging/MParticleEventLogging.kt | 2 +- .../com/mparticle/modernization/identity/IdentityCallback.kt | 2 +- .../com/mparticle/modernization/identity/MParticleIdentity.kt | 4 ++-- .../main/java/com/mparticle/modernization/kit/MParticleKit.kt | 4 ++-- .../com/mparticle/modernization/kit/MParticleKitManager.kt | 4 ++-- .../java/com/mparticle/modernization/kit/example/CustomKit.kt | 2 +- .../java/com/mparticle/modernization/kit/example/MpKit.kt | 2 +- .../main/java/com/mparticle/modernization/kit/example/XKit.kt | 2 +- .../modernization/uploading/MParticleDataUploader.kt | 2 +- .../modernization/uploading/MParticleDataUploaderImpl.kt | 2 +- .../modernization/uploading/MParticleUploadingStrategy.kt | 2 +- .../uploading/example/MParticleBreadcrumbUploading.kt | 2 +- .../modernization/uploading/example/MParticleUploaderTypes.kt | 2 +- 21 files changed, 25 insertions(+), 25 deletions(-) diff --git a/android-core/src/main/java/com/mparticle/modernization/MParticleCallback.kt b/android-core/src/main/java/com/mparticle/modernization/MParticleCallback.kt index 217a6630e..b4ba7d71d 100644 --- a/android-core/src/main/java/com/mparticle/modernization/MParticleCallback.kt +++ b/android-core/src/main/java/com/mparticle/modernization/MParticleCallback.kt @@ -1,6 +1,6 @@ package com.mparticle.modernization -abstract class MParticleCallback { +internal abstract class MParticleCallback { var isSuccessFul: Boolean = false var isCompleted: Boolean = false diff --git a/android-core/src/main/java/com/mparticle/modernization/Utils.kt b/android-core/src/main/java/com/mparticle/modernization/Utils.kt index 2ccea77f3..32e0df656 100644 --- a/android-core/src/main/java/com/mparticle/modernization/Utils.kt +++ b/android-core/src/main/java/com/mparticle/modernization/Utils.kt @@ -4,6 +4,6 @@ import com.mparticle.modernization.core.MParticleMediator import kotlinx.coroutines.CoroutineScope import kotlinx.coroutines.launch -fun MParticleMediator.launch(block: suspend CoroutineScope.() -> Unit) { +internal fun MParticleMediator.launch(block: suspend CoroutineScope.() -> Unit) { this.coroutineScope.launch(this.coroutineDispatcher) { block } } diff --git a/android-core/src/main/java/com/mparticle/modernization/config/UploadingConfiguration.kt b/android-core/src/main/java/com/mparticle/modernization/config/UploadingConfiguration.kt index 63627ba37..929119d9c 100644 --- a/android-core/src/main/java/com/mparticle/modernization/config/UploadingConfiguration.kt +++ b/android-core/src/main/java/com/mparticle/modernization/config/UploadingConfiguration.kt @@ -1,3 +1,3 @@ package com.mparticle.modernization.config -interface UploadingConfiguration +internal interface UploadingConfiguration diff --git a/android-core/src/main/java/com/mparticle/modernization/core/MParticle.kt b/android-core/src/main/java/com/mparticle/modernization/core/MParticle.kt index 9552b5782..4a7c4f3e0 100644 --- a/android-core/src/main/java/com/mparticle/modernization/core/MParticle.kt +++ b/android-core/src/main/java/com/mparticle/modernization/core/MParticle.kt @@ -6,7 +6,7 @@ import com.mparticle.modernization.identity.MParticleIdentity import com.mparticle.modernization.kit.MParticleKitManager import com.mparticle.modernization.uploading.MParticleDataUploader -class MParticle private constructor(private val options: MParticleOptions) { +internal class MParticle private constructor(private val options: MParticleOptions) { private var mediator: MParticleMediator = MParticleMediator() init { diff --git a/android-core/src/main/java/com/mparticle/modernization/core/MParticleComponent.kt b/android-core/src/main/java/com/mparticle/modernization/core/MParticleComponent.kt index e8b9e6d5d..90249455d 100644 --- a/android-core/src/main/java/com/mparticle/modernization/core/MParticleComponent.kt +++ b/android-core/src/main/java/com/mparticle/modernization/core/MParticleComponent.kt @@ -1,3 +1,3 @@ package com.mparticle.modernization.core -interface MParticleComponent +internal interface MParticleComponent diff --git a/android-core/src/main/java/com/mparticle/modernization/core/MParticleException.kt b/android-core/src/main/java/com/mparticle/modernization/core/MParticleException.kt index d5f0363a0..d00f59d29 100644 --- a/android-core/src/main/java/com/mparticle/modernization/core/MParticleException.kt +++ b/android-core/src/main/java/com/mparticle/modernization/core/MParticleException.kt @@ -1,7 +1,7 @@ package com.mparticle.modernization.core -abstract class MParticleException(message: String, throwable: Throwable? = null) : +internal abstract class MParticleException(message: String, throwable: Throwable? = null) : RuntimeException() -class MParticleInitializationException(message: String = "MParticle must be started before obtaining an instance, please call MParticle.start() first") : +internal class MParticleInitializationException(message: String = "MParticle must be started before obtaining an instance, please call MParticle.start() first") : MParticleException(message) diff --git a/android-core/src/main/java/com/mparticle/modernization/core/MParticleMediator.kt b/android-core/src/main/java/com/mparticle/modernization/core/MParticleMediator.kt index 0909020df..db6dfeb5a 100644 --- a/android-core/src/main/java/com/mparticle/modernization/core/MParticleMediator.kt +++ b/android-core/src/main/java/com/mparticle/modernization/core/MParticleMediator.kt @@ -18,7 +18,7 @@ import kotlinx.coroutines.SupervisorJob import kotlinx.coroutines.asCoroutineDispatcher import java.util.concurrent.Executors -class MParticleMediator { +internal class MParticleMediator { internal var eventLogging: MParticleEventLogging? = null internal var identity: InternalIdentity? = null internal var kitManager: KitManagerInternal? = null diff --git a/android-core/src/main/java/com/mparticle/modernization/data/MParticleDataRepository.kt b/android-core/src/main/java/com/mparticle/modernization/data/MParticleDataRepository.kt index 0ab555939..dca7fb0be 100644 --- a/android-core/src/main/java/com/mparticle/modernization/data/MParticleDataRepository.kt +++ b/android-core/src/main/java/com/mparticle/modernization/data/MParticleDataRepository.kt @@ -2,7 +2,7 @@ package com.mparticle.modernization.data import com.mparticle.internal.messages.BaseMPMessage -class MParticleDataRepository { +internal class MParticleDataRepository { suspend fun updateSession(data: BaseMPMessage) {} diff --git a/android-core/src/main/java/com/mparticle/modernization/eventlogging/MParticleEventLogging.kt b/android-core/src/main/java/com/mparticle/modernization/eventlogging/MParticleEventLogging.kt index bf2245a8e..ccd48ea2a 100644 --- a/android-core/src/main/java/com/mparticle/modernization/eventlogging/MParticleEventLogging.kt +++ b/android-core/src/main/java/com/mparticle/modernization/eventlogging/MParticleEventLogging.kt @@ -6,7 +6,7 @@ import org.jetbrains.annotations.NotNull import org.jetbrains.annotations.Nullable import java.math.BigDecimal -interface MParticleEventLogging : MParticleComponent { +internal interface MParticleEventLogging : MParticleComponent { // All common, commerce, screen, pushRegistration, notification, notificationOpened and NetworkPerformance events should be logged with the same function /** * Log an event - TODO review EventBuilder to be able to build all type of events diff --git a/android-core/src/main/java/com/mparticle/modernization/identity/IdentityCallback.kt b/android-core/src/main/java/com/mparticle/modernization/identity/IdentityCallback.kt index 5fb310d3d..d1dc88fd1 100644 --- a/android-core/src/main/java/com/mparticle/modernization/identity/IdentityCallback.kt +++ b/android-core/src/main/java/com/mparticle/modernization/identity/IdentityCallback.kt @@ -3,4 +3,4 @@ package com.mparticle.modernization.identity import com.mparticle.identity.IdentityApiResult import com.mparticle.modernization.MParticleCallback -open class IdentityCallback : MParticleCallback() +internal open class IdentityCallback : MParticleCallback() diff --git a/android-core/src/main/java/com/mparticle/modernization/identity/MParticleIdentity.kt b/android-core/src/main/java/com/mparticle/modernization/identity/MParticleIdentity.kt index acccdf7d3..d56aa9f46 100644 --- a/android-core/src/main/java/com/mparticle/modernization/identity/MParticleIdentity.kt +++ b/android-core/src/main/java/com/mparticle/modernization/identity/MParticleIdentity.kt @@ -8,7 +8,7 @@ import com.mparticle.modernization.core.MParticleComponent import org.jetbrains.annotations.NotNull import org.jetbrains.annotations.Nullable -interface MParticleIdentity : MParticleComponent { +internal interface MParticleIdentity : MParticleComponent { /** * Login @@ -91,4 +91,4 @@ internal interface InternalIdentity : MParticleIdentity { suspend fun login(@NotNull request: IdentityApiRequest): IdentityApiResult } -interface IdentityListener +internal interface IdentityListener diff --git a/android-core/src/main/java/com/mparticle/modernization/kit/MParticleKit.kt b/android-core/src/main/java/com/mparticle/modernization/kit/MParticleKit.kt index 3e9391763..16d127401 100644 --- a/android-core/src/main/java/com/mparticle/modernization/kit/MParticleKit.kt +++ b/android-core/src/main/java/com/mparticle/modernization/kit/MParticleKit.kt @@ -4,7 +4,7 @@ import com.mparticle.BaseEvent import com.mparticle.modernization.eventlogging.MParticleEventLogging import java.math.BigDecimal -abstract class MParticleKit : MParticleEventLogging { +internal abstract class MParticleKit : MParticleEventLogging { override fun logEvent(event: BaseEvent) { } @@ -30,4 +30,4 @@ abstract class MParticleKit : MParticleEventLogging { } } -abstract class MParticleKitInternal : MParticleKit() +internal abstract class MParticleKitInternal : MParticleKit() diff --git a/android-core/src/main/java/com/mparticle/modernization/kit/MParticleKitManager.kt b/android-core/src/main/java/com/mparticle/modernization/kit/MParticleKitManager.kt index f3b9b848d..63815fb49 100644 --- a/android-core/src/main/java/com/mparticle/modernization/kit/MParticleKitManager.kt +++ b/android-core/src/main/java/com/mparticle/modernization/kit/MParticleKitManager.kt @@ -2,6 +2,6 @@ package com.mparticle.modernization.kit import com.mparticle.modernization.core.MParticleComponent -abstract class MParticleKitManager : MParticleKit() +internal abstract class MParticleKitManager : MParticleKit() -abstract class KitManagerInternal : MParticleKitManager(), MParticleComponent +internal abstract class KitManagerInternal : MParticleKitManager(), MParticleComponent diff --git a/android-core/src/main/java/com/mparticle/modernization/kit/example/CustomKit.kt b/android-core/src/main/java/com/mparticle/modernization/kit/example/CustomKit.kt index 862db1dad..c079f5ba5 100644 --- a/android-core/src/main/java/com/mparticle/modernization/kit/example/CustomKit.kt +++ b/android-core/src/main/java/com/mparticle/modernization/kit/example/CustomKit.kt @@ -4,7 +4,7 @@ import android.util.Log import com.mparticle.BaseEvent import com.mparticle.modernization.kit.MParticleKit -class CustomKit : MParticleKit() { +internal class CustomKit : MParticleKit() { override fun logEvent(event: BaseEvent) { Log.d("CUSTOM_LOG", event.toString()) } diff --git a/android-core/src/main/java/com/mparticle/modernization/kit/example/MpKit.kt b/android-core/src/main/java/com/mparticle/modernization/kit/example/MpKit.kt index 095c7634f..7922e9204 100644 --- a/android-core/src/main/java/com/mparticle/modernization/kit/example/MpKit.kt +++ b/android-core/src/main/java/com/mparticle/modernization/kit/example/MpKit.kt @@ -5,7 +5,7 @@ import com.mparticle.modernization.kit.MParticleKitInternal import com.mparticle.modernization.launch import com.mparticle.modernization.uploading.example.MParticleUploaderTypes -class MpKit(private val mediator: MParticleMediator) : MParticleKitInternal() { +internal class MpKit(private val mediator: MParticleMediator) : MParticleKitInternal() { override fun leaveBreadcrumb(breadcrumb: String) { mediator.launch { diff --git a/android-core/src/main/java/com/mparticle/modernization/kit/example/XKit.kt b/android-core/src/main/java/com/mparticle/modernization/kit/example/XKit.kt index 91ec3b070..960cf5347 100644 --- a/android-core/src/main/java/com/mparticle/modernization/kit/example/XKit.kt +++ b/android-core/src/main/java/com/mparticle/modernization/kit/example/XKit.kt @@ -4,7 +4,7 @@ import com.mparticle.BaseEvent import com.mparticle.modernization.core.MParticleMediator import com.mparticle.modernization.kit.MParticleKitInternal -class XKit(private val mediator: MParticleMediator) : MParticleKitInternal() { +internal class XKit(private val mediator: MParticleMediator) : MParticleKitInternal() { override fun logEvent(event: BaseEvent) { TODO("Not yet implemented") } diff --git a/android-core/src/main/java/com/mparticle/modernization/uploading/MParticleDataUploader.kt b/android-core/src/main/java/com/mparticle/modernization/uploading/MParticleDataUploader.kt index 102bc34a5..ef0259fdd 100644 --- a/android-core/src/main/java/com/mparticle/modernization/uploading/MParticleDataUploader.kt +++ b/android-core/src/main/java/com/mparticle/modernization/uploading/MParticleDataUploader.kt @@ -3,7 +3,7 @@ package com.mparticle.modernization.uploading import com.mparticle.modernization.core.MParticleComponent import org.jetbrains.annotations.NotNull -interface MParticleDataUploader : MParticleComponent { +internal interface MParticleDataUploader : MParticleComponent { /** * Upload set of data using provided strategies. Decision made base on [type] * diff --git a/android-core/src/main/java/com/mparticle/modernization/uploading/MParticleDataUploaderImpl.kt b/android-core/src/main/java/com/mparticle/modernization/uploading/MParticleDataUploaderImpl.kt index 58f33f3a8..25023816f 100644 --- a/android-core/src/main/java/com/mparticle/modernization/uploading/MParticleDataUploaderImpl.kt +++ b/android-core/src/main/java/com/mparticle/modernization/uploading/MParticleDataUploaderImpl.kt @@ -4,7 +4,7 @@ import com.mparticle.modernization.config.UploadingConfiguration import com.mparticle.modernization.core.MParticleMediator import com.mparticle.modernization.launch -internal class MParticleDataUploaderImpl( + internal class MParticleDataUploaderImpl( private val mediator: MParticleMediator, private val strategies: List, private val uploadingConfiguration: UploadingConfiguration? = null diff --git a/android-core/src/main/java/com/mparticle/modernization/uploading/MParticleUploadingStrategy.kt b/android-core/src/main/java/com/mparticle/modernization/uploading/MParticleUploadingStrategy.kt index 3ff5591de..19635fb51 100644 --- a/android-core/src/main/java/com/mparticle/modernization/uploading/MParticleUploadingStrategy.kt +++ b/android-core/src/main/java/com/mparticle/modernization/uploading/MParticleUploadingStrategy.kt @@ -7,7 +7,7 @@ import org.jetbrains.annotations.Nullable /** * Data uploading strategies for different data types */ -interface MParticleUploadingStrategy { +internal interface MParticleUploadingStrategy { /** Upload set of data * * @param data any type of data to upload diff --git a/android-core/src/main/java/com/mparticle/modernization/uploading/example/MParticleBreadcrumbUploading.kt b/android-core/src/main/java/com/mparticle/modernization/uploading/example/MParticleBreadcrumbUploading.kt index 0ce05eb71..11ba83649 100644 --- a/android-core/src/main/java/com/mparticle/modernization/uploading/example/MParticleBreadcrumbUploading.kt +++ b/android-core/src/main/java/com/mparticle/modernization/uploading/example/MParticleBreadcrumbUploading.kt @@ -5,7 +5,7 @@ import com.mparticle.modernization.config.UploadingConfiguration import com.mparticle.modernization.data.MParticleDataRepository import com.mparticle.modernization.uploading.MParticleUploadingStrategy -class MParticleBreadcrumbUploading(private val dataRepository: MParticleDataRepository) : +internal class MParticleBreadcrumbUploading(private val dataRepository: MParticleDataRepository) : MParticleUploadingStrategy { override suspend fun upload( data: Any, diff --git a/android-core/src/main/java/com/mparticle/modernization/uploading/example/MParticleUploaderTypes.kt b/android-core/src/main/java/com/mparticle/modernization/uploading/example/MParticleUploaderTypes.kt index e710b2af4..2fd8e3e68 100644 --- a/android-core/src/main/java/com/mparticle/modernization/uploading/example/MParticleUploaderTypes.kt +++ b/android-core/src/main/java/com/mparticle/modernization/uploading/example/MParticleUploaderTypes.kt @@ -1,5 +1,5 @@ package com.mparticle.modernization.uploading.example -enum class MParticleUploaderTypes(val type: Int) { +internal enum class MParticleUploaderTypes(val type: Int) { EVENT(1), BREADCRUMB(2), DEFAULT(-1); } From 6cf063fd1af37041620b91f9ff0a17255771f2ef Mon Sep 17 00:00:00 2001 From: markvdouw Date: Thu, 6 Apr 2023 18:27:54 -0300 Subject: [PATCH 7/9] Making everything internal as of now --- android-core/build.gradle | 3 ++- .../java/com/mparticle/modernization/core/MParticle.kt | 4 ++-- .../com/mparticle/modernization/core/MParticleException.kt | 7 ------- .../modernization/uploading/MParticleDataUploaderImpl.kt | 6 +++--- 4 files changed, 7 insertions(+), 13 deletions(-) delete mode 100644 android-core/src/main/java/com/mparticle/modernization/core/MParticleException.kt diff --git a/android-core/build.gradle b/android-core/build.gradle index 6a2194119..92ed9d593 100644 --- a/android-core/build.gradle +++ b/android-core/build.gradle @@ -112,7 +112,8 @@ task coreSdkJavadocs(type: Javadoc) { exclude { String filePath = it.toString() filePath.contains('/com/mparticle/internal/') || - filePath.contains('/com/mparticle/kits/') + filePath.contains('/com/mparticle/kits/') || + filePath.contains('/com/mparticle/modernization/') } } } diff --git a/android-core/src/main/java/com/mparticle/modernization/core/MParticle.kt b/android-core/src/main/java/com/mparticle/modernization/core/MParticle.kt index 4a7c4f3e0..632fbeb0d 100644 --- a/android-core/src/main/java/com/mparticle/modernization/core/MParticle.kt +++ b/android-core/src/main/java/com/mparticle/modernization/core/MParticle.kt @@ -16,8 +16,8 @@ internal class MParticle private constructor(private val options: MParticleOptio companion object { private var _instance: MParticle? = null - @Throws(MParticleInitializationException::class) - fun getInstance(): MParticle = _instance ?: throw MParticleInitializationException() + @Throws(Exception::class) + fun getInstance(): MParticle = _instance ?: throw Exception("MParticle must be started before getting the instance") fun start(options: MParticleOptions) { _instance = MParticle(options) diff --git a/android-core/src/main/java/com/mparticle/modernization/core/MParticleException.kt b/android-core/src/main/java/com/mparticle/modernization/core/MParticleException.kt deleted file mode 100644 index d00f59d29..000000000 --- a/android-core/src/main/java/com/mparticle/modernization/core/MParticleException.kt +++ /dev/null @@ -1,7 +0,0 @@ -package com.mparticle.modernization.core - -internal abstract class MParticleException(message: String, throwable: Throwable? = null) : - RuntimeException() - -internal class MParticleInitializationException(message: String = "MParticle must be started before obtaining an instance, please call MParticle.start() first") : - MParticleException(message) diff --git a/android-core/src/main/java/com/mparticle/modernization/uploading/MParticleDataUploaderImpl.kt b/android-core/src/main/java/com/mparticle/modernization/uploading/MParticleDataUploaderImpl.kt index 25023816f..e355ecb58 100644 --- a/android-core/src/main/java/com/mparticle/modernization/uploading/MParticleDataUploaderImpl.kt +++ b/android-core/src/main/java/com/mparticle/modernization/uploading/MParticleDataUploaderImpl.kt @@ -5,9 +5,9 @@ import com.mparticle.modernization.core.MParticleMediator import com.mparticle.modernization.launch internal class MParticleDataUploaderImpl( - private val mediator: MParticleMediator, - private val strategies: List, - private val uploadingConfiguration: UploadingConfiguration? = null + private val mediator: MParticleMediator, + private val strategies: List, + private val uploadingConfiguration: UploadingConfiguration? = null ) : MParticleDataUploader { init { mediator.launch { configure() } From 4e479f4080326d817663881ae3ef4dc8818519ba Mon Sep 17 00:00:00 2001 From: markvdouw Date: Thu, 6 Apr 2023 18:28:48 -0300 Subject: [PATCH 8/9] Ktlint format --- .../modernization/uploading/MParticleDataUploaderImpl.kt | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/android-core/src/main/java/com/mparticle/modernization/uploading/MParticleDataUploaderImpl.kt b/android-core/src/main/java/com/mparticle/modernization/uploading/MParticleDataUploaderImpl.kt index e355ecb58..58f33f3a8 100644 --- a/android-core/src/main/java/com/mparticle/modernization/uploading/MParticleDataUploaderImpl.kt +++ b/android-core/src/main/java/com/mparticle/modernization/uploading/MParticleDataUploaderImpl.kt @@ -4,10 +4,10 @@ import com.mparticle.modernization.config.UploadingConfiguration import com.mparticle.modernization.core.MParticleMediator import com.mparticle.modernization.launch - internal class MParticleDataUploaderImpl( - private val mediator: MParticleMediator, - private val strategies: List, - private val uploadingConfiguration: UploadingConfiguration? = null +internal class MParticleDataUploaderImpl( + private val mediator: MParticleMediator, + private val strategies: List, + private val uploadingConfiguration: UploadingConfiguration? = null ) : MParticleDataUploader { init { mediator.launch { configure() } From 40587168b2950c80f392039eef8594b48ad7d654 Mon Sep 17 00:00:00 2001 From: markvdouw Date: Wed, 26 Apr 2023 11:09:00 -0300 Subject: [PATCH 9/9] Use case --- .../mparticle/modernization/BatchManager.kt | 13 ++++ .../modernization/MpApiClientImpl.kt | 6 ++ .../modernization/WalkthroughTest.kt | 45 ++++++++++++++ .../config/UploadingConfiguration.kt | 3 - .../mparticle/modernization/core/MParticle.kt | 6 +- .../modernization/core/MParticleMediator.kt | 40 +++++++++--- .../data/MParticleDataRepository.kt | 15 ++++- .../datahandler/DataHandlerType.kt | 16 +++++ .../MParticleDataHandler.kt} | 13 ++-- .../MParticleDataHandlerStrategy.kt | 44 +++++++++++++ .../MParticleDataStrategyManagerImpl.kt | 18 ++++++ .../example/MParticleCommerceHandler.kt | 62 +++++++++++++++++++ .../eventlogging/MParticleEventLogging.kt | 33 +--------- .../example/MParticleEventLoggingImpl.kt | 34 ++++------ .../identity/IdentityCallback.kt | 4 ++ .../identity/MParticleIdentity.kt | 1 - .../identity/example/MParticleIdentityImpl.kt | 4 ++ .../modernization/kit/KitConfiguration.kt | 8 +++ .../modernization/kit/KitListeners.kt | 25 ++++++++ .../modernization/kit/MParticleKit.kt | 33 ++-------- .../modernization/kit/MParticleKitManager.kt | 7 ++- .../kit/MParticleKitManagerImpl.kt | 33 +++++++++- .../modernization/kit/example/CustomKit.kt | 11 ---- .../modernization/kit/example/MpKit.kt | 38 ++++++++++-- .../modernization/kit/example/XKit.kt | 20 ++++-- .../uploading/MParticleDataUploaderImpl.kt | 26 -------- .../uploading/MParticleUploadingStrategy.kt | 29 --------- .../example/MParticleBreadcrumbUploading.kt | 42 ------------- 28 files changed, 398 insertions(+), 231 deletions(-) create mode 100644 android-core/src/main/java/com/mparticle/modernization/BatchManager.kt create mode 100644 android-core/src/main/java/com/mparticle/modernization/MpApiClientImpl.kt create mode 100644 android-core/src/main/java/com/mparticle/modernization/WalkthroughTest.kt delete mode 100644 android-core/src/main/java/com/mparticle/modernization/config/UploadingConfiguration.kt create mode 100644 android-core/src/main/java/com/mparticle/modernization/datahandler/DataHandlerType.kt rename android-core/src/main/java/com/mparticle/modernization/{uploading/MParticleDataUploader.kt => datahandler/MParticleDataHandler.kt} (51%) create mode 100644 android-core/src/main/java/com/mparticle/modernization/datahandler/MParticleDataHandlerStrategy.kt create mode 100644 android-core/src/main/java/com/mparticle/modernization/datahandler/MParticleDataStrategyManagerImpl.kt create mode 100644 android-core/src/main/java/com/mparticle/modernization/datahandler/example/MParticleCommerceHandler.kt create mode 100644 android-core/src/main/java/com/mparticle/modernization/kit/KitConfiguration.kt create mode 100644 android-core/src/main/java/com/mparticle/modernization/kit/KitListeners.kt delete mode 100644 android-core/src/main/java/com/mparticle/modernization/kit/example/CustomKit.kt delete mode 100644 android-core/src/main/java/com/mparticle/modernization/uploading/MParticleDataUploaderImpl.kt delete mode 100644 android-core/src/main/java/com/mparticle/modernization/uploading/MParticleUploadingStrategy.kt delete mode 100644 android-core/src/main/java/com/mparticle/modernization/uploading/example/MParticleBreadcrumbUploading.kt diff --git a/android-core/src/main/java/com/mparticle/modernization/BatchManager.kt b/android-core/src/main/java/com/mparticle/modernization/BatchManager.kt new file mode 100644 index 000000000..660a46e8b --- /dev/null +++ b/android-core/src/main/java/com/mparticle/modernization/BatchManager.kt @@ -0,0 +1,13 @@ +package com.mparticle.modernization + +class BatchManager(private val api : MpApiClientImpl) { + + suspend fun createBatch() : MpBatch? = MpBatch("", Math.random().toLong()) + + suspend fun uploadBatch(batch : MpBatch) { + api.uploadBatch(batch) + } + +} + +class MpBatch(data : String, batchId : Long){} \ No newline at end of file diff --git a/android-core/src/main/java/com/mparticle/modernization/MpApiClientImpl.kt b/android-core/src/main/java/com/mparticle/modernization/MpApiClientImpl.kt new file mode 100644 index 000000000..d54041ac6 --- /dev/null +++ b/android-core/src/main/java/com/mparticle/modernization/MpApiClientImpl.kt @@ -0,0 +1,6 @@ +package com.mparticle.modernization + +class MpApiClientImpl { + + suspend fun uploadBatch(data : MpBatch) {} +} \ No newline at end of file diff --git a/android-core/src/main/java/com/mparticle/modernization/WalkthroughTest.kt b/android-core/src/main/java/com/mparticle/modernization/WalkthroughTest.kt new file mode 100644 index 000000000..2b8cc344f --- /dev/null +++ b/android-core/src/main/java/com/mparticle/modernization/WalkthroughTest.kt @@ -0,0 +1,45 @@ +package com.mparticle.modernization + +import android.content.Context +import com.mparticle.MPEvent +import com.mparticle.MParticleOptions +import com.mparticle.commerce.CommerceEvent +import com.mparticle.commerce.Product +import com.mparticle.modernization.core.MParticle +import com.mparticle.modernization.eventlogging.MParticleEventLogging + + +class WalkthroughTest(private val context: Context) { + + private var eventLogging: MParticleEventLogging? = null + + //Only setup + fun initialize() { + val options = MParticleOptions.builder(context).credentials("key", "secret").build() + MParticle.start(options) + eventLogging = MParticle.getInstance().EventLogging() + } + + init { + initialize() + } + + //=================== + + fun runTest() { + logCommerceEvent() + logNormalEvent() + } + + fun logCommerceEvent() { + val product = Product.Builder("testName", "testSku", 100.0).build() + val commerceEvent = CommerceEvent.Builder(Product.CHECKOUT, product).build() + eventLogging?.logEvent(commerceEvent) + } + fun logNormalEvent() { + val customAttributes = + mutableMapOf(Pair("key1", "value1"), Pair("key2", 4), Pair("key3", null)) + val event = MPEvent.Builder("myEvent").customAttributes(customAttributes).build() + eventLogging?.logEvent(event) + } +} \ No newline at end of file diff --git a/android-core/src/main/java/com/mparticle/modernization/config/UploadingConfiguration.kt b/android-core/src/main/java/com/mparticle/modernization/config/UploadingConfiguration.kt deleted file mode 100644 index 929119d9c..000000000 --- a/android-core/src/main/java/com/mparticle/modernization/config/UploadingConfiguration.kt +++ /dev/null @@ -1,3 +0,0 @@ -package com.mparticle.modernization.config - -internal interface UploadingConfiguration diff --git a/android-core/src/main/java/com/mparticle/modernization/core/MParticle.kt b/android-core/src/main/java/com/mparticle/modernization/core/MParticle.kt index 632fbeb0d..b8394dc46 100644 --- a/android-core/src/main/java/com/mparticle/modernization/core/MParticle.kt +++ b/android-core/src/main/java/com/mparticle/modernization/core/MParticle.kt @@ -1,13 +1,14 @@ package com.mparticle.modernization.core import com.mparticle.MParticleOptions +import com.mparticle.modernization.data.MParticleDataRepository import com.mparticle.modernization.eventlogging.MParticleEventLogging import com.mparticle.modernization.identity.MParticleIdentity import com.mparticle.modernization.kit.MParticleKitManager -import com.mparticle.modernization.uploading.MParticleDataUploader +import com.mparticle.modernization.datahandler.MParticleDataHandler internal class MParticle private constructor(private val options: MParticleOptions) { - private var mediator: MParticleMediator = MParticleMediator() + private var mediator: MParticleMediator = MParticleMediator(MParticleDataRepository()) init { mediator.configure(options) @@ -27,5 +28,4 @@ internal class MParticle private constructor(private val options: MParticleOptio fun KitManager(): MParticleKitManager? = mediator.kitManager as MParticleKitManager? fun Identity(): MParticleIdentity? = mediator.identity as MParticleIdentity? fun EventLogging(): MParticleEventLogging? = mediator.eventLogging - fun DataUploading(): MParticleDataUploader? = mediator.dataUploader } diff --git a/android-core/src/main/java/com/mparticle/modernization/core/MParticleMediator.kt b/android-core/src/main/java/com/mparticle/modernization/core/MParticleMediator.kt index db6dfeb5a..d9b83aae6 100644 --- a/android-core/src/main/java/com/mparticle/modernization/core/MParticleMediator.kt +++ b/android-core/src/main/java/com/mparticle/modernization/core/MParticleMediator.kt @@ -1,6 +1,9 @@ package com.mparticle.modernization.core import com.mparticle.MParticleOptions +import com.mparticle.modernization.BatchManager +import com.mparticle.modernization.MpApiClientImpl +import com.mparticle.modernization.data.MParticleDataRepository import com.mparticle.modernization.eventlogging.MParticleEventLogging import com.mparticle.modernization.eventlogging.example.MParticleEventLoggingImpl import com.mparticle.modernization.identity.InternalIdentity @@ -9,39 +12,56 @@ import com.mparticle.modernization.kit.KitManagerInternal import com.mparticle.modernization.kit.MParticleKit import com.mparticle.modernization.kit.MParticleKitManagerImpl import com.mparticle.modernization.kit.example.MpKit -import com.mparticle.modernization.uploading.MParticleDataUploader -import com.mparticle.modernization.uploading.MParticleDataUploaderImpl -import com.mparticle.modernization.uploading.MParticleUploadingStrategy +import com.mparticle.modernization.datahandler.MParticleDataStrategyManagerImpl +import com.mparticle.modernization.datahandler.MParticleDataHandlerStrategy +import com.mparticle.modernization.datahandler.example.MParticleCommerceHandler import kotlinx.coroutines.CloseableCoroutineDispatcher import kotlinx.coroutines.CoroutineScope import kotlinx.coroutines.SupervisorJob import kotlinx.coroutines.asCoroutineDispatcher import java.util.concurrent.Executors -internal class MParticleMediator { +internal class MParticleMediator(private val dataRepository: MParticleDataRepository) { internal var eventLogging: MParticleEventLogging? = null internal var identity: InternalIdentity? = null internal var kitManager: KitManagerInternal? = null - internal var dataUploader: MParticleDataUploader? = null + internal var batchManager : BatchManager = BatchManager(MpApiClientImpl()) - private var kits: MutableList = mutableListOf() - private var mParticleUploadingStrategies: List = listOf() + private var mParticleUploadingStrategies: List> = listOf( + MParticleCommerceHandler(dataRepository, batchManager) + ) internal lateinit var coroutineScope: CoroutineScope internal lateinit var coroutineDispatcher: CloseableCoroutineDispatcher + /** + * Mediator register kits and components, acting as a "common layer" for the components internally, + * and also providing a single instance of the available and visible components to the MParticle + * facade. This will help also controlling which this we want to make accesible and which one we doesn't. + */ fun configure(options: MParticleOptions) { + /** + * Creation of auto-cancellable thread-pool using coroutines. + * Using a utility, and due to the fact that the relationship between mediator-mPaticle instance + * is 1:1, we would be able to launch async operation managed by the thread pool of each mparticle + * instance + */ coroutineScope = CoroutineScope(SupervisorJob()) coroutineDispatcher = Executors.newCachedThreadPool().asCoroutineDispatcher() - kits = registerKits(options) + + var kits: MutableList = registerKits(options) + /** + * Mediator has a reference to each component. The components mostly are instanciated with a + * dependency to the mediator, meaning that, if component A (running action 1) needs an action 3 from component B + * to be executed to complete action 1; component A can use the mediator to access component B + */ registerComponent(MParticleKitManagerImpl(kits)) registerComponent(MParticleIdentityImpl(this)) registerComponent(MParticleEventLoggingImpl(this)) - registerComponent(MParticleDataUploaderImpl(this, mParticleUploadingStrategies, null)) } private fun registerKits(options: MParticleOptions): MutableList = - mutableListOf(MpKit(this)) + mutableListOf(MpKit(this, MParticleDataStrategyManagerImpl(mParticleUploadingStrategies))) private fun registerComponent(component: MParticleComponent) { when (component) { diff --git a/android-core/src/main/java/com/mparticle/modernization/data/MParticleDataRepository.kt b/android-core/src/main/java/com/mparticle/modernization/data/MParticleDataRepository.kt index dca7fb0be..c2f9b8f64 100644 --- a/android-core/src/main/java/com/mparticle/modernization/data/MParticleDataRepository.kt +++ b/android-core/src/main/java/com/mparticle/modernization/data/MParticleDataRepository.kt @@ -1,10 +1,21 @@ package com.mparticle.modernization.data import com.mparticle.internal.messages.BaseMPMessage +import com.mparticle.modernization.MpBatch +/** + * This is based on the repository pattern to manage data sources (apiClients, daos, + * sharedPreferences, cache, memory, etc). + * Ideally we would inject our data sources here, and the repository would be incharge of preprocessing + * the data interacting with the data source, and post-process the data coming from data sources. + */ internal class MParticleDataRepository { - suspend fun updateSession(data: BaseMPMessage) {} + suspend fun insertCommerceDTO(data: BaseMPMessage) { + //TODO parses the event and saves it into the db + } - suspend fun insertBreadcrumb(data: BaseMPMessage) {} + suspend fun getEventsByType() : List? = emptyList() + + suspend fun getBatch() : MpBatch? = null } diff --git a/android-core/src/main/java/com/mparticle/modernization/datahandler/DataHandlerType.kt b/android-core/src/main/java/com/mparticle/modernization/datahandler/DataHandlerType.kt new file mode 100644 index 000000000..13e6d9d75 --- /dev/null +++ b/android-core/src/main/java/com/mparticle/modernization/datahandler/DataHandlerType.kt @@ -0,0 +1,16 @@ +package com.mparticle.modernization.datahandler + +enum class DataHandlerType { + MP_EVENT, COMMERCE_EVENT, BREADCRUMB; + + companion object { + fun getType(clazz: Class<*>): DataHandlerType? { + return when (clazz.javaClass.simpleName) { + "com.mparticle.MpEvent" -> MP_EVENT + "com.mparticle.commerce.CommerceEvent" -> COMMERCE_EVENT + else -> null + } + } + } + +} \ No newline at end of file diff --git a/android-core/src/main/java/com/mparticle/modernization/uploading/MParticleDataUploader.kt b/android-core/src/main/java/com/mparticle/modernization/datahandler/MParticleDataHandler.kt similarity index 51% rename from android-core/src/main/java/com/mparticle/modernization/uploading/MParticleDataUploader.kt rename to android-core/src/main/java/com/mparticle/modernization/datahandler/MParticleDataHandler.kt index ef0259fdd..93223f118 100644 --- a/android-core/src/main/java/com/mparticle/modernization/uploading/MParticleDataUploader.kt +++ b/android-core/src/main/java/com/mparticle/modernization/datahandler/MParticleDataHandler.kt @@ -1,25 +1,20 @@ -package com.mparticle.modernization.uploading +package com.mparticle.modernization.datahandler import com.mparticle.modernization.core.MParticleComponent import org.jetbrains.annotations.NotNull -internal interface MParticleDataUploader : MParticleComponent { +internal interface MParticleDataHandler : MParticleComponent { /** - * Upload set of data using provided strategies. Decision made base on [type] + *Save set of data using provided strategies. Decision made base on [type] * * @param data any type of data. Each strategy is responsible of converting and handling the data - * @param type an int (we recommend creating an enum class defining the types, each with and Int value * @param immediateUpload true or false depending if we want to force immediate data upload. By * default this is false */ - suspend fun upload( + suspend fun saveData( @NotNull data: Any, - @NotNull type: Int, @NotNull immediateUpload: Boolean = false ) - /** - * Trigger data uploader configuration. Called on DataUploader initialization - */ suspend fun configure() {} } diff --git a/android-core/src/main/java/com/mparticle/modernization/datahandler/MParticleDataHandlerStrategy.kt b/android-core/src/main/java/com/mparticle/modernization/datahandler/MParticleDataHandlerStrategy.kt new file mode 100644 index 000000000..02229cb93 --- /dev/null +++ b/android-core/src/main/java/com/mparticle/modernization/datahandler/MParticleDataHandlerStrategy.kt @@ -0,0 +1,44 @@ +package com.mparticle.modernization.datahandler + + +import com.mparticle.modernization.BatchManager +import org.jetbrains.annotations.NotNull + +/** + * Data uploading strategies for different data types + */ +internal interface MParticleDataHandlerStrategy { + /** Upload set of data + * + * @param data any type of data to upload + * @param immediateUpload true or false depending if we want to force immediate data upload. By + * default this is false + * @param uploadingConfiguration to handle auto-data uploads or other custom implementation based + * on a configuration. + */ + suspend fun saveData( + @NotNull data: Any, + @NotNull immediateUpload: Boolean + ) + + suspend fun retrieveData(): List + + fun I.toDto(): O? + + fun O.toModel(): I? + + /** + * @return strategy id + */ + fun type(): DataHandlerType + +} + +abstract class BaseMParticleDataHandlerStrategy(protected val batchManager: BatchManager) : + MParticleDataHandlerStrategy { + protected open suspend fun createAndUploadBatch() { + with(batchManager) { + createBatch()?.let { this.uploadBatch(it) } + } + } +} diff --git a/android-core/src/main/java/com/mparticle/modernization/datahandler/MParticleDataStrategyManagerImpl.kt b/android-core/src/main/java/com/mparticle/modernization/datahandler/MParticleDataStrategyManagerImpl.kt new file mode 100644 index 000000000..f2eec07ed --- /dev/null +++ b/android-core/src/main/java/com/mparticle/modernization/datahandler/MParticleDataStrategyManagerImpl.kt @@ -0,0 +1,18 @@ +package com.mparticle.modernization.datahandler + +internal class MParticleDataStrategyManagerImpl( + private val strategies: List>, +) : MParticleDataHandler { + + /** + * Based on the data type we will choose the corresponding strategy provided at config type, and + * execute an action on it. + */ + override suspend fun saveData(data: Any, immediateUpload: Boolean) { + data.javaClass.getStrategy()?.saveData(data, immediateUpload) + } + + private fun Class<*>.getStrategy(): MParticleDataHandlerStrategy<*, *>? = + strategies.firstOrNull { it.type() == DataHandlerType.getType(this) } + +} diff --git a/android-core/src/main/java/com/mparticle/modernization/datahandler/example/MParticleCommerceHandler.kt b/android-core/src/main/java/com/mparticle/modernization/datahandler/example/MParticleCommerceHandler.kt new file mode 100644 index 000000000..c85279938 --- /dev/null +++ b/android-core/src/main/java/com/mparticle/modernization/datahandler/example/MParticleCommerceHandler.kt @@ -0,0 +1,62 @@ +package com.mparticle.modernization.datahandler.example + +import com.mparticle.commerce.CommerceEvent +import com.mparticle.commerce.Product +import com.mparticle.internal.messages.BaseMPMessage +import com.mparticle.modernization.BatchManager +import com.mparticle.modernization.data.MParticleDataRepository +import com.mparticle.modernization.datahandler.BaseMParticleDataHandlerStrategy +import com.mparticle.modernization.datahandler.DataHandlerType + +/** + * As an example, each data specific type would have a handler (using the strategy pattern), + * and inherit from a baseHandler with cross type capabilities (batch operations, etc) + * + * As an example I wrote a couple of operations to save/retrieve data and convert data from and to + * businessModel/DTO. + * Each type will create a concrete strategy implementing the defined operations and specifying its type + */ +internal class MParticleCommerceHandler( + private val dataRepository: MParticleDataRepository, + batchManager: BatchManager +) : BaseMParticleDataHandlerStrategy(batchManager) { + + override suspend fun saveData( + data: Any, + immediateUpload: Boolean + ) { + (data as CommerceEvent).toDto()?.let { + with(dataRepository) { insertCommerceDTO(it) } + } + if (immediateUpload) { + createAndUploadBatch() + } + } + + override suspend fun retrieveData(): List { + return with(dataRepository) { getEventsByType() ?: emptyList() } + } + + override fun type(): DataHandlerType = DataHandlerType.COMMERCE_EVENT + + override fun BaseMPMessage.toModel(): CommerceEvent? { + //Grab a String and convert it into a business model object + var strProduct = Product.fromString("") + var productAction = Product.ADD_TO_CART + return CommerceEvent.Builder(productAction, strProduct).build() + } + + override fun CommerceEvent.toDto(): BaseMPMessage? { + // val message = BaseMPMessage.Builder(Constants.MessageType.BREADCRUMB). +// .timestamp(mAppStateManager.getSession().mLastEventTime) +// .build(mAppStateManager.getSession(), mLocation, mConfigManager.getMpid()) +// +// message.put(MessageKey.EVENT_START_TIME, mAppStateManager.getSession().mLastEventTime) +// message.put( +// MessageKey.BREADCRUMB_SESSION_COUNTER, +// mConfigManager.getUserStorage().getCurrentSessionCounter() +// ) +// message.put(MessageKey.BREADCRUMB_LABEL, breadcrumb) + return null + } +} diff --git a/android-core/src/main/java/com/mparticle/modernization/eventlogging/MParticleEventLogging.kt b/android-core/src/main/java/com/mparticle/modernization/eventlogging/MParticleEventLogging.kt index ccd48ea2a..5f68ced75 100644 --- a/android-core/src/main/java/com/mparticle/modernization/eventlogging/MParticleEventLogging.kt +++ b/android-core/src/main/java/com/mparticle/modernization/eventlogging/MParticleEventLogging.kt @@ -7,47 +7,20 @@ import org.jetbrains.annotations.Nullable import java.math.BigDecimal internal interface MParticleEventLogging : MParticleComponent { - // All common, commerce, screen, pushRegistration, notification, notificationOpened and NetworkPerformance events should be logged with the same function + // All common, commerce, screen, pushRegistration, ltvIncrease, breadcrumb, exception, notification, notificationOpened and NetworkPerformance events should be logged with the same function /** * Log an event - TODO review EventBuilder to be able to build all type of events * @param event to log */ fun logEvent(@NotNull event: BaseEvent) - /** - * Leave breadcrumb - * @param breadcrumb - */ - fun leaveBreadcrumb(@NotNull breadcrumb: String) /** * Log an error * @param message * @param params optional by default null - */ - fun logError(@NotNull message: String, @Nullable params: Map? = null) - - /** - * Log lifetime value increase - * @param valueIncreased - * @param eventName optional by default null - * @param params optional by default null - */ - fun logLtvIncrease( - @NotNull valueIncreased: BigDecimal, - @Nullable eventName: String? = null, - @Nullable params: Map? = null - ) - - /** - * Log exception * @param exception - * @param message optional by default null - * @param params optional by default null */ - fun logException( - @NotNull exception: Exception, - @Nullable message: String? = null, - @Nullable params: Map? = null - ) + fun logError(@NotNull message: String, @Nullable params: Map? = null, @Nullable exception : Exception?) + } diff --git a/android-core/src/main/java/com/mparticle/modernization/eventlogging/example/MParticleEventLoggingImpl.kt b/android-core/src/main/java/com/mparticle/modernization/eventlogging/example/MParticleEventLoggingImpl.kt index 6d031e7de..a5b28c998 100644 --- a/android-core/src/main/java/com/mparticle/modernization/eventlogging/example/MParticleEventLoggingImpl.kt +++ b/android-core/src/main/java/com/mparticle/modernization/eventlogging/example/MParticleEventLoggingImpl.kt @@ -3,36 +3,26 @@ package com.mparticle.modernization.eventlogging.example import com.mparticle.BaseEvent import com.mparticle.modernization.core.MParticleMediator import com.mparticle.modernization.eventlogging.MParticleEventLogging -import java.math.BigDecimal +import com.mparticle.modernization.kit.MParticleKit internal class MParticleEventLoggingImpl(private val mediator: MParticleMediator) : MParticleEventLogging { + /** + * The component is incharge of event logging itself, by delegation its responsability to the + * different kits (by using the kitManager component from the mediator). + * Because each kit migth have a different configuration to follow in order to "log an event", + * specifically us - we filter, create and handle projectsion, apply rules etc, this class should + * be only incharge of cross kit pre/post processing. + */ override fun logEvent(event: BaseEvent) { - TODO("Not yet implemented") - } - - override fun leaveBreadcrumb(breadcrumb: String) { - mediator.kitManager?.leaveBreadcrumb(breadcrumb) - } - - override fun logError(message: String, params: Map?) { - TODO("Not yet implemented") + //pre-process stuff + mediator.kitManager?.logEvent(event) + //post-process stuff } - override fun logLtvIncrease( - valueIncreased: BigDecimal, - eventName: String?, - params: Map? - ) { + override fun logError(message: String, params: Map?, exception: Exception?) { TODO("Not yet implemented") } - override fun logException( - exception: Exception, - message: String?, - params: Map? - ) { - TODO("Not yet implemented") - } } diff --git a/android-core/src/main/java/com/mparticle/modernization/identity/IdentityCallback.kt b/android-core/src/main/java/com/mparticle/modernization/identity/IdentityCallback.kt index d1dc88fd1..637a7e0b0 100644 --- a/android-core/src/main/java/com/mparticle/modernization/identity/IdentityCallback.kt +++ b/android-core/src/main/java/com/mparticle/modernization/identity/IdentityCallback.kt @@ -3,4 +3,8 @@ package com.mparticle.modernization.identity import com.mparticle.identity.IdentityApiResult import com.mparticle.modernization.MParticleCallback +/** + * Example of the identity callback extending the standarized behavior of the MParticleCallback + * that defines success and error + */ internal open class IdentityCallback : MParticleCallback() diff --git a/android-core/src/main/java/com/mparticle/modernization/identity/MParticleIdentity.kt b/android-core/src/main/java/com/mparticle/modernization/identity/MParticleIdentity.kt index d56aa9f46..8f2c4179c 100644 --- a/android-core/src/main/java/com/mparticle/modernization/identity/MParticleIdentity.kt +++ b/android-core/src/main/java/com/mparticle/modernization/identity/MParticleIdentity.kt @@ -91,4 +91,3 @@ internal interface InternalIdentity : MParticleIdentity { suspend fun login(@NotNull request: IdentityApiRequest): IdentityApiResult } -internal interface IdentityListener diff --git a/android-core/src/main/java/com/mparticle/modernization/identity/example/MParticleIdentityImpl.kt b/android-core/src/main/java/com/mparticle/modernization/identity/example/MParticleIdentityImpl.kt index fc9fa0844..e63ccc711 100644 --- a/android-core/src/main/java/com/mparticle/modernization/identity/example/MParticleIdentityImpl.kt +++ b/android-core/src/main/java/com/mparticle/modernization/identity/example/MParticleIdentityImpl.kt @@ -8,6 +8,10 @@ import com.mparticle.modernization.core.MParticleMediator import com.mparticle.modernization.identity.IdentityCallback import com.mparticle.modernization.identity.InternalIdentity +/** + * I would recomend using two implementations coroutine/callbacks, being the coroutine one the internal. + * The one with callback could use the coroutine implementation. + */ internal class MParticleIdentityImpl(private val mediator: MParticleMediator) : InternalIdentity { override suspend fun identify(request: IdentityApiRequest): IdentityApiResult { diff --git a/android-core/src/main/java/com/mparticle/modernization/kit/KitConfiguration.kt b/android-core/src/main/java/com/mparticle/modernization/kit/KitConfiguration.kt new file mode 100644 index 000000000..58d235300 --- /dev/null +++ b/android-core/src/main/java/com/mparticle/modernization/kit/KitConfiguration.kt @@ -0,0 +1,8 @@ +package com.mparticle.modernization.kit + +/** + * Abstraction that should have the configuration for each kit (might be passed when creating the + * instance of the kit or onKitCreate if resolved after the instance is created) + */ +class KitConfiguration { +} \ No newline at end of file diff --git a/android-core/src/main/java/com/mparticle/modernization/kit/KitListeners.kt b/android-core/src/main/java/com/mparticle/modernization/kit/KitListeners.kt new file mode 100644 index 000000000..8b226dd26 --- /dev/null +++ b/android-core/src/main/java/com/mparticle/modernization/kit/KitListeners.kt @@ -0,0 +1,25 @@ +package com.mparticle.modernization.kit + +import android.content.Context +import com.mparticle.MPEvent +import com.mparticle.commerce.CommerceEvent + +/** + * Listeners for the kits + */ +interface CommerceListener { + fun commerceEventLogged(event : CommerceEvent) +// fun ltvIncreaseEventLogged(event : LtvIncreaseEvent) +} +interface EventListener{ + fun eventLogged(event : MPEvent) + fun errorLogged(message: String, params: Map?, exception: Exception?) + //breadcrumbLogged, screen logged, etc. +} +interface MPLifecycle { + fun onKitCreate(settings : Map, context : Context) {} +} +interface IdentityListener {} +interface UserProfileListener {} +interface PushListener {} +interface ActivityListener{} diff --git a/android-core/src/main/java/com/mparticle/modernization/kit/MParticleKit.kt b/android-core/src/main/java/com/mparticle/modernization/kit/MParticleKit.kt index 16d127401..ec9b43188 100644 --- a/android-core/src/main/java/com/mparticle/modernization/kit/MParticleKit.kt +++ b/android-core/src/main/java/com/mparticle/modernization/kit/MParticleKit.kt @@ -1,33 +1,8 @@ package com.mparticle.modernization.kit -import com.mparticle.BaseEvent -import com.mparticle.modernization.eventlogging.MParticleEventLogging -import java.math.BigDecimal - -internal abstract class MParticleKit : MParticleEventLogging { - - override fun logEvent(event: BaseEvent) { - } - - override fun leaveBreadcrumb(breadcrumb: String) { - } - - override fun logError(message: String, params: Map?) { - } - - override fun logException( - exception: Exception, - message: String?, - params: Map? - ) { - } - - override fun logLtvIncrease( - valueIncreased: BigDecimal, - eventName: String?, - params: Map? - ) { - } +internal abstract class MParticleKit : MPLifecycle { + abstract fun getConfiguration() : KitConfiguration +} +internal abstract class MParticleKitInternal : MParticleKit() { } -internal abstract class MParticleKitInternal : MParticleKit() diff --git a/android-core/src/main/java/com/mparticle/modernization/kit/MParticleKitManager.kt b/android-core/src/main/java/com/mparticle/modernization/kit/MParticleKitManager.kt index 63815fb49..0d5945ee0 100644 --- a/android-core/src/main/java/com/mparticle/modernization/kit/MParticleKitManager.kt +++ b/android-core/src/main/java/com/mparticle/modernization/kit/MParticleKitManager.kt @@ -1,7 +1,10 @@ package com.mparticle.modernization.kit import com.mparticle.modernization.core.MParticleComponent +import com.mparticle.modernization.eventlogging.MParticleEventLogging -internal abstract class MParticleKitManager : MParticleKit() +internal abstract class MParticleKitManager : MParticleComponent -internal abstract class KitManagerInternal : MParticleKitManager(), MParticleComponent +internal abstract class KitManagerInternal : MParticleKitManager(), + MParticleEventLogging { +} diff --git a/android-core/src/main/java/com/mparticle/modernization/kit/MParticleKitManagerImpl.kt b/android-core/src/main/java/com/mparticle/modernization/kit/MParticleKitManagerImpl.kt index 96b892f21..70eb2d9cc 100644 --- a/android-core/src/main/java/com/mparticle/modernization/kit/MParticleKitManagerImpl.kt +++ b/android-core/src/main/java/com/mparticle/modernization/kit/MParticleKitManagerImpl.kt @@ -1,10 +1,39 @@ package com.mparticle.modernization.kit +import com.mparticle.BaseEvent +import com.mparticle.MPEvent +import com.mparticle.commerce.CommerceEvent +import com.mparticle.modernization.kit.example.MpKit + internal class MParticleKitManagerImpl( private val kits: MutableList ) : KitManagerInternal() { - override fun leaveBreadcrumb(breadcrumb: String) { - kits.forEach { it.leaveBreadcrumb(breadcrumb) } + private fun doInKits(action: (kit: MParticleKit) -> Unit) { + kits.forEach { action.invoke(it) } + } + + private fun CommerceEvent.processEvent() { + doInKits{ if (it is CommerceListener) { it.commerceEventLogged(this) } } + } + private fun MPEvent.processEvent() { + doInKits{ if (it is EventListener) { it.eventLogged(this) } } + } + + + override fun logEvent(event: BaseEvent) { + when (event) { + is CommerceEvent -> event.processEvent() + is MPEvent -> event.processEvent() + else -> {} + } + } + + override fun logError( + message: String, + params: Map?, + exception: Exception? + ) { + doInKits { if (it is EventListener) { it.errorLogged(message, params, exception) } } } } diff --git a/android-core/src/main/java/com/mparticle/modernization/kit/example/CustomKit.kt b/android-core/src/main/java/com/mparticle/modernization/kit/example/CustomKit.kt deleted file mode 100644 index c079f5ba5..000000000 --- a/android-core/src/main/java/com/mparticle/modernization/kit/example/CustomKit.kt +++ /dev/null @@ -1,11 +0,0 @@ -package com.mparticle.modernization.kit.example - -import android.util.Log -import com.mparticle.BaseEvent -import com.mparticle.modernization.kit.MParticleKit - -internal class CustomKit : MParticleKit() { - override fun logEvent(event: BaseEvent) { - Log.d("CUSTOM_LOG", event.toString()) - } -} diff --git a/android-core/src/main/java/com/mparticle/modernization/kit/example/MpKit.kt b/android-core/src/main/java/com/mparticle/modernization/kit/example/MpKit.kt index 7922e9204..ce5fdbb19 100644 --- a/android-core/src/main/java/com/mparticle/modernization/kit/example/MpKit.kt +++ b/android-core/src/main/java/com/mparticle/modernization/kit/example/MpKit.kt @@ -1,15 +1,41 @@ package com.mparticle.modernization.kit.example +import com.mparticle.MPEvent +import com.mparticle.commerce.CommerceEvent import com.mparticle.modernization.core.MParticleMediator +import com.mparticle.modernization.kit.CommerceListener +import com.mparticle.modernization.kit.EventListener import com.mparticle.modernization.kit.MParticleKitInternal import com.mparticle.modernization.launch -import com.mparticle.modernization.uploading.example.MParticleUploaderTypes +import com.mparticle.modernization.datahandler.MParticleDataHandler +import com.mparticle.modernization.kit.KitConfiguration -internal class MpKit(private val mediator: MParticleMediator) : MParticleKitInternal() { +/** + * MParticle business related logic. The component should delegate to the kitManager, and the kit manager + * delegate to each kit (being MParticle a specific use case). + * While a third-party kit wrapper like OneTrust will operate against their SDK, this one will trigger + * their internal managers and structure to manage data pre-processing,storing/retrieval,mapping,parsing,upload. + */ +internal class MpKit( + private val mediator: MParticleMediator, + private val dataHandler: MParticleDataHandler +) : MParticleKitInternal(), + CommerceListener, EventListener { - override fun leaveBreadcrumb(breadcrumb: String) { - mediator.launch { - mediator.dataUploader?.upload(breadcrumb, MParticleUploaderTypes.BREADCRUMB.type) - } + override fun commerceEventLogged(event: CommerceEvent) { + //TODO Filter, handle projections and save event + mediator.launch { dataHandler.saveData(event, true) } + } + + override fun eventLogged(event: MPEvent) { + mediator.launch { dataHandler.saveData(event) } + } + + override fun errorLogged(message: String, params: Map?, exception: Exception?) { + TODO("Not yet implemented") + } + + override fun getConfiguration(): KitConfiguration { + TODO("Not yet implemented") } } diff --git a/android-core/src/main/java/com/mparticle/modernization/kit/example/XKit.kt b/android-core/src/main/java/com/mparticle/modernization/kit/example/XKit.kt index 960cf5347..10bd64b66 100644 --- a/android-core/src/main/java/com/mparticle/modernization/kit/example/XKit.kt +++ b/android-core/src/main/java/com/mparticle/modernization/kit/example/XKit.kt @@ -1,11 +1,23 @@ package com.mparticle.modernization.kit.example -import com.mparticle.BaseEvent -import com.mparticle.modernization.core.MParticleMediator +import android.util.Log +import com.mparticle.MPEvent +import com.mparticle.modernization.kit.EventListener +import com.mparticle.modernization.kit.KitConfiguration import com.mparticle.modernization.kit.MParticleKitInternal -internal class XKit(private val mediator: MParticleMediator) : MParticleKitInternal() { - override fun logEvent(event: BaseEvent) { +internal class XKit() : MParticleKitInternal(), EventListener { + + override fun getConfiguration(): KitConfiguration { TODO("Not yet implemented") } + + override fun eventLogged(event: MPEvent) { + Log.d("MP_EVENT", event.toString()) + } + + override fun errorLogged(message: String, params: Map?, exception: Exception?) { + TODO("Not yet implemented") + } + } diff --git a/android-core/src/main/java/com/mparticle/modernization/uploading/MParticleDataUploaderImpl.kt b/android-core/src/main/java/com/mparticle/modernization/uploading/MParticleDataUploaderImpl.kt deleted file mode 100644 index 58f33f3a8..000000000 --- a/android-core/src/main/java/com/mparticle/modernization/uploading/MParticleDataUploaderImpl.kt +++ /dev/null @@ -1,26 +0,0 @@ -package com.mparticle.modernization.uploading - -import com.mparticle.modernization.config.UploadingConfiguration -import com.mparticle.modernization.core.MParticleMediator -import com.mparticle.modernization.launch - -internal class MParticleDataUploaderImpl( - private val mediator: MParticleMediator, - private val strategies: List, - private val uploadingConfiguration: UploadingConfiguration? = null -) : MParticleDataUploader { - init { - mediator.launch { configure() } - } - - override suspend fun upload(data: Any, type: Int, immediateUpload: Boolean) { - type.getStrategy()?.upload(data, immediateUpload, uploadingConfiguration) - } - - override suspend fun configure() { - // setup uploading every X based on uploadingConfiguration rules and server settings we might inject - } - - private fun Int.getStrategy(): MParticleUploadingStrategy? = - strategies.firstOrNull { it.type() == this } -} diff --git a/android-core/src/main/java/com/mparticle/modernization/uploading/MParticleUploadingStrategy.kt b/android-core/src/main/java/com/mparticle/modernization/uploading/MParticleUploadingStrategy.kt deleted file mode 100644 index 19635fb51..000000000 --- a/android-core/src/main/java/com/mparticle/modernization/uploading/MParticleUploadingStrategy.kt +++ /dev/null @@ -1,29 +0,0 @@ -package com.mparticle.modernization.uploading - -import com.mparticle.modernization.config.UploadingConfiguration -import org.jetbrains.annotations.NotNull -import org.jetbrains.annotations.Nullable - -/** - * Data uploading strategies for different data types - */ -internal interface MParticleUploadingStrategy { - /** Upload set of data - * - * @param data any type of data to upload - * @param immediateUpload true or false depending if we want to force immediate data upload. By - * default this is false - * @param uploadingConfiguration to handle auto-data uploads or other custom implementation based - * on a configuration. - */ - suspend fun upload( - @NotNull data: Any, - @NotNull immediateUpload: Boolean, - @Nullable uploadingConfiguration: UploadingConfiguration? - ) - - /** - * @return strategy id - */ - fun type(): Int -} diff --git a/android-core/src/main/java/com/mparticle/modernization/uploading/example/MParticleBreadcrumbUploading.kt b/android-core/src/main/java/com/mparticle/modernization/uploading/example/MParticleBreadcrumbUploading.kt deleted file mode 100644 index 11ba83649..000000000 --- a/android-core/src/main/java/com/mparticle/modernization/uploading/example/MParticleBreadcrumbUploading.kt +++ /dev/null @@ -1,42 +0,0 @@ -package com.mparticle.modernization.uploading.example - -import com.mparticle.internal.messages.BaseMPMessage -import com.mparticle.modernization.config.UploadingConfiguration -import com.mparticle.modernization.data.MParticleDataRepository -import com.mparticle.modernization.uploading.MParticleUploadingStrategy - -internal class MParticleBreadcrumbUploading(private val dataRepository: MParticleDataRepository) : - MParticleUploadingStrategy { - override suspend fun upload( - data: Any, - immediateUpload: Boolean, - uploadingConfiguration: UploadingConfiguration? - ) { - data.convert()?.let { - with(dataRepository) { - updateSession(it) - it.addBreadcurmbData()?.let { insertBreadcrumb(it) } - } - } - if (immediateUpload) { sendData() } - } - - private suspend fun sendData() {} - - private fun BaseMPMessage?.addBreadcurmbData(): BaseMPMessage? = null - private fun Any.convert(): BaseMPMessage? { -// val message = BaseMPMessage.Builder(Constants.MessageType.BREADCRUMB). -// .timestamp(mAppStateManager.getSession().mLastEventTime) -// .build(mAppStateManager.getSession(), mLocation, mConfigManager.getMpid()) -// -// message.put(MessageKey.EVENT_START_TIME, mAppStateManager.getSession().mLastEventTime) -// message.put( -// MessageKey.BREADCRUMB_SESSION_COUNTER, -// mConfigManager.getUserStorage().getCurrentSessionCounter() -// ) -// message.put(MessageKey.BREADCRUMB_LABEL, breadcrumb) - return null - } - - override fun type(): Int = MParticleUploaderTypes.BREADCRUMB.type -}