diff --git a/android/src/main/java/com/shabinder/spotiflyer/MainActivity.kt b/android/src/main/java/com/shabinder/spotiflyer/MainActivity.kt index 9c1c8052..c446dd93 100644 --- a/android/src/main/java/com/shabinder/spotiflyer/MainActivity.kt +++ b/android/src/main/java/com/shabinder/spotiflyer/MainActivity.kt @@ -137,8 +137,9 @@ class MainActivity : ComponentActivity() { AnalyticsDialog( askForAnalyticsPermission, enableAnalytics = { - // preferenceManager.toggleAnalytics(true) - analyticsManager.giveConsent() + preferenceManager.toggleAnalytics(true) { + analyticsManager.giveConsent() + } preferenceManager.firstLaunchDone() }, dismissDialog = { diff --git a/common/compose/src/commonMain/kotlin/com/shabinder/common/uikit/screens/SpotiFlyerPreferenceUi.kt b/common/compose/src/commonMain/kotlin/com/shabinder/common/uikit/screens/SpotiFlyerPreferenceUi.kt index 43422ac9..650d7864 100644 --- a/common/compose/src/commonMain/kotlin/com/shabinder/common/uikit/screens/SpotiFlyerPreferenceUi.kt +++ b/common/compose/src/commonMain/kotlin/com/shabinder/common/uikit/screens/SpotiFlyerPreferenceUi.kt @@ -69,7 +69,9 @@ fun SpotiFlyerPreferenceContent(component: SpotiFlyerPreference) { title = "Preferred Audio Quality", value = model.preferredQuality.kbps + "KBPS" ) { save -> - val audioQualities = AudioQuality.values() + val audioQualities = AudioQuality.values().toMutableList().apply { + remove(AudioQuality.UNKNOWN) + } audioQualities.forEach { quality -> Row( diff --git a/common/core-components/src/commonMain/kotlin/com.shabinder.common.core_components/preference_manager/PreferenceManager.kt b/common/core-components/src/commonMain/kotlin/com.shabinder.common.core_components/preference_manager/PreferenceManager.kt index 63cab014..3e355a4c 100644 --- a/common/core-components/src/commonMain/kotlin/com.shabinder.common.core_components/preference_manager/PreferenceManager.kt +++ b/common/core-components/src/commonMain/kotlin/com.shabinder.common.core_components/preference_manager/PreferenceManager.kt @@ -17,7 +17,10 @@ class PreferenceManager( /* ANALYTICS */ val isAnalyticsEnabled get() = getBooleanOrNull(ANALYTICS_KEY) ?: false - fun toggleAnalytics(enabled: Boolean) = putBoolean(ANALYTICS_KEY, enabled) + fun toggleAnalytics(enabled: Boolean,f: () -> Unit = {}) { + putBoolean(ANALYTICS_KEY, enabled) + f() + } /* DOWNLOAD DIRECTORY */ val downloadDir get() = getStringOrNull(DIR_KEY) 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 c879d009..aee4f01b 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 @@ -38,7 +38,7 @@ internal class SpotiFlyerMainImpl( init { instanceKeeper.ensureNeverFrozen() lifecycle.doOnResume { - store.accept(Intent.ToggleAnalytics(analyticsManager.isTracking())) + store.accept(Intent.ToggleAnalytics(preferenceManager.isAnalyticsEnabled)) } } 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 fc4bc398..77656809 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 @@ -67,7 +67,7 @@ internal class SpotiFlyerMainStoreProvider(dependencies: SpotiFlyerMain.Dependen private inner class ExecutorImpl : SuspendExecutor() { override suspend fun executeAction(action: Unit, getState: () -> State) { - dispatch(Result.AnalyticsToggled(analyticsManager.isTracking())) + dispatch(Result.AnalyticsToggled(preferenceManager.isAnalyticsEnabled)) updates?.collect { dispatch(Result.ItemsLoaded(it)) } @@ -82,7 +82,9 @@ internal class SpotiFlyerMainStoreProvider(dependencies: SpotiFlyerMain.Dependen is Intent.SelectCategory -> dispatch(Result.CategoryChanged(intent.category)) is Intent.ToggleAnalytics -> { dispatch(Result.AnalyticsToggled(intent.enabled)) - analyticsManager.giveConsent() + preferenceManager.toggleAnalytics(intent.enabled) { + if (intent.enabled) analyticsManager.giveConsent() else analyticsManager.revokeConsent() + } } } } 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 fcb8168c..84baf232 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 @@ -49,7 +49,7 @@ internal class SpotiFlyerPreferenceStoreProvider( private inner class ExecutorImpl : SuspendExecutor() { override suspend fun executeAction(action: Unit, getState: () -> State) { - dispatch(Result.AnalyticsToggled(analyticsManager.isTracking())) + dispatch(Result.AnalyticsToggled(preferenceManager.isAnalyticsEnabled)) dispatch(Result.PreferredAudioQualityChanged(preferenceManager.audioQuality)) dispatch(Result.DownloadPathSet(fileManager.defaultDir())) } @@ -61,7 +61,9 @@ internal class SpotiFlyerPreferenceStoreProvider( is Intent.ShareApp -> methods.value.shareApp() is Intent.ToggleAnalytics -> { dispatch(Result.AnalyticsToggled(intent.enabled)) - preferenceManager.toggleAnalytics(intent.enabled) + preferenceManager.toggleAnalytics(intent.enabled) { + if (intent.enabled) analyticsManager.giveConsent() else analyticsManager.revokeConsent() + } } is Intent.SetDownloadDirectory -> { dispatch(Result.DownloadPathSet(intent.path))