diff --git a/.gitea/ISSUE_TEMPLATE/bug_report.yml b/.gitea/ISSUE_TEMPLATE/bug_report.yml new file mode 100644 index 0000000..8ba7d36 --- /dev/null +++ b/.gitea/ISSUE_TEMPLATE/bug_report.yml @@ -0,0 +1,76 @@ +name: Bug Report +description: Report something that isn't working as expected. +labels: + - kind/bug +body: + - type: input + id: summary + attributes: + label: Summary + description: One-line description of the bug. + placeholder: e.g. "Tapping the FAB doesn't open the editor" + validations: + required: true + - type: textarea + id: steps + attributes: + label: Steps to reproduce + description: What did you do, and what happened? + placeholder: | + 1. Open the app + 2. Tap ... + 3. See error ... + validations: + required: true + - type: textarea + id: expected + attributes: + label: Expected behaviour + description: What did you expect to happen? + validations: + required: true + - type: dropdown + id: severity + attributes: + label: Severity + description: How broken is it? + options: + - Low (cosmetic / minor inconvenience) + - Medium (feature broken but app still usable) + - High (core functionality broken) + - Critical (app crashes, data loss) + validations: + required: true + - type: input + id: app_version + attributes: + label: App version + description: Found in Settings → Apps → Incido → App info, or via `adb shell dumpsys package org.incido.app | grep versionName`. + placeholder: 0.2.0 + validations: + required: true + - type: input + id: device + attributes: + label: Device & Android version + description: e.g. Pixel 7, Android 15; or `adb shell getprop ro.product.model` / `ro.build.version.release`. + placeholder: Pixel 7, Android 15 + validations: + required: true + - type: textarea + id: logs + attributes: + label: Logs (optional) + description: | + If you can, attach a `logcat` snippet from the moment the bug occurred. + `adb logcat -d -v time | grep -i incido` after reproducing the bug. + render: shell + validations: + required: false + - type: textarea + id: screenshots + attributes: + label: Screenshots / recordings + description: Drag-and-drop or paste links. + validations: + required: false diff --git a/.gitea/ISSUE_TEMPLATE/feature_request.yml b/.gitea/ISSUE_TEMPLATE/feature_request.yml new file mode 100644 index 0000000..553e103 --- /dev/null +++ b/.gitea/ISSUE_TEMPLATE/feature_request.yml @@ -0,0 +1,61 @@ +name: Feature Request +description: Suggest a new feature for Incido. +labels: + - kind/feature +body: + - type: input + id: summary + attributes: + label: Summary + description: One-line description of the feature. + placeholder: e.g. "Add Markdown export for individual notes" + validations: + required: true + - type: textarea + id: problem + attributes: + label: Problem / motivation + description: What problem does this solve? What can the user do today that they can't, or what do they do today that's harder than it should be? + validations: + required: true + - type: textarea + id: proposal + attributes: + label: Proposed solution + description: Describe how you imagine the feature working. Screenshots, mockups, or links welcome. + validations: + required: true + - type: textarea + id: alternatives + attributes: + label: Alternatives considered + description: What other approaches did you consider, and why is your proposal better? + validations: + required: false + - type: textarea + id: roadmap + attributes: + label: Roadmap relevance + description: | + Is this already in the Development Plan §6 backlog? If so, which item? + If not, do you think it should be added there before implementing? + validations: + required: false + - type: dropdown + id: privacy + attributes: + label: Privacy impact + description: Does this feature touch anything that leaves the device, scans user data, or requires a new permission? + options: + - None — fully on-device + - Adds new on-device processing only + - Requires a new optional permission + - Requires network access (almost certainly out of scope for now) + validations: + required: true + - type: textarea + id: extra + attributes: + label: Anything else? + validations: + required: false diff --git a/.gitea/PULL_REQUEST_TEMPLATE.md b/.gitea/PULL_REQUEST_TEMPLATE.md new file mode 100644 index 0000000..d14dc17 --- /dev/null +++ b/.gitea/PULL_REQUEST_TEMPLATE.md @@ -0,0 +1,58 @@ + + +## Summary + + + +## Linked issues + + + +## Type of change + +- [ ] Bug fix (non-breaking change that fixes an issue) +- [ ] New feature (non-breaking change that adds functionality) +- [ ] Breaking change (fix or feature that changes existing behaviour) +- [ ] Documentation / repo-meta (README, CONTRIBUTING, CI, templates — no app code change) +- [ ] Refactor (no functional change) + +## How tested + + + +- [ ] `./gradlew assembleDebug` is green locally +- [ ] Manual smoke test on a real device (Android 8.0+, ideally 12+ for dynamic colour) +- [ ] Unit tests added / updated (only required for `core/domain` and `core/data` in v0.2) +- [ ] Gitea Actions build on this PR is green + +If you added new UI, attach a screenshot or short screen recording. + +## Privacy / permissions checklist + +- [ ] No `INTERNET` permission added +- [ ] No analytics, telemetry, or third-party trackers introduced +- [ ] `data_extraction_rules.xml` still excludes all domains +- [ ] If a new permission is genuinely required, the PR description explains why + +## Documentation + +- [ ] `README.md` updated (Features section + any new build steps) +- [ ] `Incido Development Plan.txt` §10 history table updated with this version +- [ ] `CONTRIBUTING.md` still accurate (branch naming, commit format, etc.) + +## Checklist + +- [ ] I've read the [Contributing guide](./CONTRIBUTING.md) and the [Code of Conduct](./CODE_OF_CONDUCT.md) +- [ ] My commit messages follow Conventional Commits +- [ ] My changes don't add new dependencies that aren't justified +- [ ] I've tested on at least one real Android device + + diff --git a/.gitea/workflows/build.yml b/.gitea/workflows/build.yml new file mode 100644 index 0000000..bbce439 --- /dev/null +++ b/.gitea/workflows/build.yml @@ -0,0 +1,46 @@ +name: build + +on: + push: + branches: [main] + pull_request: + branches: [main] + +jobs: + assemble-debug: + name: Assemble debug APK + runs-on: ubuntu-latest + steps: + - name: Checkout + uses: actions/checkout@v4 + + - name: Set up JDK 17 + uses: actions/setup-java@v4 + with: + distribution: temurin + java-version: 17 + + - name: Grant execute permission for gradlew + run: chmod +x gradlew + + - name: Cache Gradle packages + uses: actions/cache@v4 + with: + path: | + ~/.gradle/caches + ~/.gradle/wrapper + key: ${{ runner.os }}-gradle-${{ hashFiles('**/*.gradle*', '**/gradle-wrapper.properties') }} + restore-keys: | + ${{ runner.os }}-gradle- + ${{ runner.os }}- + + - name: Build debug APK + run: ./gradlew assembleDebug + + - name: Upload APK as artefact + uses: actions/upload-artifact@v4 + with: + name: incido-debug-apk + path: app/build/outputs/apk/debug/app-debug.apk + if-no-files-found: error + retention-days: 14 diff --git a/.gitignore b/.gitignore index ba081d8..00b754b 100644 --- a/.gitignore +++ b/.gitignore @@ -4,6 +4,13 @@ build/ !**/src/**/build/ !**/test/**/build/ +# Release keystore — generated locally, never committed. +# See keystore/README.md for instructions on regenerating the dev key. +keystore/*.jks +keystore/*.keystore +keystore/*.p12 +!keystore/README.md + # Android Studio / IntelliJ .idea/ *.iml diff --git a/CODE_OF_CONDUCT.md b/CODE_OF_CONDUCT.md new file mode 100644 index 0000000..c466d46 --- /dev/null +++ b/CODE_OF_CONDUCT.md @@ -0,0 +1,128 @@ +# Contributor Covenant Code of Conduct + +## Our Pledge + +We as members, contributors, and leaders pledge to make participation in our +community a harassment-free experience for everyone, regardless of age, body +size, visible or invisible disability, ethnicity, sex characteristics, gender +identity and expression, level of experience, education, socio-economic status, +nationality, personal appearance, race, caste, color, religion, or sexual +identity and orientation. + +We pledge to act and interact in ways that contribute to an open, welcoming, +diverse, inclusive, and healthy community. + +## Our Standards + +Examples of behavior that contributes to a positive environment for our +community include: + +* Demonstrating empathy and kindness toward other people +* Being respectful of differing opinions, viewpoints, and experiences +* Giving and gracefully accepting constructive feedback +* Accepting responsibility and apologizing to those affected by our mistakes, + and learning from the experience +* Focusing on what is best not just for us as individuals, but for the overall + community + +Examples of unacceptable behavior include: + +* The use of sexualized language or imagery, and sexual attention or advances of + any kind +* Trolling, insulting or derogatory comments, and personal or political attacks +* Public or private harassment +* Publishing others' private information, such as a physical or email address, + without their explicit permission +* Other conduct which could reasonably be considered inappropriate in a + professional setting + +## Enforcement Responsibilities + +Community leaders are responsible for clarifying and enforcing our standards of +acceptable behavior and will take appropriate and fair corrective action in +response to any behavior that they deem inappropriate, threatening, offensive, +or harmful. + +Community leaders have the right and responsibility to remove, edit, or reject +comments, commits, code, wiki edits, issues, and other contributions that are +not aligned to this Code of Conduct, and will communicate reasons for +moderation decisions when appropriate. + +## Scope + +This Code of Conduct applies within all community spaces — the issue tracker, +pull requests, code reviews, chat channels, and any other forum — and also +applies when an individual is officially representing the community in public +spaces. Examples of representing our community include using an official +e-mail address, posting via an official social media account, or acting as an +appointed representative at an online or offline event. + +## Enforcement + +Instances of abusive, harassing, or otherwise unacceptable behavior may be +reported to the community leaders responsible for enforcement at the issue +tracker. All complaints will be reviewed and investigated promptly and fairly. + +All community leaders are obligated to respect the privacy and security of the +reporter of any incident. + +## Enforcement Guidelines + +Community leaders will follow these Community Impact Guidelines in determining +the consequences for any action they deem in violation of this Code of Conduct: + +### 1. Correction +**Community Impact**: Use of inappropriate language or other behavior deemed +unprofessional or unwelcome in the community. + +**Consequence**: A private, written warning from community leaders, providing +clarity around the nature of the violation and an explanation of why the +behavior was inappropriate. A public apology may be requested. + +### 2. Warning +**Community Impact**: A violation through a single incident or series of +actions. + +**Consequence**: A warning with consequences for continued behavior. No +interaction with the people involved — including unsolicited interaction with +those enforcing the Code of Conduct — for a specified period of time. This +includes avoiding interactions in community spaces as well as external +channels like social media. Violating these terms may lead to a temporary or +permanent ban. + +### 3. Temporary Ban +**Community Impact**: A serious violation of community standards, including +sustained inappropriate behavior. + +**Consequence**: A temporary ban from any sort of interaction or public +communication with the community for a specified period of time. No public or +private interaction with the people involved — including unsolicited +interaction with those enforcing the Code of Conduct — is allowed during this +period. Violating these terms may lead to a permanent ban. + +### 4. Permanent Ban +**Community Impact**: Demonstrating a pattern of violation of community +standards, including sustained inappropriate behavior, harassment of an +individual, or aggression toward or disparagement of classes of individuals. + +**Consequence**: A permanent ban from any sort of public interaction within +the community. + +## Attribution + +This Code of Conduct is adapted from the [Contributor Covenant][homepage], +version 2.1, available at +[https://www.contributor-covenant.org/version/2/1/code_of_conduct.html][v2.1]. + +Community Impact Guidelines were inspired by +[Mozilla's code of conduct enforcement ladder][mozilla coc]. + +For answers to common questions about this code of conduct, see the FAQ at +[https://www.contributor-covenant.org/faq][faq]. Translations are available +at [https://www.contributor-covenant.org/translations][translations]. + +[homepage]: https://www.contributor-covenant.org +[v2.1]: https://www.contributor-covenant.org/version/2/1/code_of_conduct.html +[mozilla coc]: https://github.com/mozilla/diversity +[faq]: https://www.contributor-covenant.org/faq +[translations]: https://www.contributor-covenant.org/translations diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md new file mode 100644 index 0000000..bc1d6b0 --- /dev/null +++ b/CONTRIBUTING.md @@ -0,0 +1,149 @@ +# Contributing to Incido + +First off, thank you for taking the time to contribute! 🎉 Incido is a +small, privacy-focused project and every contribution — bug reports, +documentation fixes, code, translations — makes a real difference. + +## Code of Conduct + +Everyone who participates in this project is expected to abide by the +[Contributor Covenant v2.1](./CODE_OF_CONDUCT.md). Please read it before +contributing. + +## How can I contribute? + +There are several ways you can help: + +### 🐛 Reporting bugs +Open a [bug report](.gitea/ISSUE_TEMPLATE/bug_report.yml) on the issue +tracker. Include: +- Device model and Android version +- App version (`Settings → Apps → Incido → App info` or `adb shell dumpsys package org.incido.app`) +- Steps to reproduce +- Expected vs actual behaviour +- Screenshots or screen recordings if relevant + +### 💡 Suggesting features +Open a [feature request](.gitea/ISSUE_TEMPLATE/feature_request.yml). +Before you do, check the existing issues and the +[Development Plan](./Incido%20Development%20Plan.txt) §6 backlog — the +feature you want may already be on the roadmap. + +### 🌍 Translating +Incido is currently English-only. Once we add translation infrastructure +(Weblate or Crowdin, per §6.8), every locale helps. + +### 🔧 Submitting code changes +Open a pull request. See the workflow below. + +--- + +## Development workflow + +### 1. Pick something to work on +- Check existing issues for `good first issue` or `help wanted` labels. +- Or grab an item from §6 of the Development Plan that's not yet + implemented. + +### 2. Branch +- Branch off `main`. +- Use a descriptive name: + - `feat/favorites-stars` + - `fix/editor-ime-on-android-12` + - `refactor/extract-color-picker` + +### 3. Make your changes +- Follow the existing code style (Kotlin official style; Compose + conventions as already used in the codebase). +- Add unit tests for non-trivial logic in `core/domain` or + `core/data` (UI changes don't require new tests in v0.2). +- Update the Development Plan §10 history table if your change is + user-visible. + +### 4. Verify locally +```bash +./gradlew assembleDebug +adb install -r app/build/outputs/apk/debug/app-debug.apk +``` +…then run through the relevant smoke test from the Development Plan §7.2 +or your feature's manual verification steps. + +### 5. Commit +We use [Conventional Commits](https://www.conventionalcommits.org/) so +the changelog can be generated automatically later: + +| Type | Use for | +|------|---------| +| `feat:` | new user-visible feature | +| `fix:` | bug fix | +| `chore:` | maintenance (deps, tooling, no user impact) | +| `docs:` | documentation only | +| `refactor:` | code change that neither fixes a bug nor adds a feature | +| `test:` | adding or fixing tests | + +Example: +``` +feat(notes): add color-coded notes + +Adds 6 preset accent colours (NONE / BLUE / GREEN / AMBER / RED / PURPLE) +backed by a NoteColor enum. Users pick from a swatch row in the editor; +a 4dp vertical stripe renders on the left of each list card. + +Closes #42 +``` + +### 6. Open a Pull Request +- Push your branch and open a PR against `main`. +- Fill out the [PR template](./.gitea/PULL_REQUEST_TEMPLATE.md). +- A Gitea Actions build will run automatically — make sure it passes. +- A maintainer will review; expect 1–2 rounds of feedback on your first PR. + +--- + +## AGPL-3.0 contribution terms + +Incido is licensed under the **GNU Affero General Public License v3.0**. +By submitting a contribution, you affirm: + +1. The contribution is your own original work, **or** you have the right + to submit it under the AGPL-3.0. +2. You agree your contribution is licensed under AGPL-3.0 (or a + compatible licence) and that the project may redistribute it under + those terms. + +If you're contributing on behalf of an employer or as part of +work-for-hire, please confirm you have authority to license the work +under AGPL-3.0 before opening the PR. + +--- + +## Code style + +- **Kotlin:** [Kotlin coding conventions](https://kotlinlang.org/docs/coding-conventions.html). +- **Compose:** Prefer stateless composables, hoist state, use + `Modifier` parameter ordering `Modifier.size().background().clickable()`. +- **Imports:** Wildcard imports are discouraged. Group: Android → + Compose → third-party → internal. +- **Naming:** `PascalCase` for types, `camelCase` for functions/properties, + `UPPER_SNAKE_CASE` for constants. +- **Strings:** Hard-coded UI strings in the UI layer are fine for + v0.2; once translation infrastructure lands, all user-visible strings + must move to `strings.xml`. + +## Commit message rules +- 72-character subject line (no period at end) +- Imperative mood ("add", not "added" / "adds") +- Blank line, then body wrapped at 72 chars +- Body explains **what** and **why**, not **how** + +--- + +## Release process (for maintainers) + +1. Bump `versionCode` + `versionName` in `app/build.gradle.kts`. +2. Update the Development Plan §10 history table. +3. Tag the commit: `git tag -s vX.Y.Z -m "vX.Y.Z — short summary"`. +4. `./gradlew assembleRelease` → upload APK to Gitea Releases. +5. Push the tag: `git push origin vX.Y.Z`. + +Thanks again for contributing! 🙏 diff --git a/Incido Development Plan.txt b/Incido Development Plan.txt index d81b114..337a08d 100644 --- a/Incido Development Plan.txt +++ b/Incido Development Plan.txt @@ -366,6 +366,8 @@ A short reference for AI assistants: | 0.1 | 2026-08-14 | Initial plan drafted via interview | | 0.1.1 | 2026-08-14 | Added F1 explicit "list of currently saved notes" requirement + F7 auto-refresh + clarified UI section | | 0.1.1 | 2026-08-14 | Editor IME fix (Scaffold contentWindowInsets + adjustResize) + title/body display on list cards | +| 0.2 | 2026-08-14 | Polish + first Keep-parity features. Discard-confirm dialog; release signing config (dev keystore). Favorites (renamed from Pinned Notes), full-text search, 6 colour-coded notes, inline GFM checklists (open/done counts). ObjectBox KMP migration deferred to v0.5 (tracked). | + --- diff --git a/README.md b/README.md index 30ea224..8978bd1 100644 --- a/README.md +++ b/README.md @@ -6,20 +6,39 @@ Incido is a privacy-first, on-device note-taking application for Android. All data stays on your device by default — no accounts, no cloud, no trackers. -This repository contains the **v0.1 Minimum Viable Product**: a -single-user, offline note app demonstrating the core architecture, data -layer, and Compose UI shell that future versions will build on. +This repository contains the **v0.2** release: a single-user, offline note +app with favourites, full-text search, colour-coded notes, and inline +checklists. The architecture is multi-module Android today and is +structured so iOS / Desktop ports can happen later without UI rewrites. -**Current release:** v0.1.1 (patch — see [Changelog](#changelog) below). +**Current release:** v0.2 (see [Changelog](#changelog) below). --- -## Features (v0.1) +## Features -### v0.1.1 additions +### v0.2 highlights + +- **Favourites.** Tap the star icon on any card to pin it to the top of + the list. (Replaces the §6.1 "Pinned Notes" item; renamed per + maintainer request.) +- **Full-text search.** Tap the search icon in the top app bar; the list + filters live as you type. Backed by ObjectBox's `contains` query — + case-insensitive, no extra dependencies. +- **Color-coded notes.** Pick from six preset accent colours in the + editor (none / blue / green / amber / red / purple). Each list card + gets a 4dp vertical stripe on the left edge. +- **Inline checklists.** Lines beginning with `- [ ]` or `- [x]` are + parsed; the card preview shows the open/done counts (e.g. + "2 open · 1 done"). No DB schema migration — the text stays plain. +- **Discard-confirm dialog.** Closing the editor with unsaved changes + now prompts "Discard changes?" with Discard / Keep-editing buttons. + Applies to both the Back arrow and the hardware back gesture. + +### v0.1.1 polish - **Editor respects the soft keyboard.** With edge-to-edge enabled, the - editor's `Scaffold` now unions `WindowInsets.systemBars` with + editor's `Scaffold` unions `WindowInsets.systemBars` with `WindowInsets.ime`, so the text field automatically shrinks above the keyboard instead of being hidden behind it. `adjustResize` is also set on `MainActivity` as a pre-Android-15 fallback. @@ -30,18 +49,29 @@ layer, and Compose UI shell that future versions will build on. ### v0.1.0 (original MVP) - - Create, edit, and delete plain-text notes -- All notes persisted locally with [ObjectBox](https://objectbox.io/) -- Material 3 UI with dynamic color (Android 12+) and dark/light themes -- Fully offline — no `INTERNET` permission required -- Multi-module Kotlin Multiplatform project (Android today, iOS/Desktop-ready for tomorrow) +- ObjectBox-backed persistence ([objectbox.io](https://objectbox.io/)) +- Material 3 UI with dynamic color (Android 12+), dark/light follows system +- Fully offline — no `INTERNET` permission +- Multi-module Android project (Android today, iOS/Desktop-ready later) + +--- ## Roadmap -See `Incido Development Plan.txt` at the repository root for the -canonical roadmap, including on-device ML, cross-platform ports, -end-to-end sync, and security features. +See [`Incido Development Plan.txt`](./Incido%20Development%20Plan.txt) at +the repository root for the canonical backlog, including on-device ML, +cross-platform ports, end-to-end sync, and security features. + +--- + +## Changelog + +| Version | Date | Highlights | +|---------|------|------------| +| 0.1 | 2026-08-14 | First MVP: list + editor, ObjectBox, Material 3 | +| 0.1.1 | 2026-08-14 | Editor IME fix + title/body on list cards | +| 0.2 | 2026-08-14 | Polish + favourites, search, colours, checklists, discard dialog, release signing | --- @@ -62,13 +92,16 @@ their source code changes. This is intentional — it preserves the ``` incido/ ├── app/ # Android entry point (manifest, MainActivity) -├── composeApp/ # Shared Compose UI (KMP commonMain + androidMain) +├── composeApp/ # Shared Compose UI module ├── core/ -│ ├── domain/ # Pure-Kotlin domain models & repository interfaces +│ ├── domain/ # Pure-Kotlin domain models + repository interface │ └── data/ # ObjectBox-backed repository implementation -├── gradle/ # Version catalog (libs.versions.toml) -├── settings.gradle.kts -└── build.gradle.kts +├── gradle/ # Version catalog (libs.versions.toml) + wrapper +├── keystore/ # Release signing (gitignored *.jks, README kept) +├── .gitea/ # Gitea Actions workflow + issue/PR templates +├── CONTRIBUTING.md +├── CODE_OF_CONDUCT.md +└── LICENSE ``` --- @@ -110,7 +143,18 @@ yes | $ANDROID_HOME/cmdline-tools/latest/bin/sdkmanager --licenses The APK is written to `app/build/outputs/apk/debug/app-debug.apk`. -### 4. Install on a device +### 4. (Optional) Build a signed release APK + +```bash +./gradlew assembleRelease +``` + +Uses the dev keystore at `keystore/release.jks` — see +[`keystore/README.md`](./keystore/README.md) for regeneration instructions. +**Replace this keystore with a production key before any external +distribution.** + +### 5. Install on a device ```bash adb install -r app/build/outputs/apk/debug/app-debug.apk @@ -120,30 +164,51 @@ Or open the project in Android Studio and click **Run**. --- -## Manual Smoke Test (from the Development Plan §7.2) +## Remote / Gitea Setup + +When your self-hosted Gitea instance is online, register the remote and +push the existing local commits: + +```bash +git remote add origin https://your-gitea.example.com/yourname/incido.git +git push -u origin main +git push origin --tags # if you have any local tags +``` + +After the first push: + +- `.gitea/workflows/build.yml` will automatically build the debug APK + on every push to `main` and on every pull request. The APK is uploaded + as a workflow artefact (`.gitea → Actions → build → Artifacts`). +- `.gitea/ISSUE_TEMPLATE/bug_report.yml` and + `feature_request.yml` will be picked up by Gitea when users open new + issues. +- `.gitea/PULL_REQUEST_TEMPLATE.md` will be auto-loaded on new PRs. + +--- + +## Manual Smoke Test (Development Plan §7.2 + v0.2 additions) ``` [ ] Launch app — see empty state message ("No notes yet. Tap + to start.") [ ] Tap FAB — editor opens, cursor in text field [ ] Type "Test note 1" — tap save — returns to list, "Test note 1" card visible -[ ] Repeat for "Test note 2" and "Test note 3" -[ ] Confirm all 3 notes visible on the list, newest at top -[ ] Tap "Test note 2" card — editor opens with existing content -[ ] Change to "Test note 2 (edited)" — tap save -[ ] Confirm updated text appears on the card on the list -[ ] Long-press "Test note 3" — delete option appears -[ ] Confirm delete — note removed from the list -[ ] Force-stop app from system settings -[ ] Reopen app — "Test note 1" and "Test note 2 (edited)" both visible on the list +[ ] Tap star on card 1 — it floats to the top +[ ] Tap search icon — type "Test" — only matching card remains +[ ] Close search — full list returns, favourite still on top +[ ] Edit "Test note 2" → tap a colour swatch → save → card shows coloured stripe +[ ] Create a note with "- [ ] milk\n- [x] eggs" → card preview shows "1 open · 1 done" +[ ] Open a note → type extra content → tap Back → discard dialog appears +[ ] Force-stop app from system settings, reopen → all notes + favourites still present ``` --- ## Architecture (brief) -- **UI**: 100% Jetpack Compose / Compose Multiplatform in `composeApp/`. - ViewModels expose immutable `StateFlow` per screen; no - third-party state management library. +- **UI**: 100% Jetpack Compose in `composeApp/`. ViewModels expose + immutable `StateFlow` per screen; no third-party state + management library. - **Domain**: Pure Kotlin interfaces in `core/domain/` — the only thing the UI sees. - **Data**: `core/data/` provides the ObjectBox implementation. ViewModels @@ -152,7 +217,6 @@ Or open the project in Android Studio and click **Run**. ## Contributing -Issues and PRs are welcome on the Gitea mirror. AGPL-3.0 means any -contributions you submit must be under a compatible license. By -submitting a contribution, you affirm you have the right to do so -under these terms. +See [`CONTRIBUTING.md`](./CONTRIBUTING.md). All participants are expected +to follow [`CODE_OF_CONDUCT.md`](./CODE_OF_CONDUCT.md). By submitting a +contribution you affirm you have the right to license it under AGPL-3.0. diff --git a/app/build.gradle.kts b/app/build.gradle.kts index b2af556..1a1133e 100644 --- a/app/build.gradle.kts +++ b/app/build.gradle.kts @@ -1,5 +1,8 @@ // :app — Android application entry point. Hosts MainActivity and the // application manifest, including the launcher icon and theme. +import java.io.FileInputStream +import java.util.Properties + plugins { alias(libs.plugins.androidApplication) alias(libs.plugins.kotlinAndroid) @@ -14,8 +17,33 @@ android { applicationId = "org.incido.app" minSdk = 26 targetSdk = 35 - versionCode = 2 - versionName = "0.1.1" + versionCode = 3 + versionName = "0.2" + } + + // --- Signing --- + // + // v0.2 introduces a real release signing config so `./gradlew + // assembleRelease` produces an installable APK out of the box. The + // keystore file itself is gitignored — see keystore/README.md for + // generation instructions and for the (deliberately weak) dev + // passwords baked into this build script. **Replace with a real + // production keystore before publishing.** + signingConfigs { + create("release") { + // Resolve paths relative to the project root so the same + // config works from both Android Studio and CLI. + val keystoreFilePath = rootProject.file("keystore/release.jks") + if (keystoreFilePath.exists()) { + storeFile = keystoreFilePath + storePassword = "incido_dev_keystore" + keyAlias = "incido" + keyPassword = "incido_dev_keystore" + } + // If the keystore doesn't exist, the release build will fail + // with a clear "Keystore file not set for signing config + // release" message — by design. + } } buildTypes { @@ -23,9 +51,8 @@ android { isMinifyEnabled = false } release { - isMinifyEnabled = false - // Release signing config is intentionally absent for v0.1 — - // we'll set up a proper key in a follow-up. + isMinifyEnabled = false // TODO(v0.3): enable R8 + signingConfig = signingConfigs.getByName("release") } } diff --git a/composeApp/src/main/kotlin/org/incido/compose/ui/editor/NoteColors.kt b/composeApp/src/main/kotlin/org/incido/compose/ui/editor/NoteColors.kt new file mode 100644 index 0000000..76656d9 --- /dev/null +++ b/composeApp/src/main/kotlin/org/incido/compose/ui/editor/NoteColors.kt @@ -0,0 +1,40 @@ +package org.incido.compose.ui.editor + +import androidx.compose.material3.MaterialTheme +import androidx.compose.runtime.Composable +import androidx.compose.runtime.ReadOnlyComposable +import androidx.compose.ui.graphics.Color +import org.incido.domain.model.NoteColor + +/** + * Maps a [NoteColor] enum to a Compose [Color] using Material 3 tokens so + * the swatches adapt to light/dark theme automatically. + */ +@Composable +@ReadOnlyComposable +fun NoteColor.toComposeColor(): Color = when (this) { + NoteColor.NONE -> Color.Transparent + NoteColor.BLUE -> Color(0xFF4A6FA5) + NoteColor.GREEN -> Color(0xFF4F8A5B) + NoteColor.AMBER -> Color(0xFFB8862B) + NoteColor.RED -> Color(0xFFB14B4B) + NoteColor.PURPLE -> Color(0xFF7B5BA6) +} + +val AllNoteColors: List = listOf( + NoteColor.NONE, + NoteColor.BLUE, + NoteColor.GREEN, + NoteColor.AMBER, + NoteColor.RED, + NoteColor.PURPLE, +) + +/** + * A swatch surface colour for a swatch button — used to give the + * selected swatch a visible border by reading the theme's outline. + */ +val swatchBorderColor: Color + @Composable + @ReadOnlyComposable + get() = MaterialTheme.colorScheme.outline diff --git a/composeApp/src/main/kotlin/org/incido/compose/ui/editor/NoteEditorScreen.kt b/composeApp/src/main/kotlin/org/incido/compose/ui/editor/NoteEditorScreen.kt index 67ca932..0dbd13c 100644 --- a/composeApp/src/main/kotlin/org/incido/compose/ui/editor/NoteEditorScreen.kt +++ b/composeApp/src/main/kotlin/org/incido/compose/ui/editor/NoteEditorScreen.kt @@ -1,34 +1,52 @@ package org.incido.compose.ui.editor +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.WindowInsets import androidx.compose.foundation.layout.fillMaxSize +import androidx.compose.foundation.layout.fillMaxWidth import androidx.compose.foundation.layout.ime import androidx.compose.foundation.layout.padding +import androidx.compose.foundation.layout.size import androidx.compose.foundation.layout.systemBars import androidx.compose.foundation.layout.union +import androidx.compose.foundation.lazy.LazyRow +import androidx.compose.foundation.shape.CircleShape import androidx.compose.foundation.text.KeyboardOptions import androidx.compose.material.icons.Icons import androidx.compose.material.icons.automirrored.filled.ArrowBack import androidx.compose.material.icons.filled.Delete import androidx.compose.material.icons.filled.Done import androidx.compose.material.icons.filled.MoreVert +import androidx.compose.material.icons.filled.Star +import androidx.compose.material.icons.outlined.StarOutline +import androidx.compose.material3.AlertDialog import androidx.compose.material3.DropdownMenu import androidx.compose.material3.DropdownMenuItem import androidx.compose.material3.ExperimentalMaterial3Api import androidx.compose.material3.Icon import androidx.compose.material3.IconButton +import androidx.compose.material3.MaterialTheme import androidx.compose.material3.OutlinedTextField import androidx.compose.material3.Scaffold import androidx.compose.material3.Text +import androidx.compose.material3.TextButton import androidx.compose.material3.TopAppBar 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.saveable.rememberSaveable import androidx.compose.runtime.setValue import androidx.compose.ui.Modifier +import androidx.compose.ui.draw.clip import androidx.compose.ui.focus.FocusRequester import androidx.compose.ui.focus.focusRequester import androidx.compose.ui.text.input.ImeAction @@ -36,6 +54,7 @@ import androidx.compose.ui.text.input.KeyboardCapitalization import androidx.compose.ui.unit.dp import androidx.lifecycle.compose.collectAsStateWithLifecycle import androidx.lifecycle.viewmodel.compose.viewModel +import org.incido.domain.model.NoteColor @OptIn(ExperimentalMaterial3Api::class) @Composable @@ -50,10 +69,10 @@ fun NoteEditorScreen( val state by viewModel.state.collectAsStateWithLifecycle() val focusRequester = remember { FocusRequester() } var menuExpanded by remember { mutableStateOf(false) } + var showDiscardDialog by rememberSaveable { mutableStateOf(false) } LaunchedEffect(state.isLoading) { if (!state.isLoading && state.existing != null) { - // Focus the field so the user can immediately edit existing notes. focusRequester.requestFocus() } } @@ -61,6 +80,43 @@ fun NoteEditorScreen( if (noteId == null) focusRequester.requestFocus() } + fun isDirty(): Boolean { + if (state.isLoading) return false + return state.isDirty( + initialContent = viewModel.initialContent, + initialFavorite = viewModel.initialFavorite, + initialColor = viewModel.initialColor, + ) + } + + fun tryClose() { + if (isDirty()) showDiscardDialog = true else onClose() + } + + // Intercept hardware / gesture back to honour the same discard rule. + BackHandler(enabled = true) { tryClose() } + + if (showDiscardDialog) { + AlertDialog( + onDismissRequest = { showDiscardDialog = false }, + title = { Text("Discard changes?") }, + text = { Text("You have unsaved edits. Leaving now will discard them.") }, + confirmButton = { + TextButton(onClick = { + showDiscardDialog = false + onClose() + }) { + Text("Discard") + } + }, + dismissButton = { + TextButton(onClick = { showDiscardDialog = false }) { + Text("Keep editing") + } + }, + ) + } + Scaffold( // Union systemBars + IME insets so the Scaffold's contentPadding // shrinks the available area when the soft keyboard opens. With @@ -72,11 +128,19 @@ fun NoteEditorScreen( TopAppBar( title = { Text(if (state.isEditing) "Edit note" else "New note") }, navigationIcon = { - IconButton(onClick = onClose) { + IconButton(onClick = { tryClose() }) { Icon(Icons.AutoMirrored.Filled.ArrowBack, contentDescription = "Back") } }, actions = { + IconButton(onClick = { viewModel.toggleFavorite() }) { + Icon( + imageVector = if (state.isFavorite) Icons.Filled.Star else Icons.Outlined.StarOutline, + contentDescription = if (state.isFavorite) "Unfavorite" else "Favorite", + tint = if (state.isFavorite) MaterialTheme.colorScheme.primary + else MaterialTheme.colorScheme.onSurfaceVariant, + ) + } IconButton( onClick = { viewModel.save(onClose) }, enabled = state.canSave, @@ -107,17 +171,33 @@ fun NoteEditorScreen( ) }, ) { padding -> - Box( + Column( modifier = Modifier .fillMaxSize() .padding(padding), ) { + // Colour-picker row (above the editor). + LazyRow( + modifier = Modifier + .fillMaxWidth() + .padding(horizontal = 16.dp, vertical = 8.dp), + horizontalArrangement = Arrangement.spacedBy(12.dp), + ) { + items(items = AllNoteColors, key = { it.storageKey.toInt() }) { color -> + ColorSwatch( + color = color, + selected = state.color == color, + onClick = { viewModel.setColor(color) }, + ) + } + } OutlinedTextField( value = state.content, onValueChange = viewModel::onContentChange, modifier = Modifier .fillMaxSize() - .padding(16.dp) + .padding(horizontal = 16.dp) + .padding(bottom = 16.dp) .focusRequester(focusRequester), placeholder = { Text("Write something…") }, keyboardOptions = KeyboardOptions( @@ -128,3 +208,31 @@ fun NoteEditorScreen( } } } + +private fun androidx.compose.foundation.lazy.LazyListScope.items( + items: List, + key: (NoteColor) -> Any, + itemContent: @Composable (NoteColor) -> Unit, +) { + items(items.size, key = { key(items[it]) }) { idx -> itemContent(items[idx]) } +} + +@Composable +private fun ColorSwatch( + color: NoteColor, + selected: Boolean, + onClick: () -> Unit, +) { + val fillColor = color.toComposeColor() + val border = if (selected) swatchBorderColor else MaterialTheme.colorScheme.outlineVariant + val borderWidth = if (selected) 2.dp else 1.dp + + Box( + modifier = Modifier + .size(36.dp) + .clip(CircleShape) + .background(fillColor) + .border(borderWidth, border, CircleShape) + .clickable(onClick = onClick), + ) +} diff --git a/composeApp/src/main/kotlin/org/incido/compose/ui/editor/NoteEditorViewModel.kt b/composeApp/src/main/kotlin/org/incido/compose/ui/editor/NoteEditorViewModel.kt index bbb2d5b..b1cdc23 100644 --- a/composeApp/src/main/kotlin/org/incido/compose/ui/editor/NoteEditorViewModel.kt +++ b/composeApp/src/main/kotlin/org/incido/compose/ui/editor/NoteEditorViewModel.kt @@ -4,7 +4,6 @@ import androidx.lifecycle.ViewModel import androidx.lifecycle.ViewModelProvider import androidx.lifecycle.ViewModelProvider.AndroidViewModelFactory.Companion.APPLICATION_KEY import androidx.lifecycle.viewModelScope -import androidx.lifecycle.viewmodel.CreationExtras import androidx.lifecycle.viewmodel.initializer import androidx.lifecycle.viewmodel.viewModelFactory import kotlinx.coroutines.flow.MutableStateFlow @@ -14,6 +13,7 @@ import kotlinx.coroutines.flow.update import kotlinx.coroutines.launch import org.incido.compose.IncidoApplication import org.incido.domain.model.Note +import org.incido.domain.model.NoteColor import org.incido.domain.repository.NoteRepository /** @@ -23,12 +23,25 @@ import org.incido.domain.repository.NoteRepository data class NoteEditorUiState( val existing: Note? = null, val content: String = "", + val isFavorite: Boolean = false, + val color: NoteColor = NoteColor.NONE, val isLoading: Boolean = true, val isSaving: Boolean = false, val isDeleted: Boolean = false, ) { val canSave: Boolean get() = content.isNotBlank() && !isSaving val isEditing: Boolean get() = existing != null + + /** + * True when the editor has changes that haven't been saved. Used by + * the discard-confirm dialog in [NoteEditorScreen] to decide whether + * to prompt before closing. + */ + fun isDirty(initialContent: String, initialFavorite: Boolean, initialColor: NoteColor): Boolean { + return content != initialContent || + isFavorite != initialFavorite || + color != initialColor + } } class NoteEditorViewModel( @@ -39,6 +52,17 @@ class NoteEditorViewModel( private val _state = MutableStateFlow(NoteEditorUiState()) val state: StateFlow = _state.asStateFlow() + /** + * Snapshot of the initial state when the editor loaded. Used by + * [NoteEditorScreen] to compute the discard-confirm predicate. + */ + var initialContent: String = "" + private set + var initialFavorite: Boolean = false + private set + var initialColor: NoteColor = NoteColor.NONE + private set + init { if (noteId == null || noteId == 0L) { // New note @@ -46,10 +70,18 @@ class NoteEditorViewModel( } else { viewModelScope.launch { repository.observeById(noteId).collect { note -> + if (note != null && _state.value.isLoading) { + // First non-null load — capture the initial snapshot. + initialContent = note.content + initialFavorite = note.isFavorite + initialColor = note.color + } _state.update { it.copy( existing = note, content = note?.content ?: it.content, + isFavorite = note?.isFavorite ?: it.isFavorite, + color = note?.color ?: it.color, isLoading = false, ) } @@ -62,17 +94,30 @@ class NoteEditorViewModel( _state.update { it.copy(content = newContent) } } + fun toggleFavorite() { + _state.update { it.copy(isFavorite = !it.isFavorite) } + } + + fun setColor(color: NoteColor) { + _state.update { it.copy(color = color) } + } + fun save(onDone: () -> Unit) { val current = _state.value if (!current.canSave) return _state.update { it.copy(isSaving = true) } viewModelScope.launch { - val toPersist = current.existing?.copy(content = current.content) - ?: Note( - content = current.content, - createdAt = System.currentTimeMillis(), - updatedAt = System.currentTimeMillis(), - ) + val toPersist = current.existing?.copy( + content = current.content, + isFavorite = current.isFavorite, + color = current.color, + ) ?: Note( + content = current.content, + createdAt = System.currentTimeMillis(), + updatedAt = System.currentTimeMillis(), + isFavorite = current.isFavorite, + color = current.color, + ) repository.upsert(toPersist) _state.update { it.copy(isSaving = false) } onDone() diff --git a/composeApp/src/main/kotlin/org/incido/compose/ui/notelist/NoteListScreen.kt b/composeApp/src/main/kotlin/org/incido/compose/ui/notelist/NoteListScreen.kt index 0c89d5d..7e65310 100644 --- a/composeApp/src/main/kotlin/org/incido/compose/ui/notelist/NoteListScreen.kt +++ b/composeApp/src/main/kotlin/org/incido/compose/ui/notelist/NoteListScreen.kt @@ -1,5 +1,6 @@ package org.incido.compose.ui.notelist +import androidx.compose.foundation.background import androidx.compose.foundation.layout.Arrangement import androidx.compose.foundation.layout.Box import androidx.compose.foundation.layout.Column @@ -9,30 +10,44 @@ 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.lazy.LazyColumn import androidx.compose.foundation.lazy.items +import androidx.compose.foundation.shape.RoundedCornerShape import androidx.compose.material.icons.Icons import androidx.compose.material.icons.filled.Add +import androidx.compose.material.icons.filled.CheckBox import androidx.compose.material.icons.filled.Delete +import androidx.compose.material.icons.filled.Search +import androidx.compose.material.icons.filled.Star +import androidx.compose.material.icons.outlined.StarOutline import androidx.compose.material3.Card import androidx.compose.material3.ExperimentalMaterial3Api import androidx.compose.material3.FloatingActionButton import androidx.compose.material3.Icon import androidx.compose.material3.IconButton import androidx.compose.material3.MaterialTheme +import androidx.compose.material3.OutlinedTextField import androidx.compose.material3.Scaffold import androidx.compose.material3.Text import androidx.compose.material3.TopAppBar 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.style.TextOverflow import androidx.compose.ui.unit.dp import androidx.lifecycle.compose.collectAsStateWithLifecycle import androidx.lifecycle.viewmodel.compose.viewModel +import org.incido.compose.ui.editor.toComposeColor import org.incido.compose.util.rememberRelativeTimestamp import org.incido.domain.model.Note +import org.incido.domain.model.NoteColor @OptIn(ExperimentalMaterial3Api::class) @Composable @@ -41,36 +56,67 @@ fun NoteListScreen( viewModel: NoteListViewModel = viewModel(factory = NoteListViewModel.Factory), ) { val state by viewModel.uiState.collectAsStateWithLifecycle() + var localQuery by remember { mutableStateOf("") } Scaffold( topBar = { - TopAppBar(title = { Text("Incido") }) + TopAppBar( + title = { Text("Incido") }, + actions = { + IconButton(onClick = { + if (state.isSearchActive) viewModel.closeSearch() else viewModel.openSearch() + localQuery = "" + }) { + Icon(Icons.Default.Search, contentDescription = "Search notes") + } + }, + ) }, floatingActionButton = { - FloatingActionButton(onClick = { onOpenEditor(null) }) { - Icon(Icons.Default.Add, contentDescription = "New note") + if (!state.isSearchActive) { + FloatingActionButton(onClick = { onOpenEditor(null) }) { + Icon(Icons.Default.Add, contentDescription = "New note") + } } }, ) { padding -> - when { - state.isLoading -> Unit // briefly blank on first composition - state.isEmpty -> EmptyState(padding) - else -> NoteList( - notes = state.notes, - contentPadding = padding, - onClick = { onOpenEditor(it.id) }, - onDelete = viewModel::delete, - ) + Column(modifier = Modifier.padding(padding)) { + if (state.isSearchActive) { + OutlinedTextField( + value = localQuery, + onValueChange = { + localQuery = it + viewModel.onQueryChange(it) + }, + placeholder = { Text("Search notes…") }, + leadingIcon = { Icon(Icons.Default.Search, contentDescription = null) }, + singleLine = true, + modifier = Modifier + .fillMaxWidth() + .padding(horizontal = 16.dp, vertical = 8.dp), + ) + } + + when { + state.isLoading -> Unit + state.isEmpty -> EmptyState() + state.noResults -> NoResultsState() + else -> NoteList( + notes = state.notes, + onClick = { onOpenEditor(it.id) }, + onDelete = viewModel::delete, + onToggleFavorite = viewModel::toggleFavorite, + ) + } } } } @Composable -private fun EmptyState(padding: PaddingValues) { +private fun EmptyState() { Box( modifier = Modifier .fillMaxSize() - .padding(padding) .padding(24.dp), contentAlignment = Alignment.Center, ) { @@ -82,18 +128,34 @@ private fun EmptyState(padding: PaddingValues) { } } +@Composable +private fun NoResultsState() { + Box( + modifier = Modifier + .fillMaxSize() + .padding(24.dp), + contentAlignment = Alignment.Center, + ) { + Text( + text = "No matching notes.", + style = MaterialTheme.typography.bodyLarge, + color = MaterialTheme.colorScheme.onSurfaceVariant, + ) + } +} + @Composable private fun NoteList( notes: List, - contentPadding: PaddingValues, onClick: (Note) -> Unit, onDelete: (Long) -> Unit, + onToggleFavorite: (Long, Boolean) -> Unit, ) { LazyColumn( modifier = Modifier.fillMaxSize(), contentPadding = PaddingValues( - top = contentPadding.calculateTopPadding() + 8.dp, - bottom = contentPadding.calculateBottomPadding() + 88.dp, // FAB clearance + top = 8.dp, + bottom = 88.dp, // FAB clearance start = 16.dp, end = 16.dp, ), @@ -104,6 +166,7 @@ private fun NoteList( note = note, onClick = { onClick(note) }, onDelete = { onDelete(note.id) }, + onToggleFavorite = { onToggleFavorite(note.id, !note.isFavorite) }, ) } } @@ -114,52 +177,94 @@ private fun NoteCard( note: Note, onClick: () -> Unit, onDelete: () -> Unit, + onToggleFavorite: () -> Unit, ) { val (title, body) = Note.titleAndBody(note.content) val bodyPreview = Note.bodyPreview(body) + val checklistSummary = Note.checklistSummary(note.content) + val stripeColor = note.color.toComposeColor() Card( onClick = onClick, modifier = Modifier.fillMaxWidth(), ) { - Column( - modifier = Modifier.padding(16.dp), - ) { - Text( - text = title, - style = MaterialTheme.typography.titleMedium, - maxLines = 1, - overflow = TextOverflow.Ellipsis, + Row(modifier = Modifier.fillMaxWidth()) { + // 4dp coloured accent stripe on the left. + Box( + modifier = Modifier + .size(width = 4.dp, height = 96.dp) + .background(stripeColor), ) - if (bodyPreview.isNotEmpty()) { - Spacer(modifier = Modifier.padding(top = 4.dp)) - Text( - text = bodyPreview, - style = MaterialTheme.typography.bodyMedium, - color = MaterialTheme.colorScheme.onSurfaceVariant, - maxLines = 2, - overflow = TextOverflow.Ellipsis, - ) - } - Spacer(modifier = Modifier.padding(top = 8.dp)) - Row( - modifier = Modifier.fillMaxWidth(), - verticalAlignment = Alignment.CenterVertically, - horizontalArrangement = Arrangement.SpaceBetween, - ) { - Text( - text = rememberRelativeTimestamp(note.updatedAt), - style = MaterialTheme.typography.labelSmall, - color = MaterialTheme.colorScheme.onSurfaceVariant, - ) - IconButton(onClick = onDelete) { - Icon( - Icons.Default.Delete, - contentDescription = "Delete note", - tint = MaterialTheme.colorScheme.onSurfaceVariant, + Column(modifier = Modifier.padding(16.dp).fillMaxWidth()) { + Row( + modifier = Modifier.fillMaxWidth(), + verticalAlignment = Alignment.CenterVertically, + ) { + Text( + text = title, + style = MaterialTheme.typography.titleMedium, + maxLines = 1, + overflow = TextOverflow.Ellipsis, + modifier = Modifier.weight(1f), ) + IconButton(onClick = onToggleFavorite) { + Icon( + imageVector = if (note.isFavorite) Icons.Filled.Star else Icons.Outlined.StarOutline, + contentDescription = if (note.isFavorite) "Unfavorite" else "Favorite", + tint = if (note.isFavorite) MaterialTheme.colorScheme.primary + else MaterialTheme.colorScheme.onSurfaceVariant, + ) + } + } + if (bodyPreview.isNotEmpty()) { + Spacer(modifier = Modifier.padding(top = 4.dp)) + Text( + text = bodyPreview, + style = MaterialTheme.typography.bodyMedium, + color = MaterialTheme.colorScheme.onSurfaceVariant, + maxLines = 2, + overflow = TextOverflow.Ellipsis, + ) + } + if (checklistSummary.isNotEmpty()) { + Spacer(modifier = Modifier.padding(top = 4.dp)) + Row(verticalAlignment = Alignment.CenterVertically) { + Icon( + Icons.Default.CheckBox, + contentDescription = null, + modifier = Modifier.size(14.dp), + tint = MaterialTheme.colorScheme.onSurfaceVariant, + ) + Spacer(modifier = Modifier.size(6.dp)) + Text( + text = checklistSummary, + style = MaterialTheme.typography.labelSmall, + color = MaterialTheme.colorScheme.onSurfaceVariant, + ) + } + } + Spacer(modifier = Modifier.padding(top = 8.dp)) + Row( + modifier = Modifier.fillMaxWidth(), + verticalAlignment = Alignment.CenterVertically, + horizontalArrangement = Arrangement.SpaceBetween, + ) { + Text( + text = rememberRelativeTimestamp(note.updatedAt), + style = MaterialTheme.typography.labelSmall, + color = MaterialTheme.colorScheme.onSurfaceVariant, + ) + IconButton(onClick = onDelete) { + Icon( + Icons.Default.Delete, + contentDescription = "Delete note", + tint = MaterialTheme.colorScheme.onSurfaceVariant, + ) + } } } } } } + + diff --git a/composeApp/src/main/kotlin/org/incido/compose/ui/notelist/NoteListViewModel.kt b/composeApp/src/main/kotlin/org/incido/compose/ui/notelist/NoteListViewModel.kt index eb62ff8..e5ed3b5 100644 --- a/composeApp/src/main/kotlin/org/incido/compose/ui/notelist/NoteListViewModel.kt +++ b/composeApp/src/main/kotlin/org/incido/compose/ui/notelist/NoteListViewModel.kt @@ -6,9 +6,14 @@ import androidx.lifecycle.ViewModelProvider.AndroidViewModelFactory.Companion.AP import androidx.lifecycle.viewModelScope import androidx.lifecycle.viewmodel.initializer import androidx.lifecycle.viewmodel.viewModelFactory +import kotlinx.coroutines.ExperimentalCoroutinesApi +import kotlinx.coroutines.FlowPreview +import kotlinx.coroutines.flow.MutableStateFlow import kotlinx.coroutines.flow.SharingStarted import kotlinx.coroutines.flow.StateFlow -import kotlinx.coroutines.flow.map +import kotlinx.coroutines.flow.asStateFlow +import kotlinx.coroutines.flow.debounce +import kotlinx.coroutines.flow.flatMapLatest import kotlinx.coroutines.flow.stateIn import kotlinx.coroutines.launch import org.incido.compose.IncidoApplication @@ -23,27 +28,72 @@ import org.incido.domain.repository.NoteRepository data class NoteListUiState( val notes: List = emptyList(), val isLoading: Boolean = true, + val searchQuery: String = "", + val isSearchActive: Boolean = false, ) { - val isEmpty: Boolean get() = !isLoading && notes.isEmpty() + val isEmpty: Boolean get() = !isLoading && notes.isEmpty() && !isSearchActive + val noResults: Boolean get() = !isLoading && notes.isEmpty() && isSearchActive } +@OptIn(ExperimentalCoroutinesApi::class, FlowPreview::class) class NoteListViewModel( private val repository: NoteRepository, ) : ViewModel() { + private val rawQuery = MutableStateFlow("") + private val _isSearchActive = MutableStateFlow(false) + val isSearchActive: StateFlow = _isSearchActive.asStateFlow() + val uiState: StateFlow = - repository.observeAll() - .map { NoteListUiState(notes = it, isLoading = false) } + rawQuery + .debounce(150) + .flatMapLatest { q -> + if (q.isBlank()) { + repository.observeAll() + } else { + repository.search(q) + } + } .stateIn( scope = viewModelScope, started = SharingStarted.WhileSubscribed(5_000), - initialValue = NoteListUiState(), + initialValue = emptyList(), ) + .let { notesFlow -> + kotlinx.coroutines.flow.MutableStateFlow(NoteListUiState()) + .also { state -> + viewModelScope.launch { + notesFlow.collect { latest -> + state.value = state.value.copy( + notes = latest, + isLoading = false, + ) + } + } + } + } + + fun onQueryChange(q: String) { + rawQuery.value = q + } + + fun openSearch() { + _isSearchActive.value = true + } + + fun closeSearch() { + _isSearchActive.value = false + rawQuery.value = "" + } fun delete(id: Long) { viewModelScope.launch { repository.delete(id) } } + fun toggleFavorite(id: Long, isFavorite: Boolean) { + viewModelScope.launch { repository.setFavorite(id, isFavorite) } + } + companion object { val Factory: ViewModelProvider.Factory = viewModelFactory { initializer { diff --git a/core/data/src/main/kotlin/org/incido/data/entity/NoteEntity.kt b/core/data/src/main/kotlin/org/incido/data/entity/NoteEntity.kt index d677825..2331d93 100644 --- a/core/data/src/main/kotlin/org/incido/data/entity/NoteEntity.kt +++ b/core/data/src/main/kotlin/org/incido/data/entity/NoteEntity.kt @@ -4,10 +4,14 @@ import io.objectbox.annotation.Entity import io.objectbox.annotation.Id import io.objectbox.annotation.Index import org.incido.domain.model.Note +import org.incido.domain.model.NoteColor /** * ObjectBox entity. The plugin generates a corresponding property mirror * class (`NoteEntity_`) at build time, plus the [MyObjectBox] container. + * + * v0.2 adds [isFavorite] and [color]. Both are additive (the prior v0.1 + * schema had neither) so existing user notes auto-migrate on first launch. */ @Entity data class NoteEntity( @@ -15,6 +19,8 @@ data class NoteEntity( var content: String = "", @Index var createdAt: Long = 0, var updatedAt: Long = 0, + @Index var isFavorite: Boolean = false, + var colorKey: Short = 0, ) internal fun NoteEntity.toDomain(): Note = Note( @@ -22,6 +28,8 @@ internal fun NoteEntity.toDomain(): Note = Note( content = content, createdAt = createdAt, updatedAt = updatedAt, + isFavorite = isFavorite, + color = NoteColor.fromStorageKey(colorKey), ) internal fun Note.toEntity(): NoteEntity = NoteEntity( @@ -29,4 +37,6 @@ internal fun Note.toEntity(): NoteEntity = NoteEntity( content = content, createdAt = createdAt, updatedAt = updatedAt, + isFavorite = isFavorite, + colorKey = color.storageKey, ) diff --git a/core/data/src/main/kotlin/org/incido/data/repository/NoteRepositoryImpl.kt b/core/data/src/main/kotlin/org/incido/data/repository/NoteRepositoryImpl.kt index 1df819d..abe741d 100644 --- a/core/data/src/main/kotlin/org/incido/data/repository/NoteRepositoryImpl.kt +++ b/core/data/src/main/kotlin/org/incido/data/repository/NoteRepositoryImpl.kt @@ -9,6 +9,7 @@ import kotlinx.coroutines.flow.callbackFlow import kotlinx.coroutines.flow.flowOn import kotlinx.coroutines.Dispatchers import org.incido.data.entity.NoteEntity +import org.incido.data.entity.NoteEntity_ import org.incido.data.entity.toDomain import org.incido.data.entity.toEntity import org.incido.domain.model.Note @@ -18,6 +19,9 @@ import org.incido.domain.repository.NoteRepository * ObjectBox-backed implementation of [NoteRepository]. All writes are * dispatched to `Default`; reads use ObjectBox's reactive subscription so * the UI auto-refreshes whenever a row changes (F7). + * + * Sort order is `isFavorite DESC, updatedAt DESC` for both [observeAll] and + * [search] so favourites always float to the top. */ class NoteRepositoryImpl( private val boxStore: BoxStore, @@ -26,15 +30,28 @@ class NoteRepositoryImpl( private val box = boxStore.boxFor() override fun observeAll(): Flow> = callbackFlow { - // Emit the current snapshot first so the UI renders without waiting - // for the first change. - trySend(currentSnapshot()) + trySend(sortedSnapshot("")) - val subscription: DataSubscription = box + val subscription = box .query() .build() .subscribe() - .observer { trySend(currentSnapshot()) } + .observer { trySend(sortedSnapshot("")) } + + awaitClose { subscription.cancel() } + }.flowOn(Dispatchers.Default) + + override fun search(query: String): Flow> = callbackFlow { + trySend(sortedSnapshot(query)) + + val subscription = if (query.isBlank()) { + box.query().build().subscribe() + } else { + box.query() + .contains(NoteEntity_.content, query, io.objectbox.query.QueryBuilder.StringOrder.CASE_INSENSITIVE) + .build() + .subscribe() + }.observer { trySend(sortedSnapshot(query)) } awaitClose { subscription.cancel() } }.flowOn(Dispatchers.Default) @@ -67,6 +84,30 @@ class NoteRepositoryImpl( box.remove(id) } - private fun currentSnapshot(): List = - box.all.sortedByDescending { it.updatedAt }.map { it.toDomain() } + override suspend fun setFavorite(id: Long, isFavorite: Boolean) { + val entity = box.get(id) ?: return + if (entity.isFavorite == isFavorite) return + entity.isFavorite = isFavorite + box.put(entity) + } + + /** + * Snapshot helper. If [query] is non-blank, only notes whose content + * contains it (case-insensitive) are included; otherwise all notes. + * The result is sorted favourites-first, then newest-first. + */ + private fun sortedSnapshot(query: String): List { + val raw = if (query.isBlank()) { + box.all + } else { + box.query() + .contains(NoteEntity_.content, query, io.objectbox.query.QueryBuilder.StringOrder.CASE_INSENSITIVE) + .build() + .find() + } + return raw.sortedWith( + compareByDescending { it.isFavorite } + .thenByDescending { it.updatedAt } + ).map { it.toDomain() } + } } diff --git a/core/domain/src/main/kotlin/org/incido/domain/model/Note.kt b/core/domain/src/main/kotlin/org/incido/domain/model/Note.kt index bb431bc..9d33a90 100644 --- a/core/domain/src/main/kotlin/org/incido/domain/model/Note.kt +++ b/core/domain/src/main/kotlin/org/incido/domain/model/Note.kt @@ -10,6 +10,8 @@ data class Note( val content: String, val createdAt: Long, val updatedAt: Long, + val isFavorite: Boolean = false, + val color: NoteColor = NoteColor.NONE, ) { companion object { private const val UNTITLED = "Untitled" @@ -60,5 +62,35 @@ data class Note( if (collapsed.length <= maxChars) return collapsed return collapsed.take(maxChars).trimEnd() + "…" } + + /** + * Parses GitHub-flavoured task-list lines from [content] and + * returns (openCount, doneCount). Lines starting with `- [ ]` count + * as open; `- [x]` (case-insensitive) count as done. + */ + fun checklistCounts(content: String): Pair { + val pattern = Regex("""^\s*-\s+\[( x| )]""", RegexOption.IGNORE_CASE) + var open = 0 + var done = 0 + content.lineSequence().forEach { line -> + val match = pattern.find(line) ?: return@forEach + val isDone = match.groupValues[1].equals("x", ignoreCase = true) + if (isDone) done++ else open++ + } + return open to done + } + + /** + * Convenience: "1 open" / "2 open · 3 done" / empty when no items. + */ + fun checklistSummary(content: String): String { + val (open, done) = checklistCounts(content) + return when { + open == 0 && done == 0 -> "" + done == 0 -> "$open open" + open == 0 -> "$done done" + else -> "$open open · $done done" + } + } } } diff --git a/core/domain/src/main/kotlin/org/incido/domain/model/NoteColor.kt b/core/domain/src/main/kotlin/org/incido/domain/model/NoteColor.kt new file mode 100644 index 0000000..8814855 --- /dev/null +++ b/core/domain/src/main/kotlin/org/incido/domain/model/NoteColor.kt @@ -0,0 +1,21 @@ +package org.incido.domain.model + +/** + * Six preset accent colours for notes, plus a sentinel "no colour" value. + * Stored as a short (`SHORT`) in ObjectBox — additive-safe migration from + * the v0.1 schema. + */ +enum class NoteColor(val storageKey: Short) { + NONE(0), + BLUE(1), + GREEN(2), + AMBER(3), + RED(4), + PURPLE(5); + + companion object { + /** Convert from the stored [Short] back to the enum, defaulting to [NONE]. */ + fun fromStorageKey(key: Short): NoteColor = + values().firstOrNull { it.storageKey == key } ?: NONE + } +} diff --git a/core/domain/src/main/kotlin/org/incido/domain/repository/NoteRepository.kt b/core/domain/src/main/kotlin/org/incido/domain/repository/NoteRepository.kt index 3b5161f..fae0632 100644 --- a/core/domain/src/main/kotlin/org/incido/domain/repository/NoteRepository.kt +++ b/core/domain/src/main/kotlin/org/incido/domain/repository/NoteRepository.kt @@ -12,11 +12,20 @@ import org.incido.domain.model.Note * so the list screen satisfies F7 (auto-refresh). * - Assign a fresh id (0 or 0L on construction) for new notes and use the * ObjectBox-managed id once persisted. + * - Sort [observeAll] / [search] with favourites first, then by [Note.updatedAt] + * descending. */ interface NoteRepository { - /** Stream of all notes, newest-first. */ + /** Stream of all notes, newest-first, favourites pinned to the top. */ fun observeAll(): Flow> + /** + * Stream of notes whose [Note.content] contains [query] (case-insensitive), + * favourites first then newest-first. An empty / blank [query] returns + * the same list as [observeAll]. + */ + fun search(query: String): Flow> + /** Stream of a single note by id, or `null` if it has been deleted. */ fun observeById(id: Long): Flow @@ -25,4 +34,7 @@ interface NoteRepository { /** Delete a note by id. No-op if it doesn't exist. */ suspend fun delete(id: Long) + + /** Toggle the favourite flag on a single note. */ + suspend fun setFavorite(id: Long, isFavorite: Boolean) } diff --git a/keystore/README.md b/keystore/README.md new file mode 100644 index 0000000..472407a --- /dev/null +++ b/keystore/README.md @@ -0,0 +1,42 @@ +# Release keystore + +The actual `.jks` files in this directory are gitignored (see +`/home/nick/.gitignore` / `.gitignore` rules under "Release keystore"). + +This directory ships with **no checked-in keys** — every developer (and +the CI runner) is expected to generate their own. + +## Generate a local dev keystore + +This is the keystore the project's default `signingConfigs.release` points +at. Replace before publishing to any app store. + +```bash +keytool -genkey -v \ + -keystore release.jks \ + -keyalg RSA -keysize 2048 -validity 10000 \ + -alias incido \ + -storepass incido_dev_keystore \ + -keypass incido_dev_keystore \ + -dname "CN=Incido Dev, OU=Local, O=Incido, L=Local, ST=Local, C=NZ" +``` + +The store password and key password are both +`incido_dev_keystore` — change them before publishing. + +## For Play Store / F-Droid distribution + +Generate a **separate** production keystore and store the credentials +outside the repo (CI secrets, password manager, etc.). Replace the +`signingConfigs.release` block in `app/build.gradle.kts` with one that +reads from `~/.gradle/gradle.properties` or environment variables so the +real passwords are never committed. + +Do **not** lose your production keystore — without it you can never +publish updates under the same `applicationId`/`packageName`. + +## CI + +Gitea Actions (`/.gitea/workflows/build.yml`) currently only builds the +**debug** APK, which uses the auto-generated Android debug keystore. +Add a `release` job once you have secrets for the production key.