Extract AddRecipeInput proto file to a module

This commit is contained in:
Kirill Kamakin
2022-08-04 20:53:26 +02:00
parent a53495b1f9
commit 8784912cdb
11 changed files with 109 additions and 45 deletions

View File

@@ -1,9 +1,5 @@
@file:Suppress("UnstableApiUsage")
import com.google.protobuf.gradle.builtins
import com.google.protobuf.gradle.generateProtoTasks
import com.google.protobuf.gradle.protobuf
import com.google.protobuf.gradle.protoc
import java.io.FileInputStream
import java.util.*
@@ -16,7 +12,6 @@ plugins {
id("com.google.gms.google-services")
id("com.google.firebase.crashlytics")
alias(libs.plugins.appsweep)
alias(libs.plugins.protobuf)
}
android {
@@ -72,6 +67,7 @@ android {
dependencies {
implementation(project(":database"))
implementation(project(":datastore"))
implementation(libs.android.material.material)
@@ -126,8 +122,6 @@ dependencies {
implementation(libs.androidx.datastore.preferences)
implementation(libs.androidx.datastore.datastore)
implementation(libs.google.protobuf.javalite)
implementation(libs.androidx.security.crypto)
implementation(platform(libs.google.firebase.bom))
@@ -151,23 +145,3 @@ dependencies {
debugImplementation(libs.chuckerteam.chucker)
}
protobuf {
protoc {
artifact = libs.google.protobuf.protoc.get().toString()
}
generateProtoTasks {
all().forEach { task ->
task.builtins {
val java by registering {
option("lite")
}
}
}
}
}
kapt {
correctErrorTypes = true
}

View File

@@ -2,8 +2,8 @@ package gq.kirmanak.mealient.data.add.impl
import androidx.datastore.core.DataStore
import gq.kirmanak.mealient.data.add.AddRecipeStorage
import gq.kirmanak.mealient.data.add.models.AddRecipeInput
import gq.kirmanak.mealient.data.add.models.AddRecipeRequest
import gq.kirmanak.mealient.datastore.recipe.AddRecipeInput
import kotlinx.coroutines.flow.Flow
import kotlinx.coroutines.flow.map
import timber.log.Timber

View File

@@ -1,5 +1,6 @@
package gq.kirmanak.mealient.data.add.models
import gq.kirmanak.mealient.datastore.recipe.AddRecipeInput
import kotlinx.serialization.SerialName
import kotlinx.serialization.Serializable

View File

@@ -1,14 +1,9 @@
package gq.kirmanak.mealient.di
import android.content.Context
import androidx.datastore.core.DataStore
import androidx.datastore.core.DataStoreFactory
import androidx.datastore.dataStoreFile
import dagger.Binds
import dagger.Module
import dagger.Provides
import dagger.hilt.InstallIn
import dagger.hilt.android.qualifiers.ApplicationContext
import dagger.hilt.components.SingletonComponent
import gq.kirmanak.mealient.data.add.AddRecipeDataSource
import gq.kirmanak.mealient.data.add.AddRecipeRepo
@@ -17,8 +12,6 @@ import gq.kirmanak.mealient.data.add.impl.AddRecipeDataSourceImpl
import gq.kirmanak.mealient.data.add.impl.AddRecipeRepoImpl
import gq.kirmanak.mealient.data.add.impl.AddRecipeService
import gq.kirmanak.mealient.data.add.impl.AddRecipeStorageImpl
import gq.kirmanak.mealient.data.add.models.AddRecipeInput
import gq.kirmanak.mealient.data.add.models.AddRecipeInputSerializer
import gq.kirmanak.mealient.data.baseurl.BaseURLStorage
import gq.kirmanak.mealient.data.network.RetrofitBuilder
import gq.kirmanak.mealient.data.network.ServiceFactory
@@ -34,14 +27,6 @@ interface AddRecipeModule {
companion object {
@Provides
@Singleton
fun provideAddRecipeInputStore(
@ApplicationContext context: Context
): DataStore<AddRecipeInput> = DataStoreFactory.create(AddRecipeInputSerializer) {
context.dataStoreFile("add_recipe_input")
}
@Provides
@Singleton
fun provideAddRecipeServiceFactory(

View File

@@ -39,5 +39,4 @@ dependencies {
testImplementation(libs.google.truth)
testImplementation(libs.io.mockk)
}

1
datastore/.gitignore vendored Normal file
View File

@@ -0,0 +1 @@
/build

View File

@@ -0,0 +1,60 @@
import com.google.protobuf.gradle.builtins
import com.google.protobuf.gradle.generateProtoTasks
import com.google.protobuf.gradle.protobuf
import com.google.protobuf.gradle.protoc
plugins {
id("gq.kirmanak.mealient.library")
id("kotlin-kapt")
id("dagger.hilt.android.plugin")
alias(libs.plugins.protobuf)
}
android {
namespace = "gq.kirmanak.mealient.datastore"
}
dependencies {
implementation(libs.androidx.datastore.preferences)
implementation(libs.androidx.datastore.datastore)
implementation(libs.google.protobuf.javalite)
implementation(libs.androidx.security.crypto)
implementation(libs.google.dagger.hiltAndroid)
kapt(libs.google.dagger.hiltCompiler)
kaptTest(libs.google.dagger.hiltAndroidCompiler)
testImplementation(libs.google.dagger.hiltAndroidTesting)
implementation(libs.jetbrains.kotlinx.datetime)
implementation(libs.jetbrains.kotlinx.coroutinesAndroid)
testImplementation(libs.jetbrains.kotlinx.coroutinesTest)
testImplementation(libs.androidx.test.junit)
testImplementation(libs.google.truth)
testImplementation(libs.io.mockk)
}
protobuf {
protoc {
artifact = libs.google.protobuf.protoc.get().toString()
}
generateProtoTasks {
all().forEach { task ->
task.builtins {
val java by registering {
option("lite")
}
}
}
}
}
kapt {
correctErrorTypes = true
}

View File

@@ -0,0 +1,29 @@
package gq.kirmanak.mealient.datastore
import android.content.Context
import androidx.datastore.core.DataStore
import androidx.datastore.core.DataStoreFactory
import androidx.datastore.dataStoreFile
import dagger.Module
import dagger.Provides
import dagger.hilt.InstallIn
import dagger.hilt.android.qualifiers.ApplicationContext
import dagger.hilt.components.SingletonComponent
import gq.kirmanak.mealient.datastore.recipe.AddRecipeInput
import gq.kirmanak.mealient.datastore.recipe.AddRecipeInputSerializer
import javax.inject.Singleton
@Module
@InstallIn(SingletonComponent::class)
interface DataStoreModule {
companion object {
@Provides
@Singleton
fun provideAddRecipeInputStore(
@ApplicationContext context: Context
): DataStore<AddRecipeInput> = DataStoreFactory.create(AddRecipeInputSerializer) {
context.dataStoreFile("add_recipe_input")
}
}
}

View File

@@ -1,4 +1,4 @@
package gq.kirmanak.mealient.data.add.models
package gq.kirmanak.mealient.datastore.recipe
import androidx.datastore.core.CorruptionException
import androidx.datastore.core.Serializer

View File

@@ -0,0 +1,14 @@
syntax = "proto3";
option java_package = "gq.kirmanak.mealient.datastore.recipe";
option java_multiple_files = true;
message AddRecipeInput {
string recipeName = 1;
string recipeDescription = 2;
string recipeYield = 3;
repeated string recipeInstructions = 4;
repeated string recipeIngredients = 5;
bool isRecipePublic = 6;
bool areCommentsDisabled = 7;
}

View File

@@ -21,3 +21,4 @@ rootProject.name = "Mealient"
include(":app")
include(":database")
include(":datastore")