Skip to content

Feat(backup): implement advanced app state backup (v2) & dynamic locale hot-reload#42

Open
YisusPineapple wants to merge 7 commits into
MrDemonc:mainfrom
YisusPineapple:feature/advanced-backup-system
Open

Feat(backup): implement advanced app state backup (v2) & dynamic locale hot-reload#42
YisusPineapple wants to merge 7 commits into
MrDemonc:mainfrom
YisusPineapple:feature/advanced-backup-system

Conversation

@YisusPineapple

Copy link
Copy Markdown
Contributor

Description

This pull request elevates Lune's backup utility from a simple playlist exporter to a robust, full-featured Application State Backup & Restore Engine (Backup v2). It ensures complete data preservation (including favorites, custom covers, and listening history), resolves UI configuration/language lifecycle bugs, and delivers native Material 3 Expressive visual feedback.


Key Enhancements

1. Advanced Application State Backup (Backup v2 Schema)

  • Song Overrides & Favorites: Integrated full serialization of the SQLite song_overrides database entities [MusicDatabase.kt]. Restoring a backup now seamlessly recovers custom metadata (titles, artists, genres), custom local covers, and all liked/favorite statuses (isFavorite = true).
  • App Settings: Serializes the entire state of SettingsManager using a strongly-typed, nested data structure (SettingsBackupData). This avoids generic GSON parsing issues (such as numbers defaulting to doubles) and guarantees exact restoration of audio, theme, and UI preferences.
  • Accumulated Statistics: Exports and imports the SQLite playback_stats table to ensure that home screen recommendation widgets and listening statistics are preserved across devices.
  • Backward Compatibility: Fully guaranteed. If a legacy v1 backup file is uploaded, the parser gracefully defaults to playlist-only restoration without throwing exceptions.

2. Runtime Localization & Theming Hot-Reload

  • Programmatically writing settings to SharedPreferences during import did not force Android's localization engine to update the active UI layout.
  • The Fix: On import completion, the engine on the Main Thread dynamically invokes AppCompatDelegate.setApplicationLocales(LocaleListCompat.forLanguageTags(code)) with the newly restored language code, followed by an immediate activity.recreate() call. This dynamically re-loads the entire layout tree (applying theme, custom colors, and language) without requiring a manual app restart.

3. Material 3 Expressive Loader & Thread Stabilization

  • Replaced instantaneous, blank-screen recreation toasts with a rich, non-dismissible Material 3 AlertDialog during file I/O operations.
  • The loader is driven by a lightweight, hardware-accelerated CircularWavyProgressIndicator powered by a smooth infinite loop transition, making it extremely friendly on modest devices.
  • Introduced a two-step loading phase: "Importing...""Finalizing restoration..." backed by a 1200ms coroutine delay. This guarantees SQLite write-ahead logging (WAL) and journal files on disk are fully flushed and synchronized before the Activity context is torn down and recreated.

4. Spanish Localization Alignment

  • Corrected inconsistent English labels on Spanish layouts (values-es/strings.xml):
    • "Cover player""Carátula del reproductor"
    • "Control player""Controles del reproductor"
    • "Export/Import Playlists""Exportar/Importar copia de seguridad"
  • Fully localized standard playback actions (Shuffle, Timer, Lyrics, Automix, etc.) for a clean, premium Spanish-language experience.

Technical Details & Architecture

  • Minimum SDK: 24 (Retrocompatible up to Android 15 / API 36).
  • Concurrency: Heavy I/O disk writes and Room database operations are strictly bound to Kotlin Coroutines running on Dispatchers.IO to protect Dispatchers.Main from frame drops or UI janks.
  • R8 Minification Safety: All newly introduced backup-specific data structures are fully shielded from obfuscation via existing ProGuard rules (-keep class com.demonlab.lune.tools.** { *; }).

Testing Performed

  • Database Clear Test: Performed database wipe, restored the advanced v2 JSON, and verified that playlists, custom colors, equalizer presets, home screen statistics, and song favorite stars restored successfully.
  • Legacy Test: Verified that legacy v1 backup files (containing only playlists) are still parsed and restored successfully.
  • Language Reload Test: Verified that importing a backup containing German/Spanish settings dynamically hot-reloads the UI in the target language.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant