INTEGRATION.md

6.7 KB · raw

rendered · source

D1 — OnboardingScreen integration

Drop-in screen drafted at app/drafts/D1/OnboardingScreen.kt.

1. Destination path

Move the file to:

app/src/main/java/com/peachpasswords/ui/onboarding/OnboardingScreen.kt

Package is already com.peachpasswords.ui.onboarding (new package — create the folder).

The screen exposes:

@Composable
fun OnboardingScreen(onFinished: () -> Unit)

It also exports two top-level constants the launch guard reuses (so the SharedPreferences key/name live in exactly one place):

const val ONBOARD_PREFS = "peach_prefs"
const val ONBOARD_KEY = "peach_onboarded"

OnboardingScreen writes peach_onboarded = true to SharedPreferences("peach_prefs") itself on "Get started" (in its internal finish lambda) before invoking onFinished. The host does not need to write the flag — only read it for the guard.

2. New nav route — PeachNav.kt

This file is read-only for the drafter. Add this data object to the sealed class. Insertion anchor — add it directly after the Lock entry:

sealed class PeachNav(val route: String) {
    data object Lock : PeachNav("lock")
    data object VaultList : PeachNav("vault")

becomes:

sealed class PeachNav(val route: String) {
    data object Onboarding : PeachNav("onboarding")
    data object Lock : PeachNav("lock")
    data object VaultList : PeachNav("vault")

3. Register the composable — PeachAppNavHost.kt

Add the import (alongside the other screen imports near the top):

import com.peachpasswords.ui.onboarding.OnboardingScreen

Add this composable(...) block inside the NavHost { ... } lambda. Anchor — place it immediately before the existing Lock block:

        composable(PeachNav.Lock.route) {
            LockScreen(

Insert above it:

        composable(PeachNav.Onboarding.route) {
            OnboardingScreen(
                onFinished = {
                    // Onboarding flows straight into the create-vault flow.
                    // LockScreen shows the "NEW VAULT" / create state automatically
                    // when no vault exists (state.hasVault == false), so no extra
                    // argument is needed.
                    navController.navigate(PeachNav.Lock.route) {
                        popUpTo(PeachNav.Onboarding.route) { inclusive = true }
                    }
                },
            )
        }

4. Launch guard — pick the start destination

The app currently hard-starts at PeachNav.Lock (see PeachAppNavHost's default param startDestination: PeachNav = PeachNav.Lock, and MainActivity calling PeachAppNavHost() with no argument).

The guard logic from the brief:

On app launch, if no vault exists AND peach_onboarded == false, navigate to OnboardingScreen before LockScreen.

VaultRepository.hasVault(): Boolean already exists and is synchronous (store.hasVault()), and LockViewModel already reads it the same way. There are two clean ways to wire the guard — pick one:

Option A (recommended) — compute in MainActivity, pass as startDestination

MainActivity is a @AndroidEntryPoint FragmentActivity, so it can read both SharedPreferences and an injected VaultRepository. Change the PeachAppNavHost() call site:

// MainActivity.kt — add field injection
@Inject lateinit var vault: com.peachpasswords.vault.VaultRepository

(requires import javax.inject.Inject; field injection works on a Hilt @AndroidEntryPoint activity.)

Then in onCreate, before setContent { ... }:

val prefs = getSharedPreferences("peach_prefs", MODE_PRIVATE)
val onboarded = prefs.getBoolean("peach_onboarded", false)
val start =
    if (!vault.hasVault() && !onboarded) com.peachpasswords.ui.PeachNav.Onboarding
    else com.peachpasswords.ui.PeachNav.Lock

and pass it down:

setContent {
    PeachTheme {
        PeachAppNavHost(startDestination = start)
    }
}

PeachAppNavHost already accepts startDestination — no signature change needed.

Option B — compute inside PeachAppNavHost

If you prefer to keep MainActivity untouched, compute the start destination inside PeachAppNavHost using LocalContext + hiltViewModel<LockViewModel>() (its state.hasVault already reflects vault.hasVault()), then choose the startDestination before building the NavHost. Option A is cleaner because the start destination must be known at first composition; reading it from a VM inside the host risks a one-frame flash of Lock before redirect.

Use the exported constants instead of raw strings to avoid drift:

import com.peachpasswords.ui.onboarding.ONBOARD_PREFS
import com.peachpasswords.ui.onboarding.ONBOARD_KEY
...
val onboarded = prefs.getBoolean(ONBOARD_KEY, false)

5. Visual notes / assumptions

6. No new ViewModel / Repository / model APIs required

7. Suggested koh saves (orchestrator runs these)

checkpoint "before OnboardingScreen"
save "feat: D1 OnboardingScreen — 3-card swipe flow, onboarded guard, nav (v2.1.31)"