Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions data/settings-datastore/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
/build
104 changes: 104 additions & 0 deletions data/settings-datastore/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -0,0 +1,104 @@
/*
* 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.
*/
plugins {
alias(libs.plugins.android.library)
alias(libs.plugins.kotlin.android)
alias(libs.plugins.google.protobuf)
alias(libs.plugins.kotlin.kapt)
}

android {
namespace = "com.google.jetpackcamera.data.settingsdatastore"
compileSdk = 35

defaultConfig {
minSdk = 23

testInstrumentationRunner = "androidx.test.runner.AndroidJUnitRunner"
consumerProguardFiles("consumer-rules.pro")
}

buildTypes {
release {
isMinifyEnabled = false
proguardFiles(
getDefaultProguardFile("proguard-android-optimize.txt"),
"proguard-rules.pro"
)
}
}
compileOptions {
sourceCompatibility = JavaVersion.VERSION_11
targetCompatibility = JavaVersion.VERSION_11
}
kotlinOptions {
jvmTarget = "11"
}
}

dependencies {
implementation(libs.androidx.core.ktx)
implementation(libs.androidx.appcompat)
implementation(libs.material)

// Hilt
implementation(libs.dagger.hilt.android)
kapt(libs.dagger.hilt.compiler)

// proto datastore
implementation(libs.protobuf.kotlin.lite)
implementation(libs.androidx.datastore)

// Access Model data
implementation(project(":core:common"))
implementation(project(":core:model"))
implementation(project(":data:settings"))

// Testing
testImplementation(libs.junit)
testImplementation(libs.truth)
androidTestImplementation(libs.androidx.espresso.core)
androidTestImplementation(libs.androidx.junit)
androidTestImplementation(libs.truth)
androidTestImplementation(libs.kotlinx.coroutines.test)
}

protobuf {
protoc {
artifact = "com.google.protobuf:protoc:3.21.12"
}

generateProtoTasks {
all().forEach { task ->
task.builtins {
create("java") {
option("lite")
}
}

task.builtins {
create("kotlin") {
option("lite")
}
}
}
}
}

// Allow references to generated code
kapt {
correctErrorTypes = true
}
Empty file.
21 changes: 21 additions & 0 deletions data/settings-datastore/proguard-rules.pro
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
# Add project specific ProGuard rules here.
# You can control the set of applied configuration files using the
# proguardFiles setting in build.gradle.
#
# For more details, see
# http://developer.android.com/guide/developing/tools/proguard.html

# If your project uses WebView with JS, uncomment the following
# and specify the fully qualified class name to the JavaScript interface
# class:
#-keepclassmembers class fqcn.of.javascript.interface.for.webview {
# public *;
#}

# Uncomment this to preserve the line number information for
# debugging stack traces.
#-keepattributes SourceFile,LineNumberTable

# If you keep the line number information, uncomment this to
# hide the original source file name.
#-renamesourcefileattribute SourceFile
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ import androidx.datastore.dataStoreFile
import androidx.test.core.app.ApplicationProvider
import androidx.test.ext.junit.runners.AndroidJUnit4
import com.google.common.truth.Truth.assertThat
import com.google.jetpackcamera.data.settingsdatastore.LocalSettingsRepository
import com.google.jetpackcamera.model.CaptureMode
import com.google.jetpackcamera.model.DarkMode
import com.google.jetpackcamera.model.DynamicRange
Expand Down
19 changes: 19 additions & 0 deletions data/settings-datastore/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
<?xml version="1.0" encoding="utf-8"?>
<!--
~ 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.
-->
<manifest xmlns:android="http://schemas.android.com/apk/res/android">

</manifest>
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (C) 2023 The Android Open Source Project
* 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.
Expand All @@ -13,13 +13,14 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.google.jetpackcamera.settings
package com.google.jetpackcamera.data.settingsdatastore

import android.content.Context
import androidx.datastore.core.DataStore
import androidx.datastore.core.DataStoreFactory
import androidx.datastore.core.handlers.ReplaceFileCorruptionHandler
import androidx.datastore.dataStoreFile
import com.google.jetpackcamera.settings.JcaSettings
import dagger.Module
import dagger.Provides
import dagger.hilt.InstallIn
Expand All @@ -30,7 +31,6 @@ import kotlinx.coroutines.CoroutineScope
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.SupervisorJob

