Implement custom chrome tabs in NewsResourceCardList as well

Change-Id: Ie5851666117a7c756b3d9ad02d6e17be0d3ba904
pull/465/head
Caren 2 years ago
parent 55c3ebd085
commit 45f8e069c5

@ -73,7 +73,7 @@ fun LazyGridScope.newsFeed(
}
}
private fun launchCustomChromeTab(context: Context, uri: Uri, toolbarColor: Int) {
fun launchCustomChromeTab(context: Context, uri: Uri, toolbarColor: Int) {
val customTabBarColor = CustomTabColorSchemeParams.Builder()
.setToolbarColor(toolbarColor).build()
val customTabsIntent = CustomTabsIntent.Builder()

@ -20,7 +20,9 @@ import android.content.Intent
import android.net.Uri
import androidx.compose.foundation.lazy.LazyListScope
import androidx.compose.foundation.lazy.items
import androidx.compose.material3.MaterialTheme
import androidx.compose.ui.Modifier
import androidx.compose.ui.graphics.toArgb
import androidx.compose.ui.platform.LocalContext
import androidx.core.content.ContextCompat
import com.google.samples.apps.nowinandroid.core.model.data.NewsResource
@ -47,8 +49,8 @@ fun <T> LazyListScope.newsResourceCardItems(
key = { newsResourceMapper(it).id },
itemContent = { item ->
val newsResource = newsResourceMapper(item)
val launchResourceIntent =
Intent(Intent.ACTION_VIEW, Uri.parse(newsResource.url))
val resourceUrl = Uri.parse(newsResource.url)
val backgroundColor = MaterialTheme.colorScheme.background.toArgb()
val context = LocalContext.current
NewsResourceCardExpanded(
@ -57,7 +59,7 @@ fun <T> LazyListScope.newsResourceCardItems(
onToggleBookmark = { onToggleBookmark(item) },
onClick = {
when (onItemClick) {
null -> ContextCompat.startActivity(context, launchResourceIntent, null)
null -> launchCustomChromeTab(context, resourceUrl, backgroundColor)
else -> onItemClick(item)
}
},

Loading…
Cancel
Save