# Settings

Status: `AppPreferences` (over `SharedPreferences`), a view model per settings page over one shared `SettingsTree` (#969), and the phone and TV screens; adapters and `downloads` read preferences through ports (rule R17), and so do the view models outside `settings` (rule R23, #969). As of 2026-12-01 (`main`).

## Start here

- Preferences are stored in `AppPreferences` (`settings/.../domain/AppPreferences.kt`) over Android's `SharedPreferences` (`<packageName>_preferences` in `core/.../di/SharedPreferencesModule.kt`), with typed `Preference` descriptors (`Boolean`, `Int`, `Long`, `Float`, `String?`, `Set<String>`).
- Each settings page has its own view model in `settings/.../presentation/settings/` (#969): `SettingsViewModel` (the top page), `LanguageSettingsViewModel`, `InterfaceSettingsViewModel`, `DetailPagesSettingsViewModel`, `PlayerSettingsViewModel`, `SubtitleStyleSettingsViewModel` (TV), `MpvSettingsViewModel`, `DownloadSettingsViewModel`, `NetworkSettingsViewModel`, `CacheSettingsViewModel` and `PermissionsSettingsViewModel`. Each lists only its own rows and extends `SettingsPageViewModel`. `SettingsTree` is the code they share: it filters rows by `AppVariant` (ADR 0008 / #133), `ServerCapabilities` (`ServerFeature`, #769), `minSdk` and boolean `dependencies`, fills in the values with the bounds, and saves a change. `SettingsPage` maps a route's `indexes` to the page. A setting goes on the page that shows it, so `settings` stays the one module that knows every preference.
- Phone screens live in `app/phone/.../presentation/settings/` (`SettingsScreen.kt` + `components/`). TV routes both top-level (`SettingsScreen.kt`) and nested (`SettingsSubScreen.kt`) categories through `TvSettingsLayout` (`app/tv/.../ce/presentation/settings/TvSettingsLayout.kt`, #347).
- Adapters (`data`, `server/jellyfin`, `ratings/mdblist`, `device`) and `downloads` never reference `AppPreferences` directly (R17, R18); `core/.../di/AppPreferencesPorts.kt` implements the `application` ports (`DownloadSettings`, `CurrentServerId`, `NextUpMaxDays`, `NetworkTimeouts`, `ExternalRatingsSettings`, `ResumeThresholdsStore`) over `AppPreferences`.
- View models outside `settings` read the settings through ports too (R23, #969): `PlayerSettings`, `StillWatchingSettings`, `MediaSegmentSettings`, `InterfaceSettings`, `DetailPageSettings` (with `DetailSections`), `HomeSettings`, `LibrarySettings` and `SignedInUser` in `application/.../settings/ports/`, and `CurrentServerSelection` (follow or pick the current server) in `application/.../repository/`. All are implemented in `AppPreferencesPorts.kt`. A port can return a type of `domain` instead of the stored string: `PlayerSettings.autoPlayNext` is an `AutoPlayNextSetting`, and an unset or unknown value maps to `SERVER` there (step 10 of ADR 0003). A setting a feature reads goes on the port of its area; only the view models of `settings` take `AppPreferences`.
- Test fast: `./gradlew :settings:testDebugUnitTest` and `./gradlew :app:tv:testLibreDebugUnitTest --tests '*Settings*'`.

## What it does

`AppPreferences` wraps `SharedPreferences` with `getValue`, `observe` (`callbackFlow` over `OnSharedPreferenceChangeListener`), and `setValue` (`apply()`). If reading a key fails (for example after a type mismatch), `getValue` resets it to `defaultValue` and returns that default. Alongside user-facing settings, `AppPreferences` holds internal state (`currentServer` as `ServerId` via `currentServerId()`/`setCurrentServerId()`, #902; cached session credentials `sessionServerId`, `sessionBaseUrl`, `sessionAccessToken`, `sessionUserId`, `sessionServerType`, #250, #770; `playerBrokenAudioDecoders`; `smartDownloadsSince`; `localNetworkPermissionDecided`; library `sortBy`/`sortOrder`/`filterWatched`; and one-shot migration flags). `backup_rules.xml` and `data_extraction_rules.xml` exclude the whole `sharedpref` domain from backups and device-to-device transfers (#731) so session tokens and `mdbListApiKey` never leave the device.

`BaseApplication.onCreate()` runs one-shot preference migrations at startup:
- `migrateMpvAudioOutput()` (#52) moves `"aaudio"` in `playerMpvAo` to `Constants.MpvAudioOutput.AUDIOTRACK` once (`mpvAoAaudioMigrated`).
- `migrateMediaSegmentActions()` (#271) converts the removed global segment switches and type lists via `MediaSegmentsMigration.actions()` into per-type actions (`INTRO`, `OUTRO`, `RECAP`, `PREVIEW`, `COMMERCIAL`), guarded by `mediaSegmentActionsMigrated`.
- `removeOfflineMode()` (#281) removes `pref_offline_mode` if present.
- Phone's `BaseApplication` calls `migrateMaxBitratePerNetwork()` (#837) to copy `playerMaxBitrate` (Wi-Fi/Ethernet) to `playerMaxBitrateMobile` once when the mobile key is absent; TV's `BaseApplication` calls `useTvImageCacheSize()` to default `imageCacheSize` to `TV_IMAGE_CACHE_SIZE_MB` (100 MB) when unset.

A settings route holds a path of page names (`indexes: List<Int>`, the string IDs of the rows that open them). `SettingsPage.of(indexes)` walks it from the top page: each name opens the page below with that name, a name that is no such page is skipped, and `title_settings` ends the walk (the phone opens Settings with it). The phone's `SettingsScreen` and TV's `SettingsSubScreen` then take that page's view model (`settingsPageViewModel`, one `when` per app); TV's `SettingsScreen` is always the top page. Each page view model builds `SettingsState` from its own rows (`groups`) through `SettingsTree.present`:
- Filters by `supportedDeviceTypes` (`AppVariant.PHONE` or `AppVariant.TV`, injected via each app's `AppVariantModule`). The Interface and Player pages also check `WideWindow.isPossible` (#622), `KeepPlayerLandscape.isShown` (#363) and `CastBuild.isIncluded` (#626, bound via each app/flavor's `CastBuildModule`).
- Filters groups and items by `ServerFeature` (`MEDIA_SEGMENTS`, `TRICKPLAY`, `THEME_SONGS`) against `CurrentServerCapabilities.get()`, and hides the `"server"` option from `playerAutoPlayNext` via `withoutServerChoice()` when `autoPlayNextSetting` is false (#769).
- Clamps `subtitleFontScale` (`50..200`), `smartDownloadsKeepReady` (`>= 1`), and `stillWatchingPromptTimeoutSeconds` (`>= 5`) with `AppPreferences.bounded()` (#559) both on load and on save (`SettingsTree.save`).
- Formats `PreferenceIntInput` labels with `numberInputText()` (#400) for plurals (`suffixPluralsRes`) and zero states (`zeroLabelRes` such as "Off" or "No limit").
- `DownloadSettingsViewModel` reads the download storage options on `Dispatchers.IO` on every load and sets `smartDownloadsSince` when Smart Downloads is turned on; `CacheSettingsViewModel` clears Coil + `HomeCache` via `AppCaches.clear()` (`AppCachesModule`).

Dedicated sub-screens in `settings/` and the apps handle custom flows: `ExternalRatingsSettingsViewModel` (#331), `SubtitleStyleViewModel` (phone's `SubtitleStyleScreen`, #308), `SettingsFileEditViewModel` (phone's `mpv/mpv.conf` and `mpv/input.conf` editor), `HomeRowsScreen` (#142), `AboutScreen` + `LicensesScreen` (and TV's `DeviceProfileScreen`, #211, #384, #492), and TV's `ScreensaverSettingsActivity`/`ScreensaverSettingsScreen` (#140).

## Where the code is

| Path | What |
|---|---|
| [`settings/.../domain/AppPreferences.kt`](../../settings/src/main/java/dev/jdtech/jellyfin/settings/domain/AppPreferences.kt) | Typed `Preference` keys, `SharedPreferences` read/write/observe, startup migrations, `currentServerId` |
| [`settings/.../domain/IntPreferenceBounds.kt`](../../settings/src/main/java/dev/jdtech/jellyfin/settings/domain/IntPreferenceBounds.kt), [`MediaSegmentsMigration.kt`](../../settings/src/main/java/dev/jdtech/jellyfin/settings/domain/MediaSegmentsMigration.kt) | Bounded integer clamping (#559) and pure per-type segment migration (#271) |
| [`settings/.../domain/VideoQualities.kt`](../../settings/src/main/java/dev/jdtech/jellyfin/settings/domain/VideoQualities.kt), [`QualityNetwork.kt`](../../domain/src/main/kotlin/dev/jdtech/jellyfin/domain/playback/model/QualityNetwork.kt) (in `domain` since step 15 of #970) | Bitrate-only quality ladder (#837, #1021) and metered-network split |
| [`settings/.../domain/WideWindow.kt`](../../settings/src/main/java/dev/jdtech/jellyfin/settings/domain/WideWindow.kt), [`KeepPlayerLandscape.kt`](../../settings/src/main/java/dev/jdtech/jellyfin/settings/domain/KeepPlayerLandscape.kt), [`CastBuild.kt`](../../settings/src/main/java/dev/jdtech/jellyfin/settings/presentation/settings/CastBuild.kt) | Visibility checks for tablet/foldable layout, orientation lock, and Cast settings |
| [`settings/.../domain/AppCaches.kt`](../../settings/src/main/java/dev/jdtech/jellyfin/settings/domain/AppCaches.kt), [`Constants.kt`](../../settings/src/main/java/dev/jdtech/jellyfin/settings/domain/Constants.kt) | Cache-clearing port and default constants (subtitle style, mpv `ao`, still-watching min, network timeouts) |
| [`settings/.../presentation/models/`](../../settings/src/main/java/dev/jdtech/jellyfin/settings/presentation/models/) | `Preference` UI models (`PreferenceSwitch`, `PreferenceSelect`, `PreferenceIntSelect`, `PreferenceDynamicSelect`, `PreferenceIntInput`, `PreferenceLongInput`, `PreferenceCategory`, `PreferenceAction`, `PreferenceFileEdit`, `PreferencePermission`, `PreferenceAppLanguage`, `PreferenceMultiSelect`), `ServerFeature`, `numberInputText` |
| [`settings/.../presentation/settings/SettingsTree.kt`](../../settings/src/main/java/dev/jdtech/jellyfin/settings/presentation/settings/SettingsTree.kt), [`SettingsPageViewModel.kt`](../../settings/src/main/java/dev/jdtech/jellyfin/settings/presentation/settings/SettingsPageViewModel.kt), [`SettingsPage.kt`](../../settings/src/main/java/dev/jdtech/jellyfin/settings/presentation/settings/SettingsPage.kt) | What every page shares (filtering, values, bounds, saving), the base view model of a page (state, events, rows that open pages and screens), and the pages with the walk from a route's `indexes` |
| [`settings/.../presentation/settings/SettingsViewModel.kt`](../../settings/src/main/java/dev/jdtech/jellyfin/settings/presentation/settings/SettingsViewModel.kt), [`PlayerSettingsViewModel.kt`](../../settings/src/main/java/dev/jdtech/jellyfin/settings/presentation/settings/PlayerSettingsViewModel.kt), and the other `*SettingsViewModel.kt` next to them | One view model per page with that page's rows; `SettingsAction`/`SettingsEvent` are shared |
| [`settings/.../presentation/ratings/ExternalRatingsSettingsViewModel.kt`](../../settings/src/main/java/dev/jdtech/jellyfin/settings/presentation/ratings/ExternalRatingsSettingsViewModel.kt), [`SubtitleStyleViewModel.kt`](../../settings/src/main/java/dev/jdtech/jellyfin/settings/presentation/subtitle/SubtitleStyleViewModel.kt), [`SettingsFileEditViewModel.kt`](../../settings/src/main/java/dev/jdtech/jellyfin/settings/presentation/settings/SettingsFileEditViewModel.kt) | Sub-screen ViewModels for MDBList ratings (#331), phone subtitle style (#308), and `mpv.conf`/`input.conf` |
| [`core/.../di/AppPreferencesPorts.kt`](../../core/src/main/java/dev/jdtech/jellyfin/di/AppPreferencesPorts.kt), [`AppPreferencesModule.kt`](../../core/src/main/java/dev/jdtech/jellyfin/di/AppPreferencesModule.kt), [`SharedPreferencesModule.kt`](../../core/src/main/java/dev/jdtech/jellyfin/di/SharedPreferencesModule.kt) | `AppPreferences` DI and `application` port implementations (`DownloadSettings`, `CurrentServerId` and `CurrentServerSelection`, `NextUpMaxDays`, `NetworkTimeouts`, `ExternalRatingsSettings`, `ResumeThresholdsStore`, and since #969 the view models' settings ports) |
| [`application/.../settings/ports/`](../../application/src/main/kotlin/dev/jdtech/jellyfin/settings/ports/) | The settings ports of the view models, per area (#969) |
| [`core/.../core/settings/SharedPreferencesResumeThresholdsStore.kt`](../../core/src/main/java/dev/jdtech/jellyfin/core/settings/SharedPreferencesResumeThresholdsStore.kt) | Per-server resume thresholds persisted in `SharedPreferences` (#637, #918) |
| [`app/phone/.../presentation/settings/SettingsScreen.kt`](../../app/phone/src/main/java/dev/jdtech/jellyfin/presentation/settings/SettingsScreen.kt), [`components/`](../../app/phone/src/main/java/dev/jdtech/jellyfin/presentation/settings/components/) | Phone settings screen, sub-screens (`AboutScreen.kt`, `LicensesScreen.kt`, `SubtitleStyleScreen.kt`, `HomeRowsScreen.kt`, `ExternalRatingsScreen.kt`, `SettingsFileEditScreen.kt`), and card/dialog components |
| [`app/tv/.../presentation/settings/SettingsScreen.kt`](../../app/tv/src/main/java/dev/jdtech/jellyfin/presentation/settings/SettingsScreen.kt), [`SettingsSubScreen.kt`](../../app/tv/src/main/java/dev/jdtech/jellyfin/presentation/settings/SettingsSubScreen.kt), [`TvSettingsLayout.kt`](../../app/tv/src/main/java/dev/jdtech/jellyfin/ce/presentation/settings/TvSettingsLayout.kt) | TV root/sub-settings screens and shared two-pane D-pad layout (#347, #419, #420) |
| [`app/tv/.../ce/presentation/settings/about/`](../../app/tv/src/main/java/dev/jdtech/jellyfin/ce/presentation/settings/about/) | TV `AboutScreen`, `DeviceProfileScreen`, and `LicensesScreen` (#211) |
| [`app/phone/.../di/AppVariantModule.kt`](../../app/phone/src/main/java/dev/jdtech/jellyfin/di/AppVariantModule.kt), [`app/tv/.../di/AppVariantModule.kt`](../../app/tv/src/main/java/dev/jdtech/jellyfin/di/AppVariantModule.kt), `CastBuildModule.kt` | `AppVariant.PHONE` / `AppVariant.TV`, `CastBuild` per flavour, and each app's `AppCachesModule` |

## Rules

- **R17** ([`AdapterSettingsTest.kt`](../../architecture/src/test/kotlin/dev/jdtech/jellyfin/architecture/AdapterSettingsTest.kt)): no production file of `data`, `server/jellyfin`, `ratings/mdblist`, `device`, or `downloads` may name `AppPreferences`. Expose new settings needed by adapters or the download engine through a port in `application` and implement it in `core/.../di/AppPreferencesPorts.kt` (#918).
- **R23** ([`ViewModelSettingsTest.kt`](../../architecture/src/test/kotlin/dev/jdtech/jellyfin/architecture/ViewModelSettingsTest.kt)): no view model outside `settings` names `AppPreferences`, `Context`, `Application`, `@ApplicationContext` or `AndroidViewModel`. Add the setting to the port of its area in `application/.../settings/ports/` (a new port if the area has none) and implement it in `AppPreferencesPorts.kt`; keep the key, the default and whether it is read live or once (#969).
- **R18** ([`AdapterDependencyTest.kt`](../../architecture/src/test/kotlin/dev/jdtech/jellyfin/architecture/AdapterDependencyTest.kt)): no adapter module (`data`, `server/jellyfin`, `ratings/mdblist`, `device`) may depend on a feature module such as `settings` in production.
- **R1, R2, R10**: `settings` stays free of Jellyfin SDK types/`JellyfinApi`, and uses typed IDs (`ServerId`) rather than bare `String` IDs outside the adapter.
- **Translations and `AppVariant`**: every user-visible CE string or plural must use a `ce_` key in `strings.xml` and be translated into all 36 languages (`check-translations.py`), never editing upstream translation files. Variant-only UI decisions use `AppVariant` (ADR 0008), not `FEATURE_LEANBACK`.

## How to test it

Fastest unit test commands:

```bash
./gradlew :settings:testDebugUnitTest
./gradlew :app:tv:testLibreDebugUnitTest --tests '*Settings*'
```

Also relevant when touching ports, backup rules, or phone licenses:

```bash
./gradlew :core:testLibreDebugUnitTest --tests '*SharedPreferencesResumeThresholdsStoreTest*'
./gradlew :app:phone:testLibreDebugUnitTest --tests '*LicenseDialogTextTest*' --tests '*DeviceTransferRulesTest*'
./gradlew :architecture:test --tests '*AdapterSettingsTest*'
```

Unit tests in `settings/src/test/` and `app/tv/src/test/.../settings/`:
- `settings`: `IntPreferenceBoundsTest`, `MaxBitratePerNetworkTest`, `MediaSegmentsMigrationTest`, `RemoveOfflineModeTest`, `VideoQualitiesTest`, `NumberInputTextTest`, `ExternalRatingsSettingsViewModelTest`, `SettingsPageTest` (the walk from a route to a page).
- `app/tv`: `SettingsCapabilitiesTest`, `SettingsTreeVariantTest`, `SettingsPagesTest` (each page's rows, bounds, dependencies, storage, Smart Downloads, Clear cache, the rows that open pages), `TvSettingsLayoutTest` (Robolectric Compose D-pad focus + Back behaviour), `TvSettingsNumberStepsTest`. Their `settingsPageViewModel` helper picks the view model for a path as the screens do.
- `app/phone`: `CastBuildSettingTest`, `KeepLandscapeSettingTest` (on `PlayerSettingsViewModel`).

**What unit tests do not cover:**
- `SettingsScreen` on phone (`app/phone/.../presentation/settings/SettingsScreen.kt`), `SubtitleStyleScreen`, `SettingsFileEditScreen`, and phone dialogs (`SettingsNumberInputDialog`, `SettingsSelectDialog`): these are checked by hand on a phone or tablet emulator.
- `getStorageOptions()` with multiple physical/emulated storage volumes (`StatFs` on external dirs), Android 13+ `Settings.ACTION_APP_LOCALE_SETTINGS`, runtime permission prompts (`SettingsPermissionCard`), and actual `BaseApplication` startup migrations on an upgraded APK.
- `TvSettingsLayout` visual alignment, overscan safe area, and D-pad traversal across every TV settings sub-screen on a TV emulator (`scripts/tv-dpad.sh`).

## Before a PR

```bash
./gradlew ktfmtCheck
./gradlew :settings:testDebugUnitTest
./gradlew :app:tv:testLibreDebugUnitTest --tests '*Settings*'
./gradlew :app:phone:testLibreDebugUnitTest --tests '*LicenseDialogTextTest*' --tests '*DeviceTransferRulesTest*'
./gradlew :core:testLibreDebugUnitTest --tests '*SharedPreferencesResumeThresholdsStoreTest*'
./gradlew :architecture:test
./gradlew :app:phone:compileLibreDebugKotlin :app:tv:compileLibreDebugKotlin
python3 .claude/skills/translate-strings/scripts/check-translations.py   # when strings changed
```

## Decisions and history

- [TV ADR 0008](../tv-research/adr/0008-tv-flag-in-shared-modules.md) / [#133](https://github.com/midasvo/ephyra/issues/133): `AppVariant` (`PHONE` vs `TV`) injected from each app filters shared settings (now in `SettingsTree`) instead of inspecting device hardware.
- [#347](https://github.com/midasvo/ephyra/pull/347), [#524](https://github.com/midasvo/ephyra/pull/524): unified `TvSettingsLayout` for both root and nested TV settings pages, plus D-pad focus return on `Left`/`Back` ([#419](https://github.com/midasvo/ephyra/issues/419)), whole-second stepping for millisecond settings ([#420](https://github.com/midasvo/ephyra/issues/420)), hiding the phone-only `Advanced` file-editor group on TV ([#421](https://github.com/midasvo/ephyra/issues/421)), and screensaver summary spacing ([#422](https://github.com/midasvo/ephyra/issues/422)).
- [#211](https://github.com/midasvo/ephyra/issues/211), [#384](https://github.com/midasvo/ephyra/issues/384), [#503](https://github.com/midasvo/ephyra/pull/503), [#492](https://github.com/midasvo/ephyra/pull/492): dedicated TV `AboutScreen`/`DeviceProfileScreen`/`LicensesScreen`, phone license text fallback (`LicenseDialogTextTest`), and Android 11+ device profile export.
- [#736](https://github.com/midasvo/ephyra/issues/736) / [#793](https://github.com/midasvo/ephyra/pull/793), [#918](https://github.com/midasvo/ephyra/issues/918) / [#927](https://github.com/midasvo/ephyra/pull/927) / [#926](https://github.com/midasvo/ephyra/pull/926): dropped the unused Jellyfin SDK dependency from `settings`, and moved `data`, `server/jellyfin`, and `downloads` off `AppPreferences` onto `application` ports in `AppPreferencesPorts.kt` (rule R17).
- [#969](https://github.com/midasvo/ephyra/issues/969): the view models outside `settings` take settings ports instead of `AppPreferences`, and ports instead of a `Context` (`AboutInfoSource`, `StorageVolumes`, `PlayerTexts`, `PlayerMediaSessions`, `PlayerDevice`, `PermissionDecision`); rule R23. Part 2 split the one `SettingsViewModel` (1850 lines) into a view model per page over `SettingsTree`, with `SettingsPage` for the walk; a category row no longer carries the page below it (`PreferenceCategory.nestedPreferenceGroups` is gone). `SubtitleStyleViewModel` and `ExternalRatingsSettingsViewModel` stay on `AppPreferences`: they are settings screens in `settings`, the one module that knows the keys, and a port for them would only copy those keys.
- [#769](https://github.com/midasvo/ephyra/issues/769): `ServerFeature` and `withoutServerChoice()` hide settings for features the current server lacks (`ServerCapabilities`), re-evaluated on every load of a page.
- [#271](https://github.com/midasvo/ephyra/issues/271), [#281](https://github.com/midasvo/ephyra/issues/281), [#837](https://github.com/midasvo/ephyra/issues/837), [#52](https://github.com/midasvo/ephyra/issues/52): one-shot migrations for per-type media segment actions (`MediaSegmentsMigration`), removing Offline Mode (`removeOfflineMode`), splitting Wi-Fi vs mobile streaming quality (`migrateMaxBitratePerNetwork`), and moving mpv `ao` off `"aaudio"` (`migrateMpvAudioOutput`).
- [#400](https://github.com/midasvo/ephyra/issues/400), [#559](https://github.com/midasvo/ephyra/issues/559), [#1021](https://github.com/midasvo/ephyra/pull/1021): singular/plural and zero-label number formatting (`numberInputText`), clamping bounded integer preferences on both load and save (`AppPreferences.bounded`), and bitrate-only quality labels (`VideoQualities`).
- [#950](https://github.com/midasvo/ephyra/issues/950) / [#958](https://github.com/midasvo/ephyra/pull/958): added `navigate_back` content description to the phone settings top bar Back button.

## Pitfalls

- **The settings screens reload after `OnUpdate`, and a page is found by string IDs.** `SettingsPage.of(indexes)` walks `SettingsPage.nameStringResource` from the top (for example, TV's `NavigateToSubtitleStyle` must pass both `settings_category_player` and `subtitle_style`). Renaming a page's string resource requires updating any hardcoded navigation `indexes` list too (such as `NavigationRoot.kt` or `SettingsScreen.kt` on TV). A new page needs a `SettingsPage` entry, a view model, a `pageCategory` row on its parent, and a branch in both apps' `settingsPageViewModel` (the `when` is exhaustive, so the build says where).
- **Boolean `dependencies` only disable a row; they do not hide it.** On `SettingsBaseCard` (phone) and `TvSettingsRow` (TV), `enabled = false` dims/disables interaction when any `PreferenceBackend<Boolean>` in `dependencies` is `false`. To hide a setting entirely per variant or server capability, use `supportedDeviceTypes` or `serverFeature`, not `dependencies`.
- **TV has no `PreferenceIntInput`/`PreferenceLongInput` text dialog or file editor.** `TvSettingsLayout` edits number settings in the right details pane with `+1`/`-1`/`+10`/`-10` steps (scaled by `1000L` when `suffixRes == R.string.ms`, #420) and clamps at `>= 0`. Phone-only features like `PreferenceFileEdit` (`mpv.conf`/`input.conf`) and `PreferenceIntSelect` streaming quality selectors must declare `supportedDeviceTypes = listOf(DeviceType.PHONE)` so TV does not show an uneditable or broken row (#421).
- **Adding a bounded `Int` preference needs `AppPreferences.bounded()` on both load and save.** Without clamping in `IntPreferenceBounds.kt`, the UI saves and displays raw out-of-range numbers such as `0 s` even if the consumer treats `0` as a minimum like `5 s` (#559).
- **Sensitive keys live in the same `SharedPreferences` file.** `sessionAccessToken` and `mdbListApiKey` are stored in `AppPreferences` alongside UI toggles; keep `sharedpref` excluded in both `backup_rules.xml` and `data_extraction_rules.xml` (`DeviceTransferRulesTest`, #731).
- **Adding a new `Preference` subclass requires updating both UI renderers.** `SettingsGroupCard.kt` (phone) and `TvSettingsPreference` / `TvSettingsDetails` in `TvSettingsLayout.kt` (TV) switch exhaustively over `Preference` subtypes (note TV currently omits `PreferenceDynamicSelect`, `PreferenceIntSelect`, `PreferenceAppLanguage`, and `PreferenceFileEdit`, relying on `supportedDeviceTypes = listOf(DeviceType.PHONE)`, because `TvSettingsPreference`'s `when` does not handle them if shown on TV).
- **`SharedPreferences` listeners and migrations.** `AppPreferences.observe` uses `OnSharedPreferenceChangeListener` inside `callbackFlow` (`SharedPreferences` holds weak references to listeners, so keep the flow collected). Startup migrations that flip a default (`migrateMpvAudioOutput`, `migrateMediaSegmentActions`) must keep a one-shot guard flag so a user's deliberate choice afterwards is not overwritten on the next launch.
