Skip to content

Commit fd94c7b

Browse files
committed
Switch from AsyncImage to PodcastImage and remove coil from the dependencies.
1 parent 0bfe3ae commit fd94c7b

File tree

20 files changed

+210
-178
lines changed

20 files changed

+210
-178
lines changed

Jetcaster/designsystem/src/main/java/com/example/jetcaster/designsystem/component/PodcastImage.kt

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,31 +18,36 @@ package com.example.jetcaster.designsystem.component
1818

1919
import androidx.compose.foundation.Image
2020
import androidx.compose.foundation.background
21+
import androidx.compose.foundation.isSystemInDarkTheme
2122
import androidx.compose.foundation.layout.Box
2223
import androidx.compose.foundation.layout.fillMaxSize
2324
import androidx.compose.foundation.layout.size
2425
import androidx.compose.material3.CircularProgressIndicator
25-
import androidx.compose.material3.MaterialTheme
2626
import androidx.compose.runtime.Composable
2727
import androidx.compose.runtime.getValue
2828
import androidx.compose.runtime.mutableStateOf
2929
import androidx.compose.runtime.remember
3030
import androidx.compose.runtime.setValue
3131
import androidx.compose.ui.Alignment
3232
import androidx.compose.ui.Modifier
33+
import androidx.compose.ui.graphics.Brush
34+
import androidx.compose.ui.graphics.Color
3335
import androidx.compose.ui.layout.ContentScale
3436
import androidx.compose.ui.platform.LocalContext
3537
import androidx.compose.ui.unit.dp
3638
import coil.compose.AsyncImagePainter
3739
import coil.compose.rememberAsyncImagePainter
3840
import coil.request.ImageRequest
41+
import com.example.jetcaster.designsystem.theme.surfaceContainerDark
42+
import com.example.jetcaster.designsystem.theme.surfaceContainerLight
3943

4044
@Composable
4145
fun PodcastImage(
4246
podcastImageUrl: String,
4347
contentDescription: String?,
4448
modifier: Modifier = Modifier,
4549
contentScale: ContentScale = ContentScale.Crop,
50+
placeholderBrush: Brush = thumbnailPlaceholderDefaultBrush(),
4651
) {
4752
var imagePainterState by remember {
4853
mutableStateOf<AsyncImagePainter.State>(AsyncImagePainter.State.Empty)
@@ -73,8 +78,9 @@ fun PodcastImage(
7378
else -> {
7479
Box(
7580
modifier = Modifier
81+
.background(placeholderBrush)
7682
.fillMaxSize()
77-
.background(MaterialTheme.colorScheme.surfaceContainerHigh)
83+
7884
)
7985
}
8086
}
@@ -87,3 +93,14 @@ fun PodcastImage(
8793
)
8894
}
8995
}
96+
97+
@Composable
98+
private fun podcastImageBackgroundColor(
99+
isInDarkMode: Boolean = isSystemInDarkTheme()
100+
): Color {
101+
return if (isInDarkMode) {
102+
surfaceContainerDark
103+
} else {
104+
surfaceContainerLight
105+
}
106+
}

Jetcaster/tv-app/src/main/java/com/example/jetcaster/tv/ui/component/thumbnailPlaceholder.kt renamed to Jetcaster/designsystem/src/main/java/com/example/jetcaster/designsystem/component/thumbnailPlaceholder.kt

Lines changed: 25 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -14,19 +14,38 @@
1414
* limitations under the License.
1515
*/
1616

17-
package com.example.jetcaster.tv.ui.component
17+
package com.example.jetcaster.designsystem.component
1818

19+
import androidx.compose.foundation.isSystemInDarkTheme
1920
import androidx.compose.runtime.Composable
2021
import androidx.compose.ui.graphics.Brush
22+
import androidx.compose.ui.graphics.Color
2123
import androidx.compose.ui.graphics.SolidColor
2224
import androidx.compose.ui.graphics.painter.BrushPainter
23-
import androidx.tv.material3.ExperimentalTvMaterial3Api
24-
import androidx.tv.material3.MaterialTheme
25+
import com.example.jetcaster.designsystem.theme.surfaceVariantDark
26+
import com.example.jetcaster.designsystem.theme.surfaceVariantLight
2527

