commit
71a52e4269
57 files changed
+9273
No files matched your search
@@ -0,0 +1,75 @@
|
||||
import java.util.Properties
|
||||
|
||||
plugins {
|
||||
id("com.android.application")
|
||||
id("org.jetbrains.kotlin.plugin.compose")
|
||||
id("org.jetbrains.kotlin.plugin.serialization")
|
||||
}
|
||||
|
||||
// Release signing lives in an untracked keystore.properties, so the keystore and its
|
||||
// passwords never reach version control. Without the file the release APK is built unsigned.
|
||||
val keystoreProperties = Properties().apply {
|
||||
val file = rootProject.file("keystore.properties")
|
||||
if (file.exists()) file.inputStream().use { load(it) }
|
||||
}
|
||||
|
||||
android {
|
||||
namespace = "com.oshicue.keeps"
|
||||
compileSdk = 37
|
||||
|
||||
defaultConfig {
|
||||
applicationId = "com.oshicue.keeps"
|
||||
minSdk = 26
|
||||
targetSdk = 37
|
||||
versionCode = 1
|
||||
versionName = "1.0.0"
|
||||
}
|
||||
|
||||
signingConfigs {
|
||||
if (keystoreProperties.isNotEmpty()) {
|
||||
create("release") {
|
||||
storeFile = rootProject.file(keystoreProperties.getProperty("storeFile"))
|
||||
storePassword = keystoreProperties.getProperty("storePassword")
|
||||
keyAlias = keystoreProperties.getProperty("keyAlias")
|
||||
keyPassword = keystoreProperties.getProperty("keyPassword")
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
buildTypes {
|
||||
release {
|
||||
isMinifyEnabled = true
|
||||
isShrinkResources = true
|
||||
proguardFiles(getDefaultProguardFile("proguard-android-optimize.txt"), "proguard-rules.pro")
|
||||
if (keystoreProperties.isNotEmpty()) signingConfig = signingConfigs.getByName("release")
|
||||
}
|
||||
}
|
||||
|
||||
buildFeatures {
|
||||
compose = true
|
||||
}
|
||||
|
||||
compileOptions {
|
||||
sourceCompatibility = JavaVersion.VERSION_17
|
||||
targetCompatibility = JavaVersion.VERSION_17
|
||||
}
|
||||
|
||||
testOptions {
|
||||
unitTests.isReturnDefaultValues = true
|
||||
}
|
||||
}
|
||||
|
||||
dependencies {
|
||||
implementation(platform("androidx.compose:compose-bom:2026.09.00"))
|
||||
implementation("androidx.compose.ui:ui")
|
||||
implementation("androidx.compose.ui:ui-tooling-preview")
|
||||
implementation("androidx.compose.material3:material3")
|
||||
implementation("androidx.compose.material:material-icons-extended")
|
||||
implementation("androidx.activity:activity-compose:1.13.0")
|
||||
implementation("androidx.core:core-ktx:1.19.1")
|
||||
implementation("androidx.lifecycle:lifecycle-runtime-compose:2.9.4")
|
||||
implementation("androidx.lifecycle:lifecycle-viewmodel-compose:2.9.4")
|
||||
implementation("org.jetbrains.kotlinx:kotlinx-serialization-json:1.11.0")
|
||||
testImplementation("junit:junit:4.13.2")
|
||||
debugImplementation("androidx.compose.ui:ui-tooling")
|
||||
}
|
||||
Vendored
+3
@@ -0,0 +1,3 @@
|
||||
# kotlinx.serialization ships its own keep rules. Compose and the bundled font need none.
|
||||
# Keep JSON field names readable in crash reports for the model classes.
|
||||
-keepclassmembers class com.oshicue.** { *** Companion; }
|
||||
@@ -0,0 +1,32 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<manifest xmlns:android="http://schemas.android.com/apk/res/android">
|
||||
|
||||
<application
|
||||
android:allowBackup="true"
|
||||
android:icon="@mipmap/ic_launcher"
|
||||
android:label="@string/app_name"
|
||||
android:supportsRtl="true"
|
||||
android:theme="@style/Theme.OshicueKeeps">
|
||||
<activity
|
||||
android:name=".MainActivity"
|
||||
android:exported="true"
|
||||
android:windowSoftInputMode="adjustResize"
|
||||
android:theme="@style/Theme.OshicueKeeps">
|
||||
<intent-filter>
|
||||
<action android:name="android.intent.action.MAIN" />
|
||||
<category android:name="android.intent.category.LAUNCHER" />
|
||||
</intent-filter>
|
||||
</activity>
|
||||
|
||||
<provider
|
||||
android:name="androidx.core.content.FileProvider"
|
||||
android:authorities="${applicationId}.fileprovider"
|
||||
android:exported="false"
|
||||
android:grantUriPermissions="true">
|
||||
<meta-data
|
||||
android:name="android.support.FILE_PROVIDER_PATHS"
|
||||
android:resource="@xml/file_paths" />
|
||||
</provider>
|
||||
</application>
|
||||
|
||||
</manifest>
|
||||
@@ -0,0 +1,209 @@
|
||||
// Oshicue Keeps — en
|
||||
|
||||
"import.file" = "Choose file";
|
||||
"import.validate" = "Validate";
|
||||
"settings.title" = "Settings";
|
||||
"settings.language" = "Language";
|
||||
"settings.followSystem" = "Follow system";
|
||||
"settings.about" = "About";
|
||||
"settings.version" = "Version";
|
||||
"common.done" = "Done";
|
||||
"common.cancel" = "Cancel";
|
||||
"common.close" = "Close";
|
||||
"settings.readError" = "Unable to read saved data.";
|
||||
"settings.saveError" = "Unable to save changes.";
|
||||
"settings.storageError" = "There was a problem with saved data.";
|
||||
"import.readError" = "Unable to read the file. Choose a UTF-8 JSON file.";
|
||||
"ledger.title" = "Ledger";
|
||||
"ledger.add" = "Add record";
|
||||
"ledger.today" = "Today";
|
||||
"ledger.month" = "Month";
|
||||
"ledger.year" = "Year";
|
||||
"ledger.day" = "Day";
|
||||
"ledger.lifetime" = "Lifetime";
|
||||
"ledger.quantity" = "Quantity";
|
||||
"ledger.spending" = "Spending";
|
||||
"ledger.memberCombined" = "Member · combined";
|
||||
"ledger.memberByGroup" = "Member · by group";
|
||||
"ledger.group" = "Group";
|
||||
"ledger.currency" = "Currency";
|
||||
"ledger.total" = "Total";
|
||||
"ledger.membersCount" = "%d members";
|
||||
"ledger.itemsCount" = "%d items";
|
||||
"ledger.noRecords" = "No records for this date";
|
||||
"ledger.noRecordsHint" = "Tap + to record a purchase.";
|
||||
"ledger.records" = "Records";
|
||||
"ledger.edit" = "Edit";
|
||||
"ledger.delete" = "Delete";
|
||||
"ledger.deleteTitle" = "Delete this record?";
|
||||
"ledger.deleteMessage" = "Its quantity and spending will be removed from your totals.";
|
||||
"ledger.manage" = "Manage";
|
||||
"ledger.import" = "Import ledger";
|
||||
"ledger.export" = "Export backup";
|
||||
"ledger.backup" = "JSON backup";
|
||||
"ledger.importHint" = "Paste ledger JSON or choose a backup file. Preview it before importing.";
|
||||
"ledger.preview" = "Preview";
|
||||
"ledger.apply" = "Import";
|
||||
"ledger.summary" = "%d members · %d records";
|
||||
"ledger.editRecord" = "Edit purchase";
|
||||
"ledger.date" = "Date";
|
||||
"ledger.member" = "Member";
|
||||
"ledger.chooseMember" = "Choose member";
|
||||
"ledger.chooseGroup" = "Choose group";
|
||||
"ledger.type" = "Purchase type";
|
||||
"ledger.unitPrice" = "Unit price";
|
||||
"ledger.amount" = "Amount";
|
||||
"ledger.event" = "Event";
|
||||
"ledger.optional" = "Optional";
|
||||
"ledger.noEvent" = "No event";
|
||||
"ledger.city" = "City";
|
||||
"ledger.venue" = "Venue";
|
||||
"ledger.address" = "Venue address";
|
||||
"ledger.note" = "Notes";
|
||||
"ledger.save" = "Save";
|
||||
"ledger.addMember" = "Add member";
|
||||
"ledger.addType" = "Add purchase type";
|
||||
"ledger.addEvent" = "Add event";
|
||||
"ledger.priceHint" = "New purchases use the latest matching member, group, type and currency price on or before the chosen date, then the last-added price for that type and currency, then the default or 0. Prices are editable; existing records keep their original price.";
|
||||
"ledger.invalidPrice" = "Enter a nonnegative price. JPY and KRW use whole numbers; other currencies allow up to two decimal places.";
|
||||
"ledger.invalidQuantity" = "Quantity must be at least 1.";
|
||||
"ledger.requiredSelection" = "Choose a member, group and purchase type.";
|
||||
"ledger.currencyHint" = "Totals and spending rankings are calculated separately for each currency; currencies are not converted or added together.";
|
||||
"ledger.groupColor" = "Representative color";
|
||||
"ledger.loadDemo" = "Load ledger demo";
|
||||
"ledger.loadDemoHint" = "Sample members and purchases help you explore the ledger.";
|
||||
"ledger.product.polaroid" = "Cheki";
|
||||
"ledger.product.wide" = "Wide cheki";
|
||||
"ledger.product.mobile" = "Phone photo";
|
||||
"ledger.demoRequiresEmpty" = "The demo can only be loaded into an empty ledger.";
|
||||
"ledger.error.overflow" = "The amount or quantity is too large. Enter a smaller value.";
|
||||
"ledger.previousMonth" = "Previous month";
|
||||
"ledger.nextMonth" = "Next month";
|
||||
"ledger.catalog.members" = "Members";
|
||||
"ledger.catalog.products" = "Purchase types";
|
||||
"ledger.catalog.events" = "Events";
|
||||
"ledger.catalog.add" = "Add to catalog";
|
||||
"ledger.catalog.search" = "Member / group / type / event";
|
||||
"ledger.catalog.memberCount" = "%d members";
|
||||
"ledger.catalog.noGroupMembers" = "No members in this group yet.";
|
||||
"ledger.member.shared" = "Member of multiple groups";
|
||||
"ledger.member.reuse" = "Link an existing person";
|
||||
"ledger.member.existing" = "Existing person";
|
||||
"ledger.member.name" = "Member name";
|
||||
"ledger.member.photo" = "Choose avatar from Photos";
|
||||
"ledger.member.removePhoto" = "Remove avatar";
|
||||
"ledger.member.identity" = "Identity & avatar";
|
||||
"ledger.member.identityHint" = "For the same person in another group, link their existing identity to count records together or separately.";
|
||||
"ledger.member.affiliation" = "Group & representative color";
|
||||
"ledger.member.prices" = "Default unit prices";
|
||||
"ledger.member.pricesHint" = "Leave a price blank to enter it when recording. Prices can differ by group; edits do not change past purchases.";
|
||||
"ledger.member.photoError" = "This image could not be loaded. Choose another photo.";
|
||||
"ledger.member.photoTooLarge" = "Choose a photo smaller than 10 MB.";
|
||||
"ledger.group.edit" = "Edit group";
|
||||
"ledger.group.name" = "Group name";
|
||||
"ledger.product.name" = "Type name";
|
||||
"ledger.event.name" = "Event name";
|
||||
"ledger.event.hasDate" = "Include an event date";
|
||||
"ledger.member.add" = "Add member";
|
||||
"ledger.group.add" = "Add group";
|
||||
"ledger.product.add" = "Add purchase type";
|
||||
"ledger.event.add" = "Add event";
|
||||
"ledger.period" = "Period";
|
||||
"ledger.rankingBy" = "Rank by";
|
||||
"ledger.metric" = "Metric";
|
||||
"ledger.allTypes" = "All types";
|
||||
"ledger.allGroups" = "All groups";
|
||||
"ledger.backupHint" = "Back up groups, members, avatars, prices and purchase history together.";
|
||||
"ledger.chooseRecord" = "Choose a purchase to edit";
|
||||
"ledger.chooseRecordHint" = "This member has several records on this date. Choose one to edit.";
|
||||
"ledger.deleted" = "Deleted";
|
||||
"ledger.record.delete" = "Delete this purchase";
|
||||
"ledger.member.delete" = "Delete member";
|
||||
"ledger.member.deleteTitle" = "Delete this member?";
|
||||
"ledger.member.deleteMessage" = "This member will be removed from all groups. Existing purchases and spending statistics will be kept.";
|
||||
"ledger.group.delete" = "Delete group";
|
||||
"ledger.group.deleteTitle" = "Delete this group?";
|
||||
"ledger.group.deleteMessage" = "This group and its memberships will be removed from the catalog. Members in other groups, existing purchases, and spending statistics will be kept.";
|
||||
"ledger.catalogUnavailable" = "This member or group has been deleted, so these catalog changes cannot be saved. Existing purchases can still be edited.";
|
||||
"settings.data" = "Data management";
|
||||
"settings.localData" = "Your data is stored on this device. Export a backup whenever you need.";
|
||||
"settings.ledgerDemo" = "Load ledger examples";
|
||||
"ledger.member.favorite" = "Favorite member";
|
||||
"ledger.member.favoriteHint" = "Favorite members appear first when choosing a member for purchases. This setting is shared across all of the member’s groups.";
|
||||
"ledger.members.favorites" = "Favorite members";
|
||||
"management.records" = "Record management";
|
||||
"management.backup" = "Backup";
|
||||
"management.filters" = "Filters";
|
||||
"management.search" = "Search members, groups, types, events or notes";
|
||||
"management.dateRange" = "Filter by date range";
|
||||
"management.startDate" = "Start date";
|
||||
"management.endDate" = "End date";
|
||||
"management.invalidDateRange" = "The start date must not be after the end date.";
|
||||
"management.all" = "All";
|
||||
"management.selectFiltered" = "Select all results";
|
||||
"management.clearSelection" = "Clear selection";
|
||||
"management.selectionHint" = "Only selected records are deleted. Changing filters clears the selection.";
|
||||
"management.selectedCount" = "%d selected";
|
||||
"management.resultCount" = "%d results";
|
||||
"management.deleteSelected" = "Delete selected";
|
||||
"management.empty" = "No matching records";
|
||||
"management.clearAll" = "Delete all purchase records";
|
||||
"management.clearAllHint" = "Deleting all purchases affects every date, member and currency. Groups, members, types and events are kept.";
|
||||
"ledger.management" = "Ledger management";
|
||||
"ledger.management.deleteSummary" = "Delete %d records containing %@ items.";
|
||||
"ledger.management.deleteImpact" = "Their quantities and amounts will be removed from statistics. This cannot be undone.";
|
||||
"management.catalog" = "Catalog cleanup";
|
||||
"management.catalog.search" = "Search members or groups";
|
||||
"management.catalog.hint" = "Deleting a member affects all their affiliations; deleting a group affects only that group. Existing records are kept. Valid backups can restore catalog data.";
|
||||
"management.catalog.empty" = "No members or groups to clean up";
|
||||
"management.catalog.deleteTitle" = "Delete selected catalog entries?";
|
||||
"ledger.exportCSV" = "Export purchases (CSV)";
|
||||
"ledger.exportCSVHint" = "One row per purchase, for viewing and totals in Numbers or Excel. CSV is read-only; use the JSON backup to restore data.";
|
||||
"ledger.quickAdd.product" = "Add one more: %@";
|
||||
"ledger.quickAddHint" = "Tap ⊕ to add one to the same purchase. Its price and details stay the same.";
|
||||
|
||||
"settings.keepsAbout" = "Oshicue Keeps · Your fan activity ledger.";
|
||||
"ledger.record.details" = "Record labels";
|
||||
"ledger.record.detailsHint" = "These labels and the color are kept with this purchase. Changing the member or type refreshes them; edit them here to correct a past record.";
|
||||
|
||||
// Keys looked up through helpers and ternaries
|
||||
"import.copied" = "Copied";
|
||||
"ledger.calendar" = "Calendar";
|
||||
"ledger.catalog" = "Members & types";
|
||||
"ledger.catalog.emptyEvents" = "Save an event to reuse its city and venue.";
|
||||
"ledger.catalog.emptyMembers" = "Add a group and member to get started.";
|
||||
"ledger.combinedHint" = "Members linked to the same identity are counted together across groups.";
|
||||
"ledger.copyTemplate" = "Copy template";
|
||||
"ledger.error.avatar" = "The avatar must be a valid JPEG image.";
|
||||
"ledger.error.avatarSize" = "The avatar is too large. The limit is 2 MB.";
|
||||
"ledger.error.color" = "Use a six-digit color in #RRGGBB format.";
|
||||
"ledger.error.currency" = "This currency is not supported.";
|
||||
"ledger.error.currencyRequired" = "Choose one currency to rank spending.";
|
||||
"ledger.error.date" = "Use a valid date in yyyy-MM-dd format.";
|
||||
"ledger.error.documentSize" = "The import is too large. The limit is 20 MB.";
|
||||
"ledger.error.duplicateID" = "An ID is duplicated. Each item must have a unique ID in its list.";
|
||||
"ledger.error.emptyField" = "This field must not be empty.";
|
||||
"ledger.error.emptyImport" = "There are no groups, members, purchase types, events or records to import.";
|
||||
"ledger.error.fieldType" = "A field has the wrong type or contains null. Check the field shown below against the template.";
|
||||
"ledger.error.invalidJSON" = "The text is not valid JSON. Check commas, quotation marks and brackets.";
|
||||
"ledger.error.membership" = "A member/group membership is missing or duplicated.";
|
||||
"ledger.error.missingField" = "A required field is missing. Add the field shown below.";
|
||||
"ledger.error.price" = "Unit price must be a nonnegative whole number in the currency's smallest unit.";
|
||||
"ledger.error.quantity" = "Quantity must be a positive whole number.";
|
||||
"ledger.error.recordConflict" = "A record with this ID has different contents. Use a new ID for a new purchase, or edit the existing record in the app.";
|
||||
"ledger.error.reference" = "A referenced catalog item is missing. Add the item or correct its ID.";
|
||||
"ledger.error.schemaVersion" = "This ledger version is not supported. Set schemaVersion to 1.";
|
||||
"ledger.event.edit" = "Edit event";
|
||||
"ledger.management.clearTitle" = "Delete all purchase records?";
|
||||
"ledger.management.deleteTitle" = "Delete selected purchase records?";
|
||||
"ledger.member.edit" = "Edit member";
|
||||
"ledger.newRecord" = "New purchase";
|
||||
"ledger.product.edit" = "Edit purchase type";
|
||||
"ledger.replacesDemo" = "This import replaces the unedited sample ledger data.";
|
||||
"ledger.restoreHint" = "Catalog items with matching IDs are updated. Identical purchases are skipped and other saved purchases are kept.";
|
||||
"ledger.splitHint" = "Choose whether a member in several groups is counted together or separately.";
|
||||
"ledger.stats" = "Statistics";
|
||||
"management.catalog.groupImpact" = "Archive %d groups and their affiliations. Members’ other affiliations, purchases and statistics are kept.";
|
||||
"management.catalog.memberImpact" = "Archive %d members and all their affiliations. Purchases and statistics are kept, and historical records remain editable.";
|
||||
|
||||
// Image export
|
||||
@@ -0,0 +1,209 @@
|
||||
// Oshicue Keeps — id
|
||||
|
||||
"import.file" = "Pilih file";
|
||||
"import.validate" = "Periksa format";
|
||||
"settings.title" = "Pengaturan";
|
||||
"settings.language" = "Bahasa";
|
||||
"settings.followSystem" = "Ikuti sistem";
|
||||
"settings.about" = "Tentang";
|
||||
"settings.version" = "Versi";
|
||||
"common.done" = "Selesai";
|
||||
"common.cancel" = "Batal";
|
||||
"common.close" = "Tutup";
|
||||
"settings.readError" = "Tidak dapat membaca data tersimpan.";
|
||||
"settings.saveError" = "Tidak dapat menyimpan perubahan.";
|
||||
"settings.storageError" = "Terjadi masalah pada data tersimpan.";
|
||||
"import.readError" = "Tidak dapat membaca file. Pilih file JSON berformat UTF-8.";
|
||||
"ledger.title" = "Catatan";
|
||||
"ledger.add" = "Tambah catatan";
|
||||
"ledger.today" = "Hari ini";
|
||||
"ledger.month" = "Bulan";
|
||||
"ledger.year" = "Tahun";
|
||||
"ledger.day" = "Hari";
|
||||
"ledger.lifetime" = "Sepanjang waktu";
|
||||
"ledger.quantity" = "Jumlah";
|
||||
"ledger.spending" = "Pengeluaran";
|
||||
"ledger.memberCombined" = "Anggota · gabungan";
|
||||
"ledger.memberByGroup" = "Anggota · per grup";
|
||||
"ledger.group" = "Grup";
|
||||
"ledger.currency" = "Mata uang";
|
||||
"ledger.total" = "Total";
|
||||
"ledger.membersCount" = "%d anggota";
|
||||
"ledger.itemsCount" = "%d foto";
|
||||
"ledger.noRecords" = "Belum ada catatan pada tanggal ini";
|
||||
"ledger.noRecordsHint" = "Ketuk + untuk mencatat pembelian.";
|
||||
"ledger.records" = "Catatan pembelian";
|
||||
"ledger.edit" = "Edit";
|
||||
"ledger.delete" = "Hapus";
|
||||
"ledger.deleteTitle" = "Hapus catatan ini?";
|
||||
"ledger.deleteMessage" = "Jumlah dan pengeluarannya akan dikeluarkan dari total.";
|
||||
"ledger.manage" = "Kelola";
|
||||
"ledger.import" = "Impor catatan";
|
||||
"ledger.export" = "Ekspor cadangan";
|
||||
"ledger.backup" = "Cadangan JSON";
|
||||
"ledger.importHint" = "Tempel JSON catatan atau pilih berkas cadangan. Periksa pratinjau sebelum mengimpor.";
|
||||
"ledger.preview" = "Pratinjau";
|
||||
"ledger.apply" = "Impor";
|
||||
"ledger.summary" = "%d anggota · %d catatan";
|
||||
"ledger.editRecord" = "Edit pembelian";
|
||||
"ledger.date" = "Tanggal";
|
||||
"ledger.member" = "Anggota";
|
||||
"ledger.chooseMember" = "Pilih anggota";
|
||||
"ledger.chooseGroup" = "Pilih grup";
|
||||
"ledger.type" = "Jenis pembelian";
|
||||
"ledger.unitPrice" = "Harga satuan";
|
||||
"ledger.amount" = "Nominal";
|
||||
"ledger.event" = "Acara";
|
||||
"ledger.optional" = "Opsional";
|
||||
"ledger.noEvent" = "Tanpa acara";
|
||||
"ledger.city" = "Kota";
|
||||
"ledger.venue" = "Tempat";
|
||||
"ledger.address" = "Alamat tempat";
|
||||
"ledger.note" = "Catatan tambahan";
|
||||
"ledger.save" = "Simpan";
|
||||
"ledger.addMember" = "Tambah anggota";
|
||||
"ledger.addType" = "Tambah jenis pembelian";
|
||||
"ledger.addEvent" = "Tambah acara";
|
||||
"ledger.priceHint" = "Pembelian baru memakai harga terakhir pada atau sebelum tanggal pilihan untuk anggota, grup, jenis dan mata uang yang sama, lalu harga penambahan terakhir untuk jenis dan mata uang itu, lalu harga default atau 0. Harga dapat diedit; catatan lama mempertahankan harga asli.";
|
||||
"ledger.invalidPrice" = "Masukkan harga nonnegatif. JPY dan KRW memakai bilangan bulat; mata uang lain maksimal dua angka desimal.";
|
||||
"ledger.invalidQuantity" = "Jumlah harus minimal 1.";
|
||||
"ledger.requiredSelection" = "Pilih anggota, grup dan jenis pembelian.";
|
||||
"ledger.currencyHint" = "Total dan peringkat pengeluaran dihitung per mata uang, tanpa konversi atau penjumlahan lintas mata uang.";
|
||||
"ledger.groupColor" = "Warna perwakilan";
|
||||
"ledger.loadDemo" = "Muat contoh catatan";
|
||||
"ledger.loadDemoHint" = "Jelajahi fitur dengan contoh anggota dan pembelian.";
|
||||
"ledger.product.polaroid" = "Cheki";
|
||||
"ledger.product.wide" = "Cheki wide";
|
||||
"ledger.product.mobile" = "Foto ponsel";
|
||||
"ledger.demoRequiresEmpty" = "Contoh hanya dapat dimuat ke catatan kosong.";
|
||||
"ledger.error.overflow" = "Nominal atau jumlah terlalu besar. Masukkan nilai yang lebih kecil.";
|
||||
"ledger.previousMonth" = "Bulan sebelumnya";
|
||||
"ledger.nextMonth" = "Bulan berikutnya";
|
||||
"ledger.catalog.members" = "Anggota";
|
||||
"ledger.catalog.products" = "Jenis pembelian";
|
||||
"ledger.catalog.events" = "Acara";
|
||||
"ledger.catalog.add" = "Tambah ke katalog";
|
||||
"ledger.catalog.search" = "Anggota / grup / jenis / acara";
|
||||
"ledger.catalog.memberCount" = "%d anggota";
|
||||
"ledger.catalog.noGroupMembers" = "Grup ini belum memiliki anggota.";
|
||||
"ledger.member.shared" = "Anggota beberapa grup";
|
||||
"ledger.member.reuse" = "Tautkan anggota yang ada";
|
||||
"ledger.member.existing" = "Anggota yang ada";
|
||||
"ledger.member.name" = "Nama anggota";
|
||||
"ledger.member.photo" = "Pilih avatar dari Foto";
|
||||
"ledger.member.removePhoto" = "Hapus avatar";
|
||||
"ledger.member.identity" = "Anggota & avatar";
|
||||
"ledger.member.identityHint" = "Untuk orang yang sama di grup lain, tautkan anggota yang ada agar catatan dapat dihitung gabungan atau per grup.";
|
||||
"ledger.member.affiliation" = "Grup & warna perwakilan";
|
||||
"ledger.member.prices" = "Harga satuan bawaan";
|
||||
"ledger.member.pricesHint" = "Harga boleh dikosongkan dan diisi saat mencatat. Harga tiap grup dapat berbeda; perubahan tidak mengubah pembelian sebelumnya.";
|
||||
"ledger.member.photoError" = "Gambar ini tidak dapat dimuat. Pilih foto lain.";
|
||||
"ledger.member.photoTooLarge" = "Pilih foto yang lebih kecil dari 10 MB.";
|
||||
"ledger.group.edit" = "Edit grup";
|
||||
"ledger.group.name" = "Nama grup";
|
||||
"ledger.product.name" = "Nama jenis";
|
||||
"ledger.event.name" = "Nama acara";
|
||||
"ledger.event.hasDate" = "Sertakan tanggal acara";
|
||||
"ledger.member.add" = "Tambah anggota";
|
||||
"ledger.group.add" = "Tambah grup";
|
||||
"ledger.product.add" = "Tambah jenis pembelian";
|
||||
"ledger.event.add" = "Tambah acara";
|
||||
"ledger.period" = "Periode";
|
||||
"ledger.rankingBy" = "Dasar peringkat";
|
||||
"ledger.metric" = "Indikator";
|
||||
"ledger.allTypes" = "Semua jenis";
|
||||
"ledger.allGroups" = "Semua grup";
|
||||
"ledger.backupHint" = "Cadangkan grup, anggota, avatar, harga dan riwayat pembelian bersama.";
|
||||
"ledger.chooseRecord" = "Pilih pembelian untuk diedit";
|
||||
"ledger.chooseRecordHint" = "Anggota ini memiliki beberapa catatan pada tanggal ini. Pilih satu untuk diedit.";
|
||||
"ledger.deleted" = "Dihapus";
|
||||
"ledger.record.delete" = "Hapus pembelian ini";
|
||||
"ledger.member.delete" = "Hapus anggota";
|
||||
"ledger.member.deleteTitle" = "Hapus anggota ini?";
|
||||
"ledger.member.deleteMessage" = "Anggota ini akan dihapus dari semua grup. Pembelian dan statistik pengeluaran yang sudah dicatat tetap disimpan.";
|
||||
"ledger.group.delete" = "Hapus grup";
|
||||
"ledger.group.deleteTitle" = "Hapus grup ini?";
|
||||
"ledger.group.deleteMessage" = "Grup ini dan hubungan keanggotaannya akan dihapus dari katalog. Anggota yang juga berada di grup lain, pembelian yang sudah dicatat, dan statistik pengeluaran tetap disimpan.";
|
||||
"ledger.catalogUnavailable" = "Anggota atau grup ini telah dihapus, sehingga perubahan katalog ini tidak dapat disimpan. Pembelian yang sudah ada tetap dapat diedit.";
|
||||
"settings.data" = "Pengelolaan data";
|
||||
"settings.localData" = "Data disimpan di perangkat ini. Ekspor cadangan kapan pun diperlukan.";
|
||||
"settings.ledgerDemo" = "Muat contoh catatan";
|
||||
"ledger.member.favorite" = "Anggota favorit";
|
||||
"ledger.member.favoriteHint" = "Anggota favorit muncul paling atas saat memilih anggota untuk pembelian. Pengaturan ini dibagikan ke semua grup anggota tersebut.";
|
||||
"ledger.members.favorites" = "Anggota favorit";
|
||||
"management.records" = "Kelola catatan";
|
||||
"management.backup" = "Cadangan";
|
||||
"management.filters" = "Filter";
|
||||
"management.search" = "Cari anggota, grup, jenis, acara atau catatan";
|
||||
"management.dateRange" = "Filter menurut rentang tanggal";
|
||||
"management.startDate" = "Tanggal mulai";
|
||||
"management.endDate" = "Tanggal akhir";
|
||||
"management.invalidDateRange" = "Tanggal mulai tidak boleh setelah tanggal akhir.";
|
||||
"management.all" = "Semua";
|
||||
"management.selectFiltered" = "Pilih semua hasil";
|
||||
"management.clearSelection" = "Hapus pilihan";
|
||||
"management.selectionHint" = "Hanya catatan terpilih yang dihapus. Mengubah filter menghapus pilihan.";
|
||||
"management.selectedCount" = "%d dipilih";
|
||||
"management.resultCount" = "%d hasil";
|
||||
"management.deleteSelected" = "Hapus yang dipilih";
|
||||
"management.empty" = "Tidak ada catatan yang cocok";
|
||||
"management.clearAll" = "Hapus semua catatan pembelian";
|
||||
"management.clearAllHint" = "Penghapusan semua pembelian mencakup setiap tanggal, anggota, dan mata uang. Grup, anggota, jenis, dan data acara tetap ada.";
|
||||
"ledger.management" = "Kelola Catatan";
|
||||
"ledger.management.deleteSummary" = "Hapus %d catatan dengan total %@ unit.";
|
||||
"ledger.management.deleteImpact" = "Jumlah dan nilainya akan dihapus dari statistik. Tindakan ini tidak dapat dibatalkan.";
|
||||
"management.catalog" = "Bersihkan data anggota dan grup";
|
||||
"management.catalog.search" = "Cari anggota atau grup";
|
||||
"management.catalog.hint" = "Menghapus anggota memengaruhi semua afiliasinya; menghapus grup hanya memengaruhi grup itu. Catatan lama tetap ada dan cadangan valid dapat memulihkan data.";
|
||||
"management.catalog.empty" = "Tidak ada anggota atau grup untuk dibersihkan";
|
||||
"management.catalog.deleteTitle" = "Hapus data terpilih?";
|
||||
"ledger.exportCSV" = "Ekspor pembelian (CSV)";
|
||||
"ledger.exportCSVHint" = "Satu baris per pembelian, untuk dilihat dan dijumlahkan di Numbers atau Excel. CSV hanya untuk dibaca; gunakan cadangan JSON untuk memulihkan data.";
|
||||
"ledger.quickAdd.product" = "Tambah satu lagi: %@";
|
||||
"ledger.quickAddHint" = "Ketuk ⊕ untuk menambah satu pada pembelian yang sama. Harga dan detailnya tetap.";
|
||||
|
||||
"settings.keepsAbout" = "Oshicue Keeps · Buku catatan aktivitas fan Anda.";
|
||||
"ledger.record.details" = "Label catatan";
|
||||
"ledger.record.detailsHint" = "Label dan warna ini disimpan bersama catatan. Mengubah anggota atau jenis akan memperbaruinya; sunting di sini untuk mengoreksi catatan lama.";
|
||||
|
||||
// Keys looked up through helpers and ternaries
|
||||
"import.copied" = "Disalin";
|
||||
"ledger.calendar" = "Kalender";
|
||||
"ledger.catalog" = "Anggota & jenis";
|
||||
"ledger.catalog.emptyEvents" = "Simpan acara untuk memakai kembali kota dan tempatnya.";
|
||||
"ledger.catalog.emptyMembers" = "Tambahkan grup dan anggota untuk memulai.";
|
||||
"ledger.combinedHint" = "Anggota dengan identitas yang sama dihitung gabungan lintas grup.";
|
||||
"ledger.copyTemplate" = "Salin templat";
|
||||
"ledger.error.avatar" = "Avatar harus berupa gambar JPEG yang valid.";
|
||||
"ledger.error.avatarSize" = "Avatar terlalu besar. Batasnya 2 MB.";
|
||||
"ledger.error.color" = "Gunakan kode warna enam digit dalam format #RRGGBB.";
|
||||
"ledger.error.currency" = "Mata uang ini tidak didukung.";
|
||||
"ledger.error.currencyRequired" = "Pilih satu mata uang untuk melihat peringkat pengeluaran.";
|
||||
"ledger.error.date" = "Gunakan tanggal valid dalam format yyyy-MM-dd.";
|
||||
"ledger.error.documentSize" = "Berkas impor terlalu besar. Batasnya 20 MB.";
|
||||
"ledger.error.duplicateID" = "ID terduplikasi. Setiap item dalam daftar harus memiliki ID unik.";
|
||||
"ledger.error.emptyField" = "Kolom ini tidak boleh kosong.";
|
||||
"ledger.error.emptyImport" = "Tidak ada grup, anggota, jenis pembelian, acara atau catatan untuk diimpor.";
|
||||
"ledger.error.fieldType" = "Tipe kolom salah atau bernilai null. Periksa kolom di bawah sesuai templat.";
|
||||
"ledger.error.invalidJSON" = "Teks bukan JSON yang valid. Periksa koma, tanda kutip dan kurung.";
|
||||
"ledger.error.membership" = "Hubungan anggota dan grup tidak ada atau terduplikasi.";
|
||||
"ledger.error.missingField" = "Kolom wajib tidak ada. Tambahkan kolom yang ditampilkan di bawah.";
|
||||
"ledger.error.price" = "Harga satuan harus berupa bilangan bulat nonnegatif dalam unit terkecil mata uang.";
|
||||
"ledger.error.quantity" = "Jumlah harus berupa bilangan bulat positif.";
|
||||
"ledger.error.recordConflict" = "Catatan dengan ID ini memiliki isi berbeda. Gunakan ID baru untuk pembelian baru, atau edit catatan yang ada di aplikasi.";
|
||||
"ledger.error.reference" = "Item katalog yang dirujuk tidak ada. Tambahkan item atau perbaiki ID-nya.";
|
||||
"ledger.error.schemaVersion" = "Versi catatan ini tidak didukung. Atur schemaVersion ke 1.";
|
||||
"ledger.event.edit" = "Edit acara";
|
||||
"ledger.management.clearTitle" = "Hapus semua catatan pembelian?";
|
||||
"ledger.management.deleteTitle" = "Hapus catatan pembelian terpilih?";
|
||||
"ledger.member.edit" = "Edit anggota";
|
||||
"ledger.newRecord" = "Pembelian baru";
|
||||
"ledger.product.edit" = "Edit jenis pembelian";
|
||||
"ledger.replacesDemo" = "Impor ini mengganti data contoh catatan yang belum diedit.";
|
||||
"ledger.restoreHint" = "Item katalog dengan ID sama diperbarui. Pembelian identik tidak digandakan dan pembelian lain tetap disimpan.";
|
||||
"ledger.splitHint" = "Anggota di beberapa grup dapat dihitung gabungan atau dipisah per grup.";
|
||||
"ledger.stats" = "Statistik";
|
||||
"management.catalog.groupImpact" = "Arsipkan %d grup beserta afiliasinya. Afiliasi anggota di grup lain, pembelian, dan statistik tetap ada.";
|
||||
"management.catalog.memberImpact" = "Arsipkan %d anggota dan semua afiliasinya. Pembelian dan statistik tetap ada, dan catatan lama masih dapat diedit.";
|
||||
|
||||
// Image export
|
||||
@@ -0,0 +1,209 @@
|
||||
// Oshicue Keeps — ja
|
||||
|
||||
"import.file" = "ファイルを選択";
|
||||
"import.validate" = "形式を確認";
|
||||
"settings.title" = "設定";
|
||||
"settings.language" = "言語";
|
||||
"settings.followSystem" = "システム設定に従う";
|
||||
"settings.about" = "このアプリについて";
|
||||
"settings.version" = "バージョン";
|
||||
"common.done" = "完了";
|
||||
"common.cancel" = "キャンセル";
|
||||
"common.close" = "閉じる";
|
||||
"settings.readError" = "保存したデータを読み込めませんでした。";
|
||||
"settings.saveError" = "変更を保存できませんでした。";
|
||||
"settings.storageError" = "保存データに問題が発生しました。";
|
||||
"import.readError" = "ファイルを読み込めません。UTF-8 の JSON ファイルを選んでください。";
|
||||
"ledger.title" = "手帳";
|
||||
"ledger.add" = "記録を追加";
|
||||
"ledger.today" = "今日";
|
||||
"ledger.month" = "月";
|
||||
"ledger.year" = "年";
|
||||
"ledger.day" = "日";
|
||||
"ledger.lifetime" = "累計";
|
||||
"ledger.quantity" = "枚数";
|
||||
"ledger.spending" = "支出";
|
||||
"ledger.memberCombined" = "メンバー別・合算";
|
||||
"ledger.memberByGroup" = "メンバー別・グループ別";
|
||||
"ledger.group" = "グループ";
|
||||
"ledger.currency" = "通貨";
|
||||
"ledger.total" = "合計";
|
||||
"ledger.membersCount" = "%d 人";
|
||||
"ledger.itemsCount" = "%d 枚";
|
||||
"ledger.noRecords" = "この日の記録はありません";
|
||||
"ledger.noRecordsHint" = "+をタップして物販を記録しましょう。";
|
||||
"ledger.records" = "物販記録";
|
||||
"ledger.edit" = "編集";
|
||||
"ledger.delete" = "削除";
|
||||
"ledger.deleteTitle" = "この記録を削除しますか?";
|
||||
"ledger.deleteMessage" = "この記録の枚数と支出が集計から除かれます。";
|
||||
"ledger.manage" = "管理";
|
||||
"ledger.import" = "手帳を読み込む";
|
||||
"ledger.export" = "バックアップを書き出す";
|
||||
"ledger.backup" = "JSON バックアップ";
|
||||
"ledger.importHint" = "手帳の JSON を貼り付けるか、バックアップファイルを選び、プレビューを確認して読み込んでください。";
|
||||
"ledger.preview" = "プレビュー";
|
||||
"ledger.apply" = "読み込む";
|
||||
"ledger.summary" = "%d 人・%d 件の記録";
|
||||
"ledger.editRecord" = "物販記録を編集";
|
||||
"ledger.date" = "日付";
|
||||
"ledger.member" = "メンバー";
|
||||
"ledger.chooseMember" = "メンバーを選択";
|
||||
"ledger.chooseGroup" = "グループを選択";
|
||||
"ledger.type" = "物販の種類";
|
||||
"ledger.unitPrice" = "単価";
|
||||
"ledger.amount" = "金額";
|
||||
"ledger.event" = "イベント";
|
||||
"ledger.optional" = "任意";
|
||||
"ledger.noEvent" = "イベントなし";
|
||||
"ledger.city" = "市区町村";
|
||||
"ledger.venue" = "会場";
|
||||
"ledger.address" = "会場の住所";
|
||||
"ledger.note" = "メモ";
|
||||
"ledger.save" = "保存";
|
||||
"ledger.addMember" = "メンバーを追加";
|
||||
"ledger.addType" = "物販の種類を追加";
|
||||
"ledger.addEvent" = "イベントを追加";
|
||||
"ledger.priceHint" = "新規記録は選択日以前の同じメンバー・グループ・種類・通貨の最新単価、前回追加した同じ種類・通貨の単価、標準価格または 0 の順に入力します。手動変更でき、既存記録は元の単価を保持します。";
|
||||
"ledger.invalidPrice" = "0 以上の単価を入力してください。円とウォンは整数、他の通貨は小数点以下 2 桁まで使用できます。";
|
||||
"ledger.invalidQuantity" = "枚数は 1 以上で入力してください。";
|
||||
"ledger.requiredSelection" = "メンバー、グループ、物販の種類を選択してください。";
|
||||
"ledger.currencyHint" = "金額と支出ランキングは通貨ごとに集計します。自動換算や異なる通貨の合算は行いません。";
|
||||
"ledger.groupColor" = "担当カラー";
|
||||
"ledger.loadDemo" = "手帳のサンプルを読み込む";
|
||||
"ledger.loadDemoHint" = "サンプルのメンバーと物販記録で手帳機能を試せます。";
|
||||
"ledger.product.polaroid" = "チェキ";
|
||||
"ledger.product.wide" = "ワイドチェキ";
|
||||
"ledger.product.mobile" = "スマホ撮影";
|
||||
"ledger.demoRequiresEmpty" = "サンプルは空の手帳にのみ読み込めます。";
|
||||
"ledger.error.overflow" = "金額または枚数が大きすぎます。より小さい値を入力してください。";
|
||||
"ledger.previousMonth" = "前の月";
|
||||
"ledger.nextMonth" = "次の月";
|
||||
"ledger.catalog.members" = "メンバー";
|
||||
"ledger.catalog.products" = "物販の種類";
|
||||
"ledger.catalog.events" = "イベント";
|
||||
"ledger.catalog.add" = "項目を追加";
|
||||
"ledger.catalog.search" = "メンバー・グループ・種類・イベント名";
|
||||
"ledger.catalog.memberCount" = "メンバー %d 人";
|
||||
"ledger.catalog.noGroupMembers" = "このグループにはまだメンバーがいません。";
|
||||
"ledger.member.shared" = "複数グループに所属";
|
||||
"ledger.member.reuse" = "既存のメンバーと連携";
|
||||
"ledger.member.existing" = "既存のメンバー";
|
||||
"ledger.member.name" = "メンバー名";
|
||||
"ledger.member.photo" = "写真からアイコンを選択";
|
||||
"ledger.member.removePhoto" = "アイコンを削除";
|
||||
"ledger.member.identity" = "メンバーとアイコン";
|
||||
"ledger.member.identityHint" = "同じ人が別のグループでも活動する場合は、既存のメンバーと連携すると合算やグループ別の集計ができます。";
|
||||
"ledger.member.affiliation" = "所属グループと担当カラー";
|
||||
"ledger.member.prices" = "標準単価";
|
||||
"ledger.member.pricesHint" = "単価は空欄にして記録時に入力できます。グループごとに設定でき、変更しても過去の購入額は変わりません。";
|
||||
"ledger.member.photoError" = "この画像を読み込めませんでした。別の写真を選んでください。";
|
||||
"ledger.member.photoTooLarge" = "10 MB 未満の写真を選んでください。";
|
||||
"ledger.group.edit" = "グループを編集";
|
||||
"ledger.group.name" = "グループ名";
|
||||
"ledger.product.name" = "種類名";
|
||||
"ledger.event.name" = "イベント名";
|
||||
"ledger.event.hasDate" = "イベントの日付を設定";
|
||||
"ledger.member.add" = "メンバーを追加";
|
||||
"ledger.group.add" = "グループを追加";
|
||||
"ledger.product.add" = "物販の種類を追加";
|
||||
"ledger.event.add" = "イベントを追加";
|
||||
"ledger.period" = "集計期間";
|
||||
"ledger.rankingBy" = "集計対象";
|
||||
"ledger.metric" = "指標";
|
||||
"ledger.allTypes" = "すべての種類";
|
||||
"ledger.allGroups" = "すべてのグループ";
|
||||
"ledger.backupHint" = "グループ、メンバー、アイコン、単価、物販記録をまとめてバックアップします。";
|
||||
"ledger.chooseRecord" = "編集する物販を選択";
|
||||
"ledger.chooseRecordHint" = "このメンバーには同じ日に複数の記録があります。編集する記録を選んでください。";
|
||||
"ledger.deleted" = "削除しました";
|
||||
"ledger.record.delete" = "この物販を削除";
|
||||
"ledger.member.delete" = "メンバーを削除";
|
||||
"ledger.member.deleteTitle" = "このメンバーを削除しますか?";
|
||||
"ledger.member.deleteMessage" = "このメンバーをすべてのグループから削除します。記録済みの物販と支出の統計は保持されます。";
|
||||
"ledger.group.delete" = "グループを削除";
|
||||
"ledger.group.deleteTitle" = "このグループを削除しますか?";
|
||||
"ledger.group.deleteMessage" = "このグループと所属情報を一覧から削除します。他のグループを兼任するメンバー、記録済みの物販、支出の統計は保持されます。";
|
||||
"ledger.catalogUnavailable" = "このメンバーまたはグループは削除されているため、資料の変更は保存できません。記録済みの物販は引き続き編集できます。";
|
||||
"settings.data" = "データ管理";
|
||||
"settings.localData" = "データはこの端末に保存されます。いつでも書き出してバックアップできます。";
|
||||
"settings.ledgerDemo" = "手帳のサンプルを読み込む";
|
||||
"ledger.member.favorite" = "お気に入りメンバー";
|
||||
"ledger.member.favoriteHint" = "お気に入りメンバーは物販のメンバー選択で先頭に表示します。同じメンバーのすべての所属で設定を共有します。";
|
||||
"ledger.members.favorites" = "お気に入りメンバー";
|
||||
"management.records" = "記録の管理";
|
||||
"management.backup" = "バックアップ";
|
||||
"management.filters" = "絞り込み";
|
||||
"management.search" = "メンバー・グループ・種類・イベント・メモを検索";
|
||||
"management.dateRange" = "日付範囲で絞り込む";
|
||||
"management.startDate" = "開始日";
|
||||
"management.endDate" = "終了日";
|
||||
"management.invalidDateRange" = "開始日は終了日以前にしてください。";
|
||||
"management.all" = "すべて";
|
||||
"management.selectFiltered" = "検索結果をすべて選択";
|
||||
"management.clearSelection" = "選択を解除";
|
||||
"management.selectionHint" = "選択した記録だけを削除します。絞り込みを変更すると選択が解除されます。";
|
||||
"management.selectedCount" = "%d 件選択中";
|
||||
"management.resultCount" = "%d 件の結果";
|
||||
"management.deleteSelected" = "選択項目を削除";
|
||||
"management.empty" = "該当する記録がありません";
|
||||
"management.clearAll" = "すべての物販記録を削除";
|
||||
"management.clearAllHint" = "すべての日付・メンバー・通貨の物販記録を削除します。グループ、メンバー、種類、イベント資料は保持します。";
|
||||
"ledger.management" = "手帳の管理";
|
||||
"ledger.management.deleteSummary" = "%d 件の記録、合計 %@ 点を削除します。";
|
||||
"ledger.management.deleteImpact" = "対象の数量と金額を集計から除きます。この操作は取り消せません。";
|
||||
"management.catalog" = "資料の整理";
|
||||
"management.catalog.search" = "メンバーまたはグループを検索";
|
||||
"management.catalog.hint" = "メンバー削除はすべての所属、グループ削除はそのグループだけに適用します。記録は保持し、有効なバックアップから資料を復元できます。";
|
||||
"management.catalog.empty" = "整理するメンバーやグループがありません";
|
||||
"management.catalog.deleteTitle" = "選択した資料を削除しますか?";
|
||||
"ledger.exportCSV" = "物販記録を書き出す(CSV)";
|
||||
"ledger.exportCSVHint" = "物販 1 件につき 1 行で、Numbers や Excel で閲覧・集計できます。CSV は閲覧用です。復元には JSON バックアップを使ってください。";
|
||||
"ledger.quickAdd.product" = "もう 1 つ追加:%@";
|
||||
"ledger.quickAddHint" = "⊕ をタップすると同じ記録の枚数が 1 増えます。単価やイベントなどは変わりません。";
|
||||
|
||||
"settings.keepsAbout" = "Oshicue Keeps · 応援の記録手帳。";
|
||||
"ledger.record.details" = "記録のラベル";
|
||||
"ledger.record.detailsHint" = "このラベルと色はこの記録と一緒に保存されます。メンバーや種類を変えると更新され、ここで過去の記録を直接修正できます。";
|
||||
|
||||
// Keys looked up through helpers and ternaries
|
||||
"import.copied" = "コピーしました";
|
||||
"ledger.calendar" = "カレンダー";
|
||||
"ledger.catalog" = "メンバー・種類";
|
||||
"ledger.catalog.emptyEvents" = "イベントを保存すると、市区町村や会場を次の記録でも使えます。";
|
||||
"ledger.catalog.emptyMembers" = "まずグループとメンバーを追加してください。";
|
||||
"ledger.combinedHint" = "同じ人物として連携したメンバーを、グループをまたいで合算します。";
|
||||
"ledger.copyTemplate" = "テンプレートをコピー";
|
||||
"ledger.error.avatar" = "アイコンには有効な JPEG 画像を使用してください。";
|
||||
"ledger.error.avatarSize" = "アイコン画像が大きすぎます。上限は 2 MB です。";
|
||||
"ledger.error.color" = "#RRGGBB 形式の 6 桁のカラーコードを使用してください。";
|
||||
"ledger.error.currency" = "この通貨には対応していません。";
|
||||
"ledger.error.currencyRequired" = "支出ランキングを表示する通貨を選択してください。";
|
||||
"ledger.error.date" = "yyyy-MM-dd 形式の有効な日付を使用してください。";
|
||||
"ledger.error.documentSize" = "読み込むファイルが大きすぎます。上限は 20 MB です。";
|
||||
"ledger.error.duplicateID" = "ID が重複しています。同じ一覧内の各項目には固有の ID が必要です。";
|
||||
"ledger.error.emptyField" = "この項目は空にできません。";
|
||||
"ledger.error.emptyImport" = "読み込むグループ、メンバー、物販の種類、イベント、記録がありません。";
|
||||
"ledger.error.fieldType" = "項目の型が違うか、null になっています。テンプレートと下に表示された項目を照合してください。";
|
||||
"ledger.error.invalidJSON" = "有効な JSON ではありません。コンマ、引用符、括弧を確認してください。";
|
||||
"ledger.error.membership" = "メンバーとグループの所属情報が不足しているか重複しています。";
|
||||
"ledger.error.missingField" = "必須項目がありません。下に表示された項目を追加してください。";
|
||||
"ledger.error.price" = "単価は通貨の最小単位で 0 以上の整数を指定してください。";
|
||||
"ledger.error.quantity" = "枚数は正の整数にしてください。";
|
||||
"ledger.error.recordConflict" = "同じ ID の記録と内容が異なります。新しい購入には新しい ID を使用し、既存の記録はアプリで編集してください。";
|
||||
"ledger.error.reference" = "参照先の項目がありません。項目を追加するか ID を修正してください。";
|
||||
"ledger.error.schemaVersion" = "この手帳の形式には対応していません。schemaVersion を 1 にしてください。";
|
||||
"ledger.event.edit" = "イベントを編集";
|
||||
"ledger.management.clearTitle" = "すべての物販記録を削除しますか?";
|
||||
"ledger.management.deleteTitle" = "選択した物販記録を削除しますか?";
|
||||
"ledger.member.edit" = "メンバーを編集";
|
||||
"ledger.newRecord" = "物販を記録";
|
||||
"ledger.product.edit" = "物販の種類を編集";
|
||||
"ledger.replacesDemo" = "この読み込みで、編集されていないサンプル手帳データを置き換えます。";
|
||||
"ledger.restoreHint" = "同じ ID のメンバー、グループ、テンプレートは更新されます。同一の購入記録は重複せず、他の保存済み記録は残ります。";
|
||||
"ledger.splitHint" = "複数のグループに所属するメンバーを合算するか、グループ別に集計するか選べます。";
|
||||
"ledger.stats" = "統計";
|
||||
"management.catalog.groupImpact" = "%d 組のグループと所属をアーカイブします。他グループの所属、物販と集計は保持します。";
|
||||
"management.catalog.memberImpact" = "%d 人のメンバーとすべての所属をアーカイブします。物販と集計は保持し、過去の記録は引き続き編集できます。";
|
||||
|
||||
// Image export
|
||||
@@ -0,0 +1,209 @@
|
||||
// Oshicue Keeps — ko
|
||||
|
||||
"import.file" = "파일 선택";
|
||||
"import.validate" = "형식 확인";
|
||||
"settings.title" = "설정";
|
||||
"settings.language" = "언어";
|
||||
"settings.followSystem" = "시스템 설정 따르기";
|
||||
"settings.about" = "앱 정보";
|
||||
"settings.version" = "버전";
|
||||
"common.done" = "완료";
|
||||
"common.cancel" = "취소";
|
||||
"common.close" = "닫기";
|
||||
"settings.readError" = "저장된 데이터를 읽을 수 없어요.";
|
||||
"settings.saveError" = "변경 사항을 저장할 수 없어요.";
|
||||
"settings.storageError" = "저장된 데이터에 문제가 발생했어요.";
|
||||
"import.readError" = "파일을 읽을 수 없어요. UTF-8 JSON 파일을 선택하세요.";
|
||||
"ledger.title" = "수첩";
|
||||
"ledger.add" = "기록 추가";
|
||||
"ledger.today" = "오늘";
|
||||
"ledger.month" = "월";
|
||||
"ledger.year" = "년";
|
||||
"ledger.day" = "일";
|
||||
"ledger.lifetime" = "전체 기간";
|
||||
"ledger.quantity" = "수량";
|
||||
"ledger.spending" = "지출 금액";
|
||||
"ledger.memberCombined" = "멤버별 합산";
|
||||
"ledger.memberByGroup" = "멤버별 · 그룹 구분";
|
||||
"ledger.group" = "그룹";
|
||||
"ledger.currency" = "통화";
|
||||
"ledger.total" = "합계";
|
||||
"ledger.membersCount" = "멤버 %d명";
|
||||
"ledger.itemsCount" = "%d장";
|
||||
"ledger.noRecords" = "이 날짜의 기록이 없어요";
|
||||
"ledger.noRecordsHint" = "+를 눌러 구매를 기록하세요.";
|
||||
"ledger.records" = "구매 기록";
|
||||
"ledger.edit" = "편집";
|
||||
"ledger.delete" = "삭제";
|
||||
"ledger.deleteTitle" = "이 기록을 삭제할까요?";
|
||||
"ledger.deleteMessage" = "이 기록의 수량과 금액이 통계에서 제외돼요.";
|
||||
"ledger.manage" = "관리";
|
||||
"ledger.import" = "기록 가져오기";
|
||||
"ledger.export" = "백업 내보내기";
|
||||
"ledger.backup" = "JSON 백업";
|
||||
"ledger.importHint" = "기록 JSON을 붙여 넣거나 백업 파일을 선택한 뒤 미리보기를 확인하세요.";
|
||||
"ledger.preview" = "미리보기";
|
||||
"ledger.apply" = "가져오기";
|
||||
"ledger.summary" = "멤버 %d명 · 기록 %d건";
|
||||
"ledger.editRecord" = "구매 기록 편집";
|
||||
"ledger.date" = "날짜";
|
||||
"ledger.member" = "멤버";
|
||||
"ledger.chooseMember" = "멤버 선택";
|
||||
"ledger.chooseGroup" = "그룹 선택";
|
||||
"ledger.type" = "구매 유형";
|
||||
"ledger.unitPrice" = "단가";
|
||||
"ledger.amount" = "금액";
|
||||
"ledger.event" = "행사";
|
||||
"ledger.optional" = "선택 사항";
|
||||
"ledger.noEvent" = "행사 연결 안 함";
|
||||
"ledger.city" = "도시";
|
||||
"ledger.venue" = "공연장";
|
||||
"ledger.address" = "공연장 주소";
|
||||
"ledger.note" = "메모";
|
||||
"ledger.save" = "저장";
|
||||
"ledger.addMember" = "멤버 추가";
|
||||
"ledger.addType" = "구매 유형 추가";
|
||||
"ledger.addEvent" = "행사 추가";
|
||||
"ledger.priceHint" = "새 기록은 선택일 당일 또는 이전의 같은 멤버·그룹·유형·통화 최신 가격, 마지막에 추가한 같은 유형·통화 가격, 기본 가격 또는 0 순서로 채웁니다. 직접 수정할 수 있으며 기존 기록은 원래 가격을 유지합니다.";
|
||||
"ledger.invalidPrice" = "0 이상인 단가를 입력하세요. 엔화와 원화는 정수, 다른 통화는 소수 둘째 자리까지 사용할 수 있어요.";
|
||||
"ledger.invalidQuantity" = "수량은 1 이상이어야 해요.";
|
||||
"ledger.requiredSelection" = "멤버, 그룹, 구매 유형을 선택하세요.";
|
||||
"ledger.currencyHint" = "금액과 지출 순위는 통화별로 집계해요. 서로 다른 통화를 자동 환전하거나 합산하지 않아요.";
|
||||
"ledger.groupColor" = "대표색";
|
||||
"ledger.loadDemo" = "기록 예시 불러오기";
|
||||
"ledger.loadDemoHint" = "예시 멤버와 구매 기록으로 기능을 살펴보세요.";
|
||||
"ledger.product.polaroid" = "체키";
|
||||
"ledger.product.wide" = "와이드 체키";
|
||||
"ledger.product.mobile" = "휴대폰 사진";
|
||||
"ledger.demoRequiresEmpty" = "비어 있는 수첩에만 예시를 불러올 수 있어요.";
|
||||
"ledger.error.overflow" = "금액이나 수량이 너무 커요. 더 작은 값을 입력하세요.";
|
||||
"ledger.previousMonth" = "이전 달";
|
||||
"ledger.nextMonth" = "다음 달";
|
||||
"ledger.catalog.members" = "멤버";
|
||||
"ledger.catalog.products" = "구매 유형";
|
||||
"ledger.catalog.events" = "행사";
|
||||
"ledger.catalog.add" = "항목 추가";
|
||||
"ledger.catalog.search" = "멤버 / 그룹 / 유형 / 행사명";
|
||||
"ledger.catalog.memberCount" = "멤버 %d명";
|
||||
"ledger.catalog.noGroupMembers" = "이 그룹에는 아직 멤버가 없어요.";
|
||||
"ledger.member.shared" = "여러 그룹 소속";
|
||||
"ledger.member.reuse" = "기존 멤버 연결";
|
||||
"ledger.member.existing" = "기존 멤버";
|
||||
"ledger.member.name" = "멤버 이름";
|
||||
"ledger.member.photo" = "사진에서 프로필 선택";
|
||||
"ledger.member.removePhoto" = "프로필 사진 제거";
|
||||
"ledger.member.identity" = "멤버 및 프로필 사진";
|
||||
"ledger.member.identityHint" = "같은 사람이 다른 그룹에서도 활동하면 기존 멤버에 연결해 합산하거나 그룹별로 나눠 집계하세요.";
|
||||
"ledger.member.affiliation" = "소속 그룹 및 대표색";
|
||||
"ledger.member.prices" = "기본 단가";
|
||||
"ledger.member.pricesHint" = "단가는 비워 두고 기록할 때 입력해도 돼요. 그룹별로 가격을 정할 수 있으며 변경해도 과거 구매 금액은 유지돼요.";
|
||||
"ledger.member.photoError" = "이미지를 불러올 수 없어요. 다른 사진을 선택하세요.";
|
||||
"ledger.member.photoTooLarge" = "10 MB보다 작은 사진을 선택하세요.";
|
||||
"ledger.group.edit" = "그룹 편집";
|
||||
"ledger.group.name" = "그룹 이름";
|
||||
"ledger.product.name" = "유형 이름";
|
||||
"ledger.event.name" = "행사명";
|
||||
"ledger.event.hasDate" = "행사 날짜 지정";
|
||||
"ledger.member.add" = "멤버 추가";
|
||||
"ledger.group.add" = "그룹 추가";
|
||||
"ledger.product.add" = "구매 유형 추가";
|
||||
"ledger.event.add" = "행사 추가";
|
||||
"ledger.period" = "집계 기간";
|
||||
"ledger.rankingBy" = "집계 기준";
|
||||
"ledger.metric" = "정렬 항목";
|
||||
"ledger.allTypes" = "모든 유형";
|
||||
"ledger.allGroups" = "모든 그룹";
|
||||
"ledger.backupHint" = "그룹, 멤버, 프로필 사진, 단가, 구매 기록을 함께 백업하세요.";
|
||||
"ledger.chooseRecord" = "수정할 물판 기록 선택";
|
||||
"ledger.chooseRecordHint" = "이 멤버는 같은 날짜에 기록이 여러 개 있습니다. 수정할 기록을 선택하세요.";
|
||||
"ledger.deleted" = "삭제됨";
|
||||
"ledger.record.delete" = "이 물판 기록 삭제";
|
||||
"ledger.member.delete" = "멤버 삭제";
|
||||
"ledger.member.deleteTitle" = "이 멤버를 삭제할까요?";
|
||||
"ledger.member.deleteMessage" = "이 멤버는 모든 그룹에서 삭제됩니다. 기존 물판 기록과 지출 통계는 유지됩니다.";
|
||||
"ledger.group.delete" = "그룹 삭제";
|
||||
"ledger.group.deleteTitle" = "이 그룹을 삭제할까요?";
|
||||
"ledger.group.deleteMessage" = "이 그룹과 소속 정보가 목록에서 삭제됩니다. 다른 그룹에도 소속된 멤버, 기존 물판 기록과 지출 통계는 유지됩니다.";
|
||||
"ledger.catalogUnavailable" = "이 멤버 또는 그룹은 삭제되어 정보 변경을 저장할 수 없습니다. 기존 물판 기록은 계속 수정할 수 있습니다.";
|
||||
"settings.data" = "데이터 관리";
|
||||
"settings.localData" = "데이터는 이 기기에 저장돼요. 필요할 때 언제든 백업을 내보낼 수 있어요.";
|
||||
"settings.ledgerDemo" = "수첩 예시 불러오기";
|
||||
"ledger.member.favorite" = "최애 멤버";
|
||||
"ledger.member.favoriteHint" = "최애 멤버는 물판 기록의 멤버 선택에서 맨 위에 표시됩니다. 같은 멤버의 모든 그룹 소속에서 이 설정을 공유합니다.";
|
||||
"ledger.members.favorites" = "최애 멤버";
|
||||
"management.records" = "기록 관리";
|
||||
"management.backup" = "백업";
|
||||
"management.filters" = "필터";
|
||||
"management.search" = "멤버, 그룹, 유형, 행사 또는 메모 검색";
|
||||
"management.dateRange" = "날짜 범위로 필터링";
|
||||
"management.startDate" = "시작 날짜";
|
||||
"management.endDate" = "종료 날짜";
|
||||
"management.invalidDateRange" = "시작 날짜는 종료 날짜보다 늦을 수 없습니다.";
|
||||
"management.all" = "전체";
|
||||
"management.selectFiltered" = "검색 결과 모두 선택";
|
||||
"management.clearSelection" = "선택 해제";
|
||||
"management.selectionHint" = "선택한 기록만 삭제합니다. 필터를 바꾸면 선택이 해제됩니다.";
|
||||
"management.selectedCount" = "%d개 선택";
|
||||
"management.resultCount" = "결과 %d개";
|
||||
"management.deleteSelected" = "선택 항목 삭제";
|
||||
"management.empty" = "조건에 맞는 기록이 없습니다";
|
||||
"management.clearAll" = "모든 물판 기록 삭제";
|
||||
"management.clearAllHint" = "모든 날짜, 멤버, 통화의 물판 기록을 삭제합니다. 그룹, 멤버, 유형, 행사 자료는 유지됩니다.";
|
||||
"ledger.management" = "수첩 관리";
|
||||
"ledger.management.deleteSummary" = "기록 %d개, 총 %@개를 삭제합니다.";
|
||||
"ledger.management.deleteImpact" = "해당 수량과 금액이 통계에서 제외됩니다. 이 작업은 되돌릴 수 없습니다.";
|
||||
"management.catalog" = "자료 정리";
|
||||
"management.catalog.search" = "멤버 또는 그룹 검색";
|
||||
"management.catalog.hint" = "멤버 삭제는 모든 소속에, 그룹 삭제는 해당 그룹에만 적용됩니다. 기존 기록은 남으며 유효한 백업으로 자료를 복원할 수 있습니다.";
|
||||
"management.catalog.empty" = "정리할 멤버나 그룹이 없습니다";
|
||||
"management.catalog.deleteTitle" = "선택한 자료를 삭제할까요?";
|
||||
"ledger.exportCSV" = "구매 기록 내보내기(CSV)";
|
||||
"ledger.exportCSVHint" = "구매 1건당 한 행으로 Numbers나 Excel에서 보고 합계를 낼 수 있어요. CSV는 보기용이며, 복원에는 JSON 백업을 사용하세요.";
|
||||
"ledger.quickAdd.product" = "하나 더 추가: %@";
|
||||
"ledger.quickAddHint" = "⊕를 탭하면 같은 구매의 수량이 1 늘어나요. 단가와 행사 등은 그대로예요.";
|
||||
|
||||
"settings.keepsAbout" = "Oshicue Keeps · 응원 기록 수첩.";
|
||||
"ledger.record.details" = "기록 라벨";
|
||||
"ledger.record.detailsHint" = "이 라벨과 색상은 이 기록과 함께 저장됩니다. 멤버나 유형을 바꾸면 갱신되며, 여기에서 지난 기록을 직접 고칠 수 있어요.";
|
||||
|
||||
// Keys looked up through helpers and ternaries
|
||||
"import.copied" = "복사했어요";
|
||||
"ledger.calendar" = "달력";
|
||||
"ledger.catalog" = "멤버 및 유형";
|
||||
"ledger.catalog.emptyEvents" = "행사를 저장하면 도시와 공연장 정보를 다시 사용할 수 있어요.";
|
||||
"ledger.catalog.emptyMembers" = "먼저 그룹과 멤버를 추가하세요.";
|
||||
"ledger.combinedHint" = "동일 인물로 연결된 멤버는 그룹에 관계없이 합산돼요.";
|
||||
"ledger.copyTemplate" = "템플릿 복사";
|
||||
"ledger.error.avatar" = "프로필 사진은 올바른 JPEG 이미지여야 해요.";
|
||||
"ledger.error.avatarSize" = "프로필 사진이 너무 커요. 최대 크기는 2 MB예요.";
|
||||
"ledger.error.color" = "#RRGGBB 형식의 6자리 색상 코드를 사용하세요.";
|
||||
"ledger.error.currency" = "지원하지 않는 통화예요.";
|
||||
"ledger.error.currencyRequired" = "지출 순위를 보려면 통화를 선택하세요.";
|
||||
"ledger.error.date" = "yyyy-MM-dd 형식의 올바른 날짜를 사용하세요.";
|
||||
"ledger.error.documentSize" = "가져올 파일이 너무 커요. 최대 크기는 20 MB예요.";
|
||||
"ledger.error.duplicateID" = "ID가 중복돼요. 같은 목록의 각 항목에는 고유한 ID가 필요해요.";
|
||||
"ledger.error.emptyField" = "이 필드는 비워 둘 수 없어요.";
|
||||
"ledger.error.emptyImport" = "가져올 그룹, 멤버, 구매 유형, 행사, 기록이 없어요.";
|
||||
"ledger.error.fieldType" = "필드 유형이 잘못됐거나 null이에요. 아래 필드를 템플릿과 비교해 확인하세요.";
|
||||
"ledger.error.invalidJSON" = "올바른 JSON이 아니에요. 쉼표, 따옴표, 괄호를 확인하세요.";
|
||||
"ledger.error.membership" = "멤버와 그룹의 소속 정보가 없거나 중복돼요.";
|
||||
"ledger.error.missingField" = "필수 필드가 없어요. 아래에 표시된 필드를 추가하세요.";
|
||||
"ledger.error.price" = "단가는 통화의 최소 단위로 0 이상의 정수를 입력해야 해요.";
|
||||
"ledger.error.quantity" = "수량은 양의 정수여야 해요.";
|
||||
"ledger.error.recordConflict" = "같은 ID의 기록과 내용이 달라요. 새 구매에는 새 ID를 사용하고 기존 기록은 앱에서 편집하세요.";
|
||||
"ledger.error.reference" = "참조하는 항목이 없어요. 항목을 추가하거나 ID를 수정하세요.";
|
||||
"ledger.error.schemaVersion" = "지원하지 않는 기록 형식이에요. schemaVersion을 1로 설정하세요.";
|
||||
"ledger.event.edit" = "행사 편집";
|
||||
"ledger.management.clearTitle" = "모든 물판 기록을 삭제할까요?";
|
||||
"ledger.management.deleteTitle" = "선택한 물판 기록을 삭제할까요?";
|
||||
"ledger.member.edit" = "멤버 편집";
|
||||
"ledger.newRecord" = "새 구매 기록";
|
||||
"ledger.product.edit" = "구매 유형 편집";
|
||||
"ledger.replacesDemo" = "이번 가져오기는 수정하지 않은 예시 수첩 데이터를 대체해요.";
|
||||
"ledger.restoreHint" = "같은 ID의 멤버, 그룹, 템플릿은 갱신돼요. 동일한 구매 기록은 중복 추가되지 않으며 다른 저장 기록은 유지돼요.";
|
||||
"ledger.splitHint" = "여러 그룹에서 활동하는 멤버를 합산하거나 그룹별로 나눠 집계할 수 있어요.";
|
||||
"ledger.stats" = "통계";
|
||||
"management.catalog.groupImpact" = "그룹 %d개와 소속을 보관 처리합니다. 다른 그룹의 멤버 소속, 물판과 통계는 유지됩니다.";
|
||||
"management.catalog.memberImpact" = "멤버 %d명과 모든 소속을 보관 처리합니다. 물판과 통계는 남고 과거 기록도 계속 수정할 수 있습니다.";
|
||||
|
||||
// Image export
|
||||
@@ -0,0 +1,209 @@
|
||||
// Oshicue Keeps — ms
|
||||
|
||||
"import.file" = "Pilih fail";
|
||||
"import.validate" = "Semak format";
|
||||
"settings.title" = "Tetapan";
|
||||
"settings.language" = "Bahasa";
|
||||
"settings.followSystem" = "Ikut sistem";
|
||||
"settings.about" = "Tentang";
|
||||
"settings.version" = "Versi";
|
||||
"common.done" = "Selesai";
|
||||
"common.cancel" = "Batal";
|
||||
"common.close" = "Tutup";
|
||||
"settings.readError" = "Tidak dapat membaca data yang disimpan.";
|
||||
"settings.saveError" = "Tidak dapat menyimpan perubahan.";
|
||||
"settings.storageError" = "Terdapat masalah dengan data yang disimpan.";
|
||||
"import.readError" = "Tidak dapat membaca fail. Pilih fail JSON berformat UTF-8.";
|
||||
"ledger.title" = "Catatan";
|
||||
"ledger.add" = "Tambah catatan";
|
||||
"ledger.today" = "Hari ini";
|
||||
"ledger.month" = "Bulan";
|
||||
"ledger.year" = "Tahun";
|
||||
"ledger.day" = "Hari";
|
||||
"ledger.lifetime" = "Sepanjang masa";
|
||||
"ledger.quantity" = "Kuantiti";
|
||||
"ledger.spending" = "Perbelanjaan";
|
||||
"ledger.memberCombined" = "Ahli · gabungan";
|
||||
"ledger.memberByGroup" = "Ahli · mengikut kumpulan";
|
||||
"ledger.group" = "Kumpulan";
|
||||
"ledger.currency" = "Mata wang";
|
||||
"ledger.total" = "Jumlah";
|
||||
"ledger.membersCount" = "%d ahli";
|
||||
"ledger.itemsCount" = "%d keping";
|
||||
"ledger.noRecords" = "Tiada catatan pada tarikh ini";
|
||||
"ledger.noRecordsHint" = "Ketik + untuk mencatat pembelian.";
|
||||
"ledger.records" = "Catatan pembelian";
|
||||
"ledger.edit" = "Edit";
|
||||
"ledger.delete" = "Padam";
|
||||
"ledger.deleteTitle" = "Padam catatan ini?";
|
||||
"ledger.deleteMessage" = "Kuantiti dan perbelanjaannya akan dikeluarkan daripada jumlah.";
|
||||
"ledger.manage" = "Urus";
|
||||
"ledger.import" = "Import catatan";
|
||||
"ledger.export" = "Eksport sandaran";
|
||||
"ledger.backup" = "Sandaran JSON";
|
||||
"ledger.importHint" = "Tampal JSON catatan atau pilih fail sandaran. Semak pratonton sebelum mengimport.";
|
||||
"ledger.preview" = "Pratonton";
|
||||
"ledger.apply" = "Import";
|
||||
"ledger.summary" = "%d ahli · %d catatan";
|
||||
"ledger.editRecord" = "Edit pembelian";
|
||||
"ledger.date" = "Tarikh";
|
||||
"ledger.member" = "Ahli";
|
||||
"ledger.chooseMember" = "Pilih ahli";
|
||||
"ledger.chooseGroup" = "Pilih kumpulan";
|
||||
"ledger.type" = "Jenis pembelian";
|
||||
"ledger.unitPrice" = "Harga seunit";
|
||||
"ledger.amount" = "Amaun";
|
||||
"ledger.event" = "Acara";
|
||||
"ledger.optional" = "Pilihan";
|
||||
"ledger.noEvent" = "Tanpa acara";
|
||||
"ledger.city" = "Bandar";
|
||||
"ledger.venue" = "Tempat";
|
||||
"ledger.address" = "Alamat tempat";
|
||||
"ledger.note" = "Nota";
|
||||
"ledger.save" = "Simpan";
|
||||
"ledger.addMember" = "Tambah ahli";
|
||||
"ledger.addType" = "Tambah jenis pembelian";
|
||||
"ledger.addEvent" = "Tambah acara";
|
||||
"ledger.priceHint" = "Pembelian baharu menggunakan harga terkini pada atau sebelum tarikh dipilih bagi ahli, kumpulan, jenis dan mata wang yang sama, kemudian harga penambahan terakhir bagi jenis dan mata wang itu, kemudian harga lalai atau 0. Harga boleh disunting; rekod lama mengekalkan harga asal.";
|
||||
"ledger.invalidPrice" = "Masukkan harga bukan negatif. JPY dan KRW menggunakan nombor bulat; mata wang lain membenarkan maksimum dua tempat perpuluhan.";
|
||||
"ledger.invalidQuantity" = "Kuantiti mestilah sekurang-kurangnya 1.";
|
||||
"ledger.requiredSelection" = "Pilih ahli, kumpulan dan jenis pembelian.";
|
||||
"ledger.currencyHint" = "Jumlah dan kedudukan perbelanjaan dikira mengikut mata wang, tanpa penukaran atau penambahan antara mata wang.";
|
||||
"ledger.groupColor" = "Warna wakil";
|
||||
"ledger.loadDemo" = "Muatkan contoh catatan";
|
||||
"ledger.loadDemoHint" = "Terokai ciri dengan contoh ahli dan pembelian.";
|
||||
"ledger.product.polaroid" = "Cheki";
|
||||
"ledger.product.wide" = "Cheki lebar";
|
||||
"ledger.product.mobile" = "Foto telefon";
|
||||
"ledger.demoRequiresEmpty" = "Contoh hanya boleh dimuatkan ke catatan kosong.";
|
||||
"ledger.error.overflow" = "Amaun atau kuantiti terlalu besar. Masukkan nilai yang lebih kecil.";
|
||||
"ledger.previousMonth" = "Bulan sebelumnya";
|
||||
"ledger.nextMonth" = "Bulan seterusnya";
|
||||
"ledger.catalog.members" = "Ahli";
|
||||
"ledger.catalog.products" = "Jenis pembelian";
|
||||
"ledger.catalog.events" = "Acara";
|
||||
"ledger.catalog.add" = "Tambah ke katalog";
|
||||
"ledger.catalog.search" = "Ahli / kumpulan / jenis / acara";
|
||||
"ledger.catalog.memberCount" = "%d ahli";
|
||||
"ledger.catalog.noGroupMembers" = "Kumpulan ini belum mempunyai ahli.";
|
||||
"ledger.member.shared" = "Ahli beberapa kumpulan";
|
||||
"ledger.member.reuse" = "Pautkan ahli sedia ada";
|
||||
"ledger.member.existing" = "Ahli sedia ada";
|
||||
"ledger.member.name" = "Nama ahli";
|
||||
"ledger.member.photo" = "Pilih avatar daripada Foto";
|
||||
"ledger.member.removePhoto" = "Buang avatar";
|
||||
"ledger.member.identity" = "Ahli & avatar";
|
||||
"ledger.member.identityHint" = "Bagi orang yang sama dalam kumpulan lain, pautkan ahli sedia ada supaya catatan boleh dikira bersama atau berasingan.";
|
||||
"ledger.member.affiliation" = "Kumpulan & warna wakil";
|
||||
"ledger.member.prices" = "Harga seunit lalai";
|
||||
"ledger.member.pricesHint" = "Harga boleh dikosongkan dan diisi semasa mencatat. Harga setiap kumpulan boleh berbeza; perubahan tidak mengubah pembelian terdahulu.";
|
||||
"ledger.member.photoError" = "Imej ini tidak dapat dimuatkan. Pilih foto lain.";
|
||||
"ledger.member.photoTooLarge" = "Pilih foto yang lebih kecil daripada 10 MB.";
|
||||
"ledger.group.edit" = "Edit kumpulan";
|
||||
"ledger.group.name" = "Nama kumpulan";
|
||||
"ledger.product.name" = "Nama jenis";
|
||||
"ledger.event.name" = "Nama acara";
|
||||
"ledger.event.hasDate" = "Sertakan tarikh acara";
|
||||
"ledger.member.add" = "Tambah ahli";
|
||||
"ledger.group.add" = "Tambah kumpulan";
|
||||
"ledger.product.add" = "Tambah jenis pembelian";
|
||||
"ledger.event.add" = "Tambah acara";
|
||||
"ledger.period" = "Tempoh";
|
||||
"ledger.rankingBy" = "Asas kedudukan";
|
||||
"ledger.metric" = "Ukuran";
|
||||
"ledger.allTypes" = "Semua jenis";
|
||||
"ledger.allGroups" = "Semua kumpulan";
|
||||
"ledger.backupHint" = "Sandarkan kumpulan, ahli, avatar, harga dan sejarah pembelian bersama.";
|
||||
"ledger.chooseRecord" = "Pilih pembelian untuk disunting";
|
||||
"ledger.chooseRecordHint" = "Ahli ini mempunyai beberapa rekod pada tarikh ini. Pilih satu untuk disunting.";
|
||||
"ledger.deleted" = "Dipadam";
|
||||
"ledger.record.delete" = "Padam pembelian ini";
|
||||
"ledger.member.delete" = "Padam ahli";
|
||||
"ledger.member.deleteTitle" = "Padam ahli ini?";
|
||||
"ledger.member.deleteMessage" = "Ahli ini akan dikeluarkan daripada semua kumpulan. Pembelian dan statistik perbelanjaan yang telah direkodkan akan dikekalkan.";
|
||||
"ledger.group.delete" = "Padam kumpulan";
|
||||
"ledger.group.deleteTitle" = "Padam kumpulan ini?";
|
||||
"ledger.group.deleteMessage" = "Kumpulan ini dan hubungan keahliannya akan dikeluarkan daripada katalog. Ahli yang turut menganggotai kumpulan lain, pembelian yang telah direkodkan dan statistik perbelanjaan akan dikekalkan.";
|
||||
"ledger.catalogUnavailable" = "Ahli atau kumpulan ini telah dipadam, jadi perubahan katalog ini tidak dapat disimpan. Pembelian sedia ada masih boleh disunting.";
|
||||
"settings.data" = "Pengurusan data";
|
||||
"settings.localData" = "Data disimpan pada peranti ini. Eksport sandaran apabila diperlukan.";
|
||||
"settings.ledgerDemo" = "Muat contoh catatan";
|
||||
"ledger.member.favorite" = "Ahli kegemaran";
|
||||
"ledger.member.favoriteHint" = "Ahli kegemaran dipaparkan di atas apabila memilih ahli untuk pembelian. Tetapan ini dikongsi antara semua kumpulan ahli itu.";
|
||||
"ledger.members.favorites" = "Ahli kegemaran";
|
||||
"management.records" = "Urus rekod";
|
||||
"management.backup" = "Sandaran";
|
||||
"management.filters" = "Penapis";
|
||||
"management.search" = "Cari ahli, kumpulan, jenis, acara atau nota";
|
||||
"management.dateRange" = "Tapis mengikut julat tarikh";
|
||||
"management.startDate" = "Tarikh mula";
|
||||
"management.endDate" = "Tarikh akhir";
|
||||
"management.invalidDateRange" = "Tarikh mula tidak boleh selepas tarikh akhir.";
|
||||
"management.all" = "Semua";
|
||||
"management.selectFiltered" = "Pilih semua hasil";
|
||||
"management.clearSelection" = "Kosongkan pilihan";
|
||||
"management.selectionHint" = "Hanya rekod terpilih dipadam. Menukar penapis mengosongkan pilihan.";
|
||||
"management.selectedCount" = "%d dipilih";
|
||||
"management.resultCount" = "%d hasil";
|
||||
"management.deleteSelected" = "Padam yang dipilih";
|
||||
"management.empty" = "Tiada rekod sepadan";
|
||||
"management.clearAll" = "Padam semua rekod pembelian";
|
||||
"management.clearAllHint" = "Pemadaman semua pembelian meliputi setiap tarikh, ahli dan mata wang. Kumpulan, ahli, jenis dan maklumat acara dikekalkan.";
|
||||
"ledger.management" = "Urus Catatan";
|
||||
"ledger.management.deleteSummary" = "Padam %d rekod dengan jumlah %@ unit.";
|
||||
"ledger.management.deleteImpact" = "Kuantiti dan amaunnya dikeluarkan daripada statistik. Tindakan ini tidak boleh dibatalkan.";
|
||||
"management.catalog" = "Pembersihan data ahli dan kumpulan";
|
||||
"management.catalog.search" = "Cari ahli atau kumpulan";
|
||||
"management.catalog.hint" = "Memadam ahli melibatkan semua keahliannya; memadam kumpulan hanya melibatkan kumpulan itu. Rekod lama kekal dan sandaran sah boleh memulihkan data.";
|
||||
"management.catalog.empty" = "Tiada ahli atau kumpulan untuk dibersihkan";
|
||||
"management.catalog.deleteTitle" = "Padam data terpilih?";
|
||||
"ledger.exportCSV" = "Eksport pembelian (CSV)";
|
||||
"ledger.exportCSVHint" = "Satu baris bagi setiap pembelian, untuk dilihat dan dijumlahkan dalam Numbers atau Excel. CSV hanya untuk dibaca; gunakan sandaran JSON untuk memulihkan data.";
|
||||
"ledger.quickAdd.product" = "Tambah satu lagi: %@";
|
||||
"ledger.quickAddHint" = "Ketik ⊕ untuk menambah satu pada pembelian yang sama. Harga dan butirannya kekal.";
|
||||
|
||||
"settings.keepsAbout" = "Oshicue Keeps · Buku catatan aktiviti peminat anda.";
|
||||
"ledger.record.details" = "Label rekod";
|
||||
"ledger.record.detailsHint" = "Label dan warna ini disimpan bersama rekod. Menukar ahli atau jenis akan mengemas kininya; sunting di sini untuk membetulkan rekod lama.";
|
||||
|
||||
// Keys looked up through helpers and ternaries
|
||||
"import.copied" = "Disalin";
|
||||
"ledger.calendar" = "Kalendar";
|
||||
"ledger.catalog" = "Ahli & jenis";
|
||||
"ledger.catalog.emptyEvents" = "Simpan acara untuk menggunakan semula bandar dan tempatnya.";
|
||||
"ledger.catalog.emptyMembers" = "Tambah kumpulan dan ahli untuk bermula.";
|
||||
"ledger.combinedHint" = "Ahli dengan identiti yang sama dikira bersama merentas kumpulan.";
|
||||
"ledger.copyTemplate" = "Salin templat";
|
||||
"ledger.error.avatar" = "Avatar mestilah imej JPEG yang sah.";
|
||||
"ledger.error.avatarSize" = "Avatar terlalu besar. Hadnya ialah 2 MB.";
|
||||
"ledger.error.color" = "Gunakan kod warna enam digit dalam format #RRGGBB.";
|
||||
"ledger.error.currency" = "Mata wang ini tidak disokong.";
|
||||
"ledger.error.currencyRequired" = "Pilih satu mata wang untuk melihat kedudukan perbelanjaan.";
|
||||
"ledger.error.date" = "Gunakan tarikh sah dalam format yyyy-MM-dd.";
|
||||
"ledger.error.documentSize" = "Fail import terlalu besar. Hadnya ialah 20 MB.";
|
||||
"ledger.error.duplicateID" = "ID berulang. Setiap item dalam senarai mesti mempunyai ID unik.";
|
||||
"ledger.error.emptyField" = "Medan ini tidak boleh kosong.";
|
||||
"ledger.error.emptyImport" = "Tiada kumpulan, ahli, jenis pembelian, acara atau catatan untuk diimport.";
|
||||
"ledger.error.fieldType" = "Jenis medan salah atau bernilai null. Semak medan di bawah mengikut templat.";
|
||||
"ledger.error.invalidJSON" = "Teks bukan JSON yang sah. Semak koma, tanda petik dan kurungan.";
|
||||
"ledger.error.membership" = "Hubungan ahli dan kumpulan tiada atau berulang.";
|
||||
"ledger.error.missingField" = "Medan wajib tiada. Tambahkan medan yang dipaparkan di bawah.";
|
||||
"ledger.error.price" = "Harga seunit mestilah nombor bulat bukan negatif dalam unit terkecil mata wang.";
|
||||
"ledger.error.quantity" = "Kuantiti mestilah nombor bulat positif.";
|
||||
"ledger.error.recordConflict" = "Catatan dengan ID ini mempunyai kandungan berbeza. Gunakan ID baharu untuk pembelian baharu, atau edit catatan sedia ada dalam aplikasi.";
|
||||
"ledger.error.reference" = "Item katalog yang dirujuk tiada. Tambah item atau betulkan ID.";
|
||||
"ledger.error.schemaVersion" = "Versi catatan ini tidak disokong. Tetapkan schemaVersion kepada 1.";
|
||||
"ledger.event.edit" = "Edit acara";
|
||||
"ledger.management.clearTitle" = "Padam semua rekod pembelian?";
|
||||
"ledger.management.deleteTitle" = "Padam rekod pembelian terpilih?";
|
||||
"ledger.member.edit" = "Edit ahli";
|
||||
"ledger.newRecord" = "Pembelian baharu";
|
||||
"ledger.product.edit" = "Edit jenis pembelian";
|
||||
"ledger.replacesDemo" = "Import ini menggantikan data contoh catatan yang belum diedit.";
|
||||
"ledger.restoreHint" = "Item katalog dengan ID yang sama dikemas kini. Pembelian yang sama tidak diduakan dan pembelian lain dikekalkan.";
|
||||
"ledger.splitHint" = "Ahli dalam beberapa kumpulan boleh dikira bersama atau berasingan mengikut kumpulan.";
|
||||
"ledger.stats" = "Statistik";
|
||||
"management.catalog.groupImpact" = "Arkibkan %d kumpulan serta keahliannya. Keahlian ahli dalam kumpulan lain, pembelian dan statistik dikekalkan.";
|
||||
"management.catalog.memberImpact" = "Arkibkan %d ahli dan semua keahliannya. Pembelian dan statistik kekal, dan rekod lama masih boleh disunting.";
|
||||
|
||||
// Image export
|
||||
@@ -0,0 +1,209 @@
|
||||
// Oshicue Keeps — th
|
||||
|
||||
"import.file" = "เลือกไฟล์";
|
||||
"import.validate" = "ตรวจสอบรูปแบบ";
|
||||
"settings.title" = "การตั้งค่า";
|
||||
"settings.language" = "ภาษา";
|
||||
"settings.followSystem" = "ตามระบบ";
|
||||
"settings.about" = "เกี่ยวกับ";
|
||||
"settings.version" = "เวอร์ชัน";
|
||||
"common.done" = "เสร็จสิ้น";
|
||||
"common.cancel" = "ยกเลิก";
|
||||
"common.close" = "ปิด";
|
||||
"settings.readError" = "อ่านข้อมูลที่บันทึกไว้ไม่ได้";
|
||||
"settings.saveError" = "บันทึกการเปลี่ยนแปลงไม่ได้";
|
||||
"settings.storageError" = "เกิดปัญหากับข้อมูลที่บันทึกไว้";
|
||||
"import.readError" = "อ่านไฟล์ไม่ได้ โปรดเลือกไฟล์ JSON ที่เข้ารหัส UTF-8";
|
||||
"ledger.title" = "สมุดบันทึก";
|
||||
"ledger.add" = "เพิ่มบันทึก";
|
||||
"ledger.today" = "วันนี้";
|
||||
"ledger.month" = "เดือน";
|
||||
"ledger.year" = "ปี";
|
||||
"ledger.day" = "วัน";
|
||||
"ledger.lifetime" = "สะสมทั้งหมด";
|
||||
"ledger.quantity" = "จำนวน";
|
||||
"ledger.spending" = "ยอดใช้จ่าย";
|
||||
"ledger.memberCombined" = "รวมตามสมาชิก";
|
||||
"ledger.memberByGroup" = "สมาชิกแยกตามวง";
|
||||
"ledger.group" = "วง";
|
||||
"ledger.currency" = "สกุลเงิน";
|
||||
"ledger.total" = "รวม";
|
||||
"ledger.membersCount" = "สมาชิก %d คน";
|
||||
"ledger.itemsCount" = "%d ใบ";
|
||||
"ledger.noRecords" = "ยังไม่มีบันทึกในวันนี้";
|
||||
"ledger.noRecordsHint" = "แตะ + เพื่อบันทึกการซื้อ";
|
||||
"ledger.records" = "บันทึกการซื้อ";
|
||||
"ledger.edit" = "แก้ไข";
|
||||
"ledger.delete" = "ลบ";
|
||||
"ledger.deleteTitle" = "ลบบันทึกนี้หรือไม่?";
|
||||
"ledger.deleteMessage" = "จำนวนและยอดใช้จ่ายของบันทึกนี้จะถูกหักออกจากยอดรวม";
|
||||
"ledger.manage" = "จัดการ";
|
||||
"ledger.import" = "นำเข้าบันทึก";
|
||||
"ledger.export" = "ส่งออกข้อมูลสำรอง";
|
||||
"ledger.backup" = "ข้อมูลสำรอง JSON";
|
||||
"ledger.importHint" = "วาง JSON ของบันทึก หรือเลือกไฟล์สำรอง แล้วตรวจสอบตัวอย่างก่อนนำเข้า";
|
||||
"ledger.preview" = "ดูตัวอย่าง";
|
||||
"ledger.apply" = "นำเข้า";
|
||||
"ledger.summary" = "สมาชิก %d คน · %d บันทึก";
|
||||
"ledger.editRecord" = "แก้ไขการซื้อ";
|
||||
"ledger.date" = "วันที่";
|
||||
"ledger.member" = "สมาชิก";
|
||||
"ledger.chooseMember" = "เลือกสมาชิก";
|
||||
"ledger.chooseGroup" = "เลือกวง";
|
||||
"ledger.type" = "ประเภทการซื้อ";
|
||||
"ledger.unitPrice" = "ราคาต่อหน่วย";
|
||||
"ledger.amount" = "ยอดเงิน";
|
||||
"ledger.event" = "งาน";
|
||||
"ledger.optional" = "ไม่บังคับ";
|
||||
"ledger.noEvent" = "ไม่เชื่อมโยงงาน";
|
||||
"ledger.city" = "เมือง";
|
||||
"ledger.venue" = "สถานที่";
|
||||
"ledger.address" = "ที่อยู่สถานที่";
|
||||
"ledger.note" = "หมายเหตุ";
|
||||
"ledger.save" = "บันทึก";
|
||||
"ledger.addMember" = "เพิ่มสมาชิก";
|
||||
"ledger.addType" = "เพิ่มประเภทการซื้อ";
|
||||
"ledger.addEvent" = "เพิ่มงาน";
|
||||
"ledger.priceHint" = "รายการใหม่ใช้ราคาล่าสุดในวันที่เลือกหรือก่อนหน้าของสมาชิก วง ประเภทและสกุลเงินเดียวกัน แล้วใช้ราคาที่เพิ่มครั้งล่าสุดของประเภทและสกุลเงินนั้น จากนั้นใช้ราคาเริ่มต้นหรือ 0 แก้ราคาเองได้ รายการเดิมคงราคาเดิมไว้";
|
||||
"ledger.invalidPrice" = "กรอกราคาที่ไม่ติดลบ เยนและวอนใช้จำนวนเต็ม สกุลเงินอื่นใช้ทศนิยมได้ไม่เกิน 2 ตำแหน่ง";
|
||||
"ledger.invalidQuantity" = "จำนวนต้องไม่น้อยกว่า 1";
|
||||
"ledger.requiredSelection" = "เลือกสมาชิก วง และประเภทการซื้อ";
|
||||
"ledger.currencyHint" = "ยอดเงินและอันดับการใช้จ่ายแยกตามสกุลเงิน โดยไม่แปลงหรือรวมต่างสกุลเงิน";
|
||||
"ledger.groupColor" = "สีประจำตัว";
|
||||
"ledger.loadDemo" = "โหลดตัวอย่างบันทึก";
|
||||
"ledger.loadDemoHint" = "ลองใช้บันทึกด้วยสมาชิกและการซื้อตัวอย่าง";
|
||||
"ledger.product.polaroid" = "เชกิ";
|
||||
"ledger.product.wide" = "เชกิแบบไวด์";
|
||||
"ledger.product.mobile" = "ถ่ายรูปด้วยมือถือ";
|
||||
"ledger.demoRequiresEmpty" = "โหลดตัวอย่างได้เฉพาะบันทึกที่ยังไม่มีข้อมูลเท่านั้น";
|
||||
"ledger.error.overflow" = "ยอดเงินหรือจำนวนมากเกินไป โปรดกรอกค่าที่น้อยลง";
|
||||
"ledger.previousMonth" = "เดือนก่อน";
|
||||
"ledger.nextMonth" = "เดือนถัดไป";
|
||||
"ledger.catalog.members" = "สมาชิก";
|
||||
"ledger.catalog.products" = "ประเภทการซื้อ";
|
||||
"ledger.catalog.events" = "งาน";
|
||||
"ledger.catalog.add" = "เพิ่มรายการ";
|
||||
"ledger.catalog.search" = "สมาชิก / วง / ประเภท / งาน";
|
||||
"ledger.catalog.memberCount" = "สมาชิกทั้งหมด %d คน";
|
||||
"ledger.catalog.noGroupMembers" = "วงนี้ยังไม่มีสมาชิก";
|
||||
"ledger.member.shared" = "สมาชิกหลายวง";
|
||||
"ledger.member.reuse" = "เชื่อมโยงสมาชิกเดิม";
|
||||
"ledger.member.existing" = "สมาชิกเดิม";
|
||||
"ledger.member.name" = "ชื่อสมาชิก";
|
||||
"ledger.member.photo" = "เลือกรูปโปรไฟล์จากคลังภาพ";
|
||||
"ledger.member.removePhoto" = "ลบรูปโปรไฟล์";
|
||||
"ledger.member.identity" = "สมาชิกและรูปโปรไฟล์";
|
||||
"ledger.member.identityHint" = "หากคนเดิมอยู่ในวงอื่นด้วย ให้เชื่อมโยงสมาชิกเดิมเพื่อรวมบันทึกหรือแยกตามวง";
|
||||
"ledger.member.affiliation" = "วงที่สังกัดและสีประจำตัว";
|
||||
"ledger.member.prices" = "ราคาต่อหน่วยเริ่มต้น";
|
||||
"ledger.member.pricesHint" = "เว้นราคาว่างไว้เพื่อกรอกตอนบันทึกได้ ราคาแต่ละวงตั้งแยกกันได้ การแก้ไขไม่เปลี่ยนยอดซื้อที่ผ่านมา";
|
||||
"ledger.member.photoError" = "โหลดภาพนี้ไม่ได้ โปรดเลือกภาพอื่น";
|
||||
"ledger.member.photoTooLarge" = "เลือกภาพที่มีขนาดเล็กกว่า 10 MB";
|
||||
"ledger.group.edit" = "แก้ไขวง";
|
||||
"ledger.group.name" = "ชื่อวง";
|
||||
"ledger.product.name" = "ชื่อประเภท";
|
||||
"ledger.event.name" = "ชื่องาน";
|
||||
"ledger.event.hasDate" = "ระบุวันที่ของงาน";
|
||||
"ledger.member.add" = "เพิ่มสมาชิก";
|
||||
"ledger.group.add" = "เพิ่มวง";
|
||||
"ledger.product.add" = "เพิ่มประเภทการซื้อ";
|
||||
"ledger.event.add" = "เพิ่มงาน";
|
||||
"ledger.period" = "ช่วงเวลา";
|
||||
"ledger.rankingBy" = "จัดอันดับตาม";
|
||||
"ledger.metric" = "เกณฑ์";
|
||||
"ledger.allTypes" = "ทุกประเภท";
|
||||
"ledger.allGroups" = "ทุกวง";
|
||||
"ledger.backupHint" = "สำรองข้อมูลวง สมาชิก รูปโปรไฟล์ ราคา และประวัติการซื้อไว้ด้วยกัน";
|
||||
"ledger.chooseRecord" = "เลือกรายการซื้อที่ต้องการแก้ไข";
|
||||
"ledger.chooseRecordHint" = "สมาชิกคนนี้มีหลายรายการในวันที่เลือก โปรดเลือกรายการที่ต้องการแก้ไข";
|
||||
"ledger.deleted" = "ลบแล้ว";
|
||||
"ledger.record.delete" = "ลบรายการซื้อนี้";
|
||||
"ledger.member.delete" = "ลบสมาชิก";
|
||||
"ledger.member.deleteTitle" = "ลบสมาชิกคนนี้หรือไม่";
|
||||
"ledger.member.deleteMessage" = "สมาชิกคนนี้จะถูกนำออกจากทุกวง รายการซื้อและสถิติการใช้จ่ายที่บันทึกไว้จะยังคงอยู่";
|
||||
"ledger.group.delete" = "ลบวง";
|
||||
"ledger.group.deleteTitle" = "ลบวงนี้หรือไม่";
|
||||
"ledger.group.deleteMessage" = "วงนี้และข้อมูลการสังกัดจะถูกนำออกจากรายการข้อมูล สมาชิกที่สังกัดวงอื่นด้วย รายการซื้อ และสถิติการใช้จ่ายที่บันทึกไว้จะยังคงอยู่";
|
||||
"ledger.catalogUnavailable" = "สมาชิกหรือวงนี้ถูกลบแล้ว จึงไม่สามารถบันทึกการแก้ไขข้อมูลครั้งนี้ได้ แต่ยังแก้ไขรายการซื้อที่มีอยู่ได้";
|
||||
"settings.data" = "จัดการข้อมูล";
|
||||
"settings.localData" = "ข้อมูลจะเก็บไว้ในอุปกรณ์นี้ คุณส่งออกไฟล์สำรองได้ทุกเมื่อ";
|
||||
"settings.ledgerDemo" = "โหลดตัวอย่างสมุดบันทึก";
|
||||
"ledger.member.favorite" = "สมาชิกโปรด";
|
||||
"ledger.member.favoriteHint" = "สมาชิกโปรดจะแสดงด้านบนเมื่อเลือกสมาชิกในรายการซื้อสินค้า การตั้งค่านี้ใช้ร่วมกันทุกวงของสมาชิกคนเดียวกัน";
|
||||
"ledger.members.favorites" = "สมาชิกโปรด";
|
||||
"management.records" = "จัดการรายการ";
|
||||
"management.backup" = "สำรองข้อมูล";
|
||||
"management.filters" = "ตัวกรอง";
|
||||
"management.search" = "ค้นหาสมาชิก วง ประเภท งาน หรือหมายเหตุ";
|
||||
"management.dateRange" = "กรองตามช่วงวันที่";
|
||||
"management.startDate" = "วันที่เริ่มต้น";
|
||||
"management.endDate" = "วันที่สิ้นสุด";
|
||||
"management.invalidDateRange" = "วันที่เริ่มต้นต้องไม่อยู่หลังวันที่สิ้นสุด";
|
||||
"management.all" = "ทั้งหมด";
|
||||
"management.selectFiltered" = "เลือกทุกผลลัพธ์";
|
||||
"management.clearSelection" = "ยกเลิกการเลือก";
|
||||
"management.selectionHint" = "ลบเฉพาะรายการที่เลือก การเปลี่ยนตัวกรองจะล้างการเลือก";
|
||||
"management.selectedCount" = "เลือก %d รายการ";
|
||||
"management.resultCount" = "พบ %d รายการ";
|
||||
"management.deleteSelected" = "ลบรายการที่เลือก";
|
||||
"management.empty" = "ไม่พบรายการที่ตรงเงื่อนไข";
|
||||
"management.clearAll" = "ลบรายการซื้อสินค้าทั้งหมด";
|
||||
"management.clearAllHint" = "การลบทั้งหมดมีผลต่อทุกวันที่ สมาชิก และสกุลเงิน ข้อมูลวง สมาชิก ประเภท และงานยังคงอยู่";
|
||||
"ledger.management" = "จัดการสมุดบันทึก";
|
||||
"ledger.management.deleteSummary" = "จะลบ %d รายการ รวม %@ ชิ้น";
|
||||
"ledger.management.deleteImpact" = "จำนวนและยอดเงินของรายการเหล่านี้จะถูกนำออกจากสถิติ การดำเนินการนี้ยกเลิกย้อนหลังไม่ได้";
|
||||
"management.catalog" = "จัดการข้อมูลสมาชิกและวง";
|
||||
"management.catalog.search" = "ค้นหาสมาชิกหรือวง";
|
||||
"management.catalog.hint" = "การลบสมาชิกมีผลต่อทุกสังกัด การลบวงมีผลเฉพาะวงนั้น รายการเดิมยังคงอยู่และกู้ข้อมูลจากไฟล์สำรองที่ถูกต้องได้";
|
||||
"management.catalog.empty" = "ไม่มีสมาชิกหรือวงให้จัดการ";
|
||||
"management.catalog.deleteTitle" = "ลบข้อมูลที่เลือกหรือไม่?";
|
||||
"ledger.exportCSV" = "ส่งออกรายการซื้อ (CSV)";
|
||||
"ledger.exportCSVHint" = "หนึ่งแถวต่อการซื้อหนึ่งรายการ เปิดดูและรวมยอดใน Numbers หรือ Excel ได้ CSV ใช้สำหรับดูเท่านั้น หากต้องการกู้คืนให้ใช้ไฟล์สำรอง JSON";
|
||||
"ledger.quickAdd.product" = "เพิ่มอีกหนึ่ง: %@";
|
||||
"ledger.quickAddHint" = "แตะ ⊕ เพื่อเพิ่มจำนวนของรายการเดิมหนึ่งชิ้น ราคาและรายละเอียดอื่นจะไม่เปลี่ยน";
|
||||
|
||||
"settings.keepsAbout" = "Oshicue Keeps · สมุดบันทึกกิจกรรมแฟนคลับ";
|
||||
"ledger.record.details" = "ป้ายกำกับของบันทึก";
|
||||
"ledger.record.detailsHint" = "ป้ายกำกับและสีนี้จะถูกเก็บไว้พร้อมบันทึก การเปลี่ยนสมาชิกหรือประเภทจะอัปเดตให้ และแก้ไขบันทึกย้อนหลังได้ที่นี่";
|
||||
|
||||
// Keys looked up through helpers and ternaries
|
||||
"import.copied" = "คัดลอกแล้ว";
|
||||
"ledger.calendar" = "ปฏิทิน";
|
||||
"ledger.catalog" = "สมาชิกและประเภท";
|
||||
"ledger.catalog.emptyEvents" = "บันทึกงานเพื่อใช้ข้อมูลเมืองและสถานที่ซ้ำได้อย่างรวดเร็ว";
|
||||
"ledger.catalog.emptyMembers" = "เริ่มด้วยการเพิ่มวงและสมาชิก";
|
||||
"ledger.combinedHint" = "สมาชิกที่เชื่อมโยงเป็นคนเดียวกันจะนับรวมข้ามวง";
|
||||
"ledger.copyTemplate" = "คัดลอกแม่แบบ";
|
||||
"ledger.error.avatar" = "รูปโปรไฟล์ต้องเป็นภาพ JPEG ที่ถูกต้อง";
|
||||
"ledger.error.avatarSize" = "รูปโปรไฟล์มีขนาดใหญ่เกินไป ขนาดสูงสุดคือ 2 MB";
|
||||
"ledger.error.color" = "ใช้รหัสสี 6 หลักในรูปแบบ #RRGGBB";
|
||||
"ledger.error.currency" = "ไม่รองรับสกุลเงินนี้";
|
||||
"ledger.error.currencyRequired" = "เลือกสกุลเงินหนึ่งเพื่อดูอันดับการใช้จ่าย";
|
||||
"ledger.error.date" = "ใช้วันที่ที่ถูกต้องในรูปแบบ yyyy-MM-dd";
|
||||
"ledger.error.documentSize" = "ไฟล์นำเข้ามีขนาดใหญ่เกินไป ขนาดสูงสุดคือ 20 MB";
|
||||
"ledger.error.duplicateID" = "ID ซ้ำกัน แต่ละรายการในลิสต์ต้องมี ID ที่ไม่ซ้ำ";
|
||||
"ledger.error.emptyField" = "ช่องนี้ต้องไม่ว่าง";
|
||||
"ledger.error.emptyImport" = "ไม่มีวง สมาชิก ประเภทการซื้อ งาน หรือบันทึกให้นำเข้า";
|
||||
"ledger.error.fieldType" = "ชนิดข้อมูลไม่ถูกต้องหรือเป็น null โปรดเทียบช่องที่แสดงด้านล่างกับแม่แบบ";
|
||||
"ledger.error.invalidJSON" = "ข้อความไม่ใช่ JSON ที่ถูกต้อง โปรดตรวจสอบจุลภาค เครื่องหมายคำพูด และวงเล็บ";
|
||||
"ledger.error.membership" = "ข้อมูลการเป็นสมาชิกของวงขาดหายหรือซ้ำกัน";
|
||||
"ledger.error.missingField" = "ขาดช่องข้อมูลที่จำเป็น โปรดเพิ่มช่องที่แสดงด้านล่าง";
|
||||
"ledger.error.price" = "ราคาต่อหน่วยต้องเป็นจำนวนเต็มที่ไม่ติดลบในหน่วยย่อยที่สุดของสกุลเงิน";
|
||||
"ledger.error.quantity" = "จำนวนต้องเป็นจำนวนเต็มบวก";
|
||||
"ledger.error.recordConflict" = "เนื้อหาของบันทึก ID นี้ไม่ตรงกัน ใช้ ID ใหม่สำหรับการซื้อใหม่ หรือแก้ไขบันทึกเดิมในแอป";
|
||||
"ledger.error.reference" = "ไม่พบรายการที่อ้างอิง โปรดเพิ่มรายการหรือแก้ไข ID";
|
||||
"ledger.error.schemaVersion" = "ไม่รองรับบันทึกเวอร์ชันนี้ โปรดตั้งค่า schemaVersion เป็น 1";
|
||||
"ledger.event.edit" = "แก้ไขงาน";
|
||||
"ledger.management.clearTitle" = "ลบรายการซื้อสินค้าทั้งหมดหรือไม่?";
|
||||
"ledger.management.deleteTitle" = "ลบรายการซื้อสินค้าที่เลือกหรือไม่?";
|
||||
"ledger.member.edit" = "แก้ไขสมาชิก";
|
||||
"ledger.newRecord" = "บันทึกการซื้อใหม่";
|
||||
"ledger.product.edit" = "แก้ไขประเภทการซื้อ";
|
||||
"ledger.replacesDemo" = "การนำเข้านี้จะแทนที่ข้อมูลตัวอย่างบันทึกที่ยังไม่ได้แก้ไข";
|
||||
"ledger.restoreHint" = "ข้อมูลสมาชิก วง และแม่แบบที่มี ID ตรงกันจะอัปเดต บันทึกการซื้อที่เหมือนกันจะไม่ซ้ำ และเก็บบันทึกอื่นไว้";
|
||||
"ledger.splitHint" = "เลือกนับรวมสมาชิกที่อยู่หลายวง หรือแยกนับตามวง";
|
||||
"ledger.stats" = "สถิติ";
|
||||
"management.catalog.groupImpact" = "จะเก็บวง %d วงและความสัมพันธ์สังกัดในสถานะเก็บถาวร สังกัดวงอื่นของสมาชิก รายการซื้อและสถิติยังอยู่";
|
||||
"management.catalog.memberImpact" = "จะเก็บสมาชิก %d คนและทุกสังกัดในสถานะเก็บถาวร รายการซื้อและสถิติยังอยู่ และแก้ไขประวัติได้";
|
||||
|
||||
// Image export
|
||||
@@ -0,0 +1,209 @@
|
||||
// Oshicue Keeps — zh-HK
|
||||
|
||||
"import.file" = "揀選檔案";
|
||||
"import.validate" = "檢查格式";
|
||||
"settings.title" = "設定";
|
||||
"settings.language" = "語言";
|
||||
"settings.followSystem" = "跟隨系統";
|
||||
"settings.about" = "關於";
|
||||
"settings.version" = "版本";
|
||||
"common.done" = "完成";
|
||||
"common.cancel" = "取消";
|
||||
"common.close" = "關閉";
|
||||
"settings.readError" = "讀取唔到已儲存嘅資料。";
|
||||
"settings.saveError" = "儲存唔到變更。";
|
||||
"settings.storageError" = "已儲存嘅資料出咗問題。";
|
||||
"import.readError" = "讀取唔到檔案,請揀 UTF-8 編碼嘅 JSON 檔案。";
|
||||
"ledger.title" = "手帳";
|
||||
"ledger.add" = "記一筆";
|
||||
"ledger.today" = "今日";
|
||||
"ledger.month" = "月";
|
||||
"ledger.year" = "年";
|
||||
"ledger.day" = "日";
|
||||
"ledger.lifetime" = "生涯累計";
|
||||
"ledger.quantity" = "數量";
|
||||
"ledger.spending" = "消費金額";
|
||||
"ledger.memberCombined" = "成員合計";
|
||||
"ledger.memberByGroup" = "成員按團體分開";
|
||||
"ledger.group" = "團體";
|
||||
"ledger.currency" = "貨幣";
|
||||
"ledger.total" = "總計";
|
||||
"ledger.membersCount" = "%d 位成員";
|
||||
"ledger.itemsCount" = "%d 張";
|
||||
"ledger.noRecords" = "呢日暫時冇紀錄";
|
||||
"ledger.noRecordsHint" = "撳 + 記低一筆物販。";
|
||||
"ledger.records" = "物販紀錄";
|
||||
"ledger.edit" = "編輯";
|
||||
"ledger.delete" = "刪除";
|
||||
"ledger.deleteTitle" = "刪除呢筆紀錄?";
|
||||
"ledger.deleteMessage" = "呢筆紀錄嘅數量同金額會喺統計入面移除。";
|
||||
"ledger.manage" = "管理";
|
||||
"ledger.import" = "匯入手帳";
|
||||
"ledger.export" = "匯出備份";
|
||||
"ledger.backup" = "JSON 備份";
|
||||
"ledger.importHint" = "貼上手帳 JSON 或者揀備份檔案,睇過預覽就可以匯入。";
|
||||
"ledger.preview" = "預覽";
|
||||
"ledger.apply" = "確認匯入";
|
||||
"ledger.summary" = "%d 位成員 · %d 筆紀錄";
|
||||
"ledger.editRecord" = "編輯物販";
|
||||
"ledger.date" = "日期";
|
||||
"ledger.member" = "成員";
|
||||
"ledger.chooseMember" = "揀成員";
|
||||
"ledger.chooseGroup" = "揀團體";
|
||||
"ledger.type" = "物販類型";
|
||||
"ledger.unitPrice" = "單價";
|
||||
"ledger.amount" = "金額";
|
||||
"ledger.event" = "活動";
|
||||
"ledger.optional" = "可選";
|
||||
"ledger.noEvent" = "唔連結活動";
|
||||
"ledger.city" = "城市";
|
||||
"ledger.venue" = "場館";
|
||||
"ledger.address" = "場館地址";
|
||||
"ledger.note" = "備註";
|
||||
"ledger.save" = "儲存";
|
||||
"ledger.addMember" = "新增成員";
|
||||
"ledger.addType" = "新增物販類型";
|
||||
"ledger.addEvent" = "新增活動";
|
||||
"ledger.priceHint" = "新增時先用同成員、團體、類型同貨幣喺所選日期或之前嘅最近價格,再用上次新增同類型同貨幣價格,最後用預設價或 0。可以手動改,歷史紀錄保留原價。";
|
||||
"ledger.invalidPrice" = "請輸入零或以上嘅單價。日圓同韓圜要用整數,其他貨幣最多兩位小數。";
|
||||
"ledger.invalidQuantity" = "數量最少要有 1。";
|
||||
"ledger.requiredSelection" = "請揀成員、團體同物販類型。";
|
||||
"ledger.currencyHint" = "唔同貨幣會分開計金額同消費排名,唔會自動兌換或者加埋。";
|
||||
"ledger.groupColor" = "代表色";
|
||||
"ledger.loadDemo" = "載入手帳示範";
|
||||
"ledger.loadDemoHint" = "用示範成員同物販紀錄試下手帳功能。";
|
||||
"ledger.product.polaroid" = "即影即有";
|
||||
"ledger.product.wide" = "WIDE 即影即有";
|
||||
"ledger.product.mobile" = "手機合照";
|
||||
"ledger.demoRequiresEmpty" = "只可以喺空手帳載入示範。";
|
||||
"ledger.error.overflow" = "金額或者數量太大,請輸入細啲嘅數值。";
|
||||
"ledger.previousMonth" = "上個月";
|
||||
"ledger.nextMonth" = "下個月";
|
||||
"ledger.catalog.members" = "成員";
|
||||
"ledger.catalog.products" = "物販類型";
|
||||
"ledger.catalog.events" = "活動";
|
||||
"ledger.catalog.add" = "新增範本";
|
||||
"ledger.catalog.search" = "成員/團體/類型/活動名稱";
|
||||
"ledger.catalog.memberCount" = "共 %d 位成員";
|
||||
"ledger.catalog.noGroupMembers" = "呢個團體暫時冇成員。";
|
||||
"ledger.member.shared" = "兼任多個團體";
|
||||
"ledger.member.reuse" = "連結已有成員(兼任)";
|
||||
"ledger.member.existing" = "已有成員";
|
||||
"ledger.member.name" = "成員名稱";
|
||||
"ledger.member.photo" = "喺相簿揀頭像";
|
||||
"ledger.member.removePhoto" = "移除頭像";
|
||||
"ledger.member.identity" = "成員同頭像";
|
||||
"ledger.member.identityHint" = "同一人兼任其他團體,請連結已有成員,就可以合計或者按團體分開計。";
|
||||
"ledger.member.affiliation" = "所屬團體同代表色";
|
||||
"ledger.member.prices" = "預設單價";
|
||||
"ledger.member.pricesHint" = "單價可以留空,記帳嗰陣再填;唔同團體可以分開定價,改價唔會影響以前嘅消費。";
|
||||
"ledger.member.photoError" = "讀取唔到呢張圖片,請揀另一張相。";
|
||||
"ledger.member.photoTooLarge" = "請揀細過 10 MB 嘅相。";
|
||||
"ledger.group.edit" = "編輯團體";
|
||||
"ledger.group.name" = "團體名稱";
|
||||
"ledger.product.name" = "類型名稱";
|
||||
"ledger.event.name" = "活動名稱";
|
||||
"ledger.event.hasDate" = "指定活動日期";
|
||||
"ledger.member.add" = "新增成員";
|
||||
"ledger.group.add" = "新增團體";
|
||||
"ledger.product.add" = "新增物販類型";
|
||||
"ledger.event.add" = "新增活動";
|
||||
"ledger.period" = "統計時段";
|
||||
"ledger.rankingBy" = "統計分類";
|
||||
"ledger.metric" = "排序指標";
|
||||
"ledger.allTypes" = "全部類型";
|
||||
"ledger.allGroups" = "全部團體";
|
||||
"ledger.backupHint" = "一齊備份團體、成員、頭像、單價同物販紀錄。";
|
||||
"ledger.chooseRecord" = "選擇要編輯嘅物販";
|
||||
"ledger.chooseRecordHint" = "呢位成員當日有多筆記錄,請揀其中一筆編輯。";
|
||||
"ledger.deleted" = "已刪除";
|
||||
"ledger.record.delete" = "刪除呢筆物販";
|
||||
"ledger.member.delete" = "刪除成員";
|
||||
"ledger.member.deleteTitle" = "刪除呢位成員?";
|
||||
"ledger.member.deleteMessage" = "會將呢位成員由所有團體移除。已記錄嘅物販同消費統計會保留。";
|
||||
"ledger.group.delete" = "刪除團體";
|
||||
"ledger.group.deleteTitle" = "刪除呢個團體?";
|
||||
"ledger.group.deleteMessage" = "會將呢個團體同所屬成員關係由資料列表移除。兼任其他團體嘅成員、已有物販同消費統計會保留。";
|
||||
"ledger.catalogUnavailable" = "呢位成員或團體已刪除,今次資料修改無法儲存;已有物販仍然可以編輯。";
|
||||
"settings.data" = "資料管理";
|
||||
"settings.localData" = "資料儲存喺呢部裝置,可以隨時匯出備份。";
|
||||
"settings.ledgerDemo" = "載入手帳範例";
|
||||
"ledger.member.favorite" = "最愛成員";
|
||||
"ledger.member.favoriteHint" = "最愛成員會喺物販記錄嘅成員選擇置頂;同一成員喺所有團體嘅身份共用呢個設定。";
|
||||
"ledger.members.favorites" = "最愛成員";
|
||||
"management.records" = "記錄管理";
|
||||
"management.backup" = "備份";
|
||||
"management.filters" = "篩選條件";
|
||||
"management.search" = "搜尋成員、團體、類型、活動或備註";
|
||||
"management.dateRange" = "按日期範圍篩選";
|
||||
"management.startDate" = "開始日期";
|
||||
"management.endDate" = "結束日期";
|
||||
"management.invalidDateRange" = "開始日期唔可以遲過結束日期。";
|
||||
"management.all" = "全部";
|
||||
"management.selectFiltered" = "全選目前結果";
|
||||
"management.clearSelection" = "取消選取";
|
||||
"management.selectionHint" = "只會刪除勾選嘅記錄;改篩選會清除選取。";
|
||||
"management.selectedCount" = "已選 %d 筆";
|
||||
"management.resultCount" = "共 %d 筆結果";
|
||||
"management.deleteSelected" = "刪除所選";
|
||||
"management.empty" = "冇符合條件嘅記錄";
|
||||
"management.clearAll" = "刪除全部物販記錄";
|
||||
"management.clearAllHint" = "刪除全部物販會影響所有日期、成員同幣種。團體、成員、類型同活動資料會保留。";
|
||||
"ledger.management" = "手帳管理";
|
||||
"ledger.management.deleteSummary" = "會刪除 %d 筆記錄,共 %@ 件。";
|
||||
"ledger.management.deleteImpact" = "呢啲記錄嘅數量同金額會喺統計移除,操作無法復原。";
|
||||
"management.catalog" = "資料清理";
|
||||
"management.catalog.search" = "搜尋成員或團體";
|
||||
"management.catalog.hint" = "刪除成員會影響佢喺所有團體嘅身份;刪除團體只影響嗰個團體。已有記錄會保留,可以用有效備份還原資料。";
|
||||
"management.catalog.empty" = "冇可以清理嘅成員或團體";
|
||||
"management.catalog.deleteTitle" = "刪除所選資料?";
|
||||
"ledger.exportCSV" = "匯出物販表格(CSV)";
|
||||
"ledger.exportCSVHint" = "每筆物販一行,可以用 Numbers 或者 Excel 睇同埋計數。CSV 只係用嚟睇,還原資料請用 JSON 備份。";
|
||||
"ledger.quickAdd.product" = "再記多一份:%@";
|
||||
"ledger.quickAddHint" = "撳 ⊕ 會為同一筆物販數量加 1,單價、活動等資料唔變。";
|
||||
|
||||
"settings.keepsAbout" = "Oshicue Keeps · 應援紀錄手帳。";
|
||||
"ledger.record.details" = "紀錄標籤";
|
||||
"ledger.record.detailsHint" = "呢啲標籤同顏色會跟住呢筆紀錄保存。轉成員或者類型時會自動更新,亦可以喺呢度直接改舊紀錄。";
|
||||
|
||||
// Keys looked up through helpers and ternaries
|
||||
"import.copied" = "已複製";
|
||||
"ledger.calendar" = "月曆";
|
||||
"ledger.catalog" = "成員同類型";
|
||||
"ledger.catalog.emptyEvents" = "儲存活動就可以快啲再用同一城市同場館。";
|
||||
"ledger.catalog.emptyMembers" = "先加入團體同成員。";
|
||||
"ledger.combinedHint" = "連結咗同一身份嘅成員,會跨團體合埋計。";
|
||||
"ledger.copyTemplate" = "複製範本";
|
||||
"ledger.error.avatar" = "頭像要係有效嘅 JPEG 圖片。";
|
||||
"ledger.error.avatarSize" = "頭像檔案太大,上限係 2 MB。";
|
||||
"ledger.error.color" = "請用 #RRGGBB 格式嘅六位色碼。";
|
||||
"ledger.error.currency" = "未支援呢種貨幣。";
|
||||
"ledger.error.currencyRequired" = "請揀一種貨幣睇消費排名。";
|
||||
"ledger.error.date" = "請用有效嘅 yyyy-MM-dd 格式日期。";
|
||||
"ledger.error.documentSize" = "匯入檔案太大,上限係 20 MB。";
|
||||
"ledger.error.duplicateID" = "ID 重複,同一個列表嘅每個項目都要用唔同 ID。";
|
||||
"ledger.error.emptyField" = "呢個欄位唔可以留空。";
|
||||
"ledger.error.emptyImport" = "冇團體、成員、物販類型、活動或者紀錄可以匯入。";
|
||||
"ledger.error.fieldType" = "欄位類型錯誤或者係 null,請對照範本檢查下面標示嘅欄位。";
|
||||
"ledger.error.invalidJSON" = "文字唔係有效嘅 JSON,請檢查逗號、引號同括號。";
|
||||
"ledger.error.membership" = "成員同團體嘅所屬關係缺少或者重複。";
|
||||
"ledger.error.missingField" = "缺少必填欄位,請補返下面標示嘅欄位。";
|
||||
"ledger.error.price" = "單價要按最小貨幣單位填零或以上嘅整數。";
|
||||
"ledger.error.quantity" = "數量要係正整數。";
|
||||
"ledger.error.recordConflict" = "相同 ID 嘅紀錄內容唔一致。新消費請用新 ID,已有紀錄請喺 App 入面編輯。";
|
||||
"ledger.error.reference" = "搵唔到引用嘅資料項目,請加返項目或者改正 ID。";
|
||||
"ledger.error.schemaVersion" = "未支援呢個手帳格式版本,請將 schemaVersion 設為 1。";
|
||||
"ledger.event.edit" = "編輯活動";
|
||||
"ledger.management.clearTitle" = "刪除全部物販記錄?";
|
||||
"ledger.management.deleteTitle" = "刪除所選物販記錄?";
|
||||
"ledger.member.edit" = "編輯成員";
|
||||
"ledger.newRecord" = "新增物販";
|
||||
"ledger.product.edit" = "編輯物販類型";
|
||||
"ledger.replacesDemo" = "今次匯入會取代未修改過嘅示範手帳資料。";
|
||||
"ledger.restoreHint" = "相同 ID 嘅成員、團體同範本資料會更新。相同嘅紀錄唔會重複加入,其他已有紀錄會保留。";
|
||||
"ledger.splitHint" = "同一成員兼任幾個團體,可以揀合計或者按團體分開計。";
|
||||
"ledger.stats" = "統計";
|
||||
"management.catalog.groupImpact" = "會封存 %d 個團體同所屬關係。成員喺其他團體嘅身份、已有物販同統計會保留。";
|
||||
"management.catalog.memberImpact" = "會封存 %d 位成員同佢哋喺所有團體嘅身份。已有物販同統計會保留,歷史記錄仍然可以編輯。";
|
||||
|
||||
// Image export
|
||||
@@ -0,0 +1,209 @@
|
||||
// Oshicue Keeps — zh-Hans
|
||||
|
||||
"import.file" = "选择文件";
|
||||
"import.validate" = "检查格式";
|
||||
"settings.title" = "设置";
|
||||
"settings.language" = "语言";
|
||||
"settings.followSystem" = "跟随系统";
|
||||
"settings.about" = "关于";
|
||||
"settings.version" = "版本";
|
||||
"common.done" = "完成";
|
||||
"common.cancel" = "取消";
|
||||
"common.close" = "关闭";
|
||||
"settings.readError" = "无法读取已保存的数据。";
|
||||
"settings.saveError" = "无法保存更改。";
|
||||
"settings.storageError" = "已保存的数据出现问题。";
|
||||
"import.readError" = "无法读取文件,请选择 UTF-8 编码的 JSON 文件。";
|
||||
"ledger.title" = "手账";
|
||||
"ledger.add" = "记一笔";
|
||||
"ledger.today" = "今天";
|
||||
"ledger.month" = "月";
|
||||
"ledger.year" = "年";
|
||||
"ledger.day" = "日";
|
||||
"ledger.lifetime" = "生涯累计";
|
||||
"ledger.quantity" = "数量";
|
||||
"ledger.spending" = "消费金额";
|
||||
"ledger.memberCombined" = "成员合计";
|
||||
"ledger.memberByGroup" = "成员分团";
|
||||
"ledger.group" = "团体";
|
||||
"ledger.currency" = "币种";
|
||||
"ledger.total" = "总计";
|
||||
"ledger.membersCount" = "%d 位成员";
|
||||
"ledger.itemsCount" = "%d 张";
|
||||
"ledger.noRecords" = "当天暂无记录";
|
||||
"ledger.noRecordsHint" = "点按 + 记录一笔物贩。";
|
||||
"ledger.records" = "物贩记录";
|
||||
"ledger.edit" = "编辑";
|
||||
"ledger.delete" = "删除";
|
||||
"ledger.deleteTitle" = "删除这条记录?";
|
||||
"ledger.deleteMessage" = "这条记录的数量和金额将从统计中移除。";
|
||||
"ledger.manage" = "管理";
|
||||
"ledger.import" = "导入手账";
|
||||
"ledger.export" = "导出备份";
|
||||
"ledger.backup" = "JSON 备份";
|
||||
"ledger.importHint" = "粘贴手账 JSON 或选择备份文件,检查预览后导入。";
|
||||
"ledger.preview" = "预览";
|
||||
"ledger.apply" = "确认导入";
|
||||
"ledger.summary" = "%d 位成员 · %d 条记录";
|
||||
"ledger.editRecord" = "编辑物贩";
|
||||
"ledger.date" = "日期";
|
||||
"ledger.member" = "成员";
|
||||
"ledger.chooseMember" = "选择成员";
|
||||
"ledger.chooseGroup" = "选择团体";
|
||||
"ledger.type" = "物贩类型";
|
||||
"ledger.unitPrice" = "单价";
|
||||
"ledger.amount" = "金额";
|
||||
"ledger.event" = "活动";
|
||||
"ledger.optional" = "可选";
|
||||
"ledger.noEvent" = "不关联活动";
|
||||
"ledger.city" = "城市";
|
||||
"ledger.venue" = "场馆";
|
||||
"ledger.address" = "场馆地址";
|
||||
"ledger.note" = "备注";
|
||||
"ledger.save" = "保存";
|
||||
"ledger.addMember" = "新增成员";
|
||||
"ledger.addType" = "新增物贩类型";
|
||||
"ledger.addEvent" = "新增活动";
|
||||
"ledger.priceHint" = "新增时先用同成员、团体、类型及币种在所选日期或之前的最近价格,再用上次新增同类型同币种价格,最后用默认价或 0。可手动修改,历史记录保留原价。";
|
||||
"ledger.invalidPrice" = "请输入非负单价。日元和韩元须为整数,其他币种最多两位小数。";
|
||||
"ledger.invalidQuantity" = "数量必须至少为 1。";
|
||||
"ledger.requiredSelection" = "请选择成员、团体和物贩类型。";
|
||||
"ledger.currencyHint" = "不同币种分别统计金额和消费排行,不自动换汇或混加。";
|
||||
"ledger.groupColor" = "代表色";
|
||||
"ledger.loadDemo" = "载入手账示例";
|
||||
"ledger.loadDemoHint" = "用示例成员和物贩记录体验手账功能。";
|
||||
"ledger.product.polaroid" = "拍立得";
|
||||
"ledger.product.wide" = "WIDE 拍立得";
|
||||
"ledger.product.mobile" = "手机合影";
|
||||
"ledger.demoRequiresEmpty" = "仅能在空手账中载入示例。";
|
||||
"ledger.error.overflow" = "金额或数量过大,请输入较小的数值。";
|
||||
"ledger.previousMonth" = "上个月";
|
||||
"ledger.nextMonth" = "下个月";
|
||||
"ledger.catalog.members" = "成员";
|
||||
"ledger.catalog.products" = "物贩类型";
|
||||
"ledger.catalog.events" = "活动";
|
||||
"ledger.catalog.add" = "新增模板";
|
||||
"ledger.catalog.search" = "成员/团体/类型/活动名称";
|
||||
"ledger.catalog.memberCount" = "共 %d 位成员";
|
||||
"ledger.catalog.noGroupMembers" = "该团体尚无成员。";
|
||||
"ledger.member.shared" = "兼任多个团体";
|
||||
"ledger.member.reuse" = "关联已有成员(兼任)";
|
||||
"ledger.member.existing" = "已有成员";
|
||||
"ledger.member.name" = "成员名称";
|
||||
"ledger.member.photo" = "从相册选择头像";
|
||||
"ledger.member.removePhoto" = "移除头像";
|
||||
"ledger.member.identity" = "成员与头像";
|
||||
"ledger.member.identityHint" = "同一人兼任其他团体时,请关联已有成员,即可合计或按团体分计。";
|
||||
"ledger.member.affiliation" = "所属团体与代表色";
|
||||
"ledger.member.prices" = "默认单价";
|
||||
"ledger.member.pricesHint" = "单价可留空,记账时再填;不同团体可分别设价,修改不会改变历史消费。";
|
||||
"ledger.member.photoError" = "无法读取这张图片,请选择其他照片。";
|
||||
"ledger.member.photoTooLarge" = "请选择小于 10 MB 的照片。";
|
||||
"ledger.group.edit" = "编辑团体";
|
||||
"ledger.group.name" = "团体名称";
|
||||
"ledger.product.name" = "类型名称";
|
||||
"ledger.event.name" = "活动名称";
|
||||
"ledger.event.hasDate" = "指定活动日期";
|
||||
"ledger.member.add" = "新增成员";
|
||||
"ledger.group.add" = "新增团体";
|
||||
"ledger.product.add" = "新增物贩类型";
|
||||
"ledger.event.add" = "新增活动";
|
||||
"ledger.period" = "统计周期";
|
||||
"ledger.rankingBy" = "统计维度";
|
||||
"ledger.metric" = "排序指标";
|
||||
"ledger.allTypes" = "全部类型";
|
||||
"ledger.allGroups" = "全部团体";
|
||||
"ledger.backupHint" = "一并备份团体、成员、头像、单价和物贩记录。";
|
||||
"ledger.chooseRecord" = "选择要编辑的物贩";
|
||||
"ledger.chooseRecordHint" = "这位成员当天有多笔记录,请选择其中一笔编辑。";
|
||||
"ledger.deleted" = "已删除";
|
||||
"ledger.record.delete" = "删除这笔物贩";
|
||||
"ledger.member.delete" = "删除成员";
|
||||
"ledger.member.deleteTitle" = "删除此成员?";
|
||||
"ledger.member.deleteMessage" = "将从所有团体中移除此成员。已记录的物贩和消费统计会保留。";
|
||||
"ledger.group.delete" = "删除团体";
|
||||
"ledger.group.deleteTitle" = "删除此团体?";
|
||||
"ledger.group.deleteMessage" = "将从资料列表移除此团体及其成员关系。兼任其他团体的成员、已有物贩和消费统计会保留。";
|
||||
"ledger.catalogUnavailable" = "该成员或团体已删除,无法保存这次资料修改;已有物贩仍可编辑。";
|
||||
"settings.data" = "数据管理";
|
||||
"settings.localData" = "资料保存在本机,可随时导出备份。";
|
||||
"settings.ledgerDemo" = "载入手账示例";
|
||||
"ledger.member.favorite" = "最爱成员";
|
||||
"ledger.member.favoriteHint" = "最爱成员会置顶显示在物贩记录的成员选择中;同一成员的所有团体身份共用此设置。";
|
||||
"ledger.members.favorites" = "最爱成员";
|
||||
"management.records" = "记录管理";
|
||||
"management.backup" = "备份";
|
||||
"management.filters" = "筛选条件";
|
||||
"management.search" = "搜索成员、团体、类型、活动或备注";
|
||||
"management.dateRange" = "按日期范围筛选";
|
||||
"management.startDate" = "开始日期";
|
||||
"management.endDate" = "结束日期";
|
||||
"management.invalidDateRange" = "开始日期不能晚于结束日期。";
|
||||
"management.all" = "全部";
|
||||
"management.selectFiltered" = "全选当前结果";
|
||||
"management.clearSelection" = "取消选择";
|
||||
"management.selectionHint" = "仅删除勾选的记录;更改筛选会清除选择。";
|
||||
"management.selectedCount" = "已选 %d 条";
|
||||
"management.resultCount" = "共 %d 条结果";
|
||||
"management.deleteSelected" = "删除所选";
|
||||
"management.empty" = "没有符合条件的记录";
|
||||
"management.clearAll" = "删除全部物贩记录";
|
||||
"management.clearAllHint" = "删除全部物贩会影响所有日期、成员和币种。团体、成员、类型与活动资料保留。";
|
||||
"ledger.management" = "手账管理";
|
||||
"ledger.management.deleteSummary" = "将删除 %d 条记录,共 %@ 件。";
|
||||
"ledger.management.deleteImpact" = "这些记录的数量和金额将从统计中移除,此操作无法撤销。";
|
||||
"management.catalog" = "资料清理";
|
||||
"management.catalog.search" = "搜索成员或团体";
|
||||
"management.catalog.hint" = "删除成员会影响其所有团体身份;删除团体仅影响该团体。已有记录保留,可用有效备份恢复资料。";
|
||||
"management.catalog.empty" = "没有可清理的成员或团体";
|
||||
"management.catalog.deleteTitle" = "删除所选资料?";
|
||||
"ledger.exportCSV" = "导出物贩表格(CSV)";
|
||||
"ledger.exportCSVHint" = "每笔物贩一行,可用 Numbers 或 Excel 查看、汇总。CSV 只用于查看,恢复资料请使用 JSON 备份。";
|
||||
"ledger.quickAdd.product" = "再记一份:%@";
|
||||
"ledger.quickAddHint" = "点按 ⊕ 为同一笔物贩数量加 1,单价、活动等资料不变。";
|
||||
|
||||
"settings.keepsAbout" = "Oshicue Keeps · 应援记录手账。";
|
||||
"ledger.record.details" = "记录标签";
|
||||
"ledger.record.detailsHint" = "这些标签与颜色会随此条记录保存。更换成员或类型时会自动更新;也可在此处直接修改历史记录。";
|
||||
|
||||
// Keys looked up through helpers and ternaries
|
||||
"import.copied" = "已复制";
|
||||
"ledger.calendar" = "日历";
|
||||
"ledger.catalog" = "成员与类型";
|
||||
"ledger.catalog.emptyEvents" = "保存活动,快速复用城市和场馆。";
|
||||
"ledger.catalog.emptyMembers" = "先添加团体和成员。";
|
||||
"ledger.combinedHint" = "关联为同一人的成员,将跨团体合并统计。";
|
||||
"ledger.copyTemplate" = "复制模板";
|
||||
"ledger.error.avatar" = "头像必须为有效的 JPEG 图片。";
|
||||
"ledger.error.avatarSize" = "头像文件过大,上限为 2 MB。";
|
||||
"ledger.error.color" = "请使用 #RRGGBB 格式的六位色码。";
|
||||
"ledger.error.currency" = "不支持此币种。";
|
||||
"ledger.error.currencyRequired" = "请选择一种币种查看消费排行。";
|
||||
"ledger.error.date" = "请使用有效的 yyyy-MM-dd 格式日期。";
|
||||
"ledger.error.documentSize" = "导入文件过大,上限为 20 MB。";
|
||||
"ledger.error.duplicateID" = "ID 重复,同一列表中的每个项目必须使用不同 ID。";
|
||||
"ledger.error.emptyField" = "此字段不能为空。";
|
||||
"ledger.error.emptyImport" = "没有可导入的团体、成员、物贩类型、活动或记录。";
|
||||
"ledger.error.fieldType" = "字段类型错误或为空值,请对照模板检查下面标出的字段。";
|
||||
"ledger.error.invalidJSON" = "文字不是有效的 JSON,请检查逗号、引号和括号。";
|
||||
"ledger.error.membership" = "成员与团体的所属关系缺失或重复。";
|
||||
"ledger.error.missingField" = "缺少必填字段,请补充下面标出的字段。";
|
||||
"ledger.error.price" = "单价须以最小货币单位填写非负整数。";
|
||||
"ledger.error.quantity" = "数量必须为正整数。";
|
||||
"ledger.error.recordConflict" = "相同 ID 的记录内容不一致。新消费请使用新的 ID,已有记录请在 App 内编辑。";
|
||||
"ledger.error.reference" = "找不到引用的资料项目,请补充该项目或修正 ID。";
|
||||
"ledger.error.schemaVersion" = "不支持此手账格式版本,请将 schemaVersion 设为 1。";
|
||||
"ledger.event.edit" = "编辑活动";
|
||||
"ledger.management.clearTitle" = "删除全部物贩记录?";
|
||||
"ledger.management.deleteTitle" = "删除所选物贩记录?";
|
||||
"ledger.member.edit" = "编辑成员";
|
||||
"ledger.newRecord" = "新增物贩";
|
||||
"ledger.product.edit" = "编辑物贩类型";
|
||||
"ledger.replacesDemo" = "未经修改的示例手账资料会被本次导入替换。";
|
||||
"ledger.restoreHint" = "相同 ID 的成员、团体和模板资料会更新。相同的记录不会重复添加,已有的其他记录会保留。";
|
||||
"ledger.splitHint" = "兼任多个团体的成员,可切换合计或按团体分计。";
|
||||
"ledger.stats" = "统计";
|
||||
"management.catalog.groupImpact" = "将归档 %d 个团体及其所属关系。成员的其他团体身份、已有物贩与统计保留。";
|
||||
"management.catalog.memberImpact" = "将归档 %d 位成员及其全部团体身份。已有物贩和统计保留,历史记录仍可编辑。";
|
||||
|
||||
// Image export
|
||||
@@ -0,0 +1,209 @@
|
||||
// Oshicue Keeps — zh-Hant
|
||||
|
||||
"import.file" = "選擇檔案";
|
||||
"import.validate" = "檢查格式";
|
||||
"settings.title" = "設定";
|
||||
"settings.language" = "語言";
|
||||
"settings.followSystem" = "跟隨系統";
|
||||
"settings.about" = "關於";
|
||||
"settings.version" = "版本";
|
||||
"common.done" = "完成";
|
||||
"common.cancel" = "取消";
|
||||
"common.close" = "關閉";
|
||||
"settings.readError" = "無法讀取已儲存的資料。";
|
||||
"settings.saveError" = "無法儲存變更。";
|
||||
"settings.storageError" = "已儲存的資料發生問題。";
|
||||
"import.readError" = "無法讀取檔案,請選擇 UTF-8 編碼的 JSON 檔案。";
|
||||
"ledger.title" = "手帳";
|
||||
"ledger.add" = "新增紀錄";
|
||||
"ledger.today" = "今天";
|
||||
"ledger.month" = "月";
|
||||
"ledger.year" = "年";
|
||||
"ledger.day" = "日";
|
||||
"ledger.lifetime" = "生涯累計";
|
||||
"ledger.quantity" = "數量";
|
||||
"ledger.spending" = "消費金額";
|
||||
"ledger.memberCombined" = "成員合計";
|
||||
"ledger.memberByGroup" = "成員分團";
|
||||
"ledger.group" = "團體";
|
||||
"ledger.currency" = "幣別";
|
||||
"ledger.total" = "總計";
|
||||
"ledger.membersCount" = "%d 位成員";
|
||||
"ledger.itemsCount" = "%d 張";
|
||||
"ledger.noRecords" = "當天暫無紀錄";
|
||||
"ledger.noRecordsHint" = "點按 + 記錄一筆物販。";
|
||||
"ledger.records" = "物販紀錄";
|
||||
"ledger.edit" = "編輯";
|
||||
"ledger.delete" = "刪除";
|
||||
"ledger.deleteTitle" = "刪除這筆紀錄?";
|
||||
"ledger.deleteMessage" = "這筆紀錄的數量和金額將從統計中移除。";
|
||||
"ledger.manage" = "管理";
|
||||
"ledger.import" = "匯入手帳";
|
||||
"ledger.export" = "匯出備份";
|
||||
"ledger.backup" = "JSON 備份";
|
||||
"ledger.importHint" = "貼上手帳 JSON 或選擇備份檔案,檢查預覽後匯入。";
|
||||
"ledger.preview" = "預覽";
|
||||
"ledger.apply" = "確認匯入";
|
||||
"ledger.summary" = "%d 位成員 · %d 筆紀錄";
|
||||
"ledger.editRecord" = "編輯物販";
|
||||
"ledger.date" = "日期";
|
||||
"ledger.member" = "成員";
|
||||
"ledger.chooseMember" = "選擇成員";
|
||||
"ledger.chooseGroup" = "選擇團體";
|
||||
"ledger.type" = "物販類型";
|
||||
"ledger.unitPrice" = "單價";
|
||||
"ledger.amount" = "金額";
|
||||
"ledger.event" = "活動";
|
||||
"ledger.optional" = "選填";
|
||||
"ledger.noEvent" = "不關聯活動";
|
||||
"ledger.city" = "城市";
|
||||
"ledger.venue" = "場館";
|
||||
"ledger.address" = "場館地址";
|
||||
"ledger.note" = "備註";
|
||||
"ledger.save" = "儲存";
|
||||
"ledger.addMember" = "新增成員";
|
||||
"ledger.addType" = "新增物販類型";
|
||||
"ledger.addEvent" = "新增活動";
|
||||
"ledger.priceHint" = "新增時先用同成員、團體、類型及幣別在所選日期或之前的最近價格,再用上次新增同類型同幣別價格,最後用預設價或 0。可手動修改,歷史紀錄保留原價。";
|
||||
"ledger.invalidPrice" = "請輸入非負單價。日圓和韓元須為整數,其他幣別最多兩位小數。";
|
||||
"ledger.invalidQuantity" = "數量必須至少為 1。";
|
||||
"ledger.requiredSelection" = "請選擇成員、團體和物販類型。";
|
||||
"ledger.currencyHint" = "不同幣別分別統計金額和消費排行,不會自動換匯或混加。";
|
||||
"ledger.groupColor" = "代表色";
|
||||
"ledger.loadDemo" = "載入手帳範例";
|
||||
"ledger.loadDemoHint" = "使用範例成員和物販紀錄體驗手帳功能。";
|
||||
"ledger.product.polaroid" = "拍立得";
|
||||
"ledger.product.wide" = "WIDE 拍立得";
|
||||
"ledger.product.mobile" = "手機合照";
|
||||
"ledger.demoRequiresEmpty" = "僅能在空手帳中載入範例。";
|
||||
"ledger.error.overflow" = "金額或數量過大,請輸入較小的數值。";
|
||||
"ledger.previousMonth" = "上個月";
|
||||
"ledger.nextMonth" = "下個月";
|
||||
"ledger.catalog.members" = "成員";
|
||||
"ledger.catalog.products" = "物販類型";
|
||||
"ledger.catalog.events" = "活動";
|
||||
"ledger.catalog.add" = "新增範本";
|
||||
"ledger.catalog.search" = "成員/團體/類型/活動名稱";
|
||||
"ledger.catalog.memberCount" = "共 %d 位成員";
|
||||
"ledger.catalog.noGroupMembers" = "該團體尚無成員。";
|
||||
"ledger.member.shared" = "兼任多個團體";
|
||||
"ledger.member.reuse" = "關聯已有成員(兼任)";
|
||||
"ledger.member.existing" = "已有成員";
|
||||
"ledger.member.name" = "成員名稱";
|
||||
"ledger.member.photo" = "從相簿選擇頭像";
|
||||
"ledger.member.removePhoto" = "移除頭像";
|
||||
"ledger.member.identity" = "成員與頭像";
|
||||
"ledger.member.identityHint" = "同一人兼任其他團體時,請關聯已有成員,即可合計或按團體分計。";
|
||||
"ledger.member.affiliation" = "所屬團體與代表色";
|
||||
"ledger.member.prices" = "預設單價";
|
||||
"ledger.member.pricesHint" = "單價可留空,記帳時再填;不同團體可分別設價,修改不會改變歷史消費。";
|
||||
"ledger.member.photoError" = "無法讀取這張圖片,請選擇其他照片。";
|
||||
"ledger.member.photoTooLarge" = "請選擇小於 10 MB 的照片。";
|
||||
"ledger.group.edit" = "編輯團體";
|
||||
"ledger.group.name" = "團體名稱";
|
||||
"ledger.product.name" = "類型名稱";
|
||||
"ledger.event.name" = "活動名稱";
|
||||
"ledger.event.hasDate" = "指定活動日期";
|
||||
"ledger.member.add" = "新增成員";
|
||||
"ledger.group.add" = "新增團體";
|
||||
"ledger.product.add" = "新增物販類型";
|
||||
"ledger.event.add" = "新增活動";
|
||||
"ledger.period" = "統計週期";
|
||||
"ledger.rankingBy" = "統計分類";
|
||||
"ledger.metric" = "排序指標";
|
||||
"ledger.allTypes" = "全部類型";
|
||||
"ledger.allGroups" = "全部團體";
|
||||
"ledger.backupHint" = "一併備份團體、成員、頭像、單價和物販紀錄。";
|
||||
"ledger.chooseRecord" = "選擇要編輯的物販";
|
||||
"ledger.chooseRecordHint" = "這位成員當天有多筆紀錄,請選擇其中一筆編輯。";
|
||||
"ledger.deleted" = "已刪除";
|
||||
"ledger.record.delete" = "刪除這筆物販";
|
||||
"ledger.member.delete" = "刪除成員";
|
||||
"ledger.member.deleteTitle" = "刪除此成員?";
|
||||
"ledger.member.deleteMessage" = "將從所有團體中移除此成員。已記錄的物販和消費統計會保留。";
|
||||
"ledger.group.delete" = "刪除團體";
|
||||
"ledger.group.deleteTitle" = "刪除此團體?";
|
||||
"ledger.group.deleteMessage" = "將從資料列表移除此團體及其成員關係。兼任其他團體的成員、已有物販和消費統計會保留。";
|
||||
"ledger.catalogUnavailable" = "此成員或團體已刪除,無法儲存這次資料修改;已有物販仍可編輯。";
|
||||
"settings.data" = "資料管理";
|
||||
"settings.localData" = "資料儲存在本機,可隨時匯出備份。";
|
||||
"settings.ledgerDemo" = "載入手帳範例";
|
||||
"ledger.member.favorite" = "最愛成員";
|
||||
"ledger.member.favoriteHint" = "最愛成員會置頂顯示在物販紀錄的成員選擇中;同一成員的所有團體身分共用此設定。";
|
||||
"ledger.members.favorites" = "最愛成員";
|
||||
"management.records" = "紀錄管理";
|
||||
"management.backup" = "備份";
|
||||
"management.filters" = "篩選條件";
|
||||
"management.search" = "搜尋成員、團體、類型、活動或備註";
|
||||
"management.dateRange" = "依日期範圍篩選";
|
||||
"management.startDate" = "開始日期";
|
||||
"management.endDate" = "結束日期";
|
||||
"management.invalidDateRange" = "開始日期不可晚於結束日期。";
|
||||
"management.all" = "全部";
|
||||
"management.selectFiltered" = "全選目前結果";
|
||||
"management.clearSelection" = "取消選取";
|
||||
"management.selectionHint" = "僅刪除勾選的紀錄;變更篩選會清除選取。";
|
||||
"management.selectedCount" = "已選 %d 筆";
|
||||
"management.resultCount" = "共 %d 筆結果";
|
||||
"management.deleteSelected" = "刪除所選";
|
||||
"management.empty" = "沒有符合條件的紀錄";
|
||||
"management.clearAll" = "刪除全部物販紀錄";
|
||||
"management.clearAllHint" = "刪除全部物販會影響所有日期、成員與幣別。團體、成員、類型與活動資料保留。";
|
||||
"ledger.management" = "手帳管理";
|
||||
"ledger.management.deleteSummary" = "將刪除 %d 筆紀錄,共 %@ 件。";
|
||||
"ledger.management.deleteImpact" = "這些紀錄的數量和金額將從統計中移除,此操作無法復原。";
|
||||
"management.catalog" = "資料清理";
|
||||
"management.catalog.search" = "搜尋成員或團體";
|
||||
"management.catalog.hint" = "刪除成員會影響其所有團體身分;刪除團體僅影響該團體。現有紀錄保留,可用有效備份還原資料。";
|
||||
"management.catalog.empty" = "沒有可清理的成員或團體";
|
||||
"management.catalog.deleteTitle" = "刪除所選資料?";
|
||||
"ledger.exportCSV" = "匯出物販表格(CSV)";
|
||||
"ledger.exportCSVHint" = "每筆物販一列,可用 Numbers 或 Excel 檢視、彙總。CSV 只用於檢視,還原資料請使用 JSON 備份。";
|
||||
"ledger.quickAdd.product" = "再記一份:%@";
|
||||
"ledger.quickAddHint" = "點按 ⊕ 為同一筆物販數量加 1,單價、活動等資料不變。";
|
||||
|
||||
"settings.keepsAbout" = "Oshicue Keeps · 應援紀錄手帳。";
|
||||
"ledger.record.details" = "紀錄標籤";
|
||||
"ledger.record.detailsHint" = "這些標籤與顏色會隨此筆紀錄保存。更換成員或類型時會自動更新;也可在此處直接修改歷史紀錄。";
|
||||
|
||||
// Keys looked up through helpers and ternaries
|
||||
"import.copied" = "已複製";
|
||||
"ledger.calendar" = "日曆";
|
||||
"ledger.catalog" = "成員與類型";
|
||||
"ledger.catalog.emptyEvents" = "儲存活動,快速重用城市和場館。";
|
||||
"ledger.catalog.emptyMembers" = "先新增團體和成員。";
|
||||
"ledger.combinedHint" = "關聯為同一人的成員,將跨團體合併統計。";
|
||||
"ledger.copyTemplate" = "複製範本";
|
||||
"ledger.error.avatar" = "頭像必須為有效的 JPEG 圖片。";
|
||||
"ledger.error.avatarSize" = "頭像檔案過大,上限為 2 MB。";
|
||||
"ledger.error.color" = "請使用 #RRGGBB 格式的六位色碼。";
|
||||
"ledger.error.currency" = "不支援此幣別。";
|
||||
"ledger.error.currencyRequired" = "請選擇一種幣別查看消費排行。";
|
||||
"ledger.error.date" = "請使用有效的 yyyy-MM-dd 格式日期。";
|
||||
"ledger.error.documentSize" = "匯入檔案過大,上限為 20 MB。";
|
||||
"ledger.error.duplicateID" = "ID 重複,同一列表中的每個項目必須使用不同 ID。";
|
||||
"ledger.error.emptyField" = "此欄位不能留空。";
|
||||
"ledger.error.emptyImport" = "沒有可匯入的團體、成員、物販類型、活動或紀錄。";
|
||||
"ledger.error.fieldType" = "欄位類型錯誤或為空值,請對照範本檢查下面標出的欄位。";
|
||||
"ledger.error.invalidJSON" = "文字不是有效的 JSON,請檢查逗號、引號和括號。";
|
||||
"ledger.error.membership" = "成員與團體的所屬關係缺失或重複。";
|
||||
"ledger.error.missingField" = "缺少必填欄位,請補充下面標出的欄位。";
|
||||
"ledger.error.price" = "單價須以最小貨幣單位填寫非負整數。";
|
||||
"ledger.error.quantity" = "數量必須為正整數。";
|
||||
"ledger.error.recordConflict" = "相同 ID 的紀錄內容不一致。新消費請使用新的 ID,已有紀錄請在 App 內編輯。";
|
||||
"ledger.error.reference" = "找不到引用的資料項目,請補充該項目或修正 ID。";
|
||||
"ledger.error.schemaVersion" = "不支援此手帳格式版本,請將 schemaVersion 設為 1。";
|
||||
"ledger.event.edit" = "編輯活動";
|
||||
"ledger.management.clearTitle" = "刪除全部物販紀錄?";
|
||||
"ledger.management.deleteTitle" = "刪除所選物販紀錄?";
|
||||
"ledger.member.edit" = "編輯成員";
|
||||
"ledger.newRecord" = "新增物販";
|
||||
"ledger.product.edit" = "編輯物販類型";
|
||||
"ledger.replacesDemo" = "未經修改的範例手帳資料會被本次匯入取代。";
|
||||
"ledger.restoreHint" = "相同 ID 的成員、團體和範本資料會更新。相同的紀錄不會重複新增,已有的其他紀錄會保留。";
|
||||
"ledger.splitHint" = "兼任多個團體的成員,可切換合計或按團體分計。";
|
||||
"ledger.stats" = "統計";
|
||||
"management.catalog.groupImpact" = "將封存 %d 個團體及其所屬關係。成員的其他團體身分、現有物販與統計保留。";
|
||||
"management.catalog.memberImpact" = "將封存 %d 位成員及其所有團體身分。現有物販與統計保留,歷史紀錄仍可編輯。";
|
||||
|
||||
// Image export
|
||||
@@ -0,0 +1,67 @@
|
||||
{
|
||||
"schemaVersion": 1,
|
||||
"groups": [
|
||||
{ "id": "luna", "name": "LUNA NOTE" },
|
||||
{ "id": "prism", "name": "PRISM DAYS" }
|
||||
],
|
||||
"members": [
|
||||
{ "id": "mio", "name": "Mio" },
|
||||
{ "id": "rina", "name": "Rina" }
|
||||
],
|
||||
"products": [
|
||||
{ "id": "cheki", "name": "Cheki" },
|
||||
{ "id": "wide-cheki", "name": "WIDE Cheki" },
|
||||
{ "id": "phone-photo", "name": "Phone photo" }
|
||||
],
|
||||
"memberships": [
|
||||
{
|
||||
"id": "mio-luna", "memberID": "mio", "groupID": "luna", "color": "#F28AAF",
|
||||
"prices": [
|
||||
{ "productID": "cheki", "currency": "JPY", "unitPriceMinor": 2000 },
|
||||
{ "productID": "wide-cheki", "currency": "JPY", "unitPriceMinor": 3500 },
|
||||
{ "productID": "phone-photo", "currency": "JPY", "unitPriceMinor": 1500 }
|
||||
]
|
||||
},
|
||||
{
|
||||
"id": "mio-prism", "memberID": "mio", "groupID": "prism", "color": "#9B8CF5",
|
||||
"prices": [{ "productID": "cheki", "currency": "JPY", "unitPriceMinor": 2500 }]
|
||||
},
|
||||
{
|
||||
"id": "rina-luna", "memberID": "rina", "groupID": "luna", "color": "#66C7A5",
|
||||
"prices": [{ "productID": "phone-photo", "currency": "CNY", "unitPriceMinor": 8000 }]
|
||||
}
|
||||
],
|
||||
"events": [
|
||||
{
|
||||
"id": "mini-fes-20261014", "name": "Oshicue Mini Fes", "date": "2026-10-14",
|
||||
"city": "Tokyo", "venue": "Luna Hall", "address": "Shibuya, Tokyo"
|
||||
}
|
||||
],
|
||||
"records": [
|
||||
{
|
||||
"id": "purchase-001", "date": "2026-10-14",
|
||||
"memberID": "mio", "groupID": "luna", "productID": "cheki",
|
||||
"quantity": 5, "unitPriceMinor": 2000, "currency": "JPY", "eventID": "mini-fes-20261014",
|
||||
"memberNameSnapshot": "Mio", "groupNameSnapshot": "LUNA NOTE",
|
||||
"productNameSnapshot": "Cheki", "colorSnapshot": "#F28AAF",
|
||||
"eventNameSnapshot": "Oshicue Mini Fes", "citySnapshot": "Tokyo",
|
||||
"venueSnapshot": "Luna Hall", "addressSnapshot": "Shibuya, Tokyo",
|
||||
"note": "示例记录:请替换为自己的消费"
|
||||
},
|
||||
{
|
||||
"id": "purchase-002", "date": "2026-10-14",
|
||||
"memberID": "mio", "groupID": "prism", "productID": "cheki",
|
||||
"quantity": 2, "unitPriceMinor": 2500, "currency": "JPY",
|
||||
"memberNameSnapshot": "Mio", "groupNameSnapshot": "PRISM DAYS",
|
||||
"productNameSnapshot": "Cheki", "colorSnapshot": "#9B8CF5"
|
||||
},
|
||||
{
|
||||
"id": "purchase-003", "date": "2026-10-15",
|
||||
"memberID": "rina", "groupID": "luna", "productID": "phone-photo",
|
||||
"quantity": 1, "unitPriceMinor": 8000, "currency": "CNY",
|
||||
"memberNameSnapshot": "Rina", "groupNameSnapshot": "LUNA NOTE",
|
||||
"productNameSnapshot": "Phone photo", "colorSnapshot": "#66C7A5",
|
||||
"citySnapshot": "Shanghai"
|
||||
}
|
||||
]
|
||||
}
|
||||
@@ -0,0 +1,257 @@
|
||||
package com.oshicue.keeps
|
||||
|
||||
import android.os.Bundle
|
||||
import androidx.activity.ComponentActivity
|
||||
import androidx.activity.compose.setContent
|
||||
import androidx.activity.enableEdgeToEdge
|
||||
import androidx.compose.foundation.background
|
||||
import androidx.compose.foundation.layout.Box
|
||||
import androidx.compose.foundation.layout.Column
|
||||
import androidx.compose.foundation.layout.width
|
||||
import androidx.compose.foundation.layout.fillMaxSize
|
||||
import androidx.compose.foundation.layout.padding
|
||||
import androidx.compose.material.icons.Icons
|
||||
import androidx.compose.material.icons.filled.Add
|
||||
import androidx.compose.material.icons.filled.BarChart
|
||||
import androidx.compose.material.icons.filled.CalendarMonth
|
||||
import androidx.compose.material.icons.filled.People
|
||||
import androidx.compose.material.icons.filled.Settings
|
||||
import androidx.compose.material.icons.filled.Tune
|
||||
import androidx.compose.material3.Icon
|
||||
import androidx.compose.material3.NavigationBar
|
||||
import androidx.compose.material3.NavigationBarItem
|
||||
import androidx.compose.material3.NavigationBarItemDefaults
|
||||
import androidx.compose.material3.Scaffold
|
||||
import androidx.compose.material3.Text
|
||||
import androidx.compose.runtime.Composable
|
||||
import androidx.compose.runtime.CompositionLocalProvider
|
||||
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.Color
|
||||
import androidx.compose.ui.platform.LocalContext
|
||||
import androidx.compose.ui.unit.dp
|
||||
import androidx.compose.ui.unit.sp
|
||||
import androidx.lifecycle.compose.collectAsStateWithLifecycle
|
||||
import androidx.lifecycle.viewmodel.compose.viewModel
|
||||
import com.oshicue.keeps.core.AppLanguage
|
||||
import com.oshicue.keeps.core.L10n
|
||||
import com.oshicue.keeps.core.LedgerRecord
|
||||
import com.oshicue.keeps.core.configuration
|
||||
import com.oshicue.keeps.ui.KeepsSettingsScreen
|
||||
import com.oshicue.keeps.ui.Kit
|
||||
import com.oshicue.keeps.ui.KitTheme
|
||||
import com.oshicue.keeps.ui.LedgerCalendarScreen
|
||||
import com.oshicue.keeps.ui.LedgerCatalogScreen
|
||||
import com.oshicue.keeps.ui.LedgerManagementScreen
|
||||
import com.oshicue.keeps.ui.LedgerRecordEditor
|
||||
import com.oshicue.keeps.ui.LedgerStatisticsScreen
|
||||
import com.oshicue.keeps.ui.LedgerStore
|
||||
import java.time.YearMonth
|
||||
|
||||
class MainActivity : ComponentActivity() {
|
||||
override fun onCreate(savedInstanceState: Bundle?) {
|
||||
super.onCreate(savedInstanceState)
|
||||
enableEdgeToEdge()
|
||||
setContent { KeepsApp() }
|
||||
}
|
||||
}
|
||||
|
||||
/** The bottom tabs, left to right: 日历, 成员与类型, 统计 and 设置. */
|
||||
private enum class KeepsTab { Calendar, Catalog, Stats, Settings }
|
||||
|
||||
@Composable
|
||||
fun KeepsApp() {
|
||||
val systemConfiguration = androidx.compose.ui.platform.LocalConfiguration.current
|
||||
val context = LocalContext.current
|
||||
val preferences = remember {
|
||||
context.getSharedPreferences("keeps", android.content.Context.MODE_PRIVATE)
|
||||
}
|
||||
var languageTag by remember { mutableStateOf(preferences.getString(AppLanguage.preferenceKey, null)) }
|
||||
val storedLanguage = AppLanguage.fromTag(languageTag)
|
||||
val language = remember(languageTag) {
|
||||
if (storedLanguage == AppLanguage.System) {
|
||||
val locales = systemConfiguration.locales
|
||||
AppLanguage.resolveSystemLanguage(
|
||||
(0 until locales.size()).map { locales[it].toLanguageTag() },
|
||||
if (locales.size() > 0) locales[0].country else "",
|
||||
)
|
||||
} else storedLanguage
|
||||
}
|
||||
L10n.apply(context, languageTag)
|
||||
|
||||
val store: LedgerStore = viewModel(factory = LedgerStore.Factory(context))
|
||||
val state by store.state.collectAsStateWithLifecycle()
|
||||
|
||||
var tab by remember { mutableStateOf(KeepsTab.Calendar) }
|
||||
// The calendar's selected day is shared: new purchases and the statistics period start from it.
|
||||
var selectedDate by remember { mutableStateOf(java.time.LocalDate.now()) }
|
||||
var shownMonth by remember { mutableStateOf(YearMonth.now()) }
|
||||
var editor by remember { mutableStateOf<EditorTarget?>(null) }
|
||||
var showManagement by remember { mutableStateOf(false) }
|
||||
var deleteRecord by remember { mutableStateOf<LedgerRecord?>(null) }
|
||||
|
||||
val localeConfiguration = remember(language, context) {
|
||||
language.configuration(systemConfiguration)
|
||||
}
|
||||
val localizedContext = remember(localeConfiguration, context) {
|
||||
context.createConfigurationContext(localeConfiguration)
|
||||
}
|
||||
|
||||
CompositionLocalProvider(LocalContext provides localizedContext) {
|
||||
KitTheme {
|
||||
if (editor != null) {
|
||||
val target = editor!!
|
||||
LedgerRecordEditor(store, target.date, target.record) { editor = null }
|
||||
return@KitTheme
|
||||
}
|
||||
if (showManagement) {
|
||||
LedgerManagementScreen(store) { showManagement = false }
|
||||
return@KitTheme
|
||||
}
|
||||
|
||||
Scaffold(
|
||||
containerColor = Kit.colors.background,
|
||||
bottomBar = {
|
||||
NavigationBar(containerColor = Kit.colors.surface) {
|
||||
NavigationBarItem(
|
||||
selected = tab == KeepsTab.Calendar,
|
||||
onClick = { tab = KeepsTab.Calendar },
|
||||
icon = { Icon(Icons.Filled.CalendarMonth, contentDescription = null) },
|
||||
label = { Text(L10n.text("ledger.calendar"), fontSize = 11.sp) },
|
||||
colors = barColors(),
|
||||
)
|
||||
NavigationBarItem(
|
||||
selected = tab == KeepsTab.Catalog,
|
||||
onClick = { tab = KeepsTab.Catalog },
|
||||
icon = { Icon(Icons.Filled.People, contentDescription = null) },
|
||||
label = { Text(L10n.text("ledger.catalog"), fontSize = 11.sp) },
|
||||
colors = barColors(),
|
||||
)
|
||||
NavigationBarItem(
|
||||
selected = tab == KeepsTab.Stats,
|
||||
onClick = { tab = KeepsTab.Stats },
|
||||
icon = { Icon(Icons.Filled.BarChart, contentDescription = null) },
|
||||
label = { Text(L10n.text("ledger.stats"), fontSize = 11.sp) },
|
||||
colors = barColors(),
|
||||
)
|
||||
NavigationBarItem(
|
||||
selected = tab == KeepsTab.Settings,
|
||||
onClick = { tab = KeepsTab.Settings },
|
||||
icon = { Icon(Icons.Filled.Settings, contentDescription = null) },
|
||||
label = { Text(L10n.text("settings.title"), fontSize = 11.sp) },
|
||||
colors = barColors(),
|
||||
)
|
||||
}
|
||||
},
|
||||
) { padding ->
|
||||
Box(Modifier.fillMaxSize().background(Kit.colors.background).padding(padding)) {
|
||||
when (tab) {
|
||||
KeepsTab.Calendar -> Column {
|
||||
KeepsTopBar(
|
||||
onManagement = { showManagement = true },
|
||||
onAdd = { editor = EditorTarget(java.time.LocalDate.now().toString(), null) },
|
||||
)
|
||||
LedgerCalendarScreen(
|
||||
store = store,
|
||||
selectedDate = selectedDate,
|
||||
shownMonth = shownMonth,
|
||||
onSelectedDate = { selectedDate = it },
|
||||
onShownMonth = { shownMonth = it },
|
||||
onAdd = { editor = EditorTarget(selectedDate.toString(), null) },
|
||||
onOpenCatalog = { tab = KeepsTab.Catalog },
|
||||
onEdit = { editor = EditorTarget(it.date, it) },
|
||||
onDelete = { deleteRecord = it },
|
||||
)
|
||||
}
|
||||
KeepsTab.Catalog -> Column {
|
||||
KeepsTopBar(
|
||||
onManagement = { showManagement = true },
|
||||
onAdd = { editor = EditorTarget(selectedDate.toString(), null) },
|
||||
)
|
||||
LedgerCatalogScreen(store)
|
||||
}
|
||||
KeepsTab.Stats -> Column {
|
||||
KeepsTopBar(
|
||||
onManagement = { showManagement = true },
|
||||
onAdd = { editor = EditorTarget(selectedDate.toString(), null) },
|
||||
)
|
||||
LedgerStatisticsScreen(store, selectedDate)
|
||||
}
|
||||
KeepsTab.Settings -> KeepsSettingsScreen(
|
||||
store = store,
|
||||
language = storedLanguage,
|
||||
onLanguageChange = { value ->
|
||||
languageTag = value.tag
|
||||
preferences.edit().putString(AppLanguage.preferenceKey, value.tag).apply()
|
||||
},
|
||||
onOpenManagement = { showManagement = true },
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
state.storageError?.let { message ->
|
||||
androidx.compose.material3.AlertDialog(
|
||||
onDismissRequest = { store.clearError() },
|
||||
title = { Text(L10n.text("settings.storageError")) },
|
||||
text = { Text(message) },
|
||||
confirmButton = {
|
||||
androidx.compose.material3.TextButton(onClick = { store.clearError() }) {
|
||||
Text(L10n.text("common.done"))
|
||||
}
|
||||
},
|
||||
containerColor = Kit.colors.surface,
|
||||
)
|
||||
}
|
||||
|
||||
deleteRecord?.let { record ->
|
||||
androidx.compose.material3.AlertDialog(
|
||||
onDismissRequest = { deleteRecord = null },
|
||||
title = { Text(L10n.text("ledger.deleteTitle")) },
|
||||
text = { Text(L10n.text("ledger.deleteMessage")) },
|
||||
confirmButton = {
|
||||
androidx.compose.material3.TextButton(onClick = {
|
||||
store.deleteRecord(record.id)
|
||||
deleteRecord = null
|
||||
}) { Text(L10n.text("ledger.delete")) }
|
||||
},
|
||||
dismissButton = {
|
||||
androidx.compose.material3.TextButton(onClick = { deleteRecord = null }) {
|
||||
Text(L10n.text("common.cancel"))
|
||||
}
|
||||
},
|
||||
containerColor = Kit.colors.surface,
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/** An open record editor: a new purchase on a day, or an existing one. */
|
||||
private data class EditorTarget(val date: String, val record: LedgerRecord?)
|
||||
|
||||
/** Every Keeps tab shares the wordmark row with ledger management and the add button. */
|
||||
@Composable
|
||||
private fun KeepsTopBar(onManagement: () -> Unit, onAdd: () -> Unit) {
|
||||
com.oshicue.keeps.ui.KitTopBar {
|
||||
com.oshicue.keeps.ui.CircleIconButton(
|
||||
Icons.Filled.Tune, L10n.text("ledger.management"), onManagement,
|
||||
)
|
||||
androidx.compose.foundation.layout.Spacer(Modifier.width(8.dp))
|
||||
com.oshicue.keeps.ui.CircleIconButton(
|
||||
Icons.Filled.Add, L10n.text("ledger.add"), onAdd,
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
@Composable
|
||||
private fun barColors() = NavigationBarItemDefaults.colors(
|
||||
selectedIconColor = Kit.colors.accentText,
|
||||
selectedTextColor = Kit.colors.accentText,
|
||||
unselectedIconColor = Kit.colors.muted,
|
||||
unselectedTextColor = Kit.colors.muted,
|
||||
indicatorColor = Color.Transparent,
|
||||
)
|
||||
@@ -0,0 +1,41 @@
|
||||
package com.oshicue.keeps.core
|
||||
|
||||
import java.time.Instant
|
||||
import java.time.ZoneId
|
||||
import java.time.format.DateTimeFormatter
|
||||
import java.util.Locale
|
||||
|
||||
/** Date and time labels. Formatters are cached because the timeline formats many labels per tick. */
|
||||
object KitDate {
|
||||
private val cache = mutableMapOf<String, DateTimeFormatter>()
|
||||
|
||||
private fun formatter(pattern: String, localeID: String, zone: ZoneId): DateTimeFormatter {
|
||||
val key = localeID + "|" + zone.id + "|" + pattern
|
||||
return cache.getOrPut(key) {
|
||||
DateTimeFormatter.ofPattern(pattern, Locale.forLanguageTag(localeID)).withZone(zone)
|
||||
}
|
||||
}
|
||||
|
||||
fun string(date: Instant, pattern: String, zone: ZoneId): String =
|
||||
formatter(pattern, L10n.current.localeID, zone).format(date)
|
||||
|
||||
fun time(date: Instant, zone: ZoneId): String = string(date, "HH:mm", zone)
|
||||
|
||||
/** The local civil day used in exported file names, such as 2026-11-12. */
|
||||
fun civilDay(date: Instant): String = string(date, "yyyy-MM-dd", ZoneId.systemDefault())
|
||||
}
|
||||
|
||||
/** Day and month titles for the calendar, resolved in the chosen app language. */
|
||||
object KitDateLabels {
|
||||
fun monthTitle(month: java.time.LocalDate, localeID: String): String {
|
||||
val formatter = DateTimeFormatter.ofPattern("yyyy MMMM", Locale.forLanguageTag(localeID))
|
||||
return formatter.format(month)
|
||||
}
|
||||
|
||||
fun weekdayInitials(localeID: String): List<String> {
|
||||
// A narrow weekday name is one character in every supported language except Thai.
|
||||
val formatter = DateTimeFormatter.ofPattern("EEEEE", Locale.forLanguageTag(localeID))
|
||||
val monday = java.time.LocalDate.of(2024, 1, 1) // a Monday
|
||||
return (0..6).map { formatter.format(monday.plusDays(it.toLong())) }
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,60 @@
|
||||
package com.oshicue.keeps.core
|
||||
|
||||
import android.content.Context
|
||||
import kotlinx.serialization.Serializable
|
||||
import kotlinx.serialization.json.Json
|
||||
import java.io.File
|
||||
|
||||
/**
|
||||
* Launch flags used only by isolated UI tests on Android. Release builds always read the user's own files.
|
||||
* The Android port has no such tests, so the values are constants; keeping them named makes the store
|
||||
* code read the same as the iOS one.
|
||||
*/
|
||||
object KitLaunch {
|
||||
var isUITest: Boolean = false
|
||||
var preservesUITestData: Boolean = false
|
||||
val loadsSavedData: Boolean get() = !isUITest || preservesUITestData
|
||||
}
|
||||
|
||||
/**
|
||||
* One module's JSON file in the app's private storage. Writes are atomic, and an unreadable file is
|
||||
* copied aside before anything replaces it, so a corrupt file never takes the user's data with it.
|
||||
*/
|
||||
class KitStorageFile(context: Context, name: String) {
|
||||
val file: File
|
||||
private var isUnreadable = false
|
||||
|
||||
init {
|
||||
val directory = File(context.filesDir, AppBrand.storageFolder)
|
||||
file = File(directory, if (KitLaunch.isUITest) "ui-test-$name" else name)
|
||||
}
|
||||
|
||||
val hasSavedData: Boolean get() = KitLaunch.loadsSavedData && file.exists()
|
||||
|
||||
fun read(maximumBytes: Int? = null): ByteArray {
|
||||
if (maximumBytes != null && file.length() > maximumBytes) throw SizeLimitError()
|
||||
return file.readBytes()
|
||||
}
|
||||
|
||||
fun markUnreadable() {
|
||||
isUnreadable = true
|
||||
}
|
||||
|
||||
fun write(data: ByteArray) {
|
||||
file.parentFile?.mkdirs()
|
||||
if (isUnreadable && file.exists()) {
|
||||
val recovery = File(file.parentFile, file.nameWithoutExtension + ".recovery-" +
|
||||
java.util.UUID.randomUUID() + ".json")
|
||||
file.copyTo(recovery, overwrite = true)
|
||||
isUnreadable = false
|
||||
}
|
||||
val temporary = File(file.parentFile, file.name + ".tmp")
|
||||
temporary.writeBytes(data)
|
||||
if (!temporary.renameTo(file)) {
|
||||
file.writeBytes(data)
|
||||
temporary.delete()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
class SizeLimitError : Exception("The file is too large.")
|
||||
@@ -0,0 +1,151 @@
|
||||
package com.oshicue.keeps.core
|
||||
|
||||
enum class LedgerPeriod { Day, Month, Year, Lifetime }
|
||||
|
||||
enum class LedgerGrouping { MemberCombined, MemberByGroup, Group }
|
||||
|
||||
enum class LedgerMetric { Quantity, Spending }
|
||||
|
||||
data class LedgerProductSummary(
|
||||
val id: String,
|
||||
val name: String,
|
||||
val quantity: Int,
|
||||
val amountsByCurrency: Map<String, Long>,
|
||||
)
|
||||
|
||||
data class LedgerSummary(
|
||||
val quantity: Int = 0,
|
||||
val amountsByCurrency: Map<String, Long> = emptyMap(),
|
||||
val productRows: List<LedgerProductSummary> = emptyList(),
|
||||
val memberCount: Int = 0,
|
||||
)
|
||||
|
||||
data class LedgerRankRow(
|
||||
val id: String,
|
||||
val name: String,
|
||||
val subtitle: String,
|
||||
val color: String,
|
||||
val memberID: String?,
|
||||
val groupID: String?,
|
||||
val quantity: Int,
|
||||
val amountsByCurrency: Map<String, Long>,
|
||||
val rank: Int,
|
||||
/** Fraction of the selected quantity or single-currency spending total, in 0...1. */
|
||||
val share: Double,
|
||||
val productRows: List<LedgerProductSummary>,
|
||||
)
|
||||
|
||||
object LedgerAnalytics {
|
||||
fun filtered(records: List<LedgerRecord>, period: LedgerPeriod, date: String, currency: String? = null): List<LedgerRecord> {
|
||||
if (period != LedgerPeriod.Lifetime && LedgerDates.parse(date) == null) return emptyList()
|
||||
if (currency != null && runCatching { LedgerCurrency.valueOf(currency) }.isFailure) return emptyList()
|
||||
return records.filter { record ->
|
||||
if (currency != null && record.currency != currency) return@filter false
|
||||
when (period) {
|
||||
LedgerPeriod.Day -> record.date == date
|
||||
LedgerPeriod.Month -> record.date.take(7) == date.take(7)
|
||||
LedgerPeriod.Year -> record.date.take(4) == date.take(4)
|
||||
LedgerPeriod.Lifetime -> true
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/** Preserves each currency as a separate balance and prices as captured in each purchase. */
|
||||
fun summarize(records: List<LedgerRecord>): LedgerSummary {
|
||||
var result = LedgerSummary()
|
||||
val products = mutableMapOf<String, LedgerProductSummary>()
|
||||
val ordered = records.sortedWith(compareByDescending<LedgerRecord> { it.date }.thenBy { it.id })
|
||||
for (record in ordered) {
|
||||
val total = checkedTotal(record)
|
||||
result = result.copy(
|
||||
quantity = Math.addExact(result.quantity, record.quantity),
|
||||
amountsByCurrency = result.amountsByCurrency + (record.currency to
|
||||
Math.addExact(result.amountsByCurrency.getOrDefault(record.currency, 0L), total)),
|
||||
)
|
||||
val product = products[record.productID]
|
||||
?: LedgerProductSummary(record.productID, record.productNameSnapshot, 0, emptyMap())
|
||||
products[record.productID] = product.copy(
|
||||
quantity = Math.addExact(product.quantity, record.quantity),
|
||||
amountsByCurrency = product.amountsByCurrency + (record.currency to
|
||||
Math.addExact(product.amountsByCurrency.getOrDefault(record.currency, 0L), total)),
|
||||
)
|
||||
}
|
||||
return result.copy(
|
||||
productRows = products.values.sortedBy { it.id },
|
||||
memberCount = records.map { it.memberID }.toSet().size,
|
||||
)
|
||||
}
|
||||
|
||||
/** Spending requires a single currency. Quantity can combine currencies without converting money. */
|
||||
fun rankings(
|
||||
records: List<LedgerRecord>,
|
||||
grouping: LedgerGrouping,
|
||||
metric: LedgerMetric,
|
||||
currency: String? = null,
|
||||
): List<LedgerRankRow> {
|
||||
if (currency != null && runCatching { LedgerCurrency.valueOf(currency) }.isFailure) {
|
||||
throw LedgerError("ledger.error.currency", "Unsupported currency '$currency'.", "$.currency")
|
||||
}
|
||||
if (metric == LedgerMetric.Spending && currency == null) {
|
||||
throw LedgerError("ledger.error.currencyRequired",
|
||||
"Select one currency for spending rankings. Different currencies are never added together.", "$.currency")
|
||||
}
|
||||
val selected = records.filter { currency == null || it.currency == currency }
|
||||
val summary = summarize(selected)
|
||||
val buckets = selected.groupBy { record ->
|
||||
when (grouping) {
|
||||
LedgerGrouping.MemberCombined -> "member:${record.memberID}"
|
||||
LedgerGrouping.MemberByGroup -> "membership:${LedgerImporter.pair(record.memberID, record.groupID)}"
|
||||
LedgerGrouping.Group -> "group:${record.groupID}"
|
||||
}
|
||||
}
|
||||
var rows = buckets.map { (id, bucket) ->
|
||||
val ordered = bucket.sortedWith(compareByDescending<LedgerRecord> { it.date }.thenBy { it.id })
|
||||
val latest = ordered.first()
|
||||
val bucketSummary = summarize(bucket)
|
||||
val seenGroups = mutableSetOf<String>()
|
||||
val groupNames = ordered.filter { seenGroups.add(it.groupID) }.map { it.groupNameSnapshot }
|
||||
LedgerRankRow(
|
||||
id = id,
|
||||
name = if (grouping == LedgerGrouping.Group) latest.groupNameSnapshot else latest.memberNameSnapshot,
|
||||
subtitle = if (grouping == LedgerGrouping.Group) "" else groupNames.joinToString(" / "),
|
||||
color = latest.colorSnapshot,
|
||||
memberID = if (grouping == LedgerGrouping.Group) null else latest.memberID,
|
||||
groupID = if (grouping == LedgerGrouping.MemberCombined) null else latest.groupID,
|
||||
quantity = bucketSummary.quantity,
|
||||
amountsByCurrency = bucketSummary.amountsByCurrency,
|
||||
rank = 0,
|
||||
share = 0.0,
|
||||
productRows = bucketSummary.productRows,
|
||||
)
|
||||
}
|
||||
fun value(row: LedgerRankRow): Long =
|
||||
if (metric == LedgerMetric.Quantity) row.quantity.toLong() else row.amountsByCurrency.getOrDefault(currency!!, 0L)
|
||||
|
||||
rows = rows.sortedWith { left, right ->
|
||||
val difference = value(right) - value(left)
|
||||
if (difference != 0L) (if (difference < 0) -1 else 1) else left.id.compareTo(right.id)
|
||||
}
|
||||
val overall = if (metric == LedgerMetric.Quantity) summary.quantity.toLong()
|
||||
else summary.amountsByCurrency.getOrDefault(currency!!, 0L)
|
||||
var previous: Long? = null
|
||||
var rank = 0
|
||||
rows = rows.mapIndexed { index, row ->
|
||||
val current = value(row)
|
||||
if (previous != current) rank = index + 1
|
||||
previous = current
|
||||
row.copy(rank = rank, share = if (overall > 0) current.toDouble() / overall.toDouble() else 0.0)
|
||||
}
|
||||
return rows
|
||||
}
|
||||
|
||||
private fun checkedTotal(record: LedgerRecord): Long {
|
||||
if (runCatching { LedgerCurrency.valueOf(record.currency) }.isFailure) {
|
||||
throw LedgerError("ledger.error.currency", "Unsupported currency.", "$.records.currency")
|
||||
}
|
||||
if (record.quantity <= 0) throw LedgerError("ledger.error.quantity", "quantity must be positive.", "$.records.quantity")
|
||||
if (record.unitPriceMinor < 0) throw LedgerError("ledger.error.price", "unitPriceMinor must not be negative.", "$.records.unitPriceMinor")
|
||||
return record.totalMinor
|
||||
?: throw LedgerError("ledger.error.overflow", "The ledger total is too large.", "$.records")
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,202 @@
|
||||
package com.oshicue.keeps.core
|
||||
|
||||
/** Catalog pickers exclude deleted entries. Archived identities remain available to historical records. */
|
||||
val LedgerDocument.activeGroups: List<LedgerGroup> get() = groups.filter { it.isActive }
|
||||
val LedgerDocument.activeMembers: List<LedgerMember> get() = members.filter { it.isActive }
|
||||
|
||||
val LedgerDocument.activeMemberships: List<LedgerMembership>
|
||||
get() {
|
||||
val groupIDs = activeGroups.map { it.id }.toSet()
|
||||
val memberIDs = activeMembers.map { it.id }.toSet()
|
||||
return memberships.filter { it.isActive && it.groupID in groupIDs && it.memberID in memberIDs }
|
||||
}
|
||||
|
||||
/** Deleting a person applies to every group, while leaving past purchases and prices intact. */
|
||||
fun LedgerDocument.deletingMember(id: String): LedgerDocument {
|
||||
if (members.none { it.id == id }) return this
|
||||
return copy(
|
||||
members = members.map { if (it.id == id) it.copy(isArchived = true) else it },
|
||||
memberships = memberships.map { if (it.memberID == id) it.copy(isArchived = true) else it },
|
||||
)
|
||||
}
|
||||
|
||||
/** Group deletion affects its affiliations, without deleting a shared member in another group. */
|
||||
fun LedgerDocument.deletingGroup(id: String): LedgerDocument {
|
||||
if (groups.none { it.id == id }) return this
|
||||
return copy(
|
||||
groups = groups.map { if (it.id == id) it.copy(isArchived = true) else it },
|
||||
memberships = memberships.map { if (it.groupID == id) it.copy(isArchived = true) else it },
|
||||
)
|
||||
}
|
||||
|
||||
fun LedgerDocument.deletingMembers(ids: Set<String>): LedgerDocument =
|
||||
ids.sorted().fold(this) { document, id -> document.deletingMember(id) }
|
||||
|
||||
fun LedgerDocument.deletingGroups(ids: Set<String>): LedgerDocument =
|
||||
ids.sorted().fold(this) { document, id -> document.deletingGroup(id) }
|
||||
|
||||
/** Catalog identities, events and immutable snapshots of remaining purchases survive. */
|
||||
fun LedgerDocument.deletingRecords(ids: Set<String>): LedgerDocument =
|
||||
copy(records = records.filter { it.id !in ids })
|
||||
|
||||
// Favorites and the ordering every picker uses.
|
||||
private fun naturalOrder(): Comparator<String> =
|
||||
java.text.Collator.getInstance(L10n.current.locale).let { collator ->
|
||||
Comparator { left, right ->
|
||||
val result = collator.compare(left, right)
|
||||
if (result != 0) result else left.compareTo(right)
|
||||
}
|
||||
}
|
||||
|
||||
val LedgerDocument.favoriteMembers: List<LedgerMember>
|
||||
get() = activeMembers.filter { it.isFavorited }.sortedWith { left, right ->
|
||||
val result = naturalOrder().compare(left.name, right.name)
|
||||
if (result != 0) result else left.id.compareTo(right.id)
|
||||
}
|
||||
|
||||
/** Used when linking an existing person to another group. Each person appears only once. */
|
||||
val LedgerDocument.membersForSelection: List<LedgerMember>
|
||||
get() = activeMembers.sortedWith { left, right ->
|
||||
if (left.isFavorited != right.isFavorited) {
|
||||
return@sortedWith if (left.isFavorited) -1 else 1
|
||||
}
|
||||
val result = naturalOrder().compare(left.name, right.name)
|
||||
if (result != 0) result else left.id.compareTo(right.id)
|
||||
}
|
||||
|
||||
/** Each active affiliation remains a distinct choice with its own group color and price list. */
|
||||
val LedgerDocument.favoriteMemberships: List<LedgerMembership>
|
||||
get() {
|
||||
val favoriteIDs = favoriteMembers.map { it.id }.toSet()
|
||||
return activeMemberships.filter { it.memberID in favoriteIDs }.sortedWith(membershipComparator(this))
|
||||
}
|
||||
|
||||
private fun membershipComparator(document: LedgerDocument): Comparator<LedgerMembership> {
|
||||
val order = naturalOrder()
|
||||
return Comparator { left, right ->
|
||||
val leftName = document.members.firstOrNull { it.id == left.memberID }?.name ?: ""
|
||||
val rightName = document.members.firstOrNull { it.id == right.memberID }?.name ?: ""
|
||||
val memberResult = order.compare(leftName, rightName)
|
||||
if (memberResult != 0) return@Comparator memberResult
|
||||
val leftGroup = document.groups.firstOrNull { it.id == left.groupID }?.name ?: ""
|
||||
val rightGroup = document.groups.firstOrNull { it.id == right.groupID }?.name ?: ""
|
||||
val groupResult = order.compare(leftGroup, rightGroup)
|
||||
if (groupResult != 0) groupResult else left.id.compareTo(right.id)
|
||||
}
|
||||
}
|
||||
|
||||
/** Existing purchases keep their original identity, including archived members or groups. */
|
||||
fun LedgerDocument.preferredRecordMembership(editing: LedgerRecord? = null): LedgerMembership? {
|
||||
if (editing != null) {
|
||||
memberships.firstOrNull { it.memberID == editing.memberID && it.groupID == editing.groupID }?.let { return it }
|
||||
}
|
||||
return favoriteMemberships.firstOrNull() ?: activeMemberships.firstOrNull()
|
||||
}
|
||||
|
||||
fun LedgerDocument.recordMembershipChoices(editing: LedgerRecord? = null): List<LedgerMembership> {
|
||||
val choices = activeMemberships.toMutableList()
|
||||
if (editing != null) {
|
||||
val original = memberships.firstOrNull { it.memberID == editing.memberID && it.groupID == editing.groupID }
|
||||
if (original != null && choices.none { it.id == original.id }) choices.add(original)
|
||||
}
|
||||
return choices
|
||||
}
|
||||
|
||||
/** Favorite shortcuts do not replace the complete, grouped catalog below them. */
|
||||
fun LedgerDocument.recordMembershipGroups(editing: LedgerRecord? = null): List<LedgerGroup> {
|
||||
val groupIDs = recordMembershipChoices(editing).map { it.groupID }.toSet()
|
||||
val order = naturalOrder()
|
||||
return groups.filter { it.id in groupIDs }.sortedWith { left, right ->
|
||||
val result = order.compare(left.name, right.name)
|
||||
if (result != 0) result else left.id.compareTo(right.id)
|
||||
}
|
||||
}
|
||||
|
||||
fun LedgerDocument.recordMembershipChoices(inGroupID: String, editing: LedgerRecord? = null): List<LedgerMembership> =
|
||||
recordMembershipChoices(editing).filter { it.groupID == inGroupID }.sortedWith(membershipComparator(this))
|
||||
|
||||
/** Price suggestions never change recorded purchases or combine different currencies or products. */
|
||||
object LedgerPriceSuggestions {
|
||||
/** Prefers the latest applicable purchase day for this affiliation. Array order breaks same-day ties. */
|
||||
fun price(
|
||||
document: LedgerDocument,
|
||||
membership: LedgerMembership?,
|
||||
productID: String,
|
||||
currency: String,
|
||||
on: String,
|
||||
lastAddedPrices: List<LedgerPrice> = emptyList(),
|
||||
): LedgerPrice {
|
||||
val record = latestRecord(document, membership, productID, currency, on)
|
||||
if (record != null) return LedgerPrice(productID, currency, record.unitPriceMinor)
|
||||
lastAddedPrices.lastOrNull { it.productID == productID && it.currency == currency && it.unitPriceMinor >= 0 }
|
||||
?.let { return it }
|
||||
membership?.prices?.firstOrNull { it.productID == productID && it.currency == currency }?.let { return it }
|
||||
return LedgerPrice(productID, currency, 0)
|
||||
}
|
||||
|
||||
/** A new selection starts with the currency of the applicable history, then the last added purchase. */
|
||||
fun currency(
|
||||
document: LedgerDocument,
|
||||
membership: LedgerMembership?,
|
||||
productID: String,
|
||||
on: String,
|
||||
lastAddedPrices: List<LedgerPrice> = emptyList(),
|
||||
): String {
|
||||
latestRecord(document, membership, productID, null, on)?.let { return it.currency }
|
||||
lastAddedPrices.lastOrNull {
|
||||
it.productID == productID && runCatching { LedgerCurrency.valueOf(it.currency) }.isSuccess
|
||||
}?.let { return it.currency }
|
||||
return membership?.prices?.firstOrNull { it.productID == productID }?.currency ?: LedgerCurrency.JPY.name
|
||||
}
|
||||
|
||||
/** One entry per product/currency pair; the last entry is also the most recently added currency. */
|
||||
fun remembering(price: LedgerPrice, inPrices: List<LedgerPrice>): List<LedgerPrice> {
|
||||
if (price.productID.isEmpty() || price.unitPriceMinor < 0) return inPrices
|
||||
if (runCatching { LedgerCurrency.valueOf(price.currency) }.isFailure) return inPrices
|
||||
return inPrices.filter { it.productID != price.productID || it.currency != price.currency } + price
|
||||
}
|
||||
|
||||
/** Legacy storage has no separate entry-order memory, so existing record order provides a migration seed. */
|
||||
fun seededPrices(records: List<LedgerRecord>): List<LedgerPrice> =
|
||||
records.fold(emptyList()) { result, record ->
|
||||
remembering(LedgerPrice(record.productID, record.currency, record.unitPriceMinor), result)
|
||||
}
|
||||
|
||||
private fun latestRecord(
|
||||
document: LedgerDocument,
|
||||
membership: LedgerMembership?,
|
||||
productID: String,
|
||||
currency: String?,
|
||||
on: String,
|
||||
): LedgerRecord? {
|
||||
if (membership == null || LedgerDates.parse(on) == null) return null
|
||||
var latest: LedgerRecord? = null
|
||||
for (record in document.records) {
|
||||
if (record.memberID != membership.memberID || record.groupID != membership.groupID) continue
|
||||
if (record.productID != productID) continue
|
||||
if (currency != null && record.currency != currency) continue
|
||||
if (record.date > on) continue
|
||||
if (latest == null || record.date >= latest.date) latest = record
|
||||
}
|
||||
return latest
|
||||
}
|
||||
}
|
||||
|
||||
/** The most recently added purchase for one affiliation, product and day. */
|
||||
fun LedgerDocument.latestRecord(on: String, memberID: String, groupID: String, productID: String): LedgerRecord? =
|
||||
records.lastOrNull {
|
||||
it.date == on && it.memberID == memberID && it.groupID == groupID && it.productID == productID
|
||||
}
|
||||
|
||||
/**
|
||||
* Adds to an existing purchase, keeping its unit price and snapshots. Null for an unknown record,
|
||||
* a nonpositive amount, or a quantity or total that would overflow.
|
||||
*/
|
||||
fun LedgerDocument.addingQuantity(amount: Int, toRecord: String): LedgerDocument? {
|
||||
if (amount <= 0) return null
|
||||
val index = records.indexOfFirst { it.id == toRecord }
|
||||
if (index < 0) return null
|
||||
val quantity = runCatching { Math.addExact(records[index].quantity, amount) }.getOrNull() ?: return null
|
||||
val result = copy(records = records.toMutableList().also { it[index] = it[index].copy(quantity = quantity) })
|
||||
return if (result.records[index].totalMinor == null) null else result
|
||||
}
|
||||
@@ -0,0 +1,266 @@
|
||||
package com.oshicue.keeps.core
|
||||
|
||||
import kotlinx.serialization.SerializationException
|
||||
import kotlinx.serialization.json.Json
|
||||
import kotlinx.serialization.json.jsonObject
|
||||
import kotlinx.serialization.json.jsonPrimitive
|
||||
|
||||
class LedgerError(val key: String, val detail: String, val path: String) : Exception("$path: $detail") {
|
||||
override fun toString(): String = "$path: $detail"
|
||||
}
|
||||
|
||||
object LedgerImporter {
|
||||
const val maximumDocumentBytes = 20 * 1024 * 1024
|
||||
const val maximumAvatarBytes = 2 * 1024 * 1024
|
||||
|
||||
val json = Json {
|
||||
ignoreUnknownKeys = true
|
||||
explicitNulls = true
|
||||
encodeDefaults = true
|
||||
prettyPrint = true
|
||||
}
|
||||
|
||||
fun parse(data: ByteArray): LedgerDocument {
|
||||
if (data.size > maximumDocumentBytes) throw sizeError()
|
||||
val text = runCatching { data.toString(Charsets.UTF_8) }.getOrElse {
|
||||
throw error("invalidJSON", "The ledger must contain valid UTF-8 text.", "$")
|
||||
}
|
||||
return parse(text)
|
||||
}
|
||||
|
||||
fun parse(text: String): LedgerDocument {
|
||||
if (text.toByteArray(Charsets.UTF_8).size > maximumDocumentBytes) throw sizeError()
|
||||
val document = try {
|
||||
json.decodeFromString(LedgerDocument.serializer(), text)
|
||||
} catch (failure: LedgerError) {
|
||||
throw failure
|
||||
} catch (failure: SerializationException) {
|
||||
throw translate(failure)
|
||||
} catch (failure: Exception) {
|
||||
throw error("invalidJSON", failure.message ?: "", "$")
|
||||
}
|
||||
validate(document)
|
||||
return document
|
||||
}
|
||||
|
||||
/** One document for a batch of files, merged with the same rules as an import. */
|
||||
fun combining(documents: List<LedgerDocument>): LedgerDocument =
|
||||
documents.fold(LedgerDocument()) { result, document -> result.merging(document) }
|
||||
|
||||
fun encode(document: LedgerDocument): String {
|
||||
validate(document)
|
||||
val text = json.encodeToString(LedgerDocument.serializer(), document)
|
||||
if (text.toByteArray(Charsets.UTF_8).size > maximumDocumentBytes) throw sizeError()
|
||||
return text
|
||||
}
|
||||
|
||||
fun validate(document: LedgerDocument) {
|
||||
if (document.schemaVersion != 1) throw error("schemaVersion", "Supported schemaVersion is 1.", "$.schemaVersion")
|
||||
unique(document.groups.map { it.id }, "$.groups")
|
||||
unique(document.members.map { it.id }, "$.members")
|
||||
unique(document.memberships.map { it.id }, "$.memberships")
|
||||
unique(document.products.map { it.id }, "$.products")
|
||||
unique(document.events.map { it.id }, "$.events")
|
||||
unique(document.records.map { it.id }, "$.records")
|
||||
val groupIDs = document.groups.map { it.id }.toSet()
|
||||
val memberIDs = document.members.map { it.id }.toSet()
|
||||
val productIDs = document.products.map { it.id }.toSet()
|
||||
val eventIDs = document.events.map { it.id }.toSet()
|
||||
|
||||
document.groups.forEachIndexed { index, group ->
|
||||
nonempty(group.id, "$.groups[$index].id")
|
||||
nonempty(group.name, "$.groups[$index].name")
|
||||
}
|
||||
document.members.forEachIndexed { index, member ->
|
||||
val location = "$.members[$index]"
|
||||
nonempty(member.id, "$location.id")
|
||||
nonempty(member.name, "$location.name")
|
||||
member.avatarJPEGBase64?.let { avatar ->
|
||||
val avatarPath = "$location.avatarJPEGBase64"
|
||||
// Check the encoded length before allocating the decoded image.
|
||||
if (avatar.toByteArray().size > ((maximumAvatarBytes + 2) / 3) * 4) {
|
||||
throw error("avatarSize", "Each avatar must not exceed 2 MB.", avatarPath)
|
||||
}
|
||||
val bytes = runCatching { android.util.Base64.decode(avatar, android.util.Base64.DEFAULT) }.getOrNull()
|
||||
if (bytes == null || !plausibleJPEG(bytes)) {
|
||||
throw error("avatar", "Use base64-encoded JPEG image data.", avatarPath)
|
||||
}
|
||||
if (bytes.size > maximumAvatarBytes) throw error("avatarSize", "Each avatar must not exceed 2 MB.", avatarPath)
|
||||
}
|
||||
}
|
||||
document.products.forEachIndexed { index, product ->
|
||||
nonempty(product.id, "$.products[$index].id")
|
||||
nonempty(product.name, "$.products[$index].name")
|
||||
}
|
||||
val membershipPairs = mutableSetOf<String>()
|
||||
document.memberships.forEachIndexed { index, membership ->
|
||||
val location = "$.memberships[$index]"
|
||||
nonempty(membership.id, "$location.id")
|
||||
reference(membership.memberID, memberIDs, "$location.memberID")
|
||||
reference(membership.groupID, groupIDs, "$location.groupID")
|
||||
if (!membershipPairs.add(pair(membership.memberID, membership.groupID))) {
|
||||
throw error("membership", "A member may have only one membership in the same group.", location)
|
||||
}
|
||||
color(membership.color, "$location.color")
|
||||
val priceKeys = mutableSetOf<String>()
|
||||
membership.prices.forEachIndexed { priceIndex, price ->
|
||||
val pricePath = "$location.prices[$priceIndex]"
|
||||
reference(price.productID, productIDs, "$pricePath.productID")
|
||||
currency(price.currency, "$pricePath.currency")
|
||||
if (price.unitPriceMinor < 0) throw error("price", "unitPriceMinor must not be negative.", "$pricePath.unitPriceMinor")
|
||||
if (!priceKeys.add(pair(price.productID, price.currency))) {
|
||||
throw error("duplicateID", "A product/currency price may appear only once per membership.", pricePath)
|
||||
}
|
||||
}
|
||||
}
|
||||
document.events.forEachIndexed { index, event ->
|
||||
val location = "$.events[$index]"
|
||||
nonempty(event.id, "$location.id")
|
||||
nonempty(event.name, "$location.name")
|
||||
event.date?.let { day(it, "$location.date") }
|
||||
}
|
||||
var quantityTotal = 0
|
||||
val currencyTotals = mutableMapOf<String, Long>()
|
||||
document.records.forEachIndexed { index, record ->
|
||||
val location = "$.records[$index]"
|
||||
nonempty(record.id, "$location.id")
|
||||
day(record.date, "$location.date")
|
||||
reference(record.memberID, memberIDs, "$location.memberID")
|
||||
reference(record.groupID, groupIDs, "$location.groupID")
|
||||
reference(record.productID, productIDs, "$location.productID")
|
||||
if (pair(record.memberID, record.groupID) !in membershipPairs) {
|
||||
throw error("membership", "This member must have a membership in the recorded group.", location)
|
||||
}
|
||||
record.eventID?.let { reference(it, eventIDs, "$location.eventID") }
|
||||
nonempty(record.memberNameSnapshot, "$location.memberNameSnapshot")
|
||||
nonempty(record.groupNameSnapshot, "$location.groupNameSnapshot")
|
||||
nonempty(record.productNameSnapshot, "$location.productNameSnapshot")
|
||||
color(record.colorSnapshot, "$location.colorSnapshot")
|
||||
currency(record.currency, "$location.currency")
|
||||
if (record.quantity <= 0) throw error("quantity", "quantity must be positive.", "$location.quantity")
|
||||
if (record.unitPriceMinor < 0) throw error("price", "unitPriceMinor must not be negative.", "$location.unitPriceMinor")
|
||||
val total = record.totalMinor ?: throw error("overflow", "quantity × unitPriceMinor is too large.", location)
|
||||
val nextQuantity = runCatching { Math.addExact(quantityTotal, record.quantity) }.getOrNull()
|
||||
?: throw error("overflow", "The ledger total is too large.", location)
|
||||
val nextAmount = runCatching { Math.addExact(currencyTotals.getOrDefault(record.currency, 0L), total) }.getOrNull()
|
||||
?: throw error("overflow", "The ledger total is too large.", location)
|
||||
quantityTotal = nextQuantity
|
||||
currencyTotals[record.currency] = nextAmount
|
||||
}
|
||||
// Validation is also used for manual additions, which do not pass through parse/encode.
|
||||
val encoded = json.encodeToString(LedgerDocument.serializer(), document)
|
||||
if (encoded.toByteArray(Charsets.UTF_8).size > maximumDocumentBytes) throw sizeError()
|
||||
}
|
||||
|
||||
fun sizeError() = error("documentSize", "The ledger must not exceed 20 MB.", "$")
|
||||
|
||||
internal fun pair(first: String, second: String): String =
|
||||
first.toByteArray(Charsets.UTF_8).size.toString() + ":" + first + second
|
||||
|
||||
private fun translate(failure: SerializationException): LedgerError {
|
||||
val message = generateSequence(failure as Throwable) { it.cause }.mapNotNull { it.message }.joinToString(" ")
|
||||
val missing = Regex("""Field '([^']+)' is required for type""").find(message)
|
||||
val pathMatch = Regex("""path: (?:\\\$)([\w.\[\]]*)""").find(message)
|
||||
val suffix = pathMatch?.groupValues?.get(1)?.split('.')?.joinToString("") { part ->
|
||||
when {
|
||||
part.isEmpty() -> ""
|
||||
part.startsWith("[") -> part
|
||||
else -> ".$part"
|
||||
}
|
||||
} ?: ""
|
||||
return when {
|
||||
missing != null -> error("missingField", "Required field '${missing.groupValues[1]}' is missing.", "$$suffix")
|
||||
message.contains("Unexpected JSON token") || message.contains("Expected") || message.contains("Illegal input") ->
|
||||
error("fieldType", message, "$$suffix")
|
||||
else -> error("invalidJSON", message.ifEmpty { "The ledger could not be decoded." }, "$$suffix")
|
||||
}
|
||||
}
|
||||
|
||||
private fun error(category: String, detail: String, path: String) =
|
||||
LedgerError("ledger.error.$category", detail, path)
|
||||
|
||||
private fun nonempty(value: String, path: String) {
|
||||
if (value.isBlank()) throw error("emptyField", "This field must not be empty.", path)
|
||||
}
|
||||
|
||||
private fun unique(ids: List<String>, path: String) {
|
||||
val seen = mutableSetOf<String>()
|
||||
ids.forEachIndexed { index, id ->
|
||||
if (!seen.add(id)) throw error("duplicateID", "Duplicate ID '$id'.", "$path[$index].id")
|
||||
}
|
||||
}
|
||||
|
||||
private fun reference(id: String, ids: Set<String>, path: String) {
|
||||
if (id !in ids) throw error("reference", "Referenced ID '$id' is not declared.", path)
|
||||
}
|
||||
|
||||
private fun color(value: String, path: String) {
|
||||
if (!Regex("^#[0-9a-fA-F]{6}$").matches(value)) {
|
||||
throw error("color", "Use a six-digit RGB color such as #F28AAF.", path)
|
||||
}
|
||||
}
|
||||
|
||||
private fun day(value: String, path: String) {
|
||||
if (LedgerDates.parse(value) == null) throw error("date", "Use a valid Gregorian date in yyyy-MM-dd format.", path)
|
||||
}
|
||||
|
||||
private fun currency(value: String, path: String) {
|
||||
if (runCatching { LedgerCurrency.valueOf(value) }.isFailure) {
|
||||
throw error("currency", "Use JPY, CNY, TWD, HKD, USD, KRW, THB, IDR or MYR.", path)
|
||||
}
|
||||
}
|
||||
|
||||
/** Rejects truncated headers and marker-only payloads without decoding the image. */
|
||||
private fun plausibleJPEG(data: ByteArray): Boolean {
|
||||
if (data.size < 4) return false
|
||||
if (data[0] != 0xFF.toByte() || data[1] != 0xD8.toByte()) return false
|
||||
if (data[data.size - 2] != 0xFF.toByte() || data[data.size - 1] != 0xD9.toByte()) return false
|
||||
val frameMarkers = setOf(0xC0, 0xC1, 0xC2, 0xC3, 0xC5, 0xC6, 0xC7, 0xC9, 0xCA, 0xCB, 0xCD, 0xCE, 0xCF)
|
||||
var hasFrame = false
|
||||
var offset = 2
|
||||
while (offset < data.size - 2) {
|
||||
if (data[offset].toInt() and 0xFF != 0xFF) return false
|
||||
while (offset < data.size && data[offset].toInt() and 0xFF == 0xFF) offset++
|
||||
if (offset >= data.size) return false
|
||||
val marker = data[offset].toInt() and 0xFF
|
||||
offset++
|
||||
if (marker == 0x01) continue
|
||||
if (marker == 0x00 || marker == 0xD8 || marker == 0xD9 || marker in 0xD0..0xD7 ||
|
||||
offset + 2 > data.size - 2
|
||||
) return false
|
||||
val length = (data[offset].toInt() and 0xFF) * 256 + (data[offset + 1].toInt() and 0xFF)
|
||||
if (length < 2 || offset + length > data.size - 2) return false
|
||||
if (marker in frameMarkers) {
|
||||
if (length < 8) return false
|
||||
val height = (data[offset + 3].toInt() and 0xFF) * 256 + (data[offset + 4].toInt() and 0xFF)
|
||||
val width = (data[offset + 5].toInt() and 0xFF) * 256 + (data[offset + 6].toInt() and 0xFF)
|
||||
val components = data[offset + 7].toInt() and 0xFF
|
||||
if (height <= 0 || width <= 0 || components <= 0 || length < 8 + components * 3) return false
|
||||
hasFrame = true
|
||||
}
|
||||
if (marker == 0xDA) {
|
||||
if (!hasFrame || length < 6) return false
|
||||
val components = data[offset + 2].toInt() and 0xFF
|
||||
return components > 0 && length >= 6 + components * 2 && offset + length < data.size - 2
|
||||
}
|
||||
offset += length
|
||||
}
|
||||
return false
|
||||
}
|
||||
}
|
||||
|
||||
/** A message that is already localized, for checks with no JSON location. */
|
||||
class KitMessageError(val text: String) : Exception(text)
|
||||
|
||||
object KitPresentation {
|
||||
fun error(value: Throwable): String = when (value) {
|
||||
is LedgerError -> L10n.text(value.key) + "\n" + value.path
|
||||
is KitMessageError -> value.text
|
||||
else -> value.message ?: value.toString()
|
||||
}
|
||||
|
||||
fun fileError(value: Throwable): String = when (value) {
|
||||
is LedgerError, is KitMessageError -> error(value)
|
||||
else -> L10n.text("import.readError") + "\n" + (value.message ?: value.toString())
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,198 @@
|
||||
package com.oshicue.keeps.core
|
||||
|
||||
import kotlinx.serialization.Serializable
|
||||
|
||||
object AppBrand {
|
||||
const val storageFolder = "OshicueKeeps"
|
||||
const val exportPrefix = "OshicueKeeps-"
|
||||
const val productName = "KEEPS"
|
||||
const val fullName = "Oshicue Keeps"
|
||||
}
|
||||
|
||||
/**
|
||||
* Catalog entries are normalized; each transaction also carries immutable display and price snapshots,
|
||||
* so renaming or deleting a member later never rewrites history.
|
||||
*/
|
||||
@Serializable
|
||||
data class LedgerDocument(
|
||||
val schemaVersion: Int = 1,
|
||||
val groups: List<LedgerGroup> = emptyList(),
|
||||
val members: List<LedgerMember> = emptyList(),
|
||||
val memberships: List<LedgerMembership> = emptyList(),
|
||||
val products: List<LedgerProduct> = emptyList(),
|
||||
val events: List<LedgerEvent> = emptyList(),
|
||||
val records: List<LedgerRecord> = emptyList(),
|
||||
) {
|
||||
/**
|
||||
* Catalog IDs are upserted. Already recorded transaction IDs retain their original snapshots,
|
||||
* so reimporting the same backup cannot double count or rewrite history.
|
||||
*/
|
||||
fun merging(incoming: LedgerDocument): LedgerDocument {
|
||||
LedgerImporter.validate(this)
|
||||
LedgerImporter.validate(incoming)
|
||||
val existingRecords = records.associateBy { it.id }
|
||||
for (record in incoming.records) {
|
||||
val existing = existingRecords[record.id]
|
||||
if (existing != null && existing != record) {
|
||||
throw LedgerError(
|
||||
key = "ledger.error.recordConflict",
|
||||
detail = "Record '${record.id}' already exists with different contents. " +
|
||||
"Edit it in the app, or use a new ID for a new purchase.",
|
||||
path = "$.records[id=${record.id}]",
|
||||
)
|
||||
}
|
||||
}
|
||||
fun <T> upsert(existing: List<T>, new: List<T>, id: (T) -> String): List<T> {
|
||||
val ids = new.map(id).toSet()
|
||||
return existing.filter { id(it) !in ids } + new
|
||||
}
|
||||
val existingRecordIDs = records.map { it.id }.toSet()
|
||||
val merged = LedgerDocument(
|
||||
groups = upsert(groups, incoming.groups) { it.id },
|
||||
members = upsert(members, incoming.members) { it.id },
|
||||
memberships = upsert(memberships, incoming.memberships) { it.id },
|
||||
products = upsert(products, incoming.products) { it.id },
|
||||
events = upsert(events, incoming.events) { it.id },
|
||||
records = records + incoming.records.filter { it.id !in existingRecordIDs },
|
||||
)
|
||||
LedgerImporter.validate(merged)
|
||||
return merged
|
||||
}
|
||||
|
||||
companion object {
|
||||
val defaultProducts = listOf(
|
||||
LedgerProduct("cheki", "Cheki"),
|
||||
LedgerProduct("wide-cheki", "WIDE Cheki"),
|
||||
LedgerProduct("phone-photo", "Phone photo"),
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
@Serializable
|
||||
data class LedgerGroup(
|
||||
val id: String,
|
||||
val name: String,
|
||||
val isArchived: Boolean? = null,
|
||||
) {
|
||||
val isActive: Boolean get() = isArchived != true
|
||||
}
|
||||
|
||||
@Serializable
|
||||
data class LedgerMember(
|
||||
val id: String,
|
||||
val name: String,
|
||||
val avatarJPEGBase64: String? = null,
|
||||
val isArchived: Boolean? = null,
|
||||
/** Favorites belong to the person, so all of their group memberships share this preference. */
|
||||
val isFavorite: Boolean? = null,
|
||||
) {
|
||||
val isActive: Boolean get() = isArchived != true
|
||||
val isFavorited: Boolean get() = isFavorite == true
|
||||
}
|
||||
|
||||
/** A member may have several memberships, with an independent color and price list in each group. */
|
||||
@Serializable
|
||||
data class LedgerMembership(
|
||||
val id: String,
|
||||
val memberID: String,
|
||||
val groupID: String,
|
||||
val color: String,
|
||||
val prices: List<LedgerPrice> = emptyList(),
|
||||
val isArchived: Boolean? = null,
|
||||
) {
|
||||
val isActive: Boolean get() = isArchived != true
|
||||
}
|
||||
|
||||
@Serializable
|
||||
data class LedgerPrice(
|
||||
val productID: String,
|
||||
val currency: String,
|
||||
val unitPriceMinor: Long,
|
||||
)
|
||||
|
||||
@Serializable
|
||||
data class LedgerProduct(val id: String, val name: String)
|
||||
|
||||
@Serializable
|
||||
data class LedgerEvent(
|
||||
val id: String,
|
||||
val name: String,
|
||||
val date: String? = null,
|
||||
val city: String? = null,
|
||||
val venue: String? = null,
|
||||
val address: String? = null,
|
||||
)
|
||||
|
||||
@Serializable
|
||||
data class LedgerRecord(
|
||||
val id: String,
|
||||
/** A local civil day, unaffected by later travel or device time-zone changes. */
|
||||
val date: String,
|
||||
val memberID: String,
|
||||
val groupID: String,
|
||||
val productID: String,
|
||||
val quantity: Int,
|
||||
val unitPriceMinor: Long,
|
||||
val currency: String,
|
||||
val eventID: String? = null,
|
||||
val memberNameSnapshot: String,
|
||||
val groupNameSnapshot: String,
|
||||
val productNameSnapshot: String,
|
||||
val colorSnapshot: String,
|
||||
val eventNameSnapshot: String? = null,
|
||||
val citySnapshot: String? = null,
|
||||
val venueSnapshot: String? = null,
|
||||
val addressSnapshot: String? = null,
|
||||
val note: String? = null,
|
||||
) {
|
||||
val totalMinor: Long?
|
||||
get() {
|
||||
if (quantity <= 0 || unitPriceMinor < 0) return null
|
||||
return runCatching { Math.multiplyExact(unitPriceMinor, quantity.toLong()) }.getOrNull()
|
||||
}
|
||||
}
|
||||
|
||||
@Serializable
|
||||
enum class LedgerCurrency {
|
||||
JPY, CNY, TWD, HKD, USD, KRW, THB, IDR, MYR;
|
||||
|
||||
/** ISO 4217 minor units. IDR and TWD retain two digits even when cash prices are whole numbers. */
|
||||
val minorDigits: Int get() = if (this == JPY || this == KRW) 0 else 2
|
||||
|
||||
val factor: Long get() = if (minorDigits == 0) 1L else 100L
|
||||
|
||||
/** Parses a nonnegative price without binary floating point or silently rounding excess precision. */
|
||||
fun parsePrice(text: String): Long? {
|
||||
val input = text.trim()
|
||||
if (!Regex("""^\d+(?:\.\d+)?$""").matches(input)) return null
|
||||
val parts = input.split(".")
|
||||
val whole = parts[0].toLongOrNull() ?: return null
|
||||
val fraction = parts.getOrElse(1) { "" }
|
||||
if (fraction.length > minorDigits) return null
|
||||
val padded = fraction + "0".repeat(minorDigits - fraction.length)
|
||||
val fractional = if (padded.isEmpty()) 0L else padded.toLongOrNull() ?: return null
|
||||
val major = runCatching { Math.multiplyExact(whole, factor) }.getOrNull() ?: return null
|
||||
return runCatching { Math.addExact(major, fractional) }.getOrNull()
|
||||
}
|
||||
|
||||
/** The plain decimal price used in text fields, keeping the currency's fixed digits. */
|
||||
fun priceText(minor: Long): String {
|
||||
val digits = java.math.BigDecimal.valueOf(minor).divide(java.math.BigDecimal.valueOf(factor))
|
||||
return digits.stripTrailingZeros().toPlainString()
|
||||
}
|
||||
}
|
||||
|
||||
object LedgerDates {
|
||||
fun parse(text: String): java.time.LocalDate? {
|
||||
if (!Regex("""^\d{4}-\d{2}-\d{2}$""").matches(text)) return null
|
||||
return runCatching { java.time.LocalDate.parse(text) }.getOrNull()
|
||||
}
|
||||
|
||||
fun string(date: java.time.LocalDate): String = date.toString()
|
||||
|
||||
fun string(date: java.time.Instant, zone: java.time.ZoneId = java.time.ZoneId.systemDefault()): String =
|
||||
date.atZone(zone).toLocalDate().toString()
|
||||
|
||||
/** The local civil day containing [date], as the yyyy-MM-dd text records store. */
|
||||
fun string(date: java.time.LocalDate, zone: java.time.ZoneId): String = date.toString()
|
||||
}
|
||||
@@ -0,0 +1,219 @@
|
||||
package com.oshicue.keeps.core
|
||||
|
||||
import java.time.LocalDate
|
||||
import java.time.ZoneId
|
||||
|
||||
/** A spreadsheet view of purchases. CSV is for reading and totals elsewhere; JSON remains the backup. */
|
||||
object LedgerCSV {
|
||||
/** Column order. The app supplies one localized header per column. */
|
||||
enum class Column { Date, Member, Group, Product, Quantity, Currency, UnitPrice, Total, Event, City, Venue, Address, Note }
|
||||
|
||||
/**
|
||||
* Starts with a UTF-8 byte-order mark so spreadsheet apps detect names in any language,
|
||||
* and uses CRLF line endings as RFC 4180 describes.
|
||||
*/
|
||||
fun make(
|
||||
records: List<LedgerRecord>,
|
||||
headers: Map<Column, String>,
|
||||
productName: (LedgerRecord) -> String,
|
||||
): String {
|
||||
val ordered = records.sortedWith(compareBy<LedgerRecord> { it.date })
|
||||
val lines = mutableListOf(Column.entries.joinToString(",") { text(headers[it] ?: "") })
|
||||
for (record in ordered) {
|
||||
val currency = runCatching { LedgerCurrency.valueOf(record.currency) }.getOrNull()
|
||||
lines.add(Column.entries.joinToString(",") { column ->
|
||||
when (column) {
|
||||
Column.Date -> record.date
|
||||
Column.Member -> text(record.memberNameSnapshot)
|
||||
Column.Group -> text(record.groupNameSnapshot)
|
||||
Column.Product -> text(productName(record))
|
||||
Column.Quantity -> record.quantity.toString()
|
||||
Column.Currency -> record.currency
|
||||
Column.UnitPrice -> currency?.let { amount(record.unitPriceMinor, it) } ?: ""
|
||||
Column.Total -> currency?.let { c -> record.totalMinor?.let { amount(it, c) } } ?: ""
|
||||
Column.Event -> text(record.eventNameSnapshot ?: "")
|
||||
Column.City -> text(record.citySnapshot ?: "")
|
||||
Column.Venue -> text(record.venueSnapshot ?: "")
|
||||
Column.Address -> text(record.addressSnapshot ?: "")
|
||||
Column.Note -> text(record.note ?: "")
|
||||
}
|
||||
})
|
||||
}
|
||||
return "\uFEFF" + lines.joinToString("\r\n") + "\r\n"
|
||||
}
|
||||
|
||||
/** A plain decimal in major units with the currency's fixed number of digits, such as 80.50. */
|
||||
fun amount(minor: Long, currency: LedgerCurrency): String {
|
||||
if (currency.minorDigits == 0) return minor.toString()
|
||||
val digits = (minor % currency.factor).toString()
|
||||
return (minor / currency.factor).toString() + "." +
|
||||
"0".repeat(currency.minorDigits - digits.length) + digits
|
||||
}
|
||||
|
||||
/** Quotes text when needed and neutralizes a leading formula character. */
|
||||
fun text(value: String): String {
|
||||
var cell = value
|
||||
val first = cell.firstOrNull()
|
||||
if (first != null && first in "=+-@\t\r") cell = "'" + cell
|
||||
val needsQuotes = cell.any { it == ',' || it == '"' || it == '\n' || it == '\r' } || cell != cell.trim()
|
||||
if (!needsQuotes) return cell
|
||||
return "\"" + cell.replace("\"", "\"\"") + "\""
|
||||
}
|
||||
}
|
||||
|
||||
/** Independent conditions are combined. Dates are inclusive local civil days. */
|
||||
data class LedgerRecordFilter(
|
||||
val startDate: String? = null,
|
||||
val endDate: String? = null,
|
||||
val memberID: String? = null,
|
||||
val groupID: String? = null,
|
||||
val productID: String? = null,
|
||||
val currency: String? = null,
|
||||
val eventID: String? = null,
|
||||
val requiresNoEvent: Boolean = false,
|
||||
val query: String = "",
|
||||
) {
|
||||
val hasValidDateRange: Boolean
|
||||
get() {
|
||||
if (startDate != null && LedgerDates.parse(startDate) == null) return false
|
||||
if (endDate != null && LedgerDates.parse(endDate) == null) return false
|
||||
if (startDate != null && endDate != null && startDate > endDate) return false
|
||||
return true
|
||||
}
|
||||
|
||||
fun matching(records: List<LedgerRecord>): List<LedgerRecord> {
|
||||
if (!hasValidDateRange) return emptyList()
|
||||
val words = query.split(Regex("\\s+")).filter { it.isNotEmpty() }
|
||||
return records.filter { record ->
|
||||
if (startDate != null && record.date < startDate) return@filter false
|
||||
if (endDate != null && record.date > endDate) return@filter false
|
||||
if (memberID != null && record.memberID != memberID) return@filter false
|
||||
if (groupID != null && record.groupID != groupID) return@filter false
|
||||
if (productID != null && record.productID != productID) return@filter false
|
||||
if (currency != null && record.currency != currency) return@filter false
|
||||
if (eventID != null && record.eventID != eventID) return@filter false
|
||||
if (requiresNoEvent && record.eventID != null) return@filter false
|
||||
val searchable = listOf(
|
||||
record.date, record.memberNameSnapshot, record.groupNameSnapshot, record.productNameSnapshot,
|
||||
record.eventNameSnapshot ?: "", record.note ?: "", record.currency,
|
||||
).joinToString("\n")
|
||||
words.all { TextNormalizer.contains(searchable, it) }
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/** A confirmation is a fixed selection with quantities and separate currency totals. */
|
||||
class LedgerRecordDeletion(records: List<LedgerRecord>, selectedIDs: Set<String>) {
|
||||
val recordIDs: Set<String>
|
||||
val recordCount: Int
|
||||
val quantity: Int
|
||||
val amountsByCurrency: Map<String, Long>
|
||||
|
||||
init {
|
||||
val selected = records.filter { it.id in selectedIDs }
|
||||
val summary = LedgerAnalytics.summarize(selected)
|
||||
recordIDs = selected.map { it.id }.toSet()
|
||||
recordCount = selected.size
|
||||
quantity = summary.quantity
|
||||
amountsByCurrency = summary.amountsByCurrency
|
||||
}
|
||||
}
|
||||
|
||||
/** Unchanged default product names follow the app language; renamed products keep the user's text. */
|
||||
object LedgerPresentation {
|
||||
fun date(value: String): LocalDate {
|
||||
if (LedgerDates.parse(value) == null) return LocalDate.now()
|
||||
return LocalDate.parse(value)
|
||||
}
|
||||
|
||||
fun money(amounts: Map<String, Long>): String =
|
||||
amounts.keys.sorted().joinToString(" · ") { key ->
|
||||
key + " " + (runCatching { LedgerCurrency.valueOf(key) }.getOrNull()?.let { format(it, amounts.getValue(key)) } ?: "")
|
||||
}
|
||||
|
||||
fun total(record: LedgerRecord): String =
|
||||
runCatching { LedgerCurrency.valueOf(record.currency) }.getOrNull()?.let { currency ->
|
||||
record.totalMinor?.let { format(currency, it) }
|
||||
} ?: "—"
|
||||
|
||||
fun productName(id: String, snapshot: String): String {
|
||||
val default = LedgerDocument.defaultProducts.firstOrNull { it.id == id }?.name
|
||||
if (default != snapshot) return snapshot
|
||||
return when (id) {
|
||||
"cheki" -> L10n.text("ledger.product.polaroid")
|
||||
"wide-cheki" -> L10n.text("ledger.product.wide")
|
||||
"phone-photo" -> L10n.text("ledger.product.mobile")
|
||||
else -> snapshot
|
||||
}
|
||||
}
|
||||
|
||||
/** Currency amounts use the chosen app language, so separators match the rest of the screen. */
|
||||
fun format(currency: LedgerCurrency, minor: Long): String {
|
||||
val locale = L10n.current.locale
|
||||
val formatter = java.text.NumberFormat.getCurrencyInstance(locale).apply {
|
||||
this.currency = java.util.Currency.getInstance(currency.name)
|
||||
minimumFractionDigits = currency.minorDigits
|
||||
maximumFractionDigits = currency.minorDigits
|
||||
}
|
||||
return formatter.format(java.math.BigDecimal.valueOf(minor).movePointLeft(currency.minorDigits))
|
||||
}
|
||||
|
||||
fun csv(records: List<LedgerRecord>): String {
|
||||
val keys = mapOf(
|
||||
LedgerCSV.Column.Date to "ledger.date", LedgerCSV.Column.Member to "ledger.member",
|
||||
LedgerCSV.Column.Group to "ledger.group", LedgerCSV.Column.Product to "ledger.type",
|
||||
LedgerCSV.Column.Quantity to "ledger.quantity", LedgerCSV.Column.Currency to "ledger.currency",
|
||||
LedgerCSV.Column.UnitPrice to "ledger.unitPrice", LedgerCSV.Column.Total to "ledger.amount",
|
||||
LedgerCSV.Column.Event to "ledger.event", LedgerCSV.Column.City to "ledger.city",
|
||||
LedgerCSV.Column.Venue to "ledger.venue", LedgerCSV.Column.Address to "ledger.address",
|
||||
LedgerCSV.Column.Note to "ledger.note",
|
||||
)
|
||||
return LedgerCSV.make(records, keys.mapValues { L10n.text(it.value) }) {
|
||||
productName(it.productID, it.productNameSnapshot)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/** Fictional entries for first launch, dated around today like the iOS example ledger. */
|
||||
object LedgerDemo {
|
||||
fun document(now: java.time.Instant = java.time.Instant.now()): LedgerDocument {
|
||||
val zone = ZoneId.of("Asia/Shanghai")
|
||||
val today = LedgerDates.string(now, zone)
|
||||
val earlier = LedgerDates.string(now.minusSeconds(86_400), zone)
|
||||
val thirdDay = LedgerDates.string(now.minusSeconds(172_800), zone)
|
||||
val groups = listOf(LedgerGroup("luna", "LUNA NOTE"), LedgerGroup("prism", "PRISM DAYS"))
|
||||
val members = listOf(LedgerMember("mio", "Mio"), LedgerMember("rina", "Rina"), LedgerMember("sora", "Sora"))
|
||||
val memberships = listOf(
|
||||
LedgerMembership("mio-luna", "mio", "luna", "#F28AAF", listOf(
|
||||
LedgerPrice("cheki", "JPY", 2000),
|
||||
LedgerPrice("wide-cheki", "JPY", 3500),
|
||||
LedgerPrice("phone-photo", "JPY", 1500),
|
||||
)),
|
||||
LedgerMembership("mio-prism", "mio", "prism", "#9B8CF5", listOf(LedgerPrice("cheki", "JPY", 2500))),
|
||||
LedgerMembership("rina-luna", "rina", "luna", "#66C7A5", listOf(LedgerPrice("cheki", "JPY", 2000))),
|
||||
LedgerMembership("sora-prism", "sora", "prism", "#67B9EF", listOf(LedgerPrice("phone-photo", "CNY", 8000))),
|
||||
)
|
||||
val events = listOf(
|
||||
LedgerEvent("demo-fes", "Oshicue Mini Fes", today, "Tokyo", "Luna Hall", "Shibuya, Tokyo"),
|
||||
)
|
||||
val records = listOf(
|
||||
LedgerRecord("demo-cheki", today, "mio", "luna", "cheki", 5, 2000, "JPY", "demo-fes",
|
||||
"Mio", "LUNA NOTE", "Cheki", "#F28AAF", "Oshicue Mini Fes", "Tokyo", "Luna Hall", "Shibuya, Tokyo"),
|
||||
LedgerRecord("demo-wide", today, "mio", "luna", "wide-cheki", 2, 3500, "JPY", "demo-fes",
|
||||
"Mio", "LUNA NOTE", "WIDE Cheki", "#F28AAF", "Oshicue Mini Fes", "Tokyo", "Luna Hall"),
|
||||
LedgerRecord("demo-rina", today, "rina", "luna", "cheki", 3, 2000, "JPY",
|
||||
memberNameSnapshot = "Rina", groupNameSnapshot = "LUNA NOTE",
|
||||
productNameSnapshot = "Cheki", colorSnapshot = "#66C7A5"),
|
||||
LedgerRecord("demo-shared", earlier, "mio", "prism", "cheki", 4, 2500, "JPY",
|
||||
memberNameSnapshot = "Mio", groupNameSnapshot = "PRISM DAYS",
|
||||
productNameSnapshot = "Cheki", colorSnapshot = "#9B8CF5"),
|
||||
LedgerRecord("demo-phone", thirdDay, "sora", "prism", "phone-photo", 2, 8000, "CNY",
|
||||
memberNameSnapshot = "Sora", groupNameSnapshot = "PRISM DAYS",
|
||||
productNameSnapshot = "Phone photo", colorSnapshot = "#67B9EF"),
|
||||
)
|
||||
return LedgerDocument(
|
||||
groups = groups, members = members, memberships = memberships,
|
||||
products = LedgerDocument.defaultProducts, events = events, records = records,
|
||||
)
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,10 @@
|
||||
package com.oshicue.keeps.core
|
||||
|
||||
/** Search compares case and diacritics as equal, matching the iOS ledger. */
|
||||
object TextNormalizer {
|
||||
private fun fold(value: String): String =
|
||||
java.text.Normalizer.normalize(value, java.text.Normalizer.Form.NFKD)
|
||||
.lowercase(java.util.Locale.ROOT)
|
||||
|
||||
fun contains(haystack: String, needle: String): Boolean = fold(haystack).contains(fold(needle))
|
||||
}
|
||||
@@ -0,0 +1,258 @@
|
||||
package com.oshicue.keeps.core
|
||||
|
||||
import android.content.Context
|
||||
import android.content.res.Configuration
|
||||
import java.io.InputStream
|
||||
import java.util.Locale
|
||||
|
||||
/**
|
||||
* The nine bundled translations plus "follow the system". Translations live in
|
||||
* assets/localization/<tag>.strings in the same `"key" = "value";` layout the iOS app uses,
|
||||
* so a text change is one edit in one place and the two apps read the same strings.
|
||||
*/
|
||||
enum class AppLanguage(val tag: String) {
|
||||
System("system"),
|
||||
ZhHans("zh-Hans"),
|
||||
ZhHant("zh-Hant"),
|
||||
ZhHK("zh-HK"),
|
||||
En("en"),
|
||||
Ja("ja"),
|
||||
Ko("ko"),
|
||||
Th("th"),
|
||||
Indonesian("id"),
|
||||
Ms("ms");
|
||||
|
||||
val id: String get() = tag
|
||||
|
||||
val nativeName: String
|
||||
get() = when (this) {
|
||||
System -> L10n.text("settings.followSystem")
|
||||
ZhHans -> "简体中文(中国)"
|
||||
ZhHant -> "繁體中文(台灣)"
|
||||
ZhHK -> "繁體粵語(香港)"
|
||||
En -> "English (United States)"
|
||||
Ja -> "日本語(日本)"
|
||||
Ko -> "한국어(대한민국)"
|
||||
Th -> "ไทย (ประเทศไทย)"
|
||||
Indonesian -> "Bahasa Indonesia (Indonesia)"
|
||||
Ms -> "Bahasa Melayu (Malaysia)"
|
||||
}
|
||||
|
||||
val localeID: String
|
||||
get() = when (this) {
|
||||
System -> Locale.getDefault().toLanguageTag()
|
||||
ZhHans -> "zh-Hans-CN"
|
||||
ZhHant -> "zh-Hant-TW"
|
||||
ZhHK -> "zh-Hant-HK"
|
||||
En -> "en-US"
|
||||
Ja -> "ja-JP"
|
||||
Ko -> "ko-KR"
|
||||
Th -> "th-TH"
|
||||
Indonesian -> "id-ID"
|
||||
Ms -> "ms-MY"
|
||||
}
|
||||
|
||||
val locale: Locale get() = Locale.forLanguageTag(localeID)
|
||||
|
||||
companion object {
|
||||
const val preferenceKey = "appLanguage"
|
||||
private val bundled = listOf(ZhHans, ZhHant, ZhHK, En, Ja, Ko, Th, Indonesian, Ms)
|
||||
|
||||
fun fromTag(value: String?): AppLanguage = entries.firstOrNull { it.tag == value } ?: System
|
||||
|
||||
/**
|
||||
* Resolves the system language without collapsing Hong Kong Cantonese into
|
||||
* Taiwan Traditional Chinese, which Android's own matching would do.
|
||||
*/
|
||||
fun resolveSystemLanguage(tags: List<String>, regionCode: String?): AppLanguage {
|
||||
for (identifier in tags) {
|
||||
val normalized = identifier.replace('_', '-').lowercase(Locale.ROOT)
|
||||
val components = normalized.split('-').filter { it.isNotEmpty() }
|
||||
val code = components.firstOrNull() ?: continue
|
||||
val region = regionCode?.uppercase(Locale.ROOT)
|
||||
when (code) {
|
||||
"yue" -> return ZhHK
|
||||
"zh" -> {
|
||||
if (components.any { it == "hk" || it == "mo" }) return ZhHK
|
||||
if (components.any { it == "hans" || it == "cn" || it == "sg" }) return ZhHans
|
||||
if (components.any { it == "tw" }) return ZhHant
|
||||
if (components.any { it == "hant" }) {
|
||||
return if (region == "HK" || region == "MO") ZhHK else ZhHant
|
||||
}
|
||||
if (region == "HK" || region == "MO") return ZhHK
|
||||
if (region == "TW") return ZhHant
|
||||
return ZhHans
|
||||
}
|
||||
"en" -> return En
|
||||
"ja" -> return Ja
|
||||
"ko" -> return Ko
|
||||
"th" -> return Th
|
||||
"id", "in" -> return Indonesian
|
||||
"ms" -> return Ms
|
||||
else -> continue
|
||||
}
|
||||
}
|
||||
return En
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/** Resolves and formats every visible string, mirroring the iOS L10n. */
|
||||
object L10n {
|
||||
private var tables: MutableMap<String, Map<String, String>> = mutableMapOf()
|
||||
private var applicationContext: Context? = null
|
||||
private var language: AppLanguage = AppLanguage.En
|
||||
|
||||
val current: AppLanguage get() = language
|
||||
|
||||
fun attach(context: Context) {
|
||||
applicationContext = context.applicationContext
|
||||
tables.clear()
|
||||
}
|
||||
|
||||
/** Applies the saved preference, or the system language when the preference is "follow system". */
|
||||
fun apply(context: Context, preference: String?) {
|
||||
attach(context)
|
||||
val stored = AppLanguage.fromTag(preference)
|
||||
setLanguageInternal(
|
||||
if (stored == AppLanguage.System) {
|
||||
val configuration = context.resources.configuration
|
||||
val locales = configuration.locales
|
||||
val tags = (0 until locales.size()).map { locales[it].toLanguageTag() }
|
||||
AppLanguage.resolveSystemLanguage(
|
||||
tags.ifEmpty { listOf(Locale.getDefault().toLanguageTag()) },
|
||||
if (locales.size() > 0) locales[0].country else Locale.getDefault().country,
|
||||
)
|
||||
} else stored,
|
||||
)
|
||||
}
|
||||
|
||||
/** Test and preview entry point: resolves a fixed language with no Context. */
|
||||
fun setLanguage(value: AppLanguage) {
|
||||
setLanguageInternal(if (value == AppLanguage.System) AppLanguage.En else value)
|
||||
}
|
||||
|
||||
private fun setLanguageInternal(value: AppLanguage) {
|
||||
language = value
|
||||
}
|
||||
|
||||
fun text(key: String): String {
|
||||
val value = table(language)[key]
|
||||
if (value != null) return value
|
||||
return table(AppLanguage.En)[key] ?: key
|
||||
}
|
||||
|
||||
fun format(key: String, vararg arguments: Any?): String {
|
||||
val pattern = javaFormat(text(key))
|
||||
return try {
|
||||
String.format(language.locale, pattern, *arguments)
|
||||
} catch (_: IllegalArgumentException) {
|
||||
text(key)
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Translates the iOS format specifiers to the Java ones: `%@` becomes `%s` and keeps its
|
||||
* width/position modifiers, `%d` and `%s` pass through unchanged.
|
||||
*/
|
||||
private fun javaFormat(pattern: String): String {
|
||||
val builder = StringBuilder(pattern.length + 8)
|
||||
var index = 0
|
||||
while (index < pattern.length) {
|
||||
val character = pattern[index]
|
||||
if (character != '%') {
|
||||
builder.append(character)
|
||||
index++
|
||||
continue
|
||||
}
|
||||
builder.append('%')
|
||||
index++
|
||||
if (index < pattern.length && pattern[index] == '%') {
|
||||
builder.append('%')
|
||||
index++
|
||||
continue
|
||||
}
|
||||
while (index < pattern.length && pattern[index] in "0123456789$.+- #0") {
|
||||
builder.append(pattern[index])
|
||||
index++
|
||||
}
|
||||
if (index >= pattern.length) break
|
||||
when (val conversion = pattern[index]) {
|
||||
'@' -> builder.append('s')
|
||||
'l' -> builder.append("d") // %ld is an Int64 argument
|
||||
else -> builder.append(conversion)
|
||||
}
|
||||
index++
|
||||
}
|
||||
return builder.toString()
|
||||
}
|
||||
|
||||
private fun table(value: AppLanguage): Map<String, String> {
|
||||
tables[value.tag]?.let { return it }
|
||||
val loaded = when {
|
||||
value == AppLanguage.System -> table(AppLanguage.En)
|
||||
value == AppLanguage.En -> load(value.tag) ?: emptyMap()
|
||||
else -> load(value.tag) ?: table(AppLanguage.En)
|
||||
}
|
||||
tables[value.tag] = loaded
|
||||
return loaded
|
||||
}
|
||||
|
||||
private fun load(tag: String): Map<String, String>? {
|
||||
val context = applicationContext ?: return bundledFallback(tag)
|
||||
return try {
|
||||
context.assets.open("localization/$tag.strings").use { parse(it) }
|
||||
} catch (_: Exception) {
|
||||
null
|
||||
}
|
||||
}
|
||||
|
||||
/** Used by unit tests and previews, where no Context exists. */
|
||||
private fun bundledFallback(tag: String): Map<String, String>? {
|
||||
val stream: InputStream = javaClass.getResourceAsStream("/localization/$tag.strings") ?: return null
|
||||
return stream.use { parse(it) }
|
||||
}
|
||||
|
||||
private fun parse(stream: InputStream): Map<String, String> {
|
||||
val result = mutableMapOf<String, String>()
|
||||
stream.bufferedReader(Charsets.UTF_8).forEachLine { line ->
|
||||
val trimmed = line.trim()
|
||||
if (!trimmed.startsWith("\"")) return@forEachLine
|
||||
val separator = trimmed.indexOf("\" = \"")
|
||||
if (separator < 0) return@forEachLine
|
||||
val key = trimmed.substring(1, separator)
|
||||
val end = trimmed.lastIndexOf("\";")
|
||||
if (end <= separator) return@forEachLine
|
||||
val value = trimmed.substring(separator + 5, end)
|
||||
result[unescape(key)] = unescape(value)
|
||||
}
|
||||
return result
|
||||
}
|
||||
|
||||
private fun unescape(value: String): String {
|
||||
if (!value.contains('\\')) return value
|
||||
val builder = StringBuilder(value.length)
|
||||
var index = 0
|
||||
while (index < value.length) {
|
||||
val character = value[index]
|
||||
if (character == '\\' && index + 1 < value.length) {
|
||||
when (val next = value[index + 1]) {
|
||||
'n' -> builder.append('\n')
|
||||
't' -> builder.append('\t')
|
||||
'"' -> builder.append('"')
|
||||
'\\' -> builder.append('\\')
|
||||
else -> builder.append(next)
|
||||
}
|
||||
index += 2
|
||||
} else {
|
||||
builder.append(character)
|
||||
index++
|
||||
}
|
||||
}
|
||||
return builder.toString()
|
||||
}
|
||||
}
|
||||
|
||||
/** The locale and configuration used when the chosen language differs from the system one. */
|
||||
fun AppLanguage.configuration(base: Configuration): Configuration =
|
||||
Configuration(base).apply { setLocale(locale) }
|
||||
@@ -0,0 +1,60 @@
|
||||
package com.oshicue.keeps.ui
|
||||
|
||||
import android.content.Context
|
||||
import android.content.Intent
|
||||
import android.net.Uri
|
||||
import androidx.activity.compose.rememberLauncherForActivityResult
|
||||
import androidx.activity.result.contract.ActivityResultContracts
|
||||
import androidx.compose.runtime.Composable
|
||||
import androidx.compose.runtime.Stable
|
||||
import androidx.compose.runtime.remember
|
||||
import androidx.core.content.FileProvider
|
||||
import java.io.File
|
||||
|
||||
/**
|
||||
* Picks JSON files and returns their bytes. The system picker hands back content URIs, so the
|
||||
* bytes are read through the content resolver rather than a file path.
|
||||
*/
|
||||
@Composable
|
||||
fun rememberDocumentPicker(onPicked: (List<ByteArray>) -> Unit): () -> Unit {
|
||||
val context = androidx.compose.ui.platform.LocalContext.current
|
||||
val launcher = rememberLauncherForActivityResult(
|
||||
ActivityResultContracts.OpenMultipleDocuments(),
|
||||
) { uris: List<Uri> ->
|
||||
if (uris.isEmpty()) return@rememberLauncherForActivityResult
|
||||
onPicked(uris.mapNotNull { uri ->
|
||||
runCatching { context.contentResolver.openInputStream(uri)?.use { it.readBytes() } }.getOrNull()
|
||||
})
|
||||
}
|
||||
return remember {
|
||||
{ launcher.launch(arrayOf("application/json", "text/plain", "*/*")) }
|
||||
}
|
||||
}
|
||||
|
||||
/** Writes an export into the app's cache and opens the system share sheet. */
|
||||
fun shareText(context: Context, text: String, filename: String, mimeType: String = "application/json") {
|
||||
val directory = File(context.cacheDir, "exports").apply { mkdirs() }
|
||||
val file = File(directory, filename)
|
||||
file.writeText(text, Charsets.UTF_8)
|
||||
val uri: Uri = FileProvider.getUriForFile(context, context.packageName + ".fileprovider", file)
|
||||
val intent = Intent(Intent.ACTION_SEND).apply {
|
||||
type = mimeType
|
||||
putExtra(Intent.EXTRA_STREAM, uri)
|
||||
addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION)
|
||||
}
|
||||
context.startActivity(Intent.createChooser(intent, filename))
|
||||
}
|
||||
|
||||
/** Remembers a create-document launcher whose written contents are set at share time. */
|
||||
@Stable
|
||||
class DocumentSaver internal constructor(private val launch: (String) -> Unit) {
|
||||
fun save(filename: String) = launch(filename)
|
||||
}
|
||||
|
||||
@Composable
|
||||
fun rememberDocumentSaver(onWrite: (Uri) -> Unit): DocumentSaver {
|
||||
val launcher = rememberLauncherForActivityResult(
|
||||
ActivityResultContracts.CreateDocument("application/json"),
|
||||
) { uri -> if (uri != null) onWrite(uri) }
|
||||
return remember { DocumentSaver { filename -> launcher.launch(filename) } }
|
||||
}
|
||||
@@ -0,0 +1,127 @@
|
||||
package com.oshicue.keeps.ui
|
||||
|
||||
import androidx.compose.foundation.background
|
||||
import androidx.compose.foundation.clickable
|
||||
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.fillMaxSize
|
||||
import androidx.compose.foundation.layout.fillMaxWidth
|
||||
import androidx.compose.foundation.layout.padding
|
||||
import androidx.compose.foundation.layout.width
|
||||
import androidx.compose.foundation.rememberScrollState
|
||||
import androidx.compose.foundation.shape.RoundedCornerShape
|
||||
import androidx.compose.foundation.verticalScroll
|
||||
import androidx.compose.material.icons.Icons
|
||||
import androidx.compose.material.icons.filled.Book
|
||||
import androidx.compose.material.icons.filled.Check
|
||||
import androidx.compose.material.icons.filled.Language
|
||||
import androidx.compose.material3.Icon
|
||||
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.platform.LocalContext
|
||||
import androidx.compose.ui.text.font.FontWeight
|
||||
import androidx.compose.ui.unit.dp
|
||||
import androidx.compose.ui.unit.sp
|
||||
import com.oshicue.keeps.core.AppLanguage
|
||||
import com.oshicue.keeps.core.L10n
|
||||
|
||||
/** The 设置 tab: language, ledger management and About. */
|
||||
@Composable
|
||||
fun KeepsSettingsScreen(
|
||||
store: LedgerStore,
|
||||
language: AppLanguage,
|
||||
onLanguageChange: (AppLanguage) -> Unit,
|
||||
onOpenManagement: () -> Unit,
|
||||
) {
|
||||
val context = LocalContext.current
|
||||
var languageOpen by remember { mutableStateOf(false) }
|
||||
|
||||
Column(Modifier.fillMaxSize().background(Kit.colors.background)) {
|
||||
KitTopBar {
|
||||
CircleIconButton(Icons.Filled.Language, L10n.text("settings.language")) { languageOpen = !languageOpen }
|
||||
}
|
||||
Column(
|
||||
Modifier.fillMaxSize().verticalScroll(rememberScrollState()).padding(horizontal = 20.dp).padding(bottom = 35.dp),
|
||||
verticalArrangement = Arrangement.spacedBy(16.dp),
|
||||
) {
|
||||
Text(L10n.text("settings.title"), style = KitTitleStyle, color = Kit.colors.ink)
|
||||
|
||||
KitSectionLabel(L10n.text("settings.language"))
|
||||
KeepsSettingRow(Icons.Filled.Language, language.nativeName) { languageOpen = !languageOpen }
|
||||
if (languageOpen) {
|
||||
Column(Modifier.fillMaxWidth().clip(RoundedCornerShape(16.dp)).background(Kit.colors.surface)) {
|
||||
AppLanguage.entries.forEach { value ->
|
||||
Row(
|
||||
Modifier.fillMaxWidth().clickable {
|
||||
onLanguageChange(value)
|
||||
languageOpen = false
|
||||
}.padding(horizontal = 16.dp, vertical = 13.dp),
|
||||
verticalAlignment = Alignment.CenterVertically,
|
||||
) {
|
||||
Text(value.nativeName, fontSize = 14.sp, color = Kit.colors.ink, modifier = Modifier.weight(1f))
|
||||
if (value == language) {
|
||||
Icon(Icons.Filled.Check, contentDescription = null, tint = Kit.colors.accentText,
|
||||
modifier = Modifier.width(16.dp))
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
KitSectionLabel(L10n.text("settings.data"))
|
||||
KeepsSettingRow(Icons.Filled.Book, L10n.text("ledger.management"), onOpenManagement)
|
||||
Text(L10n.text("settings.localData"), fontSize = 12.sp, color = Kit.colors.muted)
|
||||
|
||||
KitSectionLabel(L10n.text("settings.about"))
|
||||
Column(
|
||||
Modifier.fillMaxWidth().clip(RoundedCornerShape(16.dp)).background(Kit.colors.surface).padding(18.dp),
|
||||
verticalArrangement = Arrangement.spacedBy(10.dp),
|
||||
) {
|
||||
BrandWordmark()
|
||||
Row(Modifier.fillMaxWidth()) {
|
||||
Text(L10n.text("settings.version"), fontSize = 13.sp, color = Kit.colors.muted)
|
||||
Spacer(Modifier.weight(1f))
|
||||
Text(appVersion(context), fontSize = 13.sp, color = Kit.colors.ink)
|
||||
}
|
||||
Text("Unbounded — SIL Open Font License 1.1", fontSize = 12.sp, color = Kit.colors.muted)
|
||||
Text(L10n.text("settings.keepsAbout"), fontSize = 12.sp, color = Kit.colors.muted)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Composable
|
||||
private fun KeepsSettingRow(
|
||||
icon: androidx.compose.ui.graphics.vector.ImageVector,
|
||||
title: String,
|
||||
onClick: () -> Unit,
|
||||
) {
|
||||
Row(
|
||||
Modifier
|
||||
.fillMaxWidth()
|
||||
.clip(RoundedCornerShape(16.dp))
|
||||
.background(Kit.colors.surface)
|
||||
.clickable(onClick = onClick)
|
||||
.padding(horizontal = 16.dp, vertical = 15.dp),
|
||||
verticalAlignment = Alignment.CenterVertically,
|
||||
) {
|
||||
Icon(icon, contentDescription = null, tint = Kit.colors.accentText, modifier = Modifier.width(18.dp))
|
||||
Spacer(Modifier.width(12.dp))
|
||||
Text(title, fontSize = 14.sp, fontWeight = FontWeight.Medium, color = Kit.colors.ink)
|
||||
}
|
||||
}
|
||||
|
||||
/** Android has no Info.plist; the package manager reports the version and version code. */
|
||||
fun appVersion(context: android.content.Context): String = runCatching {
|
||||
val info = context.packageManager.getPackageInfo(context.packageName, 0)
|
||||
"${info.versionName ?: "—"} · ${if (android.os.Build.VERSION.SDK_INT >= 28) info.longVersionCode.toString() else "—"}"
|
||||
}.getOrDefault("—")
|
||||
@@ -0,0 +1,233 @@
|
||||
package com.oshicue.keeps.ui
|
||||
|
||||
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.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.layout.width
|
||||
import androidx.compose.foundation.shape.CircleShape
|
||||
import androidx.compose.foundation.shape.RoundedCornerShape
|
||||
import androidx.compose.foundation.text.BasicTextField
|
||||
import androidx.compose.material.icons.Icons
|
||||
import androidx.compose.material.icons.filled.Close
|
||||
import androidx.compose.material.icons.filled.Search
|
||||
import androidx.compose.material3.Icon
|
||||
import androidx.compose.material3.LocalTextStyle
|
||||
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.Color
|
||||
import androidx.compose.ui.graphics.vector.ImageVector
|
||||
import androidx.compose.ui.text.TextStyle
|
||||
import androidx.compose.ui.text.font.FontWeight
|
||||
import androidx.compose.ui.text.style.TextOverflow
|
||||
import androidx.compose.ui.unit.dp
|
||||
import androidx.compose.ui.unit.sp
|
||||
import androidx.compose.ui.text.font.Font
|
||||
import androidx.compose.ui.text.font.FontFamily
|
||||
import androidx.compose.ui.text.font.FontVariation
|
||||
import com.oshicue.keeps.R
|
||||
import com.oshicue.keeps.core.AppBrand
|
||||
import com.oshicue.keeps.core.L10n
|
||||
|
||||
/**
|
||||
* Unbounded at weight 900 — the same typeface and weight the iOS wordmark uses. The bundled file is
|
||||
* a variable font (wght 200-900), so the axis is set explicitly instead of relying on the default
|
||||
* 400 instance, which would look lighter than the iOS logo beside it.
|
||||
*/
|
||||
val BrandFont = FontFamily(
|
||||
Font(
|
||||
R.font.unbounded_regular,
|
||||
weight = FontWeight.Black,
|
||||
variationSettings = FontVariation.Settings(FontVariation.weight(900)),
|
||||
),
|
||||
)
|
||||
|
||||
/** The Oshicue family wordmark, with CUE in the family pink. */
|
||||
@Composable
|
||||
fun BrandWordmark(modifier: Modifier = Modifier) {
|
||||
Row(modifier, verticalAlignment = Alignment.Bottom) {
|
||||
Text("OSHI", color = Kit.colors.ink, fontFamily = BrandFont, fontSize = 18.sp, letterSpacing = 0.25.sp)
|
||||
Text("CUE", color = Kit.colors.familyPink, fontFamily = BrandFont, fontSize = 18.sp, letterSpacing = 0.25.sp)
|
||||
Spacer(Modifier.width(5.dp))
|
||||
Text(AppBrand.productName, color = Kit.colors.ink, fontFamily = BrandFont, fontSize = 10.sp, letterSpacing = 0.6.sp)
|
||||
}
|
||||
}
|
||||
|
||||
/** The wordmark row at the top of every page, with that page's actions on the right. */
|
||||
@Composable
|
||||
fun KitTopBar(bottomPadding: Int = 8, actions: @Composable () -> Unit) {
|
||||
Row(
|
||||
modifier = Modifier.fillMaxWidth().padding(horizontal = 20.dp).padding(top = 2.dp, bottom = bottomPadding.dp),
|
||||
verticalAlignment = Alignment.CenterVertically,
|
||||
) {
|
||||
BrandWordmark()
|
||||
Spacer(Modifier.weight(1f))
|
||||
actions()
|
||||
}
|
||||
}
|
||||
|
||||
@Composable
|
||||
fun CircleIconButton(symbol: ImageVector, label: String, onClick: () -> Unit) {
|
||||
Box(
|
||||
modifier = Modifier
|
||||
.size(42.dp)
|
||||
.clip(CircleShape)
|
||||
.background(Kit.colors.surface)
|
||||
.border(1.dp, Kit.colors.line, CircleShape)
|
||||
.clickable(onClick = onClick),
|
||||
contentAlignment = Alignment.Center,
|
||||
) {
|
||||
Icon(symbol, contentDescription = label, tint = Kit.colors.ink, modifier = Modifier.size(19.dp))
|
||||
}
|
||||
}
|
||||
|
||||
@Composable
|
||||
fun KitSearchField(text: String, prompt: String, onTextChange: (String) -> Unit, modifier: Modifier = Modifier) {
|
||||
Row(
|
||||
modifier = modifier
|
||||
.fillMaxWidth()
|
||||
.clip(RoundedCornerShape(14.dp))
|
||||
.background(Kit.colors.surface)
|
||||
.padding(13.dp),
|
||||
verticalAlignment = Alignment.CenterVertically,
|
||||
) {
|
||||
Icon(Icons.Filled.Search, contentDescription = null, tint = Kit.colors.muted, modifier = Modifier.size(18.dp))
|
||||
Spacer(Modifier.width(10.dp))
|
||||
Box(Modifier.weight(1f)) {
|
||||
if (text.isEmpty()) {
|
||||
Text(prompt, color = Kit.colors.muted, fontSize = 15.sp)
|
||||
}
|
||||
BasicTextField(
|
||||
value = text,
|
||||
onValueChange = onTextChange,
|
||||
singleLine = true,
|
||||
textStyle = LocalTextStyle.current.copy(color = Kit.colors.ink, fontSize = 15.sp),
|
||||
cursorBrush = androidx.compose.ui.graphics.SolidColor(Kit.colors.accentText),
|
||||
modifier = Modifier.fillMaxWidth(),
|
||||
)
|
||||
}
|
||||
if (text.isNotEmpty()) {
|
||||
Icon(
|
||||
Icons.Filled.Close,
|
||||
contentDescription = L10n.text("common.clearSearch"),
|
||||
tint = Kit.colors.muted,
|
||||
modifier = Modifier.size(18.dp).clickable { onTextChange("") },
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Composable
|
||||
fun KitSheetHeader(symbol: ImageVector, title: String, subtitle: String) {
|
||||
Row(verticalAlignment = Alignment.CenterVertically) {
|
||||
Box(
|
||||
modifier = Modifier
|
||||
.size(56.dp)
|
||||
.clip(RoundedCornerShape(16.dp))
|
||||
.background(Kit.colors.surface),
|
||||
contentAlignment = Alignment.Center,
|
||||
) {
|
||||
Icon(symbol, contentDescription = null, tint = Kit.colors.accentText, modifier = Modifier.size(25.dp))
|
||||
}
|
||||
Spacer(Modifier.width(12.dp))
|
||||
Column(verticalArrangement = Arrangement.spacedBy(5.dp)) {
|
||||
Text(title, fontSize = 19.sp, fontWeight = FontWeight.Bold, color = Kit.colors.ink)
|
||||
Text(subtitle, fontSize = 12.sp, color = Kit.colors.muted)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Composable
|
||||
fun KitErrorBox(message: String, modifier: Modifier = Modifier) {
|
||||
Text(
|
||||
message,
|
||||
color = Color(0xFFC62828),
|
||||
fontSize = 12.sp,
|
||||
modifier = modifier
|
||||
.fillMaxWidth()
|
||||
.clip(RoundedCornerShape(12.dp))
|
||||
.background(Color(0xFFC62828).copy(alpha = 0.05f))
|
||||
.padding(12.dp),
|
||||
)
|
||||
}
|
||||
|
||||
/** A grouped card on the page background. */
|
||||
@Composable
|
||||
fun KitCard(spacing: Int = 13, content: @Composable () -> Unit) {
|
||||
Column(
|
||||
modifier = Modifier
|
||||
.fillMaxWidth()
|
||||
.clip(RoundedCornerShape(16.dp))
|
||||
.background(Kit.colors.surface)
|
||||
.padding(18.dp),
|
||||
verticalArrangement = Arrangement.spacedBy(spacing.dp),
|
||||
) { content() }
|
||||
}
|
||||
|
||||
@Composable
|
||||
fun KitSectionLabel(text: String) {
|
||||
Text(text, fontSize = 11.sp, fontWeight = FontWeight.Bold, letterSpacing = 1.2.sp, color = Kit.colors.muted)
|
||||
}
|
||||
|
||||
fun toggle(set: Set<String>, value: String): Set<String> =
|
||||
if (value in set) set - value else set + value
|
||||
|
||||
/** Ellipsis-truncated single-line text with the shared card typography. */
|
||||
@Composable
|
||||
fun KitLine(text: String, style: TextStyle, modifier: Modifier = Modifier, maxLines: Int = 1) {
|
||||
Text(text, style = style, maxLines = maxLines, overflow = TextOverflow.Ellipsis, modifier = modifier)
|
||||
}
|
||||
|
||||
@Composable
|
||||
fun KitDivider(modifier: Modifier = Modifier) {
|
||||
Box(modifier.fillMaxWidth().height(1.dp).background(Kit.colors.line))
|
||||
}
|
||||
|
||||
/** A full-width filled call to action. */
|
||||
@Composable
|
||||
fun ProminentButton(label: String, enabled: Boolean = true, onClick: () -> Unit) {
|
||||
Text(
|
||||
label,
|
||||
fontSize = 15.sp,
|
||||
fontWeight = FontWeight.SemiBold,
|
||||
color = Kit.colors.onAccent,
|
||||
textAlign = androidx.compose.ui.text.style.TextAlign.Center,
|
||||
modifier = Modifier
|
||||
.fillMaxWidth()
|
||||
.clip(RoundedCornerShape(12.dp))
|
||||
.background(if (enabled) Kit.colors.accentFill else Kit.colors.accentFill.copy(alpha = 0.4f))
|
||||
.clickable(enabled = enabled, onClick = onClick)
|
||||
.padding(vertical = 13.dp),
|
||||
)
|
||||
}
|
||||
|
||||
/** The bar every full-page sheet uses: a close button on the left, the title, then an optional action. */
|
||||
@Composable
|
||||
fun SheetBar(title: String, onClose: () -> Unit, action: (@Composable () -> Unit)? = null) {
|
||||
Row(
|
||||
Modifier.fillMaxWidth().padding(horizontal = 16.dp).padding(top = 10.dp, bottom = 6.dp),
|
||||
verticalAlignment = Alignment.CenterVertically,
|
||||
) {
|
||||
Icon(
|
||||
androidx.compose.material.icons.Icons.Filled.Close,
|
||||
contentDescription = L10n.text("common.close"),
|
||||
tint = Kit.colors.ink,
|
||||
modifier = Modifier.size(22.dp).clickable(onClick = onClose),
|
||||
)
|
||||
Spacer(Modifier.width(14.dp))
|
||||
Text(title, fontSize = 17.sp, fontWeight = FontWeight.Bold, color = Kit.colors.ink)
|
||||
Spacer(Modifier.weight(1f))
|
||||
action?.invoke()
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,70 @@
|
||||
package com.oshicue.keeps.ui
|
||||
|
||||
import android.graphics.BitmapFactory
|
||||
import android.util.Base64
|
||||
import androidx.compose.foundation.Image
|
||||
import androidx.compose.foundation.background
|
||||
import androidx.compose.foundation.border
|
||||
import androidx.compose.foundation.layout.Box
|
||||
import androidx.compose.foundation.layout.fillMaxSize
|
||||
import androidx.compose.foundation.layout.size
|
||||
import androidx.compose.foundation.shape.CircleShape
|
||||
import androidx.compose.material.icons.Icons
|
||||
import androidx.compose.material.icons.filled.Person
|
||||
import androidx.compose.material3.Icon
|
||||
import androidx.compose.material3.Text
|
||||
import androidx.compose.runtime.Composable
|
||||
import androidx.compose.runtime.remember
|
||||
import androidx.compose.ui.Alignment
|
||||
import androidx.compose.ui.Modifier
|
||||
import androidx.compose.ui.draw.clip
|
||||
import androidx.compose.ui.graphics.Color
|
||||
import androidx.compose.ui.graphics.ImageBitmap
|
||||
import androidx.compose.ui.graphics.asImageBitmap
|
||||
import androidx.compose.ui.layout.ContentScale
|
||||
import androidx.compose.ui.unit.Dp
|
||||
import androidx.compose.ui.unit.dp
|
||||
import androidx.compose.ui.unit.sp
|
||||
import com.oshicue.keeps.core.LedgerMember
|
||||
|
||||
/** A member's photo when they have one, otherwise their group color behind a person glyph. */
|
||||
@Composable
|
||||
fun LedgerAvatar(member: LedgerMember?, color: String, size: Dp = 44.dp) {
|
||||
val photo = remember(member?.avatarJPEGBase64) { decodeAvatar(member?.avatarJPEGBase64) }
|
||||
Box(
|
||||
Modifier
|
||||
.size(size)
|
||||
.clip(CircleShape)
|
||||
.background(Color.White)
|
||||
.border(2.5.dp, Kit.parse(color), CircleShape),
|
||||
contentAlignment = Alignment.Center,
|
||||
) {
|
||||
if (photo != null) {
|
||||
Image(photo, contentDescription = null, contentScale = ContentScale.Crop, modifier = Modifier.fillMaxSize())
|
||||
} else {
|
||||
Box(Modifier.fillMaxSize().background(Kit.parse(color).copy(alpha = 0.12f)), contentAlignment = Alignment.Center) {
|
||||
Icon(Icons.Filled.Person, contentDescription = null, tint = Kit.parse(color),
|
||||
modifier = Modifier.size(size * 0.42f))
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Decoded avatars are reused: lists and rankings redraw the same faces on every change.
|
||||
* Keyed by the encoded photo, and downscaled to 256 px because the largest avatar is 70 pt.
|
||||
*/
|
||||
private val avatarCache = object : LinkedHashMap<String, ImageBitmap>(16, 0.75f, true) {
|
||||
override fun removeEldestEntry(eldest: MutableMap.MutableEntry<String, ImageBitmap>?): Boolean = size > 64
|
||||
}
|
||||
|
||||
private fun decodeAvatar(encoded: String?): ImageBitmap? {
|
||||
if (encoded.isNullOrEmpty()) return null
|
||||
avatarCache[encoded]?.let { return it }
|
||||
val bytes = runCatching { Base64.decode(encoded, Base64.DEFAULT) }.getOrNull() ?: return null
|
||||
val options = BitmapFactory.Options().apply { inSampleSize = 2 }
|
||||
val bitmap = runCatching { BitmapFactory.decodeByteArray(bytes, 0, bytes.size, options) }.getOrNull() ?: return null
|
||||
val image = bitmap.asImageBitmap()
|
||||
avatarCache[encoded] = image
|
||||
return image
|
||||
}
|
||||
@@ -0,0 +1,493 @@
|
||||
package com.oshicue.keeps.ui
|
||||
|
||||
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.Spacer
|
||||
import androidx.compose.foundation.layout.aspectRatio
|
||||
import androidx.compose.foundation.layout.fillMaxSize
|
||||
import androidx.compose.foundation.layout.fillMaxWidth
|
||||
import androidx.compose.foundation.layout.height
|
||||
import androidx.compose.foundation.layout.heightIn
|
||||
import androidx.compose.foundation.layout.padding
|
||||
import androidx.compose.foundation.layout.size
|
||||
import androidx.compose.foundation.layout.width
|
||||
import androidx.compose.foundation.lazy.grid.GridCells
|
||||
import androidx.compose.foundation.lazy.grid.LazyVerticalGrid
|
||||
import androidx.compose.foundation.lazy.grid.items
|
||||
import androidx.compose.foundation.rememberScrollState
|
||||
import androidx.compose.foundation.shape.RoundedCornerShape
|
||||
import androidx.compose.foundation.verticalScroll
|
||||
import androidx.compose.material.icons.Icons
|
||||
import androidx.compose.material.icons.automirrored.filled.KeyboardArrowLeft
|
||||
import androidx.compose.material.icons.automirrored.filled.KeyboardArrowRight
|
||||
import androidx.compose.material.icons.filled.Add
|
||||
import androidx.compose.material.icons.filled.CalendarMonth
|
||||
import androidx.compose.material.icons.filled.ChevronLeft
|
||||
import androidx.compose.material.icons.filled.ChevronRight
|
||||
import androidx.compose.material.icons.filled.ExpandMore
|
||||
import androidx.compose.material.icons.filled.PersonAdd
|
||||
import androidx.compose.material.icons.filled.PhotoLibrary
|
||||
import androidx.compose.material.icons.filled.Tune
|
||||
import androidx.compose.material3.AlertDialog
|
||||
import androidx.compose.material3.DatePicker
|
||||
import androidx.compose.material3.DatePickerDialog
|
||||
import androidx.compose.material3.rememberDatePickerState
|
||||
import androidx.compose.material3.Icon
|
||||
import androidx.compose.material3.Text
|
||||
import androidx.compose.material3.TextButton
|
||||
import androidx.compose.runtime.Composable
|
||||
import androidx.compose.runtime.LaunchedEffect
|
||||
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.text.font.FontWeight
|
||||
import androidx.compose.ui.text.style.TextAlign
|
||||
import androidx.compose.ui.text.style.TextOverflow
|
||||
import androidx.compose.ui.unit.dp
|
||||
import androidx.compose.ui.unit.sp
|
||||
import androidx.lifecycle.compose.collectAsStateWithLifecycle
|
||||
import com.oshicue.keeps.core.KitDate
|
||||
import com.oshicue.keeps.core.L10n
|
||||
import com.oshicue.keeps.core.LedgerAnalytics
|
||||
import com.oshicue.keeps.core.LedgerCurrency
|
||||
import com.oshicue.keeps.core.LedgerDates
|
||||
import com.oshicue.keeps.core.LedgerGrouping
|
||||
import com.oshicue.keeps.core.LedgerMetric
|
||||
import com.oshicue.keeps.core.LedgerPresentation
|
||||
import com.oshicue.keeps.core.LedgerRankRow
|
||||
import com.oshicue.keeps.core.LedgerRecord
|
||||
import com.oshicue.keeps.core.LedgerSummary
|
||||
import com.oshicue.keeps.core.activeMemberships
|
||||
import com.oshicue.keeps.core.latestRecord
|
||||
import java.time.Instant
|
||||
import java.time.LocalDate
|
||||
import java.time.YearMonth
|
||||
import java.time.ZoneId
|
||||
|
||||
/** The 日历 tab: a month calendar with purchase counts, the selected day's cards and every record. */
|
||||
@Composable
|
||||
fun LedgerCalendarScreen(
|
||||
store: LedgerStore,
|
||||
selectedDate: LocalDate,
|
||||
shownMonth: YearMonth,
|
||||
onSelectedDate: (LocalDate) -> Unit,
|
||||
onShownMonth: (YearMonth) -> Unit,
|
||||
onAdd: () -> Unit,
|
||||
onOpenCatalog: () -> Unit,
|
||||
onEdit: (LedgerRecord) -> Unit,
|
||||
onDelete: (LedgerRecord) -> Unit,
|
||||
) {
|
||||
val state by store.state.collectAsStateWithLifecycle()
|
||||
val document = state.document
|
||||
val day = LedgerDates.string(selectedDate)
|
||||
val dailyRecords = document.records.filter { it.date == day }
|
||||
val dailyRows = remember(dailyRecords) {
|
||||
runCatching {
|
||||
LedgerAnalytics.rankings(dailyRecords, LedgerGrouping.MemberByGroup, LedgerMetric.Quantity)
|
||||
}.getOrDefault(emptyList())
|
||||
}
|
||||
val monthRecords = remember(document.records, shownMonth) {
|
||||
document.records.filter { it.date.take(7) == shownMonth.toString() }
|
||||
}
|
||||
val monthSummary = remember(monthRecords) {
|
||||
runCatching { LedgerAnalytics.summarize(monthRecords) }.getOrNull()
|
||||
}
|
||||
val quantitiesByDay = remember(document.records) {
|
||||
document.records.groupingBy { it.date }.fold(0) { sum, record -> sum + record.quantity }
|
||||
}
|
||||
var expanded by remember { mutableStateOf(false) }
|
||||
var datePickerOpen by remember { mutableStateOf(false) }
|
||||
var selection by remember { mutableStateOf<DailySelection?>(null) }
|
||||
|
||||
Column(Modifier.fillMaxSize().verticalScroll(rememberScrollState()).padding(bottom = 35.dp)) {
|
||||
Column(Modifier.padding(horizontal = 20.dp), verticalArrangement = Arrangement.spacedBy(16.dp)) {
|
||||
CalendarCard(
|
||||
shownMonth = shownMonth,
|
||||
selectedDate = selectedDate,
|
||||
quantitiesByDay = quantitiesByDay,
|
||||
onMoveMonth = { offset ->
|
||||
val next = shownMonth.plusMonths(offset.toLong())
|
||||
onShownMonth(next)
|
||||
onSelectedDate(next.atDay(1))
|
||||
},
|
||||
onOpenDatePicker = { datePickerOpen = true },
|
||||
onSelectDay = { date ->
|
||||
onSelectedDate(date)
|
||||
if (YearMonth.from(date) != shownMonth) onShownMonth(YearMonth.from(date))
|
||||
},
|
||||
)
|
||||
|
||||
Row(horizontalArrangement = Arrangement.spacedBy(12.dp)) {
|
||||
SummaryTile(
|
||||
L10n.text("ledger.quantity"),
|
||||
(monthSummary?.quantity ?: 0).toString(),
|
||||
modifier = Modifier.weight(1f),
|
||||
)
|
||||
SummaryTile(
|
||||
L10n.text("ledger.spending"),
|
||||
monthSummary?.amountsByCurrency?.takeIf { it.isNotEmpty() }
|
||||
?.let { LedgerPresentation.money(it) } ?: "—",
|
||||
modifier = Modifier.weight(1f),
|
||||
)
|
||||
}
|
||||
|
||||
Row(verticalAlignment = Alignment.CenterVertically) {
|
||||
Box(Modifier.width(4.dp).height(24.dp).clip(RoundedCornerShape(3.dp)).background(Kit.colors.accent))
|
||||
Spacer(Modifier.width(10.dp))
|
||||
Text(
|
||||
KitDate.string(selectedDate.atStartOfDay(ZoneId.systemDefault()).toInstant(), "yyyy MMM d EEE", ZoneId.systemDefault()),
|
||||
fontSize = 16.sp, fontWeight = FontWeight.Bold, color = Kit.colors.ink, modifier = Modifier.weight(1f),
|
||||
)
|
||||
Text(
|
||||
L10n.format("ledger.itemsCount", dailyRecords.sumOf { it.quantity }),
|
||||
fontSize = 11.sp, color = Kit.colors.muted,
|
||||
)
|
||||
}
|
||||
|
||||
if (dailyRows.isEmpty()) {
|
||||
Column(
|
||||
Modifier.fillMaxWidth().clip(RoundedCornerShape(18.dp)).background(Kit.colors.surface).padding(25.dp),
|
||||
horizontalAlignment = Alignment.CenterHorizontally,
|
||||
verticalArrangement = Arrangement.spacedBy(12.dp),
|
||||
) {
|
||||
Icon(Icons.Filled.PhotoLibrary, contentDescription = null, tint = Kit.colors.accentText,
|
||||
modifier = Modifier.size(28.dp))
|
||||
Text(L10n.text("ledger.noRecords"), fontSize = 14.sp, fontWeight = FontWeight.SemiBold, color = Kit.colors.ink)
|
||||
Text(L10n.text("ledger.noRecordsHint"), fontSize = 12.sp, color = Kit.colors.muted, textAlign = TextAlign.Center)
|
||||
if (document.activeMemberships.isEmpty()) {
|
||||
Text(L10n.text("ledger.manage"), fontSize = 13.sp, fontWeight = FontWeight.SemiBold,
|
||||
color = Kit.colors.accentText, modifier = Modifier.clickable(onClick = onOpenCatalog))
|
||||
Text(L10n.text("ledger.loadDemo"), fontSize = 12.sp, color = Kit.colors.accentText,
|
||||
modifier = Modifier.clickable { store.loadDemo() })
|
||||
}
|
||||
}
|
||||
} else {
|
||||
dailyRows.forEach { row ->
|
||||
DailyCard(
|
||||
row = row,
|
||||
member = document.members.firstOrNull { it.id == row.memberID },
|
||||
onOpen = {
|
||||
val records = dailyRecords
|
||||
.filter { it.memberID == row.memberID && it.groupID == row.groupID }
|
||||
.sortedBy { it.id }
|
||||
if (records.size == 1) onEdit(records.first())
|
||||
else if (records.isNotEmpty()) selection = DailySelection(row, records)
|
||||
},
|
||||
onQuickAddProduct = { productID ->
|
||||
val memberID = row.memberID
|
||||
val groupID = row.groupID
|
||||
if (memberID != null && groupID != null) {
|
||||
val record = document.latestRecord(day, memberID, groupID, productID)
|
||||
if (record != null) store.addQuantity(1, record.id)
|
||||
}
|
||||
},
|
||||
)
|
||||
}
|
||||
|
||||
Column(
|
||||
Modifier.fillMaxWidth().clip(RoundedCornerShape(16.dp)).background(Kit.colors.surface).padding(16.dp),
|
||||
) {
|
||||
Row(
|
||||
Modifier.fillMaxWidth().clickable { expanded = !expanded },
|
||||
verticalAlignment = Alignment.CenterVertically,
|
||||
) {
|
||||
Text(L10n.text("ledger.records") + " · " + dailyRecords.size,
|
||||
fontSize = 13.sp, fontWeight = FontWeight.SemiBold, color = Kit.colors.ink)
|
||||
Spacer(Modifier.weight(1f))
|
||||
Icon(Icons.Filled.ExpandMore, contentDescription = null, tint = Kit.colors.muted,
|
||||
modifier = Modifier.size(18.dp))
|
||||
}
|
||||
if (expanded) {
|
||||
Column(Modifier.padding(top = 10.dp), verticalArrangement = Arrangement.spacedBy(10.dp)) {
|
||||
dailyRecords.sortedBy { it.id }.forEach { record ->
|
||||
RecordRow(record, onEdit = { onEdit(record) }, onDelete = { onDelete(record) },
|
||||
onQuickAdd = { store.addQuantity(1, record.id) })
|
||||
}
|
||||
Text(L10n.text("ledger.quickAddHint"), fontSize = 11.sp, color = Kit.colors.muted)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
selection?.let { picker ->
|
||||
DailyRecordPicker(
|
||||
row = picker.row,
|
||||
records = picker.records,
|
||||
member = document.members.firstOrNull { it.id == picker.row.memberID },
|
||||
onSelect = { record -> selection = null; onEdit(record) },
|
||||
onDismiss = { selection = null },
|
||||
)
|
||||
}
|
||||
|
||||
if (datePickerOpen) {
|
||||
val pickerState = rememberDatePickerState(
|
||||
initialSelectedDateMillis = selectedDate.atStartOfDay(ZoneId.of("UTC")).toInstant().toEpochMilli(),
|
||||
)
|
||||
androidx.compose.material3.DatePickerDialog(
|
||||
onDismissRequest = { datePickerOpen = false },
|
||||
confirmButton = {
|
||||
TextButton(onClick = {
|
||||
pickerState.selectedDateMillis?.let { millis ->
|
||||
val date = Instant.ofEpochMilli(millis).atZone(ZoneId.of("UTC")).toLocalDate()
|
||||
onSelectedDate(date)
|
||||
onShownMonth(YearMonth.from(date))
|
||||
}
|
||||
datePickerOpen = false
|
||||
}) { Text(L10n.text("common.done")) }
|
||||
},
|
||||
dismissButton = {
|
||||
TextButton(onClick = { datePickerOpen = false }) { Text(L10n.text("common.cancel")) }
|
||||
},
|
||||
) {
|
||||
DatePicker(state = pickerState)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Composable
|
||||
private fun CalendarCard(
|
||||
shownMonth: YearMonth,
|
||||
selectedDate: LocalDate,
|
||||
quantitiesByDay: Map<String, Int>,
|
||||
onMoveMonth: (Int) -> Unit,
|
||||
onOpenDatePicker: () -> Unit,
|
||||
onSelectDay: (LocalDate) -> Unit,
|
||||
) {
|
||||
val locale = L10n.current.locale
|
||||
val weekdays = remember(locale) {
|
||||
val formatter = java.time.format.DateTimeFormatter.ofPattern("EEEEE", locale)
|
||||
// 2024-01-01 was a Monday, so the seven names run Monday through Sunday.
|
||||
(0L..6L).map { formatter.format(LocalDate.of(2024, 1, 1).plusDays(it)) }
|
||||
}
|
||||
// Monday-first grid, padded to whole weeks, so the month always fills seven columns.
|
||||
val days = remember(shownMonth) {
|
||||
val first = shownMonth.atDay(1)
|
||||
val leading = first.dayOfWeek.value - 1
|
||||
val length = shownMonth.lengthOfMonth()
|
||||
val total = ((leading + length + 6) / 7) * 7
|
||||
(0 until total).map { first.plusDays((it - leading).toLong()) }
|
||||
}
|
||||
|
||||
Column(
|
||||
Modifier.fillMaxWidth().clip(RoundedCornerShape(20.dp)).background(Kit.colors.surface).padding(17.dp),
|
||||
verticalArrangement = Arrangement.spacedBy(14.dp),
|
||||
) {
|
||||
Row(verticalAlignment = Alignment.CenterVertically) {
|
||||
Icon(Icons.AutoMirrored.Filled.KeyboardArrowLeft, contentDescription = L10n.text("ledger.previousMonth"),
|
||||
tint = Kit.colors.ink, modifier = Modifier.size(26.dp).clickable { onMoveMonth(-1) })
|
||||
Spacer(Modifier.weight(1f))
|
||||
Text(
|
||||
KitDate.string(shownMonth.atDay(1).atStartOfDay(ZoneId.systemDefault()).toInstant(), "yyyy MMMM", ZoneId.systemDefault()),
|
||||
fontSize = 17.sp, fontWeight = FontWeight.Bold, color = Kit.colors.ink,
|
||||
modifier = Modifier.clickable(onClick = onOpenDatePicker),
|
||||
)
|
||||
Spacer(Modifier.weight(1f))
|
||||
Icon(Icons.AutoMirrored.Filled.KeyboardArrowRight, contentDescription = L10n.text("ledger.nextMonth"),
|
||||
tint = Kit.colors.ink, modifier = Modifier.size(26.dp).clickable { onMoveMonth(1) })
|
||||
}
|
||||
Row(Modifier.fillMaxWidth()) {
|
||||
weekdays.forEach { title ->
|
||||
Text(title, fontSize = 10.sp, color = Kit.colors.muted, textAlign = TextAlign.Center, modifier = Modifier.weight(1f))
|
||||
}
|
||||
}
|
||||
// A plain column of week rows keeps every day cell the same size without nested scrolling.
|
||||
Column(verticalArrangement = Arrangement.spacedBy(4.dp)) {
|
||||
days.chunked(7).forEach { week ->
|
||||
Row(Modifier.fillMaxWidth(), horizontalArrangement = Arrangement.spacedBy(3.dp)) {
|
||||
week.forEach { date ->
|
||||
val key = date.toString()
|
||||
val count = quantitiesByDay[key] ?: 0
|
||||
val selected = date == selectedDate
|
||||
val inMonth = YearMonth.from(date) == shownMonth
|
||||
val today = date == LocalDate.now()
|
||||
Column(
|
||||
Modifier
|
||||
.weight(1f)
|
||||
.clip(RoundedCornerShape(15.dp))
|
||||
.background(if (selected) Kit.colors.accentFill else androidx.compose.ui.graphics.Color.Transparent)
|
||||
.border(
|
||||
width = if (today && !selected) 1.2.dp else 0.dp,
|
||||
color = if (today && !selected) Kit.colors.accent else androidx.compose.ui.graphics.Color.Transparent,
|
||||
shape = RoundedCornerShape(15.dp),
|
||||
)
|
||||
.clickable { onSelectDay(date) }
|
||||
.padding(vertical = 6.dp),
|
||||
horizontalAlignment = Alignment.CenterHorizontally,
|
||||
verticalArrangement = Arrangement.spacedBy(2.dp),
|
||||
) {
|
||||
Text(
|
||||
date.dayOfMonth.toString(),
|
||||
fontSize = 15.sp,
|
||||
fontWeight = if (selected) FontWeight.Bold else FontWeight.Medium,
|
||||
color = when {
|
||||
selected -> Kit.colors.onAccent
|
||||
inMonth -> Kit.colors.ink
|
||||
else -> Kit.colors.muted
|
||||
},
|
||||
)
|
||||
Text(
|
||||
if (count == 0) " " else count.toString(),
|
||||
fontSize = 9.sp,
|
||||
fontWeight = FontWeight.SemiBold,
|
||||
color = if (selected) Kit.colors.onAccent else Kit.colors.accentText,
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Composable
|
||||
private fun SummaryTile(title: String, value: String, modifier: Modifier = Modifier) {
|
||||
Column(
|
||||
modifier
|
||||
.clip(RoundedCornerShape(16.dp))
|
||||
.background(Kit.colors.surface)
|
||||
.padding(14.dp),
|
||||
verticalArrangement = Arrangement.spacedBy(10.dp),
|
||||
) {
|
||||
Text(title, fontSize = 10.sp, fontFamily = androidx.compose.ui.text.font.FontFamily.Monospace, color = Kit.colors.muted)
|
||||
Text(value, fontSize = 19.sp, fontWeight = FontWeight.Bold, color = Kit.colors.ink, maxLines = 2,
|
||||
overflow = TextOverflow.Ellipsis)
|
||||
}
|
||||
}
|
||||
|
||||
@Composable
|
||||
private fun DailyCard(
|
||||
row: LedgerRankRow,
|
||||
member: com.oshicue.keeps.core.LedgerMember?,
|
||||
onOpen: () -> Unit,
|
||||
onQuickAddProduct: (String) -> Unit,
|
||||
) {
|
||||
Row(
|
||||
Modifier
|
||||
.fillMaxWidth()
|
||||
.clip(RoundedCornerShape(17.dp))
|
||||
.background(Kit.colors.surface)
|
||||
.clickable(onClick = onOpen)
|
||||
.padding(16.dp),
|
||||
verticalAlignment = Alignment.Top,
|
||||
) {
|
||||
LedgerAvatar(member, row.color, 44.dp)
|
||||
Spacer(Modifier.width(12.dp))
|
||||
Column(Modifier.weight(1f), verticalArrangement = Arrangement.spacedBy(5.dp)) {
|
||||
Text(row.name, fontSize = 15.sp, fontWeight = FontWeight.Bold, color = Kit.colors.ink)
|
||||
Text(row.subtitle, fontSize = 10.sp, color = Kit.colors.muted)
|
||||
Row(horizontalArrangement = Arrangement.spacedBy(5.dp)) {
|
||||
row.productRows.forEach { product ->
|
||||
Text(
|
||||
LedgerPresentation.productName(product.id, product.name) + " × " + product.quantity,
|
||||
fontSize = 9.sp, color = Kit.colors.ink,
|
||||
modifier = Modifier
|
||||
.clip(RoundedCornerShape(50))
|
||||
.background(Kit.colors.background)
|
||||
.clickable { onQuickAddProduct(product.id) }
|
||||
.padding(horizontal = 7.dp, vertical = 4.dp),
|
||||
)
|
||||
}
|
||||
}
|
||||
Text(LedgerPresentation.money(row.amountsByCurrency), fontSize = 11.sp, fontWeight = FontWeight.SemiBold,
|
||||
color = Kit.colors.ink)
|
||||
}
|
||||
Spacer(Modifier.width(4.dp))
|
||||
Column(horizontalAlignment = Alignment.End, verticalArrangement = Arrangement.spacedBy(10.dp)) {
|
||||
Text(row.quantity.toString(), fontSize = 25.sp, fontWeight = FontWeight.Bold,
|
||||
color = Kit.readableDataColor(row.color))
|
||||
Icon(Icons.Filled.ChevronRight, contentDescription = null, tint = Kit.colors.muted, modifier = Modifier.size(14.dp))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Composable
|
||||
private fun RecordRow(record: LedgerRecord, onEdit: () -> Unit, onDelete: () -> Unit, onQuickAdd: () -> Unit) {
|
||||
Row(Modifier.fillMaxWidth(), verticalAlignment = Alignment.CenterVertically) {
|
||||
Row(
|
||||
Modifier.weight(1f).clickable(onClick = onEdit),
|
||||
verticalAlignment = Alignment.CenterVertically,
|
||||
) {
|
||||
Box(Modifier.size(7.dp).clip(RoundedCornerShape(50)).background(Kit.parse(record.colorSnapshot)))
|
||||
Spacer(Modifier.width(9.dp))
|
||||
Column(Modifier.weight(1f), verticalArrangement = Arrangement.spacedBy(3.dp)) {
|
||||
Text(record.memberNameSnapshot, fontSize = 13.sp, fontWeight = FontWeight.SemiBold, color = Kit.colors.ink)
|
||||
Text(LedgerPresentation.productName(record.productID, record.productNameSnapshot) + " × " + record.quantity,
|
||||
fontSize = 12.sp, color = Kit.colors.muted)
|
||||
record.eventNameSnapshot?.let { Text(it, fontSize = 11.sp, color = Kit.colors.muted) }
|
||||
}
|
||||
Text(LedgerPresentation.total(record), fontSize = 11.sp, fontWeight = FontWeight.Medium, color = Kit.colors.ink)
|
||||
}
|
||||
Spacer(Modifier.width(6.dp))
|
||||
Icon(Icons.Filled.Add, contentDescription = L10n.format("ledger.quickAdd.product",
|
||||
LedgerPresentation.productName(record.productID, record.productNameSnapshot)),
|
||||
tint = Kit.colors.accentText,
|
||||
modifier = Modifier.size(30.dp).clickable(onClick = onQuickAdd).padding(5.dp))
|
||||
Text(
|
||||
L10n.text("ledger.delete"), fontSize = 11.sp, color = androidx.compose.ui.graphics.Color(0xFFC62828),
|
||||
modifier = Modifier.clickable(onClick = onDelete).padding(start = 6.dp),
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
/** Two or more purchases of the same member on one day: choose which record to edit. */
|
||||
private data class DailySelection(val row: LedgerRankRow, val records: List<LedgerRecord>)
|
||||
|
||||
@Composable
|
||||
private fun DailyRecordPicker(
|
||||
row: LedgerRankRow,
|
||||
records: List<LedgerRecord>,
|
||||
member: com.oshicue.keeps.core.LedgerMember?,
|
||||
onSelect: (LedgerRecord) -> Unit,
|
||||
onDismiss: () -> Unit,
|
||||
) {
|
||||
AlertDialog(
|
||||
onDismissRequest = onDismiss,
|
||||
title = { Text(L10n.text("ledger.chooseRecord"), fontWeight = FontWeight.Bold) },
|
||||
text = {
|
||||
Column(Modifier.heightIn(max = 420.dp).verticalScroll(rememberScrollState()),
|
||||
verticalArrangement = Arrangement.spacedBy(10.dp)) {
|
||||
Text(L10n.text("ledger.chooseRecordHint"), fontSize = 12.sp, color = Kit.colors.muted)
|
||||
Row(verticalAlignment = Alignment.CenterVertically) {
|
||||
LedgerAvatar(member, row.color, 45.dp)
|
||||
Spacer(Modifier.width(12.dp))
|
||||
Column(verticalArrangement = Arrangement.spacedBy(4.dp)) {
|
||||
Text(row.name, fontSize = 16.sp, fontWeight = FontWeight.Bold, color = Kit.colors.ink)
|
||||
Text(row.subtitle, fontSize = 12.sp, color = Kit.colors.muted)
|
||||
}
|
||||
}
|
||||
records.forEach { record ->
|
||||
Row(
|
||||
Modifier.fillMaxWidth().clickable { onSelect(record) }.padding(vertical = 8.dp),
|
||||
verticalAlignment = Alignment.CenterVertically,
|
||||
) {
|
||||
Column(Modifier.weight(1f), verticalArrangement = Arrangement.spacedBy(4.dp)) {
|
||||
Text(LedgerPresentation.productName(record.productID, record.productNameSnapshot) +
|
||||
" × " + record.quantity, fontSize = 14.sp, fontWeight = FontWeight.SemiBold,
|
||||
color = Kit.colors.ink)
|
||||
Text(L10n.text("ledger.unitPrice") + " · " +
|
||||
(runCatching { LedgerCurrency.valueOf(record.currency) }.getOrNull()
|
||||
?.let { LedgerPresentation.format(it, record.unitPriceMinor) } ?: ""),
|
||||
fontSize = 12.sp, color = Kit.colors.muted)
|
||||
record.eventNameSnapshot?.let { Text(it, fontSize = 12.sp, color = Kit.colors.muted) }
|
||||
}
|
||||
Text(LedgerPresentation.total(record), fontSize = 13.sp, fontWeight = FontWeight.SemiBold,
|
||||
color = Kit.colors.ink)
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
confirmButton = { TextButton(onClick = onDismiss) { Text(L10n.text("common.cancel")) } },
|
||||
containerColor = Kit.colors.surface,
|
||||
)
|
||||
}
|
||||
@@ -0,0 +1,674 @@
|
||||
package com.oshicue.keeps.ui
|
||||
|
||||
import android.graphics.Bitmap
|
||||
import android.graphics.BitmapFactory
|
||||
import android.util.Base64
|
||||
import androidx.activity.compose.rememberLauncherForActivityResult
|
||||
import androidx.activity.result.PickVisualMediaRequest
|
||||
import androidx.activity.result.contract.ActivityResultContracts
|
||||
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.Spacer
|
||||
import androidx.compose.foundation.layout.fillMaxSize
|
||||
import androidx.compose.foundation.layout.fillMaxWidth
|
||||
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.shape.RoundedCornerShape
|
||||
import androidx.compose.foundation.text.KeyboardOptions
|
||||
import androidx.compose.foundation.verticalScroll
|
||||
import androidx.compose.material.icons.Icons
|
||||
import androidx.compose.material.icons.filled.AddPhotoAlternate
|
||||
import androidx.compose.material.icons.filled.Close
|
||||
import androidx.compose.material.icons.filled.Delete
|
||||
import androidx.compose.material.icons.filled.Star
|
||||
import androidx.compose.material.icons.filled.StarBorder
|
||||
import androidx.compose.material3.AlertDialog
|
||||
import androidx.compose.material3.Icon
|
||||
import androidx.compose.material3.Text
|
||||
import androidx.compose.material3.TextButton
|
||||
import androidx.compose.runtime.Composable
|
||||
import androidx.compose.runtime.getValue
|
||||
import androidx.compose.runtime.mutableStateOf
|
||||
import androidx.compose.runtime.remember
|
||||
import androidx.compose.runtime.rememberCoroutineScope
|
||||
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.graphics.Color
|
||||
import androidx.compose.ui.platform.LocalContext
|
||||
import androidx.compose.ui.text.font.FontWeight
|
||||
import androidx.compose.ui.text.input.KeyboardType
|
||||
import androidx.compose.ui.unit.dp
|
||||
import androidx.compose.ui.unit.sp
|
||||
import androidx.lifecycle.compose.collectAsStateWithLifecycle
|
||||
import com.oshicue.keeps.core.L10n
|
||||
import com.oshicue.keeps.core.LedgerCurrency
|
||||
import com.oshicue.keeps.core.LedgerEvent
|
||||
import com.oshicue.keeps.core.LedgerGroup
|
||||
import com.oshicue.keeps.core.LedgerMember
|
||||
import com.oshicue.keeps.core.LedgerMembership
|
||||
import com.oshicue.keeps.core.LedgerPresentation
|
||||
import com.oshicue.keeps.core.LedgerProduct
|
||||
import com.oshicue.keeps.core.LedgerDates
|
||||
import com.oshicue.keeps.core.activeGroups
|
||||
import com.oshicue.keeps.core.activeMembers
|
||||
import com.oshicue.keeps.core.membersForSelection
|
||||
import kotlinx.coroutines.Dispatchers
|
||||
import kotlinx.coroutines.launch
|
||||
import kotlinx.coroutines.withContext
|
||||
import java.io.ByteArrayOutputStream
|
||||
import java.time.LocalDate
|
||||
import java.time.ZoneId
|
||||
|
||||
private data class PriceDraft(
|
||||
val productID: String,
|
||||
val currency: LedgerCurrency,
|
||||
val text: String,
|
||||
)
|
||||
|
||||
/** Add or edit one person, with their affiliation, photo and per-type prices. */
|
||||
@Composable
|
||||
fun LedgerMemberEditor(
|
||||
store: LedgerStore,
|
||||
membership: LedgerMembership?,
|
||||
onClose: () -> Unit,
|
||||
) {
|
||||
val state by store.state.collectAsStateWithLifecycle()
|
||||
val document = state.document
|
||||
val context = LocalContext.current
|
||||
val scope = rememberCoroutineScope()
|
||||
val existingMember = document.activeMembers.firstOrNull { it.id == membership?.memberID }
|
||||
|
||||
var name by remember { mutableStateOf(existingMember?.name ?: "") }
|
||||
var reuseMember by remember { mutableStateOf(false) }
|
||||
var existingMemberID by remember { mutableStateOf(existingMember?.id ?: "") }
|
||||
var groupID by remember { mutableStateOf(membership?.groupID ?: document.activeGroups.firstOrNull()?.id ?: "") }
|
||||
var color by remember { mutableStateOf(membership?.color ?: "#F23C6B") }
|
||||
var avatar by remember { mutableStateOf(existingMember?.avatarJPEGBase64) }
|
||||
var isFavorite by remember { mutableStateOf(existingMember?.isFavorited ?: false) }
|
||||
var error by remember { mutableStateOf<String?>(null) }
|
||||
var confirmDelete by remember { mutableStateOf(false) }
|
||||
var pickerOpen by remember { mutableStateOf(false) }
|
||||
var loadingPhoto by remember { mutableStateOf(false) }
|
||||
var prices by remember {
|
||||
mutableStateOf(
|
||||
buildList {
|
||||
(membership?.prices ?: emptyList()).forEach { price ->
|
||||
val currency = runCatching { LedgerCurrency.valueOf(price.currency) }.getOrNull() ?: LedgerCurrency.JPY
|
||||
add(PriceDraft(price.productID, currency, currency.priceText(price.unitPriceMinor)))
|
||||
}
|
||||
document.products.forEach { product ->
|
||||
if (none { it.productID == product.id }) add(PriceDraft(product.id, LedgerCurrency.JPY, ""))
|
||||
}
|
||||
},
|
||||
)
|
||||
}
|
||||
|
||||
val canSave = name.isNotBlank() && groupID.isNotEmpty() && (!reuseMember || existingMemberID.isNotEmpty())
|
||||
|
||||
fun selectExistingMember() {
|
||||
val member = document.activeMembers.firstOrNull { it.id == existingMemberID } ?: return
|
||||
name = member.name
|
||||
avatar = member.avatarJPEGBase64
|
||||
isFavorite = member.isFavorited
|
||||
}
|
||||
|
||||
val photoLauncher = rememberLauncherForActivityResult(ActivityResultContracts.PickVisualMedia()) { uri ->
|
||||
if (uri == null) return@rememberLauncherForActivityResult
|
||||
loadingPhoto = true
|
||||
scope.launch {
|
||||
val encoded = withContext(Dispatchers.IO) {
|
||||
runCatching {
|
||||
val bytes = context.contentResolver.openInputStream(uri)?.use { it.readBytes() }
|
||||
?: throw java.io.IOException("The photo could not be read.")
|
||||
// The iOS app rejects photos over 10 MB before downscaling them.
|
||||
if (bytes.size > 10 * 1024 * 1024) throw PhotoTooLarge()
|
||||
val bitmap = BitmapFactory.decodeByteArray(bytes, 0, bytes.size)
|
||||
?: throw java.io.IOException("The photo could not be decoded.")
|
||||
// A 512 px thumbnail stays sharp at 70 pt on a 3x screen, as on iOS.
|
||||
val scale = 512f / maxOf(bitmap.width, bitmap.height).toFloat()
|
||||
val resized = if (scale < 1f) {
|
||||
Bitmap.createScaledBitmap(bitmap, (bitmap.width * scale).toInt().coerceAtLeast(1),
|
||||
(bitmap.height * scale).toInt().coerceAtLeast(1), true)
|
||||
} else bitmap
|
||||
val output = ByteArrayOutputStream()
|
||||
resized.compress(Bitmap.CompressFormat.JPEG, 80, output)
|
||||
Base64.encodeToString(output.toByteArray(), Base64.NO_WRAP)
|
||||
}
|
||||
}
|
||||
encoded.onSuccess { avatar = it }
|
||||
.onFailure {
|
||||
error = if (it is PhotoTooLarge) L10n.text("ledger.member.photoTooLarge")
|
||||
else L10n.text("ledger.member.photoError")
|
||||
}
|
||||
loadingPhoto = false
|
||||
}
|
||||
}
|
||||
|
||||
fun save() {
|
||||
val savedPrices = mutableListOf<com.oshicue.keeps.core.LedgerPrice>()
|
||||
for (row in prices) {
|
||||
if (row.text.isBlank()) continue
|
||||
val amount = row.currency.parsePrice(row.text.replace(",", "."))
|
||||
if (amount == null) {
|
||||
error = L10n.text("ledger.invalidPrice"); return
|
||||
}
|
||||
savedPrices.add(com.oshicue.keeps.core.LedgerPrice(row.productID, row.currency.name, amount))
|
||||
}
|
||||
val memberID = membership?.memberID ?: (if (reuseMember) existingMemberID else java.util.UUID.randomUUID().toString())
|
||||
val value = LedgerMember(memberID, name.trim(), avatarJPEGBase64 = avatar, isFavorite = isFavorite)
|
||||
val affiliation = LedgerMembership(
|
||||
id = membership?.id ?: java.util.UUID.randomUUID().toString(),
|
||||
memberID = memberID, groupID = groupID, color = color, prices = savedPrices,
|
||||
)
|
||||
if (store.saveMember(value, affiliation)) onClose() else error = store.takeError()
|
||||
}
|
||||
|
||||
Column(Modifier.fillMaxSize().background(Kit.colors.background)) {
|
||||
SheetBar(L10n.text(if (membership == null) "ledger.member.add" else "ledger.member.edit"), onClose) {
|
||||
Text(
|
||||
L10n.text("ledger.save"), fontSize = 15.sp, fontWeight = FontWeight.SemiBold,
|
||||
color = if (canSave && !loadingPhoto) Kit.colors.accentText else Kit.colors.muted,
|
||||
modifier = Modifier.clickable(enabled = canSave && !loadingPhoto) { save() }.padding(6.dp),
|
||||
)
|
||||
}
|
||||
Column(
|
||||
Modifier.fillMaxSize().verticalScroll(rememberScrollState()).padding(horizontal = 16.dp).padding(bottom = 30.dp),
|
||||
verticalArrangement = Arrangement.spacedBy(14.dp),
|
||||
) {
|
||||
EditorCard(L10n.text("ledger.member.identity"), L10n.text("ledger.member.identityHint")) {
|
||||
if (membership == null && document.activeMembers.isNotEmpty()) {
|
||||
Row(verticalAlignment = Alignment.CenterVertically) {
|
||||
Box(
|
||||
Modifier
|
||||
.size(22.dp)
|
||||
.clip(RoundedCornerShape(6.dp))
|
||||
.background(if (reuseMember) Kit.colors.accentFill else Kit.colors.surfaceMuted)
|
||||
.clickable {
|
||||
reuseMember = !reuseMember
|
||||
if (reuseMember) {
|
||||
existingMemberID = document.membersForSelectionFirstId()
|
||||
selectExistingMember()
|
||||
} else {
|
||||
existingMemberID = ""; name = ""; avatar = null; isFavorite = false
|
||||
}
|
||||
},
|
||||
contentAlignment = Alignment.Center,
|
||||
) {
|
||||
if (reuseMember) {
|
||||
Text("✓", fontSize = 13.sp, color = Kit.colors.onAccent, fontWeight = FontWeight.Bold)
|
||||
}
|
||||
}
|
||||
Spacer(Modifier.width(10.dp))
|
||||
Text(L10n.text("ledger.member.reuse"), fontSize = 14.sp, color = Kit.colors.ink)
|
||||
}
|
||||
if (reuseMember) {
|
||||
val candidates = document.activeMembers
|
||||
Text(L10n.text("ledger.member.existing"), fontSize = 12.sp, color = Kit.colors.muted)
|
||||
Column(
|
||||
Modifier.fillMaxWidth().clip(RoundedCornerShape(10.dp)).background(Kit.colors.background),
|
||||
) {
|
||||
candidates.forEach { member ->
|
||||
Row(
|
||||
Modifier.fillMaxWidth().clickable {
|
||||
existingMemberID = member.id
|
||||
selectExistingMember()
|
||||
}.padding(horizontal = 12.dp, vertical = 10.dp),
|
||||
verticalAlignment = Alignment.CenterVertically,
|
||||
) {
|
||||
Text(member.name, fontSize = 14.sp, color = Kit.colors.ink, modifier = Modifier.weight(1f))
|
||||
if (member.isFavorited) {
|
||||
Icon(Icons.Filled.Star, contentDescription = null, tint = Kit.colors.accentText,
|
||||
modifier = Modifier.size(13.dp))
|
||||
}
|
||||
if (member.id == existingMemberID) {
|
||||
Icon(Icons.Filled.StarBorder, contentDescription = null,
|
||||
tint = Kit.colors.accentText, modifier = Modifier.size(13.dp))
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
LabeledEditorField(L10n.text("ledger.member.name"), name) { name = it }
|
||||
Row(verticalAlignment = Alignment.CenterVertically) {
|
||||
LedgerAvatar(LedgerMember("preview", name, avatarJPEGBase64 = avatar), color, 70.dp)
|
||||
Spacer(Modifier.width(18.dp))
|
||||
Column(verticalArrangement = Arrangement.spacedBy(10.dp)) {
|
||||
Row(
|
||||
Modifier
|
||||
.clip(RoundedCornerShape(10.dp))
|
||||
.background(Kit.colors.background)
|
||||
.clickable {
|
||||
photoLauncher.launch(PickVisualMediaRequest(ActivityResultContracts.PickVisualMedia.ImageOnly))
|
||||
}
|
||||
.padding(horizontal = 12.dp, vertical = 9.dp),
|
||||
verticalAlignment = Alignment.CenterVertically,
|
||||
) {
|
||||
Icon(Icons.Filled.AddPhotoAlternate, contentDescription = null, tint = Kit.colors.accentText,
|
||||
modifier = Modifier.size(16.dp))
|
||||
Spacer(Modifier.width(6.dp))
|
||||
Text(L10n.text("ledger.member.photo"), fontSize = 13.sp, color = Kit.colors.accentText)
|
||||
}
|
||||
if (avatar != null) {
|
||||
Text(
|
||||
L10n.text("ledger.member.removePhoto"), fontSize = 12.sp,
|
||||
color = Color(0xFFC62828),
|
||||
modifier = Modifier.clickable { avatar = null }.padding(4.dp),
|
||||
)
|
||||
}
|
||||
if (loadingPhoto) Text("…", fontSize = 13.sp, color = Kit.colors.muted)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
EditorCard(null, L10n.text("ledger.member.favoriteHint")) {
|
||||
Row(
|
||||
Modifier.fillMaxWidth().clickable { isFavorite = !isFavorite }.padding(vertical = 4.dp),
|
||||
verticalAlignment = Alignment.CenterVertically,
|
||||
) {
|
||||
Icon(
|
||||
if (isFavorite) Icons.Filled.Star else Icons.Filled.StarBorder,
|
||||
contentDescription = null,
|
||||
tint = if (isFavorite) Kit.colors.accentText else Kit.colors.muted,
|
||||
modifier = Modifier.size(18.dp),
|
||||
)
|
||||
Spacer(Modifier.width(8.dp))
|
||||
Text(L10n.text("ledger.member.favorite"), fontSize = 14.sp, color = Kit.colors.ink)
|
||||
}
|
||||
}
|
||||
|
||||
EditorCard(L10n.text("ledger.member.affiliation"), null) {
|
||||
Text(L10n.text("ledger.group"), fontSize = 12.sp, color = Kit.colors.muted)
|
||||
Column(Modifier.fillMaxWidth().clip(RoundedCornerShape(10.dp)).background(Kit.colors.background)) {
|
||||
document.activeGroups.forEach { group ->
|
||||
Row(
|
||||
Modifier.fillMaxWidth().clickable { groupID = group.id }
|
||||
.padding(horizontal = 12.dp, vertical = 10.dp),
|
||||
verticalAlignment = Alignment.CenterVertically,
|
||||
) {
|
||||
Text(group.name, fontSize = 14.sp, color = Kit.colors.ink, modifier = Modifier.weight(1f))
|
||||
if (group.id == groupID) {
|
||||
Text("✓", fontSize = 14.sp, color = Kit.colors.accentText, fontWeight = FontWeight.Bold)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
ColorSwatchRow(L10n.text("ledger.groupColor"), color) { color = it }
|
||||
}
|
||||
|
||||
EditorCard(L10n.text("ledger.member.prices"), L10n.text("ledger.member.pricesHint")) {
|
||||
prices.forEachIndexed { index, row ->
|
||||
val productName = document.products.firstOrNull { it.id == row.productID }
|
||||
?.let { LedgerPresentation.productName(it.id, it.name) } ?: row.productID
|
||||
Column(verticalArrangement = Arrangement.spacedBy(6.dp)) {
|
||||
Text(productName, fontSize = 13.sp, fontWeight = FontWeight.SemiBold, color = Kit.colors.ink)
|
||||
Row(verticalAlignment = Alignment.CenterVertically) {
|
||||
CurrencyChip(row.currency) { currency ->
|
||||
prices = prices.toMutableList().also {
|
||||
it[index] = row.copy(currency = currency)
|
||||
}
|
||||
}
|
||||
Spacer(Modifier.width(10.dp))
|
||||
EditorTextField(
|
||||
value = row.text,
|
||||
onValueChange = { text ->
|
||||
prices = prices.toMutableList().also { it[index] = row.copy(text = text) }
|
||||
},
|
||||
keyboardType = KeyboardType.Decimal,
|
||||
modifier = Modifier.weight(1f),
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
Text(L10n.text("ledger.product.add"), fontSize = 13.sp, color = Kit.colors.accentText,
|
||||
modifier = Modifier.clickable {
|
||||
val used = prices.map { it.productID }.toSet()
|
||||
document.products.firstOrNull { it.id !in used }?.let { product ->
|
||||
prices = prices + PriceDraft(product.id, LedgerCurrency.JPY, "")
|
||||
}
|
||||
}.padding(4.dp))
|
||||
}
|
||||
|
||||
error?.let { KitErrorBox(it) }
|
||||
|
||||
ProminentButton(L10n.text("ledger.save"), canSave && !loadingPhoto) { save() }
|
||||
|
||||
if (membership != null) {
|
||||
Text(
|
||||
L10n.text("ledger.member.delete"), fontSize = 14.sp, fontWeight = FontWeight.SemiBold,
|
||||
color = Color(0xFFC62828),
|
||||
modifier = Modifier
|
||||
.fillMaxWidth()
|
||||
.clip(RoundedCornerShape(12.dp))
|
||||
.background(Kit.colors.surface)
|
||||
.clickable { confirmDelete = true }
|
||||
.padding(vertical = 13.dp),
|
||||
textAlign = androidx.compose.ui.text.style.TextAlign.Center,
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (confirmDelete) {
|
||||
AlertDialog(
|
||||
onDismissRequest = { confirmDelete = false },
|
||||
title = { Text(L10n.text("ledger.member.deleteTitle"), fontWeight = FontWeight.Bold) },
|
||||
text = { Text(L10n.text("ledger.member.deleteMessage")) },
|
||||
confirmButton = {
|
||||
TextButton(onClick = {
|
||||
membership?.let { item ->
|
||||
if (store.deleteMember(item.memberID)) onClose() else error = store.takeError()
|
||||
}
|
||||
confirmDelete = false
|
||||
}) { Text(L10n.text("ledger.member.delete"), color = Color(0xFFC62828)) }
|
||||
},
|
||||
dismissButton = { TextButton(onClick = { confirmDelete = false }) { Text(L10n.text("common.cancel")) } },
|
||||
containerColor = Kit.colors.surface,
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
private class PhotoTooLarge : Exception()
|
||||
|
||||
private fun com.oshicue.keeps.core.LedgerDocument.membersForSelectionFirstId(): String =
|
||||
this.membersForSelection.firstOrNull()?.id ?: ""
|
||||
|
||||
/** Add or edit one group; deleting archives the group and its affiliations. */
|
||||
@Composable
|
||||
fun LedgerGroupEditor(store: LedgerStore, group: LedgerGroup?, onClose: () -> Unit) {
|
||||
var name by remember { mutableStateOf(group?.name ?: "") }
|
||||
var error by remember { mutableStateOf<String?>(null) }
|
||||
var confirmDelete by remember { mutableStateOf(false) }
|
||||
|
||||
Column(Modifier.fillMaxSize().background(Kit.colors.background)) {
|
||||
SheetBar(L10n.text(if (group == null) "ledger.group.add" else "ledger.group.edit"), onClose) {
|
||||
Text(
|
||||
L10n.text("ledger.save"), fontSize = 15.sp, fontWeight = FontWeight.SemiBold,
|
||||
color = if (name.isNotBlank()) Kit.colors.accentText else Kit.colors.muted,
|
||||
modifier = Modifier.clickable(enabled = name.isNotBlank()) {
|
||||
val value = LedgerGroup(group?.id ?: java.util.UUID.randomUUID().toString(), name.trim())
|
||||
if (store.upsertGroup(value)) onClose() else error = store.takeError()
|
||||
}.padding(6.dp),
|
||||
)
|
||||
}
|
||||
Column(
|
||||
Modifier.fillMaxSize().verticalScroll(rememberScrollState()).padding(horizontal = 16.dp),
|
||||
verticalArrangement = Arrangement.spacedBy(14.dp),
|
||||
) {
|
||||
EditorCard(null, null) {
|
||||
LabeledEditorField(L10n.text("ledger.group.name"), name) { name = it }
|
||||
}
|
||||
error?.let { KitErrorBox(it) }
|
||||
ProminentButton(L10n.text("ledger.save"), name.isNotBlank()) {
|
||||
val value = LedgerGroup(group?.id ?: java.util.UUID.randomUUID().toString(), name.trim())
|
||||
if (store.upsertGroup(value)) onClose() else error = store.takeError()
|
||||
}
|
||||
if (group != null) {
|
||||
Text(
|
||||
L10n.text("ledger.group.delete"), fontSize = 14.sp, fontWeight = FontWeight.SemiBold,
|
||||
color = Color(0xFFC62828),
|
||||
modifier = Modifier
|
||||
.fillMaxWidth()
|
||||
.clip(RoundedCornerShape(12.dp))
|
||||
.background(Kit.colors.surface)
|
||||
.clickable { confirmDelete = true }
|
||||
.padding(vertical = 13.dp),
|
||||
textAlign = androidx.compose.ui.text.style.TextAlign.Center,
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (confirmDelete) {
|
||||
AlertDialog(
|
||||
onDismissRequest = { confirmDelete = false },
|
||||
title = { Text(L10n.text("ledger.group.deleteTitle"), fontWeight = FontWeight.Bold) },
|
||||
text = { Text(L10n.text("ledger.group.deleteMessage")) },
|
||||
confirmButton = {
|
||||
TextButton(onClick = {
|
||||
group?.let { item -> if (store.deleteGroup(item.id)) onClose() else error = store.takeError() }
|
||||
confirmDelete = false
|
||||
}) { Text(L10n.text("ledger.group.delete"), color = Color(0xFFC62828)) }
|
||||
},
|
||||
dismissButton = { TextButton(onClick = { confirmDelete = false }) { Text(L10n.text("common.cancel")) } },
|
||||
containerColor = Kit.colors.surface,
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
/** Add or edit one purchase type. An unchanged default name follows the app language. */
|
||||
@Composable
|
||||
fun LedgerProductEditor(store: LedgerStore, product: LedgerProduct?, onClose: () -> Unit) {
|
||||
var name by remember {
|
||||
mutableStateOf(product?.let { LedgerPresentation.productName(it.id, it.name) } ?: "")
|
||||
}
|
||||
var error by remember { mutableStateOf<String?>(null) }
|
||||
|
||||
fun save() {
|
||||
val edited = name.trim()
|
||||
val saved = if (edited == product?.let { LedgerPresentation.productName(it.id, it.name) }) {
|
||||
product?.name ?: edited
|
||||
} else edited
|
||||
val value = LedgerProduct(product?.id ?: java.util.UUID.randomUUID().toString(), saved)
|
||||
if (store.upsertProduct(value)) onClose() else error = store.takeError()
|
||||
}
|
||||
|
||||
Column(Modifier.fillMaxSize().background(Kit.colors.background)) {
|
||||
SheetBar(L10n.text(if (product == null) "ledger.product.add" else "ledger.product.edit"), onClose) {
|
||||
Text(L10n.text("ledger.save"), fontSize = 15.sp, fontWeight = FontWeight.SemiBold,
|
||||
color = if (name.isNotBlank()) Kit.colors.accentText else Kit.colors.muted,
|
||||
modifier = Modifier.clickable(enabled = name.isNotBlank()) { save() }.padding(6.dp))
|
||||
}
|
||||
Column(
|
||||
Modifier.fillMaxSize().verticalScroll(rememberScrollState()).padding(horizontal = 16.dp),
|
||||
verticalArrangement = Arrangement.spacedBy(14.dp),
|
||||
) {
|
||||
EditorCard(null, null) {
|
||||
LabeledEditorField(L10n.text("ledger.product.name"), name) { name = it }
|
||||
}
|
||||
error?.let { KitErrorBox(it) }
|
||||
ProminentButton(L10n.text("ledger.save"), name.isNotBlank()) { save() }
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/** Add or edit one event with an optional date, city, venue and address. */
|
||||
@Composable
|
||||
fun LedgerEventEditor(store: LedgerStore, event: LedgerEvent?, onClose: () -> Unit) {
|
||||
var name by remember { mutableStateOf(event?.name ?: "") }
|
||||
var hasDate by remember { mutableStateOf(event?.date != null) }
|
||||
var date by remember { mutableStateOf(LedgerPresentation.date(event?.date ?: LedgerDates.string(LocalDate.now()))) }
|
||||
var city by remember { mutableStateOf(event?.city ?: "") }
|
||||
var venue by remember { mutableStateOf(event?.venue ?: "") }
|
||||
var address by remember { mutableStateOf(event?.address ?: "") }
|
||||
var error by remember { mutableStateOf<String?>(null) }
|
||||
var datePickerOpen by remember { mutableStateOf(false) }
|
||||
|
||||
fun optional(text: String): String? = text.trim().takeIf { it.isNotEmpty() }
|
||||
|
||||
fun save() {
|
||||
val value = LedgerEvent(
|
||||
id = event?.id ?: java.util.UUID.randomUUID().toString(),
|
||||
name = name.trim(),
|
||||
date = if (hasDate) LedgerDates.string(date) else null,
|
||||
city = optional(city), venue = optional(venue), address = optional(address),
|
||||
)
|
||||
if (store.upsertEvent(value)) onClose() else error = store.takeError()
|
||||
}
|
||||
|
||||
Column(Modifier.fillMaxSize().background(Kit.colors.background)) {
|
||||
SheetBar(L10n.text(if (event == null) "ledger.event.add" else "ledger.event.edit"), onClose) {
|
||||
Text(L10n.text("ledger.save"), fontSize = 15.sp, fontWeight = FontWeight.SemiBold,
|
||||
color = if (name.isNotBlank()) Kit.colors.accentText else Kit.colors.muted,
|
||||
modifier = Modifier.clickable(enabled = name.isNotBlank()) { save() }.padding(6.dp))
|
||||
}
|
||||
Column(
|
||||
Modifier.fillMaxSize().verticalScroll(rememberScrollState()).padding(horizontal = 16.dp),
|
||||
verticalArrangement = Arrangement.spacedBy(14.dp),
|
||||
) {
|
||||
EditorCard(null, null) {
|
||||
LabeledEditorField(L10n.text("ledger.event.name"), name) { name = it }
|
||||
Row(verticalAlignment = Alignment.CenterVertically) {
|
||||
Text(L10n.text("ledger.event.hasDate"), fontSize = 14.sp, color = Kit.colors.ink,
|
||||
modifier = Modifier.weight(1f))
|
||||
Box(
|
||||
Modifier.size(22.dp).clip(RoundedCornerShape(6.dp))
|
||||
.background(if (hasDate) Kit.colors.accentFill else Kit.colors.surfaceMuted)
|
||||
.clickable { hasDate = !hasDate },
|
||||
contentAlignment = Alignment.Center,
|
||||
) {
|
||||
if (hasDate) Text("✓", fontSize = 13.sp, color = Kit.colors.onAccent, fontWeight = FontWeight.Bold)
|
||||
}
|
||||
}
|
||||
if (hasDate) {
|
||||
Row(
|
||||
Modifier.fillMaxWidth().clickable { datePickerOpen = true }.padding(vertical = 6.dp),
|
||||
verticalAlignment = Alignment.CenterVertically,
|
||||
) {
|
||||
Text(L10n.text("ledger.date"), fontSize = 14.sp, color = Kit.colors.ink)
|
||||
Spacer(Modifier.weight(1f))
|
||||
Text(java.time.format.DateTimeFormatter.ofPattern("yyyy MMM d", L10n.current.locale).format(date),
|
||||
fontSize = 14.sp, color = Kit.colors.muted)
|
||||
}
|
||||
}
|
||||
}
|
||||
EditorCard(L10n.text("ledger.optional"), null) {
|
||||
LabeledEditorField(L10n.text("ledger.city"), city) { city = it }
|
||||
LabeledEditorField(L10n.text("ledger.venue"), venue) { venue = it }
|
||||
LabeledEditorField(L10n.text("ledger.address"), address) { address = it }
|
||||
}
|
||||
error?.let { KitErrorBox(it) }
|
||||
ProminentButton(L10n.text("ledger.save"), name.isNotBlank()) { save() }
|
||||
}
|
||||
}
|
||||
|
||||
if (datePickerOpen) {
|
||||
val pickerState = androidx.compose.material3.rememberDatePickerState(
|
||||
initialSelectedDateMillis = date.atStartOfDay(ZoneId.of("UTC")).toInstant().toEpochMilli(),
|
||||
)
|
||||
androidx.compose.material3.DatePickerDialog(
|
||||
onDismissRequest = { datePickerOpen = false },
|
||||
confirmButton = {
|
||||
TextButton(onClick = {
|
||||
pickerState.selectedDateMillis?.let {
|
||||
date = java.time.Instant.ofEpochMilli(it).atZone(ZoneId.of("UTC")).toLocalDate()
|
||||
}
|
||||
datePickerOpen = false
|
||||
}) { Text(L10n.text("common.done")) }
|
||||
},
|
||||
dismissButton = { TextButton(onClick = { datePickerOpen = false }) { Text(L10n.text("common.cancel")) } },
|
||||
) { androidx.compose.material3.DatePicker(state = pickerState) }
|
||||
}
|
||||
}
|
||||
|
||||
@Composable
|
||||
fun EditorCard(title: String?, footer: String?, content: @Composable () -> Unit) {
|
||||
Column(
|
||||
Modifier.fillMaxWidth().clip(RoundedCornerShape(16.dp)).background(Kit.colors.surface).padding(16.dp),
|
||||
verticalArrangement = Arrangement.spacedBy(10.dp),
|
||||
) {
|
||||
title?.let { Text(it, fontSize = 11.sp, fontWeight = FontWeight.Bold, letterSpacing = 1.1.sp, color = Kit.colors.muted) }
|
||||
content()
|
||||
footer?.let { Text(it, fontSize = 11.sp, color = Kit.colors.muted) }
|
||||
}
|
||||
}
|
||||
|
||||
@Composable
|
||||
fun LabeledEditorField(label: String, value: String, onValueChange: (String) -> Unit) {
|
||||
Row(Modifier.fillMaxWidth(), verticalAlignment = Alignment.CenterVertically) {
|
||||
Text(label, fontSize = 14.sp, color = Kit.colors.ink, modifier = Modifier.width(104.dp))
|
||||
EditorTextField(value, onValueChange, modifier = Modifier.weight(1f))
|
||||
}
|
||||
}
|
||||
|
||||
@Composable
|
||||
fun EditorTextField(
|
||||
value: String,
|
||||
onValueChange: (String) -> Unit,
|
||||
keyboardType: KeyboardType = KeyboardType.Text,
|
||||
modifier: Modifier = Modifier,
|
||||
) {
|
||||
Box(
|
||||
modifier
|
||||
.clip(RoundedCornerShape(9.dp))
|
||||
.background(Kit.colors.background)
|
||||
.padding(horizontal = 10.dp, vertical = 8.dp),
|
||||
) {
|
||||
androidx.compose.foundation.text.BasicTextField(
|
||||
value = value,
|
||||
onValueChange = onValueChange,
|
||||
singleLine = true,
|
||||
textStyle = androidx.compose.ui.text.TextStyle(fontSize = 14.sp, color = Kit.colors.ink),
|
||||
cursorBrush = androidx.compose.ui.graphics.SolidColor(Kit.colors.accentText),
|
||||
keyboardOptions = KeyboardOptions(keyboardType = keyboardType),
|
||||
modifier = Modifier.fillMaxWidth(),
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
@Composable
|
||||
private fun ColorSwatchRow(label: String, color: String, onColorChange: (String) -> Unit) {
|
||||
val swatches = listOf(
|
||||
"#F28AAF", "#9B8CF5", "#66C7A5", "#67B9EF", "#F4A174", "#EECF67", "#C58EC4", "#E789A5", "#20212B", "#8F8F9B",
|
||||
)
|
||||
Column(verticalArrangement = Arrangement.spacedBy(8.dp)) {
|
||||
Row(verticalAlignment = Alignment.CenterVertically) {
|
||||
Text(label, fontSize = 13.sp, color = Kit.colors.ink, modifier = Modifier.weight(1f))
|
||||
Box(Modifier.size(22.dp).clip(CircleShape).background(Kit.parse(color)).border(1.dp, Kit.colors.line, CircleShape))
|
||||
Spacer(Modifier.width(6.dp))
|
||||
Text(color, fontSize = 12.sp, color = Kit.colors.muted)
|
||||
}
|
||||
Row(horizontalArrangement = Arrangement.spacedBy(8.dp)) {
|
||||
swatches.forEach { value ->
|
||||
Box(
|
||||
Modifier.size(26.dp).clip(CircleShape).background(Kit.parse(value))
|
||||
.border(if (value == color) 2.dp else 0.dp, Kit.colors.ink, CircleShape)
|
||||
.clickable { onColorChange(value) },
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Composable
|
||||
private fun CurrencyChip(currency: LedgerCurrency, onSelect: (LedgerCurrency) -> Unit) {
|
||||
var open by remember { mutableStateOf(false) }
|
||||
Text(
|
||||
currency.name, fontSize = 13.sp, fontWeight = FontWeight.SemiBold, color = Kit.colors.ink,
|
||||
modifier = Modifier
|
||||
.clip(RoundedCornerShape(9.dp))
|
||||
.background(Kit.colors.background)
|
||||
.clickable { open = true }
|
||||
.padding(horizontal = 12.dp, vertical = 8.dp),
|
||||
)
|
||||
if (open) {
|
||||
AlertDialog(
|
||||
onDismissRequest = { open = false },
|
||||
title = { Text(L10n.text("ledger.currency"), fontWeight = FontWeight.Bold) },
|
||||
text = {
|
||||
Column {
|
||||
LedgerCurrency.entries.forEach { value ->
|
||||
Text(
|
||||
value.name, fontSize = 14.sp, color = Kit.colors.ink,
|
||||
modifier = Modifier.fillMaxWidth()
|
||||
.clickable { onSelect(value); open = false }
|
||||
.padding(vertical = 10.dp),
|
||||
)
|
||||
}
|
||||
}
|
||||
},
|
||||
confirmButton = { TextButton(onClick = { open = false }) { Text(L10n.text("common.cancel")) } },
|
||||
containerColor = Kit.colors.surface,
|
||||
)
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,380 @@
|
||||
package com.oshicue.keeps.ui
|
||||
|
||||
import androidx.compose.foundation.background
|
||||
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.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.layout.size
|
||||
import androidx.compose.foundation.layout.width
|
||||
import androidx.compose.foundation.rememberScrollState
|
||||
import androidx.compose.foundation.shape.CircleShape
|
||||
import androidx.compose.foundation.shape.RoundedCornerShape
|
||||
import androidx.compose.foundation.verticalScroll
|
||||
import androidx.compose.material.icons.Icons
|
||||
import androidx.compose.material.icons.filled.Add
|
||||
import androidx.compose.material.icons.filled.Check
|
||||
import androidx.compose.material.icons.filled.Edit
|
||||
import androidx.compose.material.icons.filled.ExpandMore
|
||||
import androidx.compose.material.icons.filled.PhotoLibrary
|
||||
import androidx.compose.material.icons.filled.Search
|
||||
import androidx.compose.material.icons.filled.Star
|
||||
import androidx.compose.material.icons.filled.ConfirmationNumber
|
||||
import androidx.compose.material3.AlertDialog
|
||||
import androidx.compose.material3.Icon
|
||||
import androidx.compose.material3.Text
|
||||
import androidx.compose.material3.TextButton
|
||||
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.graphics.Color
|
||||
import androidx.compose.ui.text.font.FontWeight
|
||||
import androidx.compose.ui.text.style.TextOverflow
|
||||
import androidx.compose.ui.unit.dp
|
||||
import androidx.compose.ui.unit.sp
|
||||
import androidx.lifecycle.compose.collectAsStateWithLifecycle
|
||||
import com.oshicue.keeps.core.L10n
|
||||
import com.oshicue.keeps.core.LedgerCurrency
|
||||
import com.oshicue.keeps.core.LedgerDates
|
||||
import com.oshicue.keeps.core.LedgerEvent
|
||||
import com.oshicue.keeps.core.LedgerGroup
|
||||
import com.oshicue.keeps.core.LedgerMembership
|
||||
import com.oshicue.keeps.core.LedgerPresentation
|
||||
import com.oshicue.keeps.core.LedgerProduct
|
||||
import com.oshicue.keeps.core.TextNormalizer
|
||||
import com.oshicue.keeps.core.activeGroups
|
||||
import com.oshicue.keeps.core.activeMembers
|
||||
import com.oshicue.keeps.core.activeMemberships
|
||||
|
||||
private enum class CatalogSection(val key: String) {
|
||||
Members("members"), Products("products"), Events("events")
|
||||
}
|
||||
|
||||
private sealed class CatalogSheet {
|
||||
data class Member(val membership: LedgerMembership?) : CatalogSheet()
|
||||
data class Group(val group: LedgerGroup?) : CatalogSheet()
|
||||
data class Product(val product: LedgerProduct?) : CatalogSheet()
|
||||
data class Event(val event: LedgerEvent?) : CatalogSheet()
|
||||
}
|
||||
|
||||
/** The 成员与类型 tab: groups and their members, then purchase types and events. */
|
||||
@Composable
|
||||
fun LedgerCatalogScreen(store: LedgerStore) {
|
||||
val state by store.state.collectAsStateWithLifecycle()
|
||||
val document = state.document
|
||||
var section by remember { mutableStateOf(CatalogSection.Members) }
|
||||
var search by remember { mutableStateOf("") }
|
||||
var sheet by remember { mutableStateOf<CatalogSheet?>(null) }
|
||||
var addMenuOpen by remember { mutableStateOf(false) }
|
||||
|
||||
fun contains(value: String): Boolean =
|
||||
search.isBlank() || TextNormalizer.contains(value, search)
|
||||
|
||||
fun memberships(group: LedgerGroup): List<LedgerMembership> {
|
||||
return document.activeMemberships.filter { affiliation ->
|
||||
if (affiliation.groupID != group.id) return@filter false
|
||||
val memberName = document.activeMembers.firstOrNull { it.id == affiliation.memberID }?.name ?: ""
|
||||
contains(group.name) || contains(memberName)
|
||||
}.sortedBy { affiliation ->
|
||||
document.activeMembers.firstOrNull { it.id == affiliation.memberID }?.name ?: ""
|
||||
}
|
||||
}
|
||||
|
||||
Column(Modifier.fillMaxSize().background(Kit.colors.background)) {
|
||||
Row(
|
||||
Modifier.fillMaxWidth().padding(horizontal = 20.dp).padding(bottom = 10.dp),
|
||||
verticalAlignment = Alignment.CenterVertically,
|
||||
) {
|
||||
Text(L10n.text("ledger.catalog"), style = KitTitleStyle, color = Kit.colors.ink, modifier = Modifier.weight(1f))
|
||||
Box(
|
||||
Modifier
|
||||
.size(38.dp)
|
||||
.clip(CircleShape)
|
||||
.background(Kit.colors.accent.copy(alpha = 0.1f))
|
||||
.clickable { addMenuOpen = !addMenuOpen },
|
||||
contentAlignment = Alignment.Center,
|
||||
) {
|
||||
Icon(Icons.Filled.Add, contentDescription = L10n.text("ledger.catalog.add"),
|
||||
tint = Kit.colors.accentText, modifier = Modifier.size(20.dp))
|
||||
}
|
||||
}
|
||||
|
||||
Column(
|
||||
Modifier.fillMaxSize().verticalScroll(rememberScrollState()).padding(horizontal = 20.dp).padding(bottom = 35.dp),
|
||||
verticalArrangement = Arrangement.spacedBy(16.dp),
|
||||
) {
|
||||
SectionPicker(section) { section = it }
|
||||
|
||||
Row(
|
||||
Modifier
|
||||
.fillMaxWidth()
|
||||
.clip(RoundedCornerShape(16.dp))
|
||||
.background(Kit.colors.surface)
|
||||
.padding(14.dp),
|
||||
verticalAlignment = Alignment.CenterVertically,
|
||||
) {
|
||||
Icon(Icons.Filled.Search, contentDescription = null, tint = Kit.colors.muted, modifier = Modifier.size(17.dp))
|
||||
Spacer(Modifier.width(10.dp))
|
||||
Box(Modifier.weight(1f)) {
|
||||
if (search.isEmpty()) Text(L10n.text("ledger.catalog.search"), fontSize = 14.sp, color = Kit.colors.muted)
|
||||
androidx.compose.foundation.text.BasicTextField(
|
||||
value = search,
|
||||
onValueChange = { search = it },
|
||||
singleLine = true,
|
||||
textStyle = androidx.compose.ui.text.TextStyle(fontSize = 14.sp, color = Kit.colors.ink),
|
||||
cursorBrush = androidx.compose.ui.graphics.SolidColor(Kit.colors.accentText),
|
||||
modifier = Modifier.fillMaxWidth(),
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
when (section) {
|
||||
CatalogSection.Members -> {
|
||||
Text(
|
||||
L10n.format("ledger.catalog.memberCount",
|
||||
document.activeMemberships.map { it.memberID }.toSet().size),
|
||||
fontSize = 13.sp, color = Kit.colors.muted,
|
||||
)
|
||||
val groups = document.activeGroups
|
||||
.filter { group -> contains(group.name) || memberships(group).isNotEmpty() }
|
||||
.sortedBy { it.name }
|
||||
if (groups.isEmpty()) {
|
||||
EmptyState("ledger.catalog.emptyMembers")
|
||||
}
|
||||
groups.forEach { group ->
|
||||
GroupCard(
|
||||
document = document,
|
||||
group = group,
|
||||
memberships = memberships(group),
|
||||
onEditGroup = { sheet = CatalogSheet.Group(group) },
|
||||
onEditMember = { sheet = CatalogSheet.Member(it) },
|
||||
)
|
||||
}
|
||||
ProminentButton(L10n.text("ledger.member.add")) { sheet = CatalogSheet.Member(null) }
|
||||
}
|
||||
|
||||
CatalogSection.Products -> {
|
||||
document.products.filter { contains(LedgerPresentation.productName(it.id, it.name)) }
|
||||
.forEach { product ->
|
||||
Row(
|
||||
Modifier
|
||||
.fillMaxWidth()
|
||||
.clip(RoundedCornerShape(16.dp))
|
||||
.background(Kit.colors.surface)
|
||||
.clickable { sheet = CatalogSheet.Product(product) }
|
||||
.padding(18.dp),
|
||||
verticalAlignment = Alignment.CenterVertically,
|
||||
) {
|
||||
Icon(Icons.Filled.PhotoLibrary, contentDescription = null, tint = Kit.colors.accentText,
|
||||
modifier = Modifier.size(18.dp))
|
||||
Spacer(Modifier.width(10.dp))
|
||||
Text(LedgerPresentation.productName(product.id, product.name), fontSize = 14.sp,
|
||||
color = Kit.colors.ink, modifier = Modifier.weight(1f))
|
||||
Icon(Icons.Filled.Edit, contentDescription = null, tint = Kit.colors.muted,
|
||||
modifier = Modifier.size(16.dp))
|
||||
}
|
||||
}
|
||||
ProminentButton(L10n.text("ledger.product.add")) { sheet = CatalogSheet.Product(null) }
|
||||
}
|
||||
|
||||
CatalogSection.Events -> {
|
||||
if (document.events.isEmpty()) EmptyState("ledger.catalog.emptyEvents")
|
||||
document.events.filter {
|
||||
contains(listOf(it.name, it.city ?: "", it.venue ?: "").joinToString(" "))
|
||||
}.forEach { event ->
|
||||
Row(
|
||||
Modifier
|
||||
.fillMaxWidth()
|
||||
.clip(RoundedCornerShape(16.dp))
|
||||
.background(Kit.colors.surface)
|
||||
.clickable { sheet = CatalogSheet.Event(event) }
|
||||
.padding(18.dp),
|
||||
verticalAlignment = Alignment.CenterVertically,
|
||||
) {
|
||||
Icon(Icons.Filled.ConfirmationNumber, contentDescription = null, tint = Kit.colors.accentText,
|
||||
modifier = Modifier.size(18.dp))
|
||||
Spacer(Modifier.width(12.dp))
|
||||
Column(Modifier.weight(1f), verticalArrangement = Arrangement.spacedBy(4.dp)) {
|
||||
Text(event.name, fontSize = 15.sp, fontWeight = FontWeight.Bold, color = Kit.colors.ink)
|
||||
val detail = listOfNotNull(event.date, event.city, event.venue).joinToString(" · ")
|
||||
if (detail.isNotEmpty()) Text(detail, fontSize = 12.sp, color = Kit.colors.muted)
|
||||
}
|
||||
Icon(Icons.Filled.Edit, contentDescription = null, tint = Kit.colors.muted,
|
||||
modifier = Modifier.size(16.dp))
|
||||
}
|
||||
}
|
||||
ProminentButton(L10n.text("ledger.event.add")) { sheet = CatalogSheet.Event(null) }
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (addMenuOpen) {
|
||||
AlertDialog(
|
||||
onDismissRequest = { addMenuOpen = false },
|
||||
title = { Text(L10n.text("ledger.catalog.add"), fontWeight = FontWeight.Bold) },
|
||||
text = {
|
||||
Column {
|
||||
listOf(
|
||||
"ledger.member.add" to { CatalogSheet.Member(null) },
|
||||
"ledger.group.add" to { CatalogSheet.Group(null) },
|
||||
"ledger.product.add" to { CatalogSheet.Product(null) },
|
||||
"ledger.event.add" to { CatalogSheet.Event(null) },
|
||||
).forEach { (key, make) ->
|
||||
Text(
|
||||
L10n.text(key), fontSize = 15.sp, color = Kit.colors.ink,
|
||||
modifier = Modifier
|
||||
.fillMaxWidth()
|
||||
.clickable { sheet = make(); addMenuOpen = false }
|
||||
.padding(vertical = 13.dp),
|
||||
)
|
||||
}
|
||||
}
|
||||
},
|
||||
confirmButton = {
|
||||
TextButton(onClick = { addMenuOpen = false }) { Text(L10n.text("common.cancel")) }
|
||||
},
|
||||
containerColor = Kit.colors.surface,
|
||||
)
|
||||
}
|
||||
|
||||
when (val current = sheet) {
|
||||
is CatalogSheet.Member -> LedgerMemberEditor(store, current.membership) { sheet = null }
|
||||
is CatalogSheet.Group -> LedgerGroupEditor(store, current.group) { sheet = null }
|
||||
is CatalogSheet.Product -> LedgerProductEditor(store, current.product) { sheet = null }
|
||||
is CatalogSheet.Event -> LedgerEventEditor(store, current.event) { sheet = null }
|
||||
null -> Unit
|
||||
}
|
||||
}
|
||||
|
||||
@Composable
|
||||
private fun SectionPicker(section: CatalogSection, onSelect: (CatalogSection) -> Unit) {
|
||||
Row(
|
||||
Modifier.fillMaxWidth().clip(RoundedCornerShape(12.dp)).background(Kit.colors.surfaceMuted).padding(4.dp),
|
||||
horizontalArrangement = Arrangement.spacedBy(4.dp),
|
||||
) {
|
||||
CatalogSection.entries.forEach { value ->
|
||||
val active = value == section
|
||||
Text(
|
||||
L10n.text("ledger.catalog." + value.key),
|
||||
fontSize = 12.sp,
|
||||
fontWeight = FontWeight.SemiBold,
|
||||
color = if (active) Kit.colors.onAccent else Kit.colors.ink,
|
||||
textAlign = androidx.compose.ui.text.style.TextAlign.Center,
|
||||
modifier = Modifier
|
||||
.weight(1f)
|
||||
.clip(RoundedCornerShape(9.dp))
|
||||
.background(if (active) Kit.colors.accentFill else Color.Transparent)
|
||||
.clickable { onSelect(value) }
|
||||
.padding(vertical = 8.dp),
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Composable
|
||||
private fun GroupCard(
|
||||
document: com.oshicue.keeps.core.LedgerDocument,
|
||||
group: LedgerGroup,
|
||||
memberships: List<LedgerMembership>,
|
||||
onEditGroup: () -> Unit,
|
||||
onEditMember: (LedgerMembership) -> Unit,
|
||||
) {
|
||||
var expanded by remember { mutableStateOf(true) }
|
||||
Column(
|
||||
Modifier.fillMaxWidth().clip(RoundedCornerShape(16.dp)).background(Kit.colors.surface).padding(16.dp),
|
||||
) {
|
||||
Row(verticalAlignment = Alignment.CenterVertically) {
|
||||
Row(
|
||||
Modifier.weight(1f).clickable { expanded = !expanded },
|
||||
verticalAlignment = Alignment.CenterVertically,
|
||||
) {
|
||||
Text(group.name, fontSize = 15.sp, fontWeight = FontWeight.Bold, color = Kit.colors.ink)
|
||||
Spacer(Modifier.width(8.dp))
|
||||
Text(
|
||||
memberships.size.toString(),
|
||||
fontSize = 11.sp, fontWeight = FontWeight.Bold, color = Kit.colors.accentText,
|
||||
modifier = Modifier
|
||||
.clip(RoundedCornerShape(6.dp))
|
||||
.background(Kit.colors.accent.copy(alpha = 0.1f))
|
||||
.padding(horizontal = 9.dp, vertical = 5.dp),
|
||||
)
|
||||
Spacer(Modifier.width(6.dp))
|
||||
Icon(Icons.Filled.ExpandMore, contentDescription = null, tint = Kit.colors.muted,
|
||||
modifier = Modifier.size(16.dp))
|
||||
}
|
||||
Box(
|
||||
Modifier
|
||||
.size(36.dp)
|
||||
.clip(CircleShape)
|
||||
.background(Kit.colors.accent.copy(alpha = 0.1f))
|
||||
.clickable(onClick = onEditGroup),
|
||||
contentAlignment = Alignment.Center,
|
||||
) {
|
||||
Icon(Icons.Filled.Edit, contentDescription = L10n.text("ledger.group.edit") + ": " + group.name,
|
||||
tint = Kit.colors.accentText, modifier = Modifier.size(16.dp))
|
||||
}
|
||||
}
|
||||
if (expanded) {
|
||||
Column(Modifier.padding(top = 12.dp), verticalArrangement = Arrangement.spacedBy(10.dp)) {
|
||||
if (memberships.isEmpty()) {
|
||||
Text(L10n.text("ledger.catalog.noGroupMembers"), fontSize = 13.sp, color = Kit.colors.muted)
|
||||
}
|
||||
memberships.forEach { affiliation ->
|
||||
val member = document.activeMembers.firstOrNull { it.id == affiliation.memberID } ?: return@forEach
|
||||
Row(
|
||||
Modifier.fillMaxWidth().clickable { onEditMember(affiliation) }.padding(vertical = 5.dp),
|
||||
verticalAlignment = Alignment.CenterVertically,
|
||||
) {
|
||||
LedgerAvatar(member, affiliation.color, 46.dp)
|
||||
Spacer(Modifier.width(12.dp))
|
||||
Column(Modifier.weight(1f), verticalArrangement = Arrangement.spacedBy(4.dp)) {
|
||||
Row(verticalAlignment = Alignment.CenterVertically) {
|
||||
Text(member.name, fontSize = 14.sp, fontWeight = FontWeight.SemiBold, color = Kit.colors.ink)
|
||||
if (member.isFavorited) {
|
||||
Spacer(Modifier.width(5.dp))
|
||||
Icon(Icons.Filled.Star, contentDescription = L10n.text("ledger.member.favorite"),
|
||||
tint = Kit.colors.accentText, modifier = Modifier.size(12.dp))
|
||||
}
|
||||
}
|
||||
if (document.activeMemberships.count { it.memberID == member.id } > 1) {
|
||||
Text(L10n.text("ledger.member.shared"), fontSize = 12.sp, color = Kit.colors.muted)
|
||||
}
|
||||
affiliation.prices.firstOrNull()?.let { price ->
|
||||
runCatching { LedgerCurrency.valueOf(price.currency) }.getOrNull()?.let { currency ->
|
||||
Text(LedgerPresentation.format(currency, price.unitPriceMinor),
|
||||
fontSize = 12.sp, color = Kit.colors.muted)
|
||||
}
|
||||
}
|
||||
}
|
||||
Icon(Icons.Filled.Edit, contentDescription = null, tint = Kit.colors.accentText,
|
||||
modifier = Modifier.size(16.dp))
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Composable
|
||||
private fun EmptyState(key: String) {
|
||||
Column(
|
||||
Modifier.fillMaxWidth().padding(28.dp),
|
||||
horizontalAlignment = Alignment.CenterHorizontally,
|
||||
verticalArrangement = Arrangement.spacedBy(10.dp),
|
||||
) {
|
||||
Text(L10n.text(key), fontSize = 13.sp, color = Kit.colors.muted,
|
||||
textAlign = androidx.compose.ui.text.style.TextAlign.Center)
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,713 @@
|
||||
package com.oshicue.keeps.ui
|
||||
|
||||
import androidx.compose.foundation.background
|
||||
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.Spacer
|
||||
import androidx.compose.foundation.layout.fillMaxSize
|
||||
import androidx.compose.foundation.layout.fillMaxWidth
|
||||
import androidx.compose.foundation.layout.heightIn
|
||||
import androidx.compose.foundation.layout.padding
|
||||
import androidx.compose.foundation.layout.size
|
||||
import androidx.compose.foundation.layout.width
|
||||
import androidx.compose.foundation.lazy.LazyColumn
|
||||
import androidx.compose.foundation.lazy.items
|
||||
import androidx.compose.foundation.rememberScrollState
|
||||
import androidx.compose.foundation.shape.RoundedCornerShape
|
||||
import androidx.compose.foundation.verticalScroll
|
||||
import androidx.compose.material.icons.Icons
|
||||
import androidx.compose.material.icons.filled.Archive
|
||||
import androidx.compose.material.icons.filled.Check
|
||||
import androidx.compose.material.icons.filled.FileOpen
|
||||
import androidx.compose.material.icons.filled.Close
|
||||
import androidx.compose.material.icons.filled.Delete
|
||||
import androidx.compose.material.icons.filled.Edit
|
||||
import androidx.compose.material.icons.filled.RadioButtonUnchecked
|
||||
import androidx.compose.material3.AlertDialog
|
||||
import androidx.compose.material3.Icon
|
||||
import androidx.compose.material3.Text
|
||||
import androidx.compose.material3.TextButton
|
||||
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.graphics.Color
|
||||
import androidx.compose.ui.platform.LocalContext
|
||||
import androidx.compose.ui.text.font.FontWeight
|
||||
import androidx.compose.ui.unit.dp
|
||||
import androidx.compose.ui.unit.sp
|
||||
import androidx.lifecycle.compose.collectAsStateWithLifecycle
|
||||
import com.oshicue.keeps.core.KitPresentation
|
||||
import com.oshicue.keeps.core.L10n
|
||||
import com.oshicue.keeps.core.LedgerCurrency
|
||||
import com.oshicue.keeps.core.LedgerDates
|
||||
import com.oshicue.keeps.core.LedgerDocument
|
||||
import com.oshicue.keeps.core.LedgerImporter
|
||||
import com.oshicue.keeps.core.LedgerPresentation
|
||||
import com.oshicue.keeps.core.LedgerPriceSuggestions
|
||||
import com.oshicue.keeps.core.LedgerRecord
|
||||
import com.oshicue.keeps.core.LedgerRecordDeletion
|
||||
import com.oshicue.keeps.core.LedgerRecordFilter
|
||||
import com.oshicue.keeps.core.TextNormalizer
|
||||
import com.oshicue.keeps.core.activeGroups
|
||||
import com.oshicue.keeps.core.activeMembers
|
||||
import kotlinx.coroutines.Dispatchers
|
||||
import kotlinx.coroutines.launch
|
||||
import kotlinx.coroutines.withContext
|
||||
import java.time.LocalDate
|
||||
|
||||
/** The ledger management sheet: record cleanup, import and backup, chosen by a segmented control. */
|
||||
@Composable
|
||||
fun LedgerManagementScreen(store: LedgerStore, onClose: () -> Unit) {
|
||||
var section by remember { mutableStateOf(0) }
|
||||
Column(Modifier.fillMaxSize().background(Kit.colors.background)) {
|
||||
SheetBar(L10n.text("ledger.management"), onClose)
|
||||
Row(Modifier.padding(horizontal = 20.dp).padding(bottom = 12.dp)) {
|
||||
SegmentedControl(
|
||||
listOf(
|
||||
L10n.text("management.records") to 0,
|
||||
L10n.text("ledger.import") to 1,
|
||||
L10n.text("management.backup") to 2,
|
||||
),
|
||||
section,
|
||||
) { section = it }
|
||||
}
|
||||
when (section) {
|
||||
0 -> LedgerRecordManagement(store)
|
||||
1 -> LedgerImportPanel(store, onClose)
|
||||
else -> LedgerBackupPanel(store)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Composable
|
||||
private fun LedgerRecordManagement(store: LedgerStore) {
|
||||
val state by store.state.collectAsStateWithLifecycle()
|
||||
val document = state.document
|
||||
var search by remember { mutableStateOf("") }
|
||||
var showFilters by remember { mutableStateOf(false) }
|
||||
var useDateRange by remember { mutableStateOf(false) }
|
||||
var startDate by remember { mutableStateOf(LocalDate.now()) }
|
||||
var endDate by remember { mutableStateOf(LocalDate.now()) }
|
||||
var memberID by remember { mutableStateOf("") }
|
||||
var groupID by remember { mutableStateOf("") }
|
||||
var productID by remember { mutableStateOf("") }
|
||||
var currency by remember { mutableStateOf("") }
|
||||
var eventSelection by remember { mutableStateOf("") }
|
||||
var requiresNoEvent by remember { mutableStateOf(false) }
|
||||
var selectedIDs by remember { mutableStateOf<Set<String>>(emptySet()) }
|
||||
var pendingDeletion by remember { mutableStateOf<LedgerRecordDeletion?>(null) }
|
||||
var deletingAll by remember { mutableStateOf(false) }
|
||||
var editRecord by remember { mutableStateOf<LedgerRecord?>(null) }
|
||||
var error by remember { mutableStateOf<String?>(null) }
|
||||
var menu by remember { mutableStateOf<String?>(null) }
|
||||
|
||||
val filter = LedgerRecordFilter(
|
||||
startDate = if (useDateRange) LedgerDates.string(startDate) else null,
|
||||
endDate = if (useDateRange) LedgerDates.string(endDate) else null,
|
||||
memberID = memberID.takeIf { it.isNotEmpty() },
|
||||
groupID = groupID.takeIf { it.isNotEmpty() },
|
||||
productID = productID.takeIf { it.isNotEmpty() },
|
||||
currency = currency.takeIf { it.isNotEmpty() },
|
||||
eventID = eventSelection.takeIf { it.isNotEmpty() && !requiresNoEvent },
|
||||
requiresNoEvent = requiresNoEvent,
|
||||
query = search,
|
||||
)
|
||||
val records = remember(filter, document.records) {
|
||||
filter.matching(document.records).sortedWith(compareByDescending<LedgerRecord> { it.date }.thenBy { it.id })
|
||||
}
|
||||
|
||||
fun prepareDeletion(all: Boolean) {
|
||||
runCatching {
|
||||
val ids = if (all) document.records.map { it.id }.toSet() else selectedIDs
|
||||
val deletion = LedgerRecordDeletion(document.records, ids)
|
||||
if (deletion.recordCount > 0) {
|
||||
deletingAll = all
|
||||
pendingDeletion = deletion
|
||||
}
|
||||
}.onFailure { error = KitPresentation.error(it) }
|
||||
}
|
||||
|
||||
LazyColumn(
|
||||
Modifier.fillMaxSize().padding(horizontal = 20.dp),
|
||||
verticalArrangement = Arrangement.spacedBy(10.dp),
|
||||
) {
|
||||
item {
|
||||
Row(
|
||||
Modifier.fillMaxWidth().clip(RoundedCornerShape(14.dp)).background(Kit.colors.surface).padding(13.dp),
|
||||
verticalAlignment = Alignment.CenterVertically,
|
||||
) {
|
||||
EditorTextField(search, { search = it }, modifier = Modifier.weight(1f))
|
||||
}
|
||||
}
|
||||
item {
|
||||
Text(
|
||||
if (showFilters) "▲ " + L10n.text("management.filters") else "▼ " + L10n.text("management.filters"),
|
||||
fontSize = 13.sp, fontWeight = FontWeight.SemiBold, color = Kit.colors.accentText,
|
||||
modifier = Modifier.clickable { showFilters = !showFilters }.padding(vertical = 6.dp),
|
||||
)
|
||||
}
|
||||
if (showFilters) {
|
||||
item {
|
||||
Column(
|
||||
Modifier.fillMaxWidth().clip(RoundedCornerShape(16.dp)).background(Kit.colors.surface).padding(16.dp),
|
||||
verticalArrangement = Arrangement.spacedBy(10.dp),
|
||||
) {
|
||||
Row(verticalAlignment = Alignment.CenterVertically) {
|
||||
Text(L10n.text("management.dateRange"), fontSize = 14.sp, color = Kit.colors.ink,
|
||||
modifier = Modifier.weight(1f))
|
||||
CheckBox(useDateRange) { useDateRange = it }
|
||||
}
|
||||
if (useDateRange) {
|
||||
DateLine(L10n.text("management.startDate"), startDate) { startDate = it }
|
||||
DateLine(L10n.text("management.endDate"), endDate) { endDate = it }
|
||||
if (!filter.hasValidDateRange) {
|
||||
Text(L10n.text("management.invalidDateRange"), fontSize = 11.sp, color = Color(0xFFC62828))
|
||||
}
|
||||
}
|
||||
FilterLine(L10n.text("ledger.member"),
|
||||
if (memberID.isEmpty()) L10n.text("management.all")
|
||||
else document.members.firstOrNull { it.id == memberID }?.name ?: "") { menu = "member" }
|
||||
FilterLine(L10n.text("ledger.group"),
|
||||
if (groupID.isEmpty()) L10n.text("management.all")
|
||||
else document.groups.firstOrNull { it.id == groupID }?.name ?: "") { menu = "group" }
|
||||
FilterLine(L10n.text("ledger.type"),
|
||||
if (productID.isEmpty()) L10n.text("management.all")
|
||||
else document.products.firstOrNull { it.id == productID }
|
||||
?.let { LedgerPresentation.productName(it.id, it.name) } ?: "") { menu = "product" }
|
||||
FilterLine(L10n.text("ledger.currency"),
|
||||
if (currency.isEmpty()) L10n.text("management.all") else currency) { menu = "currency" }
|
||||
FilterLine(L10n.text("ledger.event"),
|
||||
when {
|
||||
requiresNoEvent -> L10n.text("ledger.noEvent")
|
||||
eventSelection.isEmpty() -> L10n.text("management.all")
|
||||
else -> document.events.firstOrNull { it.id == eventSelection }?.name ?: ""
|
||||
}) { menu = "event" }
|
||||
}
|
||||
}
|
||||
}
|
||||
item {
|
||||
Row(Modifier.fillMaxWidth(), verticalAlignment = Alignment.CenterVertically) {
|
||||
Text(L10n.text("management.selectFiltered"), fontSize = 13.sp, color = Kit.colors.accentText,
|
||||
modifier = Modifier.clickable(enabled = records.isNotEmpty()) {
|
||||
selectedIDs = records.map { it.id }.toSet()
|
||||
}.padding(6.dp))
|
||||
Spacer(Modifier.width(14.dp))
|
||||
Text(L10n.text("management.clearSelection"), fontSize = 13.sp, color = Kit.colors.accentText,
|
||||
modifier = Modifier.clickable(enabled = selectedIDs.isNotEmpty()) { selectedIDs = emptySet() }
|
||||
.padding(6.dp))
|
||||
Spacer(Modifier.weight(1f))
|
||||
Text(L10n.format("management.selectedCount", selectedIDs.size), fontSize = 11.sp, color = Kit.colors.muted)
|
||||
}
|
||||
}
|
||||
item {
|
||||
Text(L10n.format("management.resultCount", records.size), fontSize = 11.sp, color = Kit.colors.muted)
|
||||
}
|
||||
if (records.isEmpty()) {
|
||||
item { Text(L10n.text("management.empty"), fontSize = 13.sp, color = Kit.colors.muted) }
|
||||
}
|
||||
items(records, key = { it.id }) { record ->
|
||||
Row(
|
||||
Modifier
|
||||
.fillMaxWidth()
|
||||
.clip(RoundedCornerShape(12.dp))
|
||||
.background(Kit.colors.surface)
|
||||
.padding(12.dp),
|
||||
verticalAlignment = Alignment.CenterVertically,
|
||||
) {
|
||||
Icon(
|
||||
if (record.id in selectedIDs) Icons.Filled.Check else Icons.Filled.RadioButtonUnchecked,
|
||||
contentDescription = null,
|
||||
tint = if (record.id in selectedIDs) Kit.colors.accentText else Kit.colors.muted,
|
||||
modifier = Modifier.size(19.dp),
|
||||
)
|
||||
Spacer(Modifier.width(10.dp))
|
||||
Column(
|
||||
Modifier.weight(1f).clickable {
|
||||
selectedIDs = if (record.id in selectedIDs) selectedIDs - record.id else selectedIDs + record.id
|
||||
}.padding(vertical = 4.dp),
|
||||
verticalArrangement = Arrangement.spacedBy(4.dp),
|
||||
) {
|
||||
Text(record.memberNameSnapshot + " · " + record.groupNameSnapshot,
|
||||
fontSize = 13.sp, fontWeight = FontWeight.SemiBold, color = Kit.colors.ink)
|
||||
Text(record.date + " · " + LedgerPresentation.productName(record.productID, record.productNameSnapshot)
|
||||
+ " × " + record.quantity, fontSize = 12.sp, color = Kit.colors.muted)
|
||||
record.eventNameSnapshot?.let { Text(it, fontSize = 11.sp, color = Kit.colors.muted) }
|
||||
record.note?.takeIf { it.isNotEmpty() }?.let { Text(it, fontSize = 11.sp, color = Kit.colors.muted) }
|
||||
}
|
||||
Text(LedgerPresentation.money(mapOf(record.currency to (record.totalMinor ?: 0))),
|
||||
fontSize = 11.sp, color = Kit.colors.ink)
|
||||
Spacer(Modifier.width(8.dp))
|
||||
Icon(Icons.Filled.Edit, contentDescription = L10n.text("ledger.editRecord"),
|
||||
tint = Kit.colors.accentText,
|
||||
modifier = Modifier.size(34.dp).clickable { editRecord = record }.padding(8.dp))
|
||||
}
|
||||
}
|
||||
item {
|
||||
ProminentButton(
|
||||
L10n.format("management.deleteSelected", selectedIDs.size),
|
||||
enabled = selectedIDs.isNotEmpty(),
|
||||
) { prepareDeletion(false) }
|
||||
}
|
||||
item {
|
||||
Text(L10n.text("management.clearAll"), fontSize = 13.sp, fontWeight = FontWeight.SemiBold,
|
||||
color = Color(0xFFC62828),
|
||||
modifier = Modifier.fillMaxWidth().clickable(enabled = document.records.isNotEmpty()) {
|
||||
prepareDeletion(true)
|
||||
}.padding(vertical = 12.dp))
|
||||
}
|
||||
item { Text(L10n.text("management.clearAllHint"), fontSize = 11.sp, color = Kit.colors.muted) }
|
||||
item {
|
||||
Text(L10n.text("management.catalog"), fontSize = 14.sp, color = Kit.colors.accentText,
|
||||
modifier = Modifier.clickable { menu = "catalog" }.padding(vertical = 10.dp))
|
||||
Spacer(Modifier.size(20.dp))
|
||||
}
|
||||
}
|
||||
|
||||
pendingDeletion?.let { deletion ->
|
||||
AlertDialog(
|
||||
onDismissRequest = { pendingDeletion = null },
|
||||
title = {
|
||||
Text(L10n.text(if (deletingAll) "ledger.management.clearTitle" else "ledger.management.deleteTitle"),
|
||||
fontWeight = FontWeight.Bold)
|
||||
},
|
||||
text = {
|
||||
Text(
|
||||
L10n.format("ledger.management.deleteSummary", deletion.recordCount, deletion.quantity.toString()) +
|
||||
"\n" + LedgerPresentation.money(deletion.amountsByCurrency) +
|
||||
"\n\n" + L10n.text("ledger.management.deleteImpact"),
|
||||
)
|
||||
},
|
||||
confirmButton = {
|
||||
TextButton(onClick = {
|
||||
if (store.deleteRecords(deletion.recordIDs)) {
|
||||
selectedIDs = selectedIDs - deletion.recordIDs
|
||||
} else {
|
||||
error = store.takeError()
|
||||
}
|
||||
pendingDeletion = null
|
||||
}) {
|
||||
Text(L10n.text(if (deletingAll) "management.clearAll" else "management.deleteSelected"),
|
||||
color = Color(0xFFC62828))
|
||||
}
|
||||
},
|
||||
dismissButton = { TextButton(onClick = { pendingDeletion = null }) { Text(L10n.text("common.cancel")) } },
|
||||
containerColor = Kit.colors.surface,
|
||||
)
|
||||
}
|
||||
|
||||
error?.let { message ->
|
||||
AlertDialog(
|
||||
onDismissRequest = { error = null },
|
||||
title = { Text(L10n.text("settings.storageError")) },
|
||||
text = { Text(message) },
|
||||
confirmButton = { TextButton(onClick = { error = null }) { Text(L10n.text("common.close")) } },
|
||||
containerColor = Kit.colors.surface,
|
||||
)
|
||||
}
|
||||
|
||||
editRecord?.let { record ->
|
||||
LedgerRecordEditor(store, record.date, record) { editRecord = null }
|
||||
}
|
||||
|
||||
menu?.let { value ->
|
||||
val options: List<Pair<String, String>> = when (value) {
|
||||
"member" -> listOf("" to L10n.text("management.all")) + document.members.map { it.id to it.name }
|
||||
"group" -> listOf("" to L10n.text("management.all")) + document.groups.map { it.id to it.name }
|
||||
"product" -> listOf("" to L10n.text("management.all")) +
|
||||
document.products.map { it.id to LedgerPresentation.productName(it.id, it.name) }
|
||||
"currency" -> listOf("" to L10n.text("management.all")) + LedgerCurrency.entries.map { it.name to it.name }
|
||||
"event" -> listOf(
|
||||
"" to L10n.text("management.all"),
|
||||
"__none__" to L10n.text("ledger.noEvent"),
|
||||
) + document.events.map { it.id to it.name }
|
||||
else -> emptyList()
|
||||
}
|
||||
if (value == "catalog") {
|
||||
LedgerCatalogManagementScreen(store) { menu = null }
|
||||
} else {
|
||||
ChoiceList(
|
||||
title = when (value) {
|
||||
"member" -> L10n.text("ledger.member")
|
||||
"group" -> L10n.text("ledger.group")
|
||||
"product" -> L10n.text("ledger.type")
|
||||
"currency" -> L10n.text("ledger.currency")
|
||||
else -> L10n.text("ledger.event")
|
||||
},
|
||||
options = options,
|
||||
selection = if (value == "event" && requiresNoEvent) "__none__" else when (value) {
|
||||
"member" -> memberID
|
||||
"group" -> groupID
|
||||
"product" -> productID
|
||||
"currency" -> currency
|
||||
else -> eventSelection
|
||||
},
|
||||
onSelect = { id ->
|
||||
when (value) {
|
||||
"member" -> memberID = id
|
||||
"group" -> groupID = id
|
||||
"product" -> productID = id
|
||||
"currency" -> currency = id
|
||||
else -> {
|
||||
requiresNoEvent = id == "__none__"
|
||||
eventSelection = if (id == "__none__") "" else id
|
||||
}
|
||||
}
|
||||
selectedIDs = emptySet()
|
||||
menu = null
|
||||
},
|
||||
onDismiss = { menu = null },
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Composable
|
||||
private fun FilterLine(label: String, value: String, onClick: () -> Unit) {
|
||||
Row(Modifier.fillMaxWidth().clickable(onClick = onClick).padding(vertical = 6.dp),
|
||||
verticalAlignment = Alignment.CenterVertically) {
|
||||
Text(label, fontSize = 13.sp, color = Kit.colors.ink)
|
||||
Spacer(Modifier.weight(1f))
|
||||
Text(value, fontSize = 13.sp, color = Kit.colors.muted)
|
||||
}
|
||||
}
|
||||
|
||||
@Composable
|
||||
private fun DateLine(label: String, date: LocalDate, onSelect: (LocalDate) -> Unit) {
|
||||
var open by remember { mutableStateOf(false) }
|
||||
Row(Modifier.fillMaxWidth().clickable { open = true }.padding(vertical = 6.dp),
|
||||
verticalAlignment = Alignment.CenterVertically) {
|
||||
Text(label, fontSize = 13.sp, color = Kit.colors.ink)
|
||||
Spacer(Modifier.weight(1f))
|
||||
Text(date.toString(), fontSize = 13.sp, color = Kit.colors.muted)
|
||||
}
|
||||
if (open) {
|
||||
val pickerState = androidx.compose.material3.rememberDatePickerState(
|
||||
initialSelectedDateMillis = date.atStartOfDay(java.time.ZoneId.of("UTC")).toInstant().toEpochMilli(),
|
||||
)
|
||||
androidx.compose.material3.DatePickerDialog(
|
||||
onDismissRequest = { open = false },
|
||||
confirmButton = {
|
||||
TextButton(onClick = {
|
||||
pickerState.selectedDateMillis?.let {
|
||||
onSelect(java.time.Instant.ofEpochMilli(it).atZone(java.time.ZoneId.of("UTC")).toLocalDate())
|
||||
}
|
||||
open = false
|
||||
}) { Text(L10n.text("common.done")) }
|
||||
},
|
||||
dismissButton = { TextButton(onClick = { open = false }) { Text(L10n.text("common.cancel")) } },
|
||||
) { androidx.compose.material3.DatePicker(state = pickerState) }
|
||||
}
|
||||
}
|
||||
|
||||
@Composable
|
||||
private fun CheckBox(checked: Boolean, onToggle: (Boolean) -> Unit) {
|
||||
Box(
|
||||
Modifier
|
||||
.size(22.dp)
|
||||
.clip(RoundedCornerShape(6.dp))
|
||||
.background(if (checked) Kit.colors.accentFill else Kit.colors.surfaceMuted)
|
||||
.clickable { onToggle(!checked) },
|
||||
contentAlignment = Alignment.Center,
|
||||
) {
|
||||
if (checked) Text("✓", fontSize = 13.sp, color = Kit.colors.onAccent, fontWeight = FontWeight.Bold)
|
||||
}
|
||||
}
|
||||
|
||||
/** The restorable JSON backup and a CSV spreadsheet of purchases. */
|
||||
@Composable
|
||||
fun LedgerBackupPanel(store: LedgerStore) {
|
||||
val context = LocalContext.current
|
||||
val state by store.state.collectAsStateWithLifecycle()
|
||||
var error by remember { mutableStateOf<String?>(null) }
|
||||
|
||||
Column(
|
||||
Modifier.fillMaxSize().verticalScroll(rememberScrollState()).padding(20.dp),
|
||||
verticalArrangement = Arrangement.spacedBy(14.dp),
|
||||
) {
|
||||
KitSheetHeader(androidx.compose.material.icons.Icons.Filled.Archive,
|
||||
L10n.text("ledger.backup"), L10n.text("ledger.backupHint"))
|
||||
ProminentButton(L10n.text("ledger.export")) {
|
||||
runCatching { store.exportJSON() }
|
||||
.onSuccess {
|
||||
shareText(context, it, com.oshicue.keeps.core.AppBrand.exportPrefix + "ledger-" +
|
||||
LedgerDates.string(LocalDate.now()))
|
||||
error = null
|
||||
}
|
||||
.onFailure { error = KitPresentation.error(it) }
|
||||
}
|
||||
Text(
|
||||
L10n.text("ledger.exportCSV"), fontSize = 15.sp, fontWeight = FontWeight.SemiBold, color = Kit.colors.ink,
|
||||
textAlign = androidx.compose.ui.text.style.TextAlign.Center,
|
||||
modifier = Modifier
|
||||
.fillMaxWidth()
|
||||
.clip(RoundedCornerShape(12.dp))
|
||||
.background(Kit.colors.surface)
|
||||
.clickable(enabled = state.document.records.isNotEmpty()) {
|
||||
shareText(context, LedgerPresentation.csv(state.document.records),
|
||||
com.oshicue.keeps.core.AppBrand.exportPrefix + "purchases-" +
|
||||
LedgerDates.string(LocalDate.now()), "text/csv")
|
||||
}
|
||||
.padding(vertical = 13.dp),
|
||||
)
|
||||
Text(L10n.text("ledger.exportCSVHint"), fontSize = 12.sp, color = Kit.colors.muted)
|
||||
error?.let { KitErrorBox(it) }
|
||||
}
|
||||
}
|
||||
|
||||
/** Import a ledger JSON, with the example ledger below it. */
|
||||
@Composable
|
||||
fun LedgerImportPanel(store: LedgerStore, onDone: () -> Unit) {
|
||||
val context = LocalContext.current
|
||||
val scope = rememberCoroutineScopeHolder()
|
||||
val state by store.state.collectAsStateWithLifecycle()
|
||||
var text by remember { mutableStateOf("") }
|
||||
var candidate by remember { mutableStateOf<LedgerDocument?>(null) }
|
||||
var error by remember { mutableStateOf<String?>(null) }
|
||||
var copied by remember { mutableStateOf(false) }
|
||||
var demoError by remember { mutableStateOf<String?>(null) }
|
||||
val pick = rememberDocumentPicker { bytess ->
|
||||
runCatching { LedgerImporter.combining(bytess.map { LedgerImporter.parse(it) }) }
|
||||
.onSuccess { document ->
|
||||
text = LedgerImporter.encode(document)
|
||||
candidate = document
|
||||
error = null
|
||||
}
|
||||
.onFailure { error = KitPresentation.fileError(it); candidate = null }
|
||||
}
|
||||
|
||||
Column(
|
||||
Modifier.fillMaxSize().verticalScroll(rememberScrollState()).padding(20.dp),
|
||||
verticalArrangement = Arrangement.spacedBy(14.dp),
|
||||
) {
|
||||
KitSheetHeader(androidx.compose.material.icons.Icons.Filled.FileOpen,
|
||||
L10n.text("ledger.import"), "JSON · UTF-8")
|
||||
Text(L10n.text("ledger.importHint"), fontSize = 12.sp, color = Kit.colors.muted)
|
||||
|
||||
Row(verticalAlignment = Alignment.CenterVertically) {
|
||||
Text(L10n.text("import.file"), fontSize = 13.sp, color = Kit.colors.accentText,
|
||||
modifier = Modifier.clickable { pick() }.padding(6.dp))
|
||||
Spacer(Modifier.weight(1f))
|
||||
Text(L10n.text(if (copied) "import.copied" else "ledger.copyTemplate"), fontSize = 13.sp,
|
||||
color = Kit.colors.accentText,
|
||||
modifier = Modifier.clickable {
|
||||
scope.launch {
|
||||
runCatching { readAssetText(context, "templates/ledger-template.json") }
|
||||
.onSuccess {
|
||||
val manager = context.getSystemService(android.content.ClipboardManager::class.java)
|
||||
manager.setPrimaryClip(android.content.ClipData.newPlainText("JSON", it))
|
||||
copied = true
|
||||
}
|
||||
.onFailure { error = KitPresentation.error(it) }
|
||||
}
|
||||
}.padding(6.dp))
|
||||
}
|
||||
|
||||
Box(
|
||||
Modifier.fillMaxWidth()
|
||||
.clip(RoundedCornerShape(14.dp))
|
||||
.background(Kit.colors.surface)
|
||||
.padding(10.dp),
|
||||
) {
|
||||
if (text.isEmpty()) Text(L10n.text("import.placeholder"), fontSize = 12.sp, color = Kit.colors.muted)
|
||||
androidx.compose.foundation.text.BasicTextField(
|
||||
value = text,
|
||||
onValueChange = { text = it; candidate = null; error = null },
|
||||
textStyle = androidx.compose.ui.text.TextStyle(
|
||||
fontSize = 12.sp, color = Kit.colors.ink,
|
||||
fontFamily = androidx.compose.ui.text.font.FontFamily.Monospace,
|
||||
),
|
||||
cursorBrush = androidx.compose.ui.graphics.SolidColor(Kit.colors.accentText),
|
||||
)
|
||||
}
|
||||
|
||||
ProminentButton(L10n.text("import.validate"), enabled = text.isNotBlank()) {
|
||||
runCatching { LedgerImporter.parse(text) }
|
||||
.onSuccess { document ->
|
||||
val empty = document.members.isEmpty() && document.groups.isEmpty() &&
|
||||
document.products.isEmpty() && document.events.isEmpty() && document.records.isEmpty()
|
||||
if (empty) {
|
||||
candidate = null
|
||||
error = L10n.text("ledger.error.emptyImport")
|
||||
} else {
|
||||
// The preview also checks the merge against saved data.
|
||||
runCatching { if (!store.canReplaceDemo) store.document.merging(document) }
|
||||
.onSuccess { candidate = document; error = null }
|
||||
.onFailure { candidate = null; error = KitPresentation.error(it) }
|
||||
}
|
||||
}
|
||||
.onFailure { candidate = null; error = KitPresentation.error(it) }
|
||||
}
|
||||
|
||||
error?.let { KitErrorBox(it) }
|
||||
|
||||
candidate?.let { preview ->
|
||||
KitCard(spacing = 12) {
|
||||
Text(L10n.text("ledger.preview"), fontSize = 17.sp, fontWeight = FontWeight.Bold, color = Kit.colors.ink)
|
||||
Text(L10n.format("ledger.summary", preview.members.size, preview.records.size), fontSize = 14.sp,
|
||||
color = Kit.colors.ink)
|
||||
Text(L10n.text(if (store.canReplaceDemo) "ledger.replacesDemo" else "ledger.restoreHint"),
|
||||
fontSize = 12.sp, color = Kit.colors.muted)
|
||||
ProminentButton(L10n.text("ledger.apply")) {
|
||||
if (store.importDocument(preview)) onDone() else error = store.takeError()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
KitDivider()
|
||||
|
||||
KitCard {
|
||||
Text(L10n.text("ledger.title"), fontSize = 17.sp, fontWeight = FontWeight.Bold, color = Kit.colors.ink)
|
||||
Text(L10n.text("settings.ledgerDemo"), fontSize = 13.sp, color = Kit.colors.accentText,
|
||||
modifier = Modifier.clickable {
|
||||
if (store.loadDemo()) onDone() else demoError = store.takeError()
|
||||
}.padding(4.dp))
|
||||
Text(L10n.text("ledger.loadDemoHint"), fontSize = 12.sp, color = Kit.colors.muted)
|
||||
demoError?.let { KitErrorBox(it) }
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/** Catalog cleanup: archive members or groups while every purchase keeps its snapshots. */
|
||||
@Composable
|
||||
fun LedgerCatalogManagementScreen(store: LedgerStore, onClose: () -> Unit) {
|
||||
val state by store.state.collectAsStateWithLifecycle()
|
||||
val document = state.document
|
||||
var mode by remember { mutableStateOf(0) }
|
||||
var search by remember { mutableStateOf("") }
|
||||
var selectedIDs by remember { mutableStateOf<Set<String>>(emptySet()) }
|
||||
var pendingIDs by remember { mutableStateOf<Set<String>>(emptySet()) }
|
||||
var showConfirmation by remember { mutableStateOf(false) }
|
||||
var error by remember { mutableStateOf<String?>(null) }
|
||||
|
||||
fun matches(value: String): Boolean = search.isBlank() || TextNormalizer.contains(value, search)
|
||||
|
||||
val visibleMembers = document.activeMembers.filter { member ->
|
||||
matches(member.name) || document.memberships.any { affiliation ->
|
||||
affiliation.memberID == member.id && document.activeGroups.any {
|
||||
it.id == affiliation.groupID && matches(it.name)
|
||||
}
|
||||
}
|
||||
}.sortedBy { it.name }
|
||||
val visibleGroups = document.activeGroups.filter { matches(it.name) }.sortedBy { it.name }
|
||||
val visibleIDs = if (mode == 0) visibleMembers.map { it.id }.toSet() else visibleGroups.map { it.id }.toSet()
|
||||
|
||||
Column(Modifier.fillMaxSize().background(Kit.colors.background)) {
|
||||
SheetBar(L10n.text("management.catalog"), onClose)
|
||||
Column(
|
||||
Modifier.fillMaxSize().verticalScroll(rememberScrollState()).padding(horizontal = 20.dp),
|
||||
verticalArrangement = Arrangement.spacedBy(12.dp),
|
||||
) {
|
||||
SegmentedControl(
|
||||
listOf(L10n.text("ledger.catalog.members") to 0, L10n.text("ledger.group") to 1),
|
||||
mode,
|
||||
) { mode = it; selectedIDs = emptySet() }
|
||||
EditorTextField(search, { search = it; selectedIDs = emptySet() }, modifier = Modifier.fillMaxWidth())
|
||||
Text(L10n.text("management.catalog.hint"), fontSize = 12.sp, color = Kit.colors.muted)
|
||||
Row(verticalAlignment = Alignment.CenterVertically) {
|
||||
Text(L10n.text("management.selectFiltered"), fontSize = 13.sp, color = Kit.colors.accentText,
|
||||
modifier = Modifier.clickable(enabled = visibleIDs.isNotEmpty()) { selectedIDs = visibleIDs }
|
||||
.padding(4.dp))
|
||||
Spacer(Modifier.weight(1f))
|
||||
Text(L10n.text("management.clearSelection"), fontSize = 13.sp, color = Kit.colors.accentText,
|
||||
modifier = Modifier.clickable(enabled = selectedIDs.isNotEmpty()) { selectedIDs = emptySet() }
|
||||
.padding(4.dp))
|
||||
}
|
||||
Text(L10n.format("management.selectedCount", selectedIDs.size), fontSize = 11.sp, color = Kit.colors.muted)
|
||||
if (visibleIDs.isEmpty()) {
|
||||
Text(L10n.text("management.catalog.empty"), fontSize = 13.sp, color = Kit.colors.muted)
|
||||
}
|
||||
if (mode == 0) {
|
||||
visibleMembers.forEach { member ->
|
||||
SelectionRow(member.name, member.id in selectedIDs) {
|
||||
selectedIDs = if (member.id in selectedIDs) selectedIDs - member.id else selectedIDs + member.id
|
||||
}
|
||||
}
|
||||
} else {
|
||||
visibleGroups.forEach { group ->
|
||||
SelectionRow(group.name, group.id in selectedIDs) {
|
||||
selectedIDs = if (group.id in selectedIDs) selectedIDs - group.id else selectedIDs + group.id
|
||||
}
|
||||
}
|
||||
}
|
||||
ProminentButton(L10n.text("management.deleteSelected"), enabled = selectedIDs.isNotEmpty()) {
|
||||
pendingIDs = selectedIDs.intersect(visibleIDs)
|
||||
showConfirmation = pendingIDs.isNotEmpty()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (showConfirmation) {
|
||||
AlertDialog(
|
||||
onDismissRequest = { showConfirmation = false },
|
||||
title = { Text(L10n.text("management.catalog.deleteTitle"), fontWeight = FontWeight.Bold) },
|
||||
text = {
|
||||
Text(L10n.format(
|
||||
if (mode == 0) "management.catalog.memberImpact" else "management.catalog.groupImpact",
|
||||
pendingIDs.size,
|
||||
))
|
||||
},
|
||||
confirmButton = {
|
||||
TextButton(onClick = {
|
||||
val ids = pendingIDs
|
||||
val success = if (mode == 0) store.deleteMembers(ids) else store.deleteGroups(ids)
|
||||
if (success) {
|
||||
selectedIDs = selectedIDs - ids
|
||||
pendingIDs = emptySet()
|
||||
} else {
|
||||
error = store.takeError()
|
||||
}
|
||||
showConfirmation = false
|
||||
}) { Text(L10n.text("management.deleteSelected"), color = Color(0xFFC62828)) }
|
||||
},
|
||||
dismissButton = {
|
||||
TextButton(onClick = { showConfirmation = false; pendingIDs = emptySet() }) {
|
||||
Text(L10n.text("common.cancel"))
|
||||
}
|
||||
},
|
||||
containerColor = Kit.colors.surface,
|
||||
)
|
||||
}
|
||||
|
||||
error?.let { message ->
|
||||
AlertDialog(
|
||||
onDismissRequest = { error = null },
|
||||
title = { Text(L10n.text("settings.storageError")) },
|
||||
text = { Text(message) },
|
||||
confirmButton = { TextButton(onClick = { error = null }) { Text(L10n.text("common.close")) } },
|
||||
containerColor = Kit.colors.surface,
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
@Composable
|
||||
private fun SelectionRow(title: String, selected: Boolean, onToggle: () -> Unit) {
|
||||
Row(
|
||||
Modifier.fillMaxWidth().clickable(onClick = onToggle).padding(vertical = 10.dp),
|
||||
verticalAlignment = Alignment.CenterVertically,
|
||||
) {
|
||||
Icon(
|
||||
if (selected) Icons.Filled.Check else Icons.Filled.RadioButtonUnchecked,
|
||||
contentDescription = null,
|
||||
tint = if (selected) Kit.colors.accentText else Kit.colors.muted,
|
||||
modifier = Modifier.size(19.dp),
|
||||
)
|
||||
Spacer(Modifier.width(10.dp))
|
||||
Text(title, fontSize = 14.sp, color = Kit.colors.ink)
|
||||
}
|
||||
}
|
||||
|
||||
@Composable
|
||||
fun rememberCoroutineScopeHolder() = androidx.compose.runtime.rememberCoroutineScope()
|
||||
|
||||
/** Reads a bundled asset; templates live in assets/templates. */
|
||||
suspend fun readAssetText(context: android.content.Context, path: String): String = withContext(Dispatchers.IO) {
|
||||
context.assets.open(path).use { it.readBytes().toString(Charsets.UTF_8) }
|
||||
}
|
||||
@@ -0,0 +1,745 @@
|
||||
package com.oshicue.keeps.ui
|
||||
|
||||
import androidx.activity.compose.BackHandler
|
||||
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.Spacer
|
||||
import androidx.compose.foundation.layout.fillMaxSize
|
||||
import androidx.compose.foundation.layout.fillMaxWidth
|
||||
import androidx.compose.foundation.layout.height
|
||||
import androidx.compose.foundation.layout.heightIn
|
||||
import androidx.compose.foundation.layout.padding
|
||||
import androidx.compose.foundation.layout.size
|
||||
import androidx.compose.foundation.layout.width
|
||||
import androidx.compose.foundation.lazy.LazyColumn
|
||||
import androidx.compose.foundation.lazy.items
|
||||
import androidx.compose.foundation.rememberScrollState
|
||||
import androidx.compose.foundation.shape.CircleShape
|
||||
import androidx.compose.foundation.shape.RoundedCornerShape
|
||||
import androidx.compose.foundation.text.BasicTextField
|
||||
import androidx.compose.foundation.text.KeyboardOptions
|
||||
import androidx.compose.foundation.verticalScroll
|
||||
import androidx.compose.material.icons.Icons
|
||||
import androidx.compose.material.icons.filled.Add
|
||||
import androidx.compose.material.icons.filled.Check
|
||||
import androidx.compose.material.icons.filled.Close
|
||||
import androidx.compose.material.icons.filled.ExpandMore
|
||||
import androidx.compose.material.icons.filled.PersonAdd
|
||||
import androidx.compose.material.icons.filled.Remove
|
||||
import androidx.compose.material.icons.filled.Star
|
||||
import androidx.compose.material3.AlertDialog
|
||||
import androidx.compose.material3.Icon
|
||||
import androidx.compose.material3.Text
|
||||
import androidx.compose.material3.TextButton
|
||||
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.graphics.Color
|
||||
import androidx.compose.ui.graphics.SolidColor
|
||||
import androidx.compose.ui.text.TextStyle
|
||||
import androidx.compose.ui.text.font.FontWeight
|
||||
import androidx.compose.ui.text.input.KeyboardType
|
||||
import androidx.compose.ui.unit.dp
|
||||
import androidx.compose.ui.unit.sp
|
||||
import androidx.lifecycle.compose.collectAsStateWithLifecycle
|
||||
import com.oshicue.keeps.core.L10n
|
||||
import com.oshicue.keeps.core.LedgerCurrency
|
||||
import com.oshicue.keeps.core.LedgerDates
|
||||
import com.oshicue.keeps.core.LedgerMember
|
||||
import com.oshicue.keeps.core.LedgerMembership
|
||||
import com.oshicue.keeps.core.LedgerPrice
|
||||
import com.oshicue.keeps.core.LedgerPriceSuggestions
|
||||
import com.oshicue.keeps.core.LedgerProduct
|
||||
import com.oshicue.keeps.core.LedgerPresentation
|
||||
import com.oshicue.keeps.core.LedgerRecord
|
||||
import com.oshicue.keeps.core.activeMembers
|
||||
import com.oshicue.keeps.core.activeMemberships
|
||||
import com.oshicue.keeps.core.favoriteMemberships
|
||||
import com.oshicue.keeps.core.preferredRecordMembership
|
||||
import com.oshicue.keeps.core.recordMembershipChoices
|
||||
import com.oshicue.keeps.core.recordMembershipGroups
|
||||
import java.time.LocalDate
|
||||
import java.time.YearMonth
|
||||
import java.time.ZoneId
|
||||
|
||||
/**
|
||||
* Edits one purchase. Every field of the record is editable, including the display snapshots kept
|
||||
* for history: changing the member or type refreshes them from the catalog, and the values can then
|
||||
* be corrected by hand without touching earlier records.
|
||||
*/
|
||||
@Composable
|
||||
fun LedgerRecordEditor(
|
||||
store: LedgerStore,
|
||||
date: String,
|
||||
record: LedgerRecord?,
|
||||
onClose: () -> Unit,
|
||||
) {
|
||||
val state by store.state.collectAsStateWithLifecycle()
|
||||
val document = state.document
|
||||
|
||||
val initial = remember(record?.id, date) {
|
||||
val membership = document.preferredRecordMembership(record)
|
||||
val productID = record?.productID ?: document.products.firstOrNull()?.id ?: ""
|
||||
val purchaseDate = record?.date ?: date
|
||||
val currency = record?.currency ?: LedgerPriceSuggestions.currency(
|
||||
document, membership, productID, purchaseDate, store.prices)
|
||||
val defaultPrice = LedgerPriceSuggestions.price(
|
||||
document, membership, productID, currency, purchaseDate, store.prices).unitPriceMinor
|
||||
EditorInitial(
|
||||
membershipID = membership?.id ?: "",
|
||||
productID = productID,
|
||||
currency = currency,
|
||||
quantity = (record?.quantity ?: 1).toString(),
|
||||
price = (runCatching { LedgerCurrency.valueOf(currency) }.getOrNull() ?: LedgerCurrency.JPY)
|
||||
.priceText(record?.unitPriceMinor ?: defaultPrice),
|
||||
eventID = record?.eventID ?: "",
|
||||
eventName = record?.eventNameSnapshot ?: "",
|
||||
city = record?.citySnapshot ?: "",
|
||||
venue = record?.venueSnapshot ?: "",
|
||||
address = record?.addressSnapshot ?: "",
|
||||
note = record?.note ?: "",
|
||||
memberLabel = record?.memberNameSnapshot
|
||||
?: document.members.firstOrNull { it.id == membership?.memberID }?.name ?: "",
|
||||
groupLabel = record?.groupNameSnapshot
|
||||
?: document.groups.firstOrNull { it.id == membership?.groupID }?.name ?: "",
|
||||
productLabel = LedgerPresentation.productName(productID,
|
||||
record?.productNameSnapshot ?: document.products.firstOrNull { it.id == productID }?.name ?: ""),
|
||||
color = record?.colorSnapshot ?: membership?.color ?: "#F26B52",
|
||||
)
|
||||
}
|
||||
|
||||
var selectedDate by remember { mutableStateOf(LedgerPresentation.date(record?.date ?: date)) }
|
||||
var membershipID by remember { mutableStateOf(initial.membershipID) }
|
||||
var productID by remember { mutableStateOf(initial.productID) }
|
||||
var currency by remember { mutableStateOf(initial.currency) }
|
||||
var quantity by remember { mutableStateOf(initial.quantity) }
|
||||
var price by remember { mutableStateOf(initial.price) }
|
||||
var eventID by remember { mutableStateOf(initial.eventID) }
|
||||
var eventName by remember { mutableStateOf(initial.eventName) }
|
||||
var city by remember { mutableStateOf(initial.city) }
|
||||
var venue by remember { mutableStateOf(initial.venue) }
|
||||
var address by remember { mutableStateOf(initial.address) }
|
||||
var note by remember { mutableStateOf(initial.note) }
|
||||
var memberLabel by remember { mutableStateOf(initial.memberLabel) }
|
||||
var groupLabel by remember { mutableStateOf(initial.groupLabel) }
|
||||
var productLabel by remember { mutableStateOf(initial.productLabel) }
|
||||
var color by remember { mutableStateOf(initial.color) }
|
||||
var error by remember { mutableStateOf<String?>(null) }
|
||||
var confirmDelete by remember { mutableStateOf(false) }
|
||||
var openMemberPicker by remember { mutableStateOf(false) }
|
||||
var openProductPicker by remember { mutableStateOf(false) }
|
||||
var openCurrencyPicker by remember { mutableStateOf(false) }
|
||||
var openEventPicker by remember { mutableStateOf(false) }
|
||||
var openDatePicker by remember { mutableStateOf(false) }
|
||||
|
||||
val membership = document.memberships.firstOrNull { it.id == membershipID }
|
||||
val member = document.members.firstOrNull { it.id == membership?.memberID }
|
||||
val group = document.groups.firstOrNull { it.id == membership?.groupID }
|
||||
val product = document.products.firstOrNull { it.id == productID }
|
||||
val selectedCurrency = runCatching { LedgerCurrency.valueOf(currency) }.getOrNull() ?: LedgerCurrency.JPY
|
||||
val priceValue = selectedCurrency.parsePrice(price.replace(",", "."))
|
||||
val quantityValue = quantity.toIntOrNull()
|
||||
val total = remember(quantityValue, priceValue) {
|
||||
if (quantityValue != null && quantityValue > 0 && priceValue != null) {
|
||||
runCatching { Math.multiplyExact(priceValue, quantityValue.toLong()) }.getOrNull()
|
||||
} else null
|
||||
}
|
||||
|
||||
fun isAvailable(item: LedgerMembership) = document.activeMemberships.any { it.id == item.id }
|
||||
|
||||
fun prefillPrice(selectCurrency: Boolean = false) {
|
||||
val day = LedgerDates.string(selectedDate)
|
||||
val chosenMembership = document.memberships.firstOrNull { it.id == membershipID }
|
||||
if (selectCurrency) {
|
||||
currency = if (record != null && record.memberID == chosenMembership?.memberID &&
|
||||
record.groupID == chosenMembership?.groupID && record.productID == productID
|
||||
) {
|
||||
record.currency
|
||||
} else {
|
||||
LedgerPriceSuggestions.currency(document, chosenMembership, productID, day, store.prices)
|
||||
}
|
||||
}
|
||||
val current = runCatching { LedgerCurrency.valueOf(currency) }.getOrNull() ?: LedgerCurrency.JPY
|
||||
price = if (record != null && record.memberID == chosenMembership?.memberID &&
|
||||
record.groupID == chosenMembership?.groupID && record.productID == productID &&
|
||||
record.currency == currency
|
||||
) {
|
||||
current.priceText(record.unitPriceMinor)
|
||||
} else {
|
||||
val suggestion = LedgerPriceSuggestions.price(
|
||||
document, chosenMembership, productID, currency, day, store.prices)
|
||||
current.priceText(suggestion.unitPriceMinor)
|
||||
}
|
||||
}
|
||||
|
||||
/** Choosing the record's own affiliation again restores the labels it was saved with. */
|
||||
fun selectMembership(id: String) {
|
||||
membershipID = id
|
||||
val chosen = document.memberships.firstOrNull { it.id == id }
|
||||
if (record != null && record.memberID == chosen?.memberID && record.groupID == chosen?.groupID) {
|
||||
memberLabel = record.memberNameSnapshot
|
||||
groupLabel = record.groupNameSnapshot
|
||||
color = record.colorSnapshot
|
||||
currency = record.currency
|
||||
price = selectedCurrencyOf(record.currency).priceText(record.unitPriceMinor)
|
||||
return
|
||||
}
|
||||
document.members.firstOrNull { it.id == chosen?.memberID }?.let { memberLabel = it.name }
|
||||
document.groups.firstOrNull { it.id == chosen?.groupID }?.let { groupLabel = it.name }
|
||||
chosen?.let { color = it.color }
|
||||
prefillPrice(selectCurrency = true)
|
||||
}
|
||||
|
||||
fun selectProduct(id: String) {
|
||||
productID = id
|
||||
val stored = if (record?.productID == id) record.productNameSnapshot
|
||||
else document.products.firstOrNull { it.id == id }?.name
|
||||
productLabel = LedgerPresentation.productName(id, stored ?: "")
|
||||
prefillPrice(selectCurrency = true)
|
||||
}
|
||||
|
||||
fun selectEvent(id: String) {
|
||||
eventID = id
|
||||
val event = document.events.firstOrNull { it.id == id }
|
||||
if (event == null) {
|
||||
eventName = ""; city = ""; venue = ""; address = ""
|
||||
} else {
|
||||
eventName = event.name; city = event.city ?: ""; venue = event.venue ?: ""; address = event.address ?: ""
|
||||
}
|
||||
}
|
||||
|
||||
fun optional(text: String): String? = text.trim().takeIf { it.isNotEmpty() }
|
||||
|
||||
fun label(text: String, stored: String?, display: String? = null, fallback: String): String {
|
||||
if (stored != null && text == (display ?: stored)) return stored
|
||||
return optional(text) ?: fallback
|
||||
}
|
||||
|
||||
fun save() {
|
||||
if (membership == null || member == null || group == null || product == null) {
|
||||
error = L10n.text("ledger.requiredSelection"); return
|
||||
}
|
||||
val quantityChecked = quantityValue
|
||||
if (quantityChecked == null || quantityChecked <= 0) {
|
||||
error = L10n.text("ledger.invalidQuantity"); return
|
||||
}
|
||||
val priceChecked = priceValue
|
||||
if (priceChecked == null || total == null) {
|
||||
error = L10n.text("ledger.invalidPrice"); return
|
||||
}
|
||||
val sameMembership = record?.memberID == member.id && record?.groupID == group.id
|
||||
val storedProduct = if (record?.productID == product.id) record.productNameSnapshot else product.name
|
||||
val memberText = label(memberLabel, if (sameMembership) record?.memberNameSnapshot else member.name, fallback = member.name)
|
||||
val groupText = label(groupLabel, if (sameMembership) record?.groupNameSnapshot else group.name, fallback = group.name)
|
||||
val productText = label(productLabel, storedProduct,
|
||||
display = storedProduct?.let { LedgerPresentation.productName(product.id, it) }, fallback = product.name)
|
||||
val colorText = if (Regex("^#[0-9a-fA-F]{6}$").matches(color)) color else membership.color
|
||||
val value = LedgerRecord(
|
||||
id = record?.id ?: java.util.UUID.randomUUID().toString(),
|
||||
date = LedgerDates.string(selectedDate),
|
||||
memberID = member.id,
|
||||
groupID = group.id,
|
||||
productID = product.id,
|
||||
quantity = quantityChecked,
|
||||
unitPriceMinor = priceChecked,
|
||||
currency = currency,
|
||||
eventID = eventID.takeIf { it.isNotEmpty() },
|
||||
memberNameSnapshot = memberText,
|
||||
groupNameSnapshot = groupText,
|
||||
productNameSnapshot = productText,
|
||||
colorSnapshot = colorText,
|
||||
eventNameSnapshot = optional(eventName),
|
||||
citySnapshot = optional(city),
|
||||
venueSnapshot = optional(venue),
|
||||
addressSnapshot = optional(address),
|
||||
note = optional(note),
|
||||
)
|
||||
if (store.saveRecord(value)) onClose() else error = store.takeError()
|
||||
}
|
||||
|
||||
BackHandler(onBack = onClose)
|
||||
|
||||
Column(Modifier.fillMaxSize().background(Kit.colors.background)) {
|
||||
SheetBar(
|
||||
L10n.text(if (record == null) "ledger.newRecord" else "ledger.editRecord"),
|
||||
onClose,
|
||||
) {
|
||||
Text(L10n.text("ledger.save"), fontSize = 15.sp, fontWeight = FontWeight.SemiBold,
|
||||
color = Kit.colors.accentText, modifier = Modifier.clickable { save() }.padding(6.dp))
|
||||
}
|
||||
Column(
|
||||
Modifier.fillMaxSize().verticalScroll(rememberScrollState()).padding(horizontal = 16.dp).padding(bottom = 30.dp),
|
||||
verticalArrangement = Arrangement.spacedBy(14.dp),
|
||||
) {
|
||||
EditorSection(L10n.text("ledger.date")) {
|
||||
SettingLine(
|
||||
title = KitDateString(selectedDate),
|
||||
onClick = { openDatePicker = true },
|
||||
)
|
||||
}
|
||||
|
||||
EditorSection(L10n.text("ledger.member")) {
|
||||
if (member != null && group != null) {
|
||||
Row(verticalAlignment = Alignment.CenterVertically) {
|
||||
LedgerAvatar(member, membership?.color ?: "#F26B52", 45.dp)
|
||||
Spacer(Modifier.width(12.dp))
|
||||
Column(verticalArrangement = Arrangement.spacedBy(4.dp)) {
|
||||
Text(member.name, fontSize = 16.sp, fontWeight = FontWeight.Bold, color = Kit.colors.ink)
|
||||
Text(group.name, fontSize = 12.sp, color = Kit.colors.muted)
|
||||
if (membership != null && !isAvailable(membership)) {
|
||||
Text(L10n.text("ledger.deleted"), fontSize = 12.sp, color = Kit.colors.muted)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
SettingLine(
|
||||
title = L10n.text("ledger.chooseMember"),
|
||||
value = membership?.let { item ->
|
||||
val name = document.members.firstOrNull { it.id == item.memberID }?.name ?: ""
|
||||
val groupName = document.groups.firstOrNull { it.id == item.groupID }?.name ?: ""
|
||||
name + " · " + groupName + (if (isAvailable(item)) "" else " · " + L10n.text("ledger.deleted"))
|
||||
} ?: "",
|
||||
onClick = { openMemberPicker = true },
|
||||
)
|
||||
}
|
||||
|
||||
EditorSection(L10n.text("ledger.type")) {
|
||||
SettingLine(
|
||||
title = L10n.text("ledger.type"),
|
||||
value = product?.let { LedgerPresentation.productName(it.id, it.name) } ?: "",
|
||||
onClick = { openProductPicker = true },
|
||||
)
|
||||
QuantityControl(
|
||||
quantity = quantity,
|
||||
onQuantityChange = { quantity = it },
|
||||
onDecrease = {
|
||||
val value = (quantityValue ?: 1) - 1
|
||||
quantity = maxOf(1, value).toString()
|
||||
},
|
||||
onIncrease = { quantity = ((quantityValue ?: 1) + 1).toString() },
|
||||
)
|
||||
SettingLine(
|
||||
title = L10n.text("ledger.currency"),
|
||||
value = currency,
|
||||
onClick = { openCurrencyPicker = true },
|
||||
)
|
||||
Row(verticalAlignment = Alignment.CenterVertically) {
|
||||
Text(L10n.text("ledger.unitPrice"), fontSize = 14.sp, color = Kit.colors.ink, modifier = Modifier.weight(1f))
|
||||
TextFieldValue(
|
||||
value = price,
|
||||
onValueChange = { price = it },
|
||||
keyboardType = KeyboardType.Decimal,
|
||||
textAlign = androidx.compose.ui.text.style.TextAlign.End,
|
||||
modifier = Modifier.width(120.dp),
|
||||
)
|
||||
}
|
||||
Row(verticalAlignment = Alignment.CenterVertically) {
|
||||
Text(L10n.text("ledger.amount"), fontSize = 14.sp, color = Kit.colors.muted, modifier = Modifier.weight(1f))
|
||||
Text(total?.let { LedgerPresentation.format(selectedCurrency, it) } ?: "—",
|
||||
fontSize = 14.sp, fontWeight = FontWeight.SemiBold, color = Kit.colors.ink)
|
||||
}
|
||||
Text(L10n.text("ledger.priceHint"), fontSize = 11.sp, color = Kit.colors.muted)
|
||||
}
|
||||
|
||||
EditorSection(L10n.text("ledger.optional")) {
|
||||
SettingLine(
|
||||
title = L10n.text("ledger.event"),
|
||||
value = if (eventID.isEmpty()) L10n.text("ledger.noEvent")
|
||||
else document.events.firstOrNull { it.id == eventID }?.name ?: L10n.text("ledger.noEvent"),
|
||||
onClick = { openEventPicker = true },
|
||||
)
|
||||
LabeledField(L10n.text("ledger.event"), eventName) { eventName = it }
|
||||
LabeledField(L10n.text("ledger.city"), city) { city = it }
|
||||
LabeledField(L10n.text("ledger.venue"), venue) { venue = it }
|
||||
LabeledField(L10n.text("ledger.address"), address) { address = it }
|
||||
LabeledField(L10n.text("ledger.note"), note) { note = it }
|
||||
}
|
||||
|
||||
// The labels and color this purchase keeps, even after the catalog changes.
|
||||
EditorSection(L10n.text("ledger.record.details"), footer = L10n.text("ledger.record.detailsHint")) {
|
||||
LabeledField(L10n.text("ledger.member"), memberLabel) { memberLabel = it }
|
||||
LabeledField(L10n.text("ledger.group"), groupLabel) { groupLabel = it }
|
||||
LabeledField(L10n.text("ledger.type"), productLabel) { productLabel = it }
|
||||
ColorField(L10n.text("ledger.groupColor"), color) { color = it }
|
||||
}
|
||||
|
||||
error?.let { KitErrorBox(it) }
|
||||
|
||||
ProminentButton(L10n.text("ledger.save")) { save() }
|
||||
|
||||
if (record != null) {
|
||||
Text(
|
||||
L10n.text("ledger.record.delete"),
|
||||
fontSize = 14.sp, fontWeight = FontWeight.SemiBold, color = Color(0xFFC62828),
|
||||
modifier = Modifier
|
||||
.fillMaxWidth()
|
||||
.clip(RoundedCornerShape(12.dp))
|
||||
.background(Kit.colors.surface)
|
||||
.clickable { confirmDelete = true }
|
||||
.padding(vertical = 13.dp),
|
||||
textAlign = androidx.compose.ui.text.style.TextAlign.Center,
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (confirmDelete) {
|
||||
AlertDialog(
|
||||
onDismissRequest = { confirmDelete = false },
|
||||
title = { Text(L10n.text("ledger.deleteTitle"), fontWeight = FontWeight.Bold) },
|
||||
text = { Text(L10n.text("ledger.deleteMessage")) },
|
||||
confirmButton = {
|
||||
TextButton(onClick = {
|
||||
if (record != null) {
|
||||
if (store.deleteRecord(record.id)) onClose() else error = store.takeError()
|
||||
}
|
||||
confirmDelete = false
|
||||
}) { Text(L10n.text("ledger.record.delete"), color = Color(0xFFC62828)) }
|
||||
},
|
||||
dismissButton = { TextButton(onClick = { confirmDelete = false }) { Text(L10n.text("common.cancel")) } },
|
||||
containerColor = Kit.colors.surface,
|
||||
)
|
||||
}
|
||||
|
||||
if (openMemberPicker) {
|
||||
MembershipPicker(
|
||||
document = document,
|
||||
record = record,
|
||||
selection = membershipID,
|
||||
onSelect = { id -> selectMembership(id); openMemberPicker = false },
|
||||
onDismiss = { openMemberPicker = false },
|
||||
)
|
||||
}
|
||||
|
||||
if (openProductPicker) {
|
||||
ChoiceDialog(
|
||||
title = L10n.text("ledger.type"),
|
||||
options = document.products.map { it.id to LedgerPresentation.productName(it.id, it.name) },
|
||||
selection = productID,
|
||||
onSelect = { id -> selectProduct(id); openProductPicker = false },
|
||||
onDismiss = { openProductPicker = false },
|
||||
)
|
||||
}
|
||||
|
||||
if (openCurrencyPicker) {
|
||||
ChoiceDialog(
|
||||
title = L10n.text("ledger.currency"),
|
||||
options = LedgerCurrency.entries.map { it.name to it.name },
|
||||
selection = currency,
|
||||
onSelect = { value -> currency = value; prefillPrice(); openCurrencyPicker = false },
|
||||
onDismiss = { openCurrencyPicker = false },
|
||||
)
|
||||
}
|
||||
|
||||
if (openEventPicker) {
|
||||
ChoiceDialog(
|
||||
title = L10n.text("ledger.event"),
|
||||
options = listOf("" to L10n.text("ledger.noEvent")) +
|
||||
document.events.map { event ->
|
||||
event.id to (event.name + (event.venue?.let { " · " + it } ?: ""))
|
||||
},
|
||||
selection = eventID,
|
||||
onSelect = { id -> selectEvent(id); openEventPicker = false },
|
||||
onDismiss = { openEventPicker = false },
|
||||
)
|
||||
}
|
||||
|
||||
if (openDatePicker) {
|
||||
val pickerState = androidx.compose.material3.rememberDatePickerState(
|
||||
initialSelectedDateMillis = selectedDate.atStartOfDay(ZoneId.of("UTC")).toInstant().toEpochMilli(),
|
||||
)
|
||||
androidx.compose.material3.DatePickerDialog(
|
||||
onDismissRequest = { openDatePicker = false },
|
||||
confirmButton = {
|
||||
TextButton(onClick = {
|
||||
pickerState.selectedDateMillis?.let { millis ->
|
||||
selectedDate = java.time.Instant.ofEpochMilli(millis).atZone(ZoneId.of("UTC")).toLocalDate()
|
||||
if (record == null) prefillPrice()
|
||||
}
|
||||
openDatePicker = false
|
||||
}) { Text(L10n.text("common.done")) }
|
||||
},
|
||||
dismissButton = {
|
||||
TextButton(onClick = { openDatePicker = false }) { Text(L10n.text("common.cancel")) }
|
||||
},
|
||||
) {
|
||||
androidx.compose.material3.DatePicker(state = pickerState)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private data class EditorInitial(
|
||||
val membershipID: String,
|
||||
val productID: String,
|
||||
val currency: String,
|
||||
val quantity: String,
|
||||
val price: String,
|
||||
val eventID: String,
|
||||
val eventName: String,
|
||||
val city: String,
|
||||
val venue: String,
|
||||
val address: String,
|
||||
val note: String,
|
||||
val memberLabel: String,
|
||||
val groupLabel: String,
|
||||
val productLabel: String,
|
||||
val color: String,
|
||||
)
|
||||
|
||||
private fun selectedCurrencyOf(value: String): LedgerCurrency =
|
||||
runCatching { LedgerCurrency.valueOf(value) }.getOrNull() ?: LedgerCurrency.JPY
|
||||
|
||||
private fun KitDateString(date: LocalDate): String =
|
||||
java.time.format.DateTimeFormatter.ofPattern("yyyy MMM d", L10n.current.locale).format(date)
|
||||
|
||||
@Composable
|
||||
private fun EditorSection(title: String, footer: String? = null, content: @Composable () -> Unit) {
|
||||
Column(
|
||||
Modifier.fillMaxWidth().clip(RoundedCornerShape(16.dp)).background(Kit.colors.surface).padding(16.dp),
|
||||
verticalArrangement = Arrangement.spacedBy(10.dp),
|
||||
) {
|
||||
Text(title, fontSize = 11.sp, fontWeight = FontWeight.Bold, letterSpacing = 1.1.sp, color = Kit.colors.muted)
|
||||
content()
|
||||
footer?.let { Text(it, fontSize = 11.sp, color = Kit.colors.muted) }
|
||||
}
|
||||
}
|
||||
|
||||
@Composable
|
||||
private fun SettingLine(title: String, value: String = "", onClick: () -> Unit) {
|
||||
Row(
|
||||
Modifier.fillMaxWidth().clickable(onClick = onClick).padding(vertical = 6.dp),
|
||||
verticalAlignment = Alignment.CenterVertically,
|
||||
) {
|
||||
Text(title, fontSize = 14.sp, color = Kit.colors.ink)
|
||||
Spacer(Modifier.weight(1f))
|
||||
Text(value, fontSize = 14.sp, color = Kit.colors.muted)
|
||||
Spacer(Modifier.width(4.dp))
|
||||
Icon(Icons.Filled.ExpandMore, contentDescription = null, tint = Kit.colors.muted, modifier = Modifier.size(16.dp))
|
||||
}
|
||||
}
|
||||
|
||||
@Composable
|
||||
private fun LabeledField(label: String, value: String, onValueChange: (String) -> Unit) {
|
||||
Row(Modifier.fillMaxWidth(), verticalAlignment = Alignment.CenterVertically) {
|
||||
Text(label, fontSize = 14.sp, color = Kit.colors.ink, modifier = Modifier.width(104.dp))
|
||||
TextFieldValue(value, onValueChange, modifier = Modifier.weight(1f))
|
||||
}
|
||||
}
|
||||
|
||||
@Composable
|
||||
private fun TextFieldValue(
|
||||
value: String,
|
||||
onValueChange: (String) -> Unit,
|
||||
keyboardType: KeyboardType = KeyboardType.Text,
|
||||
textAlign: androidx.compose.ui.text.style.TextAlign = androidx.compose.ui.text.style.TextAlign.Start,
|
||||
modifier: Modifier = Modifier,
|
||||
) {
|
||||
Box(
|
||||
modifier
|
||||
.clip(RoundedCornerShape(9.dp))
|
||||
.background(Kit.colors.background)
|
||||
.padding(horizontal = 10.dp, vertical = 8.dp),
|
||||
) {
|
||||
if (value.isEmpty()) {
|
||||
Text("", fontSize = 14.sp)
|
||||
}
|
||||
BasicTextField(
|
||||
value = value,
|
||||
onValueChange = onValueChange,
|
||||
singleLine = true,
|
||||
textStyle = TextStyle(fontSize = 14.sp, color = Kit.colors.ink, textAlign = textAlign),
|
||||
cursorBrush = SolidColor(Kit.colors.accentText),
|
||||
keyboardOptions = KeyboardOptions(keyboardType = keyboardType),
|
||||
modifier = Modifier.fillMaxWidth(),
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
/** The stored "#RRGGBB" text is edited directly, so an untouched color is saved exactly as it was. */
|
||||
@Composable
|
||||
private fun ColorField(label: String, color: String, onColorChange: (String) -> Unit) {
|
||||
var open by remember { mutableStateOf(false) }
|
||||
val swatches = listOf(
|
||||
"#F28AAF", "#9B8CF5", "#66C7A5", "#67B9EF", "#F4A174", "#EECF67", "#C58EC4", "#E789A5", "#20212B", "#8F8F9B",
|
||||
)
|
||||
Row(Modifier.fillMaxWidth().clickable { open = !open }, verticalAlignment = Alignment.CenterVertically) {
|
||||
Text(label, fontSize = 14.sp, color = Kit.colors.ink, modifier = Modifier.weight(1f))
|
||||
Box(Modifier.size(24.dp).clip(CircleShape).background(Kit.parse(color)).border(1.dp, Kit.colors.line, CircleShape))
|
||||
Spacer(Modifier.width(6.dp))
|
||||
Text(color, fontSize = 13.sp, color = Kit.colors.muted)
|
||||
}
|
||||
if (open) {
|
||||
Row(Modifier.fillMaxWidth(), horizontalArrangement = Arrangement.spacedBy(8.dp)) {
|
||||
swatches.forEach { value ->
|
||||
Box(
|
||||
Modifier
|
||||
.size(28.dp)
|
||||
.clip(CircleShape)
|
||||
.background(Kit.parse(value))
|
||||
.clickable { onColorChange(value) },
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Composable
|
||||
private fun QuantityControl(
|
||||
quantity: String,
|
||||
onQuantityChange: (String) -> Unit,
|
||||
onDecrease: () -> Unit,
|
||||
onIncrease: () -> Unit,
|
||||
) {
|
||||
Row(Modifier.fillMaxWidth(), verticalAlignment = Alignment.CenterVertically) {
|
||||
Text(L10n.text("ledger.quantity"), fontSize = 14.sp, color = Kit.colors.ink, modifier = Modifier.weight(1f))
|
||||
Icon(Icons.Filled.Remove, contentDescription = null, tint = Kit.colors.accentText,
|
||||
modifier = Modifier.size(24.dp).clickable(onClick = onDecrease))
|
||||
Box(Modifier.width(60.dp), contentAlignment = Alignment.Center) {
|
||||
TextFieldValue(quantity, onQuantityChange, KeyboardType.Number,
|
||||
androidx.compose.ui.text.style.TextAlign.Center)
|
||||
}
|
||||
Icon(Icons.Filled.Add, contentDescription = null, tint = Kit.colors.accentText,
|
||||
modifier = Modifier.size(24.dp).clickable(onClick = onIncrease))
|
||||
}
|
||||
}
|
||||
|
||||
/** Favorite shortcuts above the complete, grouped catalog, as the iOS picker shows them. */
|
||||
@Composable
|
||||
private fun MembershipPicker(
|
||||
document: com.oshicue.keeps.core.LedgerDocument,
|
||||
record: LedgerRecord?,
|
||||
selection: String,
|
||||
onSelect: (String) -> Unit,
|
||||
onDismiss: () -> Unit,
|
||||
) {
|
||||
var query by remember { mutableStateOf("") }
|
||||
AlertDialog(
|
||||
onDismissRequest = onDismiss,
|
||||
title = { Text(L10n.text("ledger.chooseMember"), fontWeight = FontWeight.Bold) },
|
||||
text = {
|
||||
Column(Modifier.heightIn(max = 440.dp), verticalArrangement = Arrangement.spacedBy(10.dp)) {
|
||||
TextFieldValue(query, { query = it }, modifier = Modifier.fillMaxWidth())
|
||||
LazyColumn(verticalArrangement = Arrangement.spacedBy(6.dp)) {
|
||||
val favorites = document.favoriteMemberships.filter { it.matches(document, query) }
|
||||
if (favorites.isNotEmpty()) {
|
||||
item {
|
||||
Row(verticalAlignment = Alignment.CenterVertically) {
|
||||
Icon(Icons.Filled.Star, contentDescription = null, tint = Kit.colors.accentText,
|
||||
modifier = Modifier.size(13.dp))
|
||||
Spacer(Modifier.width(5.dp))
|
||||
Text(L10n.text("ledger.members.favorites"), fontSize = 11.sp, color = Kit.colors.muted)
|
||||
}
|
||||
}
|
||||
items(favorites, key = { it.id }) { item ->
|
||||
MembershipRow(document, item, selection == item.id) { onSelect(item.id) }
|
||||
}
|
||||
}
|
||||
document.recordMembershipGroups(record).forEach { group ->
|
||||
val choices = document.recordMembershipChoices(group.id, record)
|
||||
.filter { it.matches(document, query) }
|
||||
if (choices.isNotEmpty()) {
|
||||
item {
|
||||
Text(group.name, fontSize = 11.sp, fontWeight = FontWeight.Bold, color = Kit.colors.muted)
|
||||
}
|
||||
items(choices, key = { it.id }) { item ->
|
||||
MembershipRow(document, item, selection == item.id) { onSelect(item.id) }
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
confirmButton = {
|
||||
TextButton(onClick = onDismiss) { Text(L10n.text("common.cancel")) }
|
||||
},
|
||||
containerColor = Kit.colors.surface,
|
||||
)
|
||||
}
|
||||
|
||||
private fun LedgerMembership.matches(
|
||||
document: com.oshicue.keeps.core.LedgerDocument,
|
||||
query: String,
|
||||
): Boolean {
|
||||
if (query.isBlank()) return true
|
||||
val memberName = document.members.firstOrNull { it.id == memberID }?.name ?: ""
|
||||
val groupName = document.groups.firstOrNull { it.id == groupID }?.name ?: ""
|
||||
return com.oshicue.keeps.core.TextNormalizer.contains(memberName + " " + groupName, query)
|
||||
}
|
||||
|
||||
@Composable
|
||||
private fun MembershipRow(
|
||||
document: com.oshicue.keeps.core.LedgerDocument,
|
||||
item: LedgerMembership,
|
||||
selected: Boolean,
|
||||
onClick: () -> Unit,
|
||||
) {
|
||||
val member = document.members.firstOrNull { it.id == item.memberID }
|
||||
val group = document.groups.firstOrNull { it.id == item.groupID }
|
||||
val available = document.activeMemberships.any { it.id == item.id }
|
||||
Row(
|
||||
Modifier.fillMaxWidth().clickable(onClick = onClick).padding(vertical = 6.dp),
|
||||
verticalAlignment = Alignment.CenterVertically,
|
||||
) {
|
||||
LedgerAvatar(member, item.color, 42.dp)
|
||||
Spacer(Modifier.width(12.dp))
|
||||
Column(Modifier.weight(1f), verticalArrangement = Arrangement.spacedBy(3.dp)) {
|
||||
Row(verticalAlignment = Alignment.CenterVertically) {
|
||||
Text(member?.name ?: "", fontSize = 14.sp, fontWeight = FontWeight.SemiBold, color = Kit.colors.ink)
|
||||
if (member?.isFavorited == true) {
|
||||
Spacer(Modifier.width(5.dp))
|
||||
Icon(Icons.Filled.Star, contentDescription = null, tint = Kit.colors.accentText,
|
||||
modifier = Modifier.size(12.dp))
|
||||
}
|
||||
}
|
||||
Text(group?.name ?: "", fontSize = 12.sp, color = Kit.colors.muted)
|
||||
if (!available) Text(L10n.text("ledger.deleted"), fontSize = 11.sp, color = Kit.colors.muted)
|
||||
}
|
||||
if (selected) {
|
||||
Icon(Icons.Filled.Check, contentDescription = null, tint = Kit.colors.accentText, modifier = Modifier.size(18.dp))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Composable
|
||||
private fun ChoiceDialog(
|
||||
title: String,
|
||||
options: List<Pair<String, String>>,
|
||||
selection: String,
|
||||
onSelect: (String) -> Unit,
|
||||
onDismiss: () -> Unit,
|
||||
) {
|
||||
AlertDialog(
|
||||
onDismissRequest = onDismiss,
|
||||
title = { Text(title, fontWeight = FontWeight.Bold) },
|
||||
text = {
|
||||
LazyColumn(Modifier.heightIn(max = 420.dp)) {
|
||||
items(options, key = { it.first }) { (id, label) ->
|
||||
Row(
|
||||
Modifier.fillMaxWidth().clickable { onSelect(id) }.padding(vertical = 11.dp),
|
||||
verticalAlignment = Alignment.CenterVertically,
|
||||
) {
|
||||
Text(label, fontSize = 14.sp, color = Kit.colors.ink, modifier = Modifier.weight(1f))
|
||||
if (id == selection) {
|
||||
Icon(Icons.Filled.Check, contentDescription = null, tint = Kit.colors.accentText,
|
||||
modifier = Modifier.size(17.dp))
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
confirmButton = {
|
||||
TextButton(onClick = onDismiss) { Text(L10n.text("common.cancel")) }
|
||||
},
|
||||
containerColor = Kit.colors.surface,
|
||||
)
|
||||
}
|
||||
@@ -0,0 +1,412 @@
|
||||
package com.oshicue.keeps.ui
|
||||
|
||||
import androidx.compose.foundation.background
|
||||
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.Spacer
|
||||
import androidx.compose.foundation.layout.fillMaxSize
|
||||
import androidx.compose.foundation.layout.fillMaxWidth
|
||||
import androidx.compose.foundation.layout.height
|
||||
import androidx.compose.foundation.layout.heightIn
|
||||
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.RoundedCornerShape
|
||||
import androidx.compose.foundation.verticalScroll
|
||||
import androidx.compose.material.icons.Icons
|
||||
import androidx.compose.material.icons.automirrored.filled.KeyboardArrowLeft
|
||||
import androidx.compose.material.icons.automirrored.filled.KeyboardArrowRight
|
||||
import androidx.compose.material.icons.filled.Check
|
||||
import androidx.compose.material3.AlertDialog
|
||||
import androidx.compose.material3.Icon
|
||||
import androidx.compose.material3.Text
|
||||
import androidx.compose.material3.TextButton
|
||||
import androidx.compose.runtime.Composable
|
||||
import androidx.compose.runtime.LaunchedEffect
|
||||
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.graphics.Color
|
||||
import androidx.compose.ui.text.font.FontWeight
|
||||
import androidx.compose.ui.text.style.TextAlign
|
||||
import androidx.compose.ui.text.style.TextOverflow
|
||||
import androidx.compose.ui.unit.dp
|
||||
import androidx.compose.ui.unit.sp
|
||||
import androidx.lifecycle.compose.collectAsStateWithLifecycle
|
||||
import com.oshicue.keeps.core.KitDate
|
||||
import com.oshicue.keeps.core.L10n
|
||||
import com.oshicue.keeps.core.LedgerAnalytics
|
||||
import com.oshicue.keeps.core.LedgerCurrency
|
||||
import com.oshicue.keeps.core.LedgerDates
|
||||
import com.oshicue.keeps.core.LedgerGrouping
|
||||
import com.oshicue.keeps.core.LedgerMetric
|
||||
import com.oshicue.keeps.core.LedgerPeriod
|
||||
import com.oshicue.keeps.core.LedgerPresentation
|
||||
import com.oshicue.keeps.core.LedgerRankRow
|
||||
import com.oshicue.keeps.core.LedgerRecord
|
||||
import java.time.LocalDate
|
||||
import java.time.YearMonth
|
||||
import java.time.ZoneId
|
||||
|
||||
/** The 统计 tab: period, ranking and metric controls over one ranked list. */
|
||||
@Composable
|
||||
fun LedgerStatisticsScreen(store: LedgerStore, referenceDate: LocalDate) {
|
||||
val state by store.state.collectAsStateWithLifecycle()
|
||||
val document = state.document
|
||||
|
||||
var period by remember { mutableStateOf(LedgerPeriod.Month) }
|
||||
var grouping by remember { mutableStateOf(LedgerGrouping.MemberCombined) }
|
||||
var metric by remember { mutableStateOf(LedgerMetric.Quantity) }
|
||||
var currency by remember { mutableStateOf("JPY") }
|
||||
var productID by remember { mutableStateOf("") }
|
||||
var groupID by remember { mutableStateOf("") }
|
||||
var anchor by remember { mutableStateOf(referenceDate) }
|
||||
var datePickerOpen by remember { mutableStateOf(false) }
|
||||
var menu by remember { mutableStateOf<String?>(null) }
|
||||
|
||||
// The shared selected day sets the starting period; later moves stay on this page.
|
||||
LaunchedEffect(referenceDate) { anchor = referenceDate }
|
||||
|
||||
val records = remember(document.records, period, anchor, metric, currency, productID, groupID) {
|
||||
LedgerAnalytics.filtered(
|
||||
document.records, period, LedgerDates.string(anchor),
|
||||
currency = if (metric == LedgerMetric.Spending) currency else null,
|
||||
).filter {
|
||||
(productID.isEmpty() || it.productID == productID) && (groupID.isEmpty() || it.groupID == groupID)
|
||||
}
|
||||
}
|
||||
val summary = remember(records) { runCatching { LedgerAnalytics.summarize(records) }.getOrNull() }
|
||||
val rows = remember(records, grouping, metric, currency) {
|
||||
runCatching {
|
||||
LedgerAnalytics.rankings(records, grouping, metric,
|
||||
currency = if (metric == LedgerMetric.Spending) currency else null)
|
||||
}.getOrDefault(emptyList())
|
||||
}
|
||||
fun move(offset: Int = -1) {
|
||||
anchor = when (period) {
|
||||
LedgerPeriod.Day -> anchor.plusDays(offset.toLong())
|
||||
LedgerPeriod.Month -> anchor.plusMonths(offset.toLong())
|
||||
LedgerPeriod.Year -> anchor.plusYears(offset.toLong())
|
||||
LedgerPeriod.Lifetime -> anchor
|
||||
}
|
||||
}
|
||||
|
||||
val periodTitle = when (period) {
|
||||
LedgerPeriod.Day -> KitDate.string(anchor.atStartOfDay(ZoneId.systemDefault()).toInstant(), "yyyy MMM d", ZoneId.systemDefault())
|
||||
LedgerPeriod.Month -> KitDate.string(anchor.atStartOfDay(ZoneId.systemDefault()).toInstant(), "yyyy MMMM", ZoneId.systemDefault())
|
||||
LedgerPeriod.Year -> anchor.year.toString()
|
||||
LedgerPeriod.Lifetime -> L10n.text("ledger.lifetime")
|
||||
}
|
||||
|
||||
Column(Modifier.fillMaxSize().background(Kit.colors.background)) {
|
||||
Column(
|
||||
Modifier.fillMaxSize().verticalScroll(rememberScrollState()).padding(horizontal = 20.dp).padding(bottom = 35.dp),
|
||||
verticalArrangement = Arrangement.spacedBy(16.dp),
|
||||
) {
|
||||
Text(L10n.text("ledger.stats"), style = KitTitleStyle, color = Kit.colors.ink)
|
||||
|
||||
SegmentedControl(
|
||||
listOf(
|
||||
L10n.text("ledger.day") to LedgerPeriod.Day,
|
||||
L10n.text("ledger.month") to LedgerPeriod.Month,
|
||||
L10n.text("ledger.year") to LedgerPeriod.Year,
|
||||
L10n.text("ledger.lifetime") to LedgerPeriod.Lifetime,
|
||||
),
|
||||
period,
|
||||
) { period = it }
|
||||
|
||||
Row(
|
||||
Modifier.fillMaxWidth().clip(RoundedCornerShape(14.dp)).background(Kit.colors.surface).padding(10.dp),
|
||||
verticalAlignment = Alignment.CenterVertically,
|
||||
) {
|
||||
Icon(Icons.AutoMirrored.Filled.KeyboardArrowLeft, contentDescription = null,
|
||||
tint = if (period == LedgerPeriod.Lifetime) Kit.colors.muted else Kit.colors.ink,
|
||||
modifier = Modifier.size(26.dp).clickable(enabled = period != LedgerPeriod.Lifetime) { move() })
|
||||
Spacer(Modifier.weight(1f))
|
||||
Text(
|
||||
periodTitle, fontSize = 18.sp, fontWeight = FontWeight.Bold, color = Kit.colors.ink,
|
||||
modifier = Modifier.clickable(enabled = period != LedgerPeriod.Lifetime) { datePickerOpen = true },
|
||||
)
|
||||
Spacer(Modifier.weight(1f))
|
||||
Icon(Icons.AutoMirrored.Filled.KeyboardArrowRight, contentDescription = null,
|
||||
tint = if (period == LedgerPeriod.Lifetime) Kit.colors.muted else Kit.colors.ink,
|
||||
modifier = Modifier.size(26.dp).clickable(enabled = period != LedgerPeriod.Lifetime) { move(+1) })
|
||||
}
|
||||
|
||||
Column(
|
||||
Modifier.fillMaxWidth().clip(RoundedCornerShape(16.dp)).background(Kit.colors.surface).padding(14.dp),
|
||||
verticalArrangement = Arrangement.spacedBy(12.dp),
|
||||
) {
|
||||
SegmentedControl(
|
||||
listOf(
|
||||
L10n.text("ledger.memberCombined") to LedgerGrouping.MemberCombined,
|
||||
L10n.text("ledger.memberByGroup") to LedgerGrouping.MemberByGroup,
|
||||
L10n.text("ledger.group") to LedgerGrouping.Group,
|
||||
),
|
||||
grouping,
|
||||
) { grouping = it }
|
||||
SegmentedControl(
|
||||
listOf(
|
||||
L10n.text("ledger.quantity") to LedgerMetric.Quantity,
|
||||
L10n.text("ledger.spending") to LedgerMetric.Spending,
|
||||
),
|
||||
metric,
|
||||
) { metric = it }
|
||||
Row(horizontalArrangement = Arrangement.spacedBy(12.dp)) {
|
||||
Text(
|
||||
if (productID.isEmpty()) L10n.text("ledger.allTypes")
|
||||
else document.products.firstOrNull { it.id == productID }
|
||||
?.let { LedgerPresentation.productName(it.id, it.name) } ?: "",
|
||||
fontSize = 11.sp, fontWeight = FontWeight.Medium, color = Kit.colors.ink,
|
||||
maxLines = 1, overflow = TextOverflow.Ellipsis,
|
||||
modifier = Modifier
|
||||
.clip(RoundedCornerShape(9.dp))
|
||||
.background(Kit.colors.background)
|
||||
.clickable { menu = "product" }
|
||||
.padding(horizontal = 10.dp, vertical = 7.dp),
|
||||
)
|
||||
Text(
|
||||
if (groupID.isEmpty()) L10n.text("ledger.allGroups")
|
||||
else document.groups.firstOrNull { it.id == groupID }?.name ?: "",
|
||||
fontSize = 11.sp, fontWeight = FontWeight.Medium, color = Kit.colors.ink,
|
||||
maxLines = 1, overflow = TextOverflow.Ellipsis,
|
||||
modifier = Modifier
|
||||
.clip(RoundedCornerShape(9.dp))
|
||||
.background(Kit.colors.background)
|
||||
.clickable { menu = "group" }
|
||||
.padding(horizontal = 10.dp, vertical = 7.dp),
|
||||
)
|
||||
}
|
||||
if (metric == LedgerMetric.Spending) {
|
||||
Text(
|
||||
L10n.text("ledger.currency") + " · " + currency,
|
||||
fontSize = 11.sp, fontWeight = FontWeight.SemiBold, color = Kit.colors.accentText,
|
||||
modifier = Modifier
|
||||
.clip(RoundedCornerShape(9.dp))
|
||||
.background(Kit.colors.background)
|
||||
.clickable { menu = "currency" }
|
||||
.padding(horizontal = 10.dp, vertical = 7.dp),
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
Text(
|
||||
L10n.text(if (grouping == LedgerGrouping.MemberByGroup) "ledger.splitHint" else "ledger.combinedHint"),
|
||||
fontSize = 10.sp, color = Kit.colors.muted,
|
||||
)
|
||||
|
||||
Row(Modifier.fillMaxWidth().padding(horizontal = 4.dp), verticalAlignment = Alignment.CenterVertically) {
|
||||
Text(L10n.text("ledger.total"), fontSize = 11.sp, fontWeight = FontWeight.Medium, color = Kit.colors.muted)
|
||||
Spacer(Modifier.weight(1f))
|
||||
Text(
|
||||
if (metric == LedgerMetric.Quantity) L10n.format("ledger.itemsCount", summary?.quantity ?: 0)
|
||||
else amount(currency, summary?.amountsByCurrency?.get(currency)),
|
||||
fontSize = 18.sp, fontWeight = FontWeight.Bold, color = Kit.colors.ink,
|
||||
)
|
||||
Spacer(Modifier.width(6.dp))
|
||||
Text(L10n.format("ledger.membersCount", summary?.memberCount ?: 0), fontSize = 10.sp, color = Kit.colors.muted)
|
||||
}
|
||||
|
||||
if (rows.isEmpty()) {
|
||||
Column(
|
||||
Modifier.fillMaxWidth().padding(30.dp),
|
||||
horizontalAlignment = Alignment.CenterHorizontally,
|
||||
verticalArrangement = Arrangement.spacedBy(8.dp),
|
||||
) {
|
||||
Text(L10n.text("ledger.noRecords"), fontSize = 14.sp, fontWeight = FontWeight.SemiBold, color = Kit.colors.ink)
|
||||
Text(L10n.text("ledger.noRecordsHint"), fontSize = 12.sp, color = Kit.colors.muted, textAlign = TextAlign.Center)
|
||||
}
|
||||
} else {
|
||||
Column(
|
||||
Modifier.fillMaxWidth().clip(RoundedCornerShape(18.dp)).background(Kit.colors.surface).padding(15.dp),
|
||||
) {
|
||||
rows.forEach { row ->
|
||||
RankRowView(row, metric, currency, document.members.firstOrNull { it.id == row.memberID })
|
||||
if (row.id != rows.last().id) {
|
||||
Box(Modifier.fillMaxWidth().padding(start = 52.dp).height(1.dp).background(Kit.colors.line))
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Text(L10n.text("ledger.currencyHint"), fontSize = 10.sp, color = Kit.colors.muted)
|
||||
}
|
||||
}
|
||||
|
||||
when (menu) {
|
||||
"product" -> ChoiceList(
|
||||
title = L10n.text("ledger.type"),
|
||||
options = listOf("" to L10n.text("ledger.allTypes")) +
|
||||
document.products.map { it.id to LedgerPresentation.productName(it.id, it.name) },
|
||||
selection = productID,
|
||||
onSelect = { productID = it; menu = null },
|
||||
onDismiss = { menu = null },
|
||||
)
|
||||
"group" -> ChoiceList(
|
||||
title = L10n.text("ledger.group"),
|
||||
options = listOf("" to L10n.text("ledger.allGroups")) + document.groups.map { it.id to it.name },
|
||||
selection = groupID,
|
||||
onSelect = { groupID = it; menu = null },
|
||||
onDismiss = { menu = null },
|
||||
)
|
||||
"currency" -> ChoiceList(
|
||||
title = L10n.text("ledger.currency"),
|
||||
options = LedgerCurrency.entries.map { it.name to it.name },
|
||||
selection = currency,
|
||||
onSelect = { currency = it; menu = null },
|
||||
onDismiss = { menu = null },
|
||||
)
|
||||
}
|
||||
|
||||
if (datePickerOpen) {
|
||||
val pickerState = androidx.compose.material3.rememberDatePickerState(
|
||||
initialSelectedDateMillis = anchor.atStartOfDay(ZoneId.of("UTC")).toInstant().toEpochMilli(),
|
||||
)
|
||||
androidx.compose.material3.DatePickerDialog(
|
||||
onDismissRequest = { datePickerOpen = false },
|
||||
confirmButton = {
|
||||
TextButton(onClick = {
|
||||
pickerState.selectedDateMillis?.let {
|
||||
anchor = java.time.Instant.ofEpochMilli(it).atZone(ZoneId.of("UTC")).toLocalDate()
|
||||
}
|
||||
datePickerOpen = false
|
||||
}) { Text(L10n.text("common.done")) }
|
||||
},
|
||||
dismissButton = { TextButton(onClick = { datePickerOpen = false }) { Text(L10n.text("common.cancel")) } },
|
||||
) { androidx.compose.material3.DatePicker(state = pickerState) }
|
||||
}
|
||||
}
|
||||
|
||||
@Composable
|
||||
fun <T> SegmentedControl(options: List<Pair<String, T>>, selection: T, onSelect: (T) -> Unit) {
|
||||
Row(
|
||||
Modifier.fillMaxWidth().clip(RoundedCornerShape(11.dp)).background(Kit.colors.surfaceMuted).padding(4.dp),
|
||||
horizontalArrangement = Arrangement.spacedBy(3.dp),
|
||||
) {
|
||||
options.forEach { (label, value) ->
|
||||
val active = value == selection
|
||||
Text(
|
||||
label, fontSize = 12.sp, fontWeight = FontWeight.SemiBold,
|
||||
color = if (active) Kit.colors.onAccent else Kit.colors.ink,
|
||||
textAlign = TextAlign.Center,
|
||||
maxLines = 1, overflow = TextOverflow.Ellipsis,
|
||||
modifier = Modifier
|
||||
.weight(1f)
|
||||
.clip(RoundedCornerShape(8.dp))
|
||||
.background(if (active) Kit.colors.accentFill else Color.Transparent)
|
||||
.clickable { onSelect(value) }
|
||||
.padding(vertical = 8.dp, horizontal = 2.dp),
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Composable
|
||||
private fun RankRowView(
|
||||
row: LedgerRankRow,
|
||||
metric: LedgerMetric,
|
||||
currency: String,
|
||||
member: com.oshicue.keeps.core.LedgerMember?,
|
||||
) {
|
||||
Column(Modifier.padding(vertical = 14.dp)) {
|
||||
Row(verticalAlignment = Alignment.Top) {
|
||||
Text(
|
||||
row.rank.toString(), fontSize = 11.sp, fontWeight = FontWeight.Bold,
|
||||
color = if (row.rank <= 3) Kit.colors.accentText else Kit.colors.muted,
|
||||
modifier = Modifier.width(16.dp).padding(top = 12.dp),
|
||||
)
|
||||
LedgerAvatar(member, row.color, 36.dp)
|
||||
Spacer(Modifier.width(11.dp))
|
||||
Column(Modifier.weight(1f), verticalArrangement = Arrangement.spacedBy(5.dp)) {
|
||||
Row {
|
||||
Text(row.name, fontSize = 14.sp, fontWeight = FontWeight.SemiBold, color = Kit.colors.ink,
|
||||
modifier = Modifier.weight(1f))
|
||||
Text(
|
||||
if (metric == LedgerMetric.Quantity) row.quantity.toString()
|
||||
else amount(currency, row.amountsByCurrency[currency]),
|
||||
fontSize = 15.sp, fontWeight = FontWeight.Bold, color = Kit.colors.ink,
|
||||
maxLines = 1, overflow = TextOverflow.Ellipsis,
|
||||
)
|
||||
}
|
||||
Row {
|
||||
Text(row.subtitle, fontSize = 10.sp, color = Kit.colors.muted, maxLines = 2,
|
||||
overflow = TextOverflow.Ellipsis, modifier = Modifier.weight(1f))
|
||||
Text(String.format(java.util.Locale.ROOT, "%.1f%%", row.share * 100),
|
||||
fontSize = 9.sp, color = Kit.colors.muted)
|
||||
}
|
||||
Row(horizontalArrangement = Arrangement.spacedBy(5.dp)) {
|
||||
row.productRows.forEach { product ->
|
||||
Text(
|
||||
LedgerPresentation.productName(product.id, product.name) + " × " + product.quantity,
|
||||
fontSize = 9.sp, color = Kit.colors.ink,
|
||||
modifier = Modifier
|
||||
.clip(RoundedCornerShape(50))
|
||||
.background(Kit.colors.background)
|
||||
.padding(horizontal = 7.dp, vertical = 4.dp),
|
||||
)
|
||||
}
|
||||
}
|
||||
// The bar length is the row's share of the selected total.
|
||||
Box(
|
||||
Modifier
|
||||
.fillMaxWidth()
|
||||
.padding(top = 5.dp)
|
||||
.height(3.dp)
|
||||
.clip(RoundedCornerShape(50))
|
||||
.background(Kit.parse(row.color).copy(alpha = 0.17f)),
|
||||
) {
|
||||
Box(
|
||||
Modifier
|
||||
.fillMaxWidth(row.share.toFloat().coerceIn(0.01f, 1f))
|
||||
.height(3.dp)
|
||||
.clip(RoundedCornerShape(50))
|
||||
.background(Kit.readableDataColor(row.color)),
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private fun amount(currency: String, minor: Long?): String =
|
||||
runCatching { LedgerCurrency.valueOf(currency) }.getOrNull()
|
||||
?.let { LedgerPresentation.format(it, minor ?: 0) } ?: "—"
|
||||
|
||||
@Composable
|
||||
fun ChoiceList(
|
||||
title: String,
|
||||
options: List<Pair<String, String>>,
|
||||
selection: String,
|
||||
onSelect: (String) -> Unit,
|
||||
onDismiss: () -> Unit,
|
||||
) {
|
||||
AlertDialog(
|
||||
onDismissRequest = onDismiss,
|
||||
title = { Text(title, fontWeight = FontWeight.Bold) },
|
||||
text = {
|
||||
Column(Modifier.heightIn(max = 420.dp).verticalScroll(rememberScrollState())) {
|
||||
options.forEach { (id, label) ->
|
||||
Row(
|
||||
Modifier.fillMaxWidth().clickable { onSelect(id) }.padding(vertical = 11.dp),
|
||||
verticalAlignment = Alignment.CenterVertically,
|
||||
) {
|
||||
Text(label, fontSize = 14.sp, color = Kit.colors.ink, modifier = Modifier.weight(1f))
|
||||
if (id == selection) {
|
||||
Icon(Icons.Filled.Check, contentDescription = null, tint = Kit.colors.accentText,
|
||||
modifier = Modifier.size(17.dp))
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
confirmButton = { TextButton(onClick = onDismiss) { Text(L10n.text("common.cancel")) } },
|
||||
containerColor = Kit.colors.surface,
|
||||
)
|
||||
}
|
||||
@@ -0,0 +1,285 @@
|
||||
package com.oshicue.keeps.ui
|
||||
|
||||
import android.content.Context
|
||||
import androidx.lifecycle.ViewModel
|
||||
import androidx.lifecycle.ViewModelProvider
|
||||
import com.oshicue.keeps.core.KitPresentation
|
||||
import com.oshicue.keeps.core.L10n
|
||||
import com.oshicue.keeps.core.LedgerDocument
|
||||
import com.oshicue.keeps.core.LedgerGroup
|
||||
import com.oshicue.keeps.core.LedgerEvent
|
||||
import com.oshicue.keeps.core.LedgerImporter
|
||||
import com.oshicue.keeps.core.LedgerMember
|
||||
import com.oshicue.keeps.core.LedgerMembership
|
||||
import com.oshicue.keeps.core.LedgerPrice
|
||||
import com.oshicue.keeps.core.LedgerPriceSuggestions
|
||||
import com.oshicue.keeps.core.LedgerProduct
|
||||
import com.oshicue.keeps.core.LedgerRecord
|
||||
import com.oshicue.keeps.core.activeGroups
|
||||
import com.oshicue.keeps.core.activeMembers
|
||||
import com.oshicue.keeps.core.activeMemberships
|
||||
import com.oshicue.keeps.core.addingQuantity
|
||||
import com.oshicue.keeps.core.deletingGroups
|
||||
import com.oshicue.keeps.core.deletingMembers
|
||||
import com.oshicue.keeps.core.deletingRecords
|
||||
import com.oshicue.keeps.core.LedgerDemo
|
||||
import kotlinx.coroutines.flow.MutableStateFlow
|
||||
import kotlinx.coroutines.flow.StateFlow
|
||||
import kotlinx.coroutines.flow.asStateFlow
|
||||
import kotlinx.serialization.SerialName
|
||||
import kotlinx.serialization.Serializable
|
||||
import kotlinx.serialization.json.Json
|
||||
import java.io.File
|
||||
|
||||
@Serializable
|
||||
private data class SavedState(
|
||||
val document: LedgerDocument,
|
||||
val isDemo: Boolean,
|
||||
val hasUserEdits: Boolean? = null,
|
||||
/** App-only preferences; exported LedgerDocument JSON remains schema version 1. */
|
||||
val lastAddedPrices: List<LedgerPrice>? = null,
|
||||
)
|
||||
|
||||
data class LedgerUiState(
|
||||
val document: LedgerDocument = LedgerDocument(products = LedgerDocument.defaultProducts),
|
||||
val isDemo: Boolean = false,
|
||||
val storageError: String? = null,
|
||||
)
|
||||
|
||||
/**
|
||||
* The ledger is independent of festival schedules. A failed save never publishes a partial edit:
|
||||
* the complete candidate is validated and written first, then published.
|
||||
*/
|
||||
class LedgerStore(context: Context) : ViewModel() {
|
||||
private val file = File(File(context.applicationContext.filesDir, "OshicueKeeps"), "ledger.json")
|
||||
private val json = Json {
|
||||
ignoreUnknownKeys = true
|
||||
prettyPrint = true
|
||||
encodeDefaults = true
|
||||
}
|
||||
private val _state = MutableStateFlow(LedgerUiState())
|
||||
val state: StateFlow<LedgerUiState> = _state.asStateFlow()
|
||||
|
||||
private var lastAddedPrices: List<LedgerPrice> = emptyList()
|
||||
private var hasUserEdits = false
|
||||
|
||||
val canReplaceDemo: Boolean get() = _state.value.isDemo && !hasUserEdits
|
||||
|
||||
init {
|
||||
if (!file.exists()) {
|
||||
// First launch: fictional members and purchases dated around today, shown even if this write fails.
|
||||
val document = LedgerDemo.document()
|
||||
val prices = LedgerPriceSuggestions.seededPrices(document.records)
|
||||
_state.value = LedgerUiState(document = document, isDemo = true)
|
||||
lastAddedPrices = prices
|
||||
runCatching { persist(document, demo = true, userEdits = false, prices = prices) }
|
||||
.onFailure { _state.value = _state.value.copy(storageError = L10n.text("settings.storageError") + "\n" + it.message) }
|
||||
} else {
|
||||
runCatching {
|
||||
val saved = json.decodeFromString(SavedState.serializer(), file.readText())
|
||||
LedgerImporter.validate(saved.document)
|
||||
saved
|
||||
}.onSuccess { saved ->
|
||||
_state.value = LedgerUiState(document = saved.document, isDemo = saved.isDemo)
|
||||
hasUserEdits = saved.hasUserEdits ?: false
|
||||
lastAddedPrices = saved.lastAddedPrices ?: LedgerPriceSuggestions.seededPrices(saved.document.records)
|
||||
}.onFailure { error ->
|
||||
_state.value = _state.value.copy(
|
||||
storageError = L10n.text("settings.readError") + "\n" + KitPresentation.error(error),
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
val document: LedgerDocument get() = _state.value.document
|
||||
val prices: List<LedgerPrice> get() = lastAddedPrices
|
||||
|
||||
/** Validates the complete candidate and atomically persists it before updating observers. */
|
||||
fun commit(update: (LedgerDocument) -> LedgerDocument): Boolean = runCatching {
|
||||
val candidate = update(document)
|
||||
save(candidate, demo = _state.value.isDemo, userEdits = hasUserEdits || _state.value.isDemo, prices = lastAddedPrices)
|
||||
true
|
||||
}.getOrElse { error ->
|
||||
_state.value = _state.value.copy(storageError = KitPresentation.error(error))
|
||||
false
|
||||
}
|
||||
|
||||
fun importDocument(incoming: LedgerDocument): Boolean = runCatching {
|
||||
val replaceDemo = canReplaceDemo
|
||||
val candidate = if (replaceDemo) {
|
||||
LedgerImporter.validate(incoming)
|
||||
incoming
|
||||
} else {
|
||||
document.merging(incoming)
|
||||
}
|
||||
val includesDemo = _state.value.isDemo && !replaceDemo
|
||||
save(candidate, demo = includesDemo, userEdits = includesDemo && hasUserEdits,
|
||||
prices = if (replaceDemo) LedgerPriceSuggestions.seededPrices(candidate.records) else lastAddedPrices)
|
||||
true
|
||||
}.getOrElse { error ->
|
||||
_state.value = _state.value.copy(storageError = KitPresentation.error(error))
|
||||
false
|
||||
}
|
||||
|
||||
/** Example purchases are loaded only into an empty ledger, or into the existing example ledger. */
|
||||
fun loadDemo(): Boolean {
|
||||
val current = document
|
||||
val empty = current.groups.isEmpty() && current.members.isEmpty() && current.memberships.isEmpty() &&
|
||||
current.records.isEmpty() && current.events.isEmpty() &&
|
||||
(current.products.isEmpty() || current.products == LedgerDocument.defaultProducts)
|
||||
if (!canReplaceDemo && !empty) {
|
||||
_state.value = _state.value.copy(storageError = L10n.text("ledger.demoRequiresEmpty"))
|
||||
return false
|
||||
}
|
||||
return runCatching {
|
||||
val candidate = LedgerDemo.document()
|
||||
save(candidate, demo = true, userEdits = false, prices = LedgerPriceSuggestions.seededPrices(candidate.records))
|
||||
true
|
||||
}.getOrElse { error ->
|
||||
_state.value = _state.value.copy(storageError = KitPresentation.error(error))
|
||||
false
|
||||
}
|
||||
}
|
||||
|
||||
fun upsertGroup(value: LedgerGroup): Boolean {
|
||||
if (!value.isActive || document.groups.firstOrNull { it.id == value.id }?.isActive == false) return unavailableCatalog()
|
||||
return commit { it.copy(groups = upsert(it.groups, value) { g -> g.id }) }
|
||||
}
|
||||
|
||||
fun upsertMember(value: LedgerMember): Boolean {
|
||||
if (!value.isActive || document.members.firstOrNull { it.id == value.id }?.isActive == false) return unavailableCatalog()
|
||||
return commit { it.copy(members = upsert(it.members, value) { m -> m.id }) }
|
||||
}
|
||||
|
||||
fun upsertMembership(value: LedgerMembership): Boolean {
|
||||
if (!value.isActive ||
|
||||
document.memberships.firstOrNull { it.id == value.id }?.isActive == false ||
|
||||
document.activeMembers.none { it.id == value.memberID } ||
|
||||
document.activeGroups.none { it.id == value.groupID }
|
||||
) return unavailableCatalog()
|
||||
return commit { it.copy(memberships = upsert(it.memberships, value) { m -> m.id }) }
|
||||
}
|
||||
|
||||
fun upsertProduct(value: LedgerProduct): Boolean =
|
||||
commit { it.copy(products = upsert(it.products, value) { p -> p.id }) }
|
||||
|
||||
fun upsertEvent(value: LedgerEvent): Boolean =
|
||||
commit { it.copy(events = upsert(it.events, value) { e -> e.id }) }
|
||||
|
||||
fun saveMember(value: LedgerMember, membership: LedgerMembership): Boolean {
|
||||
if (!value.isActive || !membership.isActive || membership.memberID != value.id ||
|
||||
document.members.firstOrNull { it.id == value.id }?.isActive == false ||
|
||||
document.memberships.firstOrNull { it.id == membership.id }?.isActive == false ||
|
||||
document.activeGroups.none { it.id == membership.groupID }
|
||||
) return unavailableCatalog()
|
||||
return commit {
|
||||
it.copy(
|
||||
members = upsert(it.members, value) { m -> m.id },
|
||||
memberships = upsert(it.memberships, membership) { m -> m.id },
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
fun saveRecord(value: LedgerRecord): Boolean {
|
||||
// A historic purchase stays editable after catalog deletion. A new or reassigned purchase
|
||||
// must use an active affiliation, including when a stale editor was open during deletion.
|
||||
val original = document.records.firstOrNull { it.id == value.id }
|
||||
val keepsHistoricalAffiliation = original?.memberID == value.memberID && original?.groupID == value.groupID
|
||||
if (!keepsHistoricalAffiliation && document.activeMemberships.none {
|
||||
it.memberID == value.memberID && it.groupID == value.groupID
|
||||
}) return unavailableCatalog()
|
||||
val prices = if (original == null) {
|
||||
LedgerPriceSuggestions.remembering(
|
||||
LedgerPrice(value.productID, value.currency, value.unitPriceMinor), lastAddedPrices)
|
||||
} else lastAddedPrices
|
||||
return runCatching {
|
||||
val candidate = document.copy(records = upsert(document.records, value) { r -> r.id })
|
||||
save(candidate, demo = _state.value.isDemo, userEdits = hasUserEdits || _state.value.isDemo, prices = prices)
|
||||
true
|
||||
}.getOrElse { error ->
|
||||
_state.value = _state.value.copy(storageError = KitPresentation.error(error))
|
||||
false
|
||||
}
|
||||
}
|
||||
|
||||
/** One more of an existing purchase, at the price and with the details already recorded. */
|
||||
fun addQuantity(amount: Int, toRecord: String): Boolean {
|
||||
if (document.records.none { it.id == toRecord }) return false
|
||||
val candidate = document.addingQuantity(amount, toRecord)
|
||||
?: run {
|
||||
_state.value = _state.value.copy(storageError = L10n.text("ledger.error.overflow"))
|
||||
return false
|
||||
}
|
||||
return commit { candidate }
|
||||
}
|
||||
|
||||
fun deleteRecord(id: String): Boolean = deleteRecords(setOf(id))
|
||||
|
||||
fun deleteRecords(ids: Set<String>): Boolean {
|
||||
if (ids.isEmpty()) return true
|
||||
return commit { it.deletingRecords(ids) }
|
||||
}
|
||||
|
||||
fun deleteMembers(ids: Set<String>): Boolean {
|
||||
if (ids.isEmpty()) return true
|
||||
return commit { it.deletingMembers(ids) }
|
||||
}
|
||||
|
||||
fun deleteGroups(ids: Set<String>): Boolean {
|
||||
if (ids.isEmpty()) return true
|
||||
return commit { it.deletingGroups(ids) }
|
||||
}
|
||||
|
||||
fun deleteMember(id: String): Boolean = deleteMembers(setOf(id))
|
||||
fun deleteGroup(id: String): Boolean = deleteGroups(setOf(id))
|
||||
|
||||
fun exportJSON(): String = LedgerImporter.encode(document)
|
||||
|
||||
/** Returns and clears the store's message, so a page can show it beside the failed action. */
|
||||
fun takeError(): String {
|
||||
val message = _state.value.storageError ?: L10n.text("settings.saveError")
|
||||
_state.value = _state.value.copy(storageError = null)
|
||||
return message
|
||||
}
|
||||
|
||||
fun clearError() {
|
||||
_state.value = _state.value.copy(storageError = null)
|
||||
}
|
||||
|
||||
private fun unavailableCatalog(): Boolean {
|
||||
_state.value = _state.value.copy(storageError = L10n.text("ledger.catalogUnavailable"))
|
||||
return false
|
||||
}
|
||||
|
||||
private fun <T> upsert(array: List<T>, value: T, id: (T) -> String): List<T> {
|
||||
val index = array.indexOfFirst { id(it) == id(value) }
|
||||
if (index < 0) return array + value
|
||||
return array.toMutableList().also { it[index] = value }
|
||||
}
|
||||
|
||||
/** Writes the complete state, then publishes it. Nothing changes when the write fails. */
|
||||
private fun save(candidate: LedgerDocument, demo: Boolean, userEdits: Boolean, prices: List<LedgerPrice>) {
|
||||
persist(candidate, demo, userEdits, prices)
|
||||
_state.value = LedgerUiState(document = candidate, isDemo = demo)
|
||||
hasUserEdits = userEdits
|
||||
lastAddedPrices = prices
|
||||
}
|
||||
|
||||
private fun persist(candidate: LedgerDocument, demo: Boolean, userEdits: Boolean, prices: List<LedgerPrice>) {
|
||||
LedgerImporter.validate(candidate)
|
||||
file.parentFile?.mkdirs()
|
||||
val text = json.encodeToString(SavedState.serializer(),
|
||||
SavedState(document = candidate, isDemo = demo, hasUserEdits = userEdits, lastAddedPrices = prices))
|
||||
val temporary = File(file.parentFile, file.name + ".tmp")
|
||||
temporary.writeText(text, Charsets.UTF_8)
|
||||
if (!temporary.renameTo(file)) {
|
||||
file.writeText(text, Charsets.UTF_8)
|
||||
temporary.delete()
|
||||
}
|
||||
}
|
||||
|
||||
class Factory(private val context: Context) : ViewModelProvider.Factory {
|
||||
@Suppress("UNCHECKED_CAST")
|
||||
override fun <T : ViewModel> create(modelClass: Class<T>): T = LedgerStore(context) as T
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,142 @@
|
||||
package com.oshicue.keeps.ui
|
||||
|
||||
import androidx.compose.foundation.isSystemInDarkTheme
|
||||
import androidx.compose.material3.MaterialTheme
|
||||
import androidx.compose.material3.darkColorScheme
|
||||
import androidx.compose.material3.lightColorScheme
|
||||
import androidx.compose.runtime.Composable
|
||||
import androidx.compose.runtime.CompositionLocalProvider
|
||||
import androidx.compose.runtime.ProvidableCompositionLocal
|
||||
import androidx.compose.runtime.staticCompositionLocalOf
|
||||
import androidx.compose.ui.graphics.Color
|
||||
import androidx.compose.ui.graphics.luminance
|
||||
import androidx.compose.ui.text.TextStyle
|
||||
import androidx.compose.ui.text.font.FontWeight
|
||||
import androidx.compose.ui.unit.sp
|
||||
|
||||
/** The app's product colors, matching the iOS palette so both apps look like one family. */
|
||||
data class KitColors(
|
||||
val accent: Color,
|
||||
val accentText: Color,
|
||||
val accentFill: Color,
|
||||
val onAccent: Color,
|
||||
val familyPink: Color,
|
||||
val ink: Color,
|
||||
val onInk: Color,
|
||||
val muted: Color,
|
||||
val warningText: Color,
|
||||
val background: Color,
|
||||
val surface: Color,
|
||||
val surfaceMuted: Color,
|
||||
val surfaceSubtle: Color,
|
||||
val line: Color,
|
||||
)
|
||||
|
||||
private fun color(hex: String): Color =
|
||||
Color(0xFF000000L.or((hex.removePrefix("#").toLongOrNull(16) ?: 0x8F8F9BL)).toInt())
|
||||
|
||||
private val lightColors = KitColors(
|
||||
accent = color("F26B52"),
|
||||
accentText = color("C0402A"),
|
||||
accentFill = color("C7442C"),
|
||||
onAccent = Color.White,
|
||||
familyPink = color("FF3D6E"),
|
||||
ink = color("20212B"),
|
||||
onInk = Color.White,
|
||||
muted = color("696873"),
|
||||
warningText = color("945300"),
|
||||
background = color("F8F7F5"),
|
||||
surface = Color.White,
|
||||
surfaceMuted = color("EDEBE8"),
|
||||
surfaceSubtle = color("F1F0ED"),
|
||||
line = color("EAE8E5"),
|
||||
)
|
||||
|
||||
private val darkColors = KitColors(
|
||||
accent = color("FF8E72"),
|
||||
accentText = color("F0906F"),
|
||||
accentFill = color("D15738"),
|
||||
onAccent = Color.White,
|
||||
familyPink = color("FF3D6E"),
|
||||
ink = color("EDECF1"),
|
||||
onInk = color("20212B"),
|
||||
muted = color("AAA9B3"),
|
||||
warningText = color("FFB45B"),
|
||||
background = color("141519"),
|
||||
surface = color("202127"),
|
||||
surfaceMuted = color("2A2B33"),
|
||||
surfaceSubtle = color("282930"),
|
||||
line = color("44434B"),
|
||||
)
|
||||
|
||||
val LocalKitColors: ProvidableCompositionLocal<KitColors> = staticCompositionLocalOf { lightColors }
|
||||
|
||||
/** `KitStyle.accent` and friends in Swift become `Kit.colors.accent` here. */
|
||||
object Kit {
|
||||
val colors: KitColors
|
||||
@Composable get() = LocalKitColors.current
|
||||
|
||||
/**
|
||||
* Large count labels keep their venue color whenever it is readable. A display-only tint
|
||||
* protects black and white venue colors in either theme; stored colors are never changed.
|
||||
*/
|
||||
@Composable
|
||||
fun readableDataColor(hex: String): Color {
|
||||
val base = color(hex)
|
||||
val background = colors.surface
|
||||
val backgroundLuminance = background.luminance().toDouble()
|
||||
val destination = if (isSystemInDarkTheme()) 1.0 else 0.0
|
||||
var result = base
|
||||
for (step in 0..20) {
|
||||
val fraction = step / 20.0
|
||||
result = Color(
|
||||
red = (base.red * (1 - fraction) + destination * fraction).toFloat(),
|
||||
green = (base.green * (1 - fraction) + destination * fraction).toFloat(),
|
||||
blue = (base.blue * (1 - fraction) + destination * fraction).toFloat(),
|
||||
)
|
||||
val foreground = result.luminance().toDouble()
|
||||
val ratio = (maxOf(foreground, backgroundLuminance) + 0.05) / (minOf(foreground, backgroundLuminance) + 0.05)
|
||||
if (ratio >= 3) break
|
||||
}
|
||||
return result
|
||||
}
|
||||
|
||||
@Composable
|
||||
fun parse(hex: String): Color = color(hex)
|
||||
}
|
||||
|
||||
val KitTitleStyle = TextStyle(fontSize = 29.sp, fontWeight = FontWeight.Bold, letterSpacing = (-1).sp)
|
||||
|
||||
@Composable
|
||||
fun KitTheme(content: @Composable () -> Unit) {
|
||||
val dark = isSystemInDarkTheme()
|
||||
val palette = if (dark) darkColors else lightColors
|
||||
val scheme = if (dark) {
|
||||
darkColorScheme(
|
||||
primary = palette.accentText,
|
||||
onPrimary = palette.onAccent,
|
||||
background = palette.background,
|
||||
surface = palette.surface,
|
||||
onSurface = palette.ink,
|
||||
onBackground = palette.ink,
|
||||
surfaceVariant = palette.surfaceMuted,
|
||||
outline = palette.line,
|
||||
error = Color(0xFFD93A3A),
|
||||
)
|
||||
} else {
|
||||
lightColorScheme(
|
||||
primary = palette.accentText,
|
||||
onPrimary = palette.onAccent,
|
||||
background = palette.background,
|
||||
surface = palette.surface,
|
||||
onSurface = palette.ink,
|
||||
onBackground = palette.ink,
|
||||
surfaceVariant = palette.surfaceMuted,
|
||||
outline = palette.line,
|
||||
error = Color(0xFFC62828),
|
||||
)
|
||||
}
|
||||
CompositionLocalProvider(LocalKitColors provides palette) {
|
||||
MaterialTheme(colorScheme = scheme, content = content)
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,13 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<vector xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:width="108dp"
|
||||
android:height="108dp"
|
||||
android:viewportWidth="108"
|
||||
android:viewportHeight="108">
|
||||
<path
|
||||
android:fillColor="#FFFFFF"
|
||||
android:pathData="M32,34h10v26h18v10h-28z" />
|
||||
<path
|
||||
android:fillColor="#FF3D6E"
|
||||
android:pathData="M64,34h12v10h-12z" />
|
||||
</vector>
|
||||
Binary file not shown.
@@ -0,0 +1,5 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<adaptive-icon xmlns:android="http://schemas.android.com/apk/res/android">
|
||||
<background android:drawable="@color/ic_launcher_background" />
|
||||
<foreground android:drawable="@drawable/ic_launcher_foreground" />
|
||||
</adaptive-icon>
|
||||
@@ -0,0 +1,4 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<resources>
|
||||
<color name="ic_launcher_background">#C7442C</color>
|
||||
</resources>
|
||||
@@ -0,0 +1,4 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<resources>
|
||||
<string name="app_name">Oshicue Keeps</string>
|
||||
</resources>
|
||||
@@ -0,0 +1,6 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<resources>
|
||||
<style name="Theme.OshicueKeeps" parent="android:Theme.Material.Light.NoActionBar">
|
||||
<item name="android:windowBackground">#F8F7F5</item>
|
||||
</style>
|
||||
</resources>
|
||||
@@ -0,0 +1,4 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<paths>
|
||||
<cache-path name="exports" path="exports/" />
|
||||
</paths>
|
||||
@@ -0,0 +1,236 @@
|
||||
package com.oshicue.keeps.core
|
||||
|
||||
import org.junit.Assert.assertEquals
|
||||
import org.junit.Assert.assertNull
|
||||
import org.junit.Assert.assertTrue
|
||||
import org.junit.Before
|
||||
import org.junit.Test
|
||||
|
||||
class LedgerCoreTest {
|
||||
@Before
|
||||
fun setUp() {
|
||||
// Resolving the "system" language reads the platform locale, which a JVM test does not have.
|
||||
L10n.setLanguage(AppLanguage.En)
|
||||
}
|
||||
|
||||
private fun record(
|
||||
id: String,
|
||||
date: String = "2026-11-14",
|
||||
member: String = "mio",
|
||||
group: String = "luna",
|
||||
product: String = "cheki",
|
||||
quantity: Int = 2,
|
||||
price: Long = 2000,
|
||||
currency: String = "JPY",
|
||||
memberName: String = "Mio",
|
||||
groupName: String = "LUNA NOTE",
|
||||
productName: String = "Cheki",
|
||||
color: String = "#F28AAF",
|
||||
eventID: String? = null,
|
||||
note: String? = null,
|
||||
) = LedgerRecord(
|
||||
id = id, date = date, memberID = member, groupID = group, productID = product,
|
||||
quantity = quantity, unitPriceMinor = price, currency = currency, eventID = eventID,
|
||||
memberNameSnapshot = memberName, groupNameSnapshot = groupName,
|
||||
productNameSnapshot = productName, colorSnapshot = color, note = note,
|
||||
)
|
||||
|
||||
private fun document(records: List<LedgerRecord> = listOf(record("r1"))) = LedgerDocument(
|
||||
groups = listOf(LedgerGroup("luna", "LUNA NOTE"), LedgerGroup("prism", "PRISM DAYS")),
|
||||
members = listOf(LedgerMember("mio", "Mio"), LedgerMember("sora", "Sora")),
|
||||
memberships = listOf(
|
||||
LedgerMembership("mio-luna", "mio", "luna", "#F28AAF", listOf(LedgerPrice("cheki", "JPY", 2000))),
|
||||
LedgerMembership("mio-prism", "mio", "prism", "#9B8CF5"),
|
||||
LedgerMembership("sora-prism", "sora", "prism", "#67B9EF"),
|
||||
),
|
||||
products = LedgerDocument.defaultProducts,
|
||||
records = records,
|
||||
)
|
||||
|
||||
@Test
|
||||
fun priceParsingKeepsCurrencyPrecision() {
|
||||
assertEquals(2000L, LedgerCurrency.JPY.parsePrice("2000"))
|
||||
assertEquals(2050L, LedgerCurrency.JPY.parsePrice("2050"))
|
||||
// A zero-decimal currency rejects a fraction it cannot represent.
|
||||
assertNull(LedgerCurrency.JPY.parsePrice("20.50"))
|
||||
assertEquals(2050L, LedgerCurrency.CNY.parsePrice("20.50"))
|
||||
assertEquals(2050L, LedgerCurrency.CNY.parsePrice("20.5"))
|
||||
assertNull(LedgerCurrency.CNY.parsePrice("20.505"))
|
||||
assertNull(LedgerCurrency.CNY.parsePrice("-1"))
|
||||
assertNull(LedgerCurrency.CNY.parsePrice("abc"))
|
||||
}
|
||||
|
||||
@Test
|
||||
fun priceTextStripsTrailingZeros() {
|
||||
assertEquals("12.5", LedgerCurrency.CNY.priceText(1250))
|
||||
assertEquals("12", LedgerCurrency.CNY.priceText(1200))
|
||||
assertEquals("2000", LedgerCurrency.JPY.priceText(2000))
|
||||
}
|
||||
|
||||
@Test
|
||||
fun totalsAndSummariesPreserveCurrencies() {
|
||||
val summary = LedgerAnalytics.summarize(listOf(
|
||||
record("a", quantity = 2, price = 2000),
|
||||
record("b", quantity = 1, price = 8000, currency = "CNY"),
|
||||
))
|
||||
assertEquals(3, summary.quantity)
|
||||
assertEquals(4000L, summary.amountsByCurrency["JPY"])
|
||||
assertEquals(8000L, summary.amountsByCurrency["CNY"])
|
||||
assertEquals(1, summary.memberCount)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun rankingsSplitIdenticalScoresIntoTheSameRank() {
|
||||
val rows = LedgerAnalytics.rankings(listOf(
|
||||
record("a", member = "mio", quantity = 5),
|
||||
record("b", member = "sora", group = "prism", memberName = "Sora", groupName = "PRISM DAYS", quantity = 5),
|
||||
record("c", member = "sora", group = "prism", memberName = "Sora", groupName = "PRISM DAYS", quantity = 9),
|
||||
), LedgerGrouping.MemberCombined, LedgerMetric.Quantity)
|
||||
assertEquals(listOf("Sora", "Mio"), rows.map { it.name })
|
||||
assertEquals(19, rows.sumOf { it.quantity })
|
||||
assertTrue(rows.all { it.share > 0 })
|
||||
}
|
||||
|
||||
@Test
|
||||
fun spendingRankingsRequireOneCurrency() {
|
||||
val failure = runCatching {
|
||||
LedgerAnalytics.rankings(listOf(record("a")), LedgerGrouping.MemberCombined, LedgerMetric.Spending)
|
||||
}.exceptionOrNull() as LedgerError
|
||||
assertEquals("ledger.error.currencyRequired", failure.key)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun periodsFilterByCivilDayMonthYearAndLifetime() {
|
||||
val records = listOf(
|
||||
record("a", date = "2025-12-31"),
|
||||
record("b", date = "2026-01-01"),
|
||||
record("c", date = "2026-01-31"),
|
||||
record("d", date = "2026-02-01"),
|
||||
)
|
||||
assertEquals(listOf("a"), LedgerAnalytics.filtered(records, LedgerPeriod.Day, "2025-12-31").map { it.id })
|
||||
assertEquals(listOf("b", "c"), LedgerAnalytics.filtered(records, LedgerPeriod.Month, "2026-01-15").map { it.id })
|
||||
assertEquals(listOf("b", "c", "d"), LedgerAnalytics.filtered(records, LedgerPeriod.Year, "2026-06-01").map { it.id })
|
||||
assertEquals(4, LedgerAnalytics.filtered(records, LedgerPeriod.Lifetime, "2026-01-01").size)
|
||||
assertEquals(0, LedgerAnalytics.filtered(records, LedgerPeriod.Day, "2026-02-30").size)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun everyRecordFieldSurvivesValidationAndJSONRoundTrip() {
|
||||
val edited = record(
|
||||
"r1", date = "2026-03-05", member = "sora", group = "prism", product = "phone-photo",
|
||||
quantity = 4, price = 1234, currency = "HKD", memberName = "Sorano", groupName = "PRISM",
|
||||
productName = "Phone shot", color = "#123ABC", eventID = null, note = "changed",
|
||||
)
|
||||
val encoded = LedgerImporter.encode(document(listOf(edited)))
|
||||
val decoded = LedgerImporter.parse(encoded)
|
||||
assertEquals(edited, decoded.records.single())
|
||||
assertEquals("Sorano", decoded.records.single().memberNameSnapshot)
|
||||
assertEquals("Phone shot", decoded.records.single().productNameSnapshot)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun clearingOptionalFieldsIsAlsoAnEdit() {
|
||||
val cleared = record("r1", note = null)
|
||||
val decoded = LedgerImporter.parse(LedgerImporter.encode(document(listOf(cleared))))
|
||||
assertNull(decoded.records.single().note)
|
||||
assertNull(decoded.records.single().eventNameSnapshot)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun archivedMembersKeepTheirRecordsEditable() {
|
||||
val rest = document().deletingMember("mio")
|
||||
assertTrue(rest.activeMembers.none { it.id == "mio" })
|
||||
// The record still validates because its snapshots carry the archived identity.
|
||||
LedgerImporter.validate(rest)
|
||||
assertEquals("Mio", rest.records.single().memberNameSnapshot)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun invalidSnapshotsAndReferencesAreRejected() {
|
||||
val badColor = runCatching {
|
||||
LedgerImporter.validate(document(listOf(record("r1", color = "red"))))
|
||||
}.exceptionOrNull() as LedgerError
|
||||
assertEquals("ledger.error.color", badColor.key)
|
||||
|
||||
val badMember = runCatching {
|
||||
LedgerImporter.validate(document(listOf(record("r1", member = "ghost"))))
|
||||
}.exceptionOrNull() as LedgerError
|
||||
assertEquals("ledger.error.reference", badMember.key)
|
||||
|
||||
val badPrice = runCatching {
|
||||
LedgerImporter.validate(document(listOf(record("r1", price = -1))))
|
||||
}.exceptionOrNull() as LedgerError
|
||||
assertEquals("ledger.error.price", badPrice.key)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun reimportingTheSameBackupCannotDoubleCount() {
|
||||
val original = document(listOf(record("r1")))
|
||||
val merged = original.merging(original)
|
||||
assertEquals(1, merged.records.size)
|
||||
// A conflicting record with the same ID but different contents is refused.
|
||||
val conflict = runCatching { original.merging(document(listOf(record("r1", quantity = 9)))) }
|
||||
assertTrue(conflict.exceptionOrNull() is LedgerError)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun addingQuantityKeepsPriceAndSnapshots() {
|
||||
val base = document(listOf(record("r1")))
|
||||
val updated = base.addingQuantity(3, "r1")!!
|
||||
assertEquals(5, updated.records.single().quantity)
|
||||
assertEquals(2000L, updated.records.single().unitPriceMinor)
|
||||
assertNull(base.addingQuantity(0, "r1"))
|
||||
assertNull(base.addingQuantity(1, "missing"))
|
||||
}
|
||||
|
||||
@Test
|
||||
fun priceSuggestionPrefersHistoryThenMemoryThenCatalog() {
|
||||
val base = document(listOf(
|
||||
record("older", date = "2026-11-01", price = 1800),
|
||||
record("newer", date = "2026-11-10", price = 2200),
|
||||
))
|
||||
val membership = base.memberships.first { it.id == "mio-luna" }
|
||||
assertEquals(2200L, LedgerPriceSuggestions.price(base, membership, "cheki", "JPY", "2026-11-14").unitPriceMinor)
|
||||
assertEquals(1800L, LedgerPriceSuggestions.price(base, membership, "cheki", "JPY", "2026-11-05").unitPriceMinor)
|
||||
assertEquals(2000L, LedgerPriceSuggestions.price(base, membership, "cheki", "JPY", "2026-10-01").unitPriceMinor)
|
||||
assertEquals("JPY", LedgerPriceSuggestions.currency(base, membership, "cheki", "2026-11-14"))
|
||||
}
|
||||
|
||||
@Test
|
||||
fun filterCombinesIndependentConditions() {
|
||||
val records = listOf(
|
||||
record("a", date = "2026-11-01", member = "mio", note = "first"),
|
||||
record("b", date = "2026-11-20", member = "sora", group = "prism", memberName = "Sora", groupName = "PRISM DAYS"),
|
||||
)
|
||||
val filter = LedgerRecordFilter(startDate = "2026-11-10", memberID = "sora")
|
||||
assertEquals(listOf("b"), filter.matching(records).map { it.id })
|
||||
assertTrue(!LedgerRecordFilter(startDate = "2026-11-20", endDate = "2026-11-01").hasValidDateRange)
|
||||
assertEquals(1, LedgerRecordFilter(query = "sora").matching(records).size)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun csvNeutralizesFormulaCellsAndQuotesCommas() {
|
||||
assertEquals("'=cmd", LedgerCSV.text("=cmd"))
|
||||
assertEquals("\"a,b\"", LedgerCSV.text("a,b"))
|
||||
assertEquals("\"say \"\"hi\"\"\"", LedgerCSV.text("say \"hi\""))
|
||||
val headers = LedgerCSV.Column.entries.associateWith { it.name }
|
||||
val csv = LedgerCSV.make(listOf(record("a", productName = "Cheki")), headers) { it.productNameSnapshot }
|
||||
assertTrue(csv.startsWith(""))
|
||||
assertTrue(csv.contains("\r\n"))
|
||||
}
|
||||
|
||||
@Test
|
||||
fun defaultProductNamesFollowTheAppLanguage() {
|
||||
L10n.setLanguage(AppLanguage.En)
|
||||
assertTrue(LedgerPresentation.productName("cheki", "Cheki").isNotEmpty())
|
||||
// A renamed product keeps the user's own text.
|
||||
assertEquals("My shot", LedgerPresentation.productName("cheki", "My shot"))
|
||||
}
|
||||
|
||||
@Test
|
||||
fun civilDatesAreTimezoneIndependent() {
|
||||
assertEquals("2026-03-05", LedgerDates.string(record("a", date = "2026-03-05").date.let { LedgerDates.parse(it)!! }))
|
||||
assertNull(LedgerDates.parse("2026-02-30"))
|
||||
assertNull(LedgerDates.parse("2026-3-5"))
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user