Change-Id: If0f12500cb55daae98fd7ee0951d3d3384d26b0e # Conflicts: # app/src/testDemo/screenshots/insets_snackbar_compact_medium.png # app/src/testDemo/screenshots/insets_snackbar_expanded_expanded.png # app/src/testDemo/screenshots/insets_snackbar_medium_medium.pngpull/1837/head
@ -1,25 +0,0 @@
|
|||||||
# https://docs.github.com/github/administering-a-repository/configuration-options-for-dependency-updates
|
|
||||||
version: 2
|
|
||||||
updates:
|
|
||||||
- package-ecosystem: "github-actions"
|
|
||||||
directory: "/"
|
|
||||||
schedule:
|
|
||||||
interval: "weekly"
|
|
||||||
- package-ecosystem: "gradle"
|
|
||||||
directory: "/"
|
|
||||||
schedule:
|
|
||||||
interval: "weekly"
|
|
||||||
registries: "*"
|
|
||||||
labels: [ "version update" ]
|
|
||||||
groups:
|
|
||||||
kotlin-ksp:
|
|
||||||
patterns:
|
|
||||||
- "org.jetbrains.kotlin:*"
|
|
||||||
- "org.jetbrains.kotlin.jvm"
|
|
||||||
- "com.google.devtools.ksp"
|
|
||||||
open-pull-requests-limit: 10
|
|
||||||
registries:
|
|
||||||
maven-google:
|
|
||||||
type: "maven-repository"
|
|
||||||
url: "https://maven.google.com"
|
|
||||||
replaces-base: true
|
|
@ -0,0 +1,14 @@
|
|||||||
|
{
|
||||||
|
"$schema": "https://docs.renovatebot.com/renovate-schema.json",
|
||||||
|
"extends": [
|
||||||
|
"local>android/.github:renovate-config"
|
||||||
|
],
|
||||||
|
"baseBranches": [
|
||||||
|
"main"
|
||||||
|
],
|
||||||
|
"gitIgnoredAuthors": [
|
||||||
|
"renovate[bot]@users.noreply.github.com",
|
||||||
|
"github-actions[bot]@users.noreply.github.com",
|
||||||
|
"41898282+github-actions[bot]@users.noreply.github.com"
|
||||||
|
]
|
||||||
|
}
|
@ -0,0 +1,49 @@
|
|||||||
|
/*
|
||||||
|
* Copyright 2024 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.util
|
||||||
|
|
||||||
|
import android.content.res.Configuration
|
||||||
|
import androidx.activity.ComponentActivity
|
||||||
|
import androidx.core.util.Consumer
|
||||||
|
import kotlinx.coroutines.channels.awaitClose
|
||||||
|
import kotlinx.coroutines.flow.callbackFlow
|
||||||
|
import kotlinx.coroutines.flow.conflate
|
||||||
|
import kotlinx.coroutines.flow.distinctUntilChanged
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Convenience wrapper for dark mode checking
|
||||||
|
*/
|
||||||
|
val Configuration.isSystemInDarkTheme
|
||||||
|
get() = (uiMode and Configuration.UI_MODE_NIGHT_MASK) == Configuration.UI_MODE_NIGHT_YES
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Registers listener for configuration changes to retrieve whether system is in dark theme or not.
|
||||||
|
* Immediately upon subscribing, it sends the current value and then registers listener for changes.
|
||||||
|
*/
|
||||||
|
fun ComponentActivity.isSystemInDarkTheme() = callbackFlow {
|
||||||
|
channel.trySend(resources.configuration.isSystemInDarkTheme)
|
||||||
|
|
||||||
|
val listener = Consumer<Configuration> {
|
||||||
|
channel.trySend(it.isSystemInDarkTheme)
|
||||||
|
}
|
||||||
|
|
||||||
|
addOnConfigurationChangedListener(listener)
|
||||||
|
|
||||||
|
awaitClose { removeOnConfigurationChangedListener(listener) }
|
||||||
|
}
|
||||||
|
.distinctUntilChanged()
|
||||||
|
.conflate()
|
Before Width: | Height: | Size: 48 KiB After Width: | Height: | Size: 50 KiB |
Before Width: | Height: | Size: 112 KiB After Width: | Height: | Size: 126 KiB |
Before Width: | Height: | Size: 62 KiB After Width: | Height: | Size: 65 KiB |
Before Width: | Height: | Size: 76 KiB After Width: | Height: | Size: 78 KiB |
Before Width: | Height: | Size: 251 KiB After Width: | Height: | Size: 276 KiB |
Before Width: | Height: | Size: 139 KiB After Width: | Height: | Size: 141 KiB |
Before Width: | Height: | Size: 26 KiB After Width: | Height: | Size: 27 KiB |
Before Width: | Height: | Size: 59 KiB After Width: | Height: | Size: 61 KiB |
Before Width: | Height: | Size: 162 KiB After Width: | Height: | Size: 185 KiB |
Before Width: | Height: | Size: 103 KiB After Width: | Height: | Size: 106 KiB |
Before Width: | Height: | Size: 50 KiB After Width: | Height: | Size: 52 KiB |
Before Width: | Height: | Size: 50 KiB After Width: | Height: | Size: 53 KiB |
Before Width: | Height: | Size: 211 KiB After Width: | Height: | Size: 216 KiB |
Before Width: | Height: | Size: 94 KiB After Width: | Height: | Size: 97 KiB |
@ -0,0 +1,47 @@
|
|||||||
|
/*
|
||||||
|
* Copyright 2025 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.dao
|
||||||
|
|
||||||
|
import android.content.Context
|
||||||
|
import androidx.room.Room
|
||||||
|
import androidx.test.core.app.ApplicationProvider
|
||||||
|
import com.google.samples.apps.nowinandroid.core.database.NiaDatabase
|
||||||
|
import org.junit.After
|
||||||
|
import org.junit.Before
|
||||||
|
|
||||||
|
internal abstract class DatabaseTest {
|
||||||
|
|
||||||
|
private lateinit var db: NiaDatabase
|
||||||
|
protected lateinit var newsResourceDao: NewsResourceDao
|
||||||
|
protected lateinit var topicDao: TopicDao
|
||||||
|
|
||||||
|
@Before
|
||||||
|
fun setup() {
|
||||||
|
db = run {
|
||||||
|
val context = ApplicationProvider.getApplicationContext<Context>()
|
||||||
|
Room.inMemoryDatabaseBuilder(
|
||||||
|
context,
|
||||||
|
NiaDatabase::class.java,
|
||||||
|
).build()
|
||||||
|
}
|
||||||
|
newsResourceDao = db.newsResourceDao()
|
||||||
|
topicDao = db.topicDao()
|
||||||
|
}
|
||||||
|
|
||||||
|
@After
|
||||||
|
fun teardown() = db.close()
|
||||||
|
}
|
@ -0,0 +1,126 @@
|
|||||||
|
/*
|
||||||
|
* Copyright 2024 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.dao
|
||||||
|
|
||||||
|
import com.google.samples.apps.nowinandroid.core.database.model.TopicEntity
|
||||||
|
import kotlinx.coroutines.flow.first
|
||||||
|
import kotlinx.coroutines.test.runTest
|
||||||
|
import org.junit.Test
|
||||||
|
import kotlin.test.assertEquals
|
||||||
|
|
||||||
|
internal class TopicDaoTest : DatabaseTest() {
|
||||||
|
|
||||||
|
@Test
|
||||||
|
fun getTopics() = runTest {
|
||||||
|
insertTopics()
|
||||||
|
|
||||||
|
val savedTopics = topicDao.getTopicEntities().first()
|
||||||
|
|
||||||
|
assertEquals(
|
||||||
|
listOf("1", "2", "3"),
|
||||||
|
savedTopics.map { it.id },
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
fun getTopic() = runTest {
|
||||||
|
insertTopics()
|
||||||
|
|
||||||
|
val savedTopicEntity = topicDao.getTopicEntity("2").first()
|
||||||
|
|
||||||
|
assertEquals("performance", savedTopicEntity.name)
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
fun getTopics_oneOff() = runTest {
|
||||||
|
insertTopics()
|
||||||
|
|
||||||
|
val savedTopics = topicDao.getOneOffTopicEntities()
|
||||||
|
|
||||||
|
assertEquals(
|
||||||
|
listOf("1", "2", "3"),
|
||||||
|
savedTopics.map { it.id },
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
fun getTopics_byId() = runTest {
|
||||||
|
insertTopics()
|
||||||
|
|
||||||
|
val savedTopics = topicDao.getTopicEntities(setOf("1", "2"))
|
||||||
|
.first()
|
||||||
|
|
||||||
|
assertEquals(listOf("compose", "performance"), savedTopics.map { it.name })
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
fun insertTopic_newEntryIsIgnoredIfAlreadyExists() = runTest {
|
||||||
|
insertTopics()
|
||||||
|
topicDao.insertOrIgnoreTopics(
|
||||||
|
listOf(testTopicEntity("1", "compose")),
|
||||||
|
)
|
||||||
|
|
||||||
|
val savedTopics = topicDao.getOneOffTopicEntities()
|
||||||
|
|
||||||
|
assertEquals(3, savedTopics.size)
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
fun upsertTopic_existingEntryIsUpdated() = runTest {
|
||||||
|
insertTopics()
|
||||||
|
topicDao.upsertTopics(
|
||||||
|
listOf(testTopicEntity("1", "newName")),
|
||||||
|
)
|
||||||
|
|
||||||
|
val savedTopics = topicDao.getOneOffTopicEntities()
|
||||||
|
|
||||||
|
assertEquals(3, savedTopics.size)
|
||||||
|
assertEquals("newName", savedTopics.first().name)
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
fun deleteTopics_byId_existingEntriesAreDeleted() = runTest {
|
||||||
|
insertTopics()
|
||||||
|
topicDao.deleteTopics(listOf("1", "2"))
|
||||||
|
|
||||||
|
val savedTopics = topicDao.getOneOffTopicEntities()
|
||||||
|
|
||||||
|
assertEquals(1, savedTopics.size)
|
||||||
|
assertEquals("3", savedTopics.first().id)
|
||||||
|
}
|
||||||
|
|
||||||
|
private suspend fun insertTopics() {
|
||||||
|
val topicEntities = listOf(
|
||||||
|
testTopicEntity("1", "compose"),
|
||||||
|
testTopicEntity("2", "performance"),
|
||||||
|
testTopicEntity("3", "headline"),
|
||||||
|
)
|
||||||
|
topicDao.insertOrIgnoreTopics(topicEntities)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private fun testTopicEntity(
|
||||||
|
id: String = "0",
|
||||||
|
name: String,
|
||||||
|
) = TopicEntity(
|
||||||
|
id = id,
|
||||||
|
name = name,
|
||||||
|
shortDescription = "",
|
||||||
|
longDescription = "",
|
||||||
|
url = "",
|
||||||
|
imageUrl = "",
|
||||||
|
)
|
Before Width: | Height: | Size: 5.5 KiB After Width: | Height: | Size: 5.3 KiB |
Before Width: | Height: | Size: 4.3 KiB After Width: | Height: | Size: 4.1 KiB |
Before Width: | Height: | Size: 4.7 KiB After Width: | Height: | Size: 4.4 KiB |
Before Width: | Height: | Size: 5.4 KiB After Width: | Height: | Size: 5.3 KiB |
Before Width: | Height: | Size: 4.1 KiB After Width: | Height: | Size: 4.3 KiB |
Before Width: | Height: | Size: 4.1 KiB After Width: | Height: | Size: 3.9 KiB |
Before Width: | Height: | Size: 11 KiB After Width: | Height: | Size: 10 KiB |
Before Width: | Height: | Size: 4.7 KiB After Width: | Height: | Size: 4.4 KiB |
Before Width: | Height: | Size: 5.5 KiB After Width: | Height: | Size: 5.3 KiB |
Before Width: | Height: | Size: 10 KiB After Width: | Height: | Size: 10 KiB |
Before Width: | Height: | Size: 4.7 KiB After Width: | Height: | Size: 4.6 KiB |
Before Width: | Height: | Size: 3.7 KiB After Width: | Height: | Size: 3.7 KiB |
Before Width: | Height: | Size: 4.6 KiB After Width: | Height: | Size: 4.7 KiB |
Before Width: | Height: | Size: 3.4 KiB After Width: | Height: | Size: 3.5 KiB |
Before Width: | Height: | Size: 4.2 KiB After Width: | Height: | Size: 4.1 KiB |
Before Width: | Height: | Size: 4.8 KiB After Width: | Height: | Size: 4.9 KiB |
Before Width: | Height: | Size: 3.8 KiB After Width: | Height: | Size: 3.9 KiB |
Before Width: | Height: | Size: 3.8 KiB After Width: | Height: | Size: 4.0 KiB |
Before Width: | Height: | Size: 4.9 KiB After Width: | Height: | Size: 4.9 KiB |
Before Width: | Height: | Size: 3.9 KiB After Width: | Height: | Size: 3.9 KiB |
Before Width: | Height: | Size: 5.5 KiB After Width: | Height: | Size: 5.5 KiB |
Before Width: | Height: | Size: 6.3 KiB After Width: | Height: | Size: 6.4 KiB |
Before Width: | Height: | Size: 5.1 KiB After Width: | Height: | Size: 5.1 KiB |
Before Width: | Height: | Size: 5.3 KiB After Width: | Height: | Size: 5.5 KiB |
Before Width: | Height: | Size: 6.2 KiB After Width: | Height: | Size: 6.4 KiB |
Before Width: | Height: | Size: 5.4 KiB After Width: | Height: | Size: 5.3 KiB |
Before Width: | Height: | Size: 3.2 KiB After Width: | Height: | Size: 3.3 KiB |
Before Width: | Height: | Size: 3.1 KiB After Width: | Height: | Size: 2.9 KiB |
Before Width: | Height: | Size: 3.1 KiB After Width: | Height: | Size: 3.2 KiB |
Before Width: | Height: | Size: 3.2 KiB After Width: | Height: | Size: 3.3 KiB |
Before Width: | Height: | Size: 3.2 KiB After Width: | Height: | Size: 3.1 KiB |
Before Width: | Height: | Size: 3.2 KiB After Width: | Height: | Size: 3.3 KiB |