26-
@OptIn(ExperimentalTvMaterial3Api::class)
2728
@Composable
28-
internal fun thumbnailPlaceholder(
29-
brush: Brush = SolidColor(MaterialTheme.colorScheme.surfaceVariant)
29+
fun thumbnailPlaceholder(
30+
brush: Brush = thumbnailPlaceholderDefaultBrush()
3031
): BrushPainter {
3132
return BrushPainter(brush)
3233
}
34+
35+
@Composable
36+
internal fun thumbnailPlaceholderDefaultBrush(
37+
color: Color = thumbnailPlaceHolderDefaultColor()
38+
): Brush {
39+
return SolidColor(color)
40+
}
41+
42+
@Composable
43+
private fun thumbnailPlaceHolderDefaultColor(
44+
isInDarkMode: Boolean = isSystemInDarkTheme()
45+
): Color {
46+
return if (isInDarkMode) {
47+
surfaceVariantDark
48+
} else {
49+
surfaceVariantLight
50+
}
51+
}

Jetcaster/tv-app/build.gradle.kts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -40,8 +40,10 @@ android {
4040
buildTypes {
4141
getByName("release") {
4242
isMinifyEnabled = true
43-
proguardFiles(getDefaultProguardFile("proguard-android-optimize.txt"),
44-
"proguard-rules.pro")
43+
proguardFiles(
44+
getDefaultProguardFile("proguard-android-optimize.txt"),
45+
"proguard-rules.pro"
46+
)
4547
}
4648
}
4749

@@ -79,15 +81,13 @@ dependencies {
7981
implementation(libs.androidx.lifecycle.runtime.compose)
8082
implementation(libs.androidx.activity.compose)
8183
implementation(libs.androidx.navigation.compose)
82-
implementation(libs.coil.kt.compose)
8384

8485
// Dependency injection
8586
implementation(libs.androidx.hilt.navigation.compose)
8687
implementation(libs.hilt.android)
8788
implementation(project(":core:model"))
8889
ksp(libs.hilt.compiler)
8990

90-
9191
implementation(project(":core"))
9292
implementation(project(":designsystem"))
9393

Jetcaster/tv-app/src/main/java/com/example/jetcaster/tv/model/PodcastList.kt

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,9 +17,9 @@
1717
package com.example.jetcaster.tv.model
1818

1919
import androidx.compose.runtime.Immutable
20-
import com.example.jetcaster.core.data.database.model.PodcastWithExtraInfo
20+
import com.example.jetcaster.core.model.PodcastInfo
2121

2222
@Immutable
2323
data class PodcastList(
24-
val member: List<PodcastWithExtraInfo>
25-
) : List<PodcastWithExtraInfo> by member
24+
val member: List<PodcastInfo>
25+
) : List<PodcastInfo> by member

Jetcaster/tv-app/src/main/java/com/example/jetcaster/tv/ui/JetcasterApp.kt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -141,7 +141,7 @@ private fun Route(jetcasterAppState: JetcasterAppState) {
141141
LibraryScreen(
142142
navigateToDiscover = jetcasterAppState::navigateToDiscover,
143143
showPodcastDetails = {
144-
jetcasterAppState.showPodcastDetails(it.podcast.uri)
144+
jetcasterAppState.showPodcastDetails(it.uri)
145145
},
146146
playEpisode = {
147147
jetcasterAppState.playEpisode()
@@ -156,7 +156,7 @@ private fun Route(jetcasterAppState: JetcasterAppState) {
156156
composable(Screen.Search.route) {
157157
SearchScreen(
158158
onPodcastSelected = {
159-
jetcasterAppState.showPodcastDetails(it.podcast.uri)
159+
jetcasterAppState.showPodcastDetails(it.uri)
160160
},
161161
modifier = Modifier
162162
.padding(JetcasterAppDefaults.overScanMargin.default.intoPaddingValues())

Jetcaster/tv-app/src/main/java/com/example/jetcaster/tv/ui/component/Background.kt

Lines changed: 32 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -23,43 +23,54 @@ import androidx.compose.runtime.Composable
2323
import androidx.compose.ui.Alignment
2424
import androidx.compose.ui.Modifier
2525
import androidx.compose.ui.graphics.Color
26-
import com.example.jetcaster.core.data.database.model.Podcast
2726
import com.example.jetcaster.core.model.PlayerEpisode
27+
import com.example.jetcaster.core.model.PodcastInfo
2828
import com.example.jetcaster.designsystem.component.ImageBackgroundRadialGradientScrim
2929

3030
@Composable
31-
internal fun Background(
32-
podcast: Podcast,
33-
modifier: Modifier = Modifier,
34-
) = Background(imageUrl = podcast.imageUrl, modifier)
35-
36-
@Composable
37-
internal fun Background(
38-
episode: PlayerEpisode,
31+
internal fun BackgroundContainer(
32+
playerEpisode: PlayerEpisode,
3933
modifier: Modifier = Modifier,
40-
) = Background(imageUrl = episode.podcastImageUrl, modifier)
34+
contentAlignment: Alignment = Alignment.Center,
35+
content: @Composable BoxScope.() -> Unit
36+
) =
37+
BackgroundContainer(
38+
imageUrl = playerEpisode.podcastImageUrl,
39+
modifier,
40+
contentAlignment,
41+
content
42+
)
4143

4244
@Composable
43-
internal fun Background(
44-
imageUrl: String?,
45+
internal fun BackgroundContainer(
46+
podcastInfo: PodcastInfo,
4547
modifier: Modifier = Modifier,
46-
) {
47-
ImageBackgroundRadialGradientScrim(
48-
url = imageUrl,
49-
colors = listOf(Color.Black, Color.Transparent),
50-
modifier = modifier,
51-
)
52-
}
48+
contentAlignment: Alignment = Alignment.Center,
49+
content: @Composable BoxScope.() -> Unit
50+
) =
51+
BackgroundContainer(imageUrl = podcastInfo.imageUrl, modifier, contentAlignment, content)
5352

5453
@Composable
5554
internal fun BackgroundContainer(
56-
playerEpisode: PlayerEpisode,
55+
imageUrl: String,
5756
modifier: Modifier = Modifier,
5857
contentAlignment: Alignment = Alignment.Center,
5958
content: @Composable BoxScope.() -> Unit
6059
) {
6160
Box(modifier = modifier, contentAlignment = contentAlignment) {
62-
Background(episode = playerEpisode, modifier = Modifier.fillMaxSize())
61+
Background(imageUrl = imageUrl, modifier = Modifier.fillMaxSize())
6362
content()
6463
}
6564
}
65+
66+
@Composable
67+
private fun Background(
68+
imageUrl: String,
69+
modifier: Modifier = Modifier,
70+
) {
71+
ImageBackgroundRadialGradientScrim(
72+
url = imageUrl,
73+
colors = listOf(Color.Black, Color.Transparent),
74+
modifier = modifier,
75+
)
76+
}

Jetcaster/tv-app/src/main/java/com/example/jetcaster/tv/ui/component/Catalog.kt

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -35,8 +35,8 @@ import androidx.tv.foundation.lazy.list.rememberTvLazyListState
3535
import androidx.tv.material3.ExperimentalTvMaterial3Api
3636
import androidx.tv.material3.MaterialTheme
3737
import androidx.tv.material3.Text
38-
import com.example.jetcaster.core.data.database.model.PodcastWithExtraInfo
3938
import com.example.jetcaster.core.model.PlayerEpisode
39+
import com.example.jetcaster.core.model.PodcastInfo
4040
import com.example.jetcaster.tv.R
4141
import com.example.jetcaster.tv.model.EpisodeList
4242
import com.example.jetcaster.tv.model.PodcastList
@@ -46,7 +46,7 @@ import com.example.jetcaster.tv.ui.theme.JetcasterAppDefaults
4646
internal fun Catalog(
4747
podcastList: PodcastList,
4848
latestEpisodeList: EpisodeList,
49-
onPodcastSelected: (PodcastWithExtraInfo) -> Unit,
49+
onPodcastSelected: (PodcastInfo) -> Unit,
5050
onEpisodeSelected: (PlayerEpisode) -> Unit,
5151
modifier: Modifier = Modifier,
5252
state: TvLazyListState = rememberTvLazyListState(),
@@ -83,7 +83,7 @@ internal fun Catalog(
8383
@Composable
8484
private fun PodcastSection(
8585
podcastList: PodcastList,
86-
onPodcastSelected: (PodcastWithExtraInfo) -> Unit,
86+
onPodcastSelected: (PodcastInfo) -> Unit,
8787
modifier: Modifier = Modifier,
8888
title: String? = null,
8989
) {
@@ -142,7 +142,7 @@ private fun Section(
142142
@Composable
143143
private fun PodcastRow(
144144
podcastList: PodcastList,
145-
onPodcastSelected: (PodcastWithExtraInfo) -> Unit,
145+
onPodcastSelected: (PodcastInfo) -> Unit,
146146
modifier: Modifier = Modifier,
147147
contentPadding: PaddingValues = PaddingValues(),
148148
horizontalArrangement: Arrangement.Horizontal =
@@ -155,7 +155,7 @@ private fun PodcastRow(
155155
) {
156156
items(podcastList) {
157157
PodcastCard(
158-
podcast = it.podcast,
158+
podcastInfo = it,
159159
onClick = { onPodcastSelected(it) },
160160
modifier = Modifier.width(JetcasterAppDefaults.cardWidth.medium)
161161
)

Jetcaster/tv-app/src/main/java/com/example/jetcaster/tv/ui/component/EpisodeCard.kt

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@ package com.example.jetcaster.tv.ui.component
1919
import androidx.compose.foundation.interaction.MutableInteractionSource
2020
import androidx.compose.foundation.layout.Column
2121
import androidx.compose.foundation.layout.Spacer
22-
import androidx.compose.foundation.layout.fillMaxSize
2322
import androidx.compose.foundation.layout.height
2423
import androidx.compose.foundation.layout.padding
2524
import androidx.compose.foundation.layout.size
@@ -36,7 +35,6 @@ import androidx.tv.material3.ExperimentalTvMaterial3Api
3635
import androidx.tv.material3.MaterialTheme
3736
import androidx.tv.material3.Text
3837
import androidx.tv.material3.WideCardLayout
39-
import coil.compose.AsyncImage
4038
import com.example.jetcaster.core.model.PlayerEpisode
4139
import com.example.jetcaster.tv.ui.theme.JetcasterAppDefaults
4240

@@ -78,12 +76,7 @@ private fun EpisodeThumbnail(
7876
scale = CardScale.None,
7977
modifier = modifier,
8078
) {
81-
AsyncImage(
82-
model = playerEpisode.podcastImageUrl,
83-
contentDescription = null,
84-
placeholder = thumbnailPlaceholder(),
85-
modifier = Modifier.fillMaxSize()
86-
)
79+
Thumbnail(episode = playerEpisode, size = JetcasterAppDefaults.thumbnailSize.episode)
8780
}
8881
}
8982

Jetcaster/tv-app/src/main/java/com/example/jetcaster/tv/ui/component/PodcastCard.kt

Lines changed: 6 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@
1717
package com.example.jetcaster.tv.ui.component
1818

1919
import androidx.compose.foundation.layout.padding
20-
import androidx.compose.foundation.layout.size
2120
import androidx.compose.runtime.Composable
2221
import androidx.compose.ui.Modifier
2322
import androidx.compose.ui.unit.dp
@@ -26,14 +25,13 @@ import androidx.tv.material3.CardScale
2625
import androidx.tv.material3.ExperimentalTvMaterial3Api
2726
import androidx.tv.material3.StandardCardLayout
2827
import androidx.tv.material3.Text
29-
import coil.compose.AsyncImage
30-
import com.example.jetcaster.core.data.database.model.Podcast
28+
import com.example.jetcaster.core.model.PodcastInfo
3129
import com.example.jetcaster.tv.ui.theme.JetcasterAppDefaults
3230

3331
@OptIn(ExperimentalTvMaterial3Api::class)
3432
@Composable
3533
internal fun PodcastCard(
36-
podcast: Podcast,
34+
podcastInfo: PodcastInfo,
3735
onClick: () -> Unit,
3836
modifier: Modifier = Modifier,
3937
) {
@@ -44,16 +42,14 @@ internal fun PodcastCard(
4442
interactionSource = it,
4543
scale = CardScale.None,
4644
) {
47-
AsyncImage(
48-
model = podcast.imageUrl,
49-
contentDescription = null,
50-
placeholder = thumbnailPlaceholder(),
51-
modifier = Modifier.size(JetcasterAppDefaults.thumbnailSize.podcast)
45+
Thumbnail(
46+
podcastInfo = podcastInfo,
47+
size = JetcasterAppDefaults.thumbnailSize.podcast
5248
)
5349
}
5450
},
5551
title = {
56-
Text(text = podcast.title, modifier = Modifier.padding(top = 12.dp))
52+
Text(text = podcastInfo.title, modifier = Modifier.padding(top = 12.dp))
5753
},
5854
modifier = modifier,
5955
)

0 commit comments

Comments
 (0)