From 1342b26c15eab30f269cb4afeacd6f94dbc044a4 Mon Sep 17 00:00:00 2001 From: Qingzhuo Zhen Date: Tue, 31 May 2022 18:25:46 -0700 Subject: [PATCH 1/4] feat: add configuration java support --- .../com/amplitude/android/Configuration.kt | 32 +++++++++---------- .../com/amplitude/android/events/Export.kt | 2 +- .../java/com/amplitude/core/Configuration.kt | 30 ++++++++--------- .../android/sample/MainApplication.java | 12 +++++-- 4 files changed, 42 insertions(+), 34 deletions(-) diff --git a/android/src/main/java/com/amplitude/android/Configuration.kt b/android/src/main/java/com/amplitude/android/Configuration.kt index db085750..cd0b8c08 100644 --- a/android/src/main/java/com/amplitude/android/Configuration.kt +++ b/android/src/main/java/com/amplitude/android/Configuration.kt @@ -1,7 +1,7 @@ package com.amplitude.android import android.content.Context -import com.amplitude.android.events.Plan +import com.amplitude.core.events.Plan import com.amplitude.android.utilities.AndroidLoggerProvider import com.amplitude.android.utilities.AndroidStorageProvider import com.amplitude.core.Configuration @@ -11,22 +11,22 @@ import com.amplitude.core.ServerZone import com.amplitude.core.StorageProvider class Configuration @JvmOverloads constructor( - apiKey: String, + override val apiKey: String, val context: Context, - flushQueueSize: Int = FLUSH_QUEUE_SIZE, - flushIntervalMillis: Int = FLUSH_INTERVAL_MILLIS, - instanceName: String = DEFAULT_INSTANCE, - optOut: Boolean = false, - storageProvider: StorageProvider = AndroidStorageProvider(), - loggerProvider: LoggerProvider = AndroidLoggerProvider(), - minIdLength: Int? = null, - partnerId: String? = null, - callback: EventCallBack? = null, - flushMaxRetries: Int = FLUSH_MAX_RETRIES, - useBatch: Boolean = false, - serverZone: ServerZone = ServerZone.US, - serverUrl: String? = null, - plan: Plan? = null, + override var flushQueueSize: Int = FLUSH_QUEUE_SIZE, + override var flushIntervalMillis: Int = FLUSH_INTERVAL_MILLIS, + override var instanceName: String = DEFAULT_INSTANCE, + override var optOut: Boolean = false, + override var storageProvider: StorageProvider = AndroidStorageProvider(), + override var loggerProvider: LoggerProvider = AndroidLoggerProvider(), + override var minIdLength: Int? = null, + override var partnerId: String? = null, + override var callback: EventCallBack? = null, + override var flushMaxRetries: Int = FLUSH_MAX_RETRIES, + override var useBatch: Boolean = false, + override var serverZone: ServerZone = ServerZone.US, + override var serverUrl: String? = null, + override var plan: Plan? = null, val useAdvertisingIdForDeviceId: Boolean = false, val useAppSetIdForDeviceId: Boolean = false, val newDeviceIdPerInstall: Boolean = false, diff --git a/android/src/main/java/com/amplitude/android/events/Export.kt b/android/src/main/java/com/amplitude/android/events/Export.kt index 6d6d34e0..8e953592 100644 --- a/android/src/main/java/com/amplitude/android/events/Export.kt +++ b/android/src/main/java/com/amplitude/android/events/Export.kt @@ -16,7 +16,7 @@ open class EventOptions : EventOptions() open class Identify : Identify() open class Revenue : Revenue() open class RevenueEvent : RevenueEvent() -open class Plan( +open class Plan @JvmOverloads constructor( branch: String? = null, source: String? = null, version: String? = null, diff --git a/core/src/main/java/com/amplitude/core/Configuration.kt b/core/src/main/java/com/amplitude/core/Configuration.kt index 4356ad7a..8278a403 100644 --- a/core/src/main/java/com/amplitude/core/Configuration.kt +++ b/core/src/main/java/com/amplitude/core/Configuration.kt @@ -8,21 +8,21 @@ import com.amplitude.core.utilities.InMemoryStorageProvider typealias EventCallBack = (BaseEvent, status: Int, message: String) -> Unit open class Configuration @JvmOverloads constructor( - val apiKey: String, - var flushQueueSize: Int = FLUSH_QUEUE_SIZE, - var flushIntervalMillis: Int = FLUSH_INTERVAL_MILLIS, - var instanceName: String = DEFAULT_INSTANCE, - var optOut: Boolean = false, - val storageProvider: StorageProvider = InMemoryStorageProvider(), - val loggerProvider: LoggerProvider = ConsoleLoggerProvider(), - var minIdLength: Int? = null, - var partnerId: String? = null, - val callback: EventCallBack? = null, - val flushMaxRetries: Int = FLUSH_MAX_RETRIES, - var useBatch: Boolean = false, - var serverZone: ServerZone = ServerZone.US, - var serverUrl: String? = null, - val plan: Plan? = null + open val apiKey: String, + open var flushQueueSize: Int = FLUSH_QUEUE_SIZE, + open var flushIntervalMillis: Int = FLUSH_INTERVAL_MILLIS, + open var instanceName: String = DEFAULT_INSTANCE, + open var optOut: Boolean = false, + open var storageProvider: StorageProvider = InMemoryStorageProvider(), + open var loggerProvider: LoggerProvider = ConsoleLoggerProvider(), + open var minIdLength: Int? = null, + open var partnerId: String? = null, + open var callback: EventCallBack? = null, + open var flushMaxRetries: Int = FLUSH_MAX_RETRIES, + open var useBatch: Boolean = false, + open var serverZone: ServerZone = ServerZone.US, + open var serverUrl: String? = null, + open var plan: Plan? = null ) { companion object { diff --git a/samples/java-android-app/src/main/java/com/amplitude/android/sample/MainApplication.java b/samples/java-android-app/src/main/java/com/amplitude/android/sample/MainApplication.java index 7aed5bdd..b42f0f5d 100644 --- a/samples/java-android-app/src/main/java/com/amplitude/android/sample/MainApplication.java +++ b/samples/java-android-app/src/main/java/com/amplitude/android/sample/MainApplication.java @@ -6,12 +6,15 @@ import androidx.annotation.Nullable; import com.amplitude.android.Amplitude; -import com.amplitude.android.Configuration; +import com.amplitude.android.AmplitudeKt; +import com.amplitude.android.events.Plan; import com.amplitude.core.events.BaseEvent; import com.amplitude.core.platform.Plugin; import java.util.HashMap; +import kotlin.Unit; + public class MainApplication extends Application { private static Amplitude amplitude; @@ -19,8 +22,13 @@ public class MainApplication extends Application { public void onCreate() { super.onCreate(); + Plan plan = new Plan("test branch", "test source", "test version", "test version id"); + // init instance - amplitude = new Amplitude(new Configuration(BuildConfig.AMPLITUDE_API_KEY, getApplicationContext())); + amplitude = AmplitudeKt.Amplitude(BuildConfig.AMPLITUDE_API_KEY, getApplicationContext(), configuration -> { + configuration.setPlan(plan); + return Unit.INSTANCE; + }); // add sample plugin amplitude.add(new SamplePlugin()); From be9382fa62b5681aeef5f2379df4268d07cb6e1e Mon Sep 17 00:00:00 2001 From: Qingzhuo Zhen Date: Tue, 31 May 2022 18:50:58 -0700 Subject: [PATCH 2/4] fix lint --- android/src/main/java/com/amplitude/android/Configuration.kt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/android/src/main/java/com/amplitude/android/Configuration.kt b/android/src/main/java/com/amplitude/android/Configuration.kt index cd0b8c08..219acdf3 100644 --- a/android/src/main/java/com/amplitude/android/Configuration.kt +++ b/android/src/main/java/com/amplitude/android/Configuration.kt @@ -1,7 +1,6 @@ package com.amplitude.android import android.content.Context -import com.amplitude.core.events.Plan import com.amplitude.android.utilities.AndroidLoggerProvider import com.amplitude.android.utilities.AndroidStorageProvider import com.amplitude.core.Configuration @@ -9,6 +8,7 @@ import com.amplitude.core.EventCallBack import com.amplitude.core.LoggerProvider import com.amplitude.core.ServerZone import com.amplitude.core.StorageProvider +import com.amplitude.core.events.Plan class Configuration @JvmOverloads constructor( override val apiKey: String, From 0ed6b55be734c70d13979fce01d8a1b906ac7c83 Mon Sep 17 00:00:00 2001 From: Qingzhuo Zhen Date: Tue, 31 May 2022 21:12:36 -0700 Subject: [PATCH 3/4] resolve comments --- android/src/main/java/com/amplitude/android/Configuration.kt | 4 ++-- core/src/main/java/com/amplitude/core/Configuration.kt | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/android/src/main/java/com/amplitude/android/Configuration.kt b/android/src/main/java/com/amplitude/android/Configuration.kt index 219acdf3..7cf3fecb 100644 --- a/android/src/main/java/com/amplitude/android/Configuration.kt +++ b/android/src/main/java/com/amplitude/android/Configuration.kt @@ -17,8 +17,8 @@ class Configuration @JvmOverloads constructor( override var flushIntervalMillis: Int = FLUSH_INTERVAL_MILLIS, override var instanceName: String = DEFAULT_INSTANCE, override var optOut: Boolean = false, - override var storageProvider: StorageProvider = AndroidStorageProvider(), - override var loggerProvider: LoggerProvider = AndroidLoggerProvider(), + override val storageProvider: StorageProvider = AndroidStorageProvider(), + override val loggerProvider: LoggerProvider = AndroidLoggerProvider(), override var minIdLength: Int? = null, override var partnerId: String? = null, override var callback: EventCallBack? = null, diff --git a/core/src/main/java/com/amplitude/core/Configuration.kt b/core/src/main/java/com/amplitude/core/Configuration.kt index 8278a403..14b55122 100644 --- a/core/src/main/java/com/amplitude/core/Configuration.kt +++ b/core/src/main/java/com/amplitude/core/Configuration.kt @@ -13,8 +13,8 @@ open class Configuration @JvmOverloads constructor( open var flushIntervalMillis: Int = FLUSH_INTERVAL_MILLIS, open var instanceName: String = DEFAULT_INSTANCE, open var optOut: Boolean = false, - open var storageProvider: StorageProvider = InMemoryStorageProvider(), - open var loggerProvider: LoggerProvider = ConsoleLoggerProvider(), + open val storageProvider: StorageProvider = InMemoryStorageProvider(), + open val loggerProvider: LoggerProvider = ConsoleLoggerProvider(), open var minIdLength: Int? = null, open var partnerId: String? = null, open var callback: EventCallBack? = null, From 239137ff598a5434b4eadb7ac40c327078e57b0e Mon Sep 17 00:00:00 2001 From: Qingzhuo Zhen Date: Tue, 31 May 2022 23:54:40 -0700 Subject: [PATCH 4/4] resolve comments --- android/src/main/java/com/amplitude/android/Configuration.kt | 4 ++-- core/src/main/java/com/amplitude/core/Configuration.kt | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/android/src/main/java/com/amplitude/android/Configuration.kt b/android/src/main/java/com/amplitude/android/Configuration.kt index 7cf3fecb..e4188e2b 100644 --- a/android/src/main/java/com/amplitude/android/Configuration.kt +++ b/android/src/main/java/com/amplitude/android/Configuration.kt @@ -11,7 +11,7 @@ import com.amplitude.core.StorageProvider import com.amplitude.core.events.Plan class Configuration @JvmOverloads constructor( - override val apiKey: String, + apiKey: String, val context: Context, override var flushQueueSize: Int = FLUSH_QUEUE_SIZE, override var flushIntervalMillis: Int = FLUSH_INTERVAL_MILLIS, @@ -38,6 +38,6 @@ class Configuration @JvmOverloads constructor( val trackingSessionEvents: Boolean = true ) : Configuration(apiKey, flushQueueSize, flushIntervalMillis, instanceName, optOut, storageProvider, loggerProvider, minIdLength, partnerId, callback, flushMaxRetries, useBatch, serverZone, serverUrl, plan) { companion object { - const val MIN_TIME_BETWEEN_SESSIONS_MILLIS: Long = 5 * 60 * 1000 + const val MIN_TIME_BETWEEN_SESSIONS_MILLIS: Long = 300000 } } diff --git a/core/src/main/java/com/amplitude/core/Configuration.kt b/core/src/main/java/com/amplitude/core/Configuration.kt index 14b55122..1761dea9 100644 --- a/core/src/main/java/com/amplitude/core/Configuration.kt +++ b/core/src/main/java/com/amplitude/core/Configuration.kt @@ -8,7 +8,7 @@ import com.amplitude.core.utilities.InMemoryStorageProvider typealias EventCallBack = (BaseEvent, status: Int, message: String) -> Unit open class Configuration @JvmOverloads constructor( - open val apiKey: String, + val apiKey: String, open var flushQueueSize: Int = FLUSH_QUEUE_SIZE, open var flushIntervalMillis: Int = FLUSH_INTERVAL_MILLIS, open var instanceName: String = DEFAULT_INSTANCE,