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() val customTabBarColor = CustomTabColorSchemeParams.Builder()
.setToolbarColor(toolbarColor).build() .setToolbarColor(toolbarColor).build()
val customTabsIntent = CustomTabsIntent.Builder() val customTabsIntent = CustomTabsIntent.Builder()

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

Loading…
Cancel
Save