Conversation
This commit refactors the theme engine to support granular, per-app theme overrides and separates the global and app-specific theme editing into distinct, modular UI components.
- **App-Specific Overrides**:
- Implemented `AppThemeOverride` to allow customizing `highlightColor`, `iconShapeId`, `iconPaddingPercent`, and `callConfig` on a per-application basis, inheriting from the global theme by default.
- Added a new "Apps" section in the Theme Creator to manage these overrides.
- App-specific customizations are now saved within the theme file and automatically applied by the notification service.
- **New `AppThemeEditor` Screen**:
- Created a dedicated `AppThemeEditorScreen.kt` for editing app-specific overrides.
- Users can navigate from the main creator to this screen, which provides a focused interface for customizing an app's colors, icons, call styles, and actions independently of the global theme.
- The editor uses the same composable modules as the global creator but binds them to app-specific state in the `ThemeViewModel`.
- **`ThemeViewModel` Refactoring**:
- Introduced a separate state management section for app-specific editing (`editingAppPackage`, `appHighlightColor`, etc.) to buffer changes without affecting the global theme state until saved.
- Added logic (`loadAppForEditing`, `saveAppChanges`) to manage the lifecycle of app override editing.
- `saveTheme` logic now correctly persists `appOverrides` and handles asset staging for both global and app-specific icons.
- Centralized the notification service reload logic into a single `reloadNotificationService()` method.
- **UI Component Modularization**:
- Refactored `ThemeCreatorScreen` and its sub-components (`ColorsDetailContent`, `IconsDetailContent`, `CallStyleSheetContent`, `ActionsDetailContent`) to be stateless. They now receive state via parameters and emit changes through callbacks, allowing them to be reused in both the global and app-specific editors.
- The old `ThemeAppScreen.kt` has been removed and its functionality is replaced by the new, more robust `AppsDetailContent.kt` and `AppThemeEditorScreen.kt`.
- The preview carousel (`SharedThemePreview`) is now a shared, stateless component that dynamically reflects either global or app-specific settings.
- **New String Resources**:
- Added strings to support the new app editor UI, including titles (`Edit App`), subtitles (`Using Global Default`, `Custom Color Set`), and descriptions.
This commit introduces critical fixes to the theme creation and app override workflow, ensuring state consistency, preventing data loss, and correctly applying app-specific styles.
- **State Management in Theme Creator**:
- A unique `currentEditingThemeId` is now generated immediately when creating a new theme (`clearCreatorState`) and persists throughout the editing session. This prevents the ID from changing and ensures app override edits are saved to the correct theme draft.
- Saving app-specific overrides now correctly passes the `currentEditingThemeId` to `saveTheme`, ensuring changes are persisted to the theme being edited.
- The `saveTheme` function logic has been updated to prioritize an explicit ID, then the session ID, before generating a new one as a fallback.
- In `ThemeCreatorScreen`, `LaunchedEffect` logic is now more robust, preventing the editor from reloading and overwriting unsaved changes when the view recomposes.
- **App Override & Editor Improvements**:
- Implemented an "Unsaved Changes" dialog in the `AppThemeEditorScreen`. When backing out, users are now prompted to either save or discard their app-specific customizations.
- The color selection logic in `BaseTranslator` has been enhanced to correctly respect the `useAppColors` flag set on a per-app basis. It now properly cascades from app-specific settings to global settings.
- Shape and padding resolution logic (`resolveShape`, `resolvePadding`) has been centralized in `BaseTranslator` and is now correctly applied in `NavTranslator` and `BaseTranslator`'s action processing, ensuring per-app icon shapes are respected.
- `CallTranslator` now correctly resolves call button colors and shapes from app-specific overrides before falling back to global theme settings.
- **Bug Fixes & Refinements**:
- Fixed an issue where returning from the `AppThemeEditor` would incorrectly clear the state of a new theme draft in `ThemeCreatorScreen`.
- Removed redundant comments and cleaned up code in `ThemeCreatorScreen` and `ThemeViewModel`.
- Added new string resources for the "Unsaved Changes" and "Discard" dialog options.
This commit refactors the `ThemeViewModel` to improve string resource handling and simplify state management within the theme creator.
- **String Resource Extraction**:
- Extracted hardcoded strings "Share Theme" and "My Theme" into `strings.xml`.
- In `ThemeViewModel`, these strings are now loaded from the application context to support localization and improve maintainability. The `share_theme` string is pre-loaded for use in the share intent chooser, and the `my_theme` string is used as a default theme name upon saving.
- **State Management Simplification**:
- Removed redundant logic and comments related to `currentEditingThemeId` management. The logic now consistently relies on the ID being set when a theme creation or editing session begins.
- In `clearCreatorState()`, the `themeName` field is now cleared, delegating the responsibility of showing a placeholder (like "My Theme") to the UI layer.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
No description provided.