Skip to content

Commit

Permalink
feat: add configuration java support (#35)
Browse files Browse the repository at this point in the history
  • Loading branch information
qingzhuozhen authored Jun 1, 2022
1 parent 8dd1ab6 commit a4e0801
Show file tree
Hide file tree
Showing 4 changed files with 41 additions and 33 deletions.
32 changes: 16 additions & 16 deletions android/src/main/java/com/amplitude/android/Configuration.kt
Original file line number Diff line number Diff line change
@@ -1,32 +1,32 @@
package com.amplitude.android

import android.content.Context
import com.amplitude.android.events.Plan
import com.amplitude.android.utilities.AndroidLoggerProvider
import com.amplitude.android.utilities.AndroidStorageProvider
import com.amplitude.core.Configuration
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(
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 val storageProvider: StorageProvider = AndroidStorageProvider(),
override val 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,
Expand All @@ -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
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
28 changes: 14 additions & 14 deletions core/src/main/java/com/amplitude/core/Configuration.kt
Original file line number Diff line number Diff line change
Expand Up @@ -9,20 +9,20 @@ 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 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 val storageProvider: StorageProvider = InMemoryStorageProvider(),
open val 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 {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,21 +6,29 @@
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;

@Override
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());
Expand Down

0 comments on commit a4e0801

Please sign in to comment.