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

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

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

Loading…
Cancel
Save