From e4752987fc05d0357cfcd886bc46eba1d9c97723 Mon Sep 17 00:00:00 2001 From: Kyle Corry Date: Sun, 12 Nov 2023 20:41:04 -0500 Subject: [PATCH] Add notice of settings move Closes #1935 --- .../kylecorry/trail_sense/main/AppState.kt | 5 ++++ .../trail_sense/main/MainActivity.kt | 2 ++ .../settings/migrations/PreferenceMigrator.kt | 3 ++ .../settings/ui/SettingsMoveNotice.kt | 29 +++++++++++++++++++ app/src/main/res/values/strings.xml | 2 ++ 5 files changed, 41 insertions(+) create mode 100644 app/src/main/java/com/kylecorry/trail_sense/main/AppState.kt create mode 100644 app/src/main/java/com/kylecorry/trail_sense/settings/ui/SettingsMoveNotice.kt diff --git a/app/src/main/java/com/kylecorry/trail_sense/main/AppState.kt b/app/src/main/java/com/kylecorry/trail_sense/main/AppState.kt new file mode 100644 index 000000000..8a246308e --- /dev/null +++ b/app/src/main/java/com/kylecorry/trail_sense/main/AppState.kt @@ -0,0 +1,5 @@ +package com.kylecorry.trail_sense.main + +object AppState { + var isReturningUser: Boolean = false +} \ No newline at end of file diff --git a/app/src/main/java/com/kylecorry/trail_sense/main/MainActivity.kt b/app/src/main/java/com/kylecorry/trail_sense/main/MainActivity.kt index b79fa0d7c..5ea968b11 100644 --- a/app/src/main/java/com/kylecorry/trail_sense/main/MainActivity.kt +++ b/app/src/main/java/com/kylecorry/trail_sense/main/MainActivity.kt @@ -28,6 +28,7 @@ import com.kylecorry.trail_sense.astronomy.domain.AstronomyService import com.kylecorry.trail_sense.backup.BackupService import com.kylecorry.trail_sense.onboarding.OnboardingActivity import com.kylecorry.trail_sense.receivers.RestartServicesCommand +import com.kylecorry.trail_sense.settings.ui.SettingsMoveNotice import com.kylecorry.trail_sense.shared.NavigationUtils.setupWithNavController import com.kylecorry.trail_sense.shared.UserPreferences import com.kylecorry.trail_sense.shared.commands.ComposedCommand @@ -142,6 +143,7 @@ class MainActivity : AndromedaActivity() { ShowDisclaimerCommand(this), PowerSavingModeAlertCommand(this), RestartServicesCommand(this), + SettingsMoveNotice(this) ).execute() if (!Sensors.hasBarometer(this)) { diff --git a/app/src/main/java/com/kylecorry/trail_sense/settings/migrations/PreferenceMigrator.kt b/app/src/main/java/com/kylecorry/trail_sense/settings/migrations/PreferenceMigrator.kt index 5d7a1604a..69819c990 100644 --- a/app/src/main/java/com/kylecorry/trail_sense/settings/migrations/PreferenceMigrator.kt +++ b/app/src/main/java/com/kylecorry/trail_sense/settings/migrations/PreferenceMigrator.kt @@ -4,6 +4,7 @@ import android.content.Context import com.kylecorry.andromeda.core.system.Screen import com.kylecorry.trail_sense.R import com.kylecorry.trail_sense.astronomy.infrastructure.AstronomyDailyWorker +import com.kylecorry.trail_sense.main.AppState import com.kylecorry.trail_sense.shared.UserPreferences import com.kylecorry.trail_sense.shared.preferences.PreferencesSubsystem import com.kylecorry.trail_sense.shared.sensors.CustomGPS @@ -22,6 +23,8 @@ class PreferenceMigrator private constructor() { val prefs = PreferencesSubsystem.getInstance(context).preferences var currentVersion = prefs.getInt("pref_version") ?: 0 + AppState.isReturningUser = currentVersion > 0 + while (currentVersion < version) { val current = currentVersion val next = currentVersion + 1 diff --git a/app/src/main/java/com/kylecorry/trail_sense/settings/ui/SettingsMoveNotice.kt b/app/src/main/java/com/kylecorry/trail_sense/settings/ui/SettingsMoveNotice.kt new file mode 100644 index 000000000..0e66e68a2 --- /dev/null +++ b/app/src/main/java/com/kylecorry/trail_sense/settings/ui/SettingsMoveNotice.kt @@ -0,0 +1,29 @@ +package com.kylecorry.trail_sense.settings.ui + +import android.content.Context +import com.kylecorry.trail_sense.R +import com.kylecorry.trail_sense.main.AppState +import com.kylecorry.trail_sense.shared.CustomUiUtils +import com.kylecorry.trail_sense.shared.commands.Command +import com.kylecorry.trail_sense.shared.preferences.PreferencesSubsystem + +class SettingsMoveNotice(private val context: Context) : Command { + + private val key = "settings_move_notice_shown" + private val prefs = PreferencesSubsystem.getInstance(context).preferences + + override fun execute() { + if (!AppState.isReturningUser) { + prefs.putBoolean(key, true) + return + } + + CustomUiUtils.disclaimer( + context, + context.getString(R.string.settings_have_moved), + context.getString(R.string.settings_have_moved_message), + key, + cancelText = null + ) + } +} \ No newline at end of file diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index 96fc5265b..1794fea4f 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -1365,6 +1365,8 @@ pref_tool_quick_action_header_key pref_tool_quick_actions pref_pinned_tools + Settings have moved + App settings have been moved to the Tools tab %d map %d maps