diff --git a/core/data/src/test/java/com/google/samples/apps/nowinandroid/core/data/CompositeUserNewsResourceRepositoryTest.kt b/core/data/src/test/java/com/google/samples/apps/nowinandroid/core/data/CompositeUserNewsResourceRepositoryTest.kt index eb4241295..743fb7e5c 100644 --- a/core/data/src/test/java/com/google/samples/apps/nowinandroid/core/data/CompositeUserNewsResourceRepositoryTest.kt +++ b/core/data/src/test/java/com/google/samples/apps/nowinandroid/core/data/CompositeUserNewsResourceRepositoryTest.kt @@ -19,7 +19,6 @@ package com.google.samples.apps.nowinandroid.core.data import com.google.samples.apps.nowinandroid.core.data.repository.CompositeUserNewsResourceRepository import com.google.samples.apps.nowinandroid.core.data.repository.NewsResourceQuery import com.google.samples.apps.nowinandroid.core.model.data.NewsResource -import com.google.samples.apps.nowinandroid.core.model.data.NewsResourceType.Video import com.google.samples.apps.nowinandroid.core.model.data.Topic import com.google.samples.apps.nowinandroid.core.model.data.mapToUserNewsResources import com.google.samples.apps.nowinandroid.core.testing.repository.TestNewsRepository @@ -164,7 +163,7 @@ private val sampleNewsResources = listOf( url = "https://youtu.be/-fJ6poHQrjM", headerImageUrl = "https://i.ytimg.com/vi/-fJ6poHQrjM/maxresdefault.jpg", publishDate = Instant.parse("2021-11-09T00:00:00.000Z"), - type = Video, + type = "Video 📺", topics = listOf(sampleTopic1), ), NewsResource( @@ -176,7 +175,7 @@ private val sampleNewsResources = listOf( url = "https://youtu.be/ZARz0pjm5YM", headerImageUrl = "https://i.ytimg.com/vi/ZARz0pjm5YM/maxresdefault.jpg", publishDate = Instant.parse("2021-11-01T00:00:00.000Z"), - type = Video, + type = "Video 📺", topics = listOf(sampleTopic1, sampleTopic2), ), NewsResource( @@ -186,7 +185,7 @@ private val sampleNewsResources = listOf( url = "https://youtu.be/r5JgIyS3t3s", headerImageUrl = "https://i.ytimg.com/vi/r5JgIyS3t3s/maxresdefault.jpg", publishDate = Instant.parse("2021-11-08T00:00:00.000Z"), - type = Video, + type = "Video 📺", topics = listOf(sampleTopic2), ), ) diff --git a/core/data/src/test/java/com/google/samples/apps/nowinandroid/core/data/UserNewsResourceTest.kt b/core/data/src/test/java/com/google/samples/apps/nowinandroid/core/data/UserNewsResourceTest.kt index 004966ec9..a21dee863 100644 --- a/core/data/src/test/java/com/google/samples/apps/nowinandroid/core/data/UserNewsResourceTest.kt +++ b/core/data/src/test/java/com/google/samples/apps/nowinandroid/core/data/UserNewsResourceTest.kt @@ -19,7 +19,6 @@ package com.google.samples.apps.nowinandroid.core.data import com.google.samples.apps.nowinandroid.core.model.data.DarkThemeConfig.FOLLOW_SYSTEM import com.google.samples.apps.nowinandroid.core.model.data.FollowableTopic import com.google.samples.apps.nowinandroid.core.model.data.NewsResource -import com.google.samples.apps.nowinandroid.core.model.data.NewsResourceType.Article import com.google.samples.apps.nowinandroid.core.model.data.ThemeBrand.DEFAULT import com.google.samples.apps.nowinandroid.core.model.data.Topic import com.google.samples.apps.nowinandroid.core.model.data.UserData @@ -45,7 +44,7 @@ class UserNewsResourceTest { url = "Test URL", headerImageUrl = "Test image URL", publishDate = Clock.System.now(), - type = Article, + type = "Article 📚", topics = listOf( Topic( id = "T1", diff --git a/core/data/src/test/java/com/google/samples/apps/nowinandroid/core/data/model/NetworkEntityKtTest.kt b/core/data/src/test/java/com/google/samples/apps/nowinandroid/core/data/model/NetworkEntityKtTest.kt index dbbb3a94e..7dd251a99 100644 --- a/core/data/src/test/java/com/google/samples/apps/nowinandroid/core/data/model/NetworkEntityKtTest.kt +++ b/core/data/src/test/java/com/google/samples/apps/nowinandroid/core/data/model/NetworkEntityKtTest.kt @@ -16,7 +16,6 @@ package com.google.samples.apps.nowinandroid.core.data.model -import com.google.samples.apps.nowinandroid.core.model.data.NewsResourceType.Article import com.google.samples.apps.nowinandroid.core.network.model.NetworkNewsResource import com.google.samples.apps.nowinandroid.core.network.model.NetworkNewsResourceExpanded import com.google.samples.apps.nowinandroid.core.network.model.NetworkTopic @@ -56,7 +55,7 @@ class NetworkEntityKtTest { url = "url", headerImageUrl = "headerImageUrl", publishDate = Instant.fromEpochMilliseconds(1), - type = Article, + type = "Article 📚", ) val entity = networkModel.asEntity() @@ -66,7 +65,7 @@ class NetworkEntityKtTest { assertEquals("url", entity.url) assertEquals("headerImageUrl", entity.headerImageUrl) assertEquals(Instant.fromEpochMilliseconds(1), entity.publishDate) - assertEquals(Article, entity.type) + assertEquals("Article 📚", entity.type) val expandedNetworkModel = NetworkNewsResourceExpanded( @@ -76,7 +75,7 @@ class NetworkEntityKtTest { url = "url", headerImageUrl = "headerImageUrl", publishDate = Instant.fromEpochMilliseconds(1), - type = Article, + type = "Article 📚", ) val entityFromExpanded = expandedNetworkModel.asEntity() @@ -87,6 +86,6 @@ class NetworkEntityKtTest { assertEquals("url", entityFromExpanded.url) assertEquals("headerImageUrl", entityFromExpanded.headerImageUrl) assertEquals(Instant.fromEpochMilliseconds(1), entityFromExpanded.publishDate) - assertEquals(Article, entityFromExpanded.type) + assertEquals("Article 📚", entityFromExpanded.type) } } diff --git a/core/data/src/test/java/com/google/samples/apps/nowinandroid/core/database/model/PopulatedNewsResourceKtTest.kt b/core/data/src/test/java/com/google/samples/apps/nowinandroid/core/database/model/PopulatedNewsResourceKtTest.kt index 83158f6cd..a1b72c52f 100644 --- a/core/data/src/test/java/com/google/samples/apps/nowinandroid/core/database/model/PopulatedNewsResourceKtTest.kt +++ b/core/data/src/test/java/com/google/samples/apps/nowinandroid/core/database/model/PopulatedNewsResourceKtTest.kt @@ -17,7 +17,6 @@ package com.google.samples.apps.nowinandroid.core.database.model import com.google.samples.apps.nowinandroid.core.model.data.NewsResource -import com.google.samples.apps.nowinandroid.core.model.data.NewsResourceType.Video import com.google.samples.apps.nowinandroid.core.model.data.Topic import kotlinx.datetime.Instant import org.junit.Test @@ -33,7 +32,7 @@ class PopulatedNewsResourceKtTest { content = "Hilt", url = "url", headerImageUrl = "headerImageUrl", - type = Video, + type = "Video 📺", publishDate = Instant.fromEpochMilliseconds(1), ), topics = listOf( @@ -56,7 +55,7 @@ class PopulatedNewsResourceKtTest { content = "Hilt", url = "url", headerImageUrl = "headerImageUrl", - type = Video, + type = "Video 📺", publishDate = Instant.fromEpochMilliseconds(1), topics = listOf( Topic( diff --git a/core/data/src/test/java/com/google/samples/apps/nowinandroid/core/database/util/NewsResourceTypeConverterTest.kt b/core/data/src/test/java/com/google/samples/apps/nowinandroid/core/database/util/NewsResourceTypeConverterTest.kt deleted file mode 100644 index 77a09819b..000000000 --- a/core/data/src/test/java/com/google/samples/apps/nowinandroid/core/database/util/NewsResourceTypeConverterTest.kt +++ /dev/null @@ -1,96 +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.core.database.util - -import com.google.samples.apps.nowinandroid.core.model.data.NewsResourceType -import org.junit.Test -import kotlin.test.assertEquals - -class NewsResourceTypeConverterTest { - - @Test - fun test_room_news_resource_type_converter_for_video() { - assertEquals( - NewsResourceType.Video, - NewsResourceTypeConverter().stringToNewsResourceType("Video 📺"), - ) - } - - @Test - fun test_room_news_resource_type_converter_for_article() { - assertEquals( - NewsResourceType.Article, - NewsResourceTypeConverter().stringToNewsResourceType("Article 📚"), - ) - } - - @Test - fun test_room_news_resource_type_converter_for_api_change() { - assertEquals( - NewsResourceType.APIChange, - NewsResourceTypeConverter().stringToNewsResourceType("API change"), - ) - } - - @Test - fun test_room_news_resource_type_converter_for_codelab() { - assertEquals( - NewsResourceType.Codelab, - NewsResourceTypeConverter().stringToNewsResourceType("Codelab"), - ) - } - - @Test - fun test_room_news_resource_type_converter_for_podcast() { - assertEquals( - NewsResourceType.Podcast, - NewsResourceTypeConverter().stringToNewsResourceType("Podcast 🎙"), - ) - } - - @Test - fun test_room_news_resource_type_converter_for_docs() { - assertEquals( - NewsResourceType.Docs, - NewsResourceTypeConverter().stringToNewsResourceType("Docs 📑"), - ) - } - - @Test - fun test_room_news_resource_type_converter_for_event() { - assertEquals( - NewsResourceType.Event, - NewsResourceTypeConverter().stringToNewsResourceType("Event 📆"), - ) - } - - @Test - fun test_room_news_resource_type_converter_for_dac() { - assertEquals( - NewsResourceType.DAC, - NewsResourceTypeConverter().stringToNewsResourceType("DAC"), - ) - } - - @Test - fun test_room_news_resource_type_converter_for_umm() { - assertEquals( - NewsResourceType.Unknown, - NewsResourceTypeConverter().stringToNewsResourceType("umm"), - ) - } -} diff --git a/core/database/src/androidTest/java/com/google/samples/apps/nowinandroid/core/database/dao/NewsResourceDaoTest.kt b/core/database/src/androidTest/java/com/google/samples/apps/nowinandroid/core/database/dao/NewsResourceDaoTest.kt index 83dc3c2e6..55e817618 100644 --- a/core/database/src/androidTest/java/com/google/samples/apps/nowinandroid/core/database/dao/NewsResourceDaoTest.kt +++ b/core/database/src/androidTest/java/com/google/samples/apps/nowinandroid/core/database/dao/NewsResourceDaoTest.kt @@ -24,7 +24,6 @@ import com.google.samples.apps.nowinandroid.core.database.model.NewsResourceEnti import com.google.samples.apps.nowinandroid.core.database.model.NewsResourceTopicCrossRef import com.google.samples.apps.nowinandroid.core.database.model.TopicEntity import com.google.samples.apps.nowinandroid.core.database.model.asExternalModel -import com.google.samples.apps.nowinandroid.core.model.data.NewsResourceType import kotlinx.coroutines.flow.first import kotlinx.coroutines.test.runTest import kotlinx.datetime.Instant @@ -305,5 +304,5 @@ private fun testNewsResource( url = "", headerImageUrl = "", publishDate = Instant.fromEpochMilliseconds(millisSinceEpoch), - type = NewsResourceType.DAC, + type = "Article 📚", ) diff --git a/core/database/src/main/java/com/google/samples/apps/nowinandroid/core/database/NiaDatabase.kt b/core/database/src/main/java/com/google/samples/apps/nowinandroid/core/database/NiaDatabase.kt index 96714f9a9..fd6b75e49 100644 --- a/core/database/src/main/java/com/google/samples/apps/nowinandroid/core/database/NiaDatabase.kt +++ b/core/database/src/main/java/com/google/samples/apps/nowinandroid/core/database/NiaDatabase.kt @@ -32,7 +32,6 @@ import com.google.samples.apps.nowinandroid.core.database.model.RecentSearchQuer import com.google.samples.apps.nowinandroid.core.database.model.TopicEntity import com.google.samples.apps.nowinandroid.core.database.model.TopicFtsEntity import com.google.samples.apps.nowinandroid.core.database.util.InstantConverter -import com.google.samples.apps.nowinandroid.core.database.util.NewsResourceTypeConverter @Database( entities = [ @@ -63,7 +62,6 @@ import com.google.samples.apps.nowinandroid.core.database.util.NewsResourceTypeC ) @TypeConverters( InstantConverter::class, - NewsResourceTypeConverter::class, ) abstract class NiaDatabase : RoomDatabase() { abstract fun topicDao(): TopicDao diff --git a/core/database/src/main/java/com/google/samples/apps/nowinandroid/core/database/model/NewsResourceEntity.kt b/core/database/src/main/java/com/google/samples/apps/nowinandroid/core/database/model/NewsResourceEntity.kt index a571d8f94..9450a24ad 100644 --- a/core/database/src/main/java/com/google/samples/apps/nowinandroid/core/database/model/NewsResourceEntity.kt +++ b/core/database/src/main/java/com/google/samples/apps/nowinandroid/core/database/model/NewsResourceEntity.kt @@ -20,7 +20,6 @@ import androidx.room.ColumnInfo import androidx.room.Entity import androidx.room.PrimaryKey import com.google.samples.apps.nowinandroid.core.model.data.NewsResource -import com.google.samples.apps.nowinandroid.core.model.data.NewsResourceType import kotlinx.datetime.Instant /** @@ -39,7 +38,7 @@ data class NewsResourceEntity( val headerImageUrl: String?, @ColumnInfo(name = "publish_date") val publishDate: Instant, - val type: NewsResourceType, + val type: String, ) fun NewsResourceEntity.asExternalModel() = NewsResource( diff --git a/core/database/src/main/java/com/google/samples/apps/nowinandroid/core/database/util/Converters.kt b/core/database/src/main/java/com/google/samples/apps/nowinandroid/core/database/util/InstantConverter.kt similarity index 67% rename from core/database/src/main/java/com/google/samples/apps/nowinandroid/core/database/util/Converters.kt rename to core/database/src/main/java/com/google/samples/apps/nowinandroid/core/database/util/InstantConverter.kt index eff1742ee..4e880886c 100644 --- a/core/database/src/main/java/com/google/samples/apps/nowinandroid/core/database/util/Converters.kt +++ b/core/database/src/main/java/com/google/samples/apps/nowinandroid/core/database/util/InstantConverter.kt @@ -17,8 +17,6 @@ package com.google.samples.apps.nowinandroid.core.database.util import androidx.room.TypeConverter -import com.google.samples.apps.nowinandroid.core.model.data.NewsResourceType -import com.google.samples.apps.nowinandroid.core.model.data.asNewsResourceType import kotlinx.datetime.Instant class InstantConverter { @@ -30,13 +28,3 @@ class InstantConverter { fun instantToLong(instant: Instant?): Long? = instant?.toEpochMilliseconds() } - -class NewsResourceTypeConverter { - @TypeConverter - fun newsResourceTypeToString(value: NewsResourceType?): String? = - value?.let(NewsResourceType::serializedName) - - @TypeConverter - fun stringToNewsResourceType(serializedName: String?): NewsResourceType = - serializedName.asNewsResourceType() -} diff --git a/core/model/src/main/java/com/google/samples/apps/nowinandroid/core/model/data/NewsResource.kt b/core/model/src/main/java/com/google/samples/apps/nowinandroid/core/model/data/NewsResource.kt index a1d4deb65..996851ff3 100644 --- a/core/model/src/main/java/com/google/samples/apps/nowinandroid/core/model/data/NewsResource.kt +++ b/core/model/src/main/java/com/google/samples/apps/nowinandroid/core/model/data/NewsResource.kt @@ -28,6 +28,6 @@ data class NewsResource( val url: String, val headerImageUrl: String?, val publishDate: Instant, - val type: NewsResourceType, + val type: String, val topics: List, ) diff --git a/core/model/src/main/java/com/google/samples/apps/nowinandroid/core/model/data/NewsResourceType.kt b/core/model/src/main/java/com/google/samples/apps/nowinandroid/core/model/data/NewsResourceType.kt deleted file mode 100644 index bb00f8620..000000000 --- a/core/model/src/main/java/com/google/samples/apps/nowinandroid/core/model/data/NewsResourceType.kt +++ /dev/null @@ -1,80 +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.core.model.data - -/** - * Type for [NewsResource] - */ -enum class NewsResourceType( - val serializedName: String, - val displayText: String, - // TODO: descriptions should probably be string resources - val description: String, -) { - Video( - serializedName = "Video 📺", - displayText = "Video 📺", - description = "A video published on YouTube", - ), - APIChange( - serializedName = "API change", - displayText = "API change", - description = "An addition, deprecation or change to the Android platform APIs.", - ), - Article( - serializedName = "Article 📚", - displayText = "Article 📚", - description = "An article, typically on Medium or the official Android blog", - ), - Codelab( - serializedName = "Codelab", - displayText = "Codelab", - description = "A new or updated codelab", - ), - Podcast( - serializedName = "Podcast 🎙", - displayText = "Podcast 🎙", - description = "A podcast", - ), - Docs( - serializedName = "Docs 📑", - displayText = "Docs 📑", - description = "A new or updated piece of documentation", - ), - Event( - serializedName = "Event 📆", - displayText = "Event 📆", - description = "Information about a developer event e.g. Android Developer Summit", - ), - DAC( - serializedName = "DAC", - displayText = "DAC", - description = "Android version features - Information about features in an Android", - ), - Unknown( - serializedName = "Unknown", - displayText = "Unknown", - description = "Unknown", - ), -} - -fun String?.asNewsResourceType() = when (this) { - null -> NewsResourceType.Unknown - else -> NewsResourceType.values() - .firstOrNull { type -> type.serializedName == this } - ?: NewsResourceType.Unknown -} diff --git a/core/model/src/main/java/com/google/samples/apps/nowinandroid/core/model/data/UserNewsResource.kt b/core/model/src/main/java/com/google/samples/apps/nowinandroid/core/model/data/UserNewsResource.kt index 251911930..4ea830022 100644 --- a/core/model/src/main/java/com/google/samples/apps/nowinandroid/core/model/data/UserNewsResource.kt +++ b/core/model/src/main/java/com/google/samples/apps/nowinandroid/core/model/data/UserNewsResource.kt @@ -29,7 +29,7 @@ data class UserNewsResource internal constructor( val url: String, val headerImageUrl: String?, val publishDate: Instant, - val type: NewsResourceType, + val type: String, val followableTopics: List, val isSaved: Boolean, val hasBeenViewed: Boolean, diff --git a/core/network/src/main/java/com/google/samples/apps/nowinandroid/core/network/model/NetworkNewsResource.kt b/core/network/src/main/java/com/google/samples/apps/nowinandroid/core/network/model/NetworkNewsResource.kt index 99fa67a52..42fbfa826 100644 --- a/core/network/src/main/java/com/google/samples/apps/nowinandroid/core/network/model/NetworkNewsResource.kt +++ b/core/network/src/main/java/com/google/samples/apps/nowinandroid/core/network/model/NetworkNewsResource.kt @@ -17,9 +17,7 @@ package com.google.samples.apps.nowinandroid.core.network.model import com.google.samples.apps.nowinandroid.core.model.data.NewsResource -import com.google.samples.apps.nowinandroid.core.model.data.NewsResourceType import com.google.samples.apps.nowinandroid.core.network.model.util.InstantSerializer -import com.google.samples.apps.nowinandroid.core.network.model.util.NewsResourceTypeSerializer import kotlinx.datetime.Instant import kotlinx.serialization.Serializable @@ -35,8 +33,7 @@ data class NetworkNewsResource( val headerImageUrl: String, @Serializable(InstantSerializer::class) val publishDate: Instant, - @Serializable(NewsResourceTypeSerializer::class) - val type: NewsResourceType, + val type: String, val topics: List = listOf(), ) @@ -52,7 +49,6 @@ data class NetworkNewsResourceExpanded( val headerImageUrl: String, @Serializable(InstantSerializer::class) val publishDate: Instant, - @Serializable(NewsResourceTypeSerializer::class) - val type: NewsResourceType, + val type: String, val topics: List = listOf(), ) diff --git a/core/network/src/main/java/com/google/samples/apps/nowinandroid/core/network/model/util/NewsResourceTypeSerializer.kt b/core/network/src/main/java/com/google/samples/apps/nowinandroid/core/network/model/util/NewsResourceTypeSerializer.kt deleted file mode 100644 index ac40d6182..000000000 --- a/core/network/src/main/java/com/google/samples/apps/nowinandroid/core/network/model/util/NewsResourceTypeSerializer.kt +++ /dev/null @@ -1,39 +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.core.network.model.util - -import com.google.samples.apps.nowinandroid.core.model.data.NewsResourceType -import com.google.samples.apps.nowinandroid.core.model.data.asNewsResourceType -import kotlinx.serialization.KSerializer -import kotlinx.serialization.descriptors.PrimitiveKind.STRING -import kotlinx.serialization.descriptors.PrimitiveSerialDescriptor -import kotlinx.serialization.descriptors.SerialDescriptor -import kotlinx.serialization.encoding.Decoder -import kotlinx.serialization.encoding.Encoder - -object NewsResourceTypeSerializer : KSerializer { - override fun deserialize(decoder: Decoder): NewsResourceType = - decoder.decodeString().asNewsResourceType() - - override val descriptor: SerialDescriptor = PrimitiveSerialDescriptor( - serialName = "type", - kind = STRING, - ) - - override fun serialize(encoder: Encoder, value: NewsResourceType) = - encoder.encodeString(value.serializedName) -} diff --git a/core/network/src/test/java/com/google/samples/apps/nowinandroid/core/network/fake/FakeNiaNetworkDataSourceTest.kt b/core/network/src/test/java/com/google/samples/apps/nowinandroid/core/network/fake/FakeNiaNetworkDataSourceTest.kt index f54351750..76c2accf2 100644 --- a/core/network/src/test/java/com/google/samples/apps/nowinandroid/core/network/fake/FakeNiaNetworkDataSourceTest.kt +++ b/core/network/src/test/java/com/google/samples/apps/nowinandroid/core/network/fake/FakeNiaNetworkDataSourceTest.kt @@ -17,7 +17,6 @@ package com.google.samples.apps.nowinandroid.core.network.fake import JvmUnitTestFakeAssetManager -import com.google.samples.apps.nowinandroid.core.model.data.NewsResourceType.Codelab import com.google.samples.apps.nowinandroid.core.network.model.NetworkNewsResource import com.google.samples.apps.nowinandroid.core.network.model.NetworkTopic import kotlinx.coroutines.test.StandardTestDispatcher @@ -81,7 +80,7 @@ class FakeNiaNetworkDataSourceTest { second = 0, nanosecond = 0, ).toInstant(TimeZone.UTC), - type = Codelab, + type = "Codelab", topics = listOf("2", "3", "10"), ), /* ktlint-enable max-line-length */ diff --git a/core/network/src/test/java/com/google/samples/apps/nowinandroid/core/network/model/util/NewsResourceTypeSerializerTest.kt b/core/network/src/test/java/com/google/samples/apps/nowinandroid/core/network/model/util/NewsResourceTypeSerializerTest.kt deleted file mode 100644 index 16ac7df26..000000000 --- a/core/network/src/test/java/com/google/samples/apps/nowinandroid/core/network/model/util/NewsResourceTypeSerializerTest.kt +++ /dev/null @@ -1,106 +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.core.network.model.util - -import com.google.samples.apps.nowinandroid.core.model.data.NewsResourceType -import kotlinx.serialization.json.Json -import org.junit.Test -import kotlin.test.assertEquals - -class NewsResourceTypeSerializerTest { - - @Test - fun test_news_resource_serializer_video() { - assertEquals( - NewsResourceType.Video, - Json.decodeFromString(NewsResourceTypeSerializer, """"Video 📺""""), - ) - } - - @Test - fun test_news_resource_serializer_article() { - assertEquals( - NewsResourceType.Article, - Json.decodeFromString(NewsResourceTypeSerializer, """"Article 📚""""), - ) - } - - @Test - fun test_news_resource_serializer_api_change() { - assertEquals( - NewsResourceType.APIChange, - Json.decodeFromString(NewsResourceTypeSerializer, """"API change""""), - ) - } - - @Test - fun test_news_resource_serializer_codelab() { - assertEquals( - NewsResourceType.Codelab, - Json.decodeFromString(NewsResourceTypeSerializer, """"Codelab""""), - ) - } - - @Test - fun test_news_resource_serializer_podcast() { - assertEquals( - NewsResourceType.Podcast, - Json.decodeFromString(NewsResourceTypeSerializer, """"Podcast 🎙""""), - ) - } - - @Test - fun test_news_resource_serializer_docs() { - assertEquals( - NewsResourceType.Docs, - Json.decodeFromString(NewsResourceTypeSerializer, """"Docs 📑""""), - ) - } - - @Test - fun test_news_resource_serializer_event() { - assertEquals( - NewsResourceType.Event, - Json.decodeFromString(NewsResourceTypeSerializer, """"Event 📆""""), - ) - } - - @Test - fun test_news_resource_serializer_dac() { - assertEquals( - NewsResourceType.DAC, - Json.decodeFromString(NewsResourceTypeSerializer, """"DAC""""), - ) - } - - @Test - fun test_news_resource_serializer_unknown() { - assertEquals( - NewsResourceType.Unknown, - Json.decodeFromString(NewsResourceTypeSerializer, """"umm""""), - ) - } - - @Test - fun test_serialize_and_deserialize() { - val json = Json.encodeToString(NewsResourceTypeSerializer, NewsResourceType.Video) - assertEquals( - NewsResourceType.Video, - Json.decodeFromString(NewsResourceTypeSerializer, json), - ) - } -} diff --git a/core/testing/src/main/java/com/google/samples/apps/nowinandroid/core/testing/data/NewsResourcesTestData.kt b/core/testing/src/main/java/com/google/samples/apps/nowinandroid/core/testing/data/NewsResourcesTestData.kt index bffa7cb79..ef845dc58 100644 --- a/core/testing/src/main/java/com/google/samples/apps/nowinandroid/core/testing/data/NewsResourcesTestData.kt +++ b/core/testing/src/main/java/com/google/samples/apps/nowinandroid/core/testing/data/NewsResourcesTestData.kt @@ -17,9 +17,6 @@ package com.google.samples.apps.nowinandroid.core.testing.data import com.google.samples.apps.nowinandroid.core.model.data.NewsResource -import com.google.samples.apps.nowinandroid.core.model.data.NewsResourceType.Codelab -import com.google.samples.apps.nowinandroid.core.model.data.NewsResourceType.Unknown -import com.google.samples.apps.nowinandroid.core.model.data.NewsResourceType.Video import kotlinx.datetime.Instant /* ktlint-disable max-line-length */ @@ -31,7 +28,7 @@ val newsResourcesTestData: List = listOf( url = "https://android-developers.googleblog.com/2022/05/new-android-basics-with-compose-course.html", headerImageUrl = "https://developer.android.com/images/hero-assets/android-basics-compose.svg", publishDate = Instant.parse("2021-11-09T00:00:00.000Z"), - type = Codelab, + type = "Codelab", topics = listOf(topicsTestData[1]), ), NewsResource( @@ -44,7 +41,7 @@ val newsResourcesTestData: List = listOf( url = "https://youtu.be/-fJ6poHQrjM", headerImageUrl = "https://i.ytimg.com/vi/-fJ6poHQrjM/maxresdefault.jpg", publishDate = Instant.parse("2021-11-09T00:00:00.000Z"), - type = Video, + type = "Video 📺", topics = listOf(topicsTestData[0], topicsTestData[1]), ), NewsResource( @@ -57,7 +54,7 @@ val newsResourcesTestData: List = listOf( url = "https://youtu.be/ZARz0pjm5YM", headerImageUrl = "https://i.ytimg.com/vi/ZARz0pjm5YM/maxresdefault.jpg", publishDate = Instant.parse("2021-11-01T00:00:00.000Z"), - type = Video, + type = "Video 📺", topics = listOf(topicsTestData[2]), ), NewsResource( @@ -68,7 +65,7 @@ val newsResourcesTestData: List = listOf( url = "https://developer.android.com/jetpack/androidx/versions/all-channel", headerImageUrl = "", publishDate = Instant.parse("2022-10-01T00:00:00.000Z"), - type = Unknown, + type = "", topics = listOf(topicsTestData[2]), ), ) diff --git a/core/testing/src/main/java/com/google/samples/apps/nowinandroid/core/testing/data/UserNewsResourcesTestData.kt b/core/testing/src/main/java/com/google/samples/apps/nowinandroid/core/testing/data/UserNewsResourcesTestData.kt index 987b48b57..97acad088 100644 --- a/core/testing/src/main/java/com/google/samples/apps/nowinandroid/core/testing/data/UserNewsResourcesTestData.kt +++ b/core/testing/src/main/java/com/google/samples/apps/nowinandroid/core/testing/data/UserNewsResourcesTestData.kt @@ -18,9 +18,6 @@ package com.google.samples.apps.nowinandroid.core.testing.data import com.google.samples.apps.nowinandroid.core.model.data.DarkThemeConfig import com.google.samples.apps.nowinandroid.core.model.data.NewsResource -import com.google.samples.apps.nowinandroid.core.model.data.NewsResourceType.Codelab -import com.google.samples.apps.nowinandroid.core.model.data.NewsResourceType.Unknown -import com.google.samples.apps.nowinandroid.core.model.data.NewsResourceType.Video import com.google.samples.apps.nowinandroid.core.model.data.ThemeBrand import com.google.samples.apps.nowinandroid.core.model.data.UserData import com.google.samples.apps.nowinandroid.core.model.data.UserNewsResource @@ -56,7 +53,7 @@ val userNewsResourcesTestData: List = UserData( second = 0, nanosecond = 0, ).toInstant(TimeZone.UTC), - type = Codelab, + type = "Codelab", topics = listOf(topicsTestData[2]), ), userData = userData, @@ -72,7 +69,7 @@ val userNewsResourcesTestData: List = UserData( url = "https://youtu.be/-fJ6poHQrjM", headerImageUrl = "https://i.ytimg.com/vi/-fJ6poHQrjM/maxresdefault.jpg", publishDate = Instant.parse("2021-11-09T00:00:00.000Z"), - type = Video, + type = "Video 📺", topics = topicsTestData.take(2), ), userData = userData, @@ -88,7 +85,7 @@ val userNewsResourcesTestData: List = UserData( url = "https://youtu.be/ZARz0pjm5YM", headerImageUrl = "https://i.ytimg.com/vi/ZARz0pjm5YM/maxresdefault.jpg", publishDate = Instant.parse("2021-11-01T00:00:00.000Z"), - type = Video, + type = "Video 📺", topics = listOf(topicsTestData[2]), ), userData = userData, @@ -102,7 +99,7 @@ val userNewsResourcesTestData: List = UserData( url = "https://developer.android.com/jetpack/androidx/versions/all-channel", headerImageUrl = "", publishDate = Instant.parse("2022-10-01T00:00:00.000Z"), - type = Unknown, + type = "", topics = listOf(topicsTestData[2]), ), userData = userData, diff --git a/core/ui/src/androidTest/java/com/google/samples/apps/nowinandroid/core/ui/NewsResourceCardTest.kt b/core/ui/src/androidTest/java/com/google/samples/apps/nowinandroid/core/ui/NewsResourceCardTest.kt index a495a6266..a2fdbaee1 100644 --- a/core/ui/src/androidTest/java/com/google/samples/apps/nowinandroid/core/ui/NewsResourceCardTest.kt +++ b/core/ui/src/androidTest/java/com/google/samples/apps/nowinandroid/core/ui/NewsResourceCardTest.kt @@ -34,7 +34,7 @@ class NewsResourceCardTest { @Test fun testMetaDataDisplay_withCodelabResource() { val newsWithKnownResourceType = userNewsResourcesTestData[0] - var dateFormatted = "" + lateinit var dateFormatted: String composeTestRule.setContent { NewsResourceCardExpanded( @@ -54,20 +54,20 @@ class NewsResourceCardTest { composeTestRule.activity.getString( R.string.card_meta_data_text, dateFormatted, - newsWithKnownResourceType.type.displayText, + newsWithKnownResourceType.type, ), ) .assertExists() } @Test - fun testMetaDataDisplay_withUnknownResource() { - val newsWithUnknownResourceType = userNewsResourcesTestData[3] - var dateFormatted = "" + fun testMetaDataDisplay_withEmptyResourceType() { + val newsWithEmptyResourceType = userNewsResourcesTestData[3] + lateinit var dateFormatted: String composeTestRule.setContent { NewsResourceCardExpanded( - userNewsResource = newsWithUnknownResourceType, + userNewsResource = newsWithEmptyResourceType, isBookmarked = false, hasBeenViewed = false, onToggleBookmark = {}, @@ -75,7 +75,7 @@ class NewsResourceCardTest { onTopicClick = {}, ) - dateFormatted = dateFormatted(publishDate = newsWithUnknownResourceType.publishDate) + dateFormatted = dateFormatted(publishDate = newsWithEmptyResourceType.publishDate) } composeTestRule diff --git a/core/ui/src/main/java/com/google/samples/apps/nowinandroid/core/ui/NewsResourceCard.kt b/core/ui/src/main/java/com/google/samples/apps/nowinandroid/core/ui/NewsResourceCard.kt index 4ed583b66..908e3352c 100644 --- a/core/ui/src/main/java/com/google/samples/apps/nowinandroid/core/ui/NewsResourceCard.kt +++ b/core/ui/src/main/java/com/google/samples/apps/nowinandroid/core/ui/NewsResourceCard.kt @@ -68,7 +68,6 @@ import com.google.samples.apps.nowinandroid.core.designsystem.icon.NiaIcons import com.google.samples.apps.nowinandroid.core.designsystem.theme.NiaTheme import com.google.samples.apps.nowinandroid.core.model.data.FollowableTopic import com.google.samples.apps.nowinandroid.core.model.data.NewsResource -import com.google.samples.apps.nowinandroid.core.model.data.NewsResourceType import com.google.samples.apps.nowinandroid.core.model.data.UserNewsResource import kotlinx.datetime.Instant import kotlinx.datetime.toJavaInstant @@ -264,12 +263,12 @@ fun dateFormatted(publishDate: Instant): String { @Composable fun NewsResourceMetaData( publishDate: Instant, - resourceType: NewsResourceType, + resourceType: String, ) { val formattedDate = dateFormatted(publishDate) Text( - if (resourceType != NewsResourceType.Unknown) { - stringResource(R.string.card_meta_data_text, formattedDate, resourceType.displayText) + if (resourceType.isNotBlank()) { + stringResource(R.string.card_meta_data_text, formattedDate, resourceType) } else { formattedDate }, diff --git a/core/ui/src/main/java/com/google/samples/apps/nowinandroid/core/ui/UserNewsResourcePreviewParameterProvider.kt b/core/ui/src/main/java/com/google/samples/apps/nowinandroid/core/ui/UserNewsResourcePreviewParameterProvider.kt index cc78e2e78..493788314 100644 --- a/core/ui/src/main/java/com/google/samples/apps/nowinandroid/core/ui/UserNewsResourcePreviewParameterProvider.kt +++ b/core/ui/src/main/java/com/google/samples/apps/nowinandroid/core/ui/UserNewsResourcePreviewParameterProvider.kt @@ -19,8 +19,6 @@ package com.google.samples.apps.nowinandroid.core.ui import androidx.compose.ui.tooling.preview.PreviewParameterProvider import com.google.samples.apps.nowinandroid.core.model.data.DarkThemeConfig import com.google.samples.apps.nowinandroid.core.model.data.NewsResource -import com.google.samples.apps.nowinandroid.core.model.data.NewsResourceType -import com.google.samples.apps.nowinandroid.core.model.data.NewsResourceType.Video import com.google.samples.apps.nowinandroid.core.model.data.ThemeBrand import com.google.samples.apps.nowinandroid.core.model.data.Topic import com.google.samples.apps.nowinandroid.core.model.data.UserData @@ -97,7 +95,7 @@ object PreviewParameterData { second = 0, nanosecond = 0, ).toInstant(TimeZone.UTC), - type = NewsResourceType.Codelab, + type = "Codelab", topics = listOf(topics[2]), ), userData = userData, @@ -113,7 +111,7 @@ object PreviewParameterData { url = "https://youtu.be/-fJ6poHQrjM", headerImageUrl = "https://i.ytimg.com/vi/-fJ6poHQrjM/maxresdefault.jpg", publishDate = Instant.parse("2021-11-09T00:00:00.000Z"), - type = Video, + type = "Video 📺", topics = topics.take(2), ), userData = userData, @@ -129,7 +127,7 @@ object PreviewParameterData { url = "https://youtu.be/ZARz0pjm5YM", headerImageUrl = "https://i.ytimg.com/vi/ZARz0pjm5YM/maxresdefault.jpg", publishDate = Instant.parse("2021-11-01T00:00:00.000Z"), - type = Video, + type = "Video 📺", topics = listOf(topics[2]), ), userData = userData, diff --git a/feature/foryou/src/test/java/com/google/samples/apps/nowinandroid/feature/foryou/ForYouViewModelTest.kt b/feature/foryou/src/test/java/com/google/samples/apps/nowinandroid/feature/foryou/ForYouViewModelTest.kt index d1f2f69b7..b75573975 100644 --- a/feature/foryou/src/test/java/com/google/samples/apps/nowinandroid/feature/foryou/ForYouViewModelTest.kt +++ b/feature/foryou/src/test/java/com/google/samples/apps/nowinandroid/feature/foryou/ForYouViewModelTest.kt @@ -23,7 +23,6 @@ import com.google.samples.apps.nowinandroid.core.data.repository.CompositeUserNe import com.google.samples.apps.nowinandroid.core.domain.GetFollowableTopicsUseCase import com.google.samples.apps.nowinandroid.core.model.data.FollowableTopic import com.google.samples.apps.nowinandroid.core.model.data.NewsResource -import com.google.samples.apps.nowinandroid.core.model.data.NewsResourceType.Video import com.google.samples.apps.nowinandroid.core.model.data.Topic import com.google.samples.apps.nowinandroid.core.model.data.UserNewsResource import com.google.samples.apps.nowinandroid.core.model.data.mapToUserNewsResources @@ -545,7 +544,7 @@ private val sampleNewsResources = listOf( url = "https://youtu.be/-fJ6poHQrjM", headerImageUrl = "https://i.ytimg.com/vi/-fJ6poHQrjM/maxresdefault.jpg", publishDate = Instant.parse("2021-11-09T00:00:00.000Z"), - type = Video, + type = "Video 📺", topics = listOf( Topic( id = "0", @@ -566,7 +565,7 @@ private val sampleNewsResources = listOf( url = "https://youtu.be/ZARz0pjm5YM", headerImageUrl = "https://i.ytimg.com/vi/ZARz0pjm5YM/maxresdefault.jpg", publishDate = Instant.parse("2021-11-01T00:00:00.000Z"), - type = Video, + type = "Video 📺", topics = listOf( Topic( id = "1", @@ -585,7 +584,7 @@ private val sampleNewsResources = listOf( url = "https://youtu.be/r5JgIyS3t3s", headerImageUrl = "https://i.ytimg.com/vi/r5JgIyS3t3s/maxresdefault.jpg", publishDate = Instant.parse("2021-11-08T00:00:00.000Z"), - type = Video, + type = "Video 📺", topics = listOf( Topic( id = "1", diff --git a/feature/topic/src/test/java/com/google/samples/apps/nowinandroid/feature/topic/TopicViewModelTest.kt b/feature/topic/src/test/java/com/google/samples/apps/nowinandroid/feature/topic/TopicViewModelTest.kt index d365232d7..8c6253d60 100644 --- a/feature/topic/src/test/java/com/google/samples/apps/nowinandroid/feature/topic/TopicViewModelTest.kt +++ b/feature/topic/src/test/java/com/google/samples/apps/nowinandroid/feature/topic/TopicViewModelTest.kt @@ -20,7 +20,6 @@ import androidx.lifecycle.SavedStateHandle import com.google.samples.apps.nowinandroid.core.data.repository.CompositeUserNewsResourceRepository import com.google.samples.apps.nowinandroid.core.model.data.FollowableTopic import com.google.samples.apps.nowinandroid.core.model.data.NewsResource -import com.google.samples.apps.nowinandroid.core.model.data.NewsResourceType.Video 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 @@ -258,7 +257,7 @@ private val sampleNewsResources = listOf( url = "https://youtu.be/-fJ6poHQrjM", headerImageUrl = "https://i.ytimg.com/vi/-fJ6poHQrjM/maxresdefault.jpg", publishDate = Instant.parse("2021-11-09T00:00:00.000Z"), - type = Video, + type = "Video 📺", topics = listOf( Topic( id = "0",