diff --git a/android/src/main/java/com/shabinder/spotiflyer/MainActivity.kt b/android/src/main/java/com/shabinder/spotiflyer/MainActivity.kt index a40a4858..015624fe 100644 --- a/android/src/main/java/com/shabinder/spotiflyer/MainActivity.kt +++ b/android/src/main/java/com/shabinder/spotiflyer/MainActivity.kt @@ -60,7 +60,6 @@ import com.shabinder.common.di.preference.PreferenceManager import com.shabinder.common.models.* import com.shabinder.common.models.PlatformActions.Companion.SharedPreferencesKey import com.shabinder.common.root.SpotiFlyerRoot -import com.shabinder.common.root.SpotiFlyerRoot.Analytics import com.shabinder.common.root.callbacks.SpotiFlyerRootCallBacks import com.shabinder.common.translations.Strings import com.shabinder.common.uikit.configurations.SpotiFlyerTheme @@ -78,7 +77,6 @@ import kotlinx.coroutines.flow.emitAll import kotlinx.coroutines.launch import org.koin.android.ext.android.inject import org.koin.core.parameter.parametersOf -import org.matomo.sdk.extra.TrackHelper import java.io.File @ExperimentalAnimationApi @@ -94,7 +92,7 @@ class MainActivity : ComponentActivity() { private var permissionGranted = mutableStateOf(true) private val internetAvailability by lazy { ConnectionLiveData(applicationContext) } - private val visibleChild get(): SpotiFlyerRoot.Child = root.routerState.value.activeChild.instance + // private val visibleChild get(): SpotiFlyerRoot.Child = root.routerState.value.activeChild.instance // Variable for storing instance of our service class var foregroundService: ForegroundService? = null @@ -139,7 +137,8 @@ class MainActivity : ComponentActivity() { AnalyticsDialog( askForAnalyticsPermission, enableAnalytics = { - preferenceManager.toggleAnalytics(true) + // preferenceManager.toggleAnalytics(true) + analyticsManager.giveConsent() preferenceManager.firstLaunchDone() }, dismissDialog = { @@ -257,6 +256,7 @@ class MainActivity : ComponentActivity() { override val fetchQuery = this@MainActivity.fetcher override val dir: Dir = this@MainActivity.dir override val preferenceManager = this@MainActivity.preferenceManager + override val analyticsManager: AnalyticsManager = this@MainActivity.analyticsManager override val downloadProgressFlow: MutableSharedFlow> = trackStatusFlow override val actions = object : Actions { @@ -329,32 +329,12 @@ class MainActivity : ComponentActivity() { } } - override fun writeMp3Tags(trackDetails: TrackDetails) { /*IMPLEMENTED*/ + override fun writeMp3Tags(trackDetails: TrackDetails) { + /*IMPLEMENTED*/ } override val isInternetAvailable get() = internetAvailability.value ?: true } - - /* - * Analytics Will Only Be Sent if User Granted us the Permission - * */ - override val analytics = object : Analytics { - override fun appLaunchEvent() { - analyticsManager.sendEvent("app_launch") - } - - override fun homeScreenVisit() { - analyticsManager.sendView("home_screen") - } - - override fun listScreenVisit() { - analyticsManager.sendView("list_screen") - } - - override fun donationDialogVisit() { - analyticsManager.sendEvent("open_donation_dialog") - } - } } ) diff --git a/common/dependency-injection/src/commonMain/kotlin/com/shabinder/common/di/analytics/AnalyticsManager.kt b/common/dependency-injection/src/commonMain/kotlin/com/shabinder/common/di/analytics/AnalyticsManager.kt index 82e4fcad..316960aa 100644 --- a/common/dependency-injection/src/commonMain/kotlin/com/shabinder/common/di/analytics/AnalyticsManager.kt +++ b/common/dependency-injection/src/commonMain/kotlin/com/shabinder/common/di/analytics/AnalyticsManager.kt @@ -11,7 +11,14 @@ interface AnalyticsManager { fun revokeConsent() fun sendView(name: String, extras: Map = emptyMap()) fun sendEvent(eventName: String, extras: Map = emptyMap()) + fun track(event: AnalyticsAction) = event.track(this) fun sendCrashReport(error: Throwable, extras: Map = emptyMap()) + + companion object { + abstract class AnalyticsAction { + abstract fun track(analyticsManager: AnalyticsManager) + } + } } @Suppress("ClassName", "SpellCheckingInspection") diff --git a/common/dependency-injection/src/commonMain/kotlin/com/shabinder/common/di/analytics/Events.kt b/common/dependency-injection/src/commonMain/kotlin/com/shabinder/common/di/analytics/Events.kt new file mode 100644 index 00000000..a33a00ab --- /dev/null +++ b/common/dependency-injection/src/commonMain/kotlin/com/shabinder/common/di/analytics/Events.kt @@ -0,0 +1,9 @@ +package com.shabinder.common.di.analytics + +sealed class AnalyticsEvent(private val eventName: String, private val extras: Map = emptyMap()): AnalyticsManager.Companion.AnalyticsAction() { + + override fun track(analyticsManager: AnalyticsManager) = analyticsManager.sendEvent(eventName,extras) + + object AppLaunch: AnalyticsEvent("app_launch") + object DonationDialogOpen: AnalyticsEvent("donation_dialog_open") +} \ No newline at end of file diff --git a/common/dependency-injection/src/commonMain/kotlin/com/shabinder/common/di/analytics/Views.kt b/common/dependency-injection/src/commonMain/kotlin/com/shabinder/common/di/analytics/Views.kt new file mode 100644 index 00000000..07fa45c5 --- /dev/null +++ b/common/dependency-injection/src/commonMain/kotlin/com/shabinder/common/di/analytics/Views.kt @@ -0,0 +1,10 @@ +package com.shabinder.common.di.analytics + +import com.shabinder.common.di.analytics.AnalyticsManager.Companion.AnalyticsAction + +sealed class AnalyticsView(private val viewName: String, private val extras: Map = emptyMap()) : AnalyticsAction() { + override fun track(analyticsManager: AnalyticsManager) = analyticsManager.sendView(viewName,extras) + + object HomeScreen: AnalyticsView("home_screen") + object ListScreen: AnalyticsView("list_screen") +} \ No newline at end of file diff --git a/common/dependency-injection/src/commonMain/kotlin/com/shabinder/common/di/preference/PreferenceManager.kt b/common/dependency-injection/src/commonMain/kotlin/com/shabinder/common/di/preference/PreferenceManager.kt index 12ea6891..fa91c3cc 100644 --- a/common/dependency-injection/src/commonMain/kotlin/com/shabinder/common/di/preference/PreferenceManager.kt +++ b/common/dependency-injection/src/commonMain/kotlin/com/shabinder/common/di/preference/PreferenceManager.kt @@ -3,7 +3,9 @@ package com.shabinder.common.di.preference import com.russhwolf.settings.Settings import com.shabinder.common.models.AudioQuality -class PreferenceManager(settings: Settings) : Settings by settings { +class PreferenceManager( + settings: Settings +) : Settings by settings { companion object { const val DIR_KEY = "downloadDir" @@ -14,8 +16,8 @@ class PreferenceManager(settings: Settings) : Settings by settings { } /* ANALYTICS */ - // val isAnalyticsEnabled get() = getBooleanOrNull(ANALYTICS_KEY) ?: false - // fun toggleAnalytics(enabled: Boolean) = putBoolean(ANALYTICS_KEY, enabled) + val isAnalyticsEnabled get() = getBooleanOrNull(ANALYTICS_KEY) ?: false + fun toggleAnalytics(enabled: Boolean) = putBoolean(ANALYTICS_KEY, enabled) /* DOWNLOAD DIRECTORY */ val downloadDir get() = getStringOrNull(DIR_KEY) diff --git a/common/list/src/commonMain/kotlin/com/shabinder/common/list/store/SpotiFlyerListStoreProvider.kt b/common/list/src/commonMain/kotlin/com/shabinder/common/list/store/SpotiFlyerListStoreProvider.kt index fa71554d..cd58e54a 100644 --- a/common/list/src/commonMain/kotlin/com/shabinder/common/list/store/SpotiFlyerListStoreProvider.kt +++ b/common/list/src/commonMain/kotlin/com/shabinder/common/list/store/SpotiFlyerListStoreProvider.kt @@ -25,6 +25,7 @@ import com.shabinder.common.di.Dir import com.shabinder.common.di.FetchPlatformQueryResult import com.shabinder.common.di.downloadTracks import com.shabinder.common.di.preference.PreferenceManager +import com.shabinder.common.list.SpotiFlyerList import com.shabinder.common.list.SpotiFlyerList.State import com.shabinder.common.list.store.SpotiFlyerListStore.Intent import com.shabinder.common.models.DownloadStatus @@ -34,14 +35,7 @@ import com.shabinder.common.models.methods import kotlinx.coroutines.flow.MutableSharedFlow import kotlinx.coroutines.flow.collect -internal class SpotiFlyerListStoreProvider( - private val dir: Dir, - private val preferenceManager: PreferenceManager, - private val storeFactory: StoreFactory, - private val fetchQuery: FetchPlatformQueryResult, - private val link: String, - private val downloadProgressFlow: MutableSharedFlow> -) { +internal class SpotiFlyerListStoreProvider(dependencies: SpotiFlyerList.Dependencies): SpotiFlyerList.Dependencies by dependencies { fun provide(): SpotiFlyerListStore = object : SpotiFlyerListStore, diff --git a/common/main/src/commonMain/kotlin/com/shabinder/common/main/SpotiFlyerMain.kt b/common/main/src/commonMain/kotlin/com/shabinder/common/main/SpotiFlyerMain.kt index d6aa3941..04694d43 100644 --- a/common/main/src/commonMain/kotlin/com/shabinder/common/main/SpotiFlyerMain.kt +++ b/common/main/src/commonMain/kotlin/com/shabinder/common/main/SpotiFlyerMain.kt @@ -21,6 +21,7 @@ import com.arkivanov.decompose.value.Value import com.arkivanov.mvikotlin.core.store.StoreFactory import com.shabinder.common.di.Dir import com.shabinder.common.di.Picture +import com.shabinder.common.di.analytics.AnalyticsManager import com.shabinder.common.di.preference.PreferenceManager import com.shabinder.common.main.integration.SpotiFlyerMainImpl import com.shabinder.common.models.Consumer @@ -67,6 +68,7 @@ interface SpotiFlyerMain { val database: Database? val dir: Dir val preferenceManager: PreferenceManager + val analyticsManager: AnalyticsManager val mainAnalytics: Analytics } diff --git a/common/main/src/commonMain/kotlin/com/shabinder/common/main/integration/SpotiFlyerMainImpl.kt b/common/main/src/commonMain/kotlin/com/shabinder/common/main/integration/SpotiFlyerMainImpl.kt index adc094d8..72627f63 100644 --- a/common/main/src/commonMain/kotlin/com/shabinder/common/main/integration/SpotiFlyerMainImpl.kt +++ b/common/main/src/commonMain/kotlin/com/shabinder/common/main/integration/SpotiFlyerMainImpl.kt @@ -41,13 +41,14 @@ internal class SpotiFlyerMainImpl( init { instanceKeeper.ensureNeverFrozen() lifecycle.doOnResume { - store.accept(Intent.ToggleAnalytics(preferenceManager.isAnalyticsEnabled)) + store.accept(Intent.ToggleAnalytics(analyticsManager.isTracking())) } } private val store = instanceKeeper.getStore { SpotiFlyerMainStoreProvider( + analyticsManager = analyticsManager, preferenceManager = preferenceManager, storeFactory = storeFactory, database = database, diff --git a/common/main/src/commonMain/kotlin/com/shabinder/common/main/store/SpotiFlyerMainStoreProvider.kt b/common/main/src/commonMain/kotlin/com/shabinder/common/main/store/SpotiFlyerMainStoreProvider.kt index 5cdfd129..0aa293a7 100644 --- a/common/main/src/commonMain/kotlin/com/shabinder/common/main/store/SpotiFlyerMainStoreProvider.kt +++ b/common/main/src/commonMain/kotlin/com/shabinder/common/main/store/SpotiFlyerMainStoreProvider.kt @@ -22,6 +22,7 @@ import com.arkivanov.mvikotlin.core.store.Store import com.arkivanov.mvikotlin.core.store.StoreFactory import com.arkivanov.mvikotlin.extensions.coroutines.SuspendExecutor import com.shabinder.common.di.Dir +import com.shabinder.common.di.analytics.AnalyticsManager import com.shabinder.common.di.preference.PreferenceManager import com.shabinder.common.main.SpotiFlyerMain import com.shabinder.common.main.SpotiFlyerMain.State @@ -36,12 +37,7 @@ import kotlinx.coroutines.flow.Flow import kotlinx.coroutines.flow.collect import kotlinx.coroutines.flow.map -internal class SpotiFlyerMainStoreProvider( - private val storeFactory: StoreFactory, - private val preferenceManager: PreferenceManager, - private val dir: Dir, - database: Database? -) { +internal class SpotiFlyerMainStoreProvider(dependencies: SpotiFlyerMain.Dependencies): SpotiFlyerMain.Dependencies by dependencies { fun provide(): SpotiFlyerMainStore = object : @@ -76,7 +72,7 @@ internal class SpotiFlyerMainStoreProvider( private inner class ExecutorImpl : SuspendExecutor() { override suspend fun executeAction(action: Unit, getState: () -> State) { - dispatch(Result.AnalyticsToggled(preferenceManager.isAnalyticsEnabled)) + dispatch(Result.AnalyticsToggled(analyticsManager.isTracking())) updates?.collect { dispatch(Result.ItemsLoaded(it)) } @@ -91,7 +87,7 @@ internal class SpotiFlyerMainStoreProvider( is Intent.SelectCategory -> dispatch(Result.CategoryChanged(intent.category)) is Intent.ToggleAnalytics -> { dispatch(Result.AnalyticsToggled(intent.enabled)) - preferenceManager.toggleAnalytics(intent.enabled) + analyticsManager.giveConsent() } } } diff --git a/common/preference/src/commonMain/kotlin/com/shabinder/common/preference/store/SpotiFlyerPreferenceStoreProvider.kt b/common/preference/src/commonMain/kotlin/com/shabinder/common/preference/store/SpotiFlyerPreferenceStoreProvider.kt index 73a90890..6831059b 100644 --- a/common/preference/src/commonMain/kotlin/com/shabinder/common/preference/store/SpotiFlyerPreferenceStoreProvider.kt +++ b/common/preference/src/commonMain/kotlin/com/shabinder/common/preference/store/SpotiFlyerPreferenceStoreProvider.kt @@ -22,6 +22,7 @@ import com.arkivanov.mvikotlin.core.store.Store import com.arkivanov.mvikotlin.core.store.StoreFactory import com.arkivanov.mvikotlin.extensions.coroutines.SuspendExecutor import com.shabinder.common.di.Dir +import com.shabinder.common.di.analytics.AnalyticsManager import com.shabinder.common.di.preference.PreferenceManager import com.shabinder.common.models.Actions import com.shabinder.common.models.AudioQuality @@ -31,6 +32,7 @@ import com.shabinder.common.preference.store.SpotiFlyerPreferenceStore.Intent internal class SpotiFlyerPreferenceStoreProvider( private val storeFactory: StoreFactory, + private val analyticsManager: AnalyticsManager, private val preferenceManager: PreferenceManager, private val dir: Dir, private val actions: Actions @@ -55,7 +57,7 @@ internal class SpotiFlyerPreferenceStoreProvider( private inner class ExecutorImpl : SuspendExecutor() { override suspend fun executeAction(action: Unit, getState: () -> State) { - dispatch(Result.AnalyticsToggled(preferenceManager.isAnalyticsEnabled)) + dispatch(Result.AnalyticsToggled(analyticsManager.isTracking())) dispatch(Result.PreferredAudioQualityChanged(preferenceManager.audioQuality)) dispatch(Result.DownloadPathSet(dir.defaultDir())) } diff --git a/common/root/src/commonMain/kotlin/com/shabinder/common/root/SpotiFlyerRoot.kt b/common/root/src/commonMain/kotlin/com/shabinder/common/root/SpotiFlyerRoot.kt index 1c8a8ff9..532ab2f0 100644 --- a/common/root/src/commonMain/kotlin/com/shabinder/common/root/SpotiFlyerRoot.kt +++ b/common/root/src/commonMain/kotlin/com/shabinder/common/root/SpotiFlyerRoot.kt @@ -22,6 +22,8 @@ import com.arkivanov.decompose.value.Value import com.arkivanov.mvikotlin.core.store.StoreFactory import com.shabinder.common.di.Dir import com.shabinder.common.di.FetchPlatformQueryResult +import com.shabinder.common.di.analytics.AnalyticsEvent +import com.shabinder.common.di.analytics.AnalyticsManager import com.shabinder.common.di.preference.PreferenceManager import com.shabinder.common.list.SpotiFlyerList import com.shabinder.common.main.SpotiFlyerMain @@ -55,16 +57,9 @@ interface SpotiFlyerRoot { val fetchQuery: FetchPlatformQueryResult val dir: Dir val preferenceManager: PreferenceManager + val analyticsManager: AnalyticsManager val downloadProgressFlow: MutableSharedFlow> val actions: Actions - val analytics: Analytics - } - - interface Analytics { - fun appLaunchEvent() - fun homeScreenVisit() - fun listScreenVisit() - fun donationDialogVisit() } } diff --git a/common/root/src/commonMain/kotlin/com/shabinder/common/root/integration/SpotiFlyerRootImpl.kt b/common/root/src/commonMain/kotlin/com/shabinder/common/root/integration/SpotiFlyerRootImpl.kt index 31da5016..0e240765 100644 --- a/common/root/src/commonMain/kotlin/com/shabinder/common/root/integration/SpotiFlyerRootImpl.kt +++ b/common/root/src/commonMain/kotlin/com/shabinder/common/root/integration/SpotiFlyerRootImpl.kt @@ -24,9 +24,11 @@ import com.arkivanov.decompose.pop import com.arkivanov.decompose.popWhile import com.arkivanov.decompose.push import com.arkivanov.decompose.router -import com.arkivanov.decompose.statekeeper.Parcelable -import com.arkivanov.decompose.statekeeper.Parcelize import com.arkivanov.decompose.value.Value +import com.arkivanov.essenty.parcelable.Parcelable +import com.arkivanov.essenty.parcelable.Parcelize +import com.shabinder.common.di.analytics.AnalyticsEvent +import com.shabinder.common.di.analytics.AnalyticsView import com.shabinder.common.di.dispatcherIO import com.shabinder.common.list.SpotiFlyerList import com.shabinder.common.main.SpotiFlyerMain @@ -35,7 +37,6 @@ import com.shabinder.common.models.Consumer import com.shabinder.common.models.methods import com.shabinder.common.preference.SpotiFlyerPreference import com.shabinder.common.root.SpotiFlyerRoot -import com.shabinder.common.root.SpotiFlyerRoot.Analytics import com.shabinder.common.root.SpotiFlyerRoot.Child import com.shabinder.common.root.SpotiFlyerRoot.Dependencies import com.shabinder.common.root.callbacks.SpotiFlyerRootCallBacks @@ -46,30 +47,10 @@ import kotlinx.coroutines.launch internal class SpotiFlyerRootImpl( componentContext: ComponentContext, - private val main: (ComponentContext, output: Consumer) -> SpotiFlyerMain, - private val list: (ComponentContext, link: String, output: Consumer) -> SpotiFlyerList, - private val preference: (ComponentContext, output: Consumer) -> SpotiFlyerPreference, - private val actions: Actions, - private val analytics: Analytics -) : SpotiFlyerRoot, ComponentContext by componentContext { + dependencies: Dependencies, +) : SpotiFlyerRoot, ComponentContext by componentContext, Dependencies by dependencies, Actions by dependencies.actions { - constructor( - componentContext: ComponentContext, - dependencies: Dependencies, - ) : this( - componentContext = componentContext, - main = { childContext, output -> - spotiFlyerMain(childContext, output, dependencies) - }, - list = { childContext, link, output -> - spotiFlyerList(childContext, link, output, dependencies) - }, - preference = { childContext, output -> - spotiFlyerPreference(childContext, output, dependencies) - }, - actions = dependencies.actions.freeze(), - analytics = dependencies.analytics - ) { + init { instanceKeeper.ensureNeverFrozen() methods.value = dependencies.actions.freeze() @@ -102,21 +83,85 @@ internal class SpotiFlyerRootImpl( router.push(Configuration.Preference) } - override fun showToast(text: String) { toastState.value = text } + override fun showToast(text: String) { + toastState.value = text + } } - private fun createChild(configuration: Configuration, componentContext: ComponentContext): Child = + private fun createChild( + configuration: Configuration, + componentContext: ComponentContext, + ): Child = when (configuration) { - is Configuration.Main -> Child.Main(main(componentContext, Consumer(::onMainOutput))) - is Configuration.List -> Child.List(list(componentContext, configuration.link, Consumer(::onListOutput))) - is Configuration.Preference -> Child.Preference(preference(componentContext, Consumer(::onPreferenceOutput)),) + is Configuration.Main -> Child.Main( + spotiFlyerMain( + componentContext, + Consumer(::onMainOutput), + ) + ) + is Configuration.List -> Child.List( + spotiFlyerList( + componentContext, + configuration.link, + Consumer(::onListOutput), + ) + ) + is Configuration.Preference -> Child.Preference( + spotiFlyerPreference( + componentContext, + Consumer(::onPreferenceOutput), + ) + ) } + + private fun spotiFlyerMain( + componentContext: ComponentContext, + output: Consumer, + ): SpotiFlyerMain = + SpotiFlyerMain( + componentContext = componentContext, + dependencies = object : SpotiFlyerMain.Dependencies, Dependencies by this { + override val mainOutput: Consumer = output + override val mainAnalytics = object : SpotiFlyerMain.Analytics { + override fun donationDialogVisit() { + AnalyticsEvent.DonationDialogOpen.track(analyticsManager) + } + } + } + ) + + private fun spotiFlyerList( + componentContext: ComponentContext, + link: String, + output: Consumer + ): SpotiFlyerList = + SpotiFlyerList( + componentContext = componentContext, + dependencies = object : SpotiFlyerList.Dependencies, Dependencies by this { + override val link: String = link + override val listOutput: Consumer = output + override val listAnalytics = object : SpotiFlyerList.Analytics {} + } + ) + + private fun spotiFlyerPreference( + componentContext: ComponentContext, + output: Consumer + ): SpotiFlyerPreference = + SpotiFlyerPreference( + componentContext = componentContext, + dependencies = object : SpotiFlyerPreference.Dependencies, Dependencies by this { + override val prefOutput: Consumer = output + override val preferenceAnalytics = object : SpotiFlyerPreference.Analytics {} + } + ) + private fun onMainOutput(output: SpotiFlyerMain.Output) = when (output) { is SpotiFlyerMain.Output.Search -> { router.push(Configuration.List(link = output.link)) - analytics.listScreenVisit() + AnalyticsView.ListScreen.track(analyticsManager) } } @@ -126,9 +171,10 @@ internal class SpotiFlyerRootImpl( if (router.state.value.activeChild.instance is Child.List && router.state.value.backStack.isNotEmpty()) { router.pop() } - analytics.homeScreenVisit() + AnalyticsView.HomeScreen.track(analyticsManager) } } + private fun onPreferenceOutput(output: SpotiFlyerPreference.Output): Unit = when (output) { is SpotiFlyerPreference.Output.Finished -> { @@ -142,7 +188,7 @@ internal class SpotiFlyerRootImpl( @OptIn(DelicateCoroutinesApi::class) private fun initAppLaunchAndAuthenticateSpotify(authenticator: suspend () -> Unit) { GlobalScope.launch(dispatcherIO) { - analytics.appLaunchEvent() + AnalyticsEvent.AppLaunch.track(analyticsManager) /*Authenticate Spotify Client*/ authenticator() } @@ -159,31 +205,3 @@ internal class SpotiFlyerRootImpl( data class List(val link: String) : Configuration() } } - -private fun spotiFlyerMain(componentContext: ComponentContext, output: Consumer, dependencies: Dependencies): SpotiFlyerMain = - SpotiFlyerMain( - componentContext = componentContext, - dependencies = object : SpotiFlyerMain.Dependencies, Dependencies by dependencies { - override val mainOutput: Consumer = output - override val mainAnalytics = object : SpotiFlyerMain.Analytics, Analytics by analytics {} - } - ) - -private fun spotiFlyerList(componentContext: ComponentContext, link: String, output: Consumer, dependencies: Dependencies): SpotiFlyerList = - SpotiFlyerList( - componentContext = componentContext, - dependencies = object : SpotiFlyerList.Dependencies, Dependencies by dependencies { - override val link: String = link - override val listOutput: Consumer = output - override val listAnalytics = object : SpotiFlyerList.Analytics, Analytics by analytics {} - } - ) - -private fun spotiFlyerPreference(componentContext: ComponentContext, output: Consumer, dependencies: Dependencies): SpotiFlyerPreference = - SpotiFlyerPreference( - componentContext = componentContext, - dependencies = object : SpotiFlyerPreference.Dependencies, Dependencies by dependencies { - override val prefOutput: Consumer = output - override val preferenceAnalytics = object : SpotiFlyerPreference.Analytics, Analytics by analytics {} - } - ) diff --git a/desktop/src/jvmMain/kotlin/Main.kt b/desktop/src/jvmMain/kotlin/Main.kt index 8de5be1c..fdb6c3ab 100644 --- a/desktop/src/jvmMain/kotlin/Main.kt +++ b/desktop/src/jvmMain/kotlin/Main.kt @@ -30,6 +30,7 @@ import com.arkivanov.mvikotlin.main.store.DefaultStoreFactory import com.shabinder.common.di.Dir import com.shabinder.common.di.DownloadProgressFlow import com.shabinder.common.di.FetchPlatformQueryResult +import com.shabinder.common.di.analytics.AnalyticsManager import com.shabinder.common.di.initKoin import com.shabinder.common.di.isInternetAccessible import com.shabinder.common.di.preference.PreferenceManager @@ -58,9 +59,6 @@ import javax.swing.JFileChooser.APPROVE_OPTION private val koin = initKoin(enableNetworkLogs = true).koin private lateinit var showToast: (String) -> Unit -private val tracker: PiwikTracker by lazy { - PiwikTracker("https://matomo.spotiflyer.ml/matomo.php") -} fun main() { @@ -96,6 +94,7 @@ private fun spotiFlyerRoot(componentContext: ComponentContext): SpotiFlyerRoot = override val dir: Dir = koin.get() override val database: Database? = dir.db override val preferenceManager: PreferenceManager = koin.get() + override val analyticsManager: AnalyticsManager = koin.get() override val downloadProgressFlow = DownloadProgressFlow override val actions: Actions = object : Actions { override val platformActions = object : PlatformActions {} @@ -159,14 +158,9 @@ private fun spotiFlyerRoot(componentContext: ComponentContext): SpotiFlyerRoot = override fun appLaunchEvent() { if (preferenceManager.isFirstLaunch) { // Enable Analytics on First Launch - preferenceManager.toggleAnalytics(true) + analyticsManager.giveConsent() preferenceManager.firstLaunchDone() } - tracker.trackAsync { - eventName = "App Launch" - eventAction = "App_Launch" - eventCategory = "events" - } } override fun homeScreenVisit() {