A fully functional Android app built entirely with Kotlin and Jetpack Compose
Use Chrome Custom tab for opening articles
Caren55c3ebd0851a
diff --git a/core/ui/build.gradle.kts b/core/ui/build.gradle.ktsindex 794b1573b..c76e4bb27 100644--- a/core/ui/build.gradle.kts+++ b/core/ui/build.gradle.kts@@ -28,6 +28,7 @@ dependencies {implementation(project(":core:model"))implementation(project(":core:domain"))+ implementation(libs.androidx.browser)implementation(libs.androidx.core.ktx)implementation(libs.coil.kt)implementation(libs.coil.kt.compose)diff --git a/core/ui/src/main/java/com/google/samples/apps/nowinandroid/core/ui/NewsFeed.kt b/core/ui/src/main/java/com/google/samples/apps/nowinandroid/core/ui/NewsFeed.ktindex 32308bd63..e72b6286e 100644--- a/core/ui/src/main/java/com/google/samples/apps/nowinandroid/core/ui/NewsFeed.kt+++ b/core/ui/src/main/java/com/google/samples/apps/nowinandroid/core/ui/NewsFeed.kt@@ -16,22 +16,25 @@package com.google.samples.apps.nowinandroid.core.ui-import android.content.Intent+import android.content.Contextimport android.net.Uri+import androidx.browser.customtabs.CustomTabColorSchemeParams+import androidx.browser.customtabs.CustomTabsIntentimport androidx.compose.foundation.lazy.LazyListScopeimport androidx.compose.foundation.lazy.grid.GridCellsimport androidx.compose.foundation.lazy.grid.LazyGridScopeimport androidx.compose.foundation.lazy.grid.LazyVerticalGridimport androidx.compose.foundation.lazy.grid.items+import androidx.compose.material3.MaterialThemeimport androidx.compose.runtime.Composableimport androidx.compose.runtime.getValueimport androidx.compose.runtime.mutableStateOfimport androidx.compose.runtime.remember+import androidx.compose.ui.graphics.toArgbimport androidx.compose.ui.platform.LocalContextimport androidx.compose.ui.tooling.preview.Devicesimport androidx.compose.ui.tooling.preview.Previewimport androidx.compose.ui.unit.dp-import androidx.core.content.ContextCompatimport com.google.samples.apps.nowinandroid.core.designsystem.theme.NiaThemeimport com.google.samples.apps.nowinandroid.core.domain.model.SaveableNewsResourceimport com.google.samples.apps.nowinandroid.core.model.data.previewNewsResources@@ -51,13 +54,13 @@ fun LazyGridScope.newsFeed(val resourceUrl by remember {mutableStateOf(Uri.parse(saveableNewsResource.newsResource.url))}- val launchResourceIntent = Intent(Intent.ACTION_VIEW, resourceUrl)val context = LocalContext.current+ val backgroundColor = MaterialTheme.colorScheme.background.toArgb()NewsResourceCardExpanded(newsResource = saveableNewsResource.newsResource,isBookmarked = saveableNewsResource.isSaved,- onClick = { ContextCompat.startActivity(context, launchResourceIntent, null) },+ onClick = { launchCustomChromeTab(context, resourceUrl, backgroundColor) },onToggleBookmark = {onNewsResourcesCheckedChanged(saveableNewsResource.newsResource.id,@@ -70,6 +73,16 @@ fun LazyGridScope.newsFeed(}}+private fun launchCustomChromeTab(context: Context, uri: Uri, toolbarColor: Int) {+ val customTabBarColor = CustomTabColorSchemeParams.Builder()+ .setToolbarColor(toolbarColor).build()+ val customTabsIntent = CustomTabsIntent.Builder()+ .setDefaultColorSchemeParams(customTabBarColor)+ .build()++ customTabsIntent.launchUrl(context, uri)+}+/*** A sealed hierarchy describing the state of the feed of news resources.*/diff --git a/gradle/libs.versions.toml b/gradle/libs.versions.tomlindex 5892e277d..6022856fe 100644--- a/gradle/libs.versions.toml+++ b/gradle/libs.versions.toml@@ -4,6 +4,7 @@ androidDesugarJdkLibs = "1.2.0"androidGradlePlugin = "7.3.1"androidxActivity = "1.6.1"androidxAppCompat = "1.5.1"+androidxBrowser = "1.4.0"androidxComposeBom = "2022.11.00"androidxComposeCompiler = "1.3.2"androidxComposeRuntimeTracing = "1.0.0-alpha01"@@ -53,6 +54,7 @@ android-desugarJdkLibs = { group = "com.android.tools", name = "desugar_jdk_libsandroidx-activity-compose = { group = "androidx.activity", name = "activity-compose", version.ref = "androidxActivity" }androidx-appcompat = { group = "androidx.appcompat", name = "appcompat", version.ref = "androidxAppCompat" }androidx-benchmark-macro = { group = "androidx.benchmark", name = "benchmark-macro-junit4", version.ref = "androidxMacroBenchmark" }+androidx-browser = { group = "androidx.browser", name = "browser", version.ref = "androidxBrowser" }androidx-compose-bom = { group = "androidx.compose", name = "compose-bom", version.ref = "androidxComposeBom" }androidx-compose-foundation = { group = "androidx.compose.foundation", name = "foundation" }androidx-compose-foundation-layout = { group = "androidx.compose.foundation", name = "foundation-layout" }