ROLE You are a senior Android engineer. Build a complete, wo...
Prompt
ROLE You are a senior Android engineer. Build a complete, working Android APK called "Reader": an AI file reader that reads any file with total coverage (no skipping, no summarizing early, no guessing) and then analyzes it and produces the outcomes I ask for. Build step by step. After each step, show what was built and wait for "continue" before moving on. STACK Kotlin, Jetpack Compose, MVVM, Room (SQLite), WorkManager, Kotlin Coroutines/Flow, Retrofit/OkHttp with SSE streaming. Min SDK 26. Output a full project plus build instructions for a debug APK. CORE PRINCIPLE: READ-FIRST HARNESS The app is built around a Reader Engine, not a chat box. The AI never answers from a file until the engine has fully read it. Every answer must be traceable back to exact positions in the source. 1. INGESTION - Open files via the Storage Access Framework. Support TXT, MD, CSV, JSON, XML, HTML, PDF, DOCX, code files, and images/scanned pages (OCR via ML Kit). - Normalize everything into one canonical text with a stable index: file, page, paragraph, sentence, line, word (each with character offsets). - Store the full index in Room so reading survives app kills. 2. READING MODES (user selectable, all use the same index) - Word by word, sentence by sentence, line by line, paragraph by paragraph. - Each mode walks the index in strict order, one unit at a time, never skipping a unit. Each unit is sent to the AI with a small rolling context window (previous N units) and a running memory note. - Every unit gets a recorded result: read status, AI observation, entities/terms found, flags. 3. COVERAGE GUARANTEE (anti-skipping, anti-scheming) - A Coverage Ledger tracks every unit as: pending, read, failed, retried. - The AI cannot finish, summarize, or produce outputs until coverage = 100%. Failed units auto-retry, then surface to the user. - Show a live coverage bar and a "verify" action that re-checks the ledger against the file's checksum and unit count. - Each AI step must return strict JSON (unit id, what it read, observations). Reject and retry any response that is missing, malformed, or references a unit id that wasn't sent. - Every claim in the final output must cite unit ids/locations. Tapping a citation jumps to the exact highlighted text. 4. ANALYSIS LAYER (runs after full read) - Multi-pass: pass 1 reads units, pass 2 builds paragraph/section summaries from unit notes, pass 3 builds a whole-document model (themes, entities, claims, contradictions, structure). - Reasoning is grounded only in the ledger and notes, never invented content. 5. OUTCOMES (user states desired result in plain language) - Summary (short/medium/full), Q&A, extraction (tables, entities, dates, action items), rewrite/translate, proofreading with line-level issues, compare two files, study notes/flashcards, report generation. - Export to TXT, MD, PDF, DOCX, JSON. 6. PROVIDERS (OpenAI-compatible) - Settings screen to add multiple providers: name, base URL, API key, model, and custom headers. - Use /v1/chat/completions with streaming. Test-connection button, model list fetch via /v1/models, per-provider temperature/max tokens/timeouts. - Keys stored in EncryptedSharedPreferences/Keystore. Optional different providers for reading vs analysis. - Rate-limit handling, exponential backoff, and a cost/token counter per file. 7. BACKGROUND + DURABILITY - Reading runs as a foreground WorkManager job with a notification and progress. Pause, resume, cancel. Resume exactly from the last completed unit after crashes or restarts. 8. UI - Dark, clean reader interface: the document view with the current unit highlighted, a side panel showing the AI's live observation, coverage bar, mode switcher, speed control (auto-advance vs tap-to-advance), and an outcomes tab. - Library screen listing files with status (unread, reading, complete) and saved results. - A "thinking/tool activity" strip showing each unit being processed. 9. SAFETY + PRIVACY - Files stay on-device; only unit text plus context is sent to the chosen provider. Show a warning before sending to a remote provider. No analytics, no hidden network calls. BUILD ORDER 1) Project setup + architecture diagram. 2) Ingestion + indexing. 3) Room schema + Coverage Ledger. 4) Provider layer + streaming. 5) Reader Engine + modes. 6) Strict JSON validation + retries. 7) Analysis passes. 8) Outcomes + export. 9) Background service. 10) UI polish. 11) Tests (coverage, resume, malformed AI output). 12) Build and sign APK. Do not stub or leave TODOs. Write complete, compilable code for each step.
Response not available