diff --git a/app/build.gradle b/app/build.gradle index b1ce95712..bf4ce0a20 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -17,11 +17,8 @@ plugins { id 'com.android.application' id 'kotlin-android' id 'kotlin-kapt' - id 'kotlinx-serialization' id 'jacoco' id 'dagger.hilt.android.plugin' - alias(libs.plugins.protobuf) - alias(libs.plugins.ksp) } def jacocoTestReport = tasks.create("jacocoTestReport") @@ -37,7 +34,7 @@ android { versionName "0.0.1" // X.Y.Z; X = Major, Y = minor, Z = Patch level // Custom test runner to set up Hilt dependency graph - testInstrumentationRunner "com.google.samples.apps.nowinandroid.NiaTestRunner" + testInstrumentationRunner "com.google.samples.apps.nowinandroid.core.testing.NiaTestRunner" vectorDrawables { useSupportLibrary true } @@ -112,81 +109,34 @@ android { } } -// Setup protobuf configuration, generating lite Java and Kotlin classes -protobuf { - protoc { - artifact = libs.protobuf.protoc.get() - } - generateProtoTasks { - all().each { task -> - task.builtins { - java { - option "lite" - } - kotlin { - option "lite" - } - } - } - } -} - dependencies { - coreLibraryDesugaring libs.android.desugarJdkLibs + implementation project(':feature-following') + implementation project(':feature-foryou') + + implementation project(':core-ui') - implementation libs.kotlinx.coroutines.android - implementation libs.kotlinx.datetime - implementation libs.kotlinx.serialization.json + androidTestImplementation project(':core-testing') + implementation project(':core-datastore-test') + + coreLibraryDesugaring libs.android.desugarJdkLibs implementation libs.androidx.activity.compose implementation libs.androidx.core.ktx - implementation libs.androidx.dataStore implementation libs.androidx.appcompat implementation libs.androidx.hilt.navigation.compose - implementation libs.androidx.lifecycle.viewModelCompose implementation libs.androidx.navigation.compose implementation libs.material3 - implementation libs.accompanist.flowlayout - - implementation libs.androidx.compose.foundation.layout - // TODO (M3): Remove this dependency when all components are available - implementation libs.androidx.compose.material - implementation libs.androidx.compose.material.iconsExtended - implementation libs.androidx.compose.material3 - implementation libs.androidx.compose.ui.tooling - implementation libs.androidx.compose.ui.util - implementation libs.androidx.compose.runtime - implementation libs.androidx.compose.runtime.livedata - implementation libs.hilt.android kapt libs.hilt.compiler - - implementation libs.room.runtime - implementation libs.room.ktx - ksp libs.room.compiler - - implementation libs.protobuf.kotlin.lite - - debugImplementation libs.androidx.compose.ui.testManifest - - testImplementation libs.junit4 - testImplementation libs.mockk - testImplementation libs.androidx.test.core - testImplementation libs.kotlinx.coroutines.test - testImplementation libs.turbine - - androidTestImplementation libs.androidx.test.espresso.core - androidTestImplementation libs.androidx.test.runner - androidTestImplementation libs.androidx.test.rules - androidTestImplementation libs.androidx.compose.ui.test - androidTestImplementation libs.hilt.android.testing kaptAndroidTest libs.hilt.compiler // androidx.test is forcing JUnit, 4.12. This forces it to use 4.13 configurations.configureEach { resolutionStrategy { force libs.junit4 + // Temporary workaround for https://issuetracker.google.com/174733673 + force 'org.objenesis:objenesis:2.6' } } } diff --git a/app/proguard-rules.pro b/app/proguard-rules.pro deleted file mode 100644 index 36260b8b4..000000000 --- a/app/proguard-rules.pro +++ /dev/null @@ -1,65 +0,0 @@ -# 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 - - -# Keep `Companion` object fields of serializable classes. -# This avoids serializer lookup through `getDeclaredClasses` as done for named companion objects. --if @kotlinx.serialization.Serializable class ** --keepclassmembers class <1> { - static <1>$Companion Companion; -} - -# Keep `serializer()` on companion objects (both default and named) of serializable classes. --if @kotlinx.serialization.Serializable class ** { - static **$* *; -} --keepclassmembers class <1>$<3> { - kotlinx.serialization.KSerializer serializer(...); -} - -# Keep `INSTANCE.serializer()` of serializable objects. --if @kotlinx.serialization.Serializable class ** { - public static ** INSTANCE; -} --keepclassmembers class <1> { - public static <1> INSTANCE; - kotlinx.serialization.KSerializer serializer(...); -} - -# @Serializable and @Polymorphic are used at runtime for polymorphic serialization. --keepattributes RuntimeVisibleAnnotations,AnnotationDefault - -# Serializer for classes with named companion objects are retrieved using `getDeclaredClasses`. -# If you have any, uncomment and replace classes with those containing named companion objects. -#-keepattributes InnerClasses # Needed for `getDeclaredClasses`. -#-if @kotlinx.serialization.Serializable class -#com.example.myapplication.HasNamedCompanion, # <-- List serializable classes with named companions. -#com.example.myapplication.HasNamedCompanion2 -#{ -# static **$* *; -#} -#-keepnames class <1>$$serializer { # -keepnames suffices; class is kept when serializer() is kept. -# static <1>$$serializer INSTANCE; -#} - -# Enable protobuf-related optimizations. --shrinkunusedprotofields diff --git a/app/src/androidTest/java/com/google/samples/apps/nowinandroid/di/TestAppModule.kt b/app/src/androidTest/java/com/google/samples/apps/nowinandroid/di/TestAppModule.kt deleted file mode 100644 index d30ea68bb..000000000 --- a/app/src/androidTest/java/com/google/samples/apps/nowinandroid/di/TestAppModule.kt +++ /dev/null @@ -1,81 +0,0 @@ -/* - * Copyright 2022 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 - * - * https://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.samples.apps.nowinandroid.di - -import androidx.datastore.core.DataStore -import androidx.datastore.core.DataStoreFactory -import com.google.samples.apps.nowinandroid.data.UserPreferences -import com.google.samples.apps.nowinandroid.data.UserPreferencesSerializer -import com.google.samples.apps.nowinandroid.data.fake.FakeNewsRepository -import com.google.samples.apps.nowinandroid.data.fake.FakeTopicsRepository -import com.google.samples.apps.nowinandroid.data.repository.NewsRepository -import com.google.samples.apps.nowinandroid.data.repository.TopicsRepository -import dagger.Binds -import dagger.Module -import dagger.Provides -import dagger.hilt.components.SingletonComponent -import dagger.hilt.testing.TestInstallIn -import javax.inject.Singleton -import kotlinx.serialization.json.Json -import org.junit.rules.TemporaryFolder - -/** - * The [TestAppModule] replaces [AppModule] during instrumentation tests. It creates test doubles - * where necessary. It also includes logic to prevent multiple data stores with the same file name - * from being created during one test execution context. - */ -@Module -@TestInstallIn( - components = [SingletonComponent::class], - replaces = [AppModule::class] -) -interface TestAppModule { - - // Use a fake repository as a test double, so we don't have a network dependency. - @Binds - fun bindsTopicRepository(fakeTopicsRepository: FakeTopicsRepository): TopicsRepository - - // Use a fake repository as a test double, so we don't have a network dependency. - @Binds - fun bindsNewsResourceRepository(fakeNewsRepository: FakeNewsRepository): NewsRepository - - // Use the default dispatchers. For the high-level UI tests, we don't want to override these. - @Binds - fun bindsNiaDispatchers(defaultNiaDispatchers: DefaultNiaDispatchers): NiaDispatchers - - companion object { - - @Provides - @Singleton - fun providesUserPreferencesDataStore( - userPreferencesSerializer: UserPreferencesSerializer, - tmpFolder: TemporaryFolder - ): DataStore { - return DataStoreFactory.create( - serializer = userPreferencesSerializer, - ) { - tmpFolder.newFile("user_preferences_test.pb") - } - } - - @Provides - @Singleton - fun providesNetworkJson(): Json = Json { - ignoreUnknownKeys = true - } - } -} diff --git a/app/src/main/java/com/google/samples/apps/nowinandroid/di/AppModule.kt b/app/src/main/java/com/google/samples/apps/nowinandroid/di/AppModule.kt deleted file mode 100644 index 11177e9d8..000000000 --- a/app/src/main/java/com/google/samples/apps/nowinandroid/di/AppModule.kt +++ /dev/null @@ -1,81 +0,0 @@ -/* - * Copyright 2022 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 - * - * https://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.samples.apps.nowinandroid.di - -import android.content.Context -import androidx.datastore.core.DataStore -import androidx.datastore.core.DataStoreFactory -import androidx.datastore.dataStoreFile -import com.google.samples.apps.nowinandroid.data.UserPreferences -import com.google.samples.apps.nowinandroid.data.UserPreferencesSerializer -import com.google.samples.apps.nowinandroid.data.fake.FakeNewsRepository -import com.google.samples.apps.nowinandroid.data.fake.FakeNiANetwork -import com.google.samples.apps.nowinandroid.data.fake.FakeTopicsRepository -import com.google.samples.apps.nowinandroid.data.network.NiANetwork -import com.google.samples.apps.nowinandroid.data.repository.NewsRepository -import com.google.samples.apps.nowinandroid.data.repository.TopicsRepository -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 javax.inject.Singleton -import kotlinx.serialization.json.Json - -@Module -@InstallIn(SingletonComponent::class) -interface AppModule { - - @Binds - fun bindsNiANetwork( - fakeNiANetwork: FakeNiANetwork - ): NiANetwork - - @Binds - fun bindsTopicRepository( - fakeTopicsRepository: FakeTopicsRepository - ): TopicsRepository - - @Binds - fun bindsNewsResourceRepository( - fakeNewsRepository: FakeNewsRepository - ): NewsRepository - - @Binds - fun bindsNiaDispatchers(defaultNiaDispatchers: DefaultNiaDispatchers): NiaDispatchers - - companion object { - @Provides - @Singleton - fun providesUserPreferencesDataStore( - @ApplicationContext context: Context, - userPreferencesSerializer: UserPreferencesSerializer - ): DataStore = - DataStoreFactory.create( - serializer = userPreferencesSerializer - ) { - context.dataStoreFile("user_preferences.pb") - } - - @Provides - @Singleton - fun providesNetworkJson(): Json = Json { - ignoreUnknownKeys = true - } - } -} diff --git a/app/src/main/java/com/google/samples/apps/nowinandroid/ui/NiaApp.kt b/app/src/main/java/com/google/samples/apps/nowinandroid/ui/NiaApp.kt index f4d7333ba..45e9437c6 100644 --- a/app/src/main/java/com/google/samples/apps/nowinandroid/ui/NiaApp.kt +++ b/app/src/main/java/com/google/samples/apps/nowinandroid/ui/NiaApp.kt @@ -51,7 +51,8 @@ import androidx.compose.ui.unit.dp import androidx.navigation.compose.currentBackStackEntryAsState import androidx.navigation.compose.rememberNavController import com.google.samples.apps.nowinandroid.R -import com.google.samples.apps.nowinandroid.ui.theme.NiaTheme +import com.google.samples.apps.nowinandroid.core.ui.ClearRippleTheme +import com.google.samples.apps.nowinandroid.core.ui.theme.NiaTheme @OptIn(ExperimentalMaterial3Api::class) @Composable diff --git a/app/src/main/java/com/google/samples/apps/nowinandroid/ui/NiaNavGraph.kt b/app/src/main/java/com/google/samples/apps/nowinandroid/ui/NiaNavGraph.kt index 1392e0c4a..7dafa94b9 100644 --- a/app/src/main/java/com/google/samples/apps/nowinandroid/ui/NiaNavGraph.kt +++ b/app/src/main/java/com/google/samples/apps/nowinandroid/ui/NiaNavGraph.kt @@ -23,8 +23,8 @@ import androidx.navigation.NavHostController import androidx.navigation.compose.NavHost import androidx.navigation.compose.composable import androidx.navigation.compose.rememberNavController -import com.google.samples.apps.nowinandroid.ui.following.FollowingRoute -import com.google.samples.apps.nowinandroid.ui.foryou.ForYouRoute +import com.google.samples.apps.nowinandroid.feature.following.FollowingRoute +import com.google.samples.apps.nowinandroid.feature.foryou.ForYouRoute /** * Top-level navigation graph. Navigation is organized as explained at diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index db9aff18e..4c32312a6 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -15,22 +15,4 @@ --> Now in Android - For you - Episodes - Saved - Done - Loading for you… - Navigate up - - - Bookmark - Unbookmark - - - Following - Loading topics - "Error loading topics" - Topic icon - Follow Topic button - Unfollow Topic button diff --git a/build.gradle b/build.gradle index fcc2bdb2c..00eae597a 100644 --- a/build.gradle +++ b/build.gradle @@ -49,7 +49,7 @@ subprojects { target '**/*.kt' targetExclude("$buildDir/**/*.kt") targetExclude('bin/**/*.kt') - targetExclude("$rootDir/app/src/main/java/com/google/samples/apps/nowinandroid/data/fake/FakeData.kt") + targetExclude("$rootDir/core-network/src/main/java/com/google/samples/apps/nowinandroid/core/network/fake/FakeData.kt") ktlint(libs.versions.ktlint.get()).userData([android: "true"]) licenseHeaderFile rootProject.file('spotless/copyright.kt') } diff --git a/core-common/.gitignore b/core-common/.gitignore new file mode 100644 index 000000000..42afabfd2 --- /dev/null +++ b/core-common/.gitignore @@ -0,0 +1 @@ +/build \ No newline at end of file diff --git a/core-common/build.gradle b/core-common/build.gradle new file mode 100644 index 000000000..1dff19e67 --- /dev/null +++ b/core-common/build.gradle @@ -0,0 +1,35 @@ +/* + * Copyright 2022 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 + * + * https://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 { + id 'com.android.library' + id 'kotlin-android' +} + +android { + compileSdk buildConfig.compileSdk + + defaultConfig { + minSdk buildConfig.minSdk + targetSdk buildConfig.targetSdk + } + compileOptions { + sourceCompatibility JavaVersion.VERSION_1_8 + targetCompatibility JavaVersion.VERSION_1_8 + } + kotlinOptions { + jvmTarget = '1.8' + } +} \ No newline at end of file diff --git a/core-common/src/main/AndroidManifest.xml b/core-common/src/main/AndroidManifest.xml new file mode 100644 index 000000000..0a9c52307 --- /dev/null +++ b/core-common/src/main/AndroidManifest.xml @@ -0,0 +1,5 @@ + + + + \ No newline at end of file diff --git a/core-database/.gitignore b/core-database/.gitignore new file mode 100644 index 000000000..42afabfd2 --- /dev/null +++ b/core-database/.gitignore @@ -0,0 +1 @@ +/build \ No newline at end of file diff --git a/core-database/build.gradle b/core-database/build.gradle new file mode 100644 index 000000000..3f372a760 --- /dev/null +++ b/core-database/build.gradle @@ -0,0 +1,52 @@ +/* + * Copyright 2022 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 + * + * https://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 { + id 'com.android.library' + id 'kotlin-android' + id 'kotlin-kapt' + id 'dagger.hilt.android.plugin' + alias(libs.plugins.ksp) +} + +android { + compileSdk buildConfig.compileSdk + + defaultConfig { + minSdk buildConfig.minSdk + targetSdk buildConfig.targetSdk + } + compileOptions { + sourceCompatibility JavaVersion.VERSION_1_8 + targetCompatibility JavaVersion.VERSION_1_8 + } + kotlinOptions { + jvmTarget = '1.8' + } +} + +dependencies { + implementation project(':core-model') + + implementation libs.room.runtime + implementation libs.room.ktx + ksp libs.room.compiler + + implementation libs.kotlinx.coroutines.android + implementation libs.kotlinx.datetime + + implementation libs.hilt.android + kapt libs.hilt.compiler +} \ No newline at end of file diff --git a/core-database/src/main/AndroidManifest.xml b/core-database/src/main/AndroidManifest.xml new file mode 100644 index 000000000..d2f457d63 --- /dev/null +++ b/core-database/src/main/AndroidManifest.xml @@ -0,0 +1,5 @@ + + + + \ No newline at end of file diff --git a/app/src/main/java/com/google/samples/apps/nowinandroid/di/DaosModule.kt b/core-database/src/main/java/com/google/samples/apps/nowinandroid/core/database/DaosModule.kt similarity index 76% rename from app/src/main/java/com/google/samples/apps/nowinandroid/di/DaosModule.kt rename to core-database/src/main/java/com/google/samples/apps/nowinandroid/core/database/DaosModule.kt index 0c07b7ae3..ea97a12e3 100644 --- a/app/src/main/java/com/google/samples/apps/nowinandroid/di/DaosModule.kt +++ b/core-database/src/main/java/com/google/samples/apps/nowinandroid/core/database/DaosModule.kt @@ -14,13 +14,12 @@ * limitations under the License. */ -package com.google.samples.apps.nowinandroid.di +package com.google.samples.apps.nowinandroid.core.database -import com.google.samples.apps.nowinandroid.data.local.NiADatabase -import com.google.samples.apps.nowinandroid.data.local.dao.AuthorDao -import com.google.samples.apps.nowinandroid.data.local.dao.EpisodeDao -import com.google.samples.apps.nowinandroid.data.local.dao.NewsResourceDao -import com.google.samples.apps.nowinandroid.data.local.dao.TopicDao +import com.google.samples.apps.nowinandroid.core.database.dao.AuthorDao +import com.google.samples.apps.nowinandroid.core.database.dao.EpisodeDao +import com.google.samples.apps.nowinandroid.core.database.dao.NewsResourceDao +import com.google.samples.apps.nowinandroid.core.database.dao.TopicDao import dagger.Module import dagger.Provides import dagger.hilt.InstallIn diff --git a/app/src/main/java/com/google/samples/apps/nowinandroid/di/DatabaseModule.kt b/core-database/src/main/java/com/google/samples/apps/nowinandroid/core/database/DatabaseModule.kt similarity index 91% rename from app/src/main/java/com/google/samples/apps/nowinandroid/di/DatabaseModule.kt rename to core-database/src/main/java/com/google/samples/apps/nowinandroid/core/database/DatabaseModule.kt index 1952e64b3..a97e70bee 100644 --- a/app/src/main/java/com/google/samples/apps/nowinandroid/di/DatabaseModule.kt +++ b/core-database/src/main/java/com/google/samples/apps/nowinandroid/core/database/DatabaseModule.kt @@ -14,11 +14,10 @@ * limitations under the License. */ -package com.google.samples.apps.nowinandroid.di +package com.google.samples.apps.nowinandroid.core.database import android.content.Context import androidx.room.Room -import com.google.samples.apps.nowinandroid.data.local.NiADatabase import dagger.Module import dagger.Provides import dagger.hilt.InstallIn diff --git a/app/src/main/java/com/google/samples/apps/nowinandroid/data/local/NiADatabase.kt b/core-database/src/main/java/com/google/samples/apps/nowinandroid/core/database/NiADatabase.kt similarity index 60% rename from app/src/main/java/com/google/samples/apps/nowinandroid/data/local/NiADatabase.kt rename to core-database/src/main/java/com/google/samples/apps/nowinandroid/core/database/NiADatabase.kt index 44f50ab17..7494c4c44 100644 --- a/app/src/main/java/com/google/samples/apps/nowinandroid/data/local/NiADatabase.kt +++ b/core-database/src/main/java/com/google/samples/apps/nowinandroid/core/database/NiADatabase.kt @@ -14,24 +14,24 @@ * limitations under the License. */ -package com.google.samples.apps.nowinandroid.data.local +package com.google.samples.apps.nowinandroid.core.database import androidx.room.Database import androidx.room.RoomDatabase import androidx.room.TypeConverters -import com.google.samples.apps.nowinandroid.data.local.dao.AuthorDao -import com.google.samples.apps.nowinandroid.data.local.dao.EpisodeDao -import com.google.samples.apps.nowinandroid.data.local.dao.NewsResourceDao -import com.google.samples.apps.nowinandroid.data.local.dao.TopicDao -import com.google.samples.apps.nowinandroid.data.local.entities.AuthorEntity -import com.google.samples.apps.nowinandroid.data.local.entities.EpisodeAuthorCrossRef -import com.google.samples.apps.nowinandroid.data.local.entities.EpisodeEntity -import com.google.samples.apps.nowinandroid.data.local.entities.NewsResourceAuthorCrossRef -import com.google.samples.apps.nowinandroid.data.local.entities.NewsResourceEntity -import com.google.samples.apps.nowinandroid.data.local.entities.NewsResourceTopicCrossRef -import com.google.samples.apps.nowinandroid.data.local.entities.TopicEntity -import com.google.samples.apps.nowinandroid.data.local.utilities.InstantConverter -import com.google.samples.apps.nowinandroid.data.local.utilities.NewsResourceTypeConverter +import com.google.samples.apps.nowinandroid.core.database.dao.AuthorDao +import com.google.samples.apps.nowinandroid.core.database.dao.EpisodeDao +import com.google.samples.apps.nowinandroid.core.database.dao.NewsResourceDao +import com.google.samples.apps.nowinandroid.core.database.dao.TopicDao +import com.google.samples.apps.nowinandroid.core.database.util.InstantConverter +import com.google.samples.apps.nowinandroid.core.database.util.NewsResourceTypeConverter +import com.google.samples.apps.nowinandroid.core.model.entities.AuthorEntity +import com.google.samples.apps.nowinandroid.core.model.entities.EpisodeAuthorCrossRef +import com.google.samples.apps.nowinandroid.core.model.entities.EpisodeEntity +import com.google.samples.apps.nowinandroid.core.model.entities.NewsResourceAuthorCrossRef +import com.google.samples.apps.nowinandroid.core.model.entities.NewsResourceEntity +import com.google.samples.apps.nowinandroid.core.model.entities.NewsResourceTopicCrossRef +import com.google.samples.apps.nowinandroid.core.model.entities.TopicEntity @Database( entities = [ diff --git a/app/src/main/java/com/google/samples/apps/nowinandroid/data/local/dao/AuthorDao.kt b/core-database/src/main/java/com/google/samples/apps/nowinandroid/core/database/dao/AuthorDao.kt similarity index 88% rename from app/src/main/java/com/google/samples/apps/nowinandroid/data/local/dao/AuthorDao.kt rename to core-database/src/main/java/com/google/samples/apps/nowinandroid/core/database/dao/AuthorDao.kt index e38e4be8b..a985f1c2d 100644 --- a/app/src/main/java/com/google/samples/apps/nowinandroid/data/local/dao/AuthorDao.kt +++ b/core-database/src/main/java/com/google/samples/apps/nowinandroid/core/database/dao/AuthorDao.kt @@ -14,12 +14,12 @@ * limitations under the License. */ -package com.google.samples.apps.nowinandroid.data.local.dao +package com.google.samples.apps.nowinandroid.core.database.dao import androidx.room.Dao import androidx.room.Insert import androidx.room.Query -import com.google.samples.apps.nowinandroid.data.local.entities.AuthorEntity +import com.google.samples.apps.nowinandroid.core.model.entities.AuthorEntity import kotlinx.coroutines.flow.Flow /** diff --git a/app/src/main/java/com/google/samples/apps/nowinandroid/data/local/dao/EpisodeDao.kt b/core-database/src/main/java/com/google/samples/apps/nowinandroid/core/database/dao/EpisodeDao.kt similarity index 83% rename from app/src/main/java/com/google/samples/apps/nowinandroid/data/local/dao/EpisodeDao.kt rename to core-database/src/main/java/com/google/samples/apps/nowinandroid/core/database/dao/EpisodeDao.kt index d873f2215..2fc5398ae 100644 --- a/app/src/main/java/com/google/samples/apps/nowinandroid/data/local/dao/EpisodeDao.kt +++ b/core-database/src/main/java/com/google/samples/apps/nowinandroid/core/database/dao/EpisodeDao.kt @@ -14,13 +14,13 @@ * limitations under the License. */ -package com.google.samples.apps.nowinandroid.data.local.dao +package com.google.samples.apps.nowinandroid.core.database.dao import androidx.room.Dao import androidx.room.Insert import androidx.room.Query -import com.google.samples.apps.nowinandroid.data.local.entities.EpisodeEntity -import com.google.samples.apps.nowinandroid.data.model.Episode +import com.google.samples.apps.nowinandroid.core.model.data.Episode +import com.google.samples.apps.nowinandroid.core.model.entities.EpisodeEntity import kotlinx.coroutines.flow.Flow /** diff --git a/app/src/main/java/com/google/samples/apps/nowinandroid/data/local/dao/NewsResourceDao.kt b/core-database/src/main/java/com/google/samples/apps/nowinandroid/core/database/dao/NewsResourceDao.kt similarity index 86% rename from app/src/main/java/com/google/samples/apps/nowinandroid/data/local/dao/NewsResourceDao.kt rename to core-database/src/main/java/com/google/samples/apps/nowinandroid/core/database/dao/NewsResourceDao.kt index 548d37fc0..dcd4ffba8 100644 --- a/app/src/main/java/com/google/samples/apps/nowinandroid/data/local/dao/NewsResourceDao.kt +++ b/core-database/src/main/java/com/google/samples/apps/nowinandroid/core/database/dao/NewsResourceDao.kt @@ -14,13 +14,13 @@ * limitations under the License. */ -package com.google.samples.apps.nowinandroid.data.local.dao +package com.google.samples.apps.nowinandroid.core.database.dao import androidx.room.Dao import androidx.room.Insert import androidx.room.Query -import com.google.samples.apps.nowinandroid.data.local.entities.NewsResourceEntity -import com.google.samples.apps.nowinandroid.data.model.NewsResource +import com.google.samples.apps.nowinandroid.core.model.data.NewsResource +import com.google.samples.apps.nowinandroid.core.model.entities.NewsResourceEntity import kotlinx.coroutines.flow.Flow /** diff --git a/app/src/main/java/com/google/samples/apps/nowinandroid/data/local/dao/TopicDao.kt b/core-database/src/main/java/com/google/samples/apps/nowinandroid/core/database/dao/TopicDao.kt similarity index 90% rename from app/src/main/java/com/google/samples/apps/nowinandroid/data/local/dao/TopicDao.kt rename to core-database/src/main/java/com/google/samples/apps/nowinandroid/core/database/dao/TopicDao.kt index c523b886b..5bf7e4439 100644 --- a/app/src/main/java/com/google/samples/apps/nowinandroid/data/local/dao/TopicDao.kt +++ b/core-database/src/main/java/com/google/samples/apps/nowinandroid/core/database/dao/TopicDao.kt @@ -14,12 +14,12 @@ * limitations under the License. */ -package com.google.samples.apps.nowinandroid.data.local.dao +package com.google.samples.apps.nowinandroid.core.database.dao import androidx.room.Dao import androidx.room.Insert import androidx.room.Query -import com.google.samples.apps.nowinandroid.data.local.entities.TopicEntity +import com.google.samples.apps.nowinandroid.core.model.entities.TopicEntity import kotlinx.coroutines.flow.Flow /** diff --git a/app/src/main/java/com/google/samples/apps/nowinandroid/data/local/utilities/Converters.kt b/core-database/src/main/java/com/google/samples/apps/nowinandroid/core/database/util/Converters.kt similarity index 90% rename from app/src/main/java/com/google/samples/apps/nowinandroid/data/local/utilities/Converters.kt rename to core-database/src/main/java/com/google/samples/apps/nowinandroid/core/database/util/Converters.kt index 4e0691609..dc7949eae 100644 --- a/app/src/main/java/com/google/samples/apps/nowinandroid/data/local/utilities/Converters.kt +++ b/core-database/src/main/java/com/google/samples/apps/nowinandroid/core/database/util/Converters.kt @@ -14,10 +14,10 @@ * limitations under the License. */ -package com.google.samples.apps.nowinandroid.data.local.utilities +package com.google.samples.apps.nowinandroid.core.database.util import androidx.room.TypeConverter -import com.google.samples.apps.nowinandroid.data.model.NewsResourceType +import com.google.samples.apps.nowinandroid.core.model.data.NewsResourceType import kotlinx.datetime.Instant class InstantConverter { diff --git a/core-datastore-test/.gitignore b/core-datastore-test/.gitignore new file mode 100644 index 000000000..42afabfd2 --- /dev/null +++ b/core-datastore-test/.gitignore @@ -0,0 +1 @@ +/build \ No newline at end of file diff --git a/core-datastore-test/build.gradle b/core-datastore-test/build.gradle new file mode 100644 index 000000000..ec696cf29 --- /dev/null +++ b/core-datastore-test/build.gradle @@ -0,0 +1,55 @@ +/* + * Copyright 2022 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 + * + * https://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 { + id 'com.android.library' + id 'kotlin-android' + id 'kotlin-kapt' + id 'dagger.hilt.android.plugin' +} + +android { + compileSdk buildConfig.compileSdk + + defaultConfig { + minSdk buildConfig.minSdk + targetSdk buildConfig.targetSdk + } + compileOptions { + sourceCompatibility JavaVersion.VERSION_1_8 + targetCompatibility JavaVersion.VERSION_1_8 + } + kotlinOptions { + jvmTarget = '1.8' + } +} + +dependencies { + implementation project(':core-datastore') + implementation project(':core-testing') + + implementation libs.androidx.dataStore + + implementation libs.hilt.android + kapt libs.hilt.compiler + kaptAndroidTest libs.hilt.compiler + + configurations.configureEach { + resolutionStrategy { + // Temporary workaround for https://issuetracker.google.com/174733673 + force 'org.objenesis:objenesis:2.6' + } + } +} \ No newline at end of file diff --git a/core-datastore-test/src/main/AndroidManifest.xml b/core-datastore-test/src/main/AndroidManifest.xml new file mode 100644 index 000000000..fa414c5d8 --- /dev/null +++ b/core-datastore-test/src/main/AndroidManifest.xml @@ -0,0 +1,5 @@ + + + + \ No newline at end of file diff --git a/core-datastore-test/src/main/java/com/google/samples/apps/nowinandroid/core/datastore/test/TestDataStoreModule.kt b/core-datastore-test/src/main/java/com/google/samples/apps/nowinandroid/core/datastore/test/TestDataStoreModule.kt new file mode 100644 index 000000000..567686fa9 --- /dev/null +++ b/core-datastore-test/src/main/java/com/google/samples/apps/nowinandroid/core/datastore/test/TestDataStoreModule.kt @@ -0,0 +1,50 @@ +/* + * Copyright 2022 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 + * + * https://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.samples.apps.nowinandroid.core.datastore.test + +import androidx.datastore.core.DataStore +import androidx.datastore.core.DataStoreFactory +import com.google.samples.apps.nowinandroid.core.datastore.UserPreferences +import com.google.samples.apps.nowinandroid.core.datastore.UserPreferencesSerializer +import com.google.samples.apps.nowinandroid.core.datastore.di.DataStoreModule +import dagger.Module +import dagger.Provides +import dagger.hilt.components.SingletonComponent +import dagger.hilt.testing.TestInstallIn +import javax.inject.Singleton +import org.junit.rules.TemporaryFolder + +@Module +@TestInstallIn( + components = [SingletonComponent::class], + replaces = [DataStoreModule::class] +) +object TestDataStoreModule { + + @Provides + @Singleton + fun providesUserPreferencesDataStore( + userPreferencesSerializer: UserPreferencesSerializer, + tmpFolder: TemporaryFolder + ): DataStore { + return DataStoreFactory.create( + serializer = userPreferencesSerializer, + ) { + tmpFolder.newFile("user_preferences_test.pb") + } + } +} diff --git a/core-datastore/.gitignore b/core-datastore/.gitignore new file mode 100644 index 000000000..42afabfd2 --- /dev/null +++ b/core-datastore/.gitignore @@ -0,0 +1 @@ +/build \ No newline at end of file diff --git a/core-datastore/build.gradle b/core-datastore/build.gradle new file mode 100644 index 000000000..c83db8768 --- /dev/null +++ b/core-datastore/build.gradle @@ -0,0 +1,70 @@ +/* + * Copyright 2022 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 + * + * https://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 { + id 'com.android.library' + id 'kotlin-android' + id 'kotlin-kapt' + id 'dagger.hilt.android.plugin' + alias(libs.plugins.protobuf) +} + +android { + compileSdk buildConfig.compileSdk + + defaultConfig { + minSdk buildConfig.minSdk + targetSdk buildConfig.targetSdk + } + compileOptions { + sourceCompatibility JavaVersion.VERSION_1_8 + targetCompatibility JavaVersion.VERSION_1_8 + } + kotlinOptions { + jvmTarget = '1.8' + } +} + +// Setup protobuf configuration, generating lite Java and Kotlin classes +protobuf { + protoc { + artifact = libs.protobuf.protoc.get() + } + generateProtoTasks { + all().each { task -> + task.builtins { + java { + option "lite" + } + kotlin { + option "lite" + } + } + } + } +} + +dependencies { + testImplementation project(':core-testing') + + implementation libs.kotlinx.coroutines.android + + implementation libs.androidx.dataStore + implementation libs.protobuf.kotlin.lite + + implementation libs.hilt.android + kapt libs.hilt.compiler + kaptAndroidTest libs.hilt.compiler +} \ No newline at end of file diff --git a/core-datastore/src/main/AndroidManifest.xml b/core-datastore/src/main/AndroidManifest.xml new file mode 100644 index 000000000..73c7fc7b6 --- /dev/null +++ b/core-datastore/src/main/AndroidManifest.xml @@ -0,0 +1,5 @@ + + + + \ No newline at end of file diff --git a/app/src/main/java/com/google/samples/apps/nowinandroid/data/NiaPreferences.kt b/core-datastore/src/main/java/com/google/samples/apps/nowinandroid/core/datastore/NiaPreferences.kt similarity index 97% rename from app/src/main/java/com/google/samples/apps/nowinandroid/data/NiaPreferences.kt rename to core-datastore/src/main/java/com/google/samples/apps/nowinandroid/core/datastore/NiaPreferences.kt index 1ca429492..ab4111ca1 100644 --- a/app/src/main/java/com/google/samples/apps/nowinandroid/data/NiaPreferences.kt +++ b/core-datastore/src/main/java/com/google/samples/apps/nowinandroid/core/datastore/NiaPreferences.kt @@ -14,7 +14,7 @@ * limitations under the License. */ -package com.google.samples.apps.nowinandroid.data +package com.google.samples.apps.nowinandroid.core.datastore import android.util.Log import androidx.datastore.core.DataStore diff --git a/app/src/main/java/com/google/samples/apps/nowinandroid/data/UserPreferencesSerializer.kt b/core-datastore/src/main/java/com/google/samples/apps/nowinandroid/core/datastore/UserPreferencesSerializer.kt similarity index 96% rename from app/src/main/java/com/google/samples/apps/nowinandroid/data/UserPreferencesSerializer.kt rename to core-datastore/src/main/java/com/google/samples/apps/nowinandroid/core/datastore/UserPreferencesSerializer.kt index 94065332b..6d1a4ab8b 100644 --- a/app/src/main/java/com/google/samples/apps/nowinandroid/data/UserPreferencesSerializer.kt +++ b/core-datastore/src/main/java/com/google/samples/apps/nowinandroid/core/datastore/UserPreferencesSerializer.kt @@ -14,7 +14,7 @@ * limitations under the License. */ -package com.google.samples.apps.nowinandroid.data +package com.google.samples.apps.nowinandroid.core.datastore import androidx.datastore.core.CorruptionException import androidx.datastore.core.Serializer diff --git a/core-datastore/src/main/java/com/google/samples/apps/nowinandroid/core/datastore/di/DataStoreModule.kt b/core-datastore/src/main/java/com/google/samples/apps/nowinandroid/core/datastore/di/DataStoreModule.kt new file mode 100644 index 000000000..bf4ca947a --- /dev/null +++ b/core-datastore/src/main/java/com/google/samples/apps/nowinandroid/core/datastore/di/DataStoreModule.kt @@ -0,0 +1,47 @@ +/* + * Copyright 2022 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 + * + * https://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.samples.apps.nowinandroid.core.datastore.di + +import android.content.Context +import androidx.datastore.core.DataStore +import androidx.datastore.core.DataStoreFactory +import androidx.datastore.dataStoreFile +import com.google.samples.apps.nowinandroid.core.datastore.UserPreferences +import com.google.samples.apps.nowinandroid.core.datastore.UserPreferencesSerializer +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 DataStoreModule { + + @Provides + @Singleton + fun providesUserPreferencesDataStore( + @ApplicationContext context: Context, + userPreferencesSerializer: UserPreferencesSerializer + ): DataStore = + DataStoreFactory.create( + serializer = userPreferencesSerializer + ) { + context.dataStoreFile("user_preferences.pb") + } +} diff --git a/app/src/main/proto/com/google/samples/apps/nowinandroid/data/user_preferences.proto b/core-datastore/src/main/proto/com/google/samples/apps/nowinandroid/data/user_preferences.proto similarity index 90% rename from app/src/main/proto/com/google/samples/apps/nowinandroid/data/user_preferences.proto rename to core-datastore/src/main/proto/com/google/samples/apps/nowinandroid/data/user_preferences.proto index e776439c1..fc42652fe 100644 --- a/app/src/main/proto/com/google/samples/apps/nowinandroid/data/user_preferences.proto +++ b/core-datastore/src/main/proto/com/google/samples/apps/nowinandroid/data/user_preferences.proto @@ -16,7 +16,7 @@ syntax = "proto3"; -option java_package = "com.google.samples.apps.nowinandroid.data"; +option java_package = "com.google.samples.apps.nowinandroid.core.datastore"; option java_multiple_files = true; message UserPreferences { diff --git a/app/src/test/java/com/google/samples/apps/nowinandroid/data/UserPreferencesSerializerTest.kt b/core-datastore/src/test/java/com/google/samples/apps/nowinandroid/core/datastore/UserPreferencesSerializerTest.kt similarity index 97% rename from app/src/test/java/com/google/samples/apps/nowinandroid/data/UserPreferencesSerializerTest.kt rename to core-datastore/src/test/java/com/google/samples/apps/nowinandroid/core/datastore/UserPreferencesSerializerTest.kt index 45aafe036..b0906f7db 100644 --- a/app/src/test/java/com/google/samples/apps/nowinandroid/data/UserPreferencesSerializerTest.kt +++ b/core-datastore/src/test/java/com/google/samples/apps/nowinandroid/core/datastore/UserPreferencesSerializerTest.kt @@ -14,7 +14,7 @@ * limitations under the License. */ -package com.google.samples.apps.nowinandroid.data +package com.google.samples.apps.nowinandroid.core.datastore import androidx.datastore.core.CorruptionException import java.io.ByteArrayInputStream diff --git a/core-domain/.gitignore b/core-domain/.gitignore new file mode 100644 index 000000000..42afabfd2 --- /dev/null +++ b/core-domain/.gitignore @@ -0,0 +1 @@ +/build \ No newline at end of file diff --git a/core-domain/build.gradle b/core-domain/build.gradle new file mode 100644 index 000000000..fe0a7612e --- /dev/null +++ b/core-domain/build.gradle @@ -0,0 +1,52 @@ +/* + * Copyright 2022 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 + * + * https://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 { + id 'com.android.library' + id 'kotlin-android' + id 'kotlin-kapt' + id 'kotlinx-serialization' + id 'dagger.hilt.android.plugin' +} + +android { + compileSdk buildConfig.compileSdk + + defaultConfig { + minSdk buildConfig.minSdk + targetSdk buildConfig.targetSdk + } + compileOptions { + sourceCompatibility JavaVersion.VERSION_1_8 + targetCompatibility JavaVersion.VERSION_1_8 + } + kotlinOptions { + jvmTarget = '1.8' + } +} + +dependencies { + implementation project(':core-model') + implementation project(':core-datastore') + implementation project(':core-network') + + testImplementation project(':core-testing') + + implementation libs.kotlinx.coroutines.android + implementation libs.kotlinx.serialization.json + + implementation libs.hilt.android + kapt libs.hilt.compiler +} \ No newline at end of file diff --git a/core-domain/src/main/AndroidManifest.xml b/core-domain/src/main/AndroidManifest.xml new file mode 100644 index 000000000..448433a3d --- /dev/null +++ b/core-domain/src/main/AndroidManifest.xml @@ -0,0 +1,5 @@ + + + + \ No newline at end of file diff --git a/core-domain/src/main/java/com/google/samples/apps/nowinandroid/core/domain/di/DomainModule.kt b/core-domain/src/main/java/com/google/samples/apps/nowinandroid/core/domain/di/DomainModule.kt new file mode 100644 index 000000000..81d9837bf --- /dev/null +++ b/core-domain/src/main/java/com/google/samples/apps/nowinandroid/core/domain/di/DomainModule.kt @@ -0,0 +1,41 @@ +/* + * Copyright 2022 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 + * + * https://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.samples.apps.nowinandroid.core.domain.di + +import com.google.samples.apps.nowinandroid.core.domain.repository.FakeNewsRepository +import com.google.samples.apps.nowinandroid.core.domain.repository.FakeTopicsRepository +import com.google.samples.apps.nowinandroid.core.domain.repository.NewsRepository +import com.google.samples.apps.nowinandroid.core.domain.repository.TopicsRepository +import dagger.Binds +import dagger.Module +import dagger.hilt.InstallIn +import dagger.hilt.components.SingletonComponent + +@Module +@InstallIn(SingletonComponent::class) +interface DomainModule { + + @Binds + fun bindsTopicRepository( + fakeTopicsRepository: FakeTopicsRepository + ): TopicsRepository + + @Binds + fun bindsNewsResourceRepository( + fakeNewsRepository: FakeNewsRepository + ): NewsRepository +} diff --git a/app/src/main/java/com/google/samples/apps/nowinandroid/data/fake/FakeNewsRepository.kt b/core-domain/src/main/java/com/google/samples/apps/nowinandroid/core/domain/repository/FakeNewsRepository.kt similarity index 83% rename from app/src/main/java/com/google/samples/apps/nowinandroid/data/fake/FakeNewsRepository.kt rename to core-domain/src/main/java/com/google/samples/apps/nowinandroid/core/domain/repository/FakeNewsRepository.kt index 087f8823c..614e38634 100644 --- a/app/src/main/java/com/google/samples/apps/nowinandroid/data/fake/FakeNewsRepository.kt +++ b/core-domain/src/main/java/com/google/samples/apps/nowinandroid/core/domain/repository/FakeNewsRepository.kt @@ -14,11 +14,10 @@ * limitations under the License. */ -package com.google.samples.apps.nowinandroid.data.fake +package com.google.samples.apps.nowinandroid.core.domain.repository -import com.google.samples.apps.nowinandroid.data.model.NewsResource -import com.google.samples.apps.nowinandroid.data.repository.NewsRepository -import com.google.samples.apps.nowinandroid.di.NiaDispatchers +import com.google.samples.apps.nowinandroid.core.model.data.NewsResource +import com.google.samples.apps.nowinandroid.core.network.NiaDispatchers import javax.inject.Inject import kotlinx.coroutines.flow.Flow import kotlinx.coroutines.flow.flowOf diff --git a/app/src/main/java/com/google/samples/apps/nowinandroid/data/fake/FakeTopicsRepository.kt b/core-domain/src/main/java/com/google/samples/apps/nowinandroid/core/domain/repository/FakeTopicsRepository.kt similarity index 83% rename from app/src/main/java/com/google/samples/apps/nowinandroid/data/fake/FakeTopicsRepository.kt rename to core-domain/src/main/java/com/google/samples/apps/nowinandroid/core/domain/repository/FakeTopicsRepository.kt index dc6b6d4e2..9c8cf8ab2 100644 --- a/app/src/main/java/com/google/samples/apps/nowinandroid/data/fake/FakeTopicsRepository.kt +++ b/core-domain/src/main/java/com/google/samples/apps/nowinandroid/core/domain/repository/FakeTopicsRepository.kt @@ -14,13 +14,13 @@ * limitations under the License. */ -package com.google.samples.apps.nowinandroid.data.fake +package com.google.samples.apps.nowinandroid.core.domain.repository -import com.google.samples.apps.nowinandroid.data.NiaPreferences -import com.google.samples.apps.nowinandroid.data.model.Topic -import com.google.samples.apps.nowinandroid.data.network.NetworkTopic -import com.google.samples.apps.nowinandroid.data.repository.TopicsRepository -import com.google.samples.apps.nowinandroid.di.NiaDispatchers +import com.google.samples.apps.nowinandroid.core.datastore.NiaPreferences +import com.google.samples.apps.nowinandroid.core.model.data.Topic +import com.google.samples.apps.nowinandroid.core.model.network.NetworkTopic +import com.google.samples.apps.nowinandroid.core.network.NiaDispatchers +import com.google.samples.apps.nowinandroid.core.network.fake.FakeDataSource import javax.inject.Inject import kotlinx.coroutines.flow.Flow import kotlinx.coroutines.flow.flow diff --git a/app/src/main/java/com/google/samples/apps/nowinandroid/data/repository/NewsRepository.kt b/core-domain/src/main/java/com/google/samples/apps/nowinandroid/core/domain/repository/NewsRepository.kt similarity index 88% rename from app/src/main/java/com/google/samples/apps/nowinandroid/data/repository/NewsRepository.kt rename to core-domain/src/main/java/com/google/samples/apps/nowinandroid/core/domain/repository/NewsRepository.kt index a1ce792d3..b23dffec4 100644 --- a/app/src/main/java/com/google/samples/apps/nowinandroid/data/repository/NewsRepository.kt +++ b/core-domain/src/main/java/com/google/samples/apps/nowinandroid/core/domain/repository/NewsRepository.kt @@ -14,9 +14,9 @@ * limitations under the License. */ -package com.google.samples.apps.nowinandroid.data.repository +package com.google.samples.apps.nowinandroid.core.domain.repository -import com.google.samples.apps.nowinandroid.data.model.NewsResource +import com.google.samples.apps.nowinandroid.core.model.data.NewsResource import kotlinx.coroutines.flow.Flow /** diff --git a/app/src/main/java/com/google/samples/apps/nowinandroid/data/repository/TopicsRepository.kt b/core-domain/src/main/java/com/google/samples/apps/nowinandroid/core/domain/repository/TopicsRepository.kt similarity index 89% rename from app/src/main/java/com/google/samples/apps/nowinandroid/data/repository/TopicsRepository.kt rename to core-domain/src/main/java/com/google/samples/apps/nowinandroid/core/domain/repository/TopicsRepository.kt index 0824bcaaa..224611989 100644 --- a/app/src/main/java/com/google/samples/apps/nowinandroid/data/repository/TopicsRepository.kt +++ b/core-domain/src/main/java/com/google/samples/apps/nowinandroid/core/domain/repository/TopicsRepository.kt @@ -14,9 +14,9 @@ * limitations under the License. */ -package com.google.samples.apps.nowinandroid.data.repository +package com.google.samples.apps.nowinandroid.core.domain.repository -import com.google.samples.apps.nowinandroid.data.model.Topic +import com.google.samples.apps.nowinandroid.core.model.data.Topic import kotlinx.coroutines.flow.Flow interface TopicsRepository { diff --git a/app/src/test/java/com/google/samples/apps/nowinandroid/data/fake/FakeNewsRepositoryTest.kt b/core-domain/src/test/java/com/google/samples/apps/nowinandroid/core/domain/repository/FakeNewsRepositoryTest.kt similarity index 87% rename from app/src/test/java/com/google/samples/apps/nowinandroid/data/fake/FakeNewsRepositoryTest.kt rename to core-domain/src/test/java/com/google/samples/apps/nowinandroid/core/domain/repository/FakeNewsRepositoryTest.kt index 05a71e0d9..061c9ec13 100644 --- a/app/src/test/java/com/google/samples/apps/nowinandroid/data/fake/FakeNewsRepositoryTest.kt +++ b/core-domain/src/test/java/com/google/samples/apps/nowinandroid/core/domain/repository/FakeNewsRepositoryTest.kt @@ -14,9 +14,9 @@ * limitations under the License. */ -package com.google.samples.apps.nowinandroid.data.fake +package com.google.samples.apps.nowinandroid.core.domain.repository -import com.google.samples.apps.nowinandroid.di.DefaultNiaDispatchers +import com.google.samples.apps.nowinandroid.core.network.DefaultNiaDispatchers import kotlinx.serialization.json.Json import org.junit.Before diff --git a/core-model/.gitignore b/core-model/.gitignore new file mode 100644 index 000000000..42afabfd2 --- /dev/null +++ b/core-model/.gitignore @@ -0,0 +1 @@ +/build \ No newline at end of file diff --git a/core-model/build.gradle b/core-model/build.gradle new file mode 100644 index 000000000..e2f84391c --- /dev/null +++ b/core-model/build.gradle @@ -0,0 +1,49 @@ +/* + * Copyright 2022 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 + * + * https://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 { + id 'com.android.library' + id 'kotlin-android' + id 'kotlinx-serialization' + alias(libs.plugins.ksp) +} + +android { + compileSdk buildConfig.compileSdk + + defaultConfig { + minSdk buildConfig.minSdk + targetSdk buildConfig.targetSdk + } + compileOptions { + sourceCompatibility JavaVersion.VERSION_1_8 + targetCompatibility JavaVersion.VERSION_1_8 + } + kotlinOptions { + jvmTarget = '1.8' + } +} + +dependencies { + testImplementation project(':core-testing') + + implementation libs.room.runtime + implementation libs.room.ktx + ksp libs.room.compiler + + implementation libs.kotlinx.coroutines.android + implementation libs.kotlinx.datetime + implementation libs.kotlinx.serialization.json +} \ No newline at end of file diff --git a/core-model/src/main/AndroidManifest.xml b/core-model/src/main/AndroidManifest.xml new file mode 100644 index 000000000..ed0bf90c5 --- /dev/null +++ b/core-model/src/main/AndroidManifest.xml @@ -0,0 +1,5 @@ + + + + \ No newline at end of file diff --git a/app/src/main/java/com/google/samples/apps/nowinandroid/data/model/Episode.kt b/core-model/src/main/java/com/google/samples/apps/nowinandroid/core/model/data/Episode.kt similarity index 80% rename from app/src/main/java/com/google/samples/apps/nowinandroid/data/model/Episode.kt rename to core-model/src/main/java/com/google/samples/apps/nowinandroid/core/model/data/Episode.kt index a4a4c10c0..6cf5677aa 100644 --- a/app/src/main/java/com/google/samples/apps/nowinandroid/data/model/Episode.kt +++ b/core-model/src/main/java/com/google/samples/apps/nowinandroid/core/model/data/Episode.kt @@ -14,15 +14,15 @@ * limitations under the License. */ -package com.google.samples.apps.nowinandroid.data.model +package com.google.samples.apps.nowinandroid.core.model.data import androidx.room.Embedded import androidx.room.Junction import androidx.room.Relation -import com.google.samples.apps.nowinandroid.data.local.entities.AuthorEntity -import com.google.samples.apps.nowinandroid.data.local.entities.EpisodeAuthorCrossRef -import com.google.samples.apps.nowinandroid.data.local.entities.EpisodeEntity -import com.google.samples.apps.nowinandroid.data.local.entities.NewsResourceEntity +import com.google.samples.apps.nowinandroid.core.model.entities.AuthorEntity +import com.google.samples.apps.nowinandroid.core.model.entities.EpisodeAuthorCrossRef +import com.google.samples.apps.nowinandroid.core.model.entities.EpisodeEntity +import com.google.samples.apps.nowinandroid.core.model.entities.NewsResourceEntity /** * External data layer representation of an NiA episode diff --git a/app/src/main/java/com/google/samples/apps/nowinandroid/data/model/NewsResource.kt b/core-model/src/main/java/com/google/samples/apps/nowinandroid/core/model/data/NewsResource.kt similarity index 79% rename from app/src/main/java/com/google/samples/apps/nowinandroid/data/model/NewsResource.kt rename to core-model/src/main/java/com/google/samples/apps/nowinandroid/core/model/data/NewsResource.kt index cc6ca9e97..6a9bae94f 100644 --- a/app/src/main/java/com/google/samples/apps/nowinandroid/data/model/NewsResource.kt +++ b/core-model/src/main/java/com/google/samples/apps/nowinandroid/core/model/data/NewsResource.kt @@ -14,17 +14,17 @@ * limitations under the License. */ -package com.google.samples.apps.nowinandroid.data.model +package com.google.samples.apps.nowinandroid.core.model.data import androidx.room.Embedded import androidx.room.Junction import androidx.room.Relation -import com.google.samples.apps.nowinandroid.data.local.entities.AuthorEntity -import com.google.samples.apps.nowinandroid.data.local.entities.EpisodeEntity -import com.google.samples.apps.nowinandroid.data.local.entities.NewsResourceAuthorCrossRef -import com.google.samples.apps.nowinandroid.data.local.entities.NewsResourceEntity -import com.google.samples.apps.nowinandroid.data.local.entities.NewsResourceTopicCrossRef -import com.google.samples.apps.nowinandroid.data.local.entities.TopicEntity +import com.google.samples.apps.nowinandroid.core.model.entities.AuthorEntity +import com.google.samples.apps.nowinandroid.core.model.entities.EpisodeEntity +import com.google.samples.apps.nowinandroid.core.model.entities.NewsResourceAuthorCrossRef +import com.google.samples.apps.nowinandroid.core.model.entities.NewsResourceEntity +import com.google.samples.apps.nowinandroid.core.model.entities.NewsResourceTopicCrossRef +import com.google.samples.apps.nowinandroid.core.model.entities.TopicEntity /** * External data layer representation of a fully populated NiA news resource diff --git a/app/src/main/java/com/google/samples/apps/nowinandroid/data/model/NewsResourceType.kt b/core-model/src/main/java/com/google/samples/apps/nowinandroid/core/model/data/NewsResourceType.kt similarity index 96% rename from app/src/main/java/com/google/samples/apps/nowinandroid/data/model/NewsResourceType.kt rename to core-model/src/main/java/com/google/samples/apps/nowinandroid/core/model/data/NewsResourceType.kt index f4efd2e74..ea839982d 100644 --- a/app/src/main/java/com/google/samples/apps/nowinandroid/data/model/NewsResourceType.kt +++ b/core-model/src/main/java/com/google/samples/apps/nowinandroid/core/model/data/NewsResourceType.kt @@ -14,7 +14,7 @@ * limitations under the License. */ -package com.google.samples.apps.nowinandroid.data.model +package com.google.samples.apps.nowinandroid.core.model.data /** * Type for [NewsResource] diff --git a/app/src/main/java/com/google/samples/apps/nowinandroid/data/model/Topic.kt b/core-model/src/main/java/com/google/samples/apps/nowinandroid/core/model/data/Topic.kt similarity index 92% rename from app/src/main/java/com/google/samples/apps/nowinandroid/data/model/Topic.kt rename to core-model/src/main/java/com/google/samples/apps/nowinandroid/core/model/data/Topic.kt index 4b1513b1b..68757c32c 100644 --- a/app/src/main/java/com/google/samples/apps/nowinandroid/data/model/Topic.kt +++ b/core-model/src/main/java/com/google/samples/apps/nowinandroid/core/model/data/Topic.kt @@ -14,7 +14,7 @@ * limitations under the License. */ -package com.google.samples.apps.nowinandroid.data.model +package com.google.samples.apps.nowinandroid.core.model.data /** * External data layer representation of a NiA Topic diff --git a/app/src/main/java/com/google/samples/apps/nowinandroid/data/local/entities/AuthorEntity.kt b/core-model/src/main/java/com/google/samples/apps/nowinandroid/core/model/entities/AuthorEntity.kt similarity index 94% rename from app/src/main/java/com/google/samples/apps/nowinandroid/data/local/entities/AuthorEntity.kt rename to core-model/src/main/java/com/google/samples/apps/nowinandroid/core/model/entities/AuthorEntity.kt index f39e1c968..eba77d4f8 100644 --- a/app/src/main/java/com/google/samples/apps/nowinandroid/data/local/entities/AuthorEntity.kt +++ b/core-model/src/main/java/com/google/samples/apps/nowinandroid/core/model/entities/AuthorEntity.kt @@ -14,7 +14,7 @@ * limitations under the License. */ -package com.google.samples.apps.nowinandroid.data.local.entities +package com.google.samples.apps.nowinandroid.core.model.entities import androidx.room.ColumnInfo import androidx.room.Entity diff --git a/app/src/main/java/com/google/samples/apps/nowinandroid/data/local/entities/EpisodeAuthorCrossRef.kt b/core-model/src/main/java/com/google/samples/apps/nowinandroid/core/model/entities/EpisodeAuthorCrossRef.kt similarity index 95% rename from app/src/main/java/com/google/samples/apps/nowinandroid/data/local/entities/EpisodeAuthorCrossRef.kt rename to core-model/src/main/java/com/google/samples/apps/nowinandroid/core/model/entities/EpisodeAuthorCrossRef.kt index 599f60215..edcd0fe2e 100644 --- a/app/src/main/java/com/google/samples/apps/nowinandroid/data/local/entities/EpisodeAuthorCrossRef.kt +++ b/core-model/src/main/java/com/google/samples/apps/nowinandroid/core/model/entities/EpisodeAuthorCrossRef.kt @@ -14,7 +14,7 @@ * limitations under the License. */ -package com.google.samples.apps.nowinandroid.data.local.entities +package com.google.samples.apps.nowinandroid.core.model.entities import androidx.room.ColumnInfo import androidx.room.Entity diff --git a/app/src/main/java/com/google/samples/apps/nowinandroid/data/local/entities/EpisodeEntity.kt b/core-model/src/main/java/com/google/samples/apps/nowinandroid/core/model/entities/EpisodeEntity.kt similarity index 94% rename from app/src/main/java/com/google/samples/apps/nowinandroid/data/local/entities/EpisodeEntity.kt rename to core-model/src/main/java/com/google/samples/apps/nowinandroid/core/model/entities/EpisodeEntity.kt index a657020aa..be9a9935c 100644 --- a/app/src/main/java/com/google/samples/apps/nowinandroid/data/local/entities/EpisodeEntity.kt +++ b/core-model/src/main/java/com/google/samples/apps/nowinandroid/core/model/entities/EpisodeEntity.kt @@ -14,7 +14,7 @@ * limitations under the License. */ -package com.google.samples.apps.nowinandroid.data.local.entities +package com.google.samples.apps.nowinandroid.core.model.entities import androidx.room.ColumnInfo import androidx.room.Entity diff --git a/app/src/main/java/com/google/samples/apps/nowinandroid/data/local/entities/NewsResourceAuthorCrossRef.kt b/core-model/src/main/java/com/google/samples/apps/nowinandroid/core/model/entities/NewsResourceAuthorCrossRef.kt similarity index 95% rename from app/src/main/java/com/google/samples/apps/nowinandroid/data/local/entities/NewsResourceAuthorCrossRef.kt rename to core-model/src/main/java/com/google/samples/apps/nowinandroid/core/model/entities/NewsResourceAuthorCrossRef.kt index 444424fc9..ee3d4bc3c 100644 --- a/app/src/main/java/com/google/samples/apps/nowinandroid/data/local/entities/NewsResourceAuthorCrossRef.kt +++ b/core-model/src/main/java/com/google/samples/apps/nowinandroid/core/model/entities/NewsResourceAuthorCrossRef.kt @@ -14,7 +14,7 @@ * limitations under the License. */ -package com.google.samples.apps.nowinandroid.data.local.entities +package com.google.samples.apps.nowinandroid.core.model.entities import androidx.room.ColumnInfo import androidx.room.Entity diff --git a/app/src/main/java/com/google/samples/apps/nowinandroid/data/local/entities/NewsResourceEntity.kt b/core-model/src/main/java/com/google/samples/apps/nowinandroid/core/model/entities/NewsResourceEntity.kt similarity index 95% rename from app/src/main/java/com/google/samples/apps/nowinandroid/data/local/entities/NewsResourceEntity.kt rename to core-model/src/main/java/com/google/samples/apps/nowinandroid/core/model/entities/NewsResourceEntity.kt index 1da247618..80375d539 100644 --- a/app/src/main/java/com/google/samples/apps/nowinandroid/data/local/entities/NewsResourceEntity.kt +++ b/core-model/src/main/java/com/google/samples/apps/nowinandroid/core/model/entities/NewsResourceEntity.kt @@ -14,7 +14,7 @@ * limitations under the License. */ -package com.google.samples.apps.nowinandroid.data.local.entities +package com.google.samples.apps.nowinandroid.core.model.entities import androidx.room.ColumnInfo import androidx.room.Entity diff --git a/app/src/main/java/com/google/samples/apps/nowinandroid/data/local/entities/NewsResourceTopicCrossRef.kt b/core-model/src/main/java/com/google/samples/apps/nowinandroid/core/model/entities/NewsResourceTopicCrossRef.kt similarity index 95% rename from app/src/main/java/com/google/samples/apps/nowinandroid/data/local/entities/NewsResourceTopicCrossRef.kt rename to core-model/src/main/java/com/google/samples/apps/nowinandroid/core/model/entities/NewsResourceTopicCrossRef.kt index d2d7f3cb5..4629707a3 100644 --- a/app/src/main/java/com/google/samples/apps/nowinandroid/data/local/entities/NewsResourceTopicCrossRef.kt +++ b/core-model/src/main/java/com/google/samples/apps/nowinandroid/core/model/entities/NewsResourceTopicCrossRef.kt @@ -14,7 +14,7 @@ * limitations under the License. */ -package com.google.samples.apps.nowinandroid.data.local.entities +package com.google.samples.apps.nowinandroid.core.model.entities import androidx.room.ColumnInfo import androidx.room.Entity diff --git a/app/src/main/java/com/google/samples/apps/nowinandroid/data/local/entities/TopicEntity.kt b/core-model/src/main/java/com/google/samples/apps/nowinandroid/core/model/entities/TopicEntity.kt similarity index 94% rename from app/src/main/java/com/google/samples/apps/nowinandroid/data/local/entities/TopicEntity.kt rename to core-model/src/main/java/com/google/samples/apps/nowinandroid/core/model/entities/TopicEntity.kt index 6829acfc4..6cb2553c8 100644 --- a/app/src/main/java/com/google/samples/apps/nowinandroid/data/local/entities/TopicEntity.kt +++ b/core-model/src/main/java/com/google/samples/apps/nowinandroid/core/model/entities/TopicEntity.kt @@ -14,7 +14,7 @@ * limitations under the License. */ -package com.google.samples.apps.nowinandroid.data.local.entities +package com.google.samples.apps.nowinandroid.core.model.entities import androidx.room.Entity import androidx.room.Index diff --git a/app/src/main/java/com/google/samples/apps/nowinandroid/data/network/utilities/InstantSerializer.kt b/core-model/src/main/java/com/google/samples/apps/nowinandroid/core/model/network/InstantSerializer.kt similarity index 95% rename from app/src/main/java/com/google/samples/apps/nowinandroid/data/network/utilities/InstantSerializer.kt rename to core-model/src/main/java/com/google/samples/apps/nowinandroid/core/model/network/InstantSerializer.kt index e3f51496f..4ccaebb7b 100644 --- a/app/src/main/java/com/google/samples/apps/nowinandroid/data/network/utilities/InstantSerializer.kt +++ b/core-model/src/main/java/com/google/samples/apps/nowinandroid/core/model/network/InstantSerializer.kt @@ -14,7 +14,7 @@ * limitations under the License. */ -package com.google.samples.apps.nowinandroid.data.network.utilities +package com.google.samples.apps.nowinandroid.core.model.network import kotlinx.datetime.Instant import kotlinx.datetime.toInstant diff --git a/app/src/main/java/com/google/samples/apps/nowinandroid/data/network/NetworkAuthor.kt b/core-model/src/main/java/com/google/samples/apps/nowinandroid/core/model/network/NetworkAuthor.kt similarity index 87% rename from app/src/main/java/com/google/samples/apps/nowinandroid/data/network/NetworkAuthor.kt rename to core-model/src/main/java/com/google/samples/apps/nowinandroid/core/model/network/NetworkAuthor.kt index 0138ef89c..b31057e0a 100644 --- a/app/src/main/java/com/google/samples/apps/nowinandroid/data/network/NetworkAuthor.kt +++ b/core-model/src/main/java/com/google/samples/apps/nowinandroid/core/model/network/NetworkAuthor.kt @@ -14,9 +14,9 @@ * limitations under the License. */ -package com.google.samples.apps.nowinandroid.data.network +package com.google.samples.apps.nowinandroid.core.model.network -import com.google.samples.apps.nowinandroid.data.local.entities.AuthorEntity +import com.google.samples.apps.nowinandroid.core.model.entities.AuthorEntity import kotlinx.serialization.Serializable /** diff --git a/app/src/main/java/com/google/samples/apps/nowinandroid/data/network/NetworkEpisode.kt b/core-model/src/main/java/com/google/samples/apps/nowinandroid/core/model/network/NetworkEpisode.kt similarity index 90% rename from app/src/main/java/com/google/samples/apps/nowinandroid/data/network/NetworkEpisode.kt rename to core-model/src/main/java/com/google/samples/apps/nowinandroid/core/model/network/NetworkEpisode.kt index b5007ce72..b36000904 100644 --- a/app/src/main/java/com/google/samples/apps/nowinandroid/data/network/NetworkEpisode.kt +++ b/core-model/src/main/java/com/google/samples/apps/nowinandroid/core/model/network/NetworkEpisode.kt @@ -14,11 +14,10 @@ * limitations under the License. */ -package com.google.samples.apps.nowinandroid.data.network +package com.google.samples.apps.nowinandroid.core.model.network import androidx.room.PrimaryKey -import com.google.samples.apps.nowinandroid.data.local.entities.EpisodeEntity -import com.google.samples.apps.nowinandroid.data.network.utilities.InstantSerializer +import com.google.samples.apps.nowinandroid.core.model.entities.EpisodeEntity import kotlinx.datetime.Instant import kotlinx.serialization.Serializable diff --git a/app/src/main/java/com/google/samples/apps/nowinandroid/data/network/NetworkNewsResource.kt b/core-model/src/main/java/com/google/samples/apps/nowinandroid/core/model/network/NetworkNewsResource.kt similarity index 90% rename from app/src/main/java/com/google/samples/apps/nowinandroid/data/network/NetworkNewsResource.kt rename to core-model/src/main/java/com/google/samples/apps/nowinandroid/core/model/network/NetworkNewsResource.kt index f1cb9762b..97248dcd1 100644 --- a/app/src/main/java/com/google/samples/apps/nowinandroid/data/network/NetworkNewsResource.kt +++ b/core-model/src/main/java/com/google/samples/apps/nowinandroid/core/model/network/NetworkNewsResource.kt @@ -14,10 +14,9 @@ * limitations under the License. */ -package com.google.samples.apps.nowinandroid.data.network +package com.google.samples.apps.nowinandroid.core.model.network -import com.google.samples.apps.nowinandroid.data.local.entities.NewsResourceEntity -import com.google.samples.apps.nowinandroid.data.network.utilities.InstantSerializer +import com.google.samples.apps.nowinandroid.core.model.entities.NewsResourceEntity import kotlinx.datetime.Instant import kotlinx.serialization.Serializable diff --git a/app/src/main/java/com/google/samples/apps/nowinandroid/data/network/NetworkTopic.kt b/core-model/src/main/java/com/google/samples/apps/nowinandroid/core/model/network/NetworkTopic.kt similarity index 88% rename from app/src/main/java/com/google/samples/apps/nowinandroid/data/network/NetworkTopic.kt rename to core-model/src/main/java/com/google/samples/apps/nowinandroid/core/model/network/NetworkTopic.kt index 3ee55b7ce..ce6221c06 100644 --- a/app/src/main/java/com/google/samples/apps/nowinandroid/data/network/NetworkTopic.kt +++ b/core-model/src/main/java/com/google/samples/apps/nowinandroid/core/model/network/NetworkTopic.kt @@ -14,9 +14,9 @@ * limitations under the License. */ -package com.google.samples.apps.nowinandroid.data.network +package com.google.samples.apps.nowinandroid.core.model.network -import com.google.samples.apps.nowinandroid.data.local.entities.TopicEntity +import com.google.samples.apps.nowinandroid.core.model.entities.TopicEntity import kotlinx.serialization.Serializable /** diff --git a/app/src/test/java/com/google/samples/apps/nowinandroid/data/network/NetworkEntityKtTest.kt b/core-model/src/test/java/com/google/samples/apps/nowinandroid/core/model/NetworkEntityKtTest.kt similarity index 86% rename from app/src/test/java/com/google/samples/apps/nowinandroid/data/network/NetworkEntityKtTest.kt rename to core-model/src/test/java/com/google/samples/apps/nowinandroid/core/model/NetworkEntityKtTest.kt index 15ac84c0f..e62ff7c3c 100644 --- a/app/src/test/java/com/google/samples/apps/nowinandroid/data/network/NetworkEntityKtTest.kt +++ b/core-model/src/test/java/com/google/samples/apps/nowinandroid/core/model/NetworkEntityKtTest.kt @@ -14,9 +14,16 @@ * limitations under the License. */ -package com.google.samples.apps.nowinandroid.data.network - -import com.google.samples.apps.nowinandroid.data.model.NewsResourceType +package com.google.samples.apps.nowinandroid.core.model + +import com.google.samples.apps.nowinandroid.core.model.data.NewsResourceType +import com.google.samples.apps.nowinandroid.core.model.network.NetworkAuthor +import com.google.samples.apps.nowinandroid.core.model.network.NetworkEpisode +import com.google.samples.apps.nowinandroid.core.model.network.NetworkEpisodeExpanded +import com.google.samples.apps.nowinandroid.core.model.network.NetworkNewsResource +import com.google.samples.apps.nowinandroid.core.model.network.NetworkNewsResourceExpanded +import com.google.samples.apps.nowinandroid.core.model.network.NetworkTopic +import com.google.samples.apps.nowinandroid.core.model.network.asEntity import kotlinx.datetime.Instant import org.junit.Assert.assertEquals import org.junit.Test diff --git a/core-network/.gitignore b/core-network/.gitignore new file mode 100644 index 000000000..42afabfd2 --- /dev/null +++ b/core-network/.gitignore @@ -0,0 +1 @@ +/build \ No newline at end of file diff --git a/core-network/build.gradle b/core-network/build.gradle new file mode 100644 index 000000000..3f40d9dd4 --- /dev/null +++ b/core-network/build.gradle @@ -0,0 +1,51 @@ +/* + * Copyright 2022 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 + * + * https://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 { + id 'com.android.library' + id 'kotlin-android' + id 'kotlin-kapt' + id 'kotlinx-serialization' + id 'dagger.hilt.android.plugin' +} + +android { + compileSdk buildConfig.compileSdk + + defaultConfig { + minSdk buildConfig.minSdk + targetSdk buildConfig.targetSdk + } + compileOptions { + sourceCompatibility JavaVersion.VERSION_1_8 + targetCompatibility JavaVersion.VERSION_1_8 + } + kotlinOptions { + jvmTarget = '1.8' + } +} + +dependencies { + implementation project(':core-model') + + testImplementation project(':core-testing') + + implementation libs.kotlinx.coroutines.android + implementation libs.kotlinx.serialization.json + implementation libs.kotlinx.datetime + + implementation libs.hilt.android + kapt libs.hilt.compiler +} \ No newline at end of file diff --git a/core-network/src/main/AndroidManifest.xml b/core-network/src/main/AndroidManifest.xml new file mode 100644 index 000000000..d9460a3de --- /dev/null +++ b/core-network/src/main/AndroidManifest.xml @@ -0,0 +1,5 @@ + + + + \ No newline at end of file diff --git a/app/src/main/java/com/google/samples/apps/nowinandroid/data/network/NiANetwork.kt b/core-network/src/main/java/com/google/samples/apps/nowinandroid/core/network/NiANetwork.kt similarity index 79% rename from app/src/main/java/com/google/samples/apps/nowinandroid/data/network/NiANetwork.kt rename to core-network/src/main/java/com/google/samples/apps/nowinandroid/core/network/NiANetwork.kt index 227c69a5d..e8e4949c5 100644 --- a/app/src/main/java/com/google/samples/apps/nowinandroid/data/network/NiANetwork.kt +++ b/core-network/src/main/java/com/google/samples/apps/nowinandroid/core/network/NiANetwork.kt @@ -14,7 +14,10 @@ * limitations under the License. */ -package com.google.samples.apps.nowinandroid.data.network +package com.google.samples.apps.nowinandroid.core.network + +import com.google.samples.apps.nowinandroid.core.model.network.NetworkNewsResource +import com.google.samples.apps.nowinandroid.core.model.network.NetworkTopic /** * Interface representing network calls to the NIA backend diff --git a/app/src/main/java/com/google/samples/apps/nowinandroid/di/NiaDispatchers.kt b/core-network/src/main/java/com/google/samples/apps/nowinandroid/core/network/NiaDispatchers.kt similarity index 95% rename from app/src/main/java/com/google/samples/apps/nowinandroid/di/NiaDispatchers.kt rename to core-network/src/main/java/com/google/samples/apps/nowinandroid/core/network/NiaDispatchers.kt index 7ca74b643..b6501ed70 100644 --- a/app/src/main/java/com/google/samples/apps/nowinandroid/di/NiaDispatchers.kt +++ b/core-network/src/main/java/com/google/samples/apps/nowinandroid/core/network/NiaDispatchers.kt @@ -14,7 +14,7 @@ * limitations under the License. */ -package com.google.samples.apps.nowinandroid.di +package com.google.samples.apps.nowinandroid.core.network import javax.inject.Inject import kotlinx.coroutines.CoroutineDispatcher diff --git a/core-network/src/main/java/com/google/samples/apps/nowinandroid/core/network/di/NetworkModule.kt b/core-network/src/main/java/com/google/samples/apps/nowinandroid/core/network/di/NetworkModule.kt new file mode 100644 index 000000000..3bae6b0a2 --- /dev/null +++ b/core-network/src/main/java/com/google/samples/apps/nowinandroid/core/network/di/NetworkModule.kt @@ -0,0 +1,50 @@ +/* + * Copyright 2022 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 + * + * https://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.samples.apps.nowinandroid.core.network.di + +import com.google.samples.apps.nowinandroid.core.network.DefaultNiaDispatchers +import com.google.samples.apps.nowinandroid.core.network.NiANetwork +import com.google.samples.apps.nowinandroid.core.network.NiaDispatchers +import com.google.samples.apps.nowinandroid.core.network.fake.FakeNiANetwork +import dagger.Binds +import dagger.Module +import dagger.Provides +import dagger.hilt.InstallIn +import dagger.hilt.components.SingletonComponent +import javax.inject.Singleton +import kotlinx.serialization.json.Json + +@Module +@InstallIn(SingletonComponent::class) +interface NetworkModule { + + @Binds + fun bindsNiANetwork( + fakeNiANetwork: FakeNiANetwork + ): NiANetwork + + @Binds + fun bindsNiaDispatchers(defaultNiaDispatchers: DefaultNiaDispatchers): NiaDispatchers + + companion object { + @Provides + @Singleton + fun providesNetworkJson(): Json = Json { + ignoreUnknownKeys = true + } + } +} diff --git a/app/src/main/java/com/google/samples/apps/nowinandroid/data/fake/FakeData.kt b/core-network/src/main/java/com/google/samples/apps/nowinandroid/core/network/fake/FakeData.kt similarity index 99% rename from app/src/main/java/com/google/samples/apps/nowinandroid/data/fake/FakeData.kt rename to core-network/src/main/java/com/google/samples/apps/nowinandroid/core/network/fake/FakeData.kt index 1073ce6e8..475d70715 100644 --- a/app/src/main/java/com/google/samples/apps/nowinandroid/data/fake/FakeData.kt +++ b/core-network/src/main/java/com/google/samples/apps/nowinandroid/core/network/fake/FakeData.kt @@ -14,10 +14,10 @@ * limitations under the License. */ -package com.google.samples.apps.nowinandroid.data.fake +package com.google.samples.apps.nowinandroid.core.network.fake -import com.google.samples.apps.nowinandroid.data.network.NetworkNewsResource -import com.google.samples.apps.nowinandroid.data.network.NetworkTopic +import com.google.samples.apps.nowinandroid.core.model.network.NetworkTopic +import com.google.samples.apps.nowinandroid.core.model.network.NetworkNewsResource import kotlinx.datetime.LocalDateTime import kotlinx.datetime.TimeZone import kotlinx.datetime.toInstant diff --git a/app/src/main/java/com/google/samples/apps/nowinandroid/data/fake/FakeNiANetwork.kt b/core-network/src/main/java/com/google/samples/apps/nowinandroid/core/network/fake/FakeNiANetwork.kt similarity index 81% rename from app/src/main/java/com/google/samples/apps/nowinandroid/data/fake/FakeNiANetwork.kt rename to core-network/src/main/java/com/google/samples/apps/nowinandroid/core/network/fake/FakeNiANetwork.kt index 54d025e07..ff6957e07 100644 --- a/app/src/main/java/com/google/samples/apps/nowinandroid/data/fake/FakeNiANetwork.kt +++ b/core-network/src/main/java/com/google/samples/apps/nowinandroid/core/network/fake/FakeNiANetwork.kt @@ -14,12 +14,12 @@ * limitations under the License. */ -package com.google.samples.apps.nowinandroid.data.fake +package com.google.samples.apps.nowinandroid.core.network.fake -import com.google.samples.apps.nowinandroid.data.network.NetworkNewsResource -import com.google.samples.apps.nowinandroid.data.network.NetworkTopic -import com.google.samples.apps.nowinandroid.data.network.NiANetwork -import com.google.samples.apps.nowinandroid.di.NiaDispatchers +import com.google.samples.apps.nowinandroid.core.model.network.NetworkNewsResource +import com.google.samples.apps.nowinandroid.core.model.network.NetworkTopic +import com.google.samples.apps.nowinandroid.core.network.NiANetwork +import com.google.samples.apps.nowinandroid.core.network.NiaDispatchers import javax.inject.Inject import kotlinx.coroutines.withContext import kotlinx.serialization.Serializable diff --git a/app/src/test/java/com/google/samples/apps/nowinandroid/data/fake/FakeNiANetworkTest.kt b/core-network/src/test/java/com/google/samples/apps/nowinandroid/core/network/fake/FakeNiANetworkTest.kt similarity index 86% rename from app/src/test/java/com/google/samples/apps/nowinandroid/data/fake/FakeNiANetworkTest.kt rename to core-network/src/test/java/com/google/samples/apps/nowinandroid/core/network/fake/FakeNiANetworkTest.kt index 464e1f972..37a6a8f52 100644 --- a/app/src/test/java/com/google/samples/apps/nowinandroid/data/fake/FakeNiANetworkTest.kt +++ b/core-network/src/test/java/com/google/samples/apps/nowinandroid/core/network/fake/FakeNiANetworkTest.kt @@ -14,9 +14,9 @@ * limitations under the License. */ -package com.google.samples.apps.nowinandroid.data.fake +package com.google.samples.apps.nowinandroid.core.network.fake -import com.google.samples.apps.nowinandroid.di.DefaultNiaDispatchers +import com.google.samples.apps.nowinandroid.core.network.DefaultNiaDispatchers import kotlinx.coroutines.test.runTest import kotlinx.serialization.json.Json import org.junit.Assert.assertEquals @@ -29,7 +29,7 @@ class FakeNiANetworkTest { @Before fun setUp() { - subject = FakeNiANetwork( + subject = com.google.samples.apps.nowinandroid.core.network.fake.FakeNiANetwork( // TODO: Create test-specific NiaDispatchers dispatchers = DefaultNiaDispatchers(), networkJson = Json { ignoreUnknownKeys = true } diff --git a/core-testing/.gitignore b/core-testing/.gitignore new file mode 100644 index 000000000..42afabfd2 --- /dev/null +++ b/core-testing/.gitignore @@ -0,0 +1 @@ +/build \ No newline at end of file diff --git a/core-testing/build.gradle b/core-testing/build.gradle new file mode 100644 index 000000000..f5a6da468 --- /dev/null +++ b/core-testing/build.gradle @@ -0,0 +1,61 @@ +/* + * Copyright 2022 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 + * + * https://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 { + id 'com.android.library' + id 'kotlin-android' +} + +android { + compileSdk buildConfig.compileSdk + + defaultConfig { + minSdk buildConfig.minSdk + targetSdk buildConfig.targetSdk + } + compileOptions { + sourceCompatibility JavaVersion.VERSION_1_8 + targetCompatibility JavaVersion.VERSION_1_8 + } + kotlinOptions { + jvmTarget = '1.8' + } +} + +dependencies { + implementation project(':core-domain') + implementation project(':core-model') + + api libs.junit4 + api libs.mockk + api libs.androidx.test.core + api libs.kotlinx.coroutines.test + api libs.turbine + + api libs.androidx.test.espresso.core + api libs.androidx.test.runner + api libs.androidx.test.rules + api libs.androidx.compose.ui.test + api libs.hilt.android.testing + + debugApi libs.androidx.compose.ui.testManifest + + configurations.configureEach { + resolutionStrategy { + // Temporary workaround for https://issuetracker.google.com/174733673 + force 'org.objenesis:objenesis:2.6' + } + } +} \ No newline at end of file diff --git a/core-testing/src/main/AndroidManifest.xml b/core-testing/src/main/AndroidManifest.xml new file mode 100644 index 000000000..2a4ffc1f0 --- /dev/null +++ b/core-testing/src/main/AndroidManifest.xml @@ -0,0 +1,5 @@ + + + + \ No newline at end of file diff --git a/app/src/androidTest/java/com/google/samples/apps/nowinandroid/NiaTestRunner.kt b/core-testing/src/main/java/com/google/samples/apps/nowinandroid/core/testing/NiaTestRunner.kt similarity index 95% rename from app/src/androidTest/java/com/google/samples/apps/nowinandroid/NiaTestRunner.kt rename to core-testing/src/main/java/com/google/samples/apps/nowinandroid/core/testing/NiaTestRunner.kt index 6dacb3c5c..30254a617 100644 --- a/app/src/androidTest/java/com/google/samples/apps/nowinandroid/NiaTestRunner.kt +++ b/core-testing/src/main/java/com/google/samples/apps/nowinandroid/core/testing/NiaTestRunner.kt @@ -14,7 +14,7 @@ * limitations under the License. */ -package com.google.samples.apps.nowinandroid +package com.google.samples.apps.nowinandroid.core.testing import android.app.Application import android.content.Context diff --git a/app/src/test/java/com/google/samples/apps/nowinandroid/testutil/TestNewsRepository.kt b/core-testing/src/main/java/com/google/samples/apps/nowinandroid/core/testing/repository/TestNewsRepository.kt similarity index 88% rename from app/src/test/java/com/google/samples/apps/nowinandroid/testutil/TestNewsRepository.kt rename to core-testing/src/main/java/com/google/samples/apps/nowinandroid/core/testing/repository/TestNewsRepository.kt index c47db0d91..901e59c72 100644 --- a/app/src/test/java/com/google/samples/apps/nowinandroid/testutil/TestNewsRepository.kt +++ b/core-testing/src/main/java/com/google/samples/apps/nowinandroid/core/testing/repository/TestNewsRepository.kt @@ -14,10 +14,10 @@ * limitations under the License. */ -package com.google.samples.apps.nowinandroid.testutil +package com.google.samples.apps.nowinandroid.core.testing.repository -import com.google.samples.apps.nowinandroid.data.model.NewsResource -import com.google.samples.apps.nowinandroid.data.repository.NewsRepository +import com.google.samples.apps.nowinandroid.core.domain.repository.NewsRepository +import com.google.samples.apps.nowinandroid.core.model.data.NewsResource import kotlinx.coroutines.channels.BufferOverflow import kotlinx.coroutines.flow.Flow import kotlinx.coroutines.flow.MutableSharedFlow diff --git a/app/src/test/java/com/google/samples/apps/nowinandroid/testutil/TestTopicsRepository.kt b/core-testing/src/main/java/com/google/samples/apps/nowinandroid/core/testing/repository/TestTopicsRepository.kt similarity index 91% rename from app/src/test/java/com/google/samples/apps/nowinandroid/testutil/TestTopicsRepository.kt rename to core-testing/src/main/java/com/google/samples/apps/nowinandroid/core/testing/repository/TestTopicsRepository.kt index 1f82b790c..9b60b2600 100644 --- a/app/src/test/java/com/google/samples/apps/nowinandroid/testutil/TestTopicsRepository.kt +++ b/core-testing/src/main/java/com/google/samples/apps/nowinandroid/core/testing/repository/TestTopicsRepository.kt @@ -14,10 +14,10 @@ * limitations under the License. */ -package com.google.samples.apps.nowinandroid.testutil +package com.google.samples.apps.nowinandroid.core.testing.repository -import com.google.samples.apps.nowinandroid.data.model.Topic -import com.google.samples.apps.nowinandroid.data.repository.TopicsRepository +import com.google.samples.apps.nowinandroid.core.domain.repository.TopicsRepository +import com.google.samples.apps.nowinandroid.core.model.data.Topic import kotlinx.coroutines.channels.BufferOverflow import kotlinx.coroutines.flow.Flow import kotlinx.coroutines.flow.MutableSharedFlow diff --git a/app/src/test/java/com/google/samples/apps/nowinandroid/testutil/TestDispatcherRule.kt b/core-testing/src/main/java/com/google/samples/apps/nowinandroid/core/testing/util/TestDispatcherRule.kt similarity index 96% rename from app/src/test/java/com/google/samples/apps/nowinandroid/testutil/TestDispatcherRule.kt rename to core-testing/src/main/java/com/google/samples/apps/nowinandroid/core/testing/util/TestDispatcherRule.kt index f7baee782..789779716 100644 --- a/app/src/test/java/com/google/samples/apps/nowinandroid/testutil/TestDispatcherRule.kt +++ b/core-testing/src/main/java/com/google/samples/apps/nowinandroid/core/testing/util/TestDispatcherRule.kt @@ -14,7 +14,7 @@ * limitations under the License. */ -package com.google.samples.apps.nowinandroid.testutil +package com.google.samples.apps.nowinandroid.core.testing.util import kotlinx.coroutines.CoroutineDispatcher import kotlinx.coroutines.Dispatchers diff --git a/core-ui/.gitignore b/core-ui/.gitignore new file mode 100644 index 000000000..42afabfd2 --- /dev/null +++ b/core-ui/.gitignore @@ -0,0 +1 @@ +/build \ No newline at end of file diff --git a/core-ui/build.gradle b/core-ui/build.gradle new file mode 100644 index 000000000..4e40909e8 --- /dev/null +++ b/core-ui/build.gradle @@ -0,0 +1,59 @@ +/* + * Copyright 2022 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 + * + * https://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 { + id 'com.android.library' + id 'kotlin-android' +} + +android { + compileSdk buildConfig.compileSdk + + defaultConfig { + minSdk buildConfig.minSdk + targetSdk buildConfig.targetSdk + } + compileOptions { + sourceCompatibility JavaVersion.VERSION_1_8 + targetCompatibility JavaVersion.VERSION_1_8 + } + kotlinOptions { + jvmTarget = '1.8' + } + buildFeatures { + compose true + } + composeOptions { + kotlinCompilerExtensionVersion libs.versions.androidxCompose.get() + } +} + +dependencies { + implementation project(':core-model') + + implementation libs.androidx.core.ktx + implementation libs.kotlinx.datetime + + api libs.androidx.compose.foundation.layout + // TODO (M3): Remove this dependency when all components are available + api libs.androidx.compose.material + api libs.androidx.compose.material.iconsExtended + api libs.androidx.compose.material3 + debugApi libs.androidx.compose.ui.tooling + api libs.androidx.compose.ui.tooling.preview + api libs.androidx.compose.ui.util + api libs.androidx.compose.runtime + api libs.androidx.compose.runtime.livedata +} \ No newline at end of file diff --git a/core-ui/src/main/AndroidManifest.xml b/core-ui/src/main/AndroidManifest.xml new file mode 100644 index 000000000..18d4170ba --- /dev/null +++ b/core-ui/src/main/AndroidManifest.xml @@ -0,0 +1,5 @@ + + + + \ No newline at end of file diff --git a/app/src/main/java/com/google/samples/apps/nowinandroid/ui/NewsResourceCard.kt b/core-ui/src/main/java/com/google/samples/apps/nowinandroid/core/ui/NewsResourceCard.kt similarity index 72% rename from app/src/main/java/com/google/samples/apps/nowinandroid/ui/NewsResourceCard.kt rename to core-ui/src/main/java/com/google/samples/apps/nowinandroid/core/ui/NewsResourceCard.kt index aff6a0db9..a8429a5ba 100644 --- a/app/src/main/java/com/google/samples/apps/nowinandroid/ui/NewsResourceCard.kt +++ b/core-ui/src/main/java/com/google/samples/apps/nowinandroid/core/ui/NewsResourceCard.kt @@ -14,7 +14,7 @@ * limitations under the License. */ -package com.google.samples.apps.nowinandroid.ui +package com.google.samples.apps.nowinandroid.core.ui import androidx.compose.foundation.layout.Column import androidx.compose.foundation.layout.Row @@ -36,17 +36,14 @@ import androidx.compose.ui.res.stringResource import androidx.compose.ui.semantics.onClick import androidx.compose.ui.semantics.semantics import androidx.compose.ui.tooling.preview.Preview -import androidx.compose.ui.tooling.preview.PreviewParameter -import androidx.compose.ui.tooling.preview.PreviewParameterProvider import androidx.compose.ui.unit.dp -import com.google.samples.apps.nowinandroid.R -import com.google.samples.apps.nowinandroid.data.fake.FakeDataSource -import com.google.samples.apps.nowinandroid.data.model.NewsResource -import com.google.samples.apps.nowinandroid.data.network.NetworkAuthor -import com.google.samples.apps.nowinandroid.data.network.NetworkEpisode -import com.google.samples.apps.nowinandroid.data.network.NetworkTopic -import com.google.samples.apps.nowinandroid.data.network.asEntity -import com.google.samples.apps.nowinandroid.ui.theme.NiaTheme +import com.google.samples.apps.nowinandroid.core.model.data.NewsResource +import com.google.samples.apps.nowinandroid.core.model.entities.AuthorEntity +import com.google.samples.apps.nowinandroid.core.model.entities.EpisodeEntity +import com.google.samples.apps.nowinandroid.core.model.entities.NewsResourceEntity +import com.google.samples.apps.nowinandroid.core.model.entities.TopicEntity +import com.google.samples.apps.nowinandroid.core.ui.theme.NiaTheme +import kotlinx.datetime.Instant /** * [NewsResource] card used on the following screens: For You, Episodes, Saved @@ -166,10 +163,9 @@ fun BookmarkButtonBookmarkedPreview() { } } +@Preview("NewsResourceCardExpanded") @Composable -fun ExpandedNewsResourcePreview( - @PreviewParameter(NewsResourcePreviewParameterProvider::class) newsResource: NewsResource -) { +fun ExpandedNewsResourcePreview() { NiaTheme { Surface { NewsResourceCardExpanded(newsResource, true, {}) @@ -177,32 +173,36 @@ fun ExpandedNewsResourcePreview( } } -class NewsResourcePreviewParameterProvider : PreviewParameterProvider { - override val values = sequenceOf( - NewsResource( - FakeDataSource.sampleResource.asEntity(), - NetworkEpisode( - id = 1, - name = "Now in Android 40", - alternateVideo = null, - alternateAudio = null, - publishDate = FakeDataSource.sampleResource.publishDate - ).asEntity(), - listOf( - NetworkAuthor( - id = 1, - name = "Android", - imageUrl = "" - ) - .asEntity() - ), - listOf( - NetworkTopic( - id = 3, - name = "Performance", - description = "" - ).asEntity() - ) +private val newsResource = NewsResource( + NewsResourceEntity( + id = 1, + episodeId = 1, + title = "Title", + content = "Content", + url = "url", + publishDate = Instant.DISTANT_FUTURE, + type = "type", + ), + EpisodeEntity( + id = 1, + name = "Title", + publishDate = Instant.DISTANT_FUTURE, + alternateVideo = "alternateVideo", + alternateAudio = "alternateAudio", + ), + listOf( + AuthorEntity( + id = 1, + name = "Name", + imageUrl = "imageUrl" + ) + ), + listOf( + TopicEntity( + id = 1, + name = "Name", + description = "Description", + followed = false ) ) -} +) diff --git a/app/src/main/java/com/google/samples/apps/nowinandroid/ui/NiaScreens.kt b/core-ui/src/main/java/com/google/samples/apps/nowinandroid/core/ui/NiaScreens.kt similarity index 98% rename from app/src/main/java/com/google/samples/apps/nowinandroid/ui/NiaScreens.kt rename to core-ui/src/main/java/com/google/samples/apps/nowinandroid/core/ui/NiaScreens.kt index d71591396..938d4a6ea 100644 --- a/app/src/main/java/com/google/samples/apps/nowinandroid/ui/NiaScreens.kt +++ b/core-ui/src/main/java/com/google/samples/apps/nowinandroid/core/ui/NiaScreens.kt @@ -14,7 +14,7 @@ * limitations under the License. */ -package com.google.samples.apps.nowinandroid.ui +package com.google.samples.apps.nowinandroid.core.ui import androidx.annotation.StringRes import androidx.compose.foundation.layout.Arrangement diff --git a/app/src/main/java/com/google/samples/apps/nowinandroid/ui/theme/Color.kt b/core-ui/src/main/java/com/google/samples/apps/nowinandroid/core/ui/theme/Color.kt similarity index 93% rename from app/src/main/java/com/google/samples/apps/nowinandroid/ui/theme/Color.kt rename to core-ui/src/main/java/com/google/samples/apps/nowinandroid/core/ui/theme/Color.kt index a7b66fe87..f5e912a8c 100644 --- a/app/src/main/java/com/google/samples/apps/nowinandroid/ui/theme/Color.kt +++ b/core-ui/src/main/java/com/google/samples/apps/nowinandroid/core/ui/theme/Color.kt @@ -14,7 +14,7 @@ * limitations under the License. */ -package com.google.samples.apps.nowinandroid.ui.theme +package com.google.samples.apps.nowinandroid.core.ui.theme import androidx.compose.ui.graphics.Color diff --git a/app/src/main/java/com/google/samples/apps/nowinandroid/ui/theme/Theme.kt b/core-ui/src/main/java/com/google/samples/apps/nowinandroid/core/ui/theme/Theme.kt similarity index 96% rename from app/src/main/java/com/google/samples/apps/nowinandroid/ui/theme/Theme.kt rename to core-ui/src/main/java/com/google/samples/apps/nowinandroid/core/ui/theme/Theme.kt index a7dbd24f9..4854210a0 100644 --- a/app/src/main/java/com/google/samples/apps/nowinandroid/ui/theme/Theme.kt +++ b/core-ui/src/main/java/com/google/samples/apps/nowinandroid/core/ui/theme/Theme.kt @@ -14,7 +14,7 @@ * limitations under the License. */ -package com.google.samples.apps.nowinandroid.ui.theme +package com.google.samples.apps.nowinandroid.core.ui.theme import android.os.Build import androidx.compose.foundation.isSystemInDarkTheme diff --git a/app/src/main/java/com/google/samples/apps/nowinandroid/ui/theme/Type.kt b/core-ui/src/main/java/com/google/samples/apps/nowinandroid/core/ui/theme/Type.kt similarity index 92% rename from app/src/main/java/com/google/samples/apps/nowinandroid/ui/theme/Type.kt rename to core-ui/src/main/java/com/google/samples/apps/nowinandroid/core/ui/theme/Type.kt index d18304691..ad0ebb554 100644 --- a/app/src/main/java/com/google/samples/apps/nowinandroid/ui/theme/Type.kt +++ b/core-ui/src/main/java/com/google/samples/apps/nowinandroid/core/ui/theme/Type.kt @@ -14,7 +14,7 @@ * limitations under the License. */ -package com.google.samples.apps.nowinandroid.ui.theme +package com.google.samples.apps.nowinandroid.core.ui.theme import androidx.compose.material3.Typography diff --git a/core-ui/src/main/res/values/strings.xml b/core-ui/src/main/res/values/strings.xml new file mode 100644 index 000000000..ff7a987f7 --- /dev/null +++ b/core-ui/src/main/res/values/strings.xml @@ -0,0 +1,19 @@ + + + Bookmark + Unbookmark + diff --git a/feature-following/.gitignore b/feature-following/.gitignore new file mode 100644 index 000000000..42afabfd2 --- /dev/null +++ b/feature-following/.gitignore @@ -0,0 +1 @@ +/build \ No newline at end of file diff --git a/feature-following/build.gradle b/feature-following/build.gradle new file mode 100644 index 000000000..3e8d64cca --- /dev/null +++ b/feature-following/build.gradle @@ -0,0 +1,71 @@ +/* + * Copyright 2022 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 + * + * https://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 { + id 'com.android.library' + id 'kotlin-android' + id 'kotlin-kapt' + id 'dagger.hilt.android.plugin' +} + +android { + compileSdk buildConfig.compileSdk + + defaultConfig { + minSdk buildConfig.minSdk + targetSdk buildConfig.targetSdk + + testInstrumentationRunner "com.google.samples.apps.nowinandroid.core.testing.NiaTestRunner" + } + compileOptions { + sourceCompatibility JavaVersion.VERSION_1_8 + targetCompatibility JavaVersion.VERSION_1_8 + } + kotlinOptions { + jvmTarget = '1.8' + } + buildFeatures { + compose true + } + composeOptions { + kotlinCompilerExtensionVersion libs.versions.androidxCompose.get() + } +} + +dependencies { + implementation project(':core-model') + implementation project(':core-ui') + implementation project(':core-domain') + + testImplementation project(':core-testing') + androidTestImplementation project(':core-testing') + + implementation libs.kotlinx.coroutines.android + + implementation libs.androidx.hilt.navigation.compose + implementation libs.androidx.lifecycle.viewModelCompose + + implementation libs.hilt.android + kapt libs.hilt.compiler + + // androidx.test is forcing JUnit, 4.12. This forces it to use 4.13 + configurations.configureEach { + resolutionStrategy { + force libs.junit4 + // Temporary workaround for https://issuetracker.google.com/174733673 + force 'org.objenesis:objenesis:2.6' + } + } +} \ No newline at end of file diff --git a/app/src/androidTest/java/com/google/samples/apps/nowinandroid/ui/following/FollowingScreenTest.kt b/feature-following/src/androidTest/java/com/google/samples/apps/nowinandroid/following/FollowingScreenTest.kt similarity index 93% rename from app/src/androidTest/java/com/google/samples/apps/nowinandroid/ui/following/FollowingScreenTest.kt rename to feature-following/src/androidTest/java/com/google/samples/apps/nowinandroid/following/FollowingScreenTest.kt index 3dd780f90..3298aea15 100644 --- a/app/src/androidTest/java/com/google/samples/apps/nowinandroid/ui/following/FollowingScreenTest.kt +++ b/feature-following/src/androidTest/java/com/google/samples/apps/nowinandroid/following/FollowingScreenTest.kt @@ -14,7 +14,7 @@ * limitations under the License. */ -package com.google.samples.apps.nowinandroid.ui.following +package com.google.samples.apps.nowinandroid.following import androidx.activity.ComponentActivity import androidx.compose.ui.test.assertCountEquals @@ -24,8 +24,10 @@ import androidx.compose.ui.test.onAllNodesWithContentDescription import androidx.compose.ui.test.onAllNodesWithText import androidx.compose.ui.test.onNodeWithContentDescription import androidx.compose.ui.test.onNodeWithText -import com.google.samples.apps.nowinandroid.R -import com.google.samples.apps.nowinandroid.data.model.Topic +import com.google.samples.apps.nowinandroid.core.model.data.Topic +import com.google.samples.apps.nowinandroid.feature.following.FollowingScreen +import com.google.samples.apps.nowinandroid.feature.following.FollowingUiState +import com.google.samples.apps.nowinandroid.feature.following.R import org.junit.Before import org.junit.Rule import org.junit.Test diff --git a/feature-following/src/main/AndroidManifest.xml b/feature-following/src/main/AndroidManifest.xml new file mode 100644 index 000000000..c5a94ff36 --- /dev/null +++ b/feature-following/src/main/AndroidManifest.xml @@ -0,0 +1,5 @@ + + + + \ No newline at end of file diff --git a/app/src/main/java/com/google/samples/apps/nowinandroid/ui/following/FollowingScreen.kt b/feature-following/src/main/java/com/google/samples/apps/nowinandroid/feature/following/FollowingScreen.kt similarity index 95% rename from app/src/main/java/com/google/samples/apps/nowinandroid/ui/following/FollowingScreen.kt rename to feature-following/src/main/java/com/google/samples/apps/nowinandroid/feature/following/FollowingScreen.kt index 452b4aed4..9ebba9602 100644 --- a/app/src/main/java/com/google/samples/apps/nowinandroid/ui/following/FollowingScreen.kt +++ b/feature-following/src/main/java/com/google/samples/apps/nowinandroid/feature/following/FollowingScreen.kt @@ -14,7 +14,7 @@ * limitations under the License. */ -package com.google.samples.apps.nowinandroid.ui.following +package com.google.samples.apps.nowinandroid.feature.following import androidx.compose.foundation.background import androidx.compose.foundation.clickable @@ -45,11 +45,10 @@ import androidx.compose.ui.res.stringResource import androidx.compose.ui.tooling.preview.Preview import androidx.compose.ui.unit.dp import androidx.hilt.navigation.compose.hiltViewModel -import com.google.samples.apps.nowinandroid.R -import com.google.samples.apps.nowinandroid.data.model.Topic -import com.google.samples.apps.nowinandroid.ui.NiaLoadingIndicator -import com.google.samples.apps.nowinandroid.ui.NiaToolbar -import com.google.samples.apps.nowinandroid.ui.theme.NiaTheme +import com.google.samples.apps.nowinandroid.core.model.data.Topic +import com.google.samples.apps.nowinandroid.core.ui.NiaLoadingIndicator +import com.google.samples.apps.nowinandroid.core.ui.NiaToolbar +import com.google.samples.apps.nowinandroid.core.ui.theme.NiaTheme @Composable fun FollowingRoute( diff --git a/app/src/main/java/com/google/samples/apps/nowinandroid/ui/following/FollowingViewModel.kt b/feature-following/src/main/java/com/google/samples/apps/nowinandroid/feature/following/FollowingViewModel.kt similarity index 93% rename from app/src/main/java/com/google/samples/apps/nowinandroid/ui/following/FollowingViewModel.kt rename to feature-following/src/main/java/com/google/samples/apps/nowinandroid/feature/following/FollowingViewModel.kt index d0a8c8b42..61549fa27 100644 --- a/app/src/main/java/com/google/samples/apps/nowinandroid/ui/following/FollowingViewModel.kt +++ b/feature-following/src/main/java/com/google/samples/apps/nowinandroid/feature/following/FollowingViewModel.kt @@ -14,12 +14,12 @@ * limitations under the License. */ -package com.google.samples.apps.nowinandroid.ui.following +package com.google.samples.apps.nowinandroid.feature.following import androidx.lifecycle.ViewModel import androidx.lifecycle.viewModelScope -import com.google.samples.apps.nowinandroid.data.model.Topic -import com.google.samples.apps.nowinandroid.data.repository.TopicsRepository +import com.google.samples.apps.nowinandroid.core.domain.repository.TopicsRepository +import com.google.samples.apps.nowinandroid.core.model.data.Topic import dagger.hilt.android.lifecycle.HiltViewModel import javax.inject.Inject import kotlinx.coroutines.flow.Flow diff --git a/feature-following/src/main/res/values/strings.xml b/feature-following/src/main/res/values/strings.xml new file mode 100644 index 000000000..a0b96b605 --- /dev/null +++ b/feature-following/src/main/res/values/strings.xml @@ -0,0 +1,23 @@ + + + Following + Loading topics + "Error loading topics" + Topic icon + Follow Topic button + Unfollow Topic button + diff --git a/app/src/test/java/com/google/samples/apps/nowinandroid/ui/following/FollowingViewModelTest.kt b/feature-following/src/test/java/com/google/samples/apps/nowinandroid/following/FollowingViewModelTest.kt similarity index 89% rename from app/src/test/java/com/google/samples/apps/nowinandroid/ui/following/FollowingViewModelTest.kt rename to feature-following/src/test/java/com/google/samples/apps/nowinandroid/following/FollowingViewModelTest.kt index 76d6a586e..b5104d259 100644 --- a/app/src/test/java/com/google/samples/apps/nowinandroid/ui/following/FollowingViewModelTest.kt +++ b/feature-following/src/test/java/com/google/samples/apps/nowinandroid/following/FollowingViewModelTest.kt @@ -14,12 +14,14 @@ * limitations under the License. */ -package com.google.samples.apps.nowinandroid.ui.following +package com.google.samples.apps.nowinandroid.following import app.cash.turbine.test -import com.google.samples.apps.nowinandroid.data.model.Topic -import com.google.samples.apps.nowinandroid.testutil.TestDispatcherRule -import com.google.samples.apps.nowinandroid.testutil.TestTopicsRepository +import com.google.samples.apps.nowinandroid.core.model.data.Topic +import com.google.samples.apps.nowinandroid.core.testing.repository.TestTopicsRepository +import com.google.samples.apps.nowinandroid.core.testing.util.TestDispatcherRule +import com.google.samples.apps.nowinandroid.feature.following.FollowingUiState +import com.google.samples.apps.nowinandroid.feature.following.FollowingViewModel import kotlinx.coroutines.test.runTest import org.junit.Assert.assertEquals import org.junit.Before diff --git a/feature-foryou/.gitignore b/feature-foryou/.gitignore new file mode 100644 index 000000000..42afabfd2 --- /dev/null +++ b/feature-foryou/.gitignore @@ -0,0 +1 @@ +/build \ No newline at end of file diff --git a/feature-foryou/build.gradle b/feature-foryou/build.gradle new file mode 100644 index 000000000..c0cb5fff0 --- /dev/null +++ b/feature-foryou/build.gradle @@ -0,0 +1,73 @@ +/* + * Copyright 2022 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 + * + * https://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 { + id 'com.android.library' + id 'kotlin-android' + id 'kotlin-kapt' + id 'dagger.hilt.android.plugin' +} + +android { + compileSdk buildConfig.compileSdk + + defaultConfig { + minSdk buildConfig.minSdk + targetSdk buildConfig.targetSdk + + testInstrumentationRunner "com.google.samples.apps.nowinandroid.core.testing.NiaTestRunner" + } + compileOptions { + sourceCompatibility JavaVersion.VERSION_1_8 + targetCompatibility JavaVersion.VERSION_1_8 + } + kotlinOptions { + jvmTarget = '1.8' + } + buildFeatures { + compose true + } + composeOptions { + kotlinCompilerExtensionVersion libs.versions.androidxCompose.get() + } +} + +dependencies { + implementation project(':core-model') + implementation project(':core-ui') + implementation project(':core-domain') + + testImplementation project(':core-testing') + androidTestImplementation project(':core-testing') + + implementation libs.kotlinx.coroutines.android + + implementation libs.androidx.hilt.navigation.compose + implementation libs.androidx.lifecycle.viewModelCompose + + implementation libs.accompanist.flowlayout + + implementation libs.hilt.android + kapt libs.hilt.compiler + + // androidx.test is forcing JUnit, 4.12. This forces it to use 4.13 + configurations.configureEach { + resolutionStrategy { + force libs.junit4 + // Temporary workaround for https://issuetracker.google.com/174733673 + force 'org.objenesis:objenesis:2.6' + } + } +} \ No newline at end of file diff --git a/app/src/androidTest/java/com/google/samples/apps/nowinandroid/ui/foryou/ForYouScreenTest.kt b/feature-foryou/src/androidTest/java/com/google/samples/apps/nowinandroid/feature/foryou/ForYouScreenTest.kt similarity index 97% rename from app/src/androidTest/java/com/google/samples/apps/nowinandroid/ui/foryou/ForYouScreenTest.kt rename to feature-foryou/src/androidTest/java/com/google/samples/apps/nowinandroid/feature/foryou/ForYouScreenTest.kt index d39f48e68..7e7a88caa 100644 --- a/app/src/androidTest/java/com/google/samples/apps/nowinandroid/ui/foryou/ForYouScreenTest.kt +++ b/feature-foryou/src/androidTest/java/com/google/samples/apps/nowinandroid/feature/foryou/ForYouScreenTest.kt @@ -14,7 +14,7 @@ * limitations under the License. */ -package com.google.samples.apps.nowinandroid.ui.foryou +package com.google.samples.apps.nowinandroid.feature.foryou import androidx.activity.ComponentActivity import androidx.compose.ui.test.assertHasClickAction @@ -26,8 +26,7 @@ import androidx.compose.ui.test.assertIsOn import androidx.compose.ui.test.junit4.createAndroidComposeRule import androidx.compose.ui.test.onNodeWithContentDescription import androidx.compose.ui.test.onNodeWithText -import com.google.samples.apps.nowinandroid.R -import com.google.samples.apps.nowinandroid.data.model.Topic +import com.google.samples.apps.nowinandroid.core.model.data.Topic import org.junit.Rule import org.junit.Test diff --git a/feature-foryou/src/main/AndroidManifest.xml b/feature-foryou/src/main/AndroidManifest.xml new file mode 100644 index 000000000..b9c06cccd --- /dev/null +++ b/feature-foryou/src/main/AndroidManifest.xml @@ -0,0 +1,5 @@ + + + + \ No newline at end of file diff --git a/app/src/main/java/com/google/samples/apps/nowinandroid/ui/foryou/ForYouScreen.kt b/feature-foryou/src/main/java/com/google/samples/apps/nowinandroid/feature/foryou/ForYouScreen.kt similarity index 92% rename from app/src/main/java/com/google/samples/apps/nowinandroid/ui/foryou/ForYouScreen.kt rename to feature-foryou/src/main/java/com/google/samples/apps/nowinandroid/feature/foryou/ForYouScreen.kt index c74ba2c66..1648a6feb 100644 --- a/app/src/main/java/com/google/samples/apps/nowinandroid/ui/foryou/ForYouScreen.kt +++ b/feature-foryou/src/main/java/com/google/samples/apps/nowinandroid/feature/foryou/ForYouScreen.kt @@ -14,7 +14,7 @@ * limitations under the License. */ -package com.google.samples.apps.nowinandroid.ui.foryou +package com.google.samples.apps.nowinandroid.feature.foryou import androidx.compose.foundation.layout.Box import androidx.compose.foundation.layout.fillMaxSize @@ -22,7 +22,6 @@ import androidx.compose.foundation.layout.fillMaxWidth import androidx.compose.foundation.layout.padding import androidx.compose.foundation.lazy.LazyColumn import androidx.compose.foundation.lazy.LazyListScope -import androidx.compose.foundation.lazy.items import androidx.compose.foundation.selection.toggleable import androidx.compose.foundation.shape.RoundedCornerShape import androidx.compose.material3.Button @@ -40,10 +39,8 @@ import androidx.compose.ui.tooling.preview.Preview import androidx.compose.ui.unit.dp import androidx.hilt.navigation.compose.hiltViewModel import com.google.accompanist.flowlayout.FlowRow -import com.google.samples.apps.nowinandroid.R -import com.google.samples.apps.nowinandroid.data.model.NewsResource -import com.google.samples.apps.nowinandroid.data.model.Topic -import com.google.samples.apps.nowinandroid.ui.NiaLoadingIndicator +import com.google.samples.apps.nowinandroid.core.model.data.Topic +import com.google.samples.apps.nowinandroid.core.ui.NiaLoadingIndicator @Composable fun ForYouRoute( @@ -84,9 +81,9 @@ fun ForYouScreen( is ForYouFeedUiState.PopulatedFeed.FeedWithoutTopicSelection -> Unit } - items(uiState.feed) { _: NewsResource -> - // TODO: News item - } +// items(uiState.feed) { _: NewsResource -> +// // TODO: News item +// } } } } diff --git a/app/src/main/java/com/google/samples/apps/nowinandroid/ui/foryou/ForYouViewModel.kt b/feature-foryou/src/main/java/com/google/samples/apps/nowinandroid/feature/foryou/ForYouViewModel.kt similarity index 93% rename from app/src/main/java/com/google/samples/apps/nowinandroid/ui/foryou/ForYouViewModel.kt rename to feature-foryou/src/main/java/com/google/samples/apps/nowinandroid/feature/foryou/ForYouViewModel.kt index 49e88c47c..142d7a952 100644 --- a/app/src/main/java/com/google/samples/apps/nowinandroid/ui/foryou/ForYouViewModel.kt +++ b/feature-foryou/src/main/java/com/google/samples/apps/nowinandroid/feature/foryou/ForYouViewModel.kt @@ -14,7 +14,7 @@ * limitations under the License. */ -package com.google.samples.apps.nowinandroid.ui.foryou +package com.google.samples.apps.nowinandroid.feature.foryou import androidx.compose.runtime.mutableStateOf import androidx.compose.runtime.snapshotFlow @@ -22,11 +22,11 @@ import androidx.compose.runtime.snapshots.Snapshot.Companion.withMutableSnapshot import androidx.lifecycle.SavedStateHandle import androidx.lifecycle.ViewModel import androidx.lifecycle.viewModelScope -import com.google.samples.apps.nowinandroid.data.model.NewsResource -import com.google.samples.apps.nowinandroid.data.model.Topic -import com.google.samples.apps.nowinandroid.data.repository.NewsRepository -import com.google.samples.apps.nowinandroid.data.repository.TopicsRepository -import com.google.samples.apps.nowinandroid.ui.saveable +import com.google.samples.apps.nowinandroid.core.domain.repository.NewsRepository +import com.google.samples.apps.nowinandroid.core.domain.repository.TopicsRepository +import com.google.samples.apps.nowinandroid.core.model.data.NewsResource +import com.google.samples.apps.nowinandroid.core.model.data.Topic +import com.google.samples.apps.nowinandroid.feature.foryou.util.saveable import dagger.hilt.android.lifecycle.HiltViewModel import javax.inject.Inject import kotlinx.coroutines.flow.SharingStarted diff --git a/app/src/main/java/com/google/samples/apps/nowinandroid/ui/SavedStateHandleExtensions.kt b/feature-foryou/src/main/java/com/google/samples/apps/nowinandroid/feature/foryou/util/SavedStateHandleExtensions.kt similarity index 99% rename from app/src/main/java/com/google/samples/apps/nowinandroid/ui/SavedStateHandleExtensions.kt rename to feature-foryou/src/main/java/com/google/samples/apps/nowinandroid/feature/foryou/util/SavedStateHandleExtensions.kt index 4e01da7eb..d58aca04f 100644 --- a/app/src/main/java/com/google/samples/apps/nowinandroid/ui/SavedStateHandleExtensions.kt +++ b/feature-foryou/src/main/java/com/google/samples/apps/nowinandroid/feature/foryou/util/SavedStateHandleExtensions.kt @@ -14,7 +14,7 @@ * limitations under the License. */ -package com.google.samples.apps.nowinandroid.ui +package com.google.samples.apps.nowinandroid.feature.foryou.util import android.os.Binder import android.os.Bundle diff --git a/feature-foryou/src/main/res/values/strings.xml b/feature-foryou/src/main/res/values/strings.xml new file mode 100644 index 000000000..fba7ed7c2 --- /dev/null +++ b/feature-foryou/src/main/res/values/strings.xml @@ -0,0 +1,23 @@ + + + For you + Episodes + Saved + Done + Loading for you… + Navigate up + diff --git a/app/src/test/java/com/google/samples/apps/nowinandroid/ui/foryou/ForYouViewModelTest.kt b/feature-foryou/src/test/java/com/google/samples/apps/nowinandroid/feature/foryou/ForYouViewModelTest.kt similarity index 95% rename from app/src/test/java/com/google/samples/apps/nowinandroid/ui/foryou/ForYouViewModelTest.kt rename to feature-foryou/src/test/java/com/google/samples/apps/nowinandroid/feature/foryou/ForYouViewModelTest.kt index 2e56e1d58..1e0cd3333 100644 --- a/app/src/test/java/com/google/samples/apps/nowinandroid/ui/foryou/ForYouViewModelTest.kt +++ b/feature-foryou/src/test/java/com/google/samples/apps/nowinandroid/feature/foryou/ForYouViewModelTest.kt @@ -14,14 +14,14 @@ * limitations under the License. */ -package com.google.samples.apps.nowinandroid.ui.foryou +package com.google.samples.apps.nowinandroid.feature.foryou import androidx.lifecycle.SavedStateHandle import app.cash.turbine.test -import com.google.samples.apps.nowinandroid.data.model.Topic -import com.google.samples.apps.nowinandroid.testutil.TestDispatcherRule -import com.google.samples.apps.nowinandroid.testutil.TestNewsRepository -import com.google.samples.apps.nowinandroid.testutil.TestTopicsRepository +import com.google.samples.apps.nowinandroid.core.model.data.Topic +import com.google.samples.apps.nowinandroid.core.testing.repository.TestNewsRepository +import com.google.samples.apps.nowinandroid.core.testing.repository.TestTopicsRepository +import com.google.samples.apps.nowinandroid.core.testing.util.TestDispatcherRule import kotlinx.coroutines.test.runTest import org.junit.Assert.assertEquals import org.junit.Before diff --git a/gradle/libs.versions.toml b/gradle/libs.versions.toml index 62881a490..951ba1225 100644 --- a/gradle/libs.versions.toml +++ b/gradle/libs.versions.toml @@ -47,6 +47,7 @@ androidx-compose-runtime-livedata = { group = "androidx.compose.runtime", name = androidx-compose-ui-test = { group = "androidx.compose.ui", name = "ui-test-junit4", version.ref = "androidxCompose" } androidx-compose-ui-testManifest = { group = "androidx.compose.ui", name = "ui-test-manifest", version.ref = "androidxCompose" } androidx-compose-ui-tooling = { group = "androidx.compose.ui", name = "ui-tooling", version.ref = "androidxCompose" } +androidx-compose-ui-tooling-preview = { group = "androidx.compose.ui", name = "ui-tooling-preview", version.ref = "androidxCompose" } androidx-compose-ui-util = { group = "androidx.compose.ui", name = "ui-util", version.ref = "androidxCompose" } androidx-core-ktx = { group = "androidx.core", name = "core-ktx", version.ref = "androidxCore" } androidx-dataStore = { group = "androidx.datastore", name = "datastore", version.ref = "androidxDataStore" } diff --git a/settings.gradle b/settings.gradle index 1233caeb2..60be75337 100644 --- a/settings.gradle +++ b/settings.gradle @@ -29,3 +29,14 @@ dependencyResolutionManagement { } rootProject.name = "nowinandroid" include ':app' +include ':core-common' +include ':core-model' +include ':core-domain' +include ':core-testing' +include ':core-ui' +include ':feature-following' +include ':feature-foryou' +include ':core-database' +include ':core-datastore' +include ':core-network' +include ':core-datastore-test'