Skip to content

Comments

Proto / Domain Mappers#477

Open
Kimblebee wants to merge 3 commits intomainfrom
kim/refactor/proto-mappers
Open

Proto / Domain Mappers#477
Kimblebee wants to merge 3 commits intomainfrom
kim/refactor/proto-mappers

Conversation

@Kimblebee
Copy link
Collaborator

Summary of changes:
Model Mappers:
* Migrate domain <--> proto conversion functions to dedicated files.
* These files now contain the toProto() and toDomain() extension functions for various domain model enums and data classes, centralizing the logic for converting between domain and Protobuf types.

Refactoring of LocalSettingsRepository
* removed the inline when statements that previously handled conversions
package, making the repository's code cleaner and more concise.

Updated Navigation Components:
* DebugSettingsNavType.kt and PreviewNavigation.kt have been updated to utilize the new DebugSettingsMapper for handling the serialization and deserialization of DebugSettings when navigating.

Comprehensive Proto Conversion Tests:
* ProtoConversionTest.kt, has more extensive coverage of the proto/domain functions

  Extracted Proto DataStore implementation into a new :data:settings-datastore module. This improves modularity and separation of concerns by isolating the persistence layer. :data:settings now solely defines interfaces and handles constraints.
  Extracted Proto DataStore implementation into a new :data:settings-datastore module. This improves modularity and separation of concerns by isolating the persistence layer. :data:settings now solely defines interfaces and handles constraints.

# Conflicts:
#	data/settings-datastore/src/main/java/com/google/jetpackcamera/data/settingsdatastore/LocalSettingsRepository.kt
Moves all proto/domain conversion logic into a dedicated mappers layer in core:model. This cleans up data models and LocalSettingsRepositor and improves testability and reusability of conversion logic.
@gemini-code-assist
Copy link
Contributor

Summary of Changes

Hello @Kimblebee, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed!

This pull request significantly refactors the data model and settings persistence layers by centralizing Protobuf conversion logic into dedicated mapper files and introducing a new DataStore module. This change improves code organization, enhances readability by removing inline conversion logic from core models and repositories, and boosts testability with comprehensive conversion tests. The overall impact is a cleaner, more maintainable codebase for handling settings and data serialization.

Highlights

  • Model Mappers Introduced: Proto conversion functions for various domain model enums and data classes have been migrated to dedicated mappers files, centralizing the logic for converting between domain and Protobuf types.
  • LocalSettingsRepository Refactored: The LocalSettingsRepository has been cleaned up by removing inline when statements that previously handled conversion logic, making the code more concise and readable.
  • New DataStore Module: A new data:settings-datastore module has been created to encapsulate the Protobuf DataStore implementation, separating it from the data:settings interface module.
  • Navigation Components Updated: DebugSettingsNavType.kt and PreviewNavigation.kt now utilize the new DebugSettingsMapper for handling serialization and deserialization of DebugSettings during navigation.
  • Comprehensive Proto Conversion Tests: A new test file, ProtoConversionTest.kt, has been added to provide more extensive coverage for the proto/domain conversion functions.

🧠 New Feature in Public Preview: You can now enable Memory to help Gemini Code Assist learn from your team's feedback. This makes future code reviews more consistent and personalized to your project's style. Click here to enable Memory in your admin console.

