A fully functional Android app built entirely with Kotlin and Jetpack Compose
Add topic icon on topic chips
Caren Chang635abb4dc2ad
diff --git a/feature-foryou/src/main/java/com/google/samples/apps/nowinandroid/feature/foryou/ForYouScreen.kt b/feature-foryou/src/main/java/com/google/samples/apps/nowinandroid/feature/foryou/ForYouScreen.ktindex 477e05e13..cc2650112 100644--- a/feature-foryou/src/main/java/com/google/samples/apps/nowinandroid/feature/foryou/ForYouScreen.kt+++ b/feature-foryou/src/main/java/com/google/samples/apps/nowinandroid/feature/foryou/ForYouScreen.kt@@ -30,6 +30,7 @@ import androidx.compose.foundation.layout.heightInimport androidx.compose.foundation.layout.onlyimport androidx.compose.foundation.layout.paddingimport androidx.compose.foundation.layout.safeDrawing+import androidx.compose.foundation.layout.sizeimport androidx.compose.foundation.layout.widthimport androidx.compose.foundation.layout.windowInsetsPaddingimport androidx.compose.foundation.layout.wrapContentSize@@ -56,6 +57,7 @@ import androidx.compose.ui.Alignmentimport androidx.compose.ui.Modifierimport androidx.compose.ui.platform.LocalContextimport androidx.compose.ui.platform.LocalDensity+import androidx.compose.ui.res.painterResourceimport androidx.compose.ui.res.stringResourceimport androidx.compose.ui.text.style.TextAlignimport androidx.compose.ui.tooling.preview.Preview@@ -64,6 +66,7 @@ import androidx.compose.ui.unit.maximport androidx.compose.ui.unit.spimport androidx.core.content.ContextCompat.startActivityimport androidx.hilt.navigation.compose.hiltViewModel+import coil.compose.AsyncImageimport com.google.samples.apps.nowinandroid.core.model.data.Authorimport com.google.samples.apps.nowinandroid.core.model.data.FollowableAuthorimport com.google.samples.apps.nowinandroid.core.model.data.FollowableTopic@@ -275,6 +278,7 @@ private fun TopicSelection(SingleTopicButton(name = it.topic.name,topicId = it.topic.id,+ imageUrl = it.topic.imageUrl,isSelected = it.isFollowed,onClick = onTopicCheckedChanged)@@ -287,6 +291,7 @@ private fun TopicSelection(private fun SingleTopicButton(name: String,topicId: String,+ imageUrl: String,isSelected: Boolean,onClick: (String, Boolean) -> Unit) {@@ -304,6 +309,9 @@ private fun SingleTopicButton(verticalAlignment = Alignment.CenterVertically,modifier = Modifier.padding(start = 12.dp, end = 8.dp)) {+ TopicIcon(+ imageUrl = imageUrl+ )Text(text = name,style = NiaTypography.titleSmall,@@ -326,6 +334,22 @@ private fun SingleTopicButton(}}+@Composable+fun TopicIcon(+ modifier: Modifier = Modifier,+ imageUrl: String+) {+ AsyncImage(+ // TODO b/228077205, show loading image visual instead of static placeholder+ placeholder = painterResource(R.drawable.ic_icon_placeholder),+ model = imageUrl,+ contentDescription = null, // decorative+ modifier = modifier+ .padding(10.dp)+ .size(32.dp)+ )+}+@Preview@Composablefun ForYouScreenLoading() {diff --git a/feature-foryou/src/main/res/drawable/ic_icon_placeholder.xml b/feature-foryou/src/main/res/drawable/ic_icon_placeholder.xmlnew file mode 100644index 000000000..742dd344f--- /dev/null+++ b/feature-foryou/src/main/res/drawable/ic_icon_placeholder.xml@@ -0,0 +1,33 @@+<?xml version="1.0" encoding="utf-8"?><!--+ ~ Copyright 2022 The Android Open Source Project+ ~+ ~ Licensed under the Apache License, Version 2.0 (the "License");+ ~ you may not use this file except in compliance with the License.+ ~ You may obtain a copy of the License at+ ~+ ~ https://www.apache.org/licenses/LICENSE-2.0+ ~+ ~ Unless required by applicable law or agreed to in writing, software+ ~ distributed under the License is distributed on an "AS IS" BASIS,+ ~ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.+ ~ See the License for the specific language governing permissions and+ ~ limitations under the License.+ ~/+ -->+<vector xmlns:android="http://schemas.android.com/apk/res/android"+ android:width="64dp"+ android:height="64dp"+ android:viewportWidth="64"+ android:viewportHeight="64">+ <path+ android:fillColor="#FCFCFC"+ android:pathData="M32,32m-32,0a32,32 0,1 1,64 0a32,32 0,1 1,-64 0" />+ <path+ android:fillAlpha="0.02"+ android:fillColor="#7E7576"+ android:pathData="M32,32m-32,0a32,32 0,1 1,64 0a32,32 0,1 1,-64 0" />+ <path+ android:fillAlpha="0.08"+ android:fillColor="#8C4190"+ android:pathData="M32,32m-32,0a32,32 0,1 1,64 0a32,32 0,1 1,-64 0" />+</vector>