Skip to content

Commit

Permalink
Migrate to Accompanist rememberCoilPainter()
Browse files Browse the repository at this point in the history
  • Loading branch information
chrisbanes committed Apr 19, 2021
1 parent c44e1d6 commit f6582e7
Show file tree
Hide file tree
Showing 8 changed files with 56 additions and 49 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@

package app.tivi.common.compose

import androidx.compose.foundation.Image
import androidx.compose.foundation.clickable
import androidx.compose.foundation.layout.Box
import androidx.compose.foundation.layout.padding
Expand All @@ -33,7 +34,7 @@ import androidx.compose.ui.res.stringResource
import androidx.compose.ui.unit.dp
import app.tivi.data.entities.TiviShow
import app.tivi.data.entities.TmdbImageEntity
import com.google.accompanist.coil.CoilImage
import com.google.accompanist.coil.rememberCoilPainter

@Composable
fun PosterCard(
Expand All @@ -58,15 +59,14 @@ fun PosterCard(
)
}
if (poster != null) {
CoilImage(
data = poster,
Image(
painter = rememberCoilPainter(poster, fadeIn = true),
contentDescription = stringResource(
R.string.cd_show_poster_image,
show.title ?: "show"
),
fadeIn = true,
modifier = Modifier.matchParentSize(),
contentScale = ContentScale.Crop,
modifier = Modifier.matchParentSize()
)
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@

package app.tivi.common.compose

import androidx.compose.foundation.Image
import androidx.compose.foundation.layout.size
import androidx.compose.foundation.shape.CircleShape
import androidx.compose.material.Icon
Expand All @@ -27,7 +28,7 @@ import androidx.compose.ui.res.painterResource
import androidx.compose.ui.res.stringResource
import androidx.compose.ui.unit.dp
import app.tivi.data.entities.TraktUser
import com.google.accompanist.coil.CoilImage
import com.google.accompanist.coil.rememberCoilPainter

@Composable
fun UserProfileButton(
Expand All @@ -42,12 +43,12 @@ fun UserProfileButton(
) {
when {
loggedIn && user?.avatarUrl != null -> {
CoilImage(
data = user.avatarUrl!!,
Image(
painter = rememberCoilPainter(user.avatarUrl!!),
contentDescription = stringResource(R.string.cd_profile_pic, user.name),
modifier = Modifier
.size(32.dp)
.clip(CircleShape)
.clip(CircleShape),
)
}
loggedIn -> {
Expand Down
2 changes: 1 addition & 1 deletion gradle/libs.versions.toml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
[versions]
accompanist = "0.7.1"
accompanist = "0.7.2-SNAPSHOT"
androidxhilt = "1.0.0-beta01"
androidxlifecycle = "2.3.0"
androidxtest = "1.2.0"
Expand Down
9 changes: 4 additions & 5 deletions ui-account/src/main/java/app/tivi/account/AccountUi.kt
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ import androidx.navigation.NavController
import app.tivi.common.compose.foregroundColor
import app.tivi.data.entities.TraktUser
import app.tivi.trakt.TraktAuthState
import com.google.accompanist.coil.CoilImage
import com.google.accompanist.coil.rememberCoilPainter
import com.google.accompanist.flowlayout.FlowMainAxisAlignment
import com.google.accompanist.flowlayout.FlowRow
import org.threeten.bp.OffsetDateTime
Expand Down Expand Up @@ -177,13 +177,12 @@ private fun UserRow(
) {
val avatarUrl = user.avatarUrl
if (avatarUrl != null) {
CoilImage(
data = avatarUrl,
Image(
painter = rememberCoilPainter(avatarUrl, fadeIn = true),
contentDescription = stringResource(R.string.cd_profile_pic, user.name),
fadeIn = true,
modifier = Modifier
.size(40.dp)
.clip(RoundedCornerShape(50))
.clip(RoundedCornerShape(50)),
)
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ package app.tivi.episodedetails

import androidx.compose.animation.animateColorAsState
import androidx.compose.animation.core.FastOutLinearInEasing
import androidx.compose.foundation.Image
import androidx.compose.foundation.background
import androidx.compose.foundation.layout.Box
import androidx.compose.foundation.layout.Column
Expand Down Expand Up @@ -96,7 +97,7 @@ import app.tivi.data.entities.EpisodeWatchEntry
import app.tivi.data.entities.PendingAction
import app.tivi.data.entities.Season
import app.tivi.ui.animations.lerp
import com.google.accompanist.coil.CoilImage
import com.google.accompanist.coil.rememberCoilPainter
import com.google.accompanist.insets.navigationBarsHeight
import com.google.accompanist.insets.navigationBarsPadding
import com.google.accompanist.insets.statusBarsPadding
Expand Down Expand Up @@ -266,12 +267,11 @@ private fun Backdrop(
Surface(modifier = modifier) {
Box(Modifier.fillMaxSize()) {
if (episode.tmdbBackdropPath != null) {
CoilImage(
data = episode,
fadeIn = true,
Image(
painter = rememberCoilPainter(episode, fadeIn = true),
contentDescription = stringResource(R.string.cd_show_poster),
modifier = Modifier.fillMaxSize(),
contentScale = ContentScale.Crop,
modifier = Modifier.fillMaxSize()
)
}

Expand Down
15 changes: 9 additions & 6 deletions ui-followed/src/main/java/app/tivi/home/followed/Followed.kt
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@

package app.tivi.home.followed

import androidx.compose.foundation.Image
import androidx.compose.foundation.clickable
import androidx.compose.foundation.layout.Box
import androidx.compose.foundation.layout.Column
Expand Down Expand Up @@ -73,7 +74,7 @@ import app.tivi.data.entities.TiviShow
import app.tivi.data.entities.TraktUser
import app.tivi.data.resultentities.FollowedShowEntryWithShow
import app.tivi.trakt.TraktAuthState
import com.google.accompanist.coil.CoilImage
import com.google.accompanist.coil.rememberCoilPainter
import com.google.accompanist.insets.statusBarsPadding

@Composable
Expand Down Expand Up @@ -227,11 +228,13 @@ private fun FollowedShowItem(
.fillMaxHeight()
.aspectRatio(2 / 3f)
) {
CoilImage(
data = poster,
contentDescription = stringResource(R.string.cd_show_poster_image, show.title ?: ""),
fadeIn = true,
modifier = Modifier.fillMaxSize()
Image(
painter = rememberCoilPainter(poster, fadeIn = true),
contentDescription = stringResource(
R.string.cd_show_poster_image,
show.title ?: ""
),
modifier = Modifier.fillMaxSize(),
)
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,7 @@ import app.tivi.data.resultentities.numberAiredToWatch
import app.tivi.data.resultentities.numberToAir
import app.tivi.data.resultentities.numberWatched
import app.tivi.data.views.FollowedShowsWatchStats
import com.google.accompanist.coil.CoilImage
import com.google.accompanist.coil.rememberCoilPainter
import com.google.accompanist.flowlayout.FlowRow
import com.google.accompanist.insets.LocalWindowInsets
import com.google.accompanist.insets.navigationBarsPadding
Expand Down Expand Up @@ -421,16 +421,15 @@ private fun PosterInfoRow(
) {
Row(modifier) {
if (posterImage != null) {
CoilImage(
data = posterImage,
fadeIn = true,
Image(
painter = rememberCoilPainter(posterImage, fadeIn = true),
contentDescription = stringResource(R.string.cd_show_poster, show.title ?: ""),
alignment = Alignment.TopStart,
modifier = Modifier
.weight(1f, fill = false)
.aspectRatio(2 / 3f)
.padding(start = 16.dp)
.clip(MaterialTheme.shapes.medium)
.clip(MaterialTheme.shapes.medium),
alignment = Alignment.TopStart,
)
}

Expand All @@ -450,12 +449,11 @@ private fun BackdropImage(
) {
Surface(modifier = modifier) {
if (backdropImage != null) {
CoilImage(
data = backdropImage,
Image(
painter = rememberCoilPainter(backdropImage, fadeIn = true),
contentDescription = stringResource(R.string.cd_show_poster),
fadeIn = true,
modifier = Modifier.fillMaxSize(),
contentScale = ContentScale.Crop,
modifier = Modifier.fillMaxSize()
)
}
// TODO show a placeholder if null
Expand Down Expand Up @@ -565,19 +563,21 @@ private fun NetworkInfoPanel(
ShowTmdbImage(path = networkLogoPath, type = ImageType.LOGO, showId = 0)
}

CoilImage(
data = tmdbImage,
requestBuilder = {
transformations(TrimTransparentEdgesTransformation)
},
Image(
painter = rememberCoilPainter(
request = tmdbImage,
requestBuilder = {
transformations(TrimTransparentEdgesTransformation)
},
),
contentDescription = stringResource(R.string.cd_network_logo),
contentScale = ContentScale.Fit,
modifier = Modifier.sizeIn(maxWidth = 72.dp, maxHeight = 32.dp),
alignment = Alignment.TopStart,
contentScale = ContentScale.Fit,
colorFilter = when {
isSystemInDarkTheme() -> ColorFilter.tint(foregroundColor())
else -> null
},
modifier = Modifier.sizeIn(maxWidth = 72.dp, maxHeight = 32.dp)
)
} else {
Text(
Expand Down
16 changes: 10 additions & 6 deletions ui-watched/src/main/java/app/tivi/home/watched/Watched.kt
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@

package app.tivi.home.watched

import androidx.compose.foundation.Image
import androidx.compose.foundation.clickable
import androidx.compose.foundation.layout.Box
import androidx.compose.foundation.layout.Column
Expand Down Expand Up @@ -73,7 +74,7 @@ import app.tivi.data.entities.TiviShow
import app.tivi.data.entities.TraktUser
import app.tivi.data.resultentities.WatchedShowEntryWithShow
import app.tivi.trakt.TraktAuthState
import com.google.accompanist.coil.CoilImage
import com.google.accompanist.coil.rememberCoilPainter
import com.google.accompanist.insets.statusBarsPadding
import org.threeten.bp.OffsetDateTime

Expand Down Expand Up @@ -227,11 +228,14 @@ private fun WatchedShowItem(
.fillMaxHeight()
.aspectRatio(2 / 3f)
) {
CoilImage(
data = poster,
fadeIn = true,
contentDescription = stringResource(R.string.cd_show_poster_image, show.title ?: ""),
modifier = Modifier.fillMaxSize()
Image(
painter = rememberCoilPainter(poster, fadeIn = true),
contentDescription = stringResource(
R.string.cd_show_poster_image,
show.title
?: ""
),
modifier = Modifier.fillMaxSize(),
)
}
}
Expand Down

0 comments on commit f6582e7

Please sign in to comment.