Skip to content

Commit

Permalink
androidApp: Migrate to coil3
Browse files Browse the repository at this point in the history
Signed-off-by: Aayush Gupta <aayushgupta219@gmail.com>
  • Loading branch information
theimpulson committed Nov 27, 2024
1 parent a6d5826 commit b16728f
Show file tree
Hide file tree
Showing 5 changed files with 25 additions and 40 deletions.
1 change: 1 addition & 0 deletions androidApp/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@ dependencies {

// Coil
implementation(libs.coil.compose)
implementation(libs.coil.okhttp)

// Navigation
implementation(libs.androidx.navigation.compose)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,9 +63,9 @@ import app.opass.ccip.android.ui.navigation.Screen
import app.opass.ccip.android.ui.screens.eventpreview.EventPreviewScreen
import app.opass.ccip.android.utils.WifiUtil
import app.opass.ccip.network.models.eventconfig.FeatureType
import coil.compose.SubcomposeAsyncImage
import coil.request.CachePolicy
import coil.request.ImageRequest
import coil3.compose.AsyncImage
import coil3.request.ImageRequest
import coil3.request.crossfade

@Composable
@OptIn(ExperimentalLayoutApi::class, ExperimentalMaterial3Api::class)
Expand Down Expand Up @@ -253,17 +253,13 @@ fun Screen.Event.EventScreen(

@Composable
private fun HeaderImage(logoUrl: String?) {
SubcomposeAsyncImage(
AsyncImage(
model = ImageRequest.Builder(LocalContext.current)
.data(logoUrl)
.placeholder(R.drawable.ic_landscape)
.error(R.drawable.ic_broken_image)
.crossfade(true)
.memoryCacheKey(logoUrl)
.diskCacheKey(logoUrl)
.diskCachePolicy(CachePolicy.ENABLED)
.memoryCachePolicy(CachePolicy.ENABLED)
.build(),
placeholder = painterResource(R.drawable.ic_landscape),
error = painterResource(R.drawable.ic_broken_image),
contentDescription = "",
contentScale = ContentScale.Fit,
modifier = Modifier
Expand Down Expand Up @@ -302,17 +298,13 @@ private fun FeatureItem(
.background(color = MaterialTheme.colorScheme.primaryContainer),
contentAlignment = Alignment.Center
) {
SubcomposeAsyncImage(
AsyncImage(
model = ImageRequest.Builder(LocalContext.current)
.data(iconRes ?: iconUrl)
.placeholder(R.drawable.ic_event)
.error(R.drawable.ic_broken_image)
.crossfade(true)
.memoryCacheKey(iconUrl)
.diskCacheKey(iconUrl)
.diskCachePolicy(CachePolicy.ENABLED)
.memoryCachePolicy(CachePolicy.ENABLED)
.build(),
placeholder = painterResource(R.drawable.ic_event),
error = painterResource(R.drawable.ic_broken_image),
contentDescription = "",
contentScale = ContentScale.Fit,
modifier = Modifier
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,9 +58,9 @@ import app.opass.ccip.android.ui.extensions.sharedPreferences
import app.opass.ccip.android.ui.extensions.shimmer
import app.opass.ccip.android.ui.navigation.Screen
import app.opass.ccip.network.models.event.Event
import coil.compose.SubcomposeAsyncImage
import coil.request.CachePolicy
import coil.request.ImageRequest
import coil3.compose.AsyncImage
import coil3.request.ImageRequest
import coil3.request.crossfade

@Composable
@OptIn(ExperimentalMaterial3Api::class)
Expand Down Expand Up @@ -203,17 +203,13 @@ private fun EventPreviewItem(
verticalAlignment = Alignment.CenterVertically,
horizontalArrangement = Arrangement.spacedBy(20.dp, Alignment.Start)
) {
SubcomposeAsyncImage(
AsyncImage(
model = ImageRequest.Builder(LocalContext.current)
.data(logoUrl)
.placeholder(R.drawable.ic_event)
.error(R.drawable.ic_broken_image)
.crossfade(true)
.memoryCacheKey(logoUrl)
.diskCacheKey(logoUrl)
.diskCachePolicy(CachePolicy.ENABLED)
.memoryCachePolicy(CachePolicy.ENABLED)
.build(),
placeholder = painterResource(R.drawable.ic_event),
error = painterResource(R.drawable.ic_broken_image),
contentDescription = "",
contentScale = ContentScale.Fit,
modifier = Modifier
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ import androidx.compose.foundation.layout.padding
import androidx.compose.foundation.layout.requiredWidth
import androidx.compose.foundation.shape.RoundedCornerShape
import androidx.compose.material3.AlertDialog
import androidx.compose.material3.BottomAppBar
import androidx.compose.material3.Button
import androidx.compose.material3.Card
import androidx.compose.material3.CardDefaults
Expand Down Expand Up @@ -69,9 +68,9 @@ import app.opass.ccip.android.ui.extensions.shimmer
import app.opass.ccip.android.ui.navigation.Screen
import app.opass.ccip.android.utils.CommonUtil.setBrightness
import app.opass.ccip.android.utils.ZXingUtil
import coil.compose.SubcomposeAsyncImage
import coil.request.CachePolicy
import coil.request.ImageRequest
import coil3.compose.AsyncImage
import coil3.request.ImageRequest
import coil3.request.crossfade
import kotlinx.coroutines.android.awaitFrame

@Composable
Expand Down Expand Up @@ -249,17 +248,13 @@ private fun RequestTicket(

@Composable
private fun HeaderImage(logoUrl: String?) {
SubcomposeAsyncImage(
AsyncImage(
model = ImageRequest.Builder(LocalContext.current)
.data(logoUrl)
.placeholder(R.drawable.ic_landscape)
.error(R.drawable.ic_broken_image)
.crossfade(true)
.memoryCacheKey(logoUrl)
.diskCacheKey(logoUrl)
.diskCachePolicy(CachePolicy.ENABLED)
.memoryCachePolicy(CachePolicy.ENABLED)
.build(),
placeholder = painterResource(R.drawable.ic_landscape),
error = painterResource(R.drawable.ic_broken_image),
contentDescription = null,
contentScale = ContentScale.Fit,
modifier = Modifier
Expand Down
5 changes: 3 additions & 2 deletions gradle/libs.versions.toml
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ androidx-composeNavigation = "2.8.4"
androidx-hilt = "1.2.0"
androidx-lifecycle = "2.8.7"
androidx-startupRuntime = "1.2.0"
coil = "2.7.0"
coil = "3.0.4"
hilt = "2.52"
markdown = "0.27.0"
material = "1.12.0"
Expand All @@ -40,7 +40,8 @@ androidx-startup-runtime = { module = "androidx.startup:startup-runtime", versio
cash-sqldelight-android = { module = "app.cash.sqldelight:android-driver", version.ref = "sqlDelight" }
cash-sqldelight-native = { module = "app.cash.sqldelight:native-driver", version.ref = "sqlDelight" }
cash-sqldelight-runtime = { module = "app.cash.sqldelight:runtime", version.ref = "sqlDelight" }
coil-compose = { module = "io.coil-kt:coil-compose", version.ref = "coil" }
coil-compose = { module = "io.coil-kt.coil3:coil-compose", version.ref = "coil" }
coil-okhttp = { module = "io.coil-kt.coil3:coil-network-okhttp", version.ref = "coil" }
compose-ui = { module = "androidx.compose.ui:ui", version.ref = "compose" }
compose-ui-tooling = { module = "androidx.compose.ui:ui-tooling", version.ref = "compose" }
compose-ui-tooling-preview = { module = "androidx.compose.ui:ui-tooling-preview", version.ref = "compose" }
Expand Down

0 comments on commit b16728f

Please sign in to comment.