Conversation
When settings are updated from SettingsRepository, CameraAppSettings.applyDiffs propagates changed preferences to CameraSystem, but previously omitted dynamicRange and imageFormat. This change: - Adds diff propagation for dynamicRange and imageFormat in CameraAppSettings.applyDiffs. - Adds unit tests in CameraSystemTest verifying applyDiffs correctly updates CameraSystem on setting changes and skips unchanged settings. - Adds unit tests in PreviewViewModelTest confirming end-to-end propagation from SettingsRepository through applyDiffs to CameraSystem. - Adds parameterized on-device tests in CameraSystemApplyDiffsDeviceTest executing across all available lenses (BACK, FRONT), verifying live diff application and skipping gracefully when unsupported by hardware constraints. Test: ./gradlew :core📷testStableUnitTest :feature:preview:testStableUnitTest Test: ./gradlew :core📷connectedStableDebugAndroidTest
There was a problem hiding this comment.
Code Review
This pull request adds support for propagating dynamicRange and imageFormat changes in CameraSystem.applyDiffs, accompanied by new unit and instrumented tests to verify the behavior. The review feedback suggests restricting the visibility of the new test classes to internal to align with the repository's style guide, and using distinctUntilChanged() on the settings flow in the instrumented tests to prevent potential flakiness.
| */ | ||
| @LargeTest | ||
| @RunWith(Parameterized::class) | ||
| class CameraSystemApplyDiffsDeviceTest(private val lensFacing: LensFacing) { |
There was a problem hiding this comment.
According to the repository style guide, all new classes should use the most restrictive visibility modifier possible. Since this test class does not need to be publicly accessible, it should be declared as internal.
| class CameraSystemApplyDiffsDeviceTest(private val lensFacing: LensFacing) { | |
| internal class CameraSystemApplyDiffsDeviceTest(private val lensFacing: LensFacing) { |
References
- Proper Visibility Modifiers: Ensure all new functions, properties, and classes use the most restrictive visibility modifier possible (e.g., private, internal) while still allowing necessary access. Avoid public visibility unless explicitly required for external API exposure. (link)
| val dynamicRangeCheck = cameraSystem.getCurrentSettings() | ||
| .filterNotNull() | ||
| .map { it.dynamicRange } | ||
| .produceIn(this) |
There was a problem hiding this comment.
To prevent potential flakiness and avoid buffering duplicate values in the channel (e.g., if other unrelated settings change and trigger emissions), it is recommended to use distinctUntilChanged() on the flow before producing the channel.
| val dynamicRangeCheck = cameraSystem.getCurrentSettings() | |
| .filterNotNull() | |
| .map { it.dynamicRange } | |
| .produceIn(this) | |
| val dynamicRangeCheck = cameraSystem.getCurrentSettings() | |
| .filterNotNull() | |
| .map { it.dynamicRange } | |
| .distinctUntilChanged() | |
| .produceIn(this) |
| val imageFormatCheck = cameraSystem.getCurrentSettings() | ||
| .filterNotNull() | ||
| .map { it.imageFormat } | ||
| .produceIn(this) |
There was a problem hiding this comment.
To prevent potential flakiness and avoid buffering duplicate values in the channel (e.g., if other unrelated settings change and trigger emissions), it is recommended to use distinctUntilChanged() on the flow before producing the channel.
| val imageFormatCheck = cameraSystem.getCurrentSettings() | |
| .filterNotNull() | |
| .map { it.imageFormat } | |
| .produceIn(this) | |
| val imageFormatCheck = cameraSystem.getCurrentSettings() | |
| .filterNotNull() | |
| .map { it.imageFormat } | |
| .distinctUntilChanged() | |
| .produceIn(this) |
| * Unit tests for [CameraSystem] extension functions, specifically [CameraAppSettings.applyDiffs]. | ||
| */ | ||
| @RunWith(JUnit4::class) | ||
| class CameraSystemTest { |
There was a problem hiding this comment.
According to the repository style guide, all new classes should use the most restrictive visibility modifier possible. Since this test class does not need to be publicly accessible, it should be declared as internal.
| class CameraSystemTest { | |
| internal class CameraSystemTest { |
References
- Proper Visibility Modifiers: Ensure all new functions, properties, and classes use the most restrictive visibility modifier possible (e.g., private, internal) while still allowing necessary access. Avoid public visibility unless explicitly required for external API exposure. (link)
TLDR:
🐛 Problem: Currently, when settings are updated from SettingsRepository,
CameraAppSettings.applyDiffspropagates changed preferences to CameraSystem. It currently omitsdynamicRangeandimageFormat.✅ Solution: this PR includes
dynamicRangeandimageFormatinCameraAppSettings.applyDiffstests.❓ note: HDR controls aren't currently included in JCA's dedicated settings screen.
Longer description:
CameraAppSettings.applyDiffs.