Skip to content

Commit

Permalink
refactor: simplify ParselyTracker methods post Kotlin migration
Browse files Browse the repository at this point in the history
  • Loading branch information
wzieba committed Dec 14, 2023
1 parent 4a9c0bd commit 42325ed
Showing 1 changed file with 7 additions and 22 deletions.
29 changes: 7 additions & 22 deletions parsely/src/main/java/com/parsely/parselyandroid/ParselyTracker.kt
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ public open class ParselyTracker protected constructor(siteId: String, flushInte
isDebug = false
flushManager.start()
ProcessLifecycleOwner.get().lifecycle.addObserver(
LifecycleEventObserver { _: LifecycleOwner?, event: Lifecycle.Event ->
LifecycleEventObserver { _, event: Lifecycle.Event ->
if (event == Lifecycle.Event.ON_STOP) {
flushEvents()
}
Expand All @@ -104,7 +104,7 @@ public open class ParselyTracker protected constructor(siteId: String, flushInte
* @return Whether the engagement tracker is running.
*/
public fun engagementIsActive(): Boolean {
return engagementManager != null && engagementManager!!.isRunning
return engagementManager?.isRunning ?: false
}

/**
Expand All @@ -113,7 +113,7 @@ public open class ParselyTracker protected constructor(siteId: String, flushInte
* @return Whether video tracking is active.
*/
public fun videoIsActive(): Boolean {
return videoEngagementManager != null && videoEngagementManager!!.isRunning
return videoEngagementManager?.isRunning ?: false
}

/**
Expand Down Expand Up @@ -216,8 +216,7 @@ public open class ParselyTracker protected constructor(siteId: String, flushInte
intervalCalculator,
sdkScope,
clock
)
engagementManager!!.start()
).also { it.start() }
}

/**
Expand All @@ -230,10 +229,7 @@ public open class ParselyTracker protected constructor(siteId: String, flushInte
* and Parse.ly values may be inaccurate.
*/
public fun stopEngagement() {
if (engagementManager == null) {
return
}
engagementManager!!.stop()
engagementManager?.stop()
engagementManager = null
}

Expand Down Expand Up @@ -318,10 +314,7 @@ public open class ParselyTracker protected constructor(siteId: String, flushInte
* and Parse.ly values may be inaccurate.
*/
public fun trackPause() {
if (videoEngagementManager == null) {
return
}
videoEngagementManager!!.stop()
videoEngagementManager?.stop()
}

/**
Expand All @@ -338,21 +331,13 @@ public open class ParselyTracker protected constructor(siteId: String, flushInte
* and Parse.ly values may be inaccurate.
*/
public fun resetVideo() {
if (videoEngagementManager == null) {
return
}
videoEngagementManager!!.stop()
videoEngagementManager?.stop()
videoEngagementManager = null
}

/**
* Add an event Map to the queue.
*
*
* Place a data structure representing the event into the in-memory queue for later use.
*
*
*
* @param event The event Map to enqueue.
*/
internal open fun enqueueEvent(event: Map<String, Any>) {
Expand Down

0 comments on commit 42325ed

Please sign in to comment.