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(
askForAnalyticsPermission,
enableAnalytics = {
// preferenceManager.toggleAnalytics(true)
preferenceManager.toggleAnalytics(true) {
analyticsManager.giveConsent()
}
preferenceManager.firstLaunchDone()
},
dismissDialog = {

View File

@ -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(

View File

@ -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)

View File

@ -38,7 +38,7 @@ internal class SpotiFlyerMainImpl(
init {
instanceKeeper.ensureNeverFrozen()
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>() {
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()
}
}
}
}

View File

@ -49,7 +49,7 @@ internal class SpotiFlyerPreferenceStoreProvider(
private inner class ExecutorImpl : SuspendExecutor<Intent, Unit, State, Result, Nothing>() {
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))