Replace `NewsResourceType` enum with simpler String type

See this discussion for rationale: https://github.com/android/nowinandroid/discussions/901
pull/902/head
Simon Marquis 1 year ago
parent 153b34fd50
commit 0377fd8712

@ -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),
),
)

@ -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",

@ -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)
}
}

@ -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(

@ -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"),
)
}
}

@ -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 = "DAC",
)

@ -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

@ -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(

@ -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 {
@ -31,12 +29,3 @@ class InstantConverter {
instant?.toEpochMilliseconds()
}
class NewsResourceTypeConverter {
@TypeConverter
fun newsResourceTypeToString(value: NewsResourceType?): String? =
value?.let(NewsResourceType::serializedName)
@TypeConverter
fun stringToNewsResourceType(serializedName: String?): NewsResourceType =
serializedName.asNewsResourceType()
}

@ -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<Topic>,
)

@ -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
}

@ -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<FollowableTopic>,
val isSaved: Boolean,
val hasBeenViewed: Boolean,

@ -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<String> = 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<NetworkTopic> = listOf(),
)

@ -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<NewsResourceType> {
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)
}

@ -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 */

@ -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),
)
}
}

@ -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<NewsResource> = 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<NewsResource> = 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<NewsResource> = 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<NewsResource> = listOf(
url = "https://developer.android.com/jetpack/androidx/versions/all-channel",
headerImageUrl = "",
publishDate = Instant.parse("2022-10-01T00:00:00.000Z"),
type = Unknown,
type = "Unknown",
topics = listOf(topicsTestData[2]),
),
)

@ -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<UserNewsResource> = 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<UserNewsResource> = 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<UserNewsResource> = 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<UserNewsResource> = UserData(
url = "https://developer.android.com/jetpack/androidx/versions/all-channel",
headerImageUrl = "",
publishDate = Instant.parse("2022-10-01T00:00:00.000Z"),
type = Unknown,
type = "Unknown",
topics = listOf(topicsTestData[2]),
),
userData = userData,

@ -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.isNotEmpty()) {
stringResource(R.string.card_meta_data_text, formattedDate, resourceType)
} else {
formattedDate
},

@ -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,

@ -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",

@ -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",

Loading…
Cancel
Save