// with hilt will ensure datastore instance access is unique per file
@Module
@InstallIn(SingletonComponent::class)
object DataStoreModule {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (C) 2023 The Android Open Source Project
* 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.
Expand All @@ -13,7 +13,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.google.jetpackcamera.settings
package com.google.jetpackcamera.data.settingsdatastore

import androidx.datastore.core.CorruptionException
import androidx.datastore.core.Serializer
Expand All @@ -26,6 +26,7 @@ import com.google.jetpackcamera.model.proto.LensFacing
import com.google.jetpackcamera.model.proto.StabilizationMode
import com.google.jetpackcamera.model.proto.StreamConfig
import com.google.jetpackcamera.model.proto.VideoQuality
import com.google.jetpackcamera.settings.JcaSettings
import com.google.protobuf.InvalidProtocolBufferException
import java.io.InputStream
import java.io.OutputStream
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (C) 2023 The Android Open Source Project
* 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.
Expand All @@ -13,7 +13,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.google.jetpackcamera.settings
package com.google.jetpackcamera.data.settingsdatastore

import androidx.datastore.core.DataStore
import com.google.jetpackcamera.core.common.DefaultCaptureModeOverride
Expand All @@ -39,13 +39,14 @@ import com.google.jetpackcamera.model.proto.DarkMode as DarkModeProto
import com.google.jetpackcamera.model.proto.FlashMode as FlashModeProto
import com.google.jetpackcamera.model.proto.StabilizationMode as StabilizationModeProto
import com.google.jetpackcamera.model.proto.StreamConfig as StreamConfigProto
import com.google.jetpackcamera.settings.JcaSettings
import com.google.jetpackcamera.settings.SettingsRepository
import com.google.jetpackcamera.settings.model.CameraAppSettings
import javax.inject.Inject
import kotlinx.coroutines.flow.first
import kotlinx.coroutines.flow.map

/**
* Implementation of [SettingsRepository] with locally stored settings.
* Implementation of [com.google.jetpackcamera.settings.SettingsRepository] with locally stored settings.
*/
class LocalSettingsRepository @Inject constructor(
private val jcaSettings: DataStore<JcaSettings>,
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
/*
* 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.data.settingsdatastore

import com.google.jetpackcamera.settings.SettingsRepository
import dagger.Binds
import dagger.Module
import dagger.hilt.InstallIn
import dagger.hilt.components.SingletonComponent

/**
* Dagger [Module] for settings data layer.
*/
@Module
@InstallIn(SingletonComponent::class)
interface SettingsModule {

@Binds
fun bindsSettingsRepository(
localSettingsRepository: LocalSettingsRepository
): SettingsRepository
}
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.google.jetpackcamera.settings.test
package com.google.jetpackcamera.data.settingsdatastore.test

import androidx.datastore.core.DataStore
import androidx.datastore.core.DataStoreFactory
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (C) 2023 The Android Open Source Project
* 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.
Expand All @@ -13,10 +13,11 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.google.jetpackcamera.settings.test
package com.google.jetpackcamera.data.settingsdatastore.test

import androidx.datastore.core.CorruptionException
import androidx.datastore.core.Serializer
import com.google.jetpackcamera.data.settingsdatastore.UNLIMITED_VIDEO_DURATION
import com.google.jetpackcamera.model.proto.AspectRatio
import com.google.jetpackcamera.model.proto.DarkMode
import com.google.jetpackcamera.model.proto.DynamicRange
Expand All @@ -27,7 +28,6 @@ import com.google.jetpackcamera.model.proto.StabilizationMode
import com.google.jetpackcamera.model.proto.StreamConfig
import com.google.jetpackcamera.model.proto.VideoQuality
import com.google.jetpackcamera.settings.JcaSettings
import com.google.jetpackcamera.settings.UNLIMITED_VIDEO_DURATION
import com.google.protobuf.InvalidProtocolBufferException
import java.io.IOException
import java.io.InputStream
Expand Down
42 changes: 1 addition & 41 deletions data/settings/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ plugins {
alias(libs.plugins.kotlin.android)
alias(libs.plugins.kotlin.kapt)
alias(libs.plugins.dagger.hilt.android)
alias(libs.plugins.google.protobuf)
}

android {
Expand Down Expand Up @@ -76,46 +75,7 @@ dependencies {
implementation(libs.dagger.hilt.android)
kapt(libs.dagger.hilt.compiler)

// proto datastore
implementation(libs.androidx.datastore)
implementation(libs.protobuf.kotlin.lite)

// Testing
testImplementation(libs.junit)
testImplementation(libs.truth)
androidTestImplementation(libs.androidx.espresso.core)
androidTestImplementation(libs.androidx.junit)
androidTestImplementation(libs.truth)
androidTestImplementation(libs.kotlinx.coroutines.test)

// Access Model data
implementation(project(":core:model"))
implementation(project(":core:common"))
}

protobuf {
protoc {
artifact = "com.google.protobuf:protoc:3.21.12"
}

generateProtoTasks {
all().forEach { task ->
task.builtins {
create("java") {
option("lite")
}
}

task.builtins {
create("kotlin") {
option("lite")
}
}
}
}
}

// Allow references to generated code
kapt {
correctErrorTypes = true
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -22,17 +22,11 @@ import dagger.hilt.components.SingletonComponent
import javax.inject.Singleton

/**
* Dagger [Module] for settings data layer.
* Dagger [Module] for constraints data layer.
*/
@Module
@InstallIn(SingletonComponent::class)
interface SettingsModule {

@Binds
fun bindsSettingsRepository(
localSettingsRepository: LocalSettingsRepository
): SettingsRepository

interface ConstraintsModule {
@Binds
@Singleton
fun bindsSettableConstraintsRepository(
Expand Down
Loading
Loading