mirror of
https://github.com/priyanshujain/sanderling.git
synced 2026-10-03 19:47:10 +00:00
WIP: rename sample app to Folio (#20)
* refactor: rename examples/sample-app to examples/folio Directory-level rename and path references in Go tests, bundle-check, top-level README, and getting-started docs. Package declarations, Gradle config, iOS bundle IDs, and class names follow in later commits. * refactor(folio): rename Kotlin package dev.uatu.sample to app.folio Moves source dirs and sqldelight schema from dev/uatu/sample to app/folio, updates package declarations and imports, and switches Android namespace/applicationId, iOS binaryOption bundleId, and sqldelight database packageName to the new identifier. * refactor(folio): rename SampleApplication to FolioApplication Android manifest now points at .FolioApplication with label 'Folio' instead of 'Uatu Sample'. * refactor(folio): set iOS bundle id and display name to Folio bundleIdPrefix + PRODUCT_BUNDLE_IDENTIFIER -> app.folio. CFBundleName + CFBundleDisplayName -> 'Folio'. * refactor(folio): update demo email to [email protected] * refactor(folio): point justfile at app.folio bundle id Updates xcrun simctl launch target, uatu test --bundle-id, and the build/uninstall comments to reference folio instead of sample. * test: update fixture package ids to app.folio Sidecar activity-resolver test and verifier spec-integration XML fixtures referenced the old dev.uatu.sample Android package. Updates them to match the folio app's real package id so the tests stay representative of what the CLI sees on-device. * test(verifier): rename SampleApp identifiers to Folio Renames TestSampleAppSpec* functions, bundleSampleAppSpec helper, and sampleAppHierarchyXML const (now loginHierarchyXML for consistency with the other per-screen fixtures). Updates trailing sample-app mentions in comments and assertion messages. * refactor(folio): rename Gradle/npm/wasm project identifiers to folio settings.gradle.kts rootProject.name, package.json + package-lock.json name, and the WasmJS index.html <title> all still read 'uatu-sample' / 'Uatu Sample'. Realigns them with the Folio brand. * docs(folio): rewrite README title + getting-started bundle id examples/folio/README.md is now titled 'Folio' with the Kotlin source paths corrected to app/folio. Getting-started example uses --bundle-id app.folio. Harness launch message is now generic ('app under test') since uatu-sample-harness is not specific to folio. * chore(folio): drop trailing 'sample' reference in gradle.properties * refactor(folio): rename LoginPage composable to LoginScreen Align with KMP/Android industry convention (NowInAndroid, Cash App, JetBrains samples use Screen, not Page). * refactor(folio): rename HomePage composable to HomeScreen * refactor(folio): rename AddAccountPage composable to AddAccountScreen * refactor(folio): rename LedgerPage composable to LedgerScreen * refactor(folio): rename AddTransactionPage composable to AddTransactionScreen * refactor(folio): split Models.kt into app.folio.data package Account, Transaction (with TxnType), and Session move into their own files under app.folio.data, matching NowInAndroid-style per-type organization. * refactor(folio): move data layer into app.folio.data package Repository, LedgerStore (expect + interface), SqlLedgerStore, WebLedgerStore, DriverFactory (expect + actuals), AndroidLedgerContext, and Snapshot move into app.folio.data. Update all consumer imports. * refactor(folio): move Navigation into app.folio.navigation package Split the former Navigation.kt into Route.kt (sealed interface) and Navigator.kt (singleton). Update consumer imports across screens, App.kt, and FolioApplication. * refactor(folio): move Platform and Format into app.folio.platform Both files carry expect declarations (Platform object, formatDate); grouping them into a dedicated platform package makes the KMP seam obvious and mirrors the structure used by JetBrains samples. * refactor(folio): move login into feature/auth package Create app.folio.feature.auth with LoginScreen + LoginUiState. Inline the former Auth.kt (DEMO_EMAIL, DEMO_PASSWORD, checkCredentials) into LoginScreen since it is the sole caller. * refactor(folio): move HomeScreen into feature/home package * refactor(folio): move account creation into feature/account package AddAccountScreen gets its own AddAccountUiState colocated with the screen, replacing the shared UiState.addAccountError. * refactor(folio): move ledger screens into feature/ledger package LedgerScreen and AddTransactionScreen move into app.folio.feature.ledger with AddTransactionUiState (txnError, txnFormType) colocated. The former catch-all UiState.kt is removed now that each screen owns its state alongside its UI. * refactor(folio): split Theme.kt; move theme and icons to subpackages Theme split into Theme.kt (tokens, layout dims, LedgerTheme) and Type.kt (typography) under app.folio.ui.theme. Icons moves to app.folio.ui.icon. Update every consumer's imports to match. * refactor(folio): split ui components into per-file under ui/component Former Widgets.kt and Components.kt become 10 focused files: AppButton, Card, EmptyState, ErrorText, FieldLabel, Header, IconButton (w/ BackButton), Screen, Segmented, TextInput. Matches NowInAndroid style of one composable per file in a designsystem/component package. * chore(folio): consolidate uatu testing files under uatu/ folder Move spec.ts, package.json, package-lock.json into examples/folio/uatu so all uatu-specific testing artifacts live in one place. runs/ and node_modules/ follow the same convention (both remain gitignored). Update justfile, README, and the two Go consumers (bundle-check tool + verifier/trace tests) that referenced the old path. * refactor(trace): drop folio path in writer test Round-trip only needs a non-empty string; neutralize to keep the library free of folio references. * refactor(sidecar): neutralize ResolveActivity test fixtures Swap app.folio for com.example.app in the fixture strings so the sidecar tests don't reference the example app by name. * refactor(bundle-check): take spec path as argument Previously the tool hardcoded examples/folio/uatu/spec.ts. Accept a positional spec path instead so the tool works for any example and leaves no folio reference in the library surface. * test(verifier): add neutral integration spec and hierarchy fixtures Adds testdata/integration_spec.ts with two routes ("list", "form"), an InputText on text_field, a Tap on primary/secondary_action, a safety property (itemCountNonNegative), and a liveness property (submitEventually). Adds hierarchies_test.go with matching XML fixtures. Constants intentionally go in a _test.go at package root rather than testdata/hierarchies.go because go skips .go files under testdata/. * refactor(verifier): replace folio integration tests with neutral ones Renames bundleFolioSpec -> bundleIntegrationSpec and the three Test* entry points to TestIntegrationSpec*. Uses the synthetic spec and hierarchies added in the previous commit so the library's test suite no longer references examples/folio at all. Folio-specific coverage remains covered by examples/folio/justfile's 'just test' which exercises the real spec on device/emulator. * chore: remove cmd/uatu-sample-harness Not referenced by Makefile, docs, CI, or any script. Duplicates the adb reverse helpers already in cmd/uatu/test_run.go, and its name implies ownership by the sample app which violates the library/ example decoupling. If a bare-protocol debugging tool is later needed it belongs inside cmd/uatu/. * docs(folio): drop Layout section and KMP layout paragraph; fix AVD override syntax The directory-tree Layout section rots faster than the code and duplicates what ls shows for free. The expect/actual paragraph in Stack was the same kind of filler. The README also claimed 'just AVD=Pixel_7 test' but the justfile reads AVD as an env var via env_var_or_default, so the correct invocation is 'AVD=Pixel_7 just test'.
This commit is contained in:
88 files changed
+949
-900
No files matched your search
@@ -0,0 +1,68 @@
|
||||
package app.folio
|
||||
|
||||
import androidx.compose.foundation.background
|
||||
import androidx.compose.foundation.layout.Box
|
||||
import androidx.compose.foundation.layout.Column
|
||||
import androidx.compose.foundation.layout.WindowInsets
|
||||
import androidx.compose.foundation.layout.fillMaxSize
|
||||
import androidx.compose.foundation.layout.safeDrawing
|
||||
import androidx.compose.foundation.layout.windowInsetsPadding
|
||||
import androidx.compose.runtime.Composable
|
||||
import androidx.compose.runtime.LaunchedEffect
|
||||
import androidx.compose.runtime.CompositionLocalProvider
|
||||
import androidx.compose.runtime.collectAsState
|
||||
import androidx.compose.runtime.getValue
|
||||
import androidx.compose.ui.Modifier
|
||||
import app.folio.data.Repository
|
||||
import app.folio.feature.account.AddAccountScreen
|
||||
import app.folio.feature.auth.LoginScreen
|
||||
import app.folio.feature.home.HomeScreen
|
||||
import app.folio.feature.ledger.AddTransactionScreen
|
||||
import app.folio.feature.ledger.LedgerScreen
|
||||
import app.folio.navigation.Navigator
|
||||
import app.folio.navigation.Route
|
||||
import app.folio.ui.theme.LedgerTheme
|
||||
import app.folio.ui.theme.LocalTokens
|
||||
import app.folio.ui.theme.Tokens
|
||||
|
||||
@Composable
|
||||
fun App() {
|
||||
val session by Repository.session.collectAsState()
|
||||
val route by Navigator.current.collectAsState()
|
||||
|
||||
LaunchedEffect(session, route) {
|
||||
if (session == null && route !is Route.Login) {
|
||||
Navigator.replace(Route.Login)
|
||||
} else if (session != null && route is Route.Login) {
|
||||
Navigator.replace(Route.Home)
|
||||
}
|
||||
}
|
||||
|
||||
LedgerTheme {
|
||||
val t = Tokens()
|
||||
CompositionLocalProvider(LocalTokens provides t) {
|
||||
Box(
|
||||
Modifier
|
||||
.fillMaxSize()
|
||||
.background(t.bg)
|
||||
.windowInsetsPadding(WindowInsets.safeDrawing),
|
||||
) {
|
||||
Column(Modifier.fillMaxSize()) {
|
||||
when (val r = route) {
|
||||
Route.Login -> LoginScreen(onLoggedIn = { Navigator.replace(Route.Home) })
|
||||
Route.Home -> HomeScreen(
|
||||
user = session?.user ?: "",
|
||||
onLogout = {
|
||||
Repository.clearSession()
|
||||
Navigator.replace(Route.Login)
|
||||
},
|
||||
)
|
||||
Route.AddAccount -> AddAccountScreen()
|
||||
is Route.Ledger -> LedgerScreen(accountId = r.accountId)
|
||||
is Route.AddTransaction -> AddTransactionScreen(accountId = r.accountId)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,21 @@
|
||||
package app.folio
|
||||
|
||||
import kotlinx.coroutines.flow.MutableStateFlow
|
||||
import kotlinx.coroutines.flow.StateFlow
|
||||
import kotlinx.coroutines.flow.asStateFlow
|
||||
|
||||
// Assumes single-focus: only one input can be focused at a time, so
|
||||
// enter() overwriting is safe. leave() is id-gated so a stale dispose
|
||||
// from a previously-focused field cannot clobber the active focus.
|
||||
object FocusTracker {
|
||||
private val _current = MutableStateFlow<String?>(null)
|
||||
val current: StateFlow<String?> = _current.asStateFlow()
|
||||
|
||||
fun enter(id: String) {
|
||||
_current.value = id
|
||||
}
|
||||
|
||||
fun leave(id: String) {
|
||||
if (_current.value == id) _current.value = null
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,7 @@
|
||||
package app.folio.data
|
||||
|
||||
data class Account(
|
||||
val id: String,
|
||||
val name: String,
|
||||
val createdAt: Long,
|
||||
)
|
||||
@@ -0,0 +1,17 @@
|
||||
package app.folio.data
|
||||
|
||||
import kotlinx.coroutines.flow.StateFlow
|
||||
|
||||
interface LedgerStore {
|
||||
val accounts: StateFlow<List<Account>>
|
||||
val transactions: StateFlow<List<Transaction>>
|
||||
val session: StateFlow<Session?>
|
||||
|
||||
fun accountExistsByName(name: String): Boolean
|
||||
fun insertAccount(id: String, name: String, createdAt: Long)
|
||||
fun insertTxn(id: String, accountId: String, type: TxnType, amount: Long, note: String, createdAt: Long)
|
||||
fun upsertSession(user: String, loggedInAt: Long)
|
||||
fun clearSession()
|
||||
}
|
||||
|
||||
expect fun createLedgerStore(): LedgerStore
|
||||
@@ -0,0 +1,49 @@
|
||||
package app.folio.data
|
||||
|
||||
import app.folio.platform.Platform
|
||||
import kotlinx.coroutines.flow.StateFlow
|
||||
|
||||
object Repository {
|
||||
private var _store: LedgerStore? = null
|
||||
private val store: LedgerStore
|
||||
get() = _store ?: error("Repository not initialized")
|
||||
|
||||
val accounts: StateFlow<List<Account>> get() = store.accounts
|
||||
val transactions: StateFlow<List<Transaction>> get() = store.transactions
|
||||
val session: StateFlow<Session?> get() = store.session
|
||||
|
||||
fun init() {
|
||||
if (_store == null) _store = createLedgerStore()
|
||||
}
|
||||
|
||||
fun createAccount(name: String): Account {
|
||||
val trimmed = name.trim()
|
||||
require(trimmed.isNotEmpty()) { "Name is required" }
|
||||
require(trimmed.length <= 40) { "Name is too long (max 40)" }
|
||||
require(!store.accountExistsByName(trimmed)) { "An account with that name already exists" }
|
||||
val account = Account(id = Platform.makeId(), name = trimmed, createdAt = Platform.now())
|
||||
store.insertAccount(account.id, account.name, account.createdAt)
|
||||
return account
|
||||
}
|
||||
|
||||
fun getAccount(id: String): Account? = accounts.value.firstOrNull { it.id == id }
|
||||
|
||||
fun createTransaction(accountId: String, type: TxnType, amount: Long, note: String): Transaction {
|
||||
require(amount > 0) { "Amount must be greater than zero" }
|
||||
requireNotNull(getAccount(accountId)) { "Account not found" }
|
||||
val txn = Transaction(
|
||||
id = Platform.makeId(),
|
||||
accountId = accountId,
|
||||
type = type,
|
||||
amount = amount,
|
||||
note = note.trim().take(80),
|
||||
createdAt = Platform.now(),
|
||||
)
|
||||
store.insertTxn(txn.id, txn.accountId, txn.type, txn.amount, txn.note, txn.createdAt)
|
||||
return txn
|
||||
}
|
||||
|
||||
fun setSession(user: String) = store.upsertSession(user, Platform.now())
|
||||
|
||||
fun clearSession() = store.clearSession()
|
||||
}
|
||||
@@ -0,0 +1,6 @@
|
||||
package app.folio.data
|
||||
|
||||
data class Session(
|
||||
val user: String,
|
||||
val loggedInAt: Long,
|
||||
)
|
||||
@@ -0,0 +1,12 @@
|
||||
package app.folio.data
|
||||
|
||||
enum class TxnType { credit, debit }
|
||||
|
||||
data class Transaction(
|
||||
val id: String,
|
||||
val accountId: String,
|
||||
val type: TxnType,
|
||||
val amount: Long,
|
||||
val note: String,
|
||||
val createdAt: Long,
|
||||
)
|
||||
+98
@@ -0,0 +1,98 @@
|
||||
package app.folio.feature.account
|
||||
|
||||
import androidx.compose.foundation.layout.Arrangement
|
||||
import androidx.compose.foundation.layout.Column
|
||||
import androidx.compose.foundation.layout.fillMaxWidth
|
||||
import androidx.compose.foundation.layout.padding
|
||||
import androidx.compose.material3.Text
|
||||
import androidx.compose.runtime.Composable
|
||||
import androidx.compose.runtime.DisposableEffect
|
||||
import androidx.compose.runtime.collectAsState
|
||||
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.unit.dp
|
||||
import app.folio.data.Repository
|
||||
import app.folio.navigation.Navigator
|
||||
import app.folio.navigation.Route
|
||||
import app.folio.ui.BackHandler
|
||||
import app.folio.ui.component.AppButton
|
||||
import app.folio.ui.component.BackButton
|
||||
import app.folio.ui.component.ButtonStyle
|
||||
import app.folio.ui.component.ErrorText
|
||||
import app.folio.ui.component.FieldLabel
|
||||
import app.folio.ui.component.Header
|
||||
import app.folio.ui.component.Screen
|
||||
import app.folio.ui.component.TextInput
|
||||
import app.folio.ui.theme.LocalTokens
|
||||
import app.folio.ui.theme.Type
|
||||
|
||||
@Composable
|
||||
fun AddAccountScreen() {
|
||||
val t = LocalTokens.current
|
||||
var name by remember { mutableStateOf("") }
|
||||
val err by AddAccountUiState.addAccountError.collectAsState()
|
||||
|
||||
BackHandler { Navigator.back(Route.Home) }
|
||||
|
||||
DisposableEffect(Unit) {
|
||||
onDispose { AddAccountUiState.addAccountError.value = "" }
|
||||
}
|
||||
|
||||
fun submit() {
|
||||
val trimmed = name.trim()
|
||||
if (trimmed.isEmpty()) {
|
||||
AddAccountUiState.addAccountError.value = "Account name is required"; return
|
||||
}
|
||||
if (trimmed.length > 40) {
|
||||
AddAccountUiState.addAccountError.value = "Name is too long (max 40 characters)"; return
|
||||
}
|
||||
try {
|
||||
Repository.createAccount(trimmed)
|
||||
AddAccountUiState.addAccountError.value = ""
|
||||
Navigator.replace(Route.Home)
|
||||
} catch (e: IllegalArgumentException) {
|
||||
AddAccountUiState.addAccountError.value = e.message ?: "Could not create account"
|
||||
}
|
||||
}
|
||||
|
||||
Screen(
|
||||
header = {
|
||||
Header(title = "New account", left = { BackButton(onClick = { Navigator.back(Route.Home) }) })
|
||||
},
|
||||
footer = {
|
||||
AppButton(
|
||||
text = "Create account",
|
||||
onClick = ::submit,
|
||||
style = ButtonStyle.Primary,
|
||||
enabled = name.trim().isNotEmpty(),
|
||||
description = "add_account_submit",
|
||||
)
|
||||
},
|
||||
) {
|
||||
Column(
|
||||
modifier = Modifier.fillMaxWidth().padding(vertical = 8.dp),
|
||||
verticalArrangement = Arrangement.spacedBy(14.dp),
|
||||
) {
|
||||
Column(verticalArrangement = Arrangement.spacedBy(6.dp)) {
|
||||
FieldLabel("Account name")
|
||||
TextInput(
|
||||
value = name,
|
||||
onChange = { name = it; AddAccountUiState.addAccountError.value = "" },
|
||||
placeholder = "e.g. Checking",
|
||||
invalid = err.isNotEmpty(),
|
||||
label = "Account name",
|
||||
description = "account_name_field",
|
||||
)
|
||||
}
|
||||
ErrorText(err)
|
||||
Text(
|
||||
"Use a short, recognizable name. You can create as many accounts as you need.",
|
||||
style = Type.caption,
|
||||
color = t.textMuted,
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
+7
@@ -0,0 +1,7 @@
|
||||
package app.folio.feature.account
|
||||
|
||||
import kotlinx.coroutines.flow.MutableStateFlow
|
||||
|
||||
object AddAccountUiState {
|
||||
val addAccountError = MutableStateFlow("")
|
||||
}
|
||||
+108
@@ -0,0 +1,108 @@
|
||||
package app.folio.feature.auth
|
||||
|
||||
import androidx.compose.foundation.layout.Arrangement
|
||||
import androidx.compose.foundation.layout.Column
|
||||
import androidx.compose.foundation.layout.Spacer
|
||||
import androidx.compose.foundation.layout.fillMaxWidth
|
||||
import androidx.compose.foundation.layout.height
|
||||
import androidx.compose.foundation.layout.padding
|
||||
import androidx.compose.material3.Text
|
||||
import androidx.compose.runtime.Composable
|
||||
import androidx.compose.runtime.DisposableEffect
|
||||
import androidx.compose.runtime.collectAsState
|
||||
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.text.input.KeyboardType
|
||||
import androidx.compose.ui.unit.dp
|
||||
import app.folio.data.Repository
|
||||
import app.folio.ui.component.AppButton
|
||||
import app.folio.ui.component.ButtonStyle
|
||||
import app.folio.ui.component.Card
|
||||
import app.folio.ui.component.ErrorText
|
||||
import app.folio.ui.component.FieldLabel
|
||||
import app.folio.ui.component.Screen
|
||||
import app.folio.ui.component.TextInput
|
||||
import app.folio.ui.theme.LocalTokens
|
||||
import app.folio.ui.theme.Type
|
||||
|
||||
const val DEMO_EMAIL = "[email protected]"
|
||||
const val DEMO_PASSWORD = "ledger123"
|
||||
|
||||
private fun checkCredentials(email: String, password: String): Boolean {
|
||||
return email.trim().lowercase() == DEMO_EMAIL && password == DEMO_PASSWORD
|
||||
}
|
||||
|
||||
@Composable
|
||||
fun LoginScreen(onLoggedIn: (String) -> Unit) {
|
||||
val t = LocalTokens.current
|
||||
var email by remember { mutableStateOf("") }
|
||||
var password by remember { mutableStateOf("") }
|
||||
val err by LoginUiState.loginError.collectAsState()
|
||||
|
||||
DisposableEffect(Unit) {
|
||||
onDispose { LoginUiState.loginError.value = "" }
|
||||
}
|
||||
|
||||
fun submit() {
|
||||
if (email.isBlank() || password.isEmpty()) {
|
||||
LoginUiState.loginError.value = "Enter email and password"; return
|
||||
}
|
||||
if (!checkCredentials(email, password)) {
|
||||
LoginUiState.loginError.value = "Invalid email or password"; return
|
||||
}
|
||||
LoginUiState.loginError.value = ""
|
||||
val user = email.trim().lowercase()
|
||||
Repository.setSession(user)
|
||||
onLoggedIn(user)
|
||||
}
|
||||
|
||||
Screen {
|
||||
Spacer(Modifier.height(16.dp))
|
||||
Column(
|
||||
modifier = Modifier.fillMaxWidth().padding(vertical = 8.dp),
|
||||
verticalArrangement = Arrangement.spacedBy(14.dp),
|
||||
) {
|
||||
Column(verticalArrangement = Arrangement.spacedBy(6.dp)) {
|
||||
FieldLabel("Email")
|
||||
TextInput(
|
||||
value = email,
|
||||
onChange = { email = it; LoginUiState.loginError.value = "" },
|
||||
placeholder = DEMO_EMAIL,
|
||||
invalid = err.isNotEmpty(),
|
||||
keyboardType = KeyboardType.Email,
|
||||
label = "Email",
|
||||
description = "login_email",
|
||||
)
|
||||
}
|
||||
Column(verticalArrangement = Arrangement.spacedBy(6.dp)) {
|
||||
FieldLabel("Password")
|
||||
TextInput(
|
||||
value = password,
|
||||
onChange = { password = it; LoginUiState.loginError.value = "" },
|
||||
placeholder = "••••••••",
|
||||
password = true,
|
||||
invalid = err.isNotEmpty(),
|
||||
keyboardType = KeyboardType.Password,
|
||||
label = "Password",
|
||||
description = "login_password",
|
||||
)
|
||||
}
|
||||
ErrorText(err)
|
||||
AppButton(
|
||||
text = "Sign in",
|
||||
onClick = ::submit,
|
||||
style = ButtonStyle.Primary,
|
||||
description = "login_submit",
|
||||
)
|
||||
Spacer(Modifier.height(4.dp))
|
||||
Card(dashed = true) {
|
||||
Text("Demo credentials", style = Type.caption, color = t.textMuted)
|
||||
Text("email: $DEMO_EMAIL", style = Type.body, color = t.text)
|
||||
Text("password: $DEMO_PASSWORD", style = Type.body, color = t.text)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,7 @@
|
||||
package app.folio.feature.auth
|
||||
|
||||
import kotlinx.coroutines.flow.MutableStateFlow
|
||||
|
||||
object LoginUiState {
|
||||
val loginError = MutableStateFlow("")
|
||||
}
|
||||
@@ -0,0 +1,151 @@
|
||||
package app.folio.feature.home
|
||||
|
||||
import androidx.compose.foundation.background
|
||||
import androidx.compose.foundation.border
|
||||
import androidx.compose.foundation.clickable
|
||||
import androidx.compose.foundation.layout.Arrangement
|
||||
import androidx.compose.foundation.layout.Box
|
||||
import androidx.compose.foundation.layout.Column
|
||||
import androidx.compose.foundation.layout.Row
|
||||
import androidx.compose.foundation.layout.fillMaxWidth
|
||||
import androidx.compose.foundation.layout.padding
|
||||
import androidx.compose.foundation.layout.size
|
||||
import androidx.compose.foundation.shape.RoundedCornerShape
|
||||
import androidx.compose.material3.Text
|
||||
import androidx.compose.runtime.Composable
|
||||
import androidx.compose.runtime.getValue
|
||||
import androidx.compose.ui.Alignment
|
||||
import androidx.compose.ui.Modifier
|
||||
import androidx.compose.ui.draw.clip
|
||||
import androidx.compose.ui.semantics.Role
|
||||
import androidx.compose.ui.semantics.contentDescription
|
||||
import androidx.compose.ui.semantics.semantics
|
||||
import androidx.compose.ui.text.style.TextOverflow
|
||||
import androidx.compose.ui.unit.dp
|
||||
import androidx.compose.runtime.collectAsState
|
||||
import app.folio.data.Repository
|
||||
import app.folio.navigation.Navigator
|
||||
import app.folio.navigation.Route
|
||||
import app.folio.platform.balanceOf
|
||||
import app.folio.platform.formatCents
|
||||
import app.folio.platform.initialsOf
|
||||
import app.folio.platform.signedAmount
|
||||
import app.folio.ui.component.AppButton
|
||||
import app.folio.ui.component.ButtonStyle
|
||||
import app.folio.ui.component.EmptyState
|
||||
import app.folio.ui.component.Header
|
||||
import app.folio.ui.component.IconButton
|
||||
import app.folio.ui.component.Screen
|
||||
import app.folio.ui.icon.Icons
|
||||
import app.folio.ui.theme.LocalTokens
|
||||
import app.folio.ui.theme.RadiusLg
|
||||
import app.folio.ui.theme.Type
|
||||
|
||||
@Composable
|
||||
fun HomeScreen(user: String, onLogout: () -> Unit) {
|
||||
val t = LocalTokens.current
|
||||
val accounts by Repository.accounts.collectAsState()
|
||||
val txns by Repository.transactions.collectAsState()
|
||||
val total = balanceOf(txns)
|
||||
|
||||
Screen(
|
||||
header = {
|
||||
Header(
|
||||
title = "Accounts",
|
||||
subtitle = user,
|
||||
right = {
|
||||
IconButton(onClick = onLogout, description = "logout_button", icon = Icons.Logout)
|
||||
},
|
||||
)
|
||||
},
|
||||
footer = {
|
||||
Row(verticalAlignment = Alignment.Bottom) {
|
||||
Column {
|
||||
Text("TOTAL BALANCE", style = Type.label, color = t.textMuted)
|
||||
Text(formatCents(total), style = Type.balance, color = t.text)
|
||||
}
|
||||
Box(Modifier.weight(1f))
|
||||
Text(
|
||||
"${accounts.size} account${if (accounts.size == 1) "" else "s"}",
|
||||
style = Type.caption,
|
||||
color = t.textFaint,
|
||||
)
|
||||
}
|
||||
AppButton(
|
||||
text = "+ Add account",
|
||||
onClick = { Navigator.push(Route.AddAccount) },
|
||||
style = ButtonStyle.Primary,
|
||||
description = "add_account_button",
|
||||
)
|
||||
},
|
||||
) {
|
||||
if (accounts.isEmpty()) {
|
||||
EmptyState(
|
||||
title = "No accounts yet",
|
||||
subtitle = "Create your first account to start tracking transactions.",
|
||||
icon = Icons.Bank,
|
||||
)
|
||||
} else {
|
||||
Column(verticalArrangement = Arrangement.spacedBy(10.dp)) {
|
||||
accounts.forEach { a ->
|
||||
val bal = txns.filter { it.accountId == a.id }.sumOf { signedAmount(it) }
|
||||
val count = txns.count { it.accountId == a.id }
|
||||
AccountCard(
|
||||
id = a.id,
|
||||
name = a.name,
|
||||
initials = initialsOf(a.name),
|
||||
count = count,
|
||||
balance = bal,
|
||||
onClick = { Navigator.push(Route.Ledger(a.id)) },
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Composable
|
||||
private fun AccountCard(
|
||||
id: String,
|
||||
name: String,
|
||||
initials: String,
|
||||
count: Int,
|
||||
balance: Long,
|
||||
onClick: () -> Unit,
|
||||
) {
|
||||
val t = LocalTokens.current
|
||||
val txnLabel = if (count == 1) "1 transaction" else "$count transactions"
|
||||
Row(
|
||||
modifier = Modifier
|
||||
.fillMaxWidth()
|
||||
.clip(RoundedCornerShape(RadiusLg))
|
||||
.background(t.surface)
|
||||
.border(1.dp, t.border, RoundedCornerShape(RadiusLg))
|
||||
.semantics(mergeDescendants = true) { contentDescription = "account_card:$id" }
|
||||
.clickable(role = Role.Button, onClick = onClick)
|
||||
.padding(16.dp),
|
||||
verticalAlignment = Alignment.CenterVertically,
|
||||
horizontalArrangement = Arrangement.spacedBy(14.dp),
|
||||
) {
|
||||
Box(
|
||||
modifier = Modifier
|
||||
.size(40.dp)
|
||||
.clip(RoundedCornerShape(12.dp))
|
||||
.background(t.surface3),
|
||||
contentAlignment = Alignment.Center,
|
||||
) {
|
||||
Text(initials, style = Type.bodyStrong, color = t.text)
|
||||
}
|
||||
Column(Modifier.weight(1f)) {
|
||||
Text(
|
||||
name,
|
||||
style = Type.bodyStrong,
|
||||
color = t.text,
|
||||
maxLines = 1,
|
||||
overflow = TextOverflow.Ellipsis,
|
||||
)
|
||||
Text(txnLabel, style = Type.caption, color = t.textMuted)
|
||||
}
|
||||
Text(formatCents(balance), style = Type.bodyStrong, color = t.text)
|
||||
}
|
||||
}
|
||||
+158
@@ -0,0 +1,158 @@
|
||||
package app.folio.feature.ledger
|
||||
|
||||
import androidx.compose.foundation.layout.Arrangement
|
||||
import androidx.compose.foundation.layout.Column
|
||||
import androidx.compose.foundation.layout.fillMaxWidth
|
||||
import androidx.compose.foundation.layout.padding
|
||||
import androidx.compose.runtime.Composable
|
||||
import androidx.compose.runtime.DisposableEffect
|
||||
import androidx.compose.runtime.getValue
|
||||
import androidx.compose.runtime.collectAsState
|
||||
import androidx.compose.runtime.mutableStateOf
|
||||
import androidx.compose.runtime.remember
|
||||
import androidx.compose.runtime.setValue
|
||||
import androidx.compose.ui.Modifier
|
||||
import androidx.compose.ui.text.input.KeyboardType
|
||||
import androidx.compose.ui.text.style.TextAlign
|
||||
import androidx.compose.ui.unit.dp
|
||||
import app.folio.data.Repository
|
||||
import app.folio.data.TxnType
|
||||
import app.folio.navigation.Navigator
|
||||
import app.folio.navigation.Route
|
||||
import app.folio.platform.parseCents
|
||||
import app.folio.ui.BackHandler
|
||||
import app.folio.ui.component.AppButton
|
||||
import app.folio.ui.component.BackButton
|
||||
import app.folio.ui.component.ButtonStyle
|
||||
import app.folio.ui.component.EmptyState
|
||||
import app.folio.ui.component.ErrorText
|
||||
import app.folio.ui.component.FieldLabel
|
||||
import app.folio.ui.component.Header
|
||||
import app.folio.ui.component.Screen
|
||||
import app.folio.ui.component.Segmented
|
||||
import app.folio.ui.component.TextInput
|
||||
import app.folio.ui.theme.Type
|
||||
|
||||
private val AMOUNT_REGEX = Regex("""^\d*(\.\d{0,2})?$""")
|
||||
|
||||
@Composable
|
||||
fun AddTransactionScreen(accountId: String) {
|
||||
val accounts by Repository.accounts.collectAsState()
|
||||
val account = accounts.firstOrNull { it.id == accountId }
|
||||
|
||||
BackHandler { Navigator.back(Route.Ledger(accountId)) }
|
||||
|
||||
if (account == null) {
|
||||
Screen(
|
||||
header = {
|
||||
Header(title = "Add transaction", left = { BackButton { Navigator.back(Route.Home) } })
|
||||
},
|
||||
) {
|
||||
EmptyState(title = "Account not found", subtitle = "")
|
||||
AppButton(
|
||||
text = "Back to accounts",
|
||||
onClick = { Navigator.replace(Route.Home) },
|
||||
style = ButtonStyle.Secondary,
|
||||
)
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
var type by remember { mutableStateOf(TxnType.credit) }
|
||||
var amount by remember { mutableStateOf("") }
|
||||
var note by remember { mutableStateOf("") }
|
||||
val err by AddTransactionUiState.txnError.collectAsState()
|
||||
|
||||
DisposableEffect(type) {
|
||||
AddTransactionUiState.txnFormType.value = if (type == TxnType.credit) "credit" else "debit"
|
||||
onDispose { AddTransactionUiState.txnFormType.value = null }
|
||||
}
|
||||
|
||||
DisposableEffect(Unit) {
|
||||
onDispose { AddTransactionUiState.txnError.value = "" }
|
||||
}
|
||||
|
||||
fun submit() {
|
||||
val cents = parseCents(amount)
|
||||
if (cents == null) {
|
||||
AddTransactionUiState.txnError.value = "Enter a valid amount (e.g. 12.34)"; return
|
||||
}
|
||||
if (cents <= 0) {
|
||||
AddTransactionUiState.txnError.value = "Amount must be greater than zero"; return
|
||||
}
|
||||
try {
|
||||
Repository.createTransaction(accountId, type, cents, note)
|
||||
AddTransactionUiState.txnError.value = ""
|
||||
Navigator.back(Route.Home)
|
||||
} catch (e: IllegalArgumentException) {
|
||||
AddTransactionUiState.txnError.value = e.message ?: "Could not save transaction"
|
||||
}
|
||||
}
|
||||
|
||||
Screen(
|
||||
header = {
|
||||
Header(
|
||||
title = "Add transaction",
|
||||
subtitle = account.name,
|
||||
left = { BackButton { Navigator.back(Route.Ledger(accountId)) } },
|
||||
)
|
||||
},
|
||||
footer = {
|
||||
AppButton(
|
||||
text = if (type == TxnType.credit) "Add credit" else "Add debit",
|
||||
onClick = ::submit,
|
||||
style = ButtonStyle.Primary,
|
||||
enabled = amount.isNotBlank(),
|
||||
description = "txn_submit",
|
||||
)
|
||||
},
|
||||
) {
|
||||
Column(
|
||||
modifier = Modifier.fillMaxWidth().padding(vertical = 8.dp),
|
||||
verticalArrangement = Arrangement.spacedBy(16.dp),
|
||||
) {
|
||||
Segmented(
|
||||
selected = if (type == TxnType.credit) 0 else 1,
|
||||
labels = listOf("Credit", "Debit"),
|
||||
onSelect = {
|
||||
AddTransactionUiState.txnError.value = ""
|
||||
type = if (it == 0) TxnType.credit else TxnType.debit
|
||||
},
|
||||
descriptions = listOf("txn_credit", "txn_debit"),
|
||||
)
|
||||
Column(verticalArrangement = Arrangement.spacedBy(6.dp)) {
|
||||
FieldLabel("Amount")
|
||||
TextInput(
|
||||
value = amount,
|
||||
onChange = {
|
||||
AddTransactionUiState.txnError.value = ""
|
||||
if (AMOUNT_REGEX.matches(it) || it.isEmpty()) {
|
||||
amount = it
|
||||
}
|
||||
},
|
||||
placeholder = "0.00",
|
||||
invalid = err.isNotEmpty(),
|
||||
keyboardType = KeyboardType.Decimal,
|
||||
textAlign = TextAlign.Center,
|
||||
textStyle = Type.amountInput,
|
||||
label = "Amount",
|
||||
description = "txn_amount",
|
||||
)
|
||||
}
|
||||
Column(verticalArrangement = Arrangement.spacedBy(6.dp)) {
|
||||
FieldLabel("Note (optional)")
|
||||
TextInput(
|
||||
value = note,
|
||||
onChange = {
|
||||
AddTransactionUiState.txnError.value = ""
|
||||
note = it.take(80)
|
||||
},
|
||||
placeholder = "What's this for?",
|
||||
label = "Note",
|
||||
description = "txn_note",
|
||||
)
|
||||
}
|
||||
ErrorText(err)
|
||||
}
|
||||
}
|
||||
}
|
||||
+8
@@ -0,0 +1,8 @@
|
||||
package app.folio.feature.ledger
|
||||
|
||||
import kotlinx.coroutines.flow.MutableStateFlow
|
||||
|
||||
object AddTransactionUiState {
|
||||
val txnError = MutableStateFlow("")
|
||||
val txnFormType = MutableStateFlow<String?>(null)
|
||||
}
|
||||
+167
@@ -0,0 +1,167 @@
|
||||
package app.folio.feature.ledger
|
||||
|
||||
import androidx.compose.foundation.background
|
||||
import androidx.compose.foundation.border
|
||||
import androidx.compose.foundation.layout.Arrangement
|
||||
import androidx.compose.foundation.layout.Box
|
||||
import androidx.compose.foundation.layout.Column
|
||||
import androidx.compose.foundation.layout.Row
|
||||
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.shape.RoundedCornerShape
|
||||
import androidx.compose.material3.Text
|
||||
import androidx.compose.runtime.Composable
|
||||
import androidx.compose.runtime.getValue
|
||||
import androidx.compose.runtime.collectAsState
|
||||
import androidx.compose.ui.Alignment
|
||||
import androidx.compose.ui.Modifier
|
||||
import androidx.compose.ui.draw.clip
|
||||
import androidx.compose.ui.semantics.contentDescription
|
||||
import androidx.compose.ui.semantics.semantics
|
||||
import androidx.compose.ui.text.style.TextOverflow
|
||||
import androidx.compose.ui.unit.dp
|
||||
import app.folio.data.Repository
|
||||
import app.folio.navigation.Navigator
|
||||
import app.folio.navigation.Route
|
||||
import app.folio.data.TxnType
|
||||
import app.folio.platform.balanceOf
|
||||
import app.folio.platform.formatCents
|
||||
import app.folio.platform.formatDate
|
||||
import app.folio.platform.signedAmount
|
||||
import app.folio.ui.BackHandler
|
||||
import app.folio.ui.component.AppButton
|
||||
import app.folio.ui.component.BackButton
|
||||
import app.folio.ui.component.ButtonStyle
|
||||
import app.folio.ui.component.Card
|
||||
import app.folio.ui.component.EmptyState
|
||||
import app.folio.ui.component.Header
|
||||
import app.folio.ui.component.Screen
|
||||
import app.folio.ui.icon.Icons
|
||||
import app.folio.ui.theme.LocalTokens
|
||||
import app.folio.ui.theme.RadiusLg
|
||||
import app.folio.ui.theme.Type
|
||||
|
||||
@Composable
|
||||
fun LedgerScreen(accountId: String) {
|
||||
val t = LocalTokens.current
|
||||
val accounts by Repository.accounts.collectAsState()
|
||||
val allTxns by Repository.transactions.collectAsState()
|
||||
|
||||
BackHandler { Navigator.back(Route.Home) }
|
||||
|
||||
val account = accounts.firstOrNull { it.id == accountId }
|
||||
if (account == null) {
|
||||
Screen(
|
||||
header = {
|
||||
Header(title = "Account", left = { BackButton { Navigator.back(Route.Home) } })
|
||||
},
|
||||
) {
|
||||
EmptyState(title = "Account not found", subtitle = "It may have been deleted.")
|
||||
AppButton(
|
||||
text = "Back to accounts",
|
||||
onClick = { Navigator.replace(Route.Home) },
|
||||
style = ButtonStyle.Secondary,
|
||||
)
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
val txns = allTxns
|
||||
.filter { it.accountId == accountId }
|
||||
.sortedByDescending { it.createdAt }
|
||||
val balance = balanceOf(txns)
|
||||
|
||||
Screen(
|
||||
header = {
|
||||
Header(
|
||||
title = account.name,
|
||||
subtitle = "Ledger",
|
||||
left = { BackButton { Navigator.back(Route.Home) } },
|
||||
)
|
||||
},
|
||||
footer = {
|
||||
AppButton(
|
||||
text = "+ Add transaction",
|
||||
onClick = { Navigator.push(Route.AddTransaction(accountId)) },
|
||||
style = ButtonStyle.Primary,
|
||||
description = "add_txn_button",
|
||||
)
|
||||
},
|
||||
) {
|
||||
Card {
|
||||
Text("BALANCE", style = Type.label, color = t.textMuted)
|
||||
Text(formatCents(balance), style = Type.balance, color = t.text)
|
||||
}
|
||||
Text(
|
||||
"ACTIVITY",
|
||||
style = Type.label,
|
||||
color = t.textFaint,
|
||||
modifier = Modifier.padding(top = 4.dp, bottom = 2.dp, start = 4.dp),
|
||||
)
|
||||
if (txns.isEmpty()) {
|
||||
EmptyState(
|
||||
title = "No transactions yet",
|
||||
subtitle = "Add your first credit or debit to see it here.",
|
||||
icon = Icons.Lines,
|
||||
)
|
||||
} else {
|
||||
Column(
|
||||
modifier = Modifier
|
||||
.fillMaxWidth()
|
||||
.clip(RoundedCornerShape(RadiusLg))
|
||||
.background(t.surface)
|
||||
.border(1.dp, t.border, RoundedCornerShape(RadiusLg))
|
||||
.padding(horizontal = 16.dp),
|
||||
) {
|
||||
txns.forEachIndexed { i, txn ->
|
||||
TxnRow(txn.id, txn.type, txn.amount, txn.note, formatDate(txn.createdAt))
|
||||
if (i != txns.lastIndex) {
|
||||
Box(Modifier.fillMaxWidth().height(1.dp).background(t.border))
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Composable
|
||||
private fun TxnRow(id: String, type: TxnType, amount: Long, note: String, date: String) {
|
||||
val t = LocalTokens.current
|
||||
val signed = if (type == TxnType.credit) amount else -amount
|
||||
Row(
|
||||
modifier = Modifier
|
||||
.fillMaxWidth()
|
||||
.padding(vertical = 14.dp)
|
||||
.semantics(mergeDescendants = true) { contentDescription = "txn_row:$id" },
|
||||
verticalAlignment = Alignment.CenterVertically,
|
||||
horizontalArrangement = Arrangement.spacedBy(12.dp),
|
||||
) {
|
||||
Box(
|
||||
modifier = Modifier
|
||||
.size(36.dp)
|
||||
.clip(RoundedCornerShape(10.dp))
|
||||
.background(t.surface2)
|
||||
.border(1.dp, t.border, RoundedCornerShape(10.dp)),
|
||||
contentAlignment = Alignment.Center,
|
||||
) {
|
||||
Text(if (type == TxnType.credit) "+" else "-", style = Type.bodyStrong, color = t.text)
|
||||
}
|
||||
Column(Modifier.weight(1f)) {
|
||||
Text(
|
||||
if (note.isNotEmpty()) note else if (type == TxnType.credit) "Credit" else "Debit",
|
||||
style = Type.body,
|
||||
color = t.text,
|
||||
maxLines = 1,
|
||||
overflow = TextOverflow.Ellipsis,
|
||||
)
|
||||
Text(date, style = Type.caption, color = t.textFaint)
|
||||
}
|
||||
Text(
|
||||
formatCents(signed, signed = true),
|
||||
style = Type.bodyStrong,
|
||||
color = t.text,
|
||||
)
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,31 @@
|
||||
package app.folio.navigation
|
||||
|
||||
import kotlinx.coroutines.flow.MutableStateFlow
|
||||
import kotlinx.coroutines.flow.StateFlow
|
||||
import kotlinx.coroutines.flow.asStateFlow
|
||||
|
||||
object Navigator {
|
||||
private val stack = ArrayDeque<Route>().apply { addLast(Route.Home) }
|
||||
private val _current = MutableStateFlow<Route>(Route.Home)
|
||||
val current: StateFlow<Route> = _current.asStateFlow()
|
||||
|
||||
fun push(route: Route) {
|
||||
stack.addLast(route)
|
||||
_current.value = route
|
||||
}
|
||||
|
||||
fun replace(route: Route) {
|
||||
stack.clear()
|
||||
stack.addLast(route)
|
||||
_current.value = route
|
||||
}
|
||||
|
||||
fun back(fallback: Route) {
|
||||
if (stack.size > 1) {
|
||||
stack.removeLast()
|
||||
_current.value = stack.last()
|
||||
} else {
|
||||
replace(fallback)
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,9 @@
|
||||
package app.folio.navigation
|
||||
|
||||
sealed interface Route {
|
||||
data object Login : Route
|
||||
data object Home : Route
|
||||
data object AddAccount : Route
|
||||
data class Ledger(val accountId: String) : Route
|
||||
data class AddTransaction(val accountId: String) : Route
|
||||
}
|
||||
@@ -0,0 +1,73 @@
|
||||
package app.folio.platform
|
||||
|
||||
import app.folio.data.Transaction
|
||||
import app.folio.data.TxnType
|
||||
import kotlin.math.absoluteValue
|
||||
|
||||
private const val CURRENCY = "$"
|
||||
private val AMOUNT_REGEX = Regex("""^\d+(\.\d{1,2})?$""")
|
||||
|
||||
fun formatCents(cents: Long, signed: Boolean = false): String {
|
||||
val abs = cents.absoluteValue
|
||||
val dollars = abs / 100
|
||||
val rem = (abs % 100).toInt()
|
||||
val dollarsStr = withThousandsSeparator(dollars)
|
||||
val remStr = rem.toString().padStart(2, '0')
|
||||
val body = "$CURRENCY$dollarsStr.$remStr"
|
||||
return when {
|
||||
cents < 0 -> "-$body"
|
||||
signed && cents > 0 -> "+$body"
|
||||
else -> body
|
||||
}
|
||||
}
|
||||
|
||||
private fun withThousandsSeparator(value: Long): String {
|
||||
val s = value.toString()
|
||||
if (s.length <= 3) return s
|
||||
val out = StringBuilder()
|
||||
var count = 0
|
||||
for (i in s.length - 1 downTo 0) {
|
||||
out.append(s[i])
|
||||
count++
|
||||
if (count == 3 && i != 0) {
|
||||
out.append(',')
|
||||
count = 0
|
||||
}
|
||||
}
|
||||
return out.reverse().toString()
|
||||
}
|
||||
|
||||
fun parseCents(input: String): Long? {
|
||||
val trimmed = input.trim().replace(",", "")
|
||||
if (trimmed.isEmpty()) return null
|
||||
if (!AMOUNT_REGEX.matches(trimmed)) return null
|
||||
val dot = trimmed.indexOf('.')
|
||||
val whole: String
|
||||
val frac: String
|
||||
if (dot < 0) {
|
||||
whole = trimmed
|
||||
frac = ""
|
||||
} else {
|
||||
whole = trimmed.substring(0, dot)
|
||||
frac = trimmed.substring(dot + 1)
|
||||
}
|
||||
val fracPadded = (frac + "00").substring(0, 2)
|
||||
val wholeLong = whole.toLongOrNull() ?: return null
|
||||
val fracLong = fracPadded.toLongOrNull() ?: return null
|
||||
val total = wholeLong * 100 + fracLong
|
||||
if (total < 0) return null
|
||||
return total
|
||||
}
|
||||
|
||||
fun signedAmount(t: Transaction): Long = if (t.type == TxnType.credit) t.amount else -t.amount
|
||||
|
||||
fun balanceOf(txns: List<Transaction>): Long = txns.sumOf { signedAmount(it) }
|
||||
|
||||
fun initialsOf(name: String): String {
|
||||
val parts = name.trim().split(Regex("\\s+")).filter { it.isNotEmpty() }
|
||||
if (parts.isEmpty()) return "?"
|
||||
if (parts.size == 1) return parts[0].take(2).uppercase()
|
||||
return (parts.first().first().toString() + parts.last().first().toString()).uppercase()
|
||||
}
|
||||
|
||||
expect fun formatDate(epochMillis: Long): String
|
||||
@@ -0,0 +1,6 @@
|
||||
package app.folio.platform
|
||||
|
||||
expect object Platform {
|
||||
fun now(): Long
|
||||
fun makeId(): String
|
||||
}
|
||||
@@ -0,0 +1,6 @@
|
||||
package app.folio.ui
|
||||
|
||||
import androidx.compose.runtime.Composable
|
||||
|
||||
@Composable
|
||||
expect fun BackHandler(onBack: () -> Unit)
|
||||
@@ -0,0 +1,57 @@
|
||||
package app.folio.ui.component
|
||||
|
||||
import androidx.compose.foundation.BorderStroke
|
||||
import androidx.compose.foundation.background
|
||||
import androidx.compose.foundation.border
|
||||
import androidx.compose.foundation.clickable
|
||||
import androidx.compose.foundation.layout.Box
|
||||
import androidx.compose.foundation.layout.fillMaxWidth
|
||||
import androidx.compose.foundation.layout.padding
|
||||
import androidx.compose.foundation.shape.RoundedCornerShape
|
||||
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.semantics.Role
|
||||
import androidx.compose.ui.semantics.contentDescription
|
||||
import androidx.compose.ui.semantics.semantics
|
||||
import androidx.compose.ui.unit.dp
|
||||
import app.folio.ui.theme.LocalTokens
|
||||
import app.folio.ui.theme.RadiusMd
|
||||
import app.folio.ui.theme.Type
|
||||
|
||||
enum class ButtonStyle { Primary, Secondary, Ghost }
|
||||
|
||||
@Composable
|
||||
fun AppButton(
|
||||
text: String,
|
||||
onClick: () -> Unit,
|
||||
modifier: Modifier = Modifier,
|
||||
style: ButtonStyle = ButtonStyle.Secondary,
|
||||
enabled: Boolean = true,
|
||||
description: String? = null,
|
||||
) {
|
||||
val t = LocalTokens.current
|
||||
val (bg, fg, border) = when (style) {
|
||||
ButtonStyle.Primary -> Triple(t.text, t.onAccent, t.text)
|
||||
ButtonStyle.Secondary -> Triple(t.surface2, t.text, t.borderStrong)
|
||||
ButtonStyle.Ghost -> Triple(t.bg, t.textMuted, t.bg)
|
||||
}
|
||||
Box(
|
||||
modifier = modifier
|
||||
.fillMaxWidth()
|
||||
.clip(RoundedCornerShape(RadiusMd))
|
||||
.background(if (enabled) bg else t.surface3)
|
||||
.border(BorderStroke(1.dp, if (enabled) border else t.border), RoundedCornerShape(RadiusMd))
|
||||
.then(
|
||||
if (description != null) Modifier.semantics { contentDescription = description }
|
||||
else Modifier
|
||||
)
|
||||
.clickable(enabled = enabled, role = Role.Button, onClick = onClick)
|
||||
.padding(vertical = 14.dp, horizontal = 16.dp),
|
||||
contentAlignment = Alignment.Center,
|
||||
) {
|
||||
Text(text, style = Type.button, color = if (enabled) fg else t.textFaint)
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,33 @@
|
||||
package app.folio.ui.component
|
||||
|
||||
import androidx.compose.foundation.background
|
||||
import androidx.compose.foundation.border
|
||||
import androidx.compose.foundation.layout.Arrangement
|
||||
import androidx.compose.foundation.layout.Column
|
||||
import androidx.compose.foundation.layout.fillMaxWidth
|
||||
import androidx.compose.foundation.layout.padding
|
||||
import androidx.compose.foundation.shape.RoundedCornerShape
|
||||
import androidx.compose.runtime.Composable
|
||||
import androidx.compose.ui.Modifier
|
||||
import androidx.compose.ui.draw.clip
|
||||
import androidx.compose.ui.unit.dp
|
||||
import app.folio.ui.theme.LocalTokens
|
||||
import app.folio.ui.theme.RadiusLg
|
||||
|
||||
@Composable
|
||||
fun Card(
|
||||
modifier: Modifier = Modifier,
|
||||
dashed: Boolean = false,
|
||||
content: @Composable () -> Unit,
|
||||
) {
|
||||
val t = LocalTokens.current
|
||||
Column(
|
||||
modifier = modifier
|
||||
.fillMaxWidth()
|
||||
.clip(RoundedCornerShape(RadiusLg))
|
||||
.background(if (dashed) t.surface2 else t.surface)
|
||||
.border(1.dp, t.border, RoundedCornerShape(RadiusLg))
|
||||
.padding(16.dp),
|
||||
verticalArrangement = Arrangement.spacedBy(6.dp),
|
||||
) { content() }
|
||||
}
|
||||
@@ -0,0 +1,56 @@
|
||||
package app.folio.ui.component
|
||||
|
||||
import androidx.compose.foundation.background
|
||||
import androidx.compose.foundation.border
|
||||
import androidx.compose.foundation.layout.Arrangement
|
||||
import androidx.compose.foundation.layout.Box
|
||||
import androidx.compose.foundation.layout.Column
|
||||
import androidx.compose.foundation.layout.Spacer
|
||||
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.shape.CircleShape
|
||||
import androidx.compose.material3.Icon
|
||||
import androidx.compose.material3.Text
|
||||
import androidx.compose.runtime.Composable
|
||||
import androidx.compose.ui.Alignment
|
||||
import androidx.compose.ui.Modifier
|
||||
import androidx.compose.ui.graphics.vector.ImageVector
|
||||
import androidx.compose.ui.graphics.vector.rememberVectorPainter
|
||||
import androidx.compose.ui.text.style.TextAlign
|
||||
import androidx.compose.ui.unit.dp
|
||||
import app.folio.ui.theme.LocalTokens
|
||||
import app.folio.ui.theme.Type
|
||||
|
||||
@Composable
|
||||
fun EmptyState(title: String, subtitle: String, icon: ImageVector? = null) {
|
||||
val t = LocalTokens.current
|
||||
Column(
|
||||
modifier = Modifier
|
||||
.fillMaxWidth()
|
||||
.padding(vertical = 48.dp, horizontal = 16.dp),
|
||||
horizontalAlignment = Alignment.CenterHorizontally,
|
||||
verticalArrangement = Arrangement.spacedBy(6.dp),
|
||||
) {
|
||||
if (icon != null) {
|
||||
Box(
|
||||
modifier = Modifier
|
||||
.size(56.dp)
|
||||
.background(t.surface2, CircleShape)
|
||||
.border(1.dp, t.border, CircleShape),
|
||||
contentAlignment = Alignment.Center,
|
||||
) {
|
||||
Icon(
|
||||
painter = rememberVectorPainter(icon),
|
||||
contentDescription = null,
|
||||
tint = t.textMuted,
|
||||
modifier = Modifier.size(22.dp),
|
||||
)
|
||||
}
|
||||
Spacer(Modifier.height(2.dp))
|
||||
}
|
||||
Text(title, style = Type.bodyStrong, color = t.text, textAlign = TextAlign.Center)
|
||||
Text(subtitle, style = Type.caption, color = t.textMuted, textAlign = TextAlign.Center)
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,21 @@
|
||||
package app.folio.ui.component
|
||||
|
||||
import androidx.compose.foundation.layout.fillMaxWidth
|
||||
import androidx.compose.foundation.layout.height
|
||||
import androidx.compose.material3.Text
|
||||
import androidx.compose.runtime.Composable
|
||||
import androidx.compose.ui.Modifier
|
||||
import androidx.compose.ui.unit.dp
|
||||
import app.folio.ui.theme.LocalTokens
|
||||
import app.folio.ui.theme.Type
|
||||
|
||||
@Composable
|
||||
fun ErrorText(err: String?) {
|
||||
val t = LocalTokens.current
|
||||
Text(
|
||||
err ?: "",
|
||||
style = Type.caption,
|
||||
color = t.text,
|
||||
modifier = Modifier.fillMaxWidth().height(18.dp),
|
||||
)
|
||||
}
|
||||
@@ -0,0 +1,12 @@
|
||||
package app.folio.ui.component
|
||||
|
||||
import androidx.compose.material3.Text
|
||||
import androidx.compose.runtime.Composable
|
||||
import app.folio.ui.theme.LocalTokens
|
||||
import app.folio.ui.theme.Type
|
||||
|
||||
@Composable
|
||||
fun FieldLabel(text: String) {
|
||||
val t = LocalTokens.current
|
||||
Text(text.uppercase(), style = Type.label, color = t.textMuted)
|
||||
}
|
||||
@@ -0,0 +1,48 @@
|
||||
package app.folio.ui.component
|
||||
|
||||
import androidx.compose.foundation.layout.Arrangement
|
||||
import androidx.compose.foundation.layout.Column
|
||||
import androidx.compose.foundation.layout.Row
|
||||
import androidx.compose.foundation.layout.fillMaxWidth
|
||||
import androidx.compose.foundation.layout.padding
|
||||
import androidx.compose.material3.Text
|
||||
import androidx.compose.runtime.Composable
|
||||
import androidx.compose.ui.Alignment
|
||||
import androidx.compose.ui.Modifier
|
||||
import androidx.compose.ui.text.style.TextOverflow
|
||||
import androidx.compose.ui.unit.dp
|
||||
import app.folio.ui.theme.LocalTokens
|
||||
import app.folio.ui.theme.ScreenPad
|
||||
import app.folio.ui.theme.Type
|
||||
|
||||
@Composable
|
||||
fun Header(
|
||||
title: String,
|
||||
subtitle: String? = null,
|
||||
left: @Composable (() -> Unit)? = null,
|
||||
right: @Composable (() -> Unit)? = null,
|
||||
) {
|
||||
val t = LocalTokens.current
|
||||
Row(
|
||||
modifier = Modifier
|
||||
.fillMaxWidth()
|
||||
.padding(start = ScreenPad, end = ScreenPad, top = 14.dp, bottom = 8.dp),
|
||||
verticalAlignment = Alignment.CenterVertically,
|
||||
horizontalArrangement = Arrangement.spacedBy(12.dp),
|
||||
) {
|
||||
if (left != null) left()
|
||||
Column(Modifier.weight(1f)) {
|
||||
Text(
|
||||
title,
|
||||
style = Type.title,
|
||||
color = t.text,
|
||||
maxLines = 1,
|
||||
overflow = TextOverflow.Ellipsis,
|
||||
)
|
||||
if (subtitle != null) {
|
||||
Text(subtitle, style = Type.caption, color = t.textMuted)
|
||||
}
|
||||
}
|
||||
if (right != null) right()
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,51 @@
|
||||
package app.folio.ui.component
|
||||
|
||||
import androidx.compose.foundation.background
|
||||
import androidx.compose.foundation.border
|
||||
import androidx.compose.foundation.clickable
|
||||
import androidx.compose.foundation.layout.Box
|
||||
import androidx.compose.foundation.layout.size
|
||||
import androidx.compose.foundation.shape.RoundedCornerShape
|
||||
import androidx.compose.material3.Icon
|
||||
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.graphics.vector.rememberVectorPainter
|
||||
import androidx.compose.ui.semantics.contentDescription
|
||||
import androidx.compose.ui.semantics.semantics
|
||||
import androidx.compose.ui.unit.dp
|
||||
import app.folio.ui.icon.Icons
|
||||
import app.folio.ui.theme.LocalTokens
|
||||
|
||||
@Composable
|
||||
fun IconButton(
|
||||
onClick: () -> Unit,
|
||||
description: String,
|
||||
icon: ImageVector,
|
||||
) {
|
||||
val t = LocalTokens.current
|
||||
Box(
|
||||
modifier = Modifier
|
||||
.size(36.dp)
|
||||
.clip(RoundedCornerShape(10.dp))
|
||||
.background(t.surface2)
|
||||
.border(1.dp, t.border, RoundedCornerShape(10.dp))
|
||||
.clickable(onClick = onClick)
|
||||
.semantics { contentDescription = description },
|
||||
contentAlignment = Alignment.Center,
|
||||
) {
|
||||
Icon(
|
||||
painter = rememberVectorPainter(icon),
|
||||
contentDescription = null,
|
||||
tint = t.text,
|
||||
modifier = Modifier.size(16.dp),
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
@Composable
|
||||
fun BackButton(onClick: () -> Unit) {
|
||||
IconButton(onClick = onClick, description = "Back", icon = Icons.Back)
|
||||
}
|
||||
@@ -0,0 +1,53 @@
|
||||
package app.folio.ui.component
|
||||
|
||||
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.Spacer
|
||||
import androidx.compose.foundation.layout.fillMaxSize
|
||||
import androidx.compose.foundation.layout.fillMaxWidth
|
||||
import androidx.compose.foundation.layout.height
|
||||
import androidx.compose.foundation.layout.padding
|
||||
import androidx.compose.foundation.rememberScrollState
|
||||
import androidx.compose.foundation.verticalScroll
|
||||
import androidx.compose.runtime.Composable
|
||||
import androidx.compose.ui.Modifier
|
||||
import androidx.compose.ui.unit.dp
|
||||
import app.folio.ui.theme.LocalTokens
|
||||
import app.folio.ui.theme.ScreenPad
|
||||
|
||||
@Composable
|
||||
fun Screen(
|
||||
header: @Composable (() -> Unit)? = null,
|
||||
footer: @Composable (() -> Unit)? = null,
|
||||
content: @Composable () -> Unit,
|
||||
) {
|
||||
val t = LocalTokens.current
|
||||
Column(Modifier.fillMaxSize()) {
|
||||
if (header != null) header()
|
||||
Column(
|
||||
modifier = Modifier
|
||||
.weight(1f)
|
||||
.fillMaxWidth()
|
||||
.verticalScroll(rememberScrollState())
|
||||
.padding(horizontal = ScreenPad, vertical = 8.dp),
|
||||
verticalArrangement = Arrangement.spacedBy(12.dp),
|
||||
) {
|
||||
content()
|
||||
Spacer(Modifier.height(16.dp))
|
||||
}
|
||||
if (footer != null) {
|
||||
Box(Modifier.fillMaxWidth().height(1.dp).background(t.border))
|
||||
Column(
|
||||
modifier = Modifier
|
||||
.fillMaxWidth()
|
||||
.background(t.bg)
|
||||
.padding(horizontal = ScreenPad, vertical = 16.dp),
|
||||
verticalArrangement = Arrangement.spacedBy(14.dp),
|
||||
) {
|
||||
footer()
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,64 @@
|
||||
package app.folio.ui.component
|
||||
|
||||
import androidx.compose.foundation.background
|
||||
import androidx.compose.foundation.border
|
||||
import androidx.compose.foundation.clickable
|
||||
import androidx.compose.foundation.layout.Arrangement
|
||||
import androidx.compose.foundation.layout.Box
|
||||
import androidx.compose.foundation.layout.Row
|
||||
import androidx.compose.foundation.layout.fillMaxWidth
|
||||
import androidx.compose.foundation.layout.padding
|
||||
import androidx.compose.foundation.shape.RoundedCornerShape
|
||||
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.semantics.Role
|
||||
import androidx.compose.ui.semantics.contentDescription
|
||||
import androidx.compose.ui.semantics.selected
|
||||
import androidx.compose.ui.semantics.semantics
|
||||
import androidx.compose.ui.unit.dp
|
||||
import app.folio.ui.theme.LocalTokens
|
||||
import app.folio.ui.theme.RadiusMd
|
||||
import app.folio.ui.theme.RadiusSm
|
||||
import app.folio.ui.theme.Type
|
||||
|
||||
@Composable
|
||||
fun Segmented(
|
||||
selected: Int,
|
||||
labels: List<String>,
|
||||
onSelect: (Int) -> Unit,
|
||||
descriptions: List<String>? = null,
|
||||
) {
|
||||
val t = LocalTokens.current
|
||||
Row(
|
||||
modifier = Modifier
|
||||
.fillMaxWidth()
|
||||
.clip(RoundedCornerShape(RadiusMd))
|
||||
.background(t.surface)
|
||||
.border(1.dp, t.border, RoundedCornerShape(RadiusMd))
|
||||
.padding(4.dp),
|
||||
horizontalArrangement = Arrangement.spacedBy(4.dp),
|
||||
) {
|
||||
labels.forEachIndexed { i, label ->
|
||||
val active = i == selected
|
||||
val desc = descriptions?.getOrNull(i)
|
||||
Box(
|
||||
modifier = Modifier
|
||||
.weight(1f)
|
||||
.clip(RoundedCornerShape(RadiusSm))
|
||||
.background(if (active) t.surface3 else t.surface)
|
||||
.semantics {
|
||||
this.selected = active
|
||||
if (desc != null) contentDescription = desc
|
||||
}
|
||||
.clickable(role = Role.Tab) { onSelect(i) }
|
||||
.padding(vertical = 10.dp),
|
||||
contentAlignment = Alignment.Center,
|
||||
) {
|
||||
Text(label, style = Type.button, color = if (active) t.text else t.textMuted)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,95 @@
|
||||
package app.folio.ui.component
|
||||
|
||||
import androidx.compose.foundation.BorderStroke
|
||||
import androidx.compose.foundation.background
|
||||
import androidx.compose.foundation.border
|
||||
import androidx.compose.foundation.layout.Box
|
||||
import androidx.compose.foundation.layout.fillMaxWidth
|
||||
import androidx.compose.foundation.layout.padding
|
||||
import androidx.compose.foundation.shape.RoundedCornerShape
|
||||
import androidx.compose.foundation.text.BasicTextField
|
||||
import androidx.compose.foundation.text.KeyboardOptions
|
||||
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.draw.clip
|
||||
import androidx.compose.ui.focus.onFocusChanged
|
||||
import androidx.compose.ui.graphics.SolidColor
|
||||
import androidx.compose.ui.semantics.contentDescription
|
||||
import androidx.compose.ui.semantics.semantics
|
||||
import androidx.compose.ui.semantics.stateDescription
|
||||
import androidx.compose.ui.text.TextStyle
|
||||
import androidx.compose.ui.text.input.KeyboardType
|
||||
import androidx.compose.ui.text.input.PasswordVisualTransformation
|
||||
import androidx.compose.ui.text.input.VisualTransformation
|
||||
import androidx.compose.ui.text.style.TextAlign
|
||||
import androidx.compose.ui.unit.dp
|
||||
import app.folio.FocusTracker
|
||||
import app.folio.ui.theme.LocalTokens
|
||||
import app.folio.ui.theme.RadiusMd
|
||||
import app.folio.ui.theme.Type
|
||||
|
||||
@Composable
|
||||
fun TextInput(
|
||||
value: String,
|
||||
onChange: (String) -> Unit,
|
||||
placeholder: String = "",
|
||||
invalid: Boolean = false,
|
||||
password: Boolean = false,
|
||||
keyboardType: KeyboardType = KeyboardType.Text,
|
||||
textAlign: TextAlign = TextAlign.Start,
|
||||
textStyle: TextStyle = Type.body,
|
||||
label: String? = null,
|
||||
description: String? = null,
|
||||
modifier: Modifier = Modifier,
|
||||
) {
|
||||
val t = LocalTokens.current
|
||||
var focused by remember { mutableStateOf(false) }
|
||||
val borderColor = if (focused || invalid) t.text else t.border
|
||||
val bg = if (focused) t.surface2 else t.surface
|
||||
Box(
|
||||
modifier = modifier
|
||||
.fillMaxWidth()
|
||||
.clip(RoundedCornerShape(RadiusMd))
|
||||
.background(bg)
|
||||
.border(BorderStroke(1.dp, borderColor), RoundedCornerShape(RadiusMd))
|
||||
.padding(horizontal = 14.dp, vertical = 14.dp),
|
||||
contentAlignment = if (textAlign == TextAlign.Center) Alignment.Center else Alignment.CenterStart,
|
||||
) {
|
||||
if (value.isEmpty() && placeholder.isNotEmpty()) {
|
||||
Text(
|
||||
placeholder,
|
||||
style = textStyle.copy(color = t.textFaint, textAlign = textAlign),
|
||||
modifier = Modifier.fillMaxWidth(),
|
||||
)
|
||||
}
|
||||
BasicTextField(
|
||||
value = value,
|
||||
onValueChange = onChange,
|
||||
textStyle = textStyle.copy(color = t.text, textAlign = textAlign),
|
||||
singleLine = true,
|
||||
visualTransformation = if (password) PasswordVisualTransformation() else VisualTransformation.None,
|
||||
keyboardOptions = KeyboardOptions(keyboardType = keyboardType),
|
||||
cursorBrush = SolidColor(t.text),
|
||||
modifier = Modifier
|
||||
.fillMaxWidth()
|
||||
.onFocusChanged {
|
||||
focused = it.isFocused
|
||||
if (description != null) {
|
||||
if (it.isFocused) FocusTracker.enter(description)
|
||||
else FocusTracker.leave(description)
|
||||
}
|
||||
}
|
||||
.semantics {
|
||||
val desc = description ?: label
|
||||
if (desc != null) contentDescription = desc
|
||||
if (invalid) stateDescription = "Invalid"
|
||||
},
|
||||
)
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,44 @@
|
||||
package app.folio.ui.icon
|
||||
|
||||
import androidx.compose.ui.graphics.Color
|
||||
import androidx.compose.ui.graphics.SolidColor
|
||||
import androidx.compose.ui.graphics.StrokeCap
|
||||
import androidx.compose.ui.graphics.StrokeJoin
|
||||
import androidx.compose.ui.graphics.vector.ImageVector
|
||||
import androidx.compose.ui.graphics.vector.addPathNodes
|
||||
import androidx.compose.ui.unit.dp
|
||||
|
||||
object Icons {
|
||||
val Back: ImageVector = strokeIcon("M15 18 L9 12 L15 6")
|
||||
|
||||
val Logout: ImageVector = strokeIcon(
|
||||
"M9 21 H5 A2 2 0 0 1 3 19 V5 A2 2 0 0 1 5 3 H9 " +
|
||||
"M16 17 L21 12 L16 7 " +
|
||||
"M21 12 H9",
|
||||
)
|
||||
|
||||
val Bank: ImageVector = strokeIcon(
|
||||
"M3 6 H21 V19 A2 2 0 0 1 19 21 H5 A2 2 0 0 1 3 19 Z " +
|
||||
"M3 10 H21",
|
||||
)
|
||||
|
||||
val Lines: ImageVector = strokeIcon(
|
||||
"M3 6 H21 " +
|
||||
"M3 12 H21 " +
|
||||
"M3 18 H15",
|
||||
)
|
||||
}
|
||||
|
||||
private fun strokeIcon(path: String): ImageVector =
|
||||
ImageVector.Builder(
|
||||
defaultWidth = 24.dp,
|
||||
defaultHeight = 24.dp,
|
||||
viewportWidth = 24f,
|
||||
viewportHeight = 24f,
|
||||
).addPath(
|
||||
pathData = addPathNodes(path),
|
||||
stroke = SolidColor(Color.Black),
|
||||
strokeLineWidth = 2f,
|
||||
strokeLineCap = StrokeCap.Round,
|
||||
strokeLineJoin = StrokeJoin.Round,
|
||||
).build()
|
||||
@@ -0,0 +1,45 @@
|
||||
package app.folio.ui.theme
|
||||
|
||||
import androidx.compose.foundation.isSystemInDarkTheme
|
||||
import androidx.compose.material3.MaterialTheme
|
||||
import androidx.compose.material3.lightColorScheme
|
||||
import androidx.compose.runtime.Composable
|
||||
import androidx.compose.runtime.staticCompositionLocalOf
|
||||
import androidx.compose.ui.graphics.Color
|
||||
import androidx.compose.ui.unit.dp
|
||||
|
||||
data class Tokens(
|
||||
val bg: Color = Color(0xFFFFFFFF),
|
||||
val surface: Color = Color(0xFFFAFAFA),
|
||||
val surface2: Color = Color(0xFFF4F4F4),
|
||||
val surface3: Color = Color(0xFFEBEBEB),
|
||||
val border: Color = Color(0xFFE7E7E7),
|
||||
val borderStrong: Color = Color(0xFFD6D6D6),
|
||||
val text: Color = Color(0xFF000000),
|
||||
val textMuted: Color = Color(0xFF6B6B6B),
|
||||
val textFaint: Color = Color(0xFF9A9A9A),
|
||||
val onAccent: Color = Color(0xFFFFFFFF),
|
||||
)
|
||||
|
||||
val LocalTokens = staticCompositionLocalOf { Tokens() }
|
||||
|
||||
@Composable
|
||||
fun LedgerTheme(content: @Composable () -> Unit) {
|
||||
@Suppress("UNUSED_VARIABLE")
|
||||
val dark = isSystemInDarkTheme()
|
||||
val scheme = lightColorScheme(
|
||||
background = Color(0xFFFFFFFF),
|
||||
surface = Color(0xFFFAFAFA),
|
||||
primary = Color(0xFF000000),
|
||||
onPrimary = Color(0xFFFFFFFF),
|
||||
)
|
||||
MaterialTheme(colorScheme = scheme) { content() }
|
||||
}
|
||||
|
||||
val FrameWidth = 420.dp
|
||||
val FrameHeight = 900.dp
|
||||
val ScreenPad = 20.dp
|
||||
val RadiusSm = 8.dp
|
||||
val RadiusMd = 12.dp
|
||||
val RadiusLg = 16.dp
|
||||
val RadiusPill = 999.dp
|
||||
@@ -0,0 +1,20 @@
|
||||
package app.folio.ui.theme
|
||||
|
||||
import androidx.compose.ui.text.TextStyle
|
||||
import androidx.compose.ui.text.font.FontFamily
|
||||
import androidx.compose.ui.text.font.FontWeight
|
||||
import androidx.compose.ui.unit.sp
|
||||
|
||||
val Mono: FontFamily = FontFamily.Monospace
|
||||
|
||||
object Type {
|
||||
val body = TextStyle(fontFamily = Mono, fontSize = 15.sp, fontWeight = FontWeight.Normal)
|
||||
val bodyStrong = TextStyle(fontFamily = Mono, fontSize = 15.sp, fontWeight = FontWeight.SemiBold)
|
||||
val title = TextStyle(fontFamily = Mono, fontSize = 20.sp, fontWeight = FontWeight.Bold, letterSpacing = (-0.2).sp)
|
||||
val caption = TextStyle(fontFamily = Mono, fontSize = 12.sp, fontWeight = FontWeight.Normal)
|
||||
val label = TextStyle(fontFamily = Mono, fontSize = 12.sp, fontWeight = FontWeight.Normal, letterSpacing = 0.7.sp)
|
||||
val balance = TextStyle(fontFamily = Mono, fontSize = 28.sp, fontWeight = FontWeight.Bold, letterSpacing = (-0.3).sp)
|
||||
val amountInput = TextStyle(fontFamily = Mono, fontSize = 36.sp, fontWeight = FontWeight.Bold, letterSpacing = (-0.3).sp)
|
||||
val button = TextStyle(fontFamily = Mono, fontSize = 15.sp, fontWeight = FontWeight.SemiBold)
|
||||
val brand = TextStyle(fontFamily = Mono, fontSize = 22.sp, fontWeight = FontWeight.Bold, letterSpacing = (-0.2).sp)
|
||||
}
|
||||
@@ -0,0 +1,47 @@
|
||||
CREATE TABLE Accounts (
|
||||
id TEXT NOT NULL PRIMARY KEY,
|
||||
name TEXT NOT NULL UNIQUE,
|
||||
createdAt INTEGER NOT NULL
|
||||
);
|
||||
|
||||
CREATE TABLE Txns (
|
||||
id TEXT NOT NULL PRIMARY KEY,
|
||||
accountId TEXT NOT NULL,
|
||||
type TEXT NOT NULL,
|
||||
amount INTEGER NOT NULL,
|
||||
note TEXT NOT NULL,
|
||||
createdAt INTEGER NOT NULL
|
||||
);
|
||||
|
||||
CREATE INDEX txn_account ON Txns(accountId);
|
||||
CREATE INDEX txn_created ON Txns(createdAt);
|
||||
|
||||
CREATE TABLE AppSession (
|
||||
key INTEGER NOT NULL PRIMARY KEY CHECK (key = 1),
|
||||
user TEXT NOT NULL,
|
||||
loggedInAt INTEGER NOT NULL
|
||||
);
|
||||
|
||||
selectAllAccounts:
|
||||
SELECT * FROM Accounts ORDER BY createdAt ASC;
|
||||
|
||||
accountExistsByName:
|
||||
SELECT EXISTS(SELECT 1 FROM Accounts WHERE name = :name COLLATE NOCASE);
|
||||
|
||||
insertAccount:
|
||||
INSERT INTO Accounts(id, name, createdAt) VALUES (?, ?, ?);
|
||||
|
||||
selectAllTxns:
|
||||
SELECT * FROM Txns;
|
||||
|
||||
insertTxn:
|
||||
INSERT INTO Txns(id, accountId, type, amount, note, createdAt) VALUES (?, ?, ?, ?, ?, ?);
|
||||
|
||||
selectSession:
|
||||
SELECT user, loggedInAt FROM AppSession WHERE key = 1;
|
||||
|
||||
upsertSession:
|
||||
INSERT OR REPLACE INTO AppSession(key, user, loggedInAt) VALUES (1, ?, ?);
|
||||
|
||||
clearSession:
|
||||
DELETE FROM AppSession WHERE key = 1;
|
||||
Reference in new issue
Block a user