From a12ecce7a2a0ca6342b1d43386b81c66d9285a4b Mon Sep 17 00:00:00 2001 From: markvdouw Date: Fri, 7 Apr 2023 11:06:19 -0300 Subject: [PATCH 1/6] feat: SDSDKS-5109 Modernization Interfaces (#339) * Adding modernization interfaces * Changes to accomodate interfaces * 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. * KtlintFormat * Ktlint format * Making everything internal as of now * Making everything internal as of now * Ktlint format --- android-core/build.gradle | 5 +- .../modernization/MParticleCallback.kt | 16 ++++ .../java/com/mparticle/modernization/Utils.kt | 9 ++ .../config/UploadingConfiguration.kt | 3 + .../mparticle/modernization/core/MParticle.kt | 31 ++++++ .../modernization/core/MParticleComponent.kt | 3 + .../modernization/core/MParticleMediator.kt | 53 +++++++++++ .../data/MParticleDataRepository.kt | 10 ++ .../eventlogging/MParticleEventLogging.kt | 53 +++++++++++ .../example/MParticleEventLoggingImpl.kt | 38 ++++++++ .../identity/IdentityCallback.kt | 6 ++ .../identity/MParticleIdentity.kt | 94 +++++++++++++++++++ .../identity/example/MParticleIdentityImpl.kt | 60 ++++++++++++ .../modernization/kit/MParticleKit.kt | 33 +++++++ .../modernization/kit/MParticleKitManager.kt | 7 ++ .../kit/MParticleKitManagerImpl.kt | 10 ++ .../modernization/kit/example/CustomKit.kt | 11 +++ .../modernization/kit/example/MpKit.kt | 15 +++ .../modernization/kit/example/XKit.kt | 11 +++ .../uploading/MParticleDataUploader.kt | 25 +++++ .../uploading/MParticleDataUploaderImpl.kt | 26 +++++ .../uploading/MParticleUploadingStrategy.kt | 29 ++++++ .../example/MParticleBreadcrumbUploading.kt | 42 +++++++++ .../example/MParticleUploaderTypes.kt | 5 + 24 files changed, 594 insertions(+), 1 deletion(-) create mode 100644 android-core/src/main/java/com/mparticle/modernization/MParticleCallback.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 create mode 100644 android-core/src/main/java/com/mparticle/modernization/core/MParticle.kt 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/MParticleMediator.kt create mode 100644 android-core/src/main/java/com/mparticle/modernization/data/MParticleDataRepository.kt create mode 100644 android-core/src/main/java/com/mparticle/modernization/eventlogging/MParticleEventLogging.kt create mode 100644 android-core/src/main/java/com/mparticle/modernization/eventlogging/example/MParticleEventLoggingImpl.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/MParticleIdentity.kt create mode 100644 android-core/src/main/java/com/mparticle/modernization/identity/example/MParticleIdentityImpl.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/example/CustomKit.kt create mode 100644 android-core/src/main/java/com/mparticle/modernization/kit/example/MpKit.kt create mode 100644 android-core/src/main/java/com/mparticle/modernization/kit/example/XKit.kt create mode 100644 android-core/src/main/java/com/mparticle/modernization/uploading/MParticleDataUploader.kt create mode 100644 android-core/src/main/java/com/mparticle/modernization/uploading/MParticleDataUploaderImpl.kt create mode 100644 android-core/src/main/java/com/mparticle/modernization/uploading/MParticleUploadingStrategy.kt create mode 100644 android-core/src/main/java/com/mparticle/modernization/uploading/example/MParticleBreadcrumbUploading.kt create mode 100644 android-core/src/main/java/com/mparticle/modernization/uploading/example/MParticleUploaderTypes.kt diff --git a/android-core/build.gradle b/android-core/build.gradle index e92819e43..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/') } } } @@ -135,6 +136,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 new file mode 100644 index 000000000..b4ba7d71d --- /dev/null +++ b/android-core/src/main/java/com/mparticle/modernization/MParticleCallback.kt @@ -0,0 +1,16 @@ +package com.mparticle.modernization + +internal 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/Utils.kt b/android-core/src/main/java/com/mparticle/modernization/Utils.kt new file mode 100644 index 000000000..32e0df656 --- /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 + +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 new file mode 100644 index 000000000..929119d9c --- /dev/null +++ b/android-core/src/main/java/com/mparticle/modernization/config/UploadingConfiguration.kt @@ -0,0 +1,3 @@ +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 new file mode 100644 index 000000000..632fbeb0d --- /dev/null +++ b/android-core/src/main/java/com/mparticle/modernization/core/MParticle.kt @@ -0,0 +1,31 @@ +package com.mparticle.modernization.core + +import com.mparticle.MParticleOptions +import com.mparticle.modernization.eventlogging.MParticleEventLogging +import com.mparticle.modernization.identity.MParticleIdentity +import com.mparticle.modernization.kit.MParticleKitManager +import com.mparticle.modernization.uploading.MParticleDataUploader + +internal class MParticle private constructor(private val options: MParticleOptions) { + private var mediator: MParticleMediator = MParticleMediator() + + init { + mediator.configure(options) + } + + companion object { + private var _instance: MParticle? = null + + @Throws(Exception::class) + fun getInstance(): MParticle = _instance ?: throw Exception("MParticle must be started before getting the instance") + + fun start(options: MParticleOptions) { + _instance = MParticle(options) + } + } + + 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/MParticleComponent.kt b/android-core/src/main/java/com/mparticle/modernization/core/MParticleComponent.kt new file mode 100644 index 000000000..90249455d --- /dev/null +++ b/android-core/src/main/java/com/mparticle/modernization/core/MParticleComponent.kt @@ -0,0 +1,3 @@ +package com.mparticle.modernization.core + +internal interface MParticleComponent 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..db6dfeb5a --- /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.eventlogging.MParticleEventLogging +import com.mparticle.modernization.eventlogging.example.MParticleEventLoggingImpl +import com.mparticle.modernization.identity.InternalIdentity +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.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 +import kotlinx.coroutines.asCoroutineDispatcher +import java.util.concurrent.Executors + +internal 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 + } + } +} 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..dca7fb0be --- /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 + +internal class MParticleDataRepository { + + suspend fun updateSession(data: BaseMPMessage) {} + + suspend fun insertBreadcrumb(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 new file mode 100644 index 000000000..ccd48ea2a --- /dev/null +++ b/android-core/src/main/java/com/mparticle/modernization/eventlogging/MParticleEventLogging.kt @@ -0,0 +1,53 @@ +package com.mparticle.modernization.eventlogging + +import com.mparticle.BaseEvent +import com.mparticle.modernization.core.MParticleComponent +import org.jetbrains.annotations.NotNull +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 + /** + * 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 + ) +} 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 new file mode 100644 index 000000000..6d031e7de --- /dev/null +++ b/android-core/src/main/java/com/mparticle/modernization/eventlogging/example/MParticleEventLoggingImpl.kt @@ -0,0 +1,38 @@ +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 + +internal class MParticleEventLoggingImpl(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") + } +} 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..d1dc88fd1 --- /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 + +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 new file mode 100644 index 000000000..d56aa9f46 --- /dev/null +++ b/android-core/src/main/java/com/mparticle/modernization/identity/MParticleIdentity.kt @@ -0,0 +1,94 @@ +package com.mparticle.modernization.identity + +import com.mparticle.identity.IdentityApiRequest +import com.mparticle.identity.IdentityApiResult +import com.mparticle.identity.MParticleUser +import com.mparticle.modernization.MParticleCallback +import com.mparticle.modernization.core.MParticleComponent +import org.jetbrains.annotations.NotNull +import org.jetbrains.annotations.Nullable + +internal interface MParticleIdentity : MParticleComponent { + + /** + * Login + * @param callback + */ + fun login(@NotNull callback: IdentityCallback) + + /** + * Logout + * @param callback + */ + fun logout(@NotNull callback: IdentityCallback) + + /** + * 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 { + /** + * 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 +} + +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 new file mode 100644 index 000000000..fc9fa0844 --- /dev/null +++ b/android-core/src/main/java/com/mparticle/modernization/identity/example/MParticleIdentityImpl.kt @@ -0,0 +1,60 @@ +package com.mparticle.modernization.identity.example + +import com.mparticle.identity.IdentityApiRequest +import com.mparticle.identity.IdentityApiResult +import com.mparticle.identity.MParticleUser +import com.mparticle.modernization.MParticleCallback +import com.mparticle.modernization.core.MParticleMediator +import com.mparticle.modernization.identity.IdentityCallback +import com.mparticle.modernization.identity.InternalIdentity + +internal class MParticleIdentityImpl(private val mediator: MParticleMediator) : + InternalIdentity { + override suspend fun identify(request: IdentityApiRequest): IdentityApiResult { + TODO("Not yet implemented") + } + + override suspend fun modify(request: IdentityApiRequest): IdentityApiResult { + TODO("Not yet implemented") + } + + override suspend fun logout(request: IdentityApiRequest): IdentityApiResult { + TODO("Not yet implemented") + } + + override fun logout(callback: IdentityCallback) { + TODO("Not yet implemented") + } + + override suspend fun logout(): IdentityApiResult { + TODO("Not yet implemented") + } + + override suspend fun login(request: IdentityApiRequest): IdentityApiResult { + TODO("Not yet implemented") + } + + override fun login(callback: IdentityCallback) { + 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") + } +} 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..16d127401 --- /dev/null +++ b/android-core/src/main/java/com/mparticle/modernization/kit/MParticleKit.kt @@ -0,0 +1,33 @@ +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 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 new file mode 100644 index 000000000..63815fb49 --- /dev/null +++ b/android-core/src/main/java/com/mparticle/modernization/kit/MParticleKitManager.kt @@ -0,0 +1,7 @@ +package com.mparticle.modernization.kit + +import com.mparticle.modernization.core.MParticleComponent + +internal abstract class MParticleKitManager : MParticleKit() + +internal 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 new file mode 100644 index 000000000..96b892f21 --- /dev/null +++ b/android-core/src/main/java/com/mparticle/modernization/kit/MParticleKitManagerImpl.kt @@ -0,0 +1,10 @@ +package com.mparticle.modernization.kit + +internal class MParticleKitManagerImpl( + private val kits: MutableList +) : KitManagerInternal() { + + override fun leaveBreadcrumb(breadcrumb: String) { + kits.forEach { it.leaveBreadcrumb(breadcrumb) } + } +} 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 new file mode 100644 index 000000000..c079f5ba5 --- /dev/null +++ b/android-core/src/main/java/com/mparticle/modernization/kit/example/CustomKit.kt @@ -0,0 +1,11 @@ +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 new file mode 100644 index 000000000..7922e9204 --- /dev/null +++ b/android-core/src/main/java/com/mparticle/modernization/kit/example/MpKit.kt @@ -0,0 +1,15 @@ +package com.mparticle.modernization.kit.example + +import com.mparticle.modernization.core.MParticleMediator +import com.mparticle.modernization.kit.MParticleKitInternal +import com.mparticle.modernization.launch +import com.mparticle.modernization.uploading.example.MParticleUploaderTypes + +internal class MpKit(private val mediator: MParticleMediator) : MParticleKitInternal() { + + override fun leaveBreadcrumb(breadcrumb: String) { + mediator.launch { + mediator.dataUploader?.upload(breadcrumb, MParticleUploaderTypes.BREADCRUMB.type) + } + } +} 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 new file mode 100644 index 000000000..960cf5347 --- /dev/null +++ b/android-core/src/main/java/com/mparticle/modernization/kit/example/XKit.kt @@ -0,0 +1,11 @@ +package com.mparticle.modernization.kit.example + +import com.mparticle.BaseEvent +import com.mparticle.modernization.core.MParticleMediator +import com.mparticle.modernization.kit.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 new file mode 100644 index 000000000..ef0259fdd --- /dev/null +++ b/android-core/src/main/java/com/mparticle/modernization/uploading/MParticleDataUploader.kt @@ -0,0 +1,25 @@ +package com.mparticle.modernization.uploading + +import com.mparticle.modernization.core.MParticleComponent +import org.jetbrains.annotations.NotNull + +internal 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 + ) + + /** + * Trigger data uploader configuration. Called on DataUploader initialization + */ + suspend fun configure() {} +} 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 new file mode 100644 index 000000000..58f33f3a8 --- /dev/null +++ b/android-core/src/main/java/com/mparticle/modernization/uploading/MParticleDataUploaderImpl.kt @@ -0,0 +1,26 @@ +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 new file mode 100644 index 000000000..19635fb51 --- /dev/null +++ b/android-core/src/main/java/com/mparticle/modernization/uploading/MParticleUploadingStrategy.kt @@ -0,0 +1,29 @@ +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 new file mode 100644 index 000000000..11ba83649 --- /dev/null +++ b/android-core/src/main/java/com/mparticle/modernization/uploading/example/MParticleBreadcrumbUploading.kt @@ -0,0 +1,42 @@ +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 +} 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 new file mode 100644 index 000000000..2fd8e3e68 --- /dev/null +++ b/android-core/src/main/java/com/mparticle/modernization/uploading/example/MParticleUploaderTypes.kt @@ -0,0 +1,5 @@ +package com.mparticle.modernization.uploading.example + +internal enum class MParticleUploaderTypes(val type: Int) { + EVENT(1), BREADCRUMB(2), DEFAULT(-1); +} From 5bf3cbc99b7c75d128ac97c8f097c34a2dad7ff2 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Fri, 31 Mar 2023 21:46:27 +0000 Subject: [PATCH 2/6] chore: bump org.codehaus.groovy:groovy-all from 3.0.13 to 3.0.17 (#355) Bumps [org.codehaus.groovy:groovy-all](https://github.com/apache/groovy) from 3.0.13 to 3.0.17. - [Release notes](https://github.com/apache/groovy/releases) - [Commits](https://github.com/apache/groovy/commits) --- updated-dependencies: - dependency-name: org.codehaus.groovy:groovy-all dependency-type: direct:production update-type: version-update:semver-patch ... Signed-off-by: dependabot[bot] Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> --- tooling/custom-lint-rules/build.gradle | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) mode change 100755 => 100644 tooling/custom-lint-rules/build.gradle diff --git a/tooling/custom-lint-rules/build.gradle b/tooling/custom-lint-rules/build.gradle old mode 100755 new mode 100644 index 99af1017b..b892364ed --- a/tooling/custom-lint-rules/build.gradle +++ b/tooling/custom-lint-rules/build.gradle @@ -42,7 +42,7 @@ dependencies { implementation configurations.lintJar compileOnly "com.android.tools.lint:lint-api:$lintVersion" compileOnly "com.android.tools.lint:lint-checks:$lintVersion" - compileOnly 'org.codehaus.groovy:groovy-all:3.0.13' + compileOnly 'org.codehaus.groovy:groovy-all:3.0.17' testImplementation 'junit:junit:4.13.2' testImplementation "com.android.tools.lint:lint:$lintVersion" testImplementation "com.android.tools.lint:lint-tests:$lintVersion" From a26594f14ebcf84a6c2ea7d4ab03d078e8d9b36a Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Fri, 31 Mar 2023 23:14:13 +0000 Subject: [PATCH 3/6] chore: bump androidx.annotation:annotation from 1.5.0 to 1.6.0 (#357) Bumps androidx.annotation:annotation from 1.5.0 to 1.6.0. --- updated-dependencies: - dependency-name: androidx.annotation:annotation dependency-type: direct:production update-type: version-update:semver-minor ... Signed-off-by: dependabot[bot] Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> --- testutils/build.gradle | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/testutils/build.gradle b/testutils/build.gradle index 3e07b087c..133862a0d 100644 --- a/testutils/build.gradle +++ b/testutils/build.gradle @@ -52,7 +52,7 @@ dependencies { compileOnly project(':android-kit-base') compileOnly 'org.mockito:mockito-android:4.9.0' - api 'androidx.annotation:annotation:1.5.0' + api 'androidx.annotation:annotation:1.6.0' api 'androidx.test.ext:junit:1.1.4' api 'androidx.test:rules:1.5.0' From 41f4595159e70ba35442e4fe83d1b16f06fc561d Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Fri, 31 Mar 2023 23:26:19 +0000 Subject: [PATCH 4/6] chore: bump androidx.test.ext:junit from 1.1.4 to 1.1.5 (#356) Bumps androidx.test.ext:junit from 1.1.4 to 1.1.5. --- updated-dependencies: - dependency-name: androidx.test.ext:junit dependency-type: direct:production update-type: version-update:semver-patch ... Signed-off-by: dependabot[bot] Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> --- testutils/build.gradle | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/testutils/build.gradle b/testutils/build.gradle index 133862a0d..055a56df0 100644 --- a/testutils/build.gradle +++ b/testutils/build.gradle @@ -53,7 +53,7 @@ dependencies { compileOnly 'org.mockito:mockito-android:4.9.0' api 'androidx.annotation:annotation:1.6.0' - api 'androidx.test.ext:junit:1.1.4' + api 'androidx.test.ext:junit:1.1.5' api 'androidx.test:rules:1.5.0' androidTestCompileOnly project(':android-core') @@ -65,7 +65,7 @@ dependencies { } androidTestImplementation 'androidx.test:runner:1.3.0' - androidTestImplementation 'androidx.test.ext:junit:1.1.4' + androidTestImplementation 'androidx.test.ext:junit:1.1.5' androidTestImplementation 'androidx.test:rules:1.5.0' androidTestImplementation 'com.google.firebase:firebase-messaging:20.0.0' From 86cceb28df459b322ba737e4761dab186d06de9f Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Fri, 31 Mar 2023 23:40:56 +0000 Subject: [PATCH 5/6] chore: bump org.mockito:mockito-android from 4.9.0 to 5.2.0 (#358) Bumps [org.mockito:mockito-android](https://github.com/mockito/mockito) from 4.9.0 to 5.2.0. - [Release notes](https://github.com/mockito/mockito/releases) - [Commits](https://github.com/mockito/mockito/compare/v4.9.0...v5.2.0) --- updated-dependencies: - dependency-name: org.mockito:mockito-android dependency-type: direct:production update-type: version-update:semver-major ... Signed-off-by: dependabot[bot] Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> --- testutils/build.gradle | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/testutils/build.gradle b/testutils/build.gradle index 055a56df0..d114a9376 100644 --- a/testutils/build.gradle +++ b/testutils/build.gradle @@ -50,7 +50,7 @@ dependencies { implementation fileTree(dir: 'libs', include: ['*.jar']) compileOnly project(':android-core') compileOnly project(':android-kit-base') - compileOnly 'org.mockito:mockito-android:4.9.0' + compileOnly 'org.mockito:mockito-android:5.2.0' api 'androidx.annotation:annotation:1.6.0' api 'androidx.test.ext:junit:1.1.5' From 17fff60b0801f4a54a9053becef3bb2af36e40bd Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Fri, 7 Apr 2023 14:07:34 +0000 Subject: [PATCH 6/6] chore: bump runner from 1.4.0 to 1.5.2 Bumps runner from 1.4.0 to 1.5.2. --- updated-dependencies: - dependency-name: androidx.test:runner dependency-type: direct:production update-type: version-update:semver-minor ... Signed-off-by: dependabot[bot] --- android-core/build.gradle | 2 +- testutils/build.gradle | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/android-core/build.gradle b/android-core/build.gradle index 92ed9d593..be2479681 100644 --- a/android-core/build.gradle +++ b/android-core/build.gradle @@ -156,7 +156,7 @@ dependencies { androidTestImplementation project(':testutils') if (useOrchestrator()) { - androidTestImplementation 'androidx.test:runner:1.4.0' + androidTestImplementation 'androidx.test:runner:1.5.2' androidTestUtil 'androidx.test:orchestrator:1.4.2' } androidTestImplementation "org.jetbrains.kotlin:kotlin-stdlib:$kotlin_version" diff --git a/testutils/build.gradle b/testutils/build.gradle index d114a9376..486055d67 100644 --- a/testutils/build.gradle +++ b/testutils/build.gradle @@ -64,7 +64,7 @@ dependencies { androidTestImplementation project(':android-core') } - androidTestImplementation 'androidx.test:runner:1.3.0' + androidTestImplementation 'androidx.test:runner:1.5.2' androidTestImplementation 'androidx.test.ext:junit:1.1.5' androidTestImplementation 'androidx.test:rules:1.5.0' androidTestImplementation 'com.google.firebase:firebase-messaging:20.0.0'