Skip to content

Commit 6c57fce

Browse files
committed
Refactor feature modules to navigation3
1 parent 4df9bbc commit 6c57fce

File tree

51 files changed

+1030
-223
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

51 files changed

+1030
-223
lines changed

app/src/main/kotlin/com/google/samples/apps/nowinandroid/navigation/TopLevelDestination.kt

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ import com.google.samples.apps.nowinandroid.feature.foryou.api.navigation.ForYou
2525
import com.google.samples.apps.nowinandroid.feature.foryou.api.navigation.ForYouRoute
2626
import com.google.samples.apps.nowinandroid.feature.interests.api.navigation.InterestsRoute
2727
import kotlin.reflect.KClass
28-
import com.google.samples.apps.nowinandroid.feature.bookmarks.api.R as bookmarksR
28+
import com.google.samples.apps.nowinandroid.feature.bookmarks.impl.R as bookmarksR
2929
import com.google.samples.apps.nowinandroid.feature.foryou.api.R as forYouR
3030
import com.google.samples.apps.nowinandroid.feature.search.api.R as searchR
3131

@@ -62,8 +62,8 @@ enum class TopLevelDestination(
6262
BOOKMARKS(
6363
selectedIcon = NiaIcons.Bookmarks,
6464
unselectedIcon = NiaIcons.BookmarksBorder,
65-
iconTextId = bookmarksR.string.feature_bookmarks_api_title,
66-
titleTextId = bookmarksR.string.feature_bookmarks_api_title,
65+
iconTextId = bookmarksR.string.feature_bookmarks_impl_title,
66+
titleTextId = bookmarksR.string.feature_bookmarks_impl_title,
6767
route = BookmarksRoute::class,
6868
),
6969
INTERESTS(

feature/bookmarks/api/build.gradle.kts

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -16,19 +16,8 @@
1616

1717
plugins {
1818
alias(libs.plugins.nowinandroid.android.feature)
19-
alias(libs.plugins.nowinandroid.android.library.compose)
20-
alias(libs.plugins.nowinandroid.android.library.jacoco)
2119
}
2220

2321
android {
2422
namespace = "com.google.samples.apps.nowinandroid.feature.bookmarks.api"
2523
}
26-
27-
dependencies {
28-
implementation(projects.core.data)
29-
30-
testImplementation(projects.core.testing)
31-
32-
androidTestImplementation(libs.bundles.androidx.compose.ui.test)
33-
androidTestImplementation(projects.core.testing)
34-
}

feature/bookmarks/api/src/main/kotlin/com/google/samples/apps/nowinandroid/feature/bookmarks/api/navigation/BookmarksNavigation.kt

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,6 @@ package com.google.samples.apps.nowinandroid.feature.bookmarks.api.navigation
1919
import androidx.navigation.NavController
2020
import androidx.navigation.NavGraphBuilder
2121
import androidx.navigation.NavOptions
22-
import androidx.navigation.compose.composable
23-
import com.google.samples.apps.nowinandroid.feature.bookmarks.api.BookmarksRoute
2422
import kotlinx.serialization.Serializable
2523

2624
@Serializable object BookmarksRoute
@@ -32,7 +30,10 @@ fun NavGraphBuilder.bookmarksScreen(
3230
onTopicClick: (String) -> Unit,
3331
onShowSnackbar: suspend (String, String?) -> Boolean,
3432
) {
35-
composable<BookmarksRoute> {
36-
BookmarksRoute(onTopicClick, onShowSnackbar)
37-
}
33+
// composable<BookmarksRoute> {
34+
// BookmarksRoute(
35+
// onTopicClick,
36+
// onShowSnackbar
37+
// )
38+
// }
3839
}

feature/bookmarks/api/src/main/res/drawable/feature_bookmarks_api_mg_empty_bookmarks.xml

Lines changed: 0 additions & 57 deletions
This file was deleted.

feature/bookmarks/impl/build.gradle.kts

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,4 +23,14 @@ android {
2323
namespace = "com.google.samples.apps.nowinandroid.feature.bookmarks.impl"
2424
}
2525

26-
dependencies { }
26+
dependencies {
27+
implementation(projects.core.data)
28+
implementation(projects.feature.bookmarks.api)
29+
implementation(projects.core.navigation)
30+
implementation(projects.feature.topic.api)
31+
32+
testImplementation(projects.core.testing)
33+
34+
androidTestImplementation(libs.bundles.androidx.compose.ui.test)
35+
androidTestImplementation(projects.core.testing)
36+
}
Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
* limitations under the License.
1515
*/
1616

17-
package com.google.samples.apps.nowinandroid.feature.bookmarks.api
17+
package com.google.samples.apps.nowinandroid.feature.bookmarks.impl
1818

1919
import androidx.activity.ComponentActivity
2020
import androidx.compose.runtime.CompositionLocalProvider
@@ -63,7 +63,7 @@ class BookmarksScreenTest {
6363

6464
composeTestRule
6565
.onNodeWithContentDescription(
66-
composeTestRule.activity.resources.getString(R.string.feature_bookmarks_loading),
66+
composeTestRule.activity.resources.getString(R.string.feature_bookmarks_api_loading),
6767
)
6868
.assertExists()
6969
}
@@ -160,13 +160,13 @@ class BookmarksScreenTest {
160160

161161
composeTestRule
162162
.onNodeWithText(
163-
composeTestRule.activity.getString(R.string.feature_bookmarks_empty_error),
163+
composeTestRule.activity.getString(R.string.feature_bookmarks_api_empty_error),
164164
)
165165
.assertExists()
166166

167167
composeTestRule
168168
.onNodeWithText(
169-
composeTestRule.activity.getString(R.string.feature_bookmarks_empty_description),
169+
composeTestRule.activity.getString(R.string.feature_bookmarks_api_empty_description),
170170
)
171171
.assertExists()
172172
}
File renamed without changes.
Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
* limitations under the License.
1515
*/
1616

17-
package com.google.samples.apps.nowinandroid.feature.bookmarks.api
17+
package com.google.samples.apps.nowinandroid.feature.bookmarks.impl
1818

1919
import androidx.annotation.VisibleForTesting
2020
import androidx.compose.foundation.Image
@@ -112,8 +112,8 @@ internal fun BookmarksScreen(
112112
undoBookmarkRemoval: () -> Unit = {},
113113
clearUndoState: () -> Unit = {},
114114
) {
115-
val bookmarkRemovedMessage = stringResource(id = R.string.feature_bookmarks_api_removed)
116-
val undoText = stringResource(id = R.string.feature_bookmarks_api_undo)
115+
val bookmarkRemovedMessage = stringResource(id = R.string.feature_bookmarks_impl_removed)
116+
val undoText = stringResource(id = R.string.feature_bookmarks_impl_undo)
117117

118118
LaunchedEffect(shouldDisplayUndoBookmark) {
119119
if (shouldDisplayUndoBookmark) {
@@ -155,7 +155,7 @@ private fun LoadingState(modifier: Modifier = Modifier) {
155155
.fillMaxWidth()
156156
.wrapContentSize()
157157
.testTag("forYou:loading"),
158-
contentDesc = stringResource(id = R.string.feature_bookmarks_api_loading),
158+
contentDesc = stringResource(id = R.string.feature_bookmarks_impl_loading),
159159
)
160160
}
161161

@@ -228,15 +228,15 @@ private fun EmptyState(modifier: Modifier = Modifier) {
228228
val iconTint = LocalTintTheme.current.iconTint
229229
Image(
230230
modifier = Modifier.fillMaxWidth(),
231-
painter = painterResource(id = R.drawable.feature_bookmarks_api_mg_empty_bookmarks),
231+
painter = painterResource(id = R.drawable.feature_bookmarks_impl_mg_empty_bookmarks),
232232
colorFilter = if (iconTint != Color.Unspecified) ColorFilter.tint(iconTint) else null,
233233
contentDescription = null,
234234
)
235235

236236
Spacer(modifier = Modifier.height(48.dp))
237237

238238
Text(
239-
text = stringResource(id = R.string.feature_bookmarks_api_empty_error),
239+
text = stringResource(id = R.string.feature_bookmarks_impl_empty_error),
240240
modifier = Modifier.fillMaxWidth(),
241241
textAlign = TextAlign.Center,
242242
style = MaterialTheme.typography.titleMedium,
@@ -246,7 +246,7 @@ private fun EmptyState(modifier: Modifier = Modifier) {
246246
Spacer(modifier = Modifier.height(8.dp))
247247

248248
Text(
249-
text = stringResource(id = R.string.feature_bookmarks_api_empty_description),
249+
text = stringResource(id = R.string.feature_bookmarks_impl_empty_description),
250250
modifier = Modifier.fillMaxWidth(),
251251
textAlign = TextAlign.Center,
252252
style = MaterialTheme.typography.bodyMedium,
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
* limitations under the License.
1515
*/
1616

17-
package com.google.samples.apps.nowinandroid.feature.bookmarks.api
17+
package com.google.samples.apps.nowinandroid.feature.bookmarks.impl
1818

1919
import androidx.compose.runtime.getValue
2020
import androidx.compose.runtime.mutableStateOf
Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
/*
2+
* Copyright 2025 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+
package com.google.samples.apps.nowinandroid.feature.bookmarks.impl.navigation
18+
19+
import androidx.compose.material3.SnackbarDuration.Short
20+
import androidx.compose.material3.SnackbarHostState
21+
import androidx.compose.material3.SnackbarResult.ActionPerformed
22+
import androidx.compose.runtime.compositionLocalOf
23+
import androidx.navigation3.runtime.EntryProviderBuilder
24+
import androidx.navigation3.runtime.entry
25+
import com.google.samples.apps.nowinandroid.core.navigation.NiaBackStack
26+
import com.google.samples.apps.nowinandroid.feature.bookmarks.api.navigation.BookmarksRoute
27+
import com.google.samples.apps.nowinandroid.feature.bookmarks.impl.BookmarksRoute
28+
import com.google.samples.apps.nowinandroid.feature.topic.api.navigation.navigateToTopic
29+
import dagger.Module
30+
import dagger.Provides
31+
import dagger.hilt.InstallIn
32+
import dagger.hilt.android.components.ActivityComponent
33+
import dagger.multibindings.IntoSet
34+
35+
@Module
36+
@InstallIn(ActivityComponent::class)
37+
object BookmarksModule {
38+
39+
@Provides
40+
@IntoSet
41+
fun provideBookmarksEntryProviderBuilder(
42+
backStack: NiaBackStack,
43+
): EntryProviderBuilder<Any>.() -> @JvmSuppressWildcards Unit = {
44+
entry<BookmarksRoute> {
45+
val snackbarHostState = LocalSnackbarHostState.current
46+
BookmarksRoute(
47+
onTopicClick = backStack::navigateToTopic,
48+
onShowSnackbar = { message, action ->
49+
snackbarHostState.showSnackbar(
50+
message = message,
51+
actionLabel = action,
52+
duration = Short,
53+
) == ActionPerformed
54+
}
55+
)
56+
}
57+
}
58+
}
59+
60+
val LocalSnackbarHostState = compositionLocalOf<SnackbarHostState> {
61+
error("host state should be initialzied at runtime")
62+
}

0 commit comments

Comments
 (0)