package com.peachpasswords.autofill import kotlinx.coroutines.flow.MutableStateFlow import kotlinx.coroutines.flow.StateFlow import kotlinx.coroutines.flow.asStateFlow import javax.inject.Inject import javax.inject.Singleton /** * Carries a one-shot "open the new-entry editor" request from the autofill picker * to the nav host. Mirrors [com.peachpasswords.updates.UpdateRepository]'s shape * so the host reads a [StateFlow] and calls a `consume` after navigating. * * Held at app scope so MainActivity's [android.app.Activity.onNewIntent] can set * the request before the NavHost subscribes (cold launches hit the same flow via * the picker→MainActivity launch path). */ @Singleton class AutofillNavRepository @Inject constructor() { private val _newEntryRequest = MutableStateFlow(null) val newEntryRequest: StateFlow = _newEntryRequest.asStateFlow() fun requestNewEntry(url: String?, username: String?, email: String?) { _newEntryRequest.value = NewEntryRequest( url = url?.takeIf { it.isNotBlank() }, username = username?.takeIf { it.isNotBlank() }, email = email?.takeIf { it.isNotBlank() }, ) } fun consumeNewEntryRequest() { _newEntryRequest.value = null } } /** * Prefill payload for the new-entry editor. Every field is optional — the * minimum contract is [url], mirroring the inline picker's create form. */ data class NewEntryRequest( val url: String? = null, val username: String? = null, val email: String? = null, )