From f67f4d1a83042507645377ac1b950d6ae3e21e9a Mon Sep 17 00:00:00 2001 From: Don Turner Date: Wed, 8 May 2024 15:10:11 +0100 Subject: [PATCH] Update ForYou destination to match current deeplink pattern Change-Id: Ia5ab36f2d75d8d061e63c0cac5262503bc93a638 --- .../apps/nowinandroid/navigation/NiaNavHost.kt | 2 +- .../core/notifications/SystemTrayNotifier.kt | 4 ++-- feature/foryou/build.gradle.kts | 1 + .../feature/foryou/navigation/ForYouNavigation.kt | 12 +++++++----- 4 files changed, 11 insertions(+), 8 deletions(-) diff --git a/app/src/main/kotlin/com/google/samples/apps/nowinandroid/navigation/NiaNavHost.kt b/app/src/main/kotlin/com/google/samples/apps/nowinandroid/navigation/NiaNavHost.kt index 23ff1edc7..f40fb0dc0 100644 --- a/app/src/main/kotlin/com/google/samples/apps/nowinandroid/navigation/NiaNavHost.kt +++ b/app/src/main/kotlin/com/google/samples/apps/nowinandroid/navigation/NiaNavHost.kt @@ -44,7 +44,7 @@ fun NiaNavHost( val navController = appState.navController NavHost( navController = navController, - startDestination = ForYouDestination(), + startDestination = ForYouDestination(linkedNewsResourceId = null), modifier = modifier, ) { forYouScreen(onTopicClick = navController::navigateToInterests) diff --git a/core/notifications/src/main/kotlin/com/google/samples/apps/nowinandroid/core/notifications/SystemTrayNotifier.kt b/core/notifications/src/main/kotlin/com/google/samples/apps/nowinandroid/core/notifications/SystemTrayNotifier.kt index 1c9e7ab63..694f7a206 100644 --- a/core/notifications/src/main/kotlin/com/google/samples/apps/nowinandroid/core/notifications/SystemTrayNotifier.kt +++ b/core/notifications/src/main/kotlin/com/google/samples/apps/nowinandroid/core/notifications/SystemTrayNotifier.kt @@ -43,8 +43,8 @@ private const val NEWS_NOTIFICATION_REQUEST_CODE = 0 private const val NEWS_NOTIFICATION_SUMMARY_ID = 1 private const val NEWS_NOTIFICATION_CHANNEL_ID = "" private const val NEWS_NOTIFICATION_GROUP = "NEWS_NOTIFICATIONS" -private const val DEEP_LINK_SCHEME_AND_HOST = "https://www.nowinandroid.apps.samples.google.com" -private const val FOR_YOU_PATH = "foryou" +const val DEEP_LINK_SCHEME_AND_HOST = "https://www.nowinandroid.apps.samples.google.com" +const val FOR_YOU_PATH = "foryou" /** * Implementation of [Notifier] that displays notifications in the system tray. diff --git a/feature/foryou/build.gradle.kts b/feature/foryou/build.gradle.kts index fd41d9a13..f37bf4bb1 100644 --- a/feature/foryou/build.gradle.kts +++ b/feature/foryou/build.gradle.kts @@ -29,6 +29,7 @@ dependencies { implementation(libs.accompanist.permissions) implementation(projects.core.data) implementation(projects.core.domain) + implementation(project(":core:notifications")) testImplementation(libs.hilt.android.testing) testImplementation(libs.robolectric) diff --git a/feature/foryou/src/main/kotlin/com/google/samples/apps/nowinandroid/feature/foryou/navigation/ForYouNavigation.kt b/feature/foryou/src/main/kotlin/com/google/samples/apps/nowinandroid/feature/foryou/navigation/ForYouNavigation.kt index 4704f20fd..4d2799444 100644 --- a/feature/foryou/src/main/kotlin/com/google/samples/apps/nowinandroid/feature/foryou/navigation/ForYouNavigation.kt +++ b/feature/foryou/src/main/kotlin/com/google/samples/apps/nowinandroid/feature/foryou/navigation/ForYouNavigation.kt @@ -21,21 +21,23 @@ import androidx.navigation.NavGraphBuilder import androidx.navigation.NavOptions import androidx.navigation.compose.composable import androidx.navigation.navDeepLink +import com.google.samples.apps.nowinandroid.core.notifications.DEEP_LINK_SCHEME_AND_HOST +import com.google.samples.apps.nowinandroid.core.notifications.FOR_YOU_PATH import com.google.samples.apps.nowinandroid.feature.foryou.ForYouRoute import kotlinx.serialization.Serializable const val LINKED_NEWS_RESOURCE_ID = "linkedNewsResourceId" -private const val DEEP_LINK_URI_PATTERN = - "https://www.nowinandroid.apps.samples.google.com/foryou/{$LINKED_NEWS_RESOURCE_ID}" -@Serializable data class ForYouDestination(val linkedNewsResourceId: String? = null) +private const val DEEP_LINK_BASE_PATH = "$DEEP_LINK_SCHEME_AND_HOST/$FOR_YOU_PATH" -fun NavController.navigateToForYou(navOptions: NavOptions) = navigate(route = ForYouDestination(), navOptions) +@Serializable data class ForYouDestination(val linkedNewsResourceId: String?) + +fun NavController.navigateToForYou(navOptions: NavOptions) = navigate(route = ForYouDestination(linkedNewsResourceId = null), navOptions) fun NavGraphBuilder.forYouScreen(onTopicClick: (String) -> Unit) { composable( deepLinks = listOf( - navDeepLink(basePath = DEEP_LINK_URI_PATTERN), + navDeepLink(basePath = DEEP_LINK_BASE_PATH), ), ) { ForYouRoute(onTopicClick)