Skip to content

Commit

Permalink
Release 1.5.0
Browse files Browse the repository at this point in the history
  • Loading branch information
cristidregan committed May 17, 2023
1 parent 202d67e commit 0c0b089
Show file tree
Hide file tree
Showing 5 changed files with 34 additions and 10 deletions.
2 changes: 1 addition & 1 deletion OmetriaSDK/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
val versionName = "1.4.2"
val versionName = "1.5.0"

plugins {
id("com.android.library")
Expand Down
26 changes: 21 additions & 5 deletions OmetriaSDK/src/main/java/com/android/ometriasdk/core/Ometria.kt
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ class Ometria private constructor() : OmetriaNotificationInteractionHandler {
private lateinit var repository: Repository
private lateinit var notificationHandler: NotificationHandler
private lateinit var executor: OmetriaThreadPoolExecutor
private lateinit var activityLifecycleHelper: OmetriaActivityLifecycleHelper
lateinit var notificationInteractionHandler: OmetriaNotificationInteractionHandler

/**
Expand All @@ -75,6 +76,7 @@ class Ometria private constructor() : OmetriaNotificationInteractionHandler {
* @param apiToken The api key that has been attributed to your project.
* @param notificationIcon The icon that will be used when displaying push notifications.
* @param notificationColor The color that will be used when displaying push notifications.
* @param notificationChannelName The name param when creating NotificationChannel object.
*/
@JvmStatic
fun initialize(
Expand All @@ -84,6 +86,8 @@ class Ometria private constructor() : OmetriaNotificationInteractionHandler {
notificationColor: Int? = COLOR_DEFAULT,
notificationChannelName: String = OMETRIA_CHANNEL_NAME
) = instance.also {
clearOldInstanceIfNeeded()

it.ometriaConfig = OmetriaConfig(apiToken, application)
it.localCache = LocalCache(application)
it.executor = OmetriaThreadPoolExecutor()
Expand All @@ -101,19 +105,31 @@ class Ometria private constructor() : OmetriaNotificationInteractionHandler {
notificationChannelName = notificationChannelName,
executor = it.executor
)
it.isInitialized = true
it.notificationInteractionHandler = instance

if (it.shouldGenerateInstallationId()) {
it.generateInstallationId()
}

val activityLifecycleHelper = OmetriaActivityLifecycleHelper(it.repository, application)
if (it.isInitialized) {
it.activityLifecycleHelper.repository = it.repository
} else {
it.activityLifecycleHelper = OmetriaActivityLifecycleHelper(
repository = it.repository,
context = application
)
ProcessLifecycleOwner.get().lifecycle.addObserver(it.activityLifecycleHelper)
application.registerActivityLifecycleCallbacks(it.activityLifecycleHelper)
}

val lifecycle = ProcessLifecycleOwner.get().lifecycle
lifecycle.addObserver(activityLifecycleHelper)
it.isInitialized = true
}

application.registerActivityLifecycleCallbacks(activityLifecycleHelper)
private fun clearOldInstanceIfNeeded() {
if (instance.isInitialized) {
instance.flush()
instance.clear()
}
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import com.android.ometriasdk.core.Repository
import java.util.concurrent.atomic.AtomicBoolean

internal class OmetriaActivityLifecycleHelper(
private val repository: Repository,
var repository: Repository,
private val context: Context
) :
DefaultLifecycleObserver,
Expand Down
10 changes: 9 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ To install the library inside **Android Studio**, declare it as dependency in yo

```gradle
dependencies {
implementation 'com.ometria:android-sdk:1.4.2'
implementation 'com.ometria:android-sdk:1.5.0'
}
```

Expand Down Expand Up @@ -78,6 +78,14 @@ Ometria.initialize(
).loggingEnabled(true)
```

### Using multiple Ometria API tokens within the same app instance (Reinitializing the SDK)

There are cases where different flows of an application should log events under different tokens (think of different user roles, or other similar scenarios).
To address this, we offer the possibility of reinitializing the Ometria SDK. Although we currently do not keep references to multiple instances of the SDK,
we ensure that on reinitialization there will be a flush attempt for all the events that have been logged up to that point on the old instance.

Reinitializing the SDK requires the exact steps as a normal initialization.

5\. Event tracking guide
------------------------
You need to be aware of your users’ behaviour on your platforms in order to understand them. Some behaviour is automatically detectable, other events need work from the app developer to track.
Expand Down
4 changes: 2 additions & 2 deletions app/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@ android {
applicationId = "com.android.sample"
minSdk = 21
targetSdk = 33
versionCode = 8
versionName = "1.0.5"
versionCode = 9
versionName = "1.0.6"
}
signingConfigs {
getByName("debug") {
Expand Down

0 comments on commit 0c0b089

Please sign in to comment.