From 1489bf66e38130ced97187000ac473129e5e13bb Mon Sep 17 00:00:00 2001 From: Keisuke Takagi Date: Thu, 16 Feb 2023 01:47:29 +0900 Subject: [PATCH 01/13] remove unused updateTopics method --- .../apps/nowinandroid/core/database/dao/TopicDao.kt | 7 ------- 1 file changed, 7 deletions(-) diff --git a/core/database/src/main/java/com/google/samples/apps/nowinandroid/core/database/dao/TopicDao.kt b/core/database/src/main/java/com/google/samples/apps/nowinandroid/core/database/dao/TopicDao.kt index 37724af69..210f55c28 100644 --- a/core/database/src/main/java/com/google/samples/apps/nowinandroid/core/database/dao/TopicDao.kt +++ b/core/database/src/main/java/com/google/samples/apps/nowinandroid/core/database/dao/TopicDao.kt @@ -20,7 +20,6 @@ import androidx.room.Dao import androidx.room.Insert import androidx.room.OnConflictStrategy import androidx.room.Query -import androidx.room.Update import androidx.room.Upsert import com.google.samples.apps.nowinandroid.core.database.model.TopicEntity import kotlinx.coroutines.flow.Flow @@ -55,12 +54,6 @@ interface TopicDao { @Insert(onConflict = OnConflictStrategy.IGNORE) suspend fun insertOrIgnoreTopics(topicEntities: List): List - /** - * Updates [entities] in the db that match the primary key, and no-ops if they don't - */ - @Update - suspend fun updateTopics(entities: List) - /** * Inserts or updates [entities] in the db under the specified primary keys */ From 67412b272034d540453ffa59d69dd4235925a27e Mon Sep 17 00:00:00 2001 From: Keisuke Takagi Date: Thu, 16 Feb 2023 01:49:09 +0900 Subject: [PATCH 02/13] remove invalid overriding method --- .../apps/nowinandroid/core/data/testdoubles/TestTopicDao.kt | 4 ---- 1 file changed, 4 deletions(-) diff --git a/core/data/src/test/java/com/google/samples/apps/nowinandroid/core/data/testdoubles/TestTopicDao.kt b/core/data/src/test/java/com/google/samples/apps/nowinandroid/core/data/testdoubles/TestTopicDao.kt index 8ac0dc0b8..96402309f 100644 --- a/core/data/src/test/java/com/google/samples/apps/nowinandroid/core/data/testdoubles/TestTopicDao.kt +++ b/core/data/src/test/java/com/google/samples/apps/nowinandroid/core/data/testdoubles/TestTopicDao.kt @@ -58,10 +58,6 @@ class TestTopicDao : TopicDao { return topicEntities.map { it.id.toLong() } } - override suspend fun updateTopics(entities: List) { - throw NotImplementedError("Unused in tests") - } - override suspend fun upsertTopics(entities: List) { entitiesStateFlow.value = entities } From fb32580e0c0302268ccde7abde5ab6245f99d2bd Mon Sep 17 00:00:00 2001 From: Keisuke Takagi Date: Thu, 16 Feb 2023 01:49:37 +0900 Subject: [PATCH 03/13] remove unused updateNewsResources method --- .../apps/nowinandroid/core/database/dao/NewsResourceDao.kt | 7 ------- 1 file changed, 7 deletions(-) diff --git a/core/database/src/main/java/com/google/samples/apps/nowinandroid/core/database/dao/NewsResourceDao.kt b/core/database/src/main/java/com/google/samples/apps/nowinandroid/core/database/dao/NewsResourceDao.kt index af0a59bce..4d89177ff 100644 --- a/core/database/src/main/java/com/google/samples/apps/nowinandroid/core/database/dao/NewsResourceDao.kt +++ b/core/database/src/main/java/com/google/samples/apps/nowinandroid/core/database/dao/NewsResourceDao.kt @@ -21,7 +21,6 @@ import androidx.room.Insert import androidx.room.OnConflictStrategy import androidx.room.Query import androidx.room.Transaction -import androidx.room.Update import androidx.room.Upsert import com.google.samples.apps.nowinandroid.core.database.model.NewsResourceEntity import com.google.samples.apps.nowinandroid.core.database.model.NewsResourceTopicCrossRef @@ -65,12 +64,6 @@ interface NewsResourceDao { @Insert(onConflict = OnConflictStrategy.IGNORE) suspend fun insertOrIgnoreNewsResources(entities: List): List - /** - * Updates [entities] in the db that match the primary key, and no-ops if they don't - */ - @Update - suspend fun updateNewsResources(entities: List) - /** * Inserts or updates [newsResourceEntities] in the db under the specified primary keys */ From 86c021a54a39c045061d373a240749cb8e0cc602 Mon Sep 17 00:00:00 2001 From: Keisuke Takagi Date: Thu, 16 Feb 2023 01:49:51 +0900 Subject: [PATCH 04/13] remove invalid overriding method --- .../nowinandroid/core/data/testdoubles/TestNewsResourceDao.kt | 4 ---- 1 file changed, 4 deletions(-) diff --git a/core/data/src/test/java/com/google/samples/apps/nowinandroid/core/data/testdoubles/TestNewsResourceDao.kt b/core/data/src/test/java/com/google/samples/apps/nowinandroid/core/data/testdoubles/TestNewsResourceDao.kt index f63014075..ba1d20581 100644 --- a/core/data/src/test/java/com/google/samples/apps/nowinandroid/core/data/testdoubles/TestNewsResourceDao.kt +++ b/core/data/src/test/java/com/google/samples/apps/nowinandroid/core/data/testdoubles/TestNewsResourceDao.kt @@ -75,10 +75,6 @@ class TestNewsResourceDao : NewsResourceDao { return entities.map { it.id.toLong() } } - override suspend fun updateNewsResources(entities: List) { - throw NotImplementedError("Unused in tests") - } - override suspend fun upsertNewsResources(newsResourceEntities: List) { entitiesStateFlow.value = newsResourceEntities } From 462b6a1b3a8c0ec0f37dac0a935a37c087044e9a Mon Sep 17 00:00:00 2001 From: vketteni Date: Fri, 17 Mar 2023 19:28:58 +0100 Subject: [PATCH 05/13] Correct a table entry of a code reference from ArchitectureLearningJourney.md --- docs/ArchitectureLearningJourney.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/ArchitectureLearningJourney.md b/docs/ArchitectureLearningJourney.md index 9d7c77e1c..925858111 100644 --- a/docs/ArchitectureLearningJourney.md +++ b/docs/ArchitectureLearningJourney.md @@ -64,7 +64,7 @@ Here's what's happening in each step. The easiest way to find the associated cod On app startup, a WorkManager job to sync all repositories is enqueued. - SyncInitializer.create + Sync.initialize From 1921c6544d2a50558dc30e5e076d3ed85daaa9be Mon Sep 17 00:00:00 2001 From: Simon Marquis Date: Sun, 16 Apr 2023 22:48:57 +0200 Subject: [PATCH 06/13] Replace deprecated methods --- app-nia-catalog/build.gradle.kts | 2 +- app/build.gradle.kts | 2 +- .../google/samples/apps/nowinandroid/GradleManagedDevices.kt | 3 +-- .../kotlin/com/google/samples/apps/nowinandroid/Jacoco.kt | 5 +++++ 4 files changed, 8 insertions(+), 4 deletions(-) diff --git a/app-nia-catalog/build.gradle.kts b/app-nia-catalog/build.gradle.kts index 42ffd7039..7a8d61339 100644 --- a/app-nia-catalog/build.gradle.kts +++ b/app-nia-catalog/build.gradle.kts @@ -47,7 +47,7 @@ android { missingDimensionStrategy(FlavorDimension.contentType.name, NiaFlavor.demo.name) } - packagingOptions { + packaging { resources { excludes.add("/META-INF/{AL2.0,LGPL2.1}") } diff --git a/app/build.gradle.kts b/app/build.gradle.kts index 42dee2602..70160f3e1 100644 --- a/app/build.gradle.kts +++ b/app/build.gradle.kts @@ -65,7 +65,7 @@ android { } } - packagingOptions { + packaging { resources { excludes.add("/META-INF/{AL2.0,LGPL2.1}") } diff --git a/build-logic/convention/src/main/kotlin/com/google/samples/apps/nowinandroid/GradleManagedDevices.kt b/build-logic/convention/src/main/kotlin/com/google/samples/apps/nowinandroid/GradleManagedDevices.kt index 624afeea9..8129defeb 100644 --- a/build-logic/convention/src/main/kotlin/com/google/samples/apps/nowinandroid/GradleManagedDevices.kt +++ b/build-logic/convention/src/main/kotlin/com/google/samples/apps/nowinandroid/GradleManagedDevices.kt @@ -20,7 +20,6 @@ import com.android.build.api.dsl.CommonExtension import com.android.build.api.dsl.ManagedVirtualDevice import org.gradle.api.Project import org.gradle.kotlin.dsl.invoke -import java.util.Locale /** * Configure project for Gradle managed devices @@ -55,7 +54,7 @@ private data class DeviceConfig( val systemImageSource: String, ) { val taskName = buildString { - append(device.toLowerCase(Locale.ROOT).replace(" ", "")) + append(device.lowercase().replace(" ", "")) append("api") append(apiLevel.toString()) append(systemImageSource.replace("-", "")) diff --git a/build-logic/convention/src/main/kotlin/com/google/samples/apps/nowinandroid/Jacoco.kt b/build-logic/convention/src/main/kotlin/com/google/samples/apps/nowinandroid/Jacoco.kt index a34cd7c1c..d801d7b69 100644 --- a/build-logic/convention/src/main/kotlin/com/google/samples/apps/nowinandroid/Jacoco.kt +++ b/build-logic/convention/src/main/kotlin/com/google/samples/apps/nowinandroid/Jacoco.kt @@ -27,6 +27,7 @@ import org.gradle.kotlin.dsl.withType import org.gradle.testing.jacoco.plugins.JacocoPluginExtension import org.gradle.testing.jacoco.plugins.JacocoTaskExtension import org.gradle.testing.jacoco.tasks.JacocoReport +import java.util.Locale private val coverageExclusions = listOf( // Android @@ -36,6 +37,10 @@ private val coverageExclusions = listOf( "**/Manifest*.*" ) +private fun String.capitalize() = replaceFirstChar { + if (it.isLowerCase()) it.titlecase(Locale.getDefault()) else it.toString() +} + internal fun Project.configureJacoco( androidComponentsExtension: AndroidComponentsExtension<*, *, *>, ) { From 459717f8baca2baa0b851c5df4753350d02991a3 Mon Sep 17 00:00:00 2001 From: Simon Marquis Date: Sun, 16 Apr 2023 22:50:09 +0200 Subject: [PATCH 07/13] Remove `DSL_SCOPE_VIOLATION` suppression as it is now fixed in Gradle 8.1 --- core/database/build.gradle.kts | 2 -- core/datastore/build.gradle.kts | 2 -- core/model/build.gradle.kts | 3 +-- 3 files changed, 1 insertion(+), 6 deletions(-) diff --git a/core/database/build.gradle.kts b/core/database/build.gradle.kts index 10eb4363c..a9c711ae3 100644 --- a/core/database/build.gradle.kts +++ b/core/database/build.gradle.kts @@ -14,8 +14,6 @@ * limitations under the License. */ -// TODO: Remove once https://youtrack.jetbrains.com/issue/KTIJ-19369 is fixed -@Suppress("DSL_SCOPE_VIOLATION") plugins { id("nowinandroid.android.library") id("nowinandroid.android.library.jacoco") diff --git a/core/datastore/build.gradle.kts b/core/datastore/build.gradle.kts index 59a3a8e32..6fecb37d4 100644 --- a/core/datastore/build.gradle.kts +++ b/core/datastore/build.gradle.kts @@ -14,8 +14,6 @@ * limitations under the License. */ -// TODO: Remove once https://youtrack.jetbrains.com/issue/KTIJ-19369 is fixed -@Suppress("DSL_SCOPE_VIOLATION") plugins { id("nowinandroid.android.library") id("nowinandroid.android.library.jacoco") diff --git a/core/model/build.gradle.kts b/core/model/build.gradle.kts index edfcc4596..d49c5b3ee 100644 --- a/core/model/build.gradle.kts +++ b/core/model/build.gradle.kts @@ -13,8 +13,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -// TODO: Remove once https://youtrack.jetbrains.com/issue/KTIJ-19369 is fixed -@Suppress("DSL_SCOPE_VIOLATION") + plugins { id("kotlin") } From 1341f7c2c59162b852ab7e70f096eac8f36e46c3 Mon Sep 17 00:00:00 2001 From: Simon Marquis Date: Sun, 16 Apr 2023 22:50:57 +0200 Subject: [PATCH 08/13] Replace unused variable with simpler method calls --- app-nia-catalog/build.gradle.kts | 2 +- app/build.gradle.kts | 4 ++-- benchmarks/build.gradle.kts | 2 +- core/datastore/build.gradle.kts | 4 ++-- 4 files changed, 6 insertions(+), 6 deletions(-) diff --git a/app-nia-catalog/build.gradle.kts b/app-nia-catalog/build.gradle.kts index 7a8d61339..1f9ac1e2a 100644 --- a/app-nia-catalog/build.gradle.kts +++ b/app-nia-catalog/build.gradle.kts @@ -55,7 +55,7 @@ android { namespace = "com.google.samples.apps.niacatalog" buildTypes { - val release by getting { + release { // To publish on the Play store a private signing key is required, but to allow anyone // who clones the code to sign and run the release variant, use the debug signing key. // TODO: Abstract the signing configuration to a separate file to avoid hardcoding this. diff --git a/app/build.gradle.kts b/app/build.gradle.kts index 70160f3e1..e172ed8bb 100644 --- a/app/build.gradle.kts +++ b/app/build.gradle.kts @@ -39,7 +39,7 @@ android { } buildTypes { - val debug by getting { + debug { applicationIdSuffix = NiaBuildType.DEBUG.applicationIdSuffix } val release by getting { @@ -52,7 +52,7 @@ android { // TODO: Abstract the signing configuration to a separate file to avoid hardcoding this. signingConfig = signingConfigs.getByName("debug") } - val benchmark by creating { + create("benchmark") { // Enable all the optimizations from release build through initWith(release). initWith(release) matchingFallbacks.add("release") diff --git a/benchmarks/build.gradle.kts b/benchmarks/build.gradle.kts index fa8aeefb0..fb46ae63f 100644 --- a/benchmarks/build.gradle.kts +++ b/benchmarks/build.gradle.kts @@ -39,7 +39,7 @@ android { // This benchmark buildType is used for benchmarking, and should function like your // release build (for example, with minification on). It's signed with a debug key // for easy local/CI testing. - val benchmark by creating { + create("benchmark") { // Keep the build type debuggable so we can attach a debugger if needed. isDebuggable = true signingConfig = signingConfigs.getByName("debug") diff --git a/core/datastore/build.gradle.kts b/core/datastore/build.gradle.kts index 6fecb37d4..a9ec7a78f 100644 --- a/core/datastore/build.gradle.kts +++ b/core/datastore/build.gradle.kts @@ -41,10 +41,10 @@ protobuf { generateProtoTasks { all().forEach { task -> task.builtins { - val java by registering { + register("java") { option("lite") } - val kotlin by registering { + register("kotlin") { option("lite") } } From f19dd06200808ea2f6e49df3db5983bbb22a35ac Mon Sep 17 00:00:00 2001 From: Simon Marquis Date: Sun, 16 Apr 2023 22:54:45 +0200 Subject: [PATCH 09/13] Remove deprecated `kotlin.Experimental` opt-in This would produce the following warning messages: ``` w: Opt-in requirement marker kotlin.Experimental is unresolved. Please make sure it's present in the module dependencies ``` --- .../kotlin/com/google/samples/apps/nowinandroid/KotlinAndroid.kt | 1 - 1 file changed, 1 deletion(-) diff --git a/build-logic/convention/src/main/kotlin/com/google/samples/apps/nowinandroid/KotlinAndroid.kt b/build-logic/convention/src/main/kotlin/com/google/samples/apps/nowinandroid/KotlinAndroid.kt index e800d0570..65a734895 100644 --- a/build-logic/convention/src/main/kotlin/com/google/samples/apps/nowinandroid/KotlinAndroid.kt +++ b/build-logic/convention/src/main/kotlin/com/google/samples/apps/nowinandroid/KotlinAndroid.kt @@ -62,7 +62,6 @@ internal fun Project.configureKotlinAndroid( // Enable experimental coroutines APIs, including Flow "-opt-in=kotlinx.coroutines.ExperimentalCoroutinesApi", "-opt-in=kotlinx.coroutines.FlowPreview", - "-opt-in=kotlin.Experimental", ) } } From 661dd2bc2e581690b468cd7ccdcfba218b55e131 Mon Sep 17 00:00:00 2001 From: Simon Marquis Date: Wed, 26 Apr 2023 20:26:22 +0200 Subject: [PATCH 10/13] Update Kotlin 1.8.20 stack - KSP 1.8.20-1.0.10 - Compose compiler 1.4.5 --- gradle/libs.versions.toml | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/gradle/libs.versions.toml b/gradle/libs.versions.toml index 95b084fa7..289f6a363 100644 --- a/gradle/libs.versions.toml +++ b/gradle/libs.versions.toml @@ -6,7 +6,7 @@ androidxActivity = "1.7.0" androidxAppCompat = "1.5.1" androidxBrowser = "1.4.0" androidxComposeBom = "2023.01.00" -androidxComposeCompiler = "1.4.4" +androidxComposeCompiler = "1.4.5" androidxComposeMaterial3 = "1.1.0-alpha06" androidxComposeRuntimeTracing = "1.0.0-alpha01" androidxCore = "1.9.0" @@ -37,11 +37,11 @@ hilt = "2.44.2" hiltExt = "1.0.0" jacoco = "0.8.7" junit4 = "4.13.2" -kotlin = "1.8.10" +kotlin = "1.8.20" kotlinxCoroutines = "1.6.4" kotlinxDatetime = "0.4.0" kotlinxSerializationJson = "1.5.0" -ksp = "1.8.10-1.0.9" +ksp = "1.8.20-1.0.10" lint = "30.3.1" okhttp = "4.10.0" protobuf = "3.21.12" From 5500edc37bc27a502ebe3371495fac23ede3a3d1 Mon Sep 17 00:00:00 2001 From: Simon Marquis Date: Tue, 18 Apr 2023 07:54:21 +0200 Subject: [PATCH 11/13] Update KSP 1.8.20-1.0.11 --- gradle/libs.versions.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/gradle/libs.versions.toml b/gradle/libs.versions.toml index 289f6a363..ccfdeca99 100644 --- a/gradle/libs.versions.toml +++ b/gradle/libs.versions.toml @@ -41,7 +41,7 @@ kotlin = "1.8.20" kotlinxCoroutines = "1.6.4" kotlinxDatetime = "0.4.0" kotlinxSerializationJson = "1.5.0" -ksp = "1.8.20-1.0.10" +ksp = "1.8.20-1.0.11" lint = "30.3.1" okhttp = "4.10.0" protobuf = "3.21.12" From 57d1bed2cccfe14e091551c95bb626a49674c88a Mon Sep 17 00:00:00 2001 From: Simon Marquis Date: Thu, 27 Apr 2023 00:27:20 +0200 Subject: [PATCH 12/13] Disable unnecessary Android instrumented tests --- .../kotlin/AndroidLibraryConventionPlugin.kt | 2 ++ .../nowinandroid/AndroidInstrumentedTests.kt | 35 +++++++++++++++++++ 2 files changed, 37 insertions(+) create mode 100644 build-logic/convention/src/main/kotlin/com/google/samples/apps/nowinandroid/AndroidInstrumentedTests.kt diff --git a/build-logic/convention/src/main/kotlin/AndroidLibraryConventionPlugin.kt b/build-logic/convention/src/main/kotlin/AndroidLibraryConventionPlugin.kt index 5b2f76edb..275a26620 100644 --- a/build-logic/convention/src/main/kotlin/AndroidLibraryConventionPlugin.kt +++ b/build-logic/convention/src/main/kotlin/AndroidLibraryConventionPlugin.kt @@ -20,6 +20,7 @@ import com.google.samples.apps.nowinandroid.configureFlavors import com.google.samples.apps.nowinandroid.configureGradleManagedDevices import com.google.samples.apps.nowinandroid.configureKotlinAndroid import com.google.samples.apps.nowinandroid.configurePrintApksTask +import com.google.samples.apps.nowinandroid.disableUnnecessaryAndroidTests import org.gradle.api.Plugin import org.gradle.api.Project import org.gradle.api.artifacts.VersionCatalogsExtension @@ -44,6 +45,7 @@ class AndroidLibraryConventionPlugin : Plugin { } extensions.configure { configurePrintApksTask(this) + disableUnnecessaryAndroidTests(target) } val libs = extensions.getByType().named("libs") configurations.configureEach { diff --git a/build-logic/convention/src/main/kotlin/com/google/samples/apps/nowinandroid/AndroidInstrumentedTests.kt b/build-logic/convention/src/main/kotlin/com/google/samples/apps/nowinandroid/AndroidInstrumentedTests.kt new file mode 100644 index 000000000..d0c26e4e6 --- /dev/null +++ b/build-logic/convention/src/main/kotlin/com/google/samples/apps/nowinandroid/AndroidInstrumentedTests.kt @@ -0,0 +1,35 @@ +/* + * Copyright 2023 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 + +import com.android.build.api.variant.LibraryAndroidComponentsExtension +import org.gradle.api.Project + +/** + * Disable unnecessary Android instrumented tests for the [project] if there is no `androidTest` folder. + * Otherwise, these projects would be compiled, packaged, installed and ran only to end-up with the following message: + * + * > Starting 0 tests on AVD + * + * Note: this could be improved by checking other potential sourceSets based on buildTypes and flavors. + */ +internal fun LibraryAndroidComponentsExtension.disableUnnecessaryAndroidTests( + project: Project, +) = beforeVariants { + it.enableAndroidTest = it.enableAndroidTest + && project.projectDir.resolve("src/androidTest").exists() +} From c364dfc84e0d50e63cfbf4203e1ea2a9af932498 Mon Sep 17 00:00:00 2001 From: Adetunji Dahunsi Date: Fri, 28 Apr 2023 08:39:03 -0400 Subject: [PATCH 13/13] Update message sender in SyncNotificationsService --- .../nowinandroid/sync/services/SyncNotificationsService.kt | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/sync/work/src/main/java/com/google/samples/apps/nowinandroid/sync/services/SyncNotificationsService.kt b/sync/work/src/main/java/com/google/samples/apps/nowinandroid/sync/services/SyncNotificationsService.kt index 1d182dda1..e51e30164 100644 --- a/sync/work/src/main/java/com/google/samples/apps/nowinandroid/sync/services/SyncNotificationsService.kt +++ b/sync/work/src/main/java/com/google/samples/apps/nowinandroid/sync/services/SyncNotificationsService.kt @@ -19,10 +19,11 @@ package com.google.samples.apps.nowinandroid.sync.services import com.google.firebase.messaging.FirebaseMessagingService import com.google.firebase.messaging.RemoteMessage import com.google.samples.apps.nowinandroid.core.data.util.SyncManager -import com.google.samples.apps.nowinandroid.sync.initializers.SYNC_TOPIC import dagger.hilt.android.AndroidEntryPoint import javax.inject.Inject +private const val SYNC_TOPIC_SENDER = "/topics/sync" + @AndroidEntryPoint class SyncNotificationsService : FirebaseMessagingService() { @@ -30,7 +31,7 @@ class SyncNotificationsService : FirebaseMessagingService() { lateinit var syncManager: SyncManager override fun onMessageReceived(message: RemoteMessage) { - if (SYNC_TOPIC == message.from) { + if (SYNC_TOPIC_SENDER == message.from) { syncManager.requestSync() } }