Analytic Toggle Fixes

This commit is contained in:
shabinder 2021-09-03 12:56:42 +05:30
parent ab2fea910a
commit 9d445fe34b
6 changed files with 19 additions and 9 deletions

View File

@ -137,8 +137,9 @@ class MainActivity : ComponentActivity() {
AnalyticsDialog( AnalyticsDialog(
askForAnalyticsPermission, askForAnalyticsPermission,
enableAnalytics = { enableAnalytics = {
// preferenceManager.toggleAnalytics(true) preferenceManager.toggleAnalytics(true) {
analyticsManager.giveConsent() analyticsManager.giveConsent()
}
preferenceManager.firstLaunchDone() preferenceManager.firstLaunchDone()
}, },
dismissDialog = { dismissDialog = {

View File

@ -69,7 +69,9 @@ fun SpotiFlyerPreferenceContent(component: SpotiFlyerPreference) {
title = "Preferred Audio Quality", title = "Preferred Audio Quality",
value = model.preferredQuality.kbps + "KBPS" value = model.preferredQuality.kbps + "KBPS"
) { save -> ) { save ->
val audioQualities = AudioQuality.values() val audioQualities = AudioQuality.values().toMutableList().apply {
remove(AudioQuality.UNKNOWN)
}
audioQualities.forEach { quality -> audioQualities.forEach { quality ->
Row( Row(

View File

@ -17,7 +17,10 @@ class PreferenceManager(
/* ANALYTICS */ /* ANALYTICS */
val isAnalyticsEnabled get() = getBooleanOrNull(ANALYTICS_KEY) ?: false 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 */ /* DOWNLOAD DIRECTORY */
val downloadDir get() = getStringOrNull(DIR_KEY) val downloadDir get() = getStringOrNull(DIR_KEY)

View File

@ -38,7 +38,7 @@ internal class SpotiFlyerMainImpl(
init { init {
instanceKeeper.ensureNeverFrozen() instanceKeeper.ensureNeverFrozen()
lifecycle.doOnResume { lifecycle.doOnResume {
store.accept(Intent.ToggleAnalytics(analyticsManager.isTracking())) store.accept(Intent.ToggleAnalytics(preferenceManager.isAnalyticsEnabled))
} }
} }

View File

@ -67,7 +67,7 @@ internal class SpotiFlyerMainStoreProvider(dependencies: SpotiFlyerMain.Dependen
private inner class ExecutorImpl : SuspendExecutor<Intent, Unit, State, Result, Nothing>() { private inner class ExecutorImpl : SuspendExecutor<Intent, Unit, State, Result, Nothing>() {
override suspend fun executeAction(action: Unit, getState: () -> State) { override suspend fun executeAction(action: Unit, getState: () -> State) {
dispatch(Result.AnalyticsToggled(analyticsManager.isTracking())) dispatch(Result.AnalyticsToggled(preferenceManager.isAnalyticsEnabled))
updates?.collect { updates?.collect {
dispatch(Result.ItemsLoaded(it)) dispatch(Result.ItemsLoaded(it))
} }
@ -82,7 +82,9 @@ internal class SpotiFlyerMainStoreProvider(dependencies: SpotiFlyerMain.Dependen
is Intent.SelectCategory -> dispatch(Result.CategoryChanged(intent.category)) is Intent.SelectCategory -> dispatch(Result.CategoryChanged(intent.category))
is Intent.ToggleAnalytics -> { is Intent.ToggleAnalytics -> {
dispatch(Result.AnalyticsToggled(intent.enabled)) dispatch(Result.AnalyticsToggled(intent.enabled))
analyticsManager.giveConsent() preferenceManager.toggleAnalytics(intent.enabled) {
if (intent.enabled) analyticsManager.giveConsent() else analyticsManager.revokeConsent()
}
} }
} }
} }

View File

@ -49,7 +49,7 @@ internal class SpotiFlyerPreferenceStoreProvider(
private inner class ExecutorImpl : SuspendExecutor<Intent, Unit, State, Result, Nothing>() { private inner class ExecutorImpl : SuspendExecutor<Intent, Unit, State, Result, Nothing>() {
override suspend fun executeAction(action: Unit, getState: () -> State) { 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.PreferredAudioQualityChanged(preferenceManager.audioQuality))
dispatch(Result.DownloadPathSet(fileManager.defaultDir())) dispatch(Result.DownloadPathSet(fileManager.defaultDir()))
} }
@ -61,7 +61,9 @@ internal class SpotiFlyerPreferenceStoreProvider(
is Intent.ShareApp -> methods.value.shareApp() is Intent.ShareApp -> methods.value.shareApp()
is Intent.ToggleAnalytics -> { is Intent.ToggleAnalytics -> {
dispatch(Result.AnalyticsToggled(intent.enabled)) dispatch(Result.AnalyticsToggled(intent.enabled))
preferenceManager.toggleAnalytics(intent.enabled) preferenceManager.toggleAnalytics(intent.enabled) {
if (intent.enabled) analyticsManager.giveConsent() else analyticsManager.revokeConsent()
}
} }
is Intent.SetDownloadDirectory -> { is Intent.SetDownloadDirectory -> {
dispatch(Result.DownloadPathSet(intent.path)) dispatch(Result.DownloadPathSet(intent.path))