Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add configuration java support #35

Merged
merged 4 commits into from
Jun 1, 2022
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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,
override val apiKey: String,
qingzhuozhen marked this conversation as resolved.
Show resolved Hide resolved
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 Down
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
30 changes: 15 additions & 15 deletions core/src/main/java/com/amplitude/core/Configuration.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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(),
qingzhuozhen marked this conversation as resolved.
Show resolved Hide resolved
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 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