Compare commits
13 Commits
0db0e3883f
...
566caf4305
| Author | SHA1 | Date | |
|---|---|---|---|
| 566caf4305 | |||
| d9e4e877cc | |||
| aee26a28f3 | |||
| 86f44805d1 | |||
| 09d3f9b934 | |||
| 24ada183e2 | |||
| 1e36c229ca | |||
| ea96e970c7 | |||
| 2085b82a5e | |||
| 10e0ca0b06 | |||
| 4eb9809993 | |||
| 367a8ff8af | |||
| 25ec248e73 |
54
CHANGELOG.md
Normal file
54
CHANGELOG.md
Normal file
@@ -0,0 +1,54 @@
|
|||||||
|
# Changelog
|
||||||
|
|
||||||
|
All notable changes to floret-kit are documented here. The format follows
|
||||||
|
[Keep a Changelog](https://keepachangelog.com/).
|
||||||
|
|
||||||
|
floret-kit is consumed **from source** — each app embeds it as a git submodule
|
||||||
|
and builds it through a Gradle composite build, pinning a specific commit. There
|
||||||
|
are no binary releases; "version" tracks the shared `version` in the root build
|
||||||
|
(currently `0.1.0`). Entries are grouped by module.
|
||||||
|
|
||||||
|
## [Unreleased]
|
||||||
|
|
||||||
|
### Added
|
||||||
|
|
||||||
|
- **`core-time`** (JVM library) — pure-Kotlin date/time helpers, no Android and
|
||||||
|
no third-party dependencies:
|
||||||
|
- `DayWindow.today()` — local-day boundaries for smart-list logic.
|
||||||
|
- `Instant.formatDate()` / `formatTime()` / `formatDateTime()` — locale- and
|
||||||
|
zone-aware display formatting over `kotlin.time.Instant`.
|
||||||
|
- `TimeBridge` — `Long` epoch-millis ↔ `Instant`, for content-provider I/O.
|
||||||
|
- **`core-crash`** (Android library) — privacy-respecting, on-device crash
|
||||||
|
capture and reporting. Writes an allowlist-only report (app/Android/device
|
||||||
|
version, locale, time, stack trace — nothing else) to private storage and
|
||||||
|
chains to the platform handler; uploads nothing. Includes startup crash-loop
|
||||||
|
detection, a report dialog that shows the full text before it leaves the
|
||||||
|
device, and an issue-tracker hand-off. Per-app specifics (display name, issue
|
||||||
|
URLs) come from a `CrashConfig` supplied at `install()`; each app keeps its
|
||||||
|
own thin themed `CrashReportActivity`.
|
||||||
|
- **`identity`** (Android library) — the family's Material 3 Expressive theme
|
||||||
|
factory `FloretExpressiveTheme(lightScheme, darkScheme, …)` (dynamic colour on
|
||||||
|
API 31+, system light/dark fallback, the standard motion scheme) plus
|
||||||
|
`rememberNavSlideSpec()`. Each app passes its own seed-derived colour schemes
|
||||||
|
and typography — the mechanics are shared, the look is not.
|
||||||
|
- **`components`** (Android library) — the shared Compose component vocabulary:
|
||||||
|
- `GroupedSurface` / `GroupedRow` + `Position` / `positionOf` — the canonical
|
||||||
|
press-morphing tonal grouped-row primitive (the Android-15 settings pattern).
|
||||||
|
- `InlineTextField` — the borderless tonal text input (capitalization is a
|
||||||
|
parameter).
|
||||||
|
- `OptionCard` — the sanctioned selection-dialog pick.
|
||||||
|
- `CollapsingScaffold` — the collapsing settings/sub-screen scaffold.
|
||||||
|
- `FullScreenPicker` / `OptionPicker` — the full-screen single-select picker.
|
||||||
|
- `pastelize()` — softens a raw provider colour to a theme-fitting pastel.
|
||||||
|
|
||||||
|
App-agnostic by design: apps compose their own screens and keep their own
|
||||||
|
identity chips/icons. String resources here (e.g. `back`) are fallbacks an app
|
||||||
|
can override.
|
||||||
|
|
||||||
|
### Conventions
|
||||||
|
|
||||||
|
- **No `foojay` toolchain resolver** anywhere — it can fetch a JDK at build time,
|
||||||
|
which reproducible / official F-Droid builds reject. Modules set `jvmTarget`
|
||||||
|
directly. See [`docs/ARCHITECTURE.md`](docs/ARCHITECTURE.md).
|
||||||
|
- AGP 9.x provides built-in Kotlin compilation, so Android modules apply only the
|
||||||
|
Android library + Compose plugins (no separate `kotlin.android`).
|
||||||
77
CONTRIBUTING.md
Normal file
77
CONTRIBUTING.md
Normal file
@@ -0,0 +1,77 @@
|
|||||||
|
# Contributing to floret-kit
|
||||||
|
|
||||||
|
floret-kit is the shared Material 3 Expressive design system + plumbing for the
|
||||||
|
Floret app family. Before changing it, skim
|
||||||
|
[`docs/ARCHITECTURE.md`](docs/ARCHITECTURE.md) (how it's built and consumed) and
|
||||||
|
[`docs/ROADMAP.md`](docs/ROADMAP.md) (what's in scope). This file is the
|
||||||
|
practical how.
|
||||||
|
|
||||||
|
## The rules
|
||||||
|
|
||||||
|
1. **Share mechanics, not look.** Extract the machinery; leave seed colours,
|
||||||
|
palettes, identity chips, and wording to the apps. If a piece can't be made
|
||||||
|
app-agnostic without contortion, it doesn't belong here yet.
|
||||||
|
2. **No app coupling.** A kit module never imports an app package, an app's `R`,
|
||||||
|
or a domain type. App-specific values arrive as **constructor/config
|
||||||
|
parameters** or **callbacks** (see `core-crash`'s `CrashConfig`,
|
||||||
|
`InlineTextField`'s `capitalization`).
|
||||||
|
3. **String resources are fallbacks.** Kit strings are English defaults an app
|
||||||
|
overrides via resource merge. Don't put app-specific or per-app-divergent
|
||||||
|
wording in the kit.
|
||||||
|
4. **Bake divergence into parameters, don't pick a silent winner.** Where two
|
||||||
|
apps differ, expose the difference. When a shared primitive adopts one app's
|
||||||
|
version as canonical, that's a deliberate, documented convergence.
|
||||||
|
5. **No `foojay` toolchain resolver** — not in any `*.gradle.kts`, not even as a
|
||||||
|
token in a comment. It breaks reproducible / official F-Droid builds. Set
|
||||||
|
`jvmTarget` directly. See [`docs/ARCHITECTURE.md`](docs/ARCHITECTURE.md) §5.
|
||||||
|
|
||||||
|
## Prerequisites
|
||||||
|
|
||||||
|
- JDK 17
|
||||||
|
- Android SDK (compileSdk 37) for the Android modules — set `ANDROID_HOME` or add
|
||||||
|
a gitignored `local.properties` with `sdk.dir`. Pure-JVM modules need neither.
|
||||||
|
|
||||||
|
## Build & test
|
||||||
|
|
||||||
|
```sh
|
||||||
|
./gradlew :core-time:test # JVM module (JUnit 5 + Truth)
|
||||||
|
./gradlew :core-crash:testDebugUnitTest
|
||||||
|
./gradlew :identity:assembleDebug
|
||||||
|
./gradlew build # everything
|
||||||
|
```
|
||||||
|
|
||||||
|
In practice the kit is exercised through a consuming app's composite build (e.g.
|
||||||
|
`agendula`'s `./gradlew assembleDebug`), which compiles the included modules from
|
||||||
|
source.
|
||||||
|
|
||||||
|
## Adding a module
|
||||||
|
|
||||||
|
1. Create `:<module>` and add `include(":<module>")` to
|
||||||
|
[`settings.gradle.kts`](settings.gradle.kts).
|
||||||
|
2. Add a `<module>/build.gradle.kts`:
|
||||||
|
- **JVM:** `plugins { alias(libs.plugins.kotlin.jvm) }`, a `kotlin { compilerOptions { jvmTarget = JVM_17 } }` block, JUnit 5 test deps.
|
||||||
|
- **Android:** `plugins { alias(libs.plugins.android.library); alias(libs.plugins.kotlin.compose) }` (no `kotlin.android` — AGP 9.x is built-in), `namespace = "de.jeanlucmakiola.floret.<area>"`, `compileSdk 37` / `minSdk 29`, `jvmTarget = JVM_17`.
|
||||||
|
3. Put sources under `src/main/kotlin/de/jeanlucmakiola/floret/<area>/`. The root
|
||||||
|
build's `subprojects {}` sets the shared `group`/`version`, so no per-module
|
||||||
|
coordinates are needed.
|
||||||
|
4. Add an entry to [`CHANGELOG.md`](CHANGELOG.md), the README module table, and
|
||||||
|
(if status-worthy) [`docs/ROADMAP.md`](docs/ROADMAP.md).
|
||||||
|
|
||||||
|
## Adopting the kit in an app
|
||||||
|
|
||||||
|
1. `git submodule add <kit-url> floret-kit`.
|
||||||
|
2. `includeBuild("floret-kit")` in the app's `settings.gradle.kts`.
|
||||||
|
3. `implementation("de.jeanlucmakiola.floret:<module>")` in the app module.
|
||||||
|
4. Ensure CI checks out submodules (`submodules: recursive`) and the included
|
||||||
|
build can find the SDK (`ANDROID_HOME`). For official F-Droid reproducible
|
||||||
|
builds, add `submodules: true` to the fdroiddata recipe and have the repro
|
||||||
|
guard scan the submodule.
|
||||||
|
5. The app pins a kit commit via the submodule; bump it deliberately to adopt kit
|
||||||
|
changes.
|
||||||
|
|
||||||
|
## Validate before pushing
|
||||||
|
|
||||||
|
- `python3 -c "import yaml; yaml.safe_load(open('<workflow>.yml'))"` after any
|
||||||
|
workflow edit — indentation bites.
|
||||||
|
- A consuming app's `lintDebug` + `testDebugUnitTest` + `assembleDebug` should be
|
||||||
|
green after a kit change you mean to land.
|
||||||
21
LICENSE
Normal file
21
LICENSE
Normal file
@@ -0,0 +1,21 @@
|
|||||||
|
MIT License
|
||||||
|
|
||||||
|
Copyright (c) 2026 Jean-Luc Makiola
|
||||||
|
|
||||||
|
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||||
|
of this software and associated documentation files (the "Software"), to deal
|
||||||
|
in the Software without restriction, including without limitation the rights
|
||||||
|
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||||
|
copies of the Software, and to permit persons to whom the Software is
|
||||||
|
furnished to do so, subject to the following conditions:
|
||||||
|
|
||||||
|
The above copyright notice and this permission notice shall be included in all
|
||||||
|
copies or substantial portions of the Software.
|
||||||
|
|
||||||
|
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||||
|
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||||
|
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||||
|
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||||
|
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||||
|
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||||
|
SOFTWARE.
|
||||||
32
README.md
32
README.md
@@ -25,18 +25,38 @@ implementation("de.jeanlucmakiola.floret:core-time")
|
|||||||
```
|
```
|
||||||
|
|
||||||
Gradle's dependency substitution maps `de.jeanlucmakiola.floret:<module>` to the
|
Gradle's dependency substitution maps `de.jeanlucmakiola.floret:<module>` to the
|
||||||
local source module — edit the kit and the app picks it up immediately.
|
local source module — edit the kit and the app picks it up immediately. Android
|
||||||
|
modules need an SDK location for the included build: set `ANDROID_HOME` (CI) or
|
||||||
|
add a gitignored `<app>/floret-kit/local.properties` with `sdk.dir` (locally).
|
||||||
|
See [`docs/ARCHITECTURE.md`](docs/ARCHITECTURE.md) for the full consumption model.
|
||||||
|
|
||||||
## Modules
|
## Modules
|
||||||
|
|
||||||
| Module | What it holds |
|
| Module | Type | What it holds |
|
||||||
|--------|---------------|
|
|--------|------|---------------|
|
||||||
| `core-time` | Pure-Kotlin date/time helpers: local-day windows (`DayWindow`) for smart-list logic and locale/zone-aware display formatting (`Instant.formatDate()` / `formatTime()` / `formatDateTime()`). No Android, no deps. |
|
| `core-time` | JVM | Date/time helpers: `DayWindow` local-day windows, locale/zone-aware `Instant` formatting, `TimeBridge` (millis ↔ `Instant`). No Android, no deps. |
|
||||||
|
| `core-reminders` | JVM | Reminder-lead plumbing: the lead-time unit model (`ReminderUnit`, `decomposeReminderMinutes`), the per-target override model (`ReminderOverride` + `reminderLeadFor` / `applyReminderOverride`) and the stored-format codec (`ReminderOverrideCodec`, separators configurable per app). Each app layers its own DataStore + string labels on top. |
|
||||||
|
| `core-locale` | Android | Per-app language plumbing (`AppLanguage`): read the shipped languages from the app's `res/xml/locales_config.xml`, get/set the applied language via `AppCompatDelegate`, render each language's autonym. The app passes its own `locales_config`; appcompat only, no Compose. |
|
||||||
|
| `core-crash` | Android | Privacy-respecting on-device crash capture + report dialog + issue-tracker hand-off. Parameterized per app via `CrashConfig`. |
|
||||||
|
| `identity` | Android | The M3 Expressive theme factory `FloretExpressiveTheme(…)`, `rememberNavSlideSpec()`, the content transitions (`expandEnter`/`collapseExit`/`itemEnter`/…) and the `predictiveBack` peek. Each app supplies its own seed/palette. |
|
||||||
|
| `components` | Android | Shared Compose vocabulary + recipes: `GroupedSurface`/`GroupedRow`, `InlineTextField`, `OptionCard`, `CollapsingScaffold`, `OptionPicker`, `pastelize()`, `DialogControls`, `OnboardingScaffold`, `OptionalFormSection`, `AboutCard`, `LanguagePickerRow`. |
|
||||||
|
|
||||||
_More modules (identity/theme, components, screen recipes, provider/prefs/reminders/crash plumbing) land as they're extracted from the apps._
|
_The principle: the **mechanics** are shared, the **look** stays per-app. See
|
||||||
|
[`docs/ROADMAP.md`](docs/ROADMAP.md) for what's extracted, deferred, and
|
||||||
|
deliberately not shared._
|
||||||
|
|
||||||
|
## Docs
|
||||||
|
|
||||||
|
See [`docs/`](docs/) — start with [`docs/README.md`](docs/README.md)
|
||||||
|
([ARCHITECTURE](docs/ARCHITECTURE.md), [ROADMAP](docs/ROADMAP.md)) and
|
||||||
|
[`CONTRIBUTING.md`](CONTRIBUTING.md) to add or change a module.
|
||||||
|
[`CHANGELOG.md`](CHANGELOG.md) tracks what landed.
|
||||||
|
>>>>>>> origin/main
|
||||||
|
|
||||||
## Build
|
## Build
|
||||||
|
|
||||||
```sh
|
```sh
|
||||||
./gradlew :core-time:test
|
./gradlew :core-time:test # JVM module tests
|
||||||
|
./gradlew :core-crash:testDebugUnitTest
|
||||||
|
./gradlew build # everything (Android modules need an SDK; see above)
|
||||||
```
|
```
|
||||||
|
|||||||
@@ -33,6 +33,12 @@ kotlin {
|
|||||||
}
|
}
|
||||||
|
|
||||||
dependencies {
|
dependencies {
|
||||||
|
// identity supplies the shared motion (expandEnter/collapseExit) that the
|
||||||
|
// revealable components animate with.
|
||||||
|
implementation(project(":identity"))
|
||||||
|
// core-locale backs the language-picker recipe (AppLanguage).
|
||||||
|
implementation(project(":core-locale"))
|
||||||
|
|
||||||
implementation(platform(libs.androidx.compose.bom))
|
implementation(platform(libs.androidx.compose.bom))
|
||||||
implementation(libs.androidx.ui)
|
implementation(libs.androidx.ui)
|
||||||
implementation(libs.androidx.foundation)
|
implementation(libs.androidx.foundation)
|
||||||
|
|||||||
@@ -3,6 +3,7 @@ package de.jeanlucmakiola.floret.components
|
|||||||
import androidx.compose.foundation.background
|
import androidx.compose.foundation.background
|
||||||
import androidx.compose.foundation.layout.Column
|
import androidx.compose.foundation.layout.Column
|
||||||
import androidx.compose.foundation.layout.ColumnScope
|
import androidx.compose.foundation.layout.ColumnScope
|
||||||
|
import androidx.compose.foundation.layout.RowScope
|
||||||
import androidx.compose.foundation.layout.consumeWindowInsets
|
import androidx.compose.foundation.layout.consumeWindowInsets
|
||||||
import androidx.compose.foundation.layout.fillMaxSize
|
import androidx.compose.foundation.layout.fillMaxSize
|
||||||
import androidx.compose.foundation.layout.imePadding
|
import androidx.compose.foundation.layout.imePadding
|
||||||
@@ -25,6 +26,7 @@ import androidx.compose.ui.Modifier
|
|||||||
import androidx.compose.ui.input.nestedscroll.nestedScroll
|
import androidx.compose.ui.input.nestedscroll.nestedScroll
|
||||||
import androidx.compose.ui.res.stringResource
|
import androidx.compose.ui.res.stringResource
|
||||||
import androidx.compose.ui.unit.dp
|
import androidx.compose.ui.unit.dp
|
||||||
|
import de.jeanlucmakiola.floret.identity.predictiveBack
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The family's collapsing scaffold for settings hubs, sub-screens and the
|
* The family's collapsing scaffold for settings hubs, sub-screens and the
|
||||||
@@ -32,6 +34,11 @@ import androidx.compose.ui.unit.dp
|
|||||||
* button, and a vertically scrolling content column. [content] lays out the
|
* button, and a vertically scrolling content column. [content] lays out the
|
||||||
* connected grouped rows. The back content description uses the kit's `back`
|
* connected grouped rows. The back content description uses the kit's `back`
|
||||||
* string, which an app can override with its own (localized) `back`.
|
* string, which an app can override with its own (localized) `back`.
|
||||||
|
*
|
||||||
|
* Optional extras, all defaulting to the bare scaffold so existing callers are
|
||||||
|
* unchanged: [actions] adds trailing app-bar items; [snackbarHost] hosts
|
||||||
|
* transient messages; [predictiveBack] (off by default) wires the gesture
|
||||||
|
* preview to [onBack] for full-screen surfaces that want it.
|
||||||
*/
|
*/
|
||||||
@OptIn(ExperimentalMaterial3Api::class)
|
@OptIn(ExperimentalMaterial3Api::class)
|
||||||
@Composable
|
@Composable
|
||||||
@@ -39,12 +46,16 @@ fun CollapsingScaffold(
|
|||||||
title: String,
|
title: String,
|
||||||
onBack: () -> Unit,
|
onBack: () -> Unit,
|
||||||
modifier: Modifier = Modifier,
|
modifier: Modifier = Modifier,
|
||||||
|
predictiveBack: Boolean = false,
|
||||||
|
actions: @Composable RowScope.() -> Unit = {},
|
||||||
|
snackbarHost: @Composable () -> Unit = {},
|
||||||
content: @Composable ColumnScope.() -> Unit,
|
content: @Composable ColumnScope.() -> Unit,
|
||||||
) {
|
) {
|
||||||
val scrollBehavior =
|
val scrollBehavior =
|
||||||
TopAppBarDefaults.exitUntilCollapsedScrollBehavior(rememberTopAppBarState())
|
TopAppBarDefaults.exitUntilCollapsedScrollBehavior(rememberTopAppBarState())
|
||||||
Scaffold(
|
Scaffold(
|
||||||
modifier = modifier
|
modifier = modifier
|
||||||
|
.then(if (predictiveBack) Modifier.predictiveBack(onBack = onBack) else Modifier)
|
||||||
.fillMaxSize()
|
.fillMaxSize()
|
||||||
.background(MaterialTheme.colorScheme.surface)
|
.background(MaterialTheme.colorScheme.surface)
|
||||||
.nestedScroll(scrollBehavior.nestedScrollConnection),
|
.nestedScroll(scrollBehavior.nestedScrollConnection),
|
||||||
@@ -59,12 +70,14 @@ fun CollapsingScaffold(
|
|||||||
)
|
)
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
actions = actions,
|
||||||
scrollBehavior = scrollBehavior,
|
scrollBehavior = scrollBehavior,
|
||||||
colors = TopAppBarDefaults.largeTopAppBarColors(
|
colors = TopAppBarDefaults.largeTopAppBarColors(
|
||||||
scrolledContainerColor = MaterialTheme.colorScheme.surface,
|
scrolledContainerColor = MaterialTheme.colorScheme.surface,
|
||||||
),
|
),
|
||||||
)
|
)
|
||||||
},
|
},
|
||||||
|
snackbarHost = snackbarHost,
|
||||||
) { innerPadding ->
|
) { innerPadding ->
|
||||||
Column(
|
Column(
|
||||||
modifier = Modifier
|
modifier = Modifier
|
||||||
|
|||||||
@@ -0,0 +1,95 @@
|
|||||||
|
package de.jeanlucmakiola.floret.components
|
||||||
|
|
||||||
|
import androidx.compose.foundation.layout.Box
|
||||||
|
import androidx.compose.foundation.layout.Row
|
||||||
|
import androidx.compose.foundation.layout.Spacer
|
||||||
|
import androidx.compose.foundation.layout.padding
|
||||||
|
import androidx.compose.foundation.layout.width
|
||||||
|
import androidx.compose.foundation.shape.RoundedCornerShape
|
||||||
|
import androidx.compose.material.icons.Icons
|
||||||
|
import androidx.compose.material.icons.filled.ArrowDropDown
|
||||||
|
import androidx.compose.material3.DropdownMenu
|
||||||
|
import androidx.compose.material3.DropdownMenuItem
|
||||||
|
import androidx.compose.material3.Icon
|
||||||
|
import androidx.compose.material3.MaterialTheme
|
||||||
|
import androidx.compose.material3.Surface
|
||||||
|
import androidx.compose.material3.Text
|
||||||
|
import androidx.compose.runtime.Composable
|
||||||
|
import androidx.compose.runtime.getValue
|
||||||
|
import androidx.compose.runtime.mutableStateOf
|
||||||
|
import androidx.compose.runtime.remember
|
||||||
|
import androidx.compose.runtime.setValue
|
||||||
|
import androidx.compose.ui.Alignment
|
||||||
|
import androidx.compose.ui.Modifier
|
||||||
|
import androidx.compose.ui.text.input.KeyboardType
|
||||||
|
import androidx.compose.ui.unit.dp
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Tonal 3-digit number input shared by the custom reminder/recurrence steps and
|
||||||
|
* the pickers — the family's [InlineTextField] over a tonal surface, so it
|
||||||
|
* matches the card/grouped-row design language (not Material's outlined field).
|
||||||
|
* Non-digit input and anything past three digits is ignored.
|
||||||
|
*/
|
||||||
|
@Composable
|
||||||
|
fun DialogAmountField(
|
||||||
|
value: String,
|
||||||
|
onValueChange: (String) -> Unit,
|
||||||
|
placeholder: String,
|
||||||
|
) {
|
||||||
|
// surfaceContainerHighest — the picker/dialog sits on surfaceContainerHigh,
|
||||||
|
// so anything lower vanishes.
|
||||||
|
Surface(
|
||||||
|
color = MaterialTheme.colorScheme.surfaceContainerHighest,
|
||||||
|
shape = RoundedCornerShape(12.dp),
|
||||||
|
) {
|
||||||
|
InlineTextField(
|
||||||
|
value = value,
|
||||||
|
onValueChange = { text ->
|
||||||
|
if (text.length <= 3 && text.all(Char::isDigit)) onValueChange(text)
|
||||||
|
},
|
||||||
|
placeholder = placeholder,
|
||||||
|
textStyle = MaterialTheme.typography.titleMedium,
|
||||||
|
keyboardType = KeyboardType.Number,
|
||||||
|
modifier = Modifier
|
||||||
|
.width(72.dp)
|
||||||
|
.padding(horizontal = 14.dp, vertical = 12.dp),
|
||||||
|
)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/** Tonal dropdown trigger + menu shared by the custom reminder/recurrence steps and pickers. */
|
||||||
|
@Composable
|
||||||
|
fun DialogUnitDropdown(
|
||||||
|
label: String,
|
||||||
|
entries: List<String>,
|
||||||
|
onPick: (Int) -> Unit,
|
||||||
|
) {
|
||||||
|
var open by remember { mutableStateOf(false) }
|
||||||
|
Box {
|
||||||
|
Surface(
|
||||||
|
color = MaterialTheme.colorScheme.surfaceContainerHighest,
|
||||||
|
shape = RoundedCornerShape(12.dp),
|
||||||
|
onClick = { open = true },
|
||||||
|
) {
|
||||||
|
Row(
|
||||||
|
verticalAlignment = Alignment.CenterVertically,
|
||||||
|
modifier = Modifier.padding(start = 14.dp, end = 8.dp, top = 12.dp, bottom = 12.dp),
|
||||||
|
) {
|
||||||
|
Text(text = label, style = MaterialTheme.typography.titleMedium)
|
||||||
|
Spacer(Modifier.width(4.dp))
|
||||||
|
Icon(imageVector = Icons.Default.ArrowDropDown, contentDescription = null)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
DropdownMenu(expanded = open, onDismissRequest = { open = false }) {
|
||||||
|
entries.forEachIndexed { index, entry ->
|
||||||
|
DropdownMenuItem(
|
||||||
|
text = { Text(entry) },
|
||||||
|
onClick = {
|
||||||
|
onPick(index)
|
||||||
|
open = false
|
||||||
|
},
|
||||||
|
)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,26 @@
|
|||||||
|
package de.jeanlucmakiola.floret.components
|
||||||
|
|
||||||
|
import androidx.compose.animation.AnimatedVisibility
|
||||||
|
import androidx.compose.foundation.layout.Column
|
||||||
|
import androidx.compose.foundation.layout.ColumnScope
|
||||||
|
import androidx.compose.foundation.layout.fillMaxWidth
|
||||||
|
import androidx.compose.runtime.Composable
|
||||||
|
import androidx.compose.ui.Modifier
|
||||||
|
import de.jeanlucmakiola.floret.identity.collapseExit
|
||||||
|
import de.jeanlucmakiola.floret.identity.expandEnter
|
||||||
|
|
||||||
|
/**
|
||||||
|
* A form section that reveals/hides with the family's expand+fade motion — the
|
||||||
|
* shared wrapper for the optional fields behind a "More fields" toggle in the
|
||||||
|
* edit forms. [content] is laid out in a full-width [Column].
|
||||||
|
*/
|
||||||
|
@Composable
|
||||||
|
fun OptionalFormSection(visible: Boolean, content: @Composable ColumnScope.() -> Unit) {
|
||||||
|
AnimatedVisibility(
|
||||||
|
visible = visible,
|
||||||
|
enter = expandEnter(),
|
||||||
|
exit = collapseExit(),
|
||||||
|
) {
|
||||||
|
Column(modifier = Modifier.fillMaxWidth(), content = content)
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -82,6 +82,12 @@ fun GroupedSurface(
|
|||||||
* One row in a grouped list: an M3 [ListItem] over a [GroupedSurface] (the
|
* One row in a grouped list: an M3 [ListItem] over a [GroupedSurface] (the
|
||||||
* tonal, position-shaped, press-morphing family container). Insets 16dp like
|
* tonal, position-shaped, press-morphing family container). Insets 16dp like
|
||||||
* the lists overview.
|
* the lists overview.
|
||||||
|
*
|
||||||
|
* [selected] highlights the row in the secondary container. [dimmed] fades the
|
||||||
|
* headline and summary to the M3 disabled emphasis while leaving the [trailing]
|
||||||
|
* control at full opacity — for rows that are present but switched off.
|
||||||
|
* [container] overrides the row's tonal colour (e.g. a category tint); ignored
|
||||||
|
* when [selected].
|
||||||
*/
|
*/
|
||||||
@OptIn(ExperimentalMaterial3Api::class)
|
@OptIn(ExperimentalMaterial3Api::class)
|
||||||
@Composable
|
@Composable
|
||||||
@@ -91,6 +97,8 @@ fun GroupedRow(
|
|||||||
modifier: Modifier = Modifier,
|
modifier: Modifier = Modifier,
|
||||||
summary: String? = null,
|
summary: String? = null,
|
||||||
selected: Boolean = false,
|
selected: Boolean = false,
|
||||||
|
dimmed: Boolean = false,
|
||||||
|
container: Color? = null,
|
||||||
minHeight: Dp = 72.dp,
|
minHeight: Dp = 72.dp,
|
||||||
leading: @Composable (() -> Unit)? = null,
|
leading: @Composable (() -> Unit)? = null,
|
||||||
trailing: @Composable (() -> Unit)? = null,
|
trailing: @Composable (() -> Unit)? = null,
|
||||||
@@ -104,13 +112,23 @@ fun GroupedRow(
|
|||||||
supportingColor = MaterialTheme.colorScheme.onSecondaryContainer,
|
supportingColor = MaterialTheme.colorScheme.onSecondaryContainer,
|
||||||
trailingIconColor = MaterialTheme.colorScheme.onSecondaryContainer,
|
trailingIconColor = MaterialTheme.colorScheme.onSecondaryContainer,
|
||||||
)
|
)
|
||||||
|
} else if (dimmed) {
|
||||||
|
// M3 disabled emphasis (0.38α) on the text/leading; the trailing control
|
||||||
|
// stays full-opacity so a toggle reads as live even on a faded row.
|
||||||
|
val muted = MaterialTheme.colorScheme.onSurface.copy(alpha = 0.38f)
|
||||||
|
ListItemDefaults.colors(
|
||||||
|
containerColor = Color.Transparent,
|
||||||
|
headlineColor = muted,
|
||||||
|
leadingIconColor = muted,
|
||||||
|
supportingColor = muted,
|
||||||
|
)
|
||||||
} else {
|
} else {
|
||||||
ListItemDefaults.colors(containerColor = Color.Transparent)
|
ListItemDefaults.colors(containerColor = Color.Transparent)
|
||||||
}
|
}
|
||||||
val containerColor = if (selected) {
|
val containerColor = when {
|
||||||
MaterialTheme.colorScheme.secondaryContainer
|
selected -> MaterialTheme.colorScheme.secondaryContainer
|
||||||
} else {
|
container != null -> container
|
||||||
MaterialTheme.colorScheme.surfaceContainerHigh
|
else -> MaterialTheme.colorScheme.surfaceContainerHigh
|
||||||
}
|
}
|
||||||
GroupedSurface(
|
GroupedSurface(
|
||||||
position = position,
|
position = position,
|
||||||
|
|||||||
@@ -0,0 +1,117 @@
|
|||||||
|
package de.jeanlucmakiola.floret.components
|
||||||
|
|
||||||
|
import androidx.compose.foundation.background
|
||||||
|
import androidx.compose.foundation.layout.Arrangement
|
||||||
|
import androidx.compose.foundation.layout.Box
|
||||||
|
import androidx.compose.foundation.layout.Column
|
||||||
|
import androidx.compose.foundation.layout.ColumnScope
|
||||||
|
import androidx.compose.foundation.layout.Row
|
||||||
|
import androidx.compose.foundation.layout.Spacer
|
||||||
|
import androidx.compose.foundation.layout.fillMaxSize
|
||||||
|
import androidx.compose.foundation.layout.fillMaxWidth
|
||||||
|
import androidx.compose.foundation.layout.height
|
||||||
|
import androidx.compose.foundation.layout.navigationBarsPadding
|
||||||
|
import androidx.compose.foundation.layout.padding
|
||||||
|
import androidx.compose.foundation.layout.size
|
||||||
|
import androidx.compose.foundation.layout.width
|
||||||
|
import androidx.compose.foundation.rememberScrollState
|
||||||
|
import androidx.compose.foundation.shape.CircleShape
|
||||||
|
import androidx.compose.foundation.verticalScroll
|
||||||
|
import androidx.compose.material3.Icon
|
||||||
|
import androidx.compose.material3.MaterialTheme
|
||||||
|
import androidx.compose.material3.Scaffold
|
||||||
|
import androidx.compose.material3.Text
|
||||||
|
import androidx.compose.runtime.Composable
|
||||||
|
import androidx.compose.ui.Alignment
|
||||||
|
import androidx.compose.ui.Modifier
|
||||||
|
import androidx.compose.ui.draw.clip
|
||||||
|
import androidx.compose.ui.graphics.vector.ImageVector
|
||||||
|
import androidx.compose.ui.unit.dp
|
||||||
|
|
||||||
|
/** MD3 8dp spacing scale shared by the onboarding screens. */
|
||||||
|
object OnboardingSpace {
|
||||||
|
val xs = 8.dp
|
||||||
|
val sm = 16.dp
|
||||||
|
val md = 24.dp
|
||||||
|
val lg = 32.dp
|
||||||
|
val xl = 48.dp
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Shared onboarding shell: a scrollable, centred [hero] + [body] with the
|
||||||
|
* call(s) to action ([actions]) pinned to the bottom (clear of the navigation
|
||||||
|
* bar). The content slot is centred horizontally; benefit rows fill the width so
|
||||||
|
* their own content left-aligns. Each app supplies its own hero so the apps read
|
||||||
|
* as one family while keeping their own mark.
|
||||||
|
*/
|
||||||
|
@Composable
|
||||||
|
fun OnboardingScaffold(
|
||||||
|
hero: @Composable () -> Unit,
|
||||||
|
actions: @Composable ColumnScope.() -> Unit,
|
||||||
|
modifier: Modifier = Modifier,
|
||||||
|
body: @Composable ColumnScope.() -> Unit,
|
||||||
|
) {
|
||||||
|
Scaffold(
|
||||||
|
modifier = modifier,
|
||||||
|
containerColor = MaterialTheme.colorScheme.surface,
|
||||||
|
bottomBar = {
|
||||||
|
Column(
|
||||||
|
modifier = Modifier
|
||||||
|
.fillMaxWidth()
|
||||||
|
.navigationBarsPadding()
|
||||||
|
.padding(horizontal = OnboardingSpace.md, vertical = OnboardingSpace.sm),
|
||||||
|
horizontalAlignment = Alignment.CenterHorizontally,
|
||||||
|
verticalArrangement = Arrangement.spacedBy(4.dp),
|
||||||
|
content = actions,
|
||||||
|
)
|
||||||
|
},
|
||||||
|
) { innerPadding ->
|
||||||
|
Column(
|
||||||
|
modifier = Modifier
|
||||||
|
.fillMaxSize()
|
||||||
|
.padding(innerPadding)
|
||||||
|
.verticalScroll(rememberScrollState())
|
||||||
|
.padding(horizontal = OnboardingSpace.md),
|
||||||
|
horizontalAlignment = Alignment.CenterHorizontally,
|
||||||
|
) {
|
||||||
|
Spacer(Modifier.height(OnboardingSpace.xl))
|
||||||
|
hero()
|
||||||
|
Spacer(Modifier.height(OnboardingSpace.lg))
|
||||||
|
body()
|
||||||
|
Spacer(Modifier.height(OnboardingSpace.md))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/** One trust point: a tonal icon chip on the left, title + supporting text right. */
|
||||||
|
@Composable
|
||||||
|
fun BenefitRow(icon: ImageVector, title: String, body: String) {
|
||||||
|
Row(
|
||||||
|
modifier = Modifier.fillMaxWidth(),
|
||||||
|
verticalAlignment = Alignment.CenterVertically,
|
||||||
|
) {
|
||||||
|
Box(
|
||||||
|
modifier = Modifier
|
||||||
|
.size(44.dp)
|
||||||
|
.clip(CircleShape)
|
||||||
|
.background(MaterialTheme.colorScheme.secondaryContainer),
|
||||||
|
contentAlignment = Alignment.Center,
|
||||||
|
) {
|
||||||
|
Icon(
|
||||||
|
imageVector = icon,
|
||||||
|
contentDescription = null,
|
||||||
|
tint = MaterialTheme.colorScheme.onSecondaryContainer,
|
||||||
|
modifier = Modifier.size(22.dp),
|
||||||
|
)
|
||||||
|
}
|
||||||
|
Spacer(Modifier.width(OnboardingSpace.sm))
|
||||||
|
Column(modifier = Modifier.weight(1f)) {
|
||||||
|
Text(text = title, style = MaterialTheme.typography.titleMedium)
|
||||||
|
Text(
|
||||||
|
text = body,
|
||||||
|
style = MaterialTheme.typography.bodyMedium,
|
||||||
|
color = MaterialTheme.colorScheme.onSurfaceVariant,
|
||||||
|
)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -1,13 +1,17 @@
|
|||||||
package de.jeanlucmakiola.floret.components
|
package de.jeanlucmakiola.floret.components
|
||||||
|
|
||||||
|
import android.view.WindowManager
|
||||||
import androidx.compose.foundation.layout.ColumnScope
|
import androidx.compose.foundation.layout.ColumnScope
|
||||||
import androidx.compose.material.icons.Icons
|
import androidx.compose.material.icons.Icons
|
||||||
import androidx.compose.material.icons.rounded.Check
|
import androidx.compose.material.icons.rounded.Check
|
||||||
import androidx.compose.material3.Icon
|
import androidx.compose.material3.Icon
|
||||||
import androidx.compose.material3.MaterialTheme
|
import androidx.compose.material3.MaterialTheme
|
||||||
import androidx.compose.runtime.Composable
|
import androidx.compose.runtime.Composable
|
||||||
|
import androidx.compose.runtime.SideEffect
|
||||||
|
import androidx.compose.ui.platform.LocalView
|
||||||
import androidx.compose.ui.window.Dialog
|
import androidx.compose.ui.window.Dialog
|
||||||
import androidx.compose.ui.window.DialogProperties
|
import androidx.compose.ui.window.DialogProperties
|
||||||
|
import androidx.compose.ui.window.DialogWindowProvider
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Full-screen scaffold for selection pickers: a full-bleed [Dialog] that reuses
|
* Full-screen scaffold for selection pickers: a full-bleed [Dialog] that reuses
|
||||||
@@ -19,6 +23,7 @@ import androidx.compose.ui.window.DialogProperties
|
|||||||
fun FullScreenPicker(
|
fun FullScreenPicker(
|
||||||
title: String,
|
title: String,
|
||||||
onDismiss: () -> Unit,
|
onDismiss: () -> Unit,
|
||||||
|
predictiveBack: Boolean = false,
|
||||||
content: @Composable ColumnScope.() -> Unit,
|
content: @Composable ColumnScope.() -> Unit,
|
||||||
) {
|
) {
|
||||||
Dialog(
|
Dialog(
|
||||||
@@ -28,7 +33,21 @@ fun FullScreenPicker(
|
|||||||
decorFitsSystemWindows = false,
|
decorFitsSystemWindows = false,
|
||||||
),
|
),
|
||||||
) {
|
) {
|
||||||
CollapsingScaffold(title = title, onBack = onDismiss, content = content)
|
// The dialog window pans by default when the keyboard opens, which —
|
||||||
|
// combined with the content's own imePadding — leaves a fixed black gap
|
||||||
|
// above the keyboard. Switch it to ADJUST_NOTHING so the window stays
|
||||||
|
// full-screen and imePadding alone lifts the focused field.
|
||||||
|
val view = LocalView.current
|
||||||
|
SideEffect {
|
||||||
|
(view.parent as? DialogWindowProvider)?.window
|
||||||
|
?.setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_ADJUST_NOTHING)
|
||||||
|
}
|
||||||
|
CollapsingScaffold(
|
||||||
|
title = title,
|
||||||
|
onBack = onDismiss,
|
||||||
|
predictiveBack = predictiveBack,
|
||||||
|
content = content,
|
||||||
|
)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -46,8 +65,11 @@ fun <T> OptionPicker(
|
|||||||
onSelect: (T) -> Unit,
|
onSelect: (T) -> Unit,
|
||||||
onDismiss: () -> Unit,
|
onDismiss: () -> Unit,
|
||||||
leading: (@Composable (T) -> Unit)? = null,
|
leading: (@Composable (T) -> Unit)? = null,
|
||||||
|
header: (@Composable ColumnScope.() -> Unit)? = null,
|
||||||
|
predictiveBack: Boolean = false,
|
||||||
) {
|
) {
|
||||||
FullScreenPicker(title = title, onDismiss = onDismiss) {
|
FullScreenPicker(title = title, onDismiss = onDismiss, predictiveBack = predictiveBack) {
|
||||||
|
header?.invoke(this)
|
||||||
options.forEachIndexed { index, option ->
|
options.forEachIndexed { index, option ->
|
||||||
val isSelected = option == selected
|
val isSelected = option == selected
|
||||||
GroupedRow(
|
GroupedRow(
|
||||||
|
|||||||
@@ -0,0 +1,147 @@
|
|||||||
|
package de.jeanlucmakiola.floret.components
|
||||||
|
|
||||||
|
import android.content.Intent
|
||||||
|
import android.net.Uri
|
||||||
|
import androidx.annotation.XmlRes
|
||||||
|
import androidx.compose.foundation.layout.Arrangement
|
||||||
|
import androidx.compose.foundation.layout.Column
|
||||||
|
import androidx.compose.foundation.layout.Row
|
||||||
|
import androidx.compose.foundation.layout.Spacer
|
||||||
|
import androidx.compose.foundation.layout.PaddingValues
|
||||||
|
import androidx.compose.foundation.layout.fillMaxWidth
|
||||||
|
import androidx.compose.foundation.layout.height
|
||||||
|
import androidx.compose.foundation.layout.padding
|
||||||
|
import androidx.compose.foundation.layout.size
|
||||||
|
import androidx.compose.foundation.layout.width
|
||||||
|
import androidx.compose.foundation.shape.RoundedCornerShape
|
||||||
|
import androidx.compose.material3.FilledTonalButton
|
||||||
|
import androidx.compose.material3.Icon
|
||||||
|
import androidx.compose.material3.MaterialTheme
|
||||||
|
import androidx.compose.material3.OutlinedButton
|
||||||
|
import androidx.compose.material3.Surface
|
||||||
|
import androidx.compose.material3.Text
|
||||||
|
import androidx.compose.runtime.Composable
|
||||||
|
import androidx.compose.runtime.getValue
|
||||||
|
import androidx.compose.runtime.mutableStateOf
|
||||||
|
import androidx.compose.runtime.remember
|
||||||
|
import androidx.compose.runtime.setValue
|
||||||
|
import androidx.compose.ui.Alignment
|
||||||
|
import androidx.compose.ui.Modifier
|
||||||
|
import androidx.compose.ui.graphics.vector.ImageVector
|
||||||
|
import androidx.compose.ui.platform.LocalContext
|
||||||
|
import androidx.compose.ui.unit.dp
|
||||||
|
import de.jeanlucmakiola.floret.locale.AppLanguage
|
||||||
|
|
||||||
|
/** A labelled, icon-led external link rendered as a button in [AboutCard]. */
|
||||||
|
data class AboutLink(val icon: ImageVector, val label: String, val url: String)
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The "about this app" card shared across the family: the app's [logo] beside
|
||||||
|
* its [appName] and [author], then [primaryLinks] as a row of equal-width
|
||||||
|
* outlined buttons (e.g. source, licence) and an optional full-width
|
||||||
|
* [highlightLink] tonal button (e.g. donate). Each link opens its URL in the
|
||||||
|
* browser. The app supplies its own logo, strings and links.
|
||||||
|
*/
|
||||||
|
@Composable
|
||||||
|
fun AboutCard(
|
||||||
|
logo: @Composable () -> Unit,
|
||||||
|
appName: String,
|
||||||
|
author: String,
|
||||||
|
primaryLinks: List<AboutLink>,
|
||||||
|
highlightLink: AboutLink? = null,
|
||||||
|
) {
|
||||||
|
val context = LocalContext.current
|
||||||
|
val open = { url: String ->
|
||||||
|
runCatching { context.startActivity(Intent(Intent.ACTION_VIEW, Uri.parse(url))) }
|
||||||
|
Unit
|
||||||
|
}
|
||||||
|
Surface(
|
||||||
|
color = MaterialTheme.colorScheme.surfaceContainerHigh,
|
||||||
|
shape = RoundedCornerShape(24.dp),
|
||||||
|
modifier = Modifier.fillMaxWidth(),
|
||||||
|
) {
|
||||||
|
Column(Modifier.fillMaxWidth().padding(16.dp)) {
|
||||||
|
Row(verticalAlignment = Alignment.CenterVertically) {
|
||||||
|
logo()
|
||||||
|
Spacer(Modifier.width(16.dp))
|
||||||
|
Column(Modifier.weight(1f)) {
|
||||||
|
Text(appName, style = MaterialTheme.typography.titleLarge)
|
||||||
|
Text(
|
||||||
|
text = author,
|
||||||
|
style = MaterialTheme.typography.bodyMedium,
|
||||||
|
color = MaterialTheme.colorScheme.onSurfaceVariant,
|
||||||
|
)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (primaryLinks.isNotEmpty()) {
|
||||||
|
Spacer(Modifier.height(12.dp))
|
||||||
|
Row(Modifier.fillMaxWidth(), horizontalArrangement = Arrangement.spacedBy(8.dp)) {
|
||||||
|
primaryLinks.forEach { link ->
|
||||||
|
OutlinedButton(
|
||||||
|
onClick = { open(link.url) },
|
||||||
|
contentPadding = PaddingValues(horizontal = 12.dp),
|
||||||
|
modifier = Modifier.weight(1f),
|
||||||
|
) {
|
||||||
|
Icon(link.icon, contentDescription = null, modifier = Modifier.size(18.dp))
|
||||||
|
Spacer(Modifier.width(8.dp))
|
||||||
|
Text(link.label)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (highlightLink != null) {
|
||||||
|
Spacer(Modifier.height(8.dp))
|
||||||
|
FilledTonalButton(onClick = { open(highlightLink.url) }, modifier = Modifier.fillMaxWidth()) {
|
||||||
|
Icon(highlightLink.icon, contentDescription = null, modifier = Modifier.size(18.dp))
|
||||||
|
Spacer(Modifier.width(8.dp))
|
||||||
|
Text(highlightLink.label)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* A settings row that opens a full-screen language picker, backed by
|
||||||
|
* [AppLanguage]. The choice is mirrored locally so the row updates instantly
|
||||||
|
* before the activity recreation lands. [autoLabel] names the follow-the-system
|
||||||
|
* option (the `null` tag); [localesConfig] is the app's `res/xml/locales_config`;
|
||||||
|
* [leading] is the row's icon.
|
||||||
|
*/
|
||||||
|
@Composable
|
||||||
|
fun LanguagePickerRow(
|
||||||
|
position: Position,
|
||||||
|
title: String,
|
||||||
|
autoLabel: String,
|
||||||
|
@XmlRes localesConfig: Int,
|
||||||
|
leading: @Composable () -> Unit,
|
||||||
|
) {
|
||||||
|
val context = LocalContext.current
|
||||||
|
var current by remember { mutableStateOf(AppLanguage.currentTag()) }
|
||||||
|
var showDialog by remember { mutableStateOf(false) }
|
||||||
|
// null = follow the system; the rest are BCP-47 tags from locales_config.xml.
|
||||||
|
val options = remember { listOf<String?>(null) + AppLanguage.supportedTags(context, localesConfig) }
|
||||||
|
val label: (String?) -> String = { tag -> tag?.let { AppLanguage.displayName(it) } ?: autoLabel }
|
||||||
|
|
||||||
|
GroupedRow(
|
||||||
|
title = title,
|
||||||
|
summary = label(current),
|
||||||
|
position = position,
|
||||||
|
leading = leading,
|
||||||
|
onClick = { showDialog = true },
|
||||||
|
)
|
||||||
|
|
||||||
|
if (showDialog) {
|
||||||
|
OptionPicker(
|
||||||
|
title = title,
|
||||||
|
options = options,
|
||||||
|
selected = current,
|
||||||
|
label = { label(it) },
|
||||||
|
onSelect = {
|
||||||
|
current = it
|
||||||
|
AppLanguage.apply(it)
|
||||||
|
},
|
||||||
|
onDismiss = { showDialog = false },
|
||||||
|
)
|
||||||
|
}
|
||||||
|
}
|
||||||
46
core-locale/build.gradle.kts
Normal file
46
core-locale/build.gradle.kts
Normal file
@@ -0,0 +1,46 @@
|
|||||||
|
// core-locale — per-app language plumbing shared across the family: read the
|
||||||
|
// shipped languages from res/xml/locales_config.xml, get/set the applied
|
||||||
|
// language via AppCompatDelegate, and render each language's autonym. App-
|
||||||
|
// agnostic — the consuming app passes its own locales_config resource id; no
|
||||||
|
// Compose, no DataStore.
|
||||||
|
plugins {
|
||||||
|
alias(libs.plugins.android.library)
|
||||||
|
}
|
||||||
|
|
||||||
|
android {
|
||||||
|
namespace = "de.jeanlucmakiola.floret.locale"
|
||||||
|
compileSdk = 37
|
||||||
|
|
||||||
|
defaultConfig {
|
||||||
|
minSdk = 29
|
||||||
|
}
|
||||||
|
|
||||||
|
compileOptions {
|
||||||
|
sourceCompatibility = JavaVersion.VERSION_17
|
||||||
|
targetCompatibility = JavaVersion.VERSION_17
|
||||||
|
}
|
||||||
|
|
||||||
|
testOptions {
|
||||||
|
unitTests {
|
||||||
|
all { it.useJUnitPlatform() }
|
||||||
|
isReturnDefaultValues = true
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
kotlin {
|
||||||
|
compilerOptions {
|
||||||
|
jvmTarget = org.jetbrains.kotlin.gradle.dsl.JvmTarget.JVM_17
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
dependencies {
|
||||||
|
// appcompat brings AppCompatDelegate plus its core (LocaleListCompat) and
|
||||||
|
// annotation (XmlRes) transitives.
|
||||||
|
implementation(libs.androidx.appcompat)
|
||||||
|
|
||||||
|
testImplementation(libs.junit.jupiter.api)
|
||||||
|
testRuntimeOnly(libs.junit.jupiter.engine)
|
||||||
|
testRuntimeOnly(libs.junit.platform.launcher)
|
||||||
|
testImplementation(libs.truth)
|
||||||
|
}
|
||||||
@@ -0,0 +1,80 @@
|
|||||||
|
package de.jeanlucmakiola.floret.locale
|
||||||
|
|
||||||
|
import android.content.Context
|
||||||
|
import androidx.annotation.XmlRes
|
||||||
|
import androidx.appcompat.app.AppCompatDelegate
|
||||||
|
import androidx.core.os.LocaleListCompat
|
||||||
|
import org.xmlpull.v1.XmlPullParser
|
||||||
|
import java.util.Locale
|
||||||
|
|
||||||
|
private const val ANDROID_NS = "http://schemas.android.com/apk/res/android"
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Per-app language via AppCompatDelegate, driven by an app's
|
||||||
|
* res/xml/locales_config.xml.
|
||||||
|
*
|
||||||
|
* That file is the single source of truth for which languages an app ships:
|
||||||
|
* dropping in a values-<tag> translation and adding a matching `<locale>` entry
|
||||||
|
* makes the language show up here and in the system per-app-language settings,
|
||||||
|
* with no other code change. The system-default choice is represented as `null`.
|
||||||
|
*
|
||||||
|
* On API 33+ this delegates to the platform per-app-languages API; below that
|
||||||
|
* the appcompat backport persists the choice itself (manifest `autoStoreLocales`
|
||||||
|
* service), so we don't mirror it in DataStore. Setting a locale recreates the
|
||||||
|
* activity, which re-reads the current value for the picker.
|
||||||
|
*/
|
||||||
|
object AppLanguage {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The BCP-47 tags the app ships translations for, in declaration order, as
|
||||||
|
* listed in [localesConfig] (the app's `res/xml/locales_config.xml`). Returns
|
||||||
|
* whatever could be parsed; a missing or malformed config yields an empty
|
||||||
|
* list (the picker then offers only the system-default entry rather than
|
||||||
|
* crashing).
|
||||||
|
*/
|
||||||
|
fun supportedTags(context: Context, @XmlRes localesConfig: Int): List<String> {
|
||||||
|
val tags = mutableListOf<String>()
|
||||||
|
val parser = context.resources.getXml(localesConfig)
|
||||||
|
try {
|
||||||
|
var event = parser.eventType
|
||||||
|
while (event != XmlPullParser.END_DOCUMENT) {
|
||||||
|
if (event == XmlPullParser.START_TAG && parser.name == "locale") {
|
||||||
|
parser.getAttributeValue(ANDROID_NS, "name")?.let(tags::add)
|
||||||
|
}
|
||||||
|
event = parser.next()
|
||||||
|
}
|
||||||
|
} catch (_: Exception) {
|
||||||
|
// Fall back to whatever was parsed before the failure.
|
||||||
|
} finally {
|
||||||
|
parser.close()
|
||||||
|
}
|
||||||
|
return tags
|
||||||
|
}
|
||||||
|
|
||||||
|
/** The applied app language as a BCP-47 tag, or `null` when following the system. */
|
||||||
|
fun currentTag(): String? {
|
||||||
|
val locales = AppCompatDelegate.getApplicationLocales()
|
||||||
|
return if (locales.isEmpty) null else locales[0]?.toLanguageTag()
|
||||||
|
}
|
||||||
|
|
||||||
|
/** Apply a BCP-47 tag, or `null` to follow the system languages. */
|
||||||
|
fun apply(tag: String?) {
|
||||||
|
val locales = if (tag == null) {
|
||||||
|
LocaleListCompat.getEmptyLocaleList()
|
||||||
|
} else {
|
||||||
|
LocaleListCompat.forLanguageTags(tag)
|
||||||
|
}
|
||||||
|
AppCompatDelegate.setApplicationLocales(locales)
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The autonym for a tag — the language's own name in its own script, e.g.
|
||||||
|
* "Deutsch", "English", "Français" — so users find their language regardless
|
||||||
|
* of the current UI language. Capitalised per the language's own rules.
|
||||||
|
*/
|
||||||
|
fun displayName(tag: String): String {
|
||||||
|
val locale = Locale.forLanguageTag(tag)
|
||||||
|
return locale.getDisplayName(locale)
|
||||||
|
.replaceFirstChar { if (it.isLowerCase()) it.titlecase(locale) else it.toString() }
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,20 @@
|
|||||||
|
package de.jeanlucmakiola.floret.locale
|
||||||
|
|
||||||
|
import com.google.common.truth.Truth.assertThat
|
||||||
|
import org.junit.jupiter.api.Test
|
||||||
|
|
||||||
|
class AppLanguageTest {
|
||||||
|
|
||||||
|
@Test
|
||||||
|
fun `autonym is the language's own name`() {
|
||||||
|
assertThat(AppLanguage.displayName("en")).isEqualTo("English")
|
||||||
|
assertThat(AppLanguage.displayName("de")).isEqualTo("Deutsch")
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
fun `autonym is capitalised per the language's own rules`() {
|
||||||
|
// French autonyms are lower-case in CLDR ("français"); the picker shows
|
||||||
|
// them title-cased so each language reads as a proper name.
|
||||||
|
assertThat(AppLanguage.displayName("fr")).isEqualTo("Français")
|
||||||
|
}
|
||||||
|
}
|
||||||
32
core-reminders/build.gradle.kts
Normal file
32
core-reminders/build.gradle.kts
Normal file
@@ -0,0 +1,32 @@
|
|||||||
|
// core-reminders — pure-Kotlin reminder-lead plumbing shared across the family:
|
||||||
|
// the lead-time unit model (ReminderUnit / decomposeReminderMinutes), the
|
||||||
|
// per-target override model (ReminderOverride + resolution helpers) and the
|
||||||
|
// stored-format codec (ReminderOverrideCodec, separators configurable so each
|
||||||
|
// app keeps its on-disk format). No Android, no third-party deps — a plain JVM
|
||||||
|
// library, like core-time; each app layers its own DataStore + string labels on
|
||||||
|
// top.
|
||||||
|
plugins {
|
||||||
|
alias(libs.plugins.kotlin.jvm)
|
||||||
|
}
|
||||||
|
|
||||||
|
java {
|
||||||
|
sourceCompatibility = JavaVersion.VERSION_17
|
||||||
|
targetCompatibility = JavaVersion.VERSION_17
|
||||||
|
}
|
||||||
|
|
||||||
|
kotlin {
|
||||||
|
compilerOptions {
|
||||||
|
jvmTarget = org.jetbrains.kotlin.gradle.dsl.JvmTarget.JVM_17
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
dependencies {
|
||||||
|
testImplementation(libs.junit.jupiter.api)
|
||||||
|
testRuntimeOnly(libs.junit.jupiter.engine)
|
||||||
|
testRuntimeOnly(libs.junit.platform.launcher)
|
||||||
|
testImplementation(libs.truth)
|
||||||
|
}
|
||||||
|
|
||||||
|
tasks.test {
|
||||||
|
useJUnitPlatform()
|
||||||
|
}
|
||||||
@@ -0,0 +1,44 @@
|
|||||||
|
package de.jeanlucmakiola.floret.reminders
|
||||||
|
|
||||||
|
/**
|
||||||
|
* A target's override of the default reminder lead time — a list (Agendula) or a
|
||||||
|
* calendar (Calendula). Targets are keyed by id in the override map; this is the
|
||||||
|
* choice a picker returns.
|
||||||
|
*/
|
||||||
|
sealed interface ReminderOverride {
|
||||||
|
/** No override — the target uses the global default. */
|
||||||
|
data object Inherit : ReminderOverride
|
||||||
|
|
||||||
|
/** Explicit "no reminder" for this target, regardless of the global default. */
|
||||||
|
data object None : ReminderOverride
|
||||||
|
|
||||||
|
/** A specific lead time in minutes before due. */
|
||||||
|
data class Minutes(val minutes: Int) : ReminderOverride
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The lead time for [id]: its override if one is set (a null map value means an
|
||||||
|
* explicit "no reminder"), otherwise the global [default]. A null result means
|
||||||
|
* no reminder. Mirrors the absent/null/value semantics of the override map.
|
||||||
|
*/
|
||||||
|
fun Map<Long, Int?>.reminderLeadFor(id: Long, default: Int): Int? =
|
||||||
|
if (containsKey(id)) this[id] else default
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Read [id]'s entry as a [ReminderOverride]: absent → [Inherit], null → [None],
|
||||||
|
* a value → [Minutes].
|
||||||
|
*/
|
||||||
|
fun Map<Long, Int?>.reminderOverrideFor(id: Long): ReminderOverride = when {
|
||||||
|
!containsKey(id) -> ReminderOverride.Inherit
|
||||||
|
this[id] == null -> ReminderOverride.None
|
||||||
|
else -> ReminderOverride.Minutes(getValue(id)!!)
|
||||||
|
}
|
||||||
|
|
||||||
|
/** Apply [override] for [id] to this override map ([Inherit] removes the key). */
|
||||||
|
fun MutableMap<Long, Int?>.applyReminderOverride(id: Long, override: ReminderOverride) {
|
||||||
|
when (override) {
|
||||||
|
ReminderOverride.Inherit -> remove(id)
|
||||||
|
ReminderOverride.None -> put(id, null)
|
||||||
|
is ReminderOverride.Minutes -> put(id, override.minutes)
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,38 @@
|
|||||||
|
package de.jeanlucmakiola.floret.reminders
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Encodes a per-target reminder-override map (`id → minutes`, where a null value
|
||||||
|
* is an explicit "no reminder") to and from a single stored string, e.g.
|
||||||
|
* `"12:30;7:none"`.
|
||||||
|
*
|
||||||
|
* The separators are configurable because each app already has bytes on disk in
|
||||||
|
* its own dialect — Agendula stores `id:minutes`, Calendula `id=minutes` — and
|
||||||
|
* the stored format must stay stable. Use [DEFAULT] (Agendula's `:` / `;`) or
|
||||||
|
* build a codec with the app's own separators; never change an app's separators
|
||||||
|
* after release without a migration.
|
||||||
|
*/
|
||||||
|
class ReminderOverrideCodec(
|
||||||
|
private val entrySep: String = ";",
|
||||||
|
private val keyValueSep: String = ":",
|
||||||
|
private val noneToken: String = "none",
|
||||||
|
) {
|
||||||
|
/** Decode the stored string into a map (a null value = explicit no-reminder). */
|
||||||
|
fun parse(stored: String?): Map<Long, Int?> {
|
||||||
|
if (stored.isNullOrBlank()) return emptyMap()
|
||||||
|
return stored.split(entrySep).mapNotNull { entry ->
|
||||||
|
val parts = entry.split(keyValueSep).takeIf { it.size == 2 } ?: return@mapNotNull null
|
||||||
|
val id = parts[0].toLongOrNull() ?: return@mapNotNull null
|
||||||
|
val value = if (parts[1] == noneToken) null else parts[1].toIntOrNull() ?: return@mapNotNull null
|
||||||
|
id to value
|
||||||
|
}.toMap()
|
||||||
|
}
|
||||||
|
|
||||||
|
/** Encode the map back to its stored string form. */
|
||||||
|
fun serialize(map: Map<Long, Int?>): String =
|
||||||
|
map.entries.joinToString(entrySep) { (id, minutes) -> "$id$keyValueSep${minutes ?: noneToken}" }
|
||||||
|
|
||||||
|
companion object {
|
||||||
|
/** Agendula's dialect: `id:minutes` entries joined by `;`. */
|
||||||
|
val DEFAULT = ReminderOverrideCodec()
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,31 @@
|
|||||||
|
package de.jeanlucmakiola.floret.reminders
|
||||||
|
|
||||||
|
/** The unit of a custom reminder lead time; [minutesFactor] converts to minutes. */
|
||||||
|
enum class ReminderUnit(val minutesFactor: Int) {
|
||||||
|
Minutes(1),
|
||||||
|
Hours(60),
|
||||||
|
Days(1_440),
|
||||||
|
Weeks(10_080),
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* A reminder lead time broken into a whole [amount] of a [unit] — the seed for a
|
||||||
|
* custom-amount editor. [amount] is null when there is no lead time to show.
|
||||||
|
*/
|
||||||
|
data class ReminderAmount(val amount: Int?, val unit: ReminderUnit)
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Decompose a reminder lead time (minutes before due) into the largest unit that
|
||||||
|
* divides it evenly: 120 → 2 hours, 1 440 → 1 day, 10 080 → 1 week, 90 → 90
|
||||||
|
* minutes. null or a non-positive lead time → no amount, defaulting to minutes.
|
||||||
|
*/
|
||||||
|
fun decomposeReminderMinutes(minutes: Int?): ReminderAmount = when {
|
||||||
|
minutes == null || minutes <= 0 -> ReminderAmount(null, ReminderUnit.Minutes)
|
||||||
|
minutes % ReminderUnit.Weeks.minutesFactor == 0 ->
|
||||||
|
ReminderAmount(minutes / ReminderUnit.Weeks.minutesFactor, ReminderUnit.Weeks)
|
||||||
|
minutes % ReminderUnit.Days.minutesFactor == 0 ->
|
||||||
|
ReminderAmount(minutes / ReminderUnit.Days.minutesFactor, ReminderUnit.Days)
|
||||||
|
minutes % ReminderUnit.Hours.minutesFactor == 0 ->
|
||||||
|
ReminderAmount(minutes / ReminderUnit.Hours.minutesFactor, ReminderUnit.Hours)
|
||||||
|
else -> ReminderAmount(minutes, ReminderUnit.Minutes)
|
||||||
|
}
|
||||||
@@ -0,0 +1,52 @@
|
|||||||
|
package de.jeanlucmakiola.floret.reminders
|
||||||
|
|
||||||
|
import com.google.common.truth.Truth.assertThat
|
||||||
|
import org.junit.jupiter.api.Test
|
||||||
|
|
||||||
|
class ReminderModelTest {
|
||||||
|
|
||||||
|
@Test
|
||||||
|
fun `decompose picks the largest whole unit`() {
|
||||||
|
assertThat(decomposeReminderMinutes(120)).isEqualTo(ReminderAmount(2, ReminderUnit.Hours))
|
||||||
|
assertThat(decomposeReminderMinutes(1_440)).isEqualTo(ReminderAmount(1, ReminderUnit.Days))
|
||||||
|
assertThat(decomposeReminderMinutes(10_080)).isEqualTo(ReminderAmount(1, ReminderUnit.Weeks))
|
||||||
|
assertThat(decomposeReminderMinutes(90)).isEqualTo(ReminderAmount(90, ReminderUnit.Minutes))
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
fun `decompose of null or non-positive has no amount`() {
|
||||||
|
assertThat(decomposeReminderMinutes(null)).isEqualTo(ReminderAmount(null, ReminderUnit.Minutes))
|
||||||
|
assertThat(decomposeReminderMinutes(0)).isEqualTo(ReminderAmount(null, ReminderUnit.Minutes))
|
||||||
|
assertThat(decomposeReminderMinutes(-5)).isEqualTo(ReminderAmount(null, ReminderUnit.Minutes))
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
fun `reminderLeadFor distinguishes absent, explicit-none and a value`() {
|
||||||
|
val map = mapOf(1L to 30, 2L to null)
|
||||||
|
assertThat(map.reminderLeadFor(1L, default = 10)).isEqualTo(30)
|
||||||
|
assertThat(map.reminderLeadFor(2L, default = 10)).isNull() // explicit no-reminder
|
||||||
|
assertThat(map.reminderLeadFor(3L, default = 10)).isEqualTo(10) // inherits default
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
fun `reminderOverrideFor maps absent, null and value to the choice types`() {
|
||||||
|
val map = mapOf(1L to 30, 2L to null)
|
||||||
|
assertThat(map.reminderOverrideFor(1L)).isEqualTo(ReminderOverride.Minutes(30))
|
||||||
|
assertThat(map.reminderOverrideFor(2L)).isEqualTo(ReminderOverride.None)
|
||||||
|
assertThat(map.reminderOverrideFor(3L)).isEqualTo(ReminderOverride.Inherit)
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
fun `applyReminderOverride writes, clears and removes entries`() {
|
||||||
|
val map = mutableMapOf<Long, Int?>()
|
||||||
|
map.applyReminderOverride(1L, ReminderOverride.Minutes(45))
|
||||||
|
assertThat(map).containsExactly(1L, 45)
|
||||||
|
|
||||||
|
map.applyReminderOverride(1L, ReminderOverride.None)
|
||||||
|
assertThat(map[1L]).isNull()
|
||||||
|
assertThat(map).containsKey(1L)
|
||||||
|
|
||||||
|
map.applyReminderOverride(1L, ReminderOverride.Inherit)
|
||||||
|
assertThat(map).doesNotContainKey(1L)
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,52 @@
|
|||||||
|
package de.jeanlucmakiola.floret.reminders
|
||||||
|
|
||||||
|
import com.google.common.truth.Truth.assertThat
|
||||||
|
import org.junit.jupiter.api.Test
|
||||||
|
|
||||||
|
class ReminderOverrideCodecTest {
|
||||||
|
|
||||||
|
private val codec = ReminderOverrideCodec.DEFAULT
|
||||||
|
|
||||||
|
@Test
|
||||||
|
fun `round-trips ids, minutes and explicit none`() {
|
||||||
|
val map = mapOf(12L to 30, 7L to null, 3L to 0)
|
||||||
|
assertThat(codec.parse(codec.serialize(map))).isEqualTo(map)
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
fun `null or blank parses to empty`() {
|
||||||
|
assertThat(codec.parse(null)).isEmpty()
|
||||||
|
assertThat(codec.parse("")).isEmpty()
|
||||||
|
assertThat(codec.parse(" ")).isEmpty()
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
fun `empty map serializes to empty string`() {
|
||||||
|
assertThat(codec.serialize(emptyMap())).isEmpty()
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
fun `none token decodes to a null value`() {
|
||||||
|
assertThat(codec.parse("7:none")).isEqualTo(mapOf(7L to null))
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
fun `garbage entries are dropped, valid ones kept`() {
|
||||||
|
assertThat(codec.parse("12:30;garbage;x:5;9:notnum;4:10"))
|
||||||
|
.isEqualTo(mapOf(12L to 30, 4L to 10))
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
fun `a custom dialect keeps a separate on-disk format`() {
|
||||||
|
// Calendula's dialect: id=minutes entries.
|
||||||
|
val calendula = ReminderOverrideCodec(entrySep = ";", keyValueSep = "=", noneToken = "none")
|
||||||
|
val map = mapOf(12L to 30, 7L to null)
|
||||||
|
val stored = calendula.serialize(map)
|
||||||
|
|
||||||
|
assertThat(stored).contains("12=30")
|
||||||
|
assertThat(stored).contains("7=none")
|
||||||
|
assertThat(calendula.parse(stored)).isEqualTo(map)
|
||||||
|
// The Agendula dialect cannot read Calendula's bytes — the formats are distinct.
|
||||||
|
assertThat(codec.parse(stored)).isEmpty()
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -1,8 +1,13 @@
|
|||||||
package de.jeanlucmakiola.floret.time
|
package de.jeanlucmakiola.floret.time
|
||||||
|
|
||||||
|
import java.time.LocalDate
|
||||||
|
import java.time.LocalTime
|
||||||
import java.time.ZoneId
|
import java.time.ZoneId
|
||||||
|
import java.time.chrono.IsoChronology
|
||||||
import java.time.format.DateTimeFormatter
|
import java.time.format.DateTimeFormatter
|
||||||
|
import java.time.format.DateTimeFormatterBuilder
|
||||||
import java.time.format.FormatStyle
|
import java.time.format.FormatStyle
|
||||||
|
import java.util.Locale
|
||||||
import kotlin.time.Instant
|
import kotlin.time.Instant
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -26,3 +31,28 @@ fun Instant.formatTime(): String = atSystemZone().format(timeFormatter)
|
|||||||
/** Date alone for all-day items, otherwise date + time. */
|
/** Date alone for all-day items, otherwise date + time. */
|
||||||
fun Instant.formatDateTime(allDay: Boolean): String =
|
fun Instant.formatDateTime(allDay: Boolean): String =
|
||||||
if (allDay) formatDate() else "${formatDate()} · ${formatTime()}"
|
if (allDay) formatDate() else "${formatDate()} · ${formatTime()}"
|
||||||
|
|
||||||
|
// The locale's medium date pattern with the year token stripped, e.g. "20 Jun" /
|
||||||
|
// "Jun 20" — derived from the pattern so day/month order still follows the locale.
|
||||||
|
// Built once; locale changes within a running process are rare enough to ignore.
|
||||||
|
private val dateNoYearFormatter: DateTimeFormatter = run {
|
||||||
|
val medium = DateTimeFormatterBuilder.getLocalizedDateTimePattern(
|
||||||
|
FormatStyle.MEDIUM, null, IsoChronology.INSTANCE, Locale.getDefault(),
|
||||||
|
)
|
||||||
|
val noYear = medium.replace(Regex("[\\s.,/'’-]*y+[\\s.,/'’-]*"), " ").trim()
|
||||||
|
DateTimeFormatter.ofPattern(noYear, Locale.getDefault())
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Compact form for dense list rows: the year is dropped when the date is in the
|
||||||
|
* current year, and the time is dropped when it carries no information (all-day
|
||||||
|
* items, or a midnight time). Examples: "20 Jun", "20 Jun · 14:30", "20 Jun 2027".
|
||||||
|
*/
|
||||||
|
fun Instant.formatDateTimeCompact(allDay: Boolean): String {
|
||||||
|
val zdt = atSystemZone()
|
||||||
|
val datePart =
|
||||||
|
if (zdt.year == LocalDate.now(ZoneId.systemDefault()).year) zdt.format(dateNoYearFormatter)
|
||||||
|
else formatDate()
|
||||||
|
return if (allDay || zdt.toLocalTime() == LocalTime.MIDNIGHT) datePart
|
||||||
|
else "$datePart · ${formatTime()}"
|
||||||
|
}
|
||||||
|
|||||||
147
docs/ARCHITECTURE.md
Normal file
147
docs/ARCHITECTURE.md
Normal file
@@ -0,0 +1,147 @@
|
|||||||
|
# floret-kit — architecture
|
||||||
|
|
||||||
|
How the kit is structured, built, and consumed **as it stands today**. For what
|
||||||
|
is and isn't extracted, see [`ROADMAP.md`](ROADMAP.md); for the practical how of
|
||||||
|
adding a module, see [`../CONTRIBUTING.md`](../CONTRIBUTING.md).
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
## 1. The thesis in one sentence
|
||||||
|
|
||||||
|
floret-kit is a Gradle build of small, focused modules — plumbing and a Material
|
||||||
|
3 Expressive design layer — that the family's apps draw from instead of
|
||||||
|
re-deriving the same code. The whole design hangs off one rule:
|
||||||
|
|
||||||
|
> Share the **mechanics**, keep the **look** per-app.
|
||||||
|
|
||||||
|
Theme machinery, content-provider plumbing, and component primitives are shared;
|
||||||
|
seed colours, palettes, identity chips, domain types, and app-specific wording
|
||||||
|
stay in each app. The kit never knows about a specific app's domain.
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
## 2. How an app consumes the kit
|
||||||
|
|
||||||
|
Each app embeds this repo as a **git submodule** and wires it in as a Gradle
|
||||||
|
**composite build**. The kit is therefore always built **from source** — there
|
||||||
|
are no published binaries — which keeps every consuming app reproducible (a
|
||||||
|
requirement for official F-Droid).
|
||||||
|
|
||||||
|
```kotlin
|
||||||
|
// <app>/settings.gradle.kts
|
||||||
|
includeBuild("floret-kit")
|
||||||
|
```
|
||||||
|
```kotlin
|
||||||
|
// <app>/app/build.gradle.kts
|
||||||
|
implementation("de.jeanlucmakiola.floret:core-time")
|
||||||
|
implementation("de.jeanlucmakiola.floret:components")
|
||||||
|
```
|
||||||
|
|
||||||
|
Every module sets `group = "de.jeanlucmakiola.floret"` (via the root build's
|
||||||
|
`subprojects {}`), so Gradle's dependency substitution maps
|
||||||
|
`de.jeanlucmakiola.floret:<module>` to the local `project(":<module>")` of the
|
||||||
|
included build. Editing the kit is picked up by the app's next build with no
|
||||||
|
publish step.
|
||||||
|
|
||||||
|
Each app **pins a specific kit commit** through its submodule gitlink. So a
|
||||||
|
breaking change in the kit can't reach an app until that app deliberately
|
||||||
|
re-pins — apps stay on independent cadences (important while Calendula ships and
|
||||||
|
Agendula moves fast).
|
||||||
|
|
||||||
|
### SDK location for the included build
|
||||||
|
|
||||||
|
An included Android build needs to locate the Android SDK independently of the
|
||||||
|
host app. Provide it via:
|
||||||
|
|
||||||
|
- **CI:** an `ANDROID_HOME` env var (the apps set it at the job level), or
|
||||||
|
- **locally:** a gitignored `<app>/floret-kit/local.properties` with `sdk.dir`.
|
||||||
|
|
||||||
|
Pure-JVM modules (`core-time`) need neither.
|
||||||
|
|
||||||
|
### Submodules in CI / F-Droid
|
||||||
|
|
||||||
|
Consuming apps must check out submodules (`submodules: recursive` in the
|
||||||
|
checkout step) so `floret-kit/` isn't empty. For an app published via **official
|
||||||
|
F-Droid reproducible builds** (Calendula), the fdroiddata recipe additionally
|
||||||
|
needs `submodules: true` on the build entry, and the app's reproducibility guard
|
||||||
|
should scan the submodule's Gradle scripts (see §5).
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
## 3. Module layering
|
||||||
|
|
||||||
|
| Layer | Modules | Notes |
|
||||||
|
|---|---|---|
|
||||||
|
| Plumbing | `core-time` (JVM) | Pure logic; no Android, no deps. |
|
||||||
|
| Plumbing | `core-crash` (Android) | Self-contained subsystem; parameterized per app. |
|
||||||
|
| Design — identity | `identity` (Android) | Theme factory + motion. App supplies seed/palette. |
|
||||||
|
| Design — components | `components` (Android) | Shared Compose primitives. App composes screens. |
|
||||||
|
|
||||||
|
Dependencies between modules are kept minimal: `core-time` depends on nothing in
|
||||||
|
the kit; `identity` and `components` depend only on Compose + (for components)
|
||||||
|
`material-icons-core`. There is no app-level or cross-domain coupling.
|
||||||
|
|
||||||
|
Each module's package is `de.jeanlucmakiola.floret.<area>` (e.g.
|
||||||
|
`de.jeanlucmakiola.floret.components`).
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
## 4. Module types & the build
|
||||||
|
|
||||||
|
Two kinds of module:
|
||||||
|
|
||||||
|
- **JVM library** (`core-time`) — `org.jetbrains.kotlin.jvm`, `jvmTarget = 17`,
|
||||||
|
JUnit 5 + Truth tests. The right home for pure logic; cheapest to build and
|
||||||
|
test.
|
||||||
|
- **Android library** (`core-crash`, `identity`, `components`) —
|
||||||
|
`com.android.library` + the Compose plugin, `compileSdk 37` / `minSdk 29`.
|
||||||
|
|
||||||
|
> **AGP 9.x provides built-in Kotlin compilation.** Android modules therefore
|
||||||
|
> apply only `com.android.library` and `org.jetbrains.kotlin.plugin.compose` —
|
||||||
|
> **not** a separate `org.jetbrains.kotlin.android` plugin (applying it errors).
|
||||||
|
> They set `jvmTarget` directly in a `kotlin { compilerOptions { … } }` block.
|
||||||
|
|
||||||
|
Versions live in [`gradle/libs.versions.toml`](../gradle/libs.versions.toml),
|
||||||
|
kept in lockstep with the apps' catalogs.
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
## 5. Reproducibility rules
|
||||||
|
|
||||||
|
Because consuming apps build the kit from source — and at least one publishes via
|
||||||
|
official F-Droid reproducible builds — the kit follows the same invariants:
|
||||||
|
|
||||||
|
1. **No `foojay` toolchain resolver**, anywhere (not even as a token in a
|
||||||
|
comment). It can fetch a JDK over the network at build time, which the offline
|
||||||
|
F-Droid source scanner rejects. Modules set `jvmTarget` directly instead of
|
||||||
|
using a Java toolchain block that would need a resolver.
|
||||||
|
2. **No published artifacts.** Built from source, pinned by commit.
|
||||||
|
3. Android library modules emit no APK-level metadata of their own (no
|
||||||
|
`buildConfig`); the consuming app controls APK-level reproducibility
|
||||||
|
(`vcsInfo`/`dependenciesInfo`).
|
||||||
|
|
||||||
|
A consuming app's reproducibility guard should scan the submodule's `*.gradle.kts`
|
||||||
|
for the resolver too, since the included build is part of the from-source graph.
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
## 6. The design-divergence contract
|
||||||
|
|
||||||
|
The design modules (`identity`, `components`) carry the family's look, so they
|
||||||
|
extract **mechanics** and leave **identity** to the app:
|
||||||
|
|
||||||
|
- `identity` exposes a theme **factory**; each app passes its own seed-derived
|
||||||
|
`lightScheme`/`darkScheme` and typography. Seed colours and hand-tuned
|
||||||
|
fallbacks are never shared constants.
|
||||||
|
- `components` are app-agnostic primitives. Where two apps differ, the
|
||||||
|
difference is an explicit **parameter** (e.g. `InlineTextField`'s
|
||||||
|
`capitalization`) or a **callback**, never a silently-picked winner. Apps keep
|
||||||
|
their own identity chips/icons and compose their own screens.
|
||||||
|
- **String resources** in the kit are English **fallbacks**; an app overrides
|
||||||
|
them (with its localized values) via resource merge. App-specific wording
|
||||||
|
stays in the app.
|
||||||
|
|
||||||
|
When a primitive is shared by adopting one app's version as canonical (e.g.
|
||||||
|
`components`' `GroupedSurface` follows Agendula's cleaner abstraction), that is a
|
||||||
|
deliberate, signed-off convergence — the other app's surfaces change when it
|
||||||
|
re-pins, reviewable at that point.
|
||||||
26
docs/README.md
Normal file
26
docs/README.md
Normal file
@@ -0,0 +1,26 @@
|
|||||||
|
# floret-kit — documentation
|
||||||
|
|
||||||
|
floret-kit is the shared **Material 3 Expressive design system + plumbing** for
|
||||||
|
the Floret family of Android apps
|
||||||
|
([Calendula](https://gitea.jeanlucmakiola.de/makiolaj/calendula),
|
||||||
|
[Agendula](https://gitea.jeanlucmakiola.de/makiolaj/agendula), and future
|
||||||
|
siblings). It is consumed from source as a git submodule + Gradle composite
|
||||||
|
build. See the top-level [`../README.md`](../README.md) for the pitch.
|
||||||
|
|
||||||
|
## Index
|
||||||
|
|
||||||
|
| Doc | What it covers |
|
||||||
|
|---|---|
|
||||||
|
| [`ARCHITECTURE.md`](ARCHITECTURE.md) | How the kit is built and **consumed** — the module layering, JVM vs Android-library modules, the submodule + composite-build model, and the reproducibility rules. Start here. |
|
||||||
|
| [`ROADMAP.md`](ROADMAP.md) | **What's extracted, what's deferred, and what's deliberately not shared** — the module status and the divergence decisions from the cross-app survey. |
|
||||||
|
| [`../CONTRIBUTING.md`](../CONTRIBUTING.md) | The practical how — adding a module, the no-app-coupling rules, build/test, and how an app adopts the kit. |
|
||||||
|
| [`../CHANGELOG.md`](../CHANGELOG.md) | Keep a Changelog; what each module added. |
|
||||||
|
|
||||||
|
## The one principle
|
||||||
|
|
||||||
|
> Share the **mechanics**, keep the **look** per-app.
|
||||||
|
|
||||||
|
Theme machinery, plumbing, and component primitives are shared; seed colours,
|
||||||
|
palettes, identity chips, and app-specific wording stay in each app. This is what
|
||||||
|
lets the family read as one design language without homogenising apps that are
|
||||||
|
meant to have distinct personalities.
|
||||||
68
docs/ROADMAP.md
Normal file
68
docs/ROADMAP.md
Normal file
@@ -0,0 +1,68 @@
|
|||||||
|
# floret-kit — roadmap
|
||||||
|
|
||||||
|
What's extracted, what's deferred, and what's deliberately **not** shared. The
|
||||||
|
defer/skip calls come from a cross-app survey of both Calendula and Agendula —
|
||||||
|
the guiding rule is to share only what is genuinely common, and to keep
|
||||||
|
divergent or app-specific code where it lives.
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
## Extracted (done)
|
||||||
|
|
||||||
|
| Module | Type | Consumers |
|
||||||
|
|---|---|---|
|
||||||
|
| `core-time` | JVM | Agendula (and Calendula's pending branch) |
|
||||||
|
| `core-crash` | Android | Agendula |
|
||||||
|
| `identity` | Android | Agendula |
|
||||||
|
| `components` | Android | Agendula |
|
||||||
|
|
||||||
|
See [`../CHANGELOG.md`](../CHANGELOG.md) for the contents of each.
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
## Deferred / not yet worth it
|
||||||
|
|
||||||
|
- **`core-prefs`** (DataStore base: `ThemeMode`, `dynamicColor`, the typed
|
||||||
|
wrapper, `toEnum()`) and **`core-di`** (`@IoDispatcher` + provider) — genuinely
|
||||||
|
shared but **low value**: pure relocation, no new capability, the shared
|
||||||
|
surface is tiny once the store name and bindings stay app-local. Sensible to
|
||||||
|
defer until a third app makes the duplication hurt.
|
||||||
|
- **`ReminderFormatting`** (`ReminderUnit` + `reminderLeadTimeLabel` +
|
||||||
|
`decomposeReminder`) — the labels are `@Composable` over app-specific
|
||||||
|
`R.plurals`, and the presets differ per app. Extract later behind a
|
||||||
|
**label/preset callback API**, not before.
|
||||||
|
|
||||||
|
## Deferred — needs migration first
|
||||||
|
|
||||||
|
- **`core-provider`** (the ContentProvider seam: `ColumnReader`, failures,
|
||||||
|
observer→Flow) — the two apps' `ColumnReader`s diverged (Calendula index-based,
|
||||||
|
Agendula name-based + null-safe). True sharing means migrating Calendula to the
|
||||||
|
better name-based design first (~a few hundred LOC), so it waits until Calendula
|
||||||
|
is actively on the kit.
|
||||||
|
|
||||||
|
## Not shared (by design)
|
||||||
|
|
||||||
|
- **A generic Settings scaffold** — the two apps' settings *domains* are too
|
||||||
|
divergent for a config-driven `SettingsScaffold` to stay readable. The win is
|
||||||
|
captured instead at the **component** level (shared `GroupedRow`/section
|
||||||
|
primitives + `CollapsingScaffold` + `OptionPicker`); each app composes its own
|
||||||
|
settings from those.
|
||||||
|
- **`core-reminders`** (unified) — Agendula self-schedules alarms (pull),
|
||||||
|
Calendula is provider-event-driven (push). Opposite architectures over
|
||||||
|
incompatible data models; forcing a shared abstraction would be leaky. A tiny
|
||||||
|
`core-notification` (idempotent channel setup, `POST_NOTIFICATIONS` checks)
|
||||||
|
*might* land later; schedulers stay app-local.
|
||||||
|
- Domain-specific UI (date/time fields tied to a domain, calendar/timeline
|
||||||
|
widgets, recurrence text, domain pickers) and all string wording — these encode
|
||||||
|
each app's model and resist parameterization.
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
## Consumers & cadence
|
||||||
|
|
||||||
|
- **Agendula** consumes the kit on `main` (active development).
|
||||||
|
- **Calendula** (ships via official F-Droid reproducible builds) has a pending
|
||||||
|
adoption branch. Bringing it onto the kit is where the canonical-`GroupedSurface`
|
||||||
|
convergence becomes visible, and where the F-Droid reproducibility checklist
|
||||||
|
(`submodules: true` in the recipe; the repro guard scanning the submodule)
|
||||||
|
applies — see [`ARCHITECTURE.md`](ARCHITECTURE.md) §2 and §5.
|
||||||
@@ -4,6 +4,8 @@
|
|||||||
agp = "9.2.1"
|
agp = "9.2.1"
|
||||||
kotlin = "2.3.21"
|
kotlin = "2.3.21"
|
||||||
coreKtx = "1.19.0"
|
coreKtx = "1.19.0"
|
||||||
|
appcompat = "1.7.1"
|
||||||
|
activityCompose = "1.13.0"
|
||||||
composeBom = "2026.05.01"
|
composeBom = "2026.05.01"
|
||||||
# Material 3 Expressive APIs live in the 1.5 alpha line; pinned to override the BOM.
|
# Material 3 Expressive APIs live in the 1.5 alpha line; pinned to override the BOM.
|
||||||
material3 = "1.5.0-alpha21"
|
material3 = "1.5.0-alpha21"
|
||||||
@@ -13,10 +15,13 @@ truth = "1.4.5"
|
|||||||
|
|
||||||
[libraries]
|
[libraries]
|
||||||
androidx-core-ktx = { group = "androidx.core", name = "core-ktx", version.ref = "coreKtx" }
|
androidx-core-ktx = { group = "androidx.core", name = "core-ktx", version.ref = "coreKtx" }
|
||||||
|
androidx-appcompat = { group = "androidx.appcompat", name = "appcompat", version.ref = "appcompat" }
|
||||||
|
androidx-activity-compose = { group = "androidx.activity", name = "activity-compose", version.ref = "activityCompose" }
|
||||||
androidx-compose-bom = { group = "androidx.compose", name = "compose-bom", version.ref = "composeBom" }
|
androidx-compose-bom = { group = "androidx.compose", name = "compose-bom", version.ref = "composeBom" }
|
||||||
androidx-ui = { group = "androidx.compose.ui", name = "ui" }
|
androidx-ui = { group = "androidx.compose.ui", name = "ui" }
|
||||||
androidx-foundation = { group = "androidx.compose.foundation", name = "foundation" }
|
androidx-foundation = { group = "androidx.compose.foundation", name = "foundation" }
|
||||||
androidx-material3 = { group = "androidx.compose.material3", name = "material3", version.ref = "material3" }
|
androidx-material3 = { group = "androidx.compose.material3", name = "material3", version.ref = "material3" }
|
||||||
|
androidx-animation = { group = "androidx.compose.animation", name = "animation" }
|
||||||
androidx-material-icons-core = { group = "androidx.compose.material", name = "material-icons-core" }
|
androidx-material-icons-core = { group = "androidx.compose.material", name = "material-icons-core" }
|
||||||
|
|
||||||
junit-jupiter-api = { group = "org.junit.jupiter", name = "junit-jupiter-api", version.ref = "junit" }
|
junit-jupiter-api = { group = "org.junit.jupiter", name = "junit-jupiter-api", version.ref = "junit" }
|
||||||
|
|||||||
@@ -36,4 +36,7 @@ dependencies {
|
|||||||
implementation(libs.androidx.ui)
|
implementation(libs.androidx.ui)
|
||||||
implementation(libs.androidx.foundation)
|
implementation(libs.androidx.foundation)
|
||||||
implementation(libs.androidx.material3)
|
implementation(libs.androidx.material3)
|
||||||
|
implementation(libs.androidx.animation)
|
||||||
|
// activity-compose for PredictiveBackHandler + BackEventCompat (the back-gesture peek).
|
||||||
|
implementation(libs.androidx.activity.compose)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,87 @@
|
|||||||
|
package de.jeanlucmakiola.floret.identity
|
||||||
|
|
||||||
|
import android.provider.Settings
|
||||||
|
import androidx.activity.BackEventCompat
|
||||||
|
import androidx.activity.compose.PredictiveBackHandler
|
||||||
|
import androidx.compose.animation.core.Animatable
|
||||||
|
import androidx.compose.animation.core.FastOutSlowInEasing
|
||||||
|
import androidx.compose.foundation.shape.RoundedCornerShape
|
||||||
|
import androidx.compose.runtime.Composable
|
||||||
|
import androidx.compose.runtime.getValue
|
||||||
|
import androidx.compose.runtime.mutableStateOf
|
||||||
|
import androidx.compose.runtime.remember
|
||||||
|
import androidx.compose.runtime.setValue
|
||||||
|
import androidx.compose.ui.Modifier
|
||||||
|
import androidx.compose.ui.graphics.graphicsLayer
|
||||||
|
import androidx.compose.ui.platform.LocalContext
|
||||||
|
import androidx.compose.ui.unit.dp
|
||||||
|
import kotlin.coroutines.cancellation.CancellationException
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Whether the user has asked the system to remove animations (Settings →
|
||||||
|
* Accessibility → "Remove animations", which sets the global animator duration
|
||||||
|
* scale to 0). Compose animations do *not* honour this platform flag on their
|
||||||
|
* own, so the shared motion helpers check it and fall back to no spatial
|
||||||
|
* movement — respecting the vestibular intent of the setting while keeping state
|
||||||
|
* changes legible.
|
||||||
|
*
|
||||||
|
* Read once at composition; the scale changes rarely and only takes full effect
|
||||||
|
* after a process restart anyway.
|
||||||
|
*/
|
||||||
|
@Composable
|
||||||
|
fun rememberReduceMotion(): Boolean {
|
||||||
|
val resolver = LocalContext.current.contentResolver
|
||||||
|
return remember(resolver) {
|
||||||
|
Settings.Global.getFloat(resolver, Settings.Global.ANIMATOR_DURATION_SCALE, 1f) == 0f
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The standard Android predictive-back transform for a full-screen surface: as
|
||||||
|
* the back gesture is dragged, the surface scales toward ~90%, shifts toward the
|
||||||
|
* swiped edge and rounds its corners, previewing what's behind. Completing the
|
||||||
|
* gesture invokes [onBack]; cancelling springs it back.
|
||||||
|
*
|
||||||
|
* A drop-in replacement for a screen's own `BackHandler(onBack)` — register it
|
||||||
|
* once and apply the returned [Modifier] to that screen's root so the preview
|
||||||
|
* respects the same back semantics. Under reduced motion the visual preview is
|
||||||
|
* skipped (the back still works); on API < 34 the system delivers no progress,
|
||||||
|
* so it degrades to a plain back. Shared so the family's apps preview the same
|
||||||
|
* way.
|
||||||
|
*
|
||||||
|
* @param enabled gate the handler — e.g. set false while a screen's own inner
|
||||||
|
* back (a sub-section) should take the gesture instead.
|
||||||
|
*/
|
||||||
|
@Composable
|
||||||
|
fun Modifier.predictiveBack(
|
||||||
|
onBack: () -> Unit,
|
||||||
|
enabled: Boolean = true,
|
||||||
|
reduceMotion: Boolean = rememberReduceMotion(),
|
||||||
|
): Modifier {
|
||||||
|
val progress = remember { Animatable(0f) }
|
||||||
|
var fromLeftEdge by remember { mutableStateOf(true) }
|
||||||
|
|
||||||
|
PredictiveBackHandler(enabled = enabled) { events ->
|
||||||
|
try {
|
||||||
|
events.collect { event ->
|
||||||
|
fromLeftEdge = event.swipeEdge == BackEventCompat.EDGE_LEFT
|
||||||
|
progress.snapTo(FastOutSlowInEasing.transform(event.progress))
|
||||||
|
}
|
||||||
|
onBack()
|
||||||
|
progress.snapTo(0f)
|
||||||
|
} catch (_: CancellationException) {
|
||||||
|
progress.animateTo(0f)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (reduceMotion) return this
|
||||||
|
return this.graphicsLayer {
|
||||||
|
val p = progress.value
|
||||||
|
val scale = 1f - 0.1f * p
|
||||||
|
scaleX = scale
|
||||||
|
scaleY = scale
|
||||||
|
translationX = (if (fromLeftEdge) 1f else -1f) * 24.dp.toPx() * p
|
||||||
|
shape = RoundedCornerShape(32.dp.toPx() * p)
|
||||||
|
clip = p > 0f
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,91 @@
|
|||||||
|
package de.jeanlucmakiola.floret.identity
|
||||||
|
|
||||||
|
import androidx.compose.animation.ContentTransform
|
||||||
|
import androidx.compose.animation.EnterTransition
|
||||||
|
import androidx.compose.animation.ExitTransition
|
||||||
|
import androidx.compose.animation.expandVertically
|
||||||
|
import androidx.compose.animation.fadeIn
|
||||||
|
import androidx.compose.animation.fadeOut
|
||||||
|
import androidx.compose.animation.shrinkVertically
|
||||||
|
import androidx.compose.animation.slideInVertically
|
||||||
|
import androidx.compose.animation.togetherWith
|
||||||
|
import androidx.compose.foundation.lazy.LazyItemScope
|
||||||
|
import androidx.compose.material3.ExperimentalMaterial3ExpressiveApi
|
||||||
|
import androidx.compose.material3.MaterialTheme
|
||||||
|
import androidx.compose.runtime.Composable
|
||||||
|
import androidx.compose.ui.Modifier
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The family's content transitions, driven by the active M3 Expressive motion
|
||||||
|
* scheme so every app reveals, collapses and re-lays-out the same way. Each
|
||||||
|
* honours [rememberReduceMotion]: when the user has asked the system to remove
|
||||||
|
* animations, the spatial movement is dropped and only a quick fade remains.
|
||||||
|
*
|
||||||
|
* Drawn from Calendula's motion helpers; pair [expandEnter] with [collapseExit]
|
||||||
|
* on an `AnimatedVisibility`, use [itemEnter] for content revealed once it
|
||||||
|
* resolves, [animateItemMotion] for `LazyColumn`/`LazyRow` row relayout, and
|
||||||
|
* [fadeThrough] to swap whole blocks with no spatial direction.
|
||||||
|
*/
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Enter for a vertically-revealed section (expandable rows, inline fields):
|
||||||
|
* height grows from the top while fading in; a quick fade only under reduced
|
||||||
|
* motion. Pair with [collapseExit].
|
||||||
|
*/
|
||||||
|
@OptIn(ExperimentalMaterial3ExpressiveApi::class)
|
||||||
|
@Composable
|
||||||
|
fun expandEnter(reduceMotion: Boolean = rememberReduceMotion()): EnterTransition {
|
||||||
|
val fade = fadeIn(MaterialTheme.motionScheme.fastEffectsSpec())
|
||||||
|
return if (reduceMotion) fade else expandVertically(MaterialTheme.motionScheme.fastSpatialSpec()) + fade
|
||||||
|
}
|
||||||
|
|
||||||
|
/** Exit counterpart to [expandEnter]: shrink + fade, or fade only under reduced motion. */
|
||||||
|
@OptIn(ExperimentalMaterial3ExpressiveApi::class)
|
||||||
|
@Composable
|
||||||
|
fun collapseExit(reduceMotion: Boolean = rememberReduceMotion()): ExitTransition {
|
||||||
|
val fade = fadeOut(MaterialTheme.motionScheme.fastEffectsSpec())
|
||||||
|
return if (reduceMotion) fade else shrinkVertically(MaterialTheme.motionScheme.fastSpatialSpec()) + fade
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Enter for content revealed by an `AnimatedContent`/`AnimatedVisibility` (e.g.
|
||||||
|
* results once a query resolves): a gentle rise + fade; fade only under reduced
|
||||||
|
* motion.
|
||||||
|
*/
|
||||||
|
@OptIn(ExperimentalMaterial3ExpressiveApi::class)
|
||||||
|
@Composable
|
||||||
|
fun itemEnter(reduceMotion: Boolean = rememberReduceMotion()): EnterTransition {
|
||||||
|
val fade = fadeIn(MaterialTheme.motionScheme.fastEffectsSpec())
|
||||||
|
return if (reduceMotion) fade else fade + slideInVertically(MaterialTheme.motionScheme.fastSpatialSpec()) { h -> h / 6 }
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* `LazyItemScope.animateItem` wired to the app's motion scheme instead of
|
||||||
|
* Compose's default spring, so list rows fade/relocate consistently. Returns a
|
||||||
|
* bare [Modifier] under reduced motion so rows snap into place. Requires stable
|
||||||
|
* item keys.
|
||||||
|
*/
|
||||||
|
@OptIn(ExperimentalMaterial3ExpressiveApi::class)
|
||||||
|
@Composable
|
||||||
|
fun LazyItemScope.animateItemMotion(reduceMotion: Boolean = rememberReduceMotion()): Modifier =
|
||||||
|
if (reduceMotion) {
|
||||||
|
Modifier
|
||||||
|
} else {
|
||||||
|
Modifier.animateItem(
|
||||||
|
fadeInSpec = MaterialTheme.motionScheme.fastEffectsSpec(),
|
||||||
|
placementSpec = MaterialTheme.motionScheme.fastSpatialSpec(),
|
||||||
|
fadeOutSpec = MaterialTheme.motionScheme.fastEffectsSpec(),
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Cross-fade [ContentTransform] for swapping whole screens or blocks with no
|
||||||
|
* meaningful spatial direction (e.g. onboarding gates). Pure opacity, so it
|
||||||
|
* doubles as its own reduced-motion form.
|
||||||
|
*/
|
||||||
|
@OptIn(ExperimentalMaterial3ExpressiveApi::class)
|
||||||
|
@Composable
|
||||||
|
fun fadeThrough(): ContentTransform {
|
||||||
|
val fade = MaterialTheme.motionScheme.fastEffectsSpec<Float>()
|
||||||
|
return fadeIn(fade).togetherWith(fadeOut(fade))
|
||||||
|
}
|
||||||
@@ -32,6 +32,8 @@ dependencyResolutionManagement {
|
|||||||
rootProject.name = "floret-kit"
|
rootProject.name = "floret-kit"
|
||||||
|
|
||||||
include(":core-time")
|
include(":core-time")
|
||||||
|
include(":core-reminders")
|
||||||
|
include(":core-locale")
|
||||||
include(":core-crash")
|
include(":core-crash")
|
||||||
include(":identity")
|
include(":identity")
|
||||||
include(":components")
|
include(":components")
|
||||||
|
|||||||
Reference in New Issue
Block a user