Changelog
  • core/model/src/main/java/com/google/jetpackcamera/model/AspectRatio.kt
    • Removed proto conversion logic from companion object.
  • core/model/src/main/java/com/google/jetpackcamera/model/DebugSettings.kt
    • Removed proto conversion and encoding/decoding logic from companion object.
  • core/model/src/main/java/com/google/jetpackcamera/model/DynamicRange.kt
    • Removed proto conversion logic from companion object.
  • core/model/src/main/java/com/google/jetpackcamera/model/ImageOutputFormat.kt
    • Removed proto conversion logic from companion object.
  • core/model/src/main/java/com/google/jetpackcamera/model/LensFacing.kt
    • Removed proto conversion logic from companion object.
  • core/model/src/main/java/com/google/jetpackcamera/model/LowLightBoostPriority.kt
    • Removed proto conversion logic from companion object.
  • core/model/src/main/java/com/google/jetpackcamera/model/StabilizationMode.kt
    • Removed proto conversion logic from companion object.
  • core/model/src/main/java/com/google/jetpackcamera/model/TestPattern.kt
    • Removed proto conversion logic from companion object.
  • core/model/src/main/java/com/google/jetpackcamera/model/VideoQuality.kt
    • Removed proto conversion logic from companion object.
  • core/model/src/main/java/com/google/jetpackcamera/model/mappers/DebugSettingsMapper.kt
    • Added new file to handle DebugSettings proto conversion and encoding/decoding.
  • core/model/src/main/java/com/google/jetpackcamera/model/mappers/ProtoMappers.kt
    • Added new file containing extension functions for converting between domain models and Protobuf types for various enums and data classes.
  • core/model/src/test/java/com/google/jetpackcamera/model/ProtoConversionTest.kt
    • Added new test file to verify the correctness of all proto/domain conversion functions.
  • data/settings-datastore/.gitignore
    • Added new file to ignore build artifacts.
  • data/settings-datastore/build.gradle.kts
    • Added new build script for the settings-datastore module, including protobuf configuration and dependencies.
  • data/settings-datastore/proguard-rules.pro
    • Added new ProGuard rules file for the settings-datastore module.
  • data/settings-datastore/src/androidTest/java/com/google/jetpackcamera/data/settings_datastore/DataStoreModuleTest.kt
    • Renamed file and updated package and imports to reflect the new module structure.
  • data/settings-datastore/src/androidTest/java/com/google/jetpackcamera/data/settings_datastore/LocalSettingsRepositoryInstrumentedTest.kt
    • Renamed file and updated package and imports to reflect the new module structure.
  • data/settings-datastore/src/main/AndroidManifest.xml
    • Added new AndroidManifest file for the settings-datastore module.
  • data/settings-datastore/src/main/java/com/google/jetpackcamera/data/settingsdatastore/DataStoreModule.kt
    • Renamed file and updated package and imports for the DataStore module.
  • data/settings-datastore/src/main/java/com/google/jetpackcamera/data/settingsdatastore/JcaSettingsSerializer.kt
    • Renamed file and updated package and imports for the JcaSettings serializer.
  • data/settings-datastore/src/main/java/com/google/jetpackcamera/data/settingsdatastore/LocalSettingsRepository.kt
    • Renamed file, updated package and imports, and refactored to use the new proto mapper extension functions.
  • data/settings-datastore/src/main/java/com/google/jetpackcamera/data/settingsdatastore/SettingsModule.kt
    • Added new Dagger module to bind LocalSettingsRepository as SettingsRepository.
  • data/settings-datastore/src/main/java/com/google/jetpackcamera/data/settingsdatastore/test/FakeDataStoreModule.kt
    • Renamed file and updated package to reflect the new module structure.
  • data/settings-datastore/src/main/java/com/google/jetpackcamera/data/settingsdatastore/test/FakeJcaSettingsSerializer.kt
    • Renamed file and updated package and imports to reflect the new module structure.
  • data/settings-datastore/src/main/proto/com/google/jetpackcamera/settings/jca_settings.proto
    • Renamed proto definition file to be part of the new settings-datastore module.
  • data/settings/build.gradle.kts
    • Removed protobuf plugin and related dependencies, as they are now handled by the new data:settings-datastore module.
  • data/settings/src/main/java/com/google/jetpackcamera/settings/ConstraintsModule.kt
    • Renamed SettingsModule to ConstraintsModule and removed the SettingsRepository binding, which is now in data:settings-datastore.
  • data/settings/src/test/java/com/google/jetpackcamera/settings/ProtoConversionTest.kt
    • Removed test file as its functionality has been moved to core/model/src/test/java/com/google/jetpackcamera/model/ProtoConversionTest.kt.
  • feature/preview/build.gradle.kts
    • Added dependency on the new data:settings-datastore module.
  • feature/preview/src/main/java/com/google/jetpackcamera/feature/preview/navigation/DebugSettingsNavType.kt
    • Updated imports and usage to leverage the new DebugSettingsMapper for handling DebugSettings serialization and deserialization.
  • feature/preview/src/main/java/com/google/jetpackcamera/feature/preview/navigation/PreviewNavigation.kt
    • Updated imports and usage to leverage the new DebugSettingsMapper for retrieving DebugSettings.
  • settings.gradle.kts
    • Included the new data:settings-datastore module in the project.
Using Gemini Code Assist

The full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips.

Invoking Gemini

You can request assistance from Gemini at any point by creating a comment using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands on the current page.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in pull request comments and review comments.
Help /gemini help Displays a list of available commands.

Customization

To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a .gemini/ folder in the base of the repository. Detailed instructions can be found here.

Limitations & Feedback

Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for Github and other Google products, sign up here.

You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension.

Footnotes

  1. Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution.

Copy link
Contributor

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request is a great refactoring effort that significantly improves the codebase's structure and maintainability. By centralizing the domain-to-proto mapping logic into dedicated mapper files (ProtoMappers.kt and DebugSettingsMapper.kt), you've made the model classes cleaner and the data layer (LocalSettingsRepository) more concise and readable. The creation of the new data:settings-datastore module is a solid architectural improvement that better separates concerns. The addition of comprehensive unit tests in ProtoConversionTest.kt ensures the correctness of these new mappers. I have one minor suggestion for simplification.

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