-
-
Notifications
You must be signed in to change notification settings - Fork 174
Add Settings Dialog with Theme Mode Selection and Proto DataStore Persistence #46
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
hmzgtl16
wants to merge
20
commits into
skydoves:main
Choose a base branch
from
hmzgtl16:main
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Conversation
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
- Create a new `:core:datastore` module to handle data persistence. - Add initial setup including build configurations, test files, and an AndroidManifest. - Update `settings.gradle.kts` to include the new module.
Integrates Proto DataStore to manage user preferences, replacing the previous dependency on `appcompat` and `material` with Protocol Buffers. - Adds `androidx.datastore` and `protobuf` dependencies. - Introduces a `protobuf` plugin configuration in the `core:datastore` module. - Defines `UserPreferences` and `UiThemeConfigProto` protobuf messages to store UI theme settings and whether to use dynamic theming.
* Creates a new `:core:common` pure Kotlin module. * Moves `DispatchersModule`, `PokedexAppDispatchers`, and related coroutine logic from `:core:network` to `:core:common`. * Adds a new `CoroutineScopesModule` to provide a singleton `CoroutineScope`. * Updates dependencies to support the new module structure.
- Introduce a new `core:datastore` module using Proto DataStore to manage user preferences like UI theme and dynamic colors. - Define a `UserData` model in `core:model` to represent user settings. - Implement `PreferencesDataSource` to handle getting and setting theme and dynamic color preferences. - Add a Hilt module (`DataStoreModule`) to provide the `DataStore<UserPreferences>` instance. - Update `core:data` repositories to use the new `core:common` module for dispatchers. - Remove boilerplate test files from the `datastore` module.
Add a `SettingsRepository` to handle user settings, such as UI theme and dynamic color preferences. This repository abstracts the data source logic for fetching and updating user preferences from the `PreferencesDataSource`.
Binds the `SettingsRepository` interface to its implementation, `SettingsRepositoryImpl`, within the Hilt dependency graph.
- Introduces a new `:feature:settings` module to manage user preferences like UI theme and dynamic colors. - Adds a `Settings` object to `PokedexScreen` for navigation. - Implements a `PokedexSettings` composable, which displays as a dialog, to allow users to change theme settings. - Creates a `SettingsViewModel` to handle the business logic for fetching and updating user data. - Adds a settings icon to the `PokedexAppBar` on the home screen to navigate to the new settings dialog. - Includes a `FakeSettingsRepository` for testing purposes.
Adds unit tests for the `core:datastore` module to ensure the reliability of user preference handling. - Implements `UserPreferencesSerializerTest` to verify the serialization and deserialization of `UserPreferences`, including default values, correct read/write operations, and corruption handling. - Adds `PreferencesDataSourceTest` to validate the logic for setting and retrieving UI theme and dynamic color settings. - Introduces `InMemoryDataStore`, a test fake for `DataStore`, to facilitate testing of the data source in isolation.
Updates the `FakeSettingsRepository` to emit a default `UserData` object in its `fetchUserData` flow. This ensures that tests relying on this fake implementation have initial data to work with, setting the UI theme to `FOLLOW_SYSTEM` and `useDynamicColors` to `true`.
Adds unit tests for `SettingsRepositoryImpl` to verify its functionality. - Implements an `InMemoryDataStore` for testing `PreferencesDataSource` without relying on the actual file system. - Verifies that the default user data is correct upon initialization. - Confirms that `setDynamicColors` correctly updates the `useDynamicColors` preference. - Confirms that `setUiTheme` correctly updates the `uiTheme` preference. - Adds the `protobuf-kotlin-lite` test dependency to support the tests. - Updates `FakeSettingsRepository` to align with repository interface changes.
Removes the `useDynamicColors` boolean preference from the user settings. This simplifies the `UserData` model and the corresponding Proto DataStore schema, making the theme preference the sole user-configurable setting. - Removes the `useDynamicColors` field from the `UserData` data class in the `:core:model` module. - Updates the `user_preferences.proto` file in `:core:datastore` to remove the `use_dynamic_colors` field. - Adjusts tests for `UserPreferencesSerializer` to reflect the removal of the dynamic color setting.
…dynamic colors - Renames `SettingsRepository` and its related classes to `UserDataRepository` to more accurately reflect that it manages all user data, not just settings. - Simplifies the `UserData` model and repository by removing the `useDynamicColors` option, which will be implicitly handled by Material 3. - Removes the `fetchUserData` method in favor of directly exposing a `userData` Flow. - Updates Hilt bindings and tests to reflect the new repository name and simplified data model.
Adds the Apache 2.0 license header to files in the `:core:datastore` module. This commit also includes minor code formatting adjustments.
Refactors the settings screen to simplify its UI and state management. This change streamlines the underlying logic by removing dynamic color theming options and dependencies on the Palette API. - Updates `SettingsViewModel` to directly use `UserDataRepository` and a simpler `SettingsUiState` (Loading, Success, Error). - Removes the `SettingsBackground.kt` file and its dependency on the Palette API for dynamic background colors. - Simplifies the `PokedexSettings` and `SettingsDialog` composables by removing logic for dynamic colors and palette extraction. - Updates UI components to use `PokedexTheme` for consistent styling.
Integrates user preferences from `UserDataRepository` to dynamically set the app's theme. - Introduces a `MainActivityViewModel` to expose a `MainActivityUiState` which holds the `UserData`. - The `MainActivity` now collects this state to determine whether to use a dark theme, light theme, or follow the system setting. - The splash screen is now kept on-screen until the user data (and theme preference) is loaded. - Updates `PokedexMain` composable to accept a `darkTheme` boolean parameter to apply the selected theme. - Adds a dependency on the `:core:data` module in the `:app` module to access `UserDataRepository`.
Updates unit tests for `HomeRepositoryImpl` to include the newly added `onLastPageReached` lambda parameter in the `fetchPokemonList` method calls.
Updates unit tests for `HomeRepositoryImpl` to include the newly added `onLastPageReached` lambda parameter in the `fetchPokemonList` method calls.
Renames `SettingsRepository` to `UserDataRepository` for consistency and clarity. This update also refactors related code, including: - Renaming the Hilt binding method in `DataModule` from `bindsSettingsRepository` to `bindsUserDataRepository`. - Removing unused imports (`Build`, `ChecksSdkIntAtLeast`) from `PokedexTheme`. - Simplifying the initial state value in `MainActivityViewModel` from `MainActivityUiState.Loading` to just `Loading`.
Adds the Apache 2.0 license header to multiple files across various modules. This commit also includes minor code formatting adjustments, such as correcting trailing commas and removing unnecessary parameters, to improve consistency and readability.
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.
🎯 Goal
This PR adds a new Settings dialog that allows users to choose their preferred UI theme (Follow system / Dark / Light).
The selected theme is persisted with Proto DataStore and applied across the entire app, including splash screen behavior and system theme overrides.
🛠 Implementation details
✍️ Explain examples
Settings dialog integration in navigation
Persisting selected theme
Applying theme in MainActivity