CountryRepository

class CountryRepository(dataSource: CountryDataSource = DefaultCountryDataSource)(source)

Caches the result of a CountryDataSource and applies the caller's allow/exclude rules.

The cache exists so reopening the sheet, rotating the device, or retrying after an error does not re-hit a remote source. Concurrent countries calls are collapsed by a Mutex, so two selectors opening at once trigger one load, not two.

The cache is keyed by the platform's default Locale. The bundled source returns country names in the device's language, so a cache that ignored the locale would keep serving French names after the user switched to Arabic — for the whole process lifetime, since Default is a singleton. A locale change is rare and a reload is cheap, so the check is simply made on every call.

This class holds no UI state and is safe to keep in a singleton, a DI graph, or a remember.

Constructors

Link copied to clipboard
constructor(dataSource: CountryDataSource = DefaultCountryDataSource)

Types

Link copied to clipboard
object Companion

Functions

Link copied to clipboard
fun applyAvailability(countries: List<Country>, allowedCountryCodes: Set<String>?, excludedCountryCodes: Set<String>): List<Country>

Narrows countries to what a picker is allowed to show.

Link copied to clipboard
suspend fun countries(): List<Country>

Returns the full country list, loading it on first call.

Link copied to clipboard

Drops the cache so the next countries call reloads. Used by the sheet's Retry action.