# NuvioTV Hybrid Rebrand Approach — Lessons Learned

## Source availability
NuvioTV is open source (GitHub: NuvioMedia/NuvioTV, GPL-3.0). When source is available,
clone the repo and read the actual Kotlin source directly rather than decompiling the APK.
The zip at `~/apk-analysis/NuvioTV-0.6.20-beta.zip` contains the full source tree, not just
a binary APK.

## Key architecture
- 530 Kotlin files, package `com.nuvio.tv`
- mpv-based player (libmpv-android + ffmpeg-decoder-downmix modules)
- Stremio addon protocol
- Supabase cloud sync (heavy integration — problematic for adoption)
- Device-code Trakt OAuth with QR code
- 7-theme preset system (Crimson, Ocean, Violet, Emerald, Amber, Rose, White)
- Settings split into per-section ViewModels (not god objects)

## Adoption pitfalls

### KSP / Hilt dependency chain
NuvioTV's data layer is tightly coupled to Supabase through `ProfileDataStoreFactory` and
~20 DataStore classes. When adopting the codebase wholesale, KSP annotation processing
fails before Kotlin compilation even starts because `error.NonExistentClass` (Supabase SDK)
is not available. 

**Fix path:** Either add Supabase SDK (complex) or strip Hilt from adopted files and replace
the data layer with your own. The latter is faster.

### Resource conflicts
NuvioTV has ~300 resource files (drawables, fonts, localized strings, layouts). When
merging into an existing project, duplicates cause AAPT2 merge failures. Remove the
old project's conflicting resources before copying NuvioTV's.

### build.gradle.kts dependencies
NuvioTV uses a `libs.versions.toml` version catalog. The build config references:
- libmpv-android
- ffmpeg-decoder-downmix (custom module)
- Supabase SDK
- zxing (QR codes)
- Coil 3
- Hilt
- Compose for TV / tv-material3

When adopting, copy the version catalog and Gradle wrapper properties first.

## Recommended approach (Ray's preference)
1. Keep our backend/data layer (debrid resolvers, source ranking, catalog worker)
2. Replace only the UI layer with NuvioTV's (screens, navigation, theme, components)
3. Strip Hilt from adopted files where Supabase is referenced
4. Build after each screen migration, not after bulk copy
5. Rebrand: replace all Nuvio branding, package names, icons, strings, URLs
6. GPL-3.0 compliance: keep license, add NOTICE, attribute NuvioTV

## What to keep from our app
- `data/debrid/` — RD/AD/PM resolvers
- `data/source/` — SourceRanker, FallbackEngine
- `data/catalog/` — CatalogWorker integration
- `services/catalog-worker/` — Cloudflare Worker
- `data/local/` — SecureTokenStore, PinHasher (if better than NuvioTV's)

## What to adopt from NuvioTV
- All UI screens (home, details, player, settings, profiles, search, addons)
- Navigation system (NuvioNavHost, Screen routes)
- Theme system (7 presets, NexColors)
- Settings design system (SettingsDesignSystem.kt)
- Player overlays (Pause, Loading, PostPlay, SkipIntro, etc.)
- Trailer system (TrailerService, InAppYouTubeExtractor)
- Trakt OAuth flow (TraktScreen, TraktViewModel)
- Focus management patterns
