========================================================================= TiviMate EPG Rendering - Key Algorithm Patterns (decompiled) ========================================================================= === EPG TIMELINE RENDERING === The EPG is rendered via custom Canvas drawing (NOT RecyclerView). Key approach: 1. A horizontal scrollable container 2. Time ruler drawn at top (hours:minutes) 3. Program blocks drawn as colored rectangles 4. Each block positioned at: x = (programStartTime - dayStartInMillis) * pixelsPerMinute / 60000 width = programDuration * pixelsPerMinute / 60000 === TIME CALCULATION CONSTANTS === milliseconds -> minutes: value / 60000 TimeRuler step: 1 hour = 3600000ms Day start: midnight (00:00) of current day === PROGRAM OVERLAP HANDLING === When programs overlap: - Split into multiple "rows" within the same timeslot - Each row gets a portion of the available height - Greedy algorithm: place program on first available row - Fall back to "more" indicator when too many overlaps === LIVE INDICATOR === - Red vertical line at current time position - Updated every 30 seconds via Handler postDelayed - Position = (now - dayStart) * pixelsPerMinute / 60000 === EPG DATA FLOW === 1. XMLTV data fetched from URL (XML format) 2. Parsed into program entries: channel_id, title, description, start_time, end_time, category 3. Stored in SQLite (Parse SDK) keyed by channel_id 4. When user opens EPG: a. Query DB for current day's programs b. Group by channel (y-axis) c. Calculate x/width for each program (x-axis) d. Render Canvas with: - Time ruler header - Channel labels (left column) - Program blocks (main area) - Live indicator line 5. D-pad navigation moves focus between programs 6. "Now" button scrolls timeline to current time === EPG REFRESH === - Refresh interval: configurable (default 30 min) - Background refresh via WorkManager/AlarmManager - Auto-scroll to current time on first load ========================================================================= HOW TO REPLICATE IN COMPOSE TV: 1. Use LazyHorizontalGrid or custom Canvas in Compose 2. HorizontalScrollState with scroll to current time 3. Draw time ruler with drawLine + drawText 4. For each program: drawRect with rounded corners + drawText 5. Red vertical line at "now" position 6. Overlap detection: track occupied rows per time slot =========================================================================