Skip to content

Commit 4284e69

Browse files
committed
Merge remote-tracking branch 'github/main' into feb9automerger
* github/main: Bump version to 4 Remove unused DropdownMenu component Route topic chip tap events up to NiaNavHost Apply suggestions from code review Migrate custom room configuration into a convention plugin Update docs/ArchitectureLearningJourney.md - User action follow topic Update docs/ArchitectureLearningJourney.md - Writing data Change-Id: I417abcaba792bbf297a8156bb1c4cf677dcb8bea
2 parents e3e33d8 + d806684 commit 4284e69

File tree

31 files changed

+185
-402
lines changed

31 files changed

+185
-402
lines changed

app-nia-catalog/src/main/java/com/google/samples/apps/niacatalog/ui/Catalog.kt

Lines changed: 5 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,6 @@ import androidx.compose.ui.res.painterResource
3838
import androidx.compose.ui.unit.dp
3939
import com.google.accompanist.flowlayout.FlowRow
4040
import com.google.samples.apps.nowinandroid.core.designsystem.component.NiaButton
41-
import com.google.samples.apps.nowinandroid.core.designsystem.component.NiaDropdownMenuButton
4241
import com.google.samples.apps.nowinandroid.core.designsystem.component.NiaFilterChip
4342
import com.google.samples.apps.nowinandroid.core.designsystem.component.NiaIconToggleButton
4443
import com.google.samples.apps.nowinandroid.core.designsystem.component.NiaNavigationBar
@@ -167,23 +166,6 @@ fun NiaCatalog() {
167166
}
168167
}
169168
item { Text("Dropdown menus", Modifier.padding(top = 16.dp)) }
170-
item {
171-
FlowRow(mainAxisSpacing = 16.dp) {
172-
NiaDropdownMenuButton(
173-
text = { Text("Enabled") },
174-
items = listOf("Item 1", "Item 2", "Item 3"),
175-
onItemClick = {},
176-
itemText = { item -> Text(item) },
177-
)
178-
NiaDropdownMenuButton(
179-
text = { Text("Disabled") },
180-
items = listOf("Item 1", "Item 2", "Item 3"),
181-
onItemClick = {},
182-
itemText = { item -> Text(item) },
183-
enabled = false,
184-
)
185-
}
186-
}
187169
item { Text("Chips", Modifier.padding(top = 16.dp)) }
188170
item {
189171
FlowRow(mainAxisSpacing = 16.dp) {
@@ -315,45 +297,19 @@ fun NiaCatalog() {
315297
item { Text("Tags", Modifier.padding(top = 16.dp)) }
316298
item {
317299
FlowRow(mainAxisSpacing = 16.dp) {
318-
var expandedTopicId by remember { mutableStateOf<String?>(null) }
319-
320-
var firstFollowed by remember { mutableStateOf(false) }
321300
NiaTopicTag(
322-
expanded = expandedTopicId == "Topic 1",
323-
followed = firstFollowed,
324-
onDropdownMenuToggle = { show ->
325-
expandedTopicId = if (show) "Topic 1" else null
326-
},
327-
onFollowClick = { firstFollowed = true },
328-
onUnfollowClick = { firstFollowed = false },
329-
onBrowseClick = {},
301+
followed = true,
302+
onClick = {},
330303
text = { Text(text = "Topic 1".uppercase()) },
331-
followText = { Text(text = "Follow") },
332-
unFollowText = { Text(text = "Unfollow") },
333-
browseText = { Text(text = "Browse topic") },
334304
)
335-
var secondFollowed by remember { mutableStateOf(true) }
336305
NiaTopicTag(
337-
expanded = expandedTopicId == "Topic 2",
338-
followed = secondFollowed,
339-
onDropdownMenuToggle = { show ->
340-
expandedTopicId = if (show) "Topic 2" else null
341-
},
342-
onFollowClick = { secondFollowed = true },
343-
onUnfollowClick = { secondFollowed = false },
344-
onBrowseClick = {},
306+
followed = false,
307+
onClick = {},
345308
text = { Text(text = "Topic 2".uppercase()) },
346-
followText = { Text(text = "Follow") },
347-
unFollowText = { Text(text = "Unfollow") },
348-
browseText = { Text(text = "Browse topic") },
349309
)
350310
NiaTopicTag(
351-
expanded = false,
352311
followed = false,
353-
onDropdownMenuToggle = {},
354-
onFollowClick = {},
355-
onUnfollowClick = {},
356-
onBrowseClick = {},
312+
onClick = {},
357313
text = { Text(text = "Disabled".uppercase()) },
358314
enabled = false,
359315
)

app/build.gradle.kts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,8 +29,8 @@ plugins {
2929
android {
3030
defaultConfig {
3131
applicationId = "com.google.samples.apps.nowinandroid"
32-
versionCode = 3
33-
versionName = "0.0.3" // X.Y.Z; X = Major, Y = minor, Z = Patch level
32+
versionCode = 4
33+
versionName = "0.0.4" // X.Y.Z; X = Major, Y = minor, Z = Patch level
3434

3535
// Custom test runner to set up Hilt dependency graph
3636
testInstrumentationRunner = "com.google.samples.apps.nowinandroid.core.testing.NiaTestRunner"

app/src/main/java/com/google/samples/apps/nowinandroid/navigation/NiaNavHost.kt

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,6 @@ import com.google.samples.apps.nowinandroid.feature.topic.navigation.topicScreen
3737
@Composable
3838
fun NiaNavHost(
3939
navController: NavHostController,
40-
onBackClick: () -> Unit,
4140
modifier: Modifier = Modifier,
4241
startDestination: String = forYouNavigationRoute,
4342
) {
@@ -46,14 +45,18 @@ fun NiaNavHost(
4645
startDestination = startDestination,
4746
modifier = modifier,
4847
) {
49-
forYouScreen()
50-
bookmarksScreen()
48+
// TODO: handle topic clicks from each top level destination
49+
forYouScreen(onTopicClick = {})
50+
bookmarksScreen(onTopicClick = {})
5151
interestsGraph(
52-
navigateToTopic = { topicId ->
52+
onTopicClick = { topicId ->
5353
navController.navigateToTopic(topicId)
5454
},
5555
nestedGraphs = {
56-
topicScreen(onBackClick)
56+
topicScreen(
57+
onBackClick = navController::popBackStack,
58+
onTopicClick = {},
59+
)
5760
},
5861
)
5962
}

app/src/main/java/com/google/samples/apps/nowinandroid/ui/NiaApp.kt

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -178,10 +178,7 @@ fun NiaApp(
178178
)
179179
}
180180

181-
NiaNavHost(
182-
navController = appState.navController,
183-
onBackClick = appState::onBackClick,
184-
)
181+
NiaNavHost(appState.navController)
185182
}
186183

187184
// TODO: We may want to add padding or spacer when the snackbar is shown so that

app/src/main/java/com/google/samples/apps/nowinandroid/ui/NiaAppState.kt

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -136,10 +136,6 @@ class NiaAppState(
136136
}
137137
}
138138

139-
fun onBackClick() {
140-
navController.popBackStack()
141-
}
142-
143139
fun setShowSettingsDialog(shouldShow: Boolean) {
144140
shouldShowSettingsDialog = shouldShow
145141
}

build-logic/convention/build.gradle.kts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ dependencies {
3030
compileOnly(libs.kotlin.gradlePlugin)
3131
compileOnly(libs.firebase.performance.gradle)
3232
compileOnly(libs.firebase.crashlytics.gradle)
33+
compileOnly(libs.ksp.gradlePlugin)
3334
}
3435

3536
gradlePlugin {
@@ -70,6 +71,10 @@ gradlePlugin {
7071
id = "nowinandroid.android.hilt"
7172
implementationClass = "AndroidHiltConventionPlugin"
7273
}
74+
register("androidRoom") {
75+
id = "nowinandroid.android.room"
76+
implementationClass = "AndroidRoomConventionPlugin"
77+
}
7378
register("androidFirebase") {
7479
id = "nowinandroid.android.application.firebase"
7580
implementationClass = "AndroidApplicationFirebaseConventionPlugin"
@@ -78,6 +83,5 @@ gradlePlugin {
7883
id = "nowinandroid.android.application.flavors"
7984
implementationClass = "AndroidApplicationFlavorsConventionPlugin"
8085
}
81-
8286
}
8387
}
Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
/*
2+
* Copyright 2022 The Android Open Source Project
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* https://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
import com.google.devtools.ksp.gradle.KspExtension
18+
import org.gradle.api.Plugin
19+
import org.gradle.api.Project
20+
import org.gradle.api.artifacts.VersionCatalogsExtension
21+
import org.gradle.api.tasks.InputDirectory
22+
import org.gradle.api.tasks.PathSensitive
23+
import org.gradle.api.tasks.PathSensitivity
24+
import org.gradle.kotlin.dsl.configure
25+
import org.gradle.kotlin.dsl.dependencies
26+
import org.gradle.kotlin.dsl.getByType
27+
import org.gradle.process.CommandLineArgumentProvider
28+
import java.io.File
29+
30+
class AndroidRoomConventionPlugin : Plugin<Project> {
31+
32+
override fun apply(target: Project) {
33+
with(target) {
34+
pluginManager.apply("com.google.devtools.ksp")
35+
36+
extensions.configure<KspExtension> {
37+
// The schemas directory contains a schema file for each version of the Room database.
38+
// This is required to enable Room auto migrations.
39+
// See https://developer.android.com/reference/kotlin/androidx/room/AutoMigration.
40+
arg(RoomSchemaArgProvider(File(projectDir, "schemas")))
41+
}
42+
43+
val libs = extensions.getByType<VersionCatalogsExtension>().named("libs")
44+
dependencies {
45+
add("implementation", libs.findLibrary("room.runtime").get())
46+
add("implementation", libs.findLibrary("room.ktx").get())
47+
add("ksp", libs.findLibrary("room.compiler").get())
48+
}
49+
}
50+
}
51+
52+
/**
53+
* https://issuetracker.google.com/issues/132245929
54+
* [Export schemas](https://developer.android.com/training/data-storage/room/migrating-db-versions#export-schemas)
55+
*/
56+
class RoomSchemaArgProvider(
57+
@get:InputDirectory
58+
@get:PathSensitive(PathSensitivity.RELATIVE)
59+
val schemaDir: File,
60+
) : CommandLineArgumentProvider {
61+
override fun asArguments() = listOf("room.schemaLocation=${schemaDir.path}")
62+
}
63+
}

build.gradle.kts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,5 +33,6 @@ plugins {
3333
alias(libs.plugins.firebase.perf) apply false
3434
alias(libs.plugins.gms) apply false
3535
alias(libs.plugins.hilt) apply false
36+
alias(libs.plugins.ksp) apply false
3637
alias(libs.plugins.secrets) apply false
3738
}

core/database/build.gradle.kts

Lines changed: 1 addition & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -22,18 +22,11 @@ plugins {
2222
id("nowinandroid.android.library")
2323
id("nowinandroid.android.library.jacoco")
2424
id("nowinandroid.android.hilt")
25-
alias(libs.plugins.ksp)
25+
id("nowinandroid.android.room")
2626
}
2727

2828
android {
2929
defaultConfig {
30-
// The schemas directory contains a schema file for each version of the Room database.
31-
// This is required to enable Room auto migrations.
32-
// See https://developer.android.com/reference/kotlin/androidx/room/AutoMigration.
33-
ksp {
34-
arg("room.schemaLocation", "$projectDir/schemas")
35-
}
36-
3730
testInstrumentationRunner =
3831
"com.google.samples.apps.nowinandroid.core.testing.NiaTestRunner"
3932
}
@@ -57,10 +50,6 @@ android {
5750
dependencies {
5851
implementation(project(":core:model"))
5952

60-
implementation(libs.room.runtime)
61-
implementation(libs.room.ktx)
62-
ksp(libs.room.compiler)
63-
6453
implementation(libs.kotlinx.coroutines.android)
6554
implementation(libs.kotlinx.datetime)
6655

0 commit comments

Comments
 (0)