Skip to content

Open-source Android PDF and document toolkit with PDF tools, Office viewing, XLSX editing, scanning, and image editing. Built with Kotlin and Jetpack Compose.

feat: re-show onboarding after app updates; revert version to 1.2.0/3

Chethan616380636c96d8b
diff --git a/app/build.gradle.kts b/app/build.gradle.kts
index d332b19..1013ce3 100644
--- a/app/build.gradle.kts
+++ b/app/build.gradle.kts
@@ -38,8 +38,8 @@ android {
applicationId = "com.chethan616.clearpdf"
minSdk = 23
targetSdk = 36
- versionCode = 4
- versionName = "1.3.0"
+ versionCode = 3
+ versionName = "1.2.0"
// Keep every locale declared by the app. Filtering this to English
// removes values-pt-rBR from the packaged APK, so the language picker
// can appear to work while the app continues to resolve English.
diff --git a/app/src/main/java/com/chethan616/clearpdf/data/repository/OnboardingManager.kt b/app/src/main/java/com/chethan616/clearpdf/data/repository/OnboardingManager.kt
index eda2266..d142511 100644
--- a/app/src/main/java/com/chethan616/clearpdf/data/repository/OnboardingManager.kt
+++ b/app/src/main/java/com/chethan616/clearpdf/data/repository/OnboardingManager.kt
@@ -10,6 +10,10 @@ object OnboardingManager {
private const val PREFS_NAME = "clearpdf_onboarding"
private const val KEY_COMPLETED = "onboarding_completed"
private const val KEY_LOCALE = "selected_locale"
+ // The app versionCode the user last finished onboarding on. When a newer build is
+ // installed this is behind [currentVersionCode], so the tour is shown again to surface
+ // what changed in the update.
+ private const val KEY_ONBOARDED_VERSION = "onboarded_version_code"
private fun prefs(context: Context): SharedPreferences =
context.getSharedPreferences(PREFS_NAME, Context.MODE_PRIVATE)
@@ -17,11 +21,40 @@ object OnboardingManager {
fun hasCompletedOnboarding(context: Context): Boolean =
prefs(context).getBoolean(KEY_COMPLETED, false)
+ /** The installed app's versionCode (0 if it can't be resolved). */
+ fun currentVersionCode(context: Context): Int = try {
+ val info = context.packageManager.getPackageInfo(context.packageName, 0)
+ if (android.os.Build.VERSION.SDK_INT >= 28) info.longVersionCode.toInt()
+ else @Suppress("DEPRECATION") info.versionCode
+ } catch (e: Exception) {
+ 0
+ }
+
+ private fun onboardedVersionCode(context: Context): Int =
+ prefs(context).getInt(KEY_ONBOARDED_VERSION, -1)
+
+ /**
+ * Onboarding is shown on the very first launch AND again after every app update — i.e.
+ * whenever the installed [currentVersionCode] is newer than the one the user last completed
+ * the tour on. Completing (or replaying) it records the current version so it won't repeat
+ * until the next update.
+ */
+ fun shouldShowOnboarding(context: Context): Boolean {
+ if (!hasCompletedOnboarding(context)) return true
+ return onboardedVersionCode(context) < currentVersionCode(context)
+ }
+
fun setOnboardingComplete(context: Context) =
- prefs(context).edit().putBoolean(KEY_COMPLETED, true).apply()
+ prefs(context).edit()
+ .putBoolean(KEY_COMPLETED, true)
+ .putInt(KEY_ONBOARDED_VERSION, currentVersionCode(context))
+ .apply()
fun resetOnboarding(context: Context) =
- prefs(context).edit().putBoolean(KEY_COMPLETED, false).apply()
+ prefs(context).edit()
+ .putBoolean(KEY_COMPLETED, false)
+ .remove(KEY_ONBOARDED_VERSION)
+ .apply()
fun getSelectedLocale(context: Context): String =
prefs(context).getString(KEY_LOCALE, "en") ?: "en"
diff --git a/app/src/main/java/com/chethan616/clearpdf/ui/DocsApp.kt b/app/src/main/java/com/chethan616/clearpdf/ui/DocsApp.kt
index a932bf5..1ba73d0 100644
--- a/app/src/main/java/com/chethan616/clearpdf/ui/DocsApp.kt
+++ b/app/src/main/java/com/chethan616/clearpdf/ui/DocsApp.kt
@@ -96,7 +96,8 @@ fun DocsApp(shortcutRoute: String? = null, incomingPdfUri: android.net.Uri? = nu
// share or a shortcut skips the tour and goes straight to the document — the flag is left unset,
// so onboarding still appears on the next ordinary cold start rather than being lost.
val needsOnboarding = remember {
- !OnboardingManager.hasCompletedOnboarding(context) &&
+ // Shows on first launch and again after each app update (version-aware).
+ OnboardingManager.shouldShowOnboarding(context) &&
shortcutRoute == null && incomingPdfUri == null
}
// The locale the Activity actually booted with. Onboarding changes `selectedLocale` in place for