Open NewsResource URL when Card is tapped

Bug: 226603463
Change-Id: Ia9d15e9fd85ae1076c7744bf96ad39fd0d5f2e66
pull/2/head
Caren Chang 3 years ago committed by Don Turner
parent ccb822286f
commit 1486a3e503

@ -17,6 +17,7 @@
package com.google.samples.apps.nowinandroid.core.ui package com.google.samples.apps.nowinandroid.core.ui
import androidx.compose.foundation.background import androidx.compose.foundation.background
import androidx.compose.foundation.clickable
import androidx.compose.foundation.layout.Column import androidx.compose.foundation.layout.Column
import androidx.compose.foundation.layout.Row import androidx.compose.foundation.layout.Row
import androidx.compose.foundation.layout.Spacer import androidx.compose.foundation.layout.Spacer
@ -63,10 +64,15 @@ import kotlinx.datetime.Instant
fun NewsResourceCardExpanded( fun NewsResourceCardExpanded(
newsResource: NewsResource, newsResource: NewsResource,
isBookmarked: Boolean, isBookmarked: Boolean,
onToggleBookmark: () -> Unit onToggleBookmark: () -> Unit,
onClick: () -> Unit
) { ) {
Column( Column(
modifier = Modifier.padding(16.dp) modifier = Modifier.padding(16.dp)
.clickable(
onClickLabel = stringResource(R.string.card_tap_action),
onClick = { onClick() }
)
) { ) {
if (!newsResource.headerImageUrl.isNullOrEmpty()) { if (!newsResource.headerImageUrl.isNullOrEmpty()) {
Row { Row {
@ -228,7 +234,7 @@ fun BookmarkButtonBookmarkedPreview() {
fun ExpandedNewsResourcePreview() { fun ExpandedNewsResourcePreview() {
NiaTheme { NiaTheme {
Surface { Surface {
NewsResourceCardExpanded(newsResource, true, {}) NewsResourceCardExpanded(newsResource, true, {}, {})
} }
} }
} }

@ -16,4 +16,6 @@
<resources> <resources>
<string name="bookmark">Bookmark</string> <string name="bookmark">Bookmark</string>
<string name="unbookmark">Unbookmark</string> <string name="unbookmark">Unbookmark</string>
<string name="card_tap_action">Open Resource Link</string>
</resources> </resources>

@ -16,6 +16,8 @@
package com.google.samples.apps.nowinandroid.feature.foryou package com.google.samples.apps.nowinandroid.feature.foryou
import android.content.Intent
import android.net.Uri
import androidx.compose.foundation.layout.Box import androidx.compose.foundation.layout.Box
import androidx.compose.foundation.layout.fillMaxSize import androidx.compose.foundation.layout.fillMaxSize
import androidx.compose.foundation.layout.fillMaxWidth import androidx.compose.foundation.layout.fillMaxWidth
@ -34,10 +36,12 @@ import androidx.compose.runtime.collectAsState
import androidx.compose.runtime.getValue import androidx.compose.runtime.getValue
import androidx.compose.runtime.key import androidx.compose.runtime.key
import androidx.compose.ui.Modifier import androidx.compose.ui.Modifier
import androidx.compose.ui.platform.LocalContext
import androidx.compose.ui.res.stringResource import androidx.compose.ui.res.stringResource
import androidx.compose.ui.semantics.Role import androidx.compose.ui.semantics.Role
import androidx.compose.ui.tooling.preview.Preview import androidx.compose.ui.tooling.preview.Preview
import androidx.compose.ui.unit.dp import androidx.compose.ui.unit.dp
import androidx.core.content.ContextCompat.startActivity
import androidx.hilt.navigation.compose.hiltViewModel import androidx.hilt.navigation.compose.hiltViewModel
import com.google.accompanist.flowlayout.FlowRow import com.google.accompanist.flowlayout.FlowRow
import com.google.samples.apps.nowinandroid.core.model.data.FollowableTopic import com.google.samples.apps.nowinandroid.core.model.data.FollowableTopic
@ -91,12 +95,19 @@ fun ForYouScreen(
} }
items(uiState.feed) { (newsResource: NewsResource, isBookmarked: Boolean) -> items(uiState.feed) { (newsResource: NewsResource, isBookmarked: Boolean) ->
val launchResourceIntent =
Intent(Intent.ACTION_VIEW, Uri.parse(newsResource.url))
val context = LocalContext.current
NewsResourceCardExpanded( NewsResourceCardExpanded(
newsResource = newsResource, newsResource = newsResource,
isBookmarked = isBookmarked, isBookmarked = isBookmarked,
onToggleBookmark = { onToggleBookmark = {
onNewsResourcesCheckedChanged(newsResource.id, !isBookmarked) onNewsResourcesCheckedChanged(newsResource.id, !isBookmarked)
} },
onClick = {
startActivity(context, launchResourceIntent, null)
},
) )
} }
} }

Loading…
Cancel
Save