Skip to content

Commit

Permalink
559 ghost start issue (#564)
Browse files Browse the repository at this point in the history
  • Loading branch information
StaehliJ authored Jun 5, 2024
1 parent 33a7a1d commit cdd115e
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 4 deletions.
2 changes: 1 addition & 1 deletion config/detekt/detekt.yml
Original file line number Diff line number Diff line change
Expand Up @@ -208,7 +208,7 @@ empty-blocks:
active: true
EmptyFunctionBlock:
active: true
ignoreOverridden: false
ignoreOverridden: true
EmptyIfBlock:
active: true
EmptyInitBlock:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,9 @@
package ch.srgssr.pillarbox.analytics.comscore

import android.app.Activity
import android.app.Application
import android.content.Context
import android.os.Bundle
import android.util.Log
import ch.srgssr.pillarbox.analytics.AnalyticsConfig
import ch.srgssr.pillarbox.analytics.BuildConfig
Expand All @@ -22,7 +24,7 @@ import java.util.concurrent.atomic.AtomicBoolean
*
* SRGSSR doc : https://confluence.srg.beecollaboration.com/pages/viewpage.action?pageId=13188965
*/
internal object ComScoreSrg : ComScore {
internal object ComScoreSrg : ComScore, Application.ActivityLifecycleCallbacks {
private var config: AnalyticsConfig? = null
private const val publisherId = "6036016"
private val started = AtomicBoolean(false)
Expand Down Expand Up @@ -71,14 +73,14 @@ internal object ComScoreSrg : ComScore {
if (BuildConfig.DEBUG) {
Analytics.getConfiguration().enableImplementationValidationMode()
}
start(applicationContext)
(applicationContext as Application).registerActivityLifecycleCallbacks(this)
return this
}

internal fun start(appContext: Context) {
if (!started.getAndSet(true)) {
checkInitialized()
Log.i("COMSCORE", "Start")
Log.i("COMSCORE", "Start Comscore for SRG")
Analytics.start(appContext)
}
}
Expand Down Expand Up @@ -125,4 +127,22 @@ internal object ComScoreSrg : ComScore {
private fun checkInitialized() {
requireNotNull(config) { "ComScore init has to be called before start." }
}

override fun onActivityPreCreated(activity: Activity, savedInstanceState: Bundle?) {
start(activity.applicationContext)
}

override fun onActivityCreated(activity: Activity, savedInstanceState: Bundle?) {}

override fun onActivityStarted(activity: Activity) {}

override fun onActivityResumed(activity: Activity) {}

override fun onActivityPaused(activity: Activity) {}

override fun onActivityStopped(activity: Activity) {}

override fun onActivitySaveInstanceState(activity: Activity, outState: Bundle) {}

override fun onActivityDestroyed(activity: Activity) {}
}
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ class ComScoreSrgTest {

mockkStatic(Analytics::class)
ComScoreSrg.init(config = config, context = context)
ComScoreSrg.start(context)
}

@AfterTest
Expand Down

0 comments on commit cdd115e

Please sign in to comment.