diff --git a/android-core/build.gradle b/android-core/build.gradle index e92819e43..be2479681 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') @@ -153,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/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); +} diff --git a/testutils/build.gradle b/testutils/build.gradle index 3e07b087c..486055d67 100644 --- a/testutils/build.gradle +++ b/testutils/build.gradle @@ -50,10 +50,10 @@ 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.5.0' - api 'androidx.test.ext:junit:1.1.4' + api 'androidx.annotation:annotation:1.6.0' + api 'androidx.test.ext:junit:1.1.5' api 'androidx.test:rules:1.5.0' androidTestCompileOnly project(':android-core') @@ -64,8 +64,8 @@ dependencies { androidTestImplementation project(':android-core') } - androidTestImplementation 'androidx.test:runner:1.3.0' - androidTestImplementation 'androidx.test.ext:junit:1.1.4' + 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' 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"