Modern Apps git
git clone https://git.maproj.org/Modern-Apps.git
main ▾

Modern-Apps.git / calculator / AGENTS.md

AGENTS.md6.8 KiBRenderedCodeRaw
1# AGENTS.md — calculator/ (':calculator')
2
3> Scoped supplement. Global rules in root `AGENTS.md` apply. Stay inside `calculator/` + allowed shared modules. Do not root-scan.
4
5_Install: ./install calculator (dev by default)._
6- Gradle: :calculator / dir: calculator/
7- Package roots present: ui, widget, domain, platform, network, intents
8- Entry files: MainActivity.kt + Route.kt + Navigation.kt (tab destinations: Calculator, Graph, Units)
9- Deps: :library:network, :library:widgets
10- Metadata: metadata_data/calculator.md (present)
11- Rust: no / screenshotTest: yes
12
13## Overview
14**Purpose:** Modern Material You calculator — scientific/basic modes, function graphing with analysis, and a multi-category unit converter with live currency rates.
15**Key features:**
16- Scientific + basic keypad with multi-line expression history: lines stack above the input, tapping a line reuses its result, long-pressing loads its expression for in-place editing (submitting re-runs that line and every line after it in order), and assigned variables show above the input and survive AC
17- Variables instead of an M register: the `var` key opens a dropup listing every assignable single letter with current values; selecting one inserts just its name (variable names are entered only this way — the 2nd layer shifts function/operator keys only and digit keys always emit digits). Variable names are lowercase-only: an uppercase letter in an expression is always a unit symbol, never a variable. Assignable letters are `a`–`z` except the prohibited set in `Expression.prohibitedSingleLetterVariableNames`, derived case-sensitively from the engine's reserved meanings: `e` (Euler), `x`/`t` (graph free variable) and every single-letter unit token/alias in `UnitRegistry.parseTokens` whose exact spelling is lowercase (`c`/`g`/`h`/`k`/`l`/`m`/`s`); today that leaves `a`/`b`/`d`/`f`/`i`/`j`/`n`/`o`/`p`/`q`/`r`/`u`/`v`/`w`/`y`/`z` assignable, so a letter whose only reserved form is capital (`A` ampere, `B` byte, `F` farad, `J` joule, `N` newton, `V` volt, `W` watt) is assignable in lowercase while its capital keeps the unit meaning (`a` the variable vs `2A` two amperes). A prohibited letter keeps its original meaning everywhere and can never be assigned: it is absent from the dropup and a `<letter>=…` line is rejected like other invalid assignments (an uppercase `<Letter>=…` line is likewise never an assignment); a pre-existing assignment to a now-prohibited letter is ignored (its line still evaluates, the variable is dropped) on the next re-evaluation. Picking a name, then the literal `=` key, a value and Enter assigns (`d=5`); a name alone plus Enter reads its value; any other line plus Enter evaluates as a plain expression. Only a leading `<name>=<expr>` line assigns on Enter, and reserved names (`e`, multi-letter `ans`/`pi`/`tau`/`phi`/`theta`, functions, multi-letter unit tokens) can never be assigned. The literal `=` key is a regular key in the top section and never submits; the accent Enter key (filled return icon, bottom-right) submits
18- Graph page: plots functions with root / intercept / min-max / intersection detection
19- Unit converter across many categories incl. live currency rates (`CurrencyApi` over `:library:network`)
20- Home-screen widgets for both calculator and unit converter (`:library:widgets` Glance)
21**Architecture / data-flow:** Single-screen `MainActivity` hosting `ui/` pages (`CalculatorPage`, `GraphPage`, `UnitConverterPage`) over a `platform/` ViewModel + pure `domain/` expression/graph/units helpers; widget receivers in `widget/` share the same logic. Internet is used only for currency rates.
22**Entry points + reading order:** `MainActivity.kt` → `ui/CalculatorPage.kt` → `platform/CalculatorViewModel.kt` + `platform/CalculatorUiContract.kt` → `domain/Expression.kt` / `domain/GraphAnalysis.kt` / `domain/UnitRegistry.kt` → `widget/CalculatorGlanceWidget.kt`.
23**Gotchas:**
24- There is no M memory register and no MC/MR/M+/M- keys; state that must persist across AC lives in assigned variables (`CalculatorTab.variables`), re-derived by re-evaluating history lines in order on every Enter
25- Currency rates are the only network call — everything else must stay offline-safe
26
27## Key files
28### Root — entry
29- com/vayunmathur/calculator/MainActivity.kt
30- com/vayunmathur/calculator/Route.kt + Navigation.kt
31### ui/ — keypad, graph, converter pages
32- com/vayunmathur/calculator/ui/CalculatorPage.kt
33- com/vayunmathur/calculator/ui/CalculatorKeypad.kt
34- com/vayunmathur/calculator/ui/CalculatorVariablePicker.kt — the `var` key + variable dropup
35- com/vayunmathur/calculator/ui/CalculatorDialogs.kt (unit-picker sheet; its absolute-time date/time pickers stay local — see the DIALOG LOCAL EXCEPTION in the file)
36- com/vayunmathur/calculator/ui/GraphPage.kt
37- com/vayunmathur/calculator/ui/UnitConverterPage.kt
38### platform/ — ViewModel + UI contract (domain/ — pure engine)
39- com/vayunmathur/calculator/platform/CalculatorViewModel.kt
40- com/vayunmathur/calculator/platform/CalculatorUiContract.kt — `CalculatorUiState.variables` (name → formatted value), `CalculatorActions.insertVariable`/`evaluate`
41- com/vayunmathur/calculator/platform/CalculatorTab.kt — input/history/variables, multi-line re-evaluation, assignment on Enter
42- com/vayunmathur/calculator/domain/Expression.kt — expression parsing/eval; named variables, `Expression.assignableVariableNames`, `Expression.isVariableNameAvailable`
43- com/vayunmathur/calculator/domain/GraphAnalysis.kt — root/intercept/min-max/intersection
44- com/vayunmathur/calculator/domain/UnitRegistry.kt
45- com/vayunmathur/calculator/network/CurrencyApi.kt — only network call
46- com/vayunmathur/calculator/domain/Formatting.kt
47### intents/ — assistant IPC (validated contracts over the engines above)
48- com/vayunmathur/calculator/intents/CalculatorContract.kt — caps + validation (expression ≤200 ch, result ≤100 ch); evaluation reuses `domain/Expression`, conversion reuses `domain/UnitRegistry` + live currency category
49- com/vayunmathur/calculator/intents/EvaluateIntent.kt — `calculator_evaluate` (scalar result)
50- com/vayunmathur/calculator/intents/ConvertUnitIntent.kt — `calculator_convert_unit` (the app's one network call, live rates, only for currency pairs)
51### widget/ — Glance widgets sharing the same logic
52- com/vayunmathur/calculator/widget/CalculatorGlanceWidget.kt
53- com/vayunmathur/calculator/widget/CalculatorGlanceWidgetReceiver.kt
54- com/vayunmathur/calculator/widget/CalculatorKeyAction.kt
55- com/vayunmathur/calculator/widget/CalculatorWidgetSettingsActivity.kt
56- com/vayunmathur/calculator/widget/UnitsGlanceWidget.kt
57- com/vayunmathur/calculator/widget/UnitsGlanceWidgetReceiver.kt
58- com/vayunmathur/calculator/widget/UnitsWidgetActions.kt
59
60## Verify (this module only)
61```
62./gradlew :calculator:compileDevKotlin
63./gradlew :calculator:lint :calculator:lintVitalRelease :calculator:testDevUnitTest
64./gradlew :calculator:checkMetadata
65```