-
Notifications
You must be signed in to change notification settings - Fork 63
Refactor settings storage to Preferences DataStore to remove Protobuf #525
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
davidjiagoogle
wants to merge
16
commits into
main
Choose a base branch
from
david/protobufRemoval
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.
Open
Changes from all commits
Commits
Show all changes
16 commits
Select commit
Hold shift + click to select a range
72f4cad
Refactor settings storage to Preferences DataStore to remove Protobuf
davidjiagoogle 4279a6b
Address code review comments on safe string parsing & apply spotless …
davidjiagoogle cdcb36c
Remove unused androidx.datastore dependency from feature/settings and…
davidjiagoogle 2e7792f
Clean up unused datastore and protobuf version and plugin declaration…
davidjiagoogle d6d18ad
Merge branch 'main' into david/protobufRemoval
davidjiagoogle beae310
Remove obsolete protobuf files and ProtoConversionTest from data:sett…
davidjiagoogle f752651
Merge branch 'main' into david/protobufRemoval
davidjiagoogle 2b6816a
Refactor persistence into standalone :data:settings-datastore module
davidjiagoogle 2385509
Merge branch 'main' into david/protobufRemoval
davidjiagoogle 08094c0
Refactor settings persistence using modular Preferences DataStore (Op…
davidjiagoogle d898370
Address PR 525 review comments: optimize enum mapping performance, ad…
davidjiagoogle fb28c2c
Merge branch 'main' into david/protobufRemoval
davidjiagoogle 721af6c
Import onAllNodesWithTag in ComposeTestRuleExt.kt
davidjiagoogle ecf3c27
Merge branch 'main' into david/protobufRemoval and resolve conflicts
davidjiagoogle 7386f53
Address PR #525 review feedback: rename data source to PrefsDataStore…
davidjiagoogle bd78d82
Merge branch 'main' into david/protobufRemoval and resolve conflicts
davidjiagoogle File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
54 changes: 54 additions & 0 deletions
54
app/src/main/java/com/google/jetpackcamera/AppSettingsModule.kt
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,54 @@ | ||
| /* | ||
| * Copyright (C) 2026 The Android Open Source Project | ||
| * | ||
| * Licensed under the Apache License, Version 2.0 (the "License"); | ||
| * you may not use this file except in compliance with the License. | ||
| * You may obtain a copy of the License at | ||
| * | ||
| * http://www.apache.org/licenses/LICENSE-2.0 | ||
| * | ||
| * Unless required by applicable law or agreed to in writing, software | ||
| * distributed under the License is distributed on an "AS IS" BASIS, | ||
| * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| * See the License for the specific language governing permissions and | ||
| * limitations under the License. | ||
| */ | ||
| package com.google.jetpackcamera | ||
|
|
||
| import android.content.Context | ||
| import androidx.datastore.core.DataStore | ||
| import androidx.datastore.preferences.core.PreferenceDataStoreFactory | ||
| import androidx.datastore.preferences.core.Preferences | ||
| import androidx.datastore.preferences.preferencesDataStoreFile | ||
| import com.google.jetpackcamera.core.common.DefaultCaptureModeOverride | ||
| import com.google.jetpackcamera.core.settings.datastoreprefs.PrefsDataStoreSettingsDataSource | ||
| import com.google.jetpackcamera.model.CaptureMode | ||
| import com.google.jetpackcamera.settings.SettingsDataSource | ||
| import dagger.Module | ||
| import dagger.Provides | ||
| import dagger.hilt.InstallIn | ||
| import dagger.hilt.android.qualifiers.ApplicationContext | ||
| import dagger.hilt.components.SingletonComponent | ||
| import javax.inject.Singleton | ||
|
|
||
| @Module | ||
| @InstallIn(SingletonComponent::class) | ||
| object AppSettingsModule { | ||
|
|
||
| @Provides | ||
| @Singleton | ||
| fun providePreferencesDataStore(@ApplicationContext context: Context): DataStore<Preferences> { | ||
| return PreferenceDataStoreFactory.create( | ||
| produceFile = { context.preferencesDataStoreFile("app_settings.preferences_pb") } | ||
| ) | ||
| } | ||
|
|
||
| @Provides | ||
| @Singleton | ||
| fun provideSettingsDataSource( | ||
| dataStore: DataStore<Preferences>, | ||
| @DefaultCaptureModeOverride defaultCaptureMode: CaptureMode | ||
| ): SettingsDataSource { | ||
| return PrefsDataStoreSettingsDataSource(dataStore, defaultCaptureMode) | ||
| } | ||
| } |
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
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
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
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
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
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
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
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
Oops, something went wrong.
Oops, something went wrong.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Since we are replacing Protobuf with a custom, hand-rolled string parser, we need unit tests to ensure this logic is robust. String parsing based on delimiters (
:,;,,) and specific string formats (likeSolidColor(...)) is prone to regressions if the model changes in the future.Could you please add a
DebugSettingsTest.ktin thecore:modelmodule? It should verify thatparseFromString(encodeAsString())correctly rebuilds the object. Specifically, we should test:TestPatternvariants (likeColorBars).TestPattern.SolidColorvariant to ensure the regex/splitting of the 4 color channels works correctly.