Skip to content

Commit

Permalink
Migrate to coil multiplatform
Browse files Browse the repository at this point in the history
  • Loading branch information
prof18 committed Mar 31, 2024
1 parent 98fd1a4 commit 1f5b283
Show file tree
Hide file tree
Showing 15 changed files with 126 additions and 117 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import android.app.Application
import android.content.Context
import com.prof18.feedflow.core.utils.AppEnvironment
import com.prof18.feedflow.shared.di.getWith
import com.prof18.feedflow.shared.di.initKoin
import com.prof18.feedflow.shared.ui.utils.coilImageLoader
import com.prof18.feedflow.shared.utils.enableKmpCrashlytics
import org.koin.dsl.module

Expand Down Expand Up @@ -35,6 +35,12 @@ class FeedFlowApp : Application() {
logger = getWith("BrowserManager"),
)
}
single {
coilImageLoader(
context = this@FeedFlowApp,
debug = appEnvironment.isDebug()
)
}
},
),
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,9 @@ import androidx.navigation.NavHostController
import androidx.navigation.compose.NavHost
import androidx.navigation.compose.composable
import androidx.navigation.compose.rememberNavController
import coil3.ImageLoader
import coil3.annotation.ExperimentalCoilApi
import coil3.compose.setSingletonImageLoaderFactory
import com.google.accompanist.systemuicontroller.rememberSystemUiController
import com.prof18.feedflow.android.addfeed.AddFeedScreen
import com.prof18.feedflow.android.feedsourcelist.FeedSourceListScreen
Expand All @@ -32,9 +35,10 @@ import com.prof18.feedflow.android.settings.about.LicensesScreen
import com.prof18.feedflow.android.settings.importexport.ImportExportScreen
import com.prof18.feedflow.shared.ui.utils.ProvideFeedFlowStrings
import com.prof18.feedflow.shared.ui.utils.rememberFeedFlowStrings
import org.koin.compose.getKoin

class MainActivity : ComponentActivity() {
@OptIn(ExperimentalMaterial3WindowSizeClassApi::class)
@OptIn(ExperimentalMaterial3WindowSizeClassApi::class, ExperimentalCoilApi::class)
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)

Expand All @@ -50,6 +54,9 @@ class MainActivity : ComponentActivity() {
onDispose {}
}

val koin = getKoin()
setSingletonImageLoaderFactory { koin.get<ImageLoader>() }

val windowSize = calculateWindowSizeClass(this@MainActivity)

FeedFlowTheme {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,12 @@ import androidx.compose.ui.Modifier
import androidx.compose.ui.draw.clip
import androidx.compose.ui.graphics.Color
import androidx.compose.ui.layout.ContentScale
import androidx.compose.ui.platform.LocalContext
import androidx.compose.ui.platform.LocalInspectionMode
import androidx.compose.ui.tooling.preview.Preview
import androidx.compose.ui.unit.Dp
import coil.compose.AsyncImage
import coil.request.ImageRequest
import coil3.compose.AsyncImage
import coil3.compose.LocalPlatformContext
import coil3.request.ImageRequest
import com.prof18.feedflow.shared.ui.style.Spacing

@Composable
Expand All @@ -31,9 +31,8 @@ internal fun FeedItemImage(
)
} else {
AsyncImage(
model = ImageRequest.Builder(LocalContext.current)
model = ImageRequest.Builder(LocalPlatformContext.current)
.data(url)
.crossfade(true)
.build(),
contentDescription = null,
contentScale = ContentScale.Crop,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,12 @@ import androidx.compose.ui.draw.clip
import androidx.compose.ui.graphics.Color
import androidx.compose.ui.graphics.vector.rememberVectorPainter
import androidx.compose.ui.layout.ContentScale
import androidx.compose.ui.platform.LocalContext
import androidx.compose.ui.platform.LocalInspectionMode
import androidx.compose.ui.unit.Dp
import androidx.compose.ui.unit.dp
import coil.compose.AsyncImage
import coil.request.ImageRequest
import coil3.compose.AsyncImage
import coil3.compose.LocalPlatformContext
import coil3.request.ImageRequest
import com.prof18.feedflow.shared.ui.preview.PreviewPhone
import com.prof18.feedflow.shared.ui.style.Spacing

Expand All @@ -35,11 +35,11 @@ fun FeedSourceLogoImage(
)
} else {
AsyncImage(
model = ImageRequest.Builder(LocalContext.current)
model = ImageRequest.Builder(LocalPlatformContext.current)
.data(imageUrl)
.crossfade(true)
.build(),
placeholder = rememberVectorPainter(Icons.Default.Category),
fallback = rememberVectorPainter(Icons.Default.Category),
error = rememberVectorPainter(Icons.Default.Category),
contentDescription = null,
contentScale = ContentScale.Crop,
Expand Down
1 change: 0 additions & 1 deletion desktopApp/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@ kotlin {
implementation(libs.kotlinx.coroutines.core)
implementation(libs.decompose)
implementation(libs.decompose.compose.jetbrains)
implementation(libs.compose.image.loader)
implementation(libs.bundles.about.libraries)
implementation(libs.jsoup)
implementation(libs.slf4j.nop)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@ import androidx.compose.ui.window.DialogWindow
import androidx.compose.ui.window.Window
import androidx.compose.ui.window.application
import androidx.compose.ui.window.rememberWindowState
import coil3.ImageLoader
import coil3.compose.setSingletonImageLoaderFactory
import com.arkivanov.decompose.DefaultComponentContext
import com.arkivanov.decompose.ExperimentalDecomposeApi
import com.arkivanov.decompose.extensions.compose.jetbrains.lifecycle.LifecycleController
Expand Down Expand Up @@ -138,6 +140,9 @@ fun main() = application {
newVersionChecker.notifyIfNewVersionIsAvailable()
}

val koin = DI.koin
setSingletonImageLoaderFactory { koin.get<ImageLoader>() }

Window(
onCloseRequest = ::exitApplication,
state = windowState,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
package com.prof18.feedflow.desktop.di

import coil3.PlatformContext
import com.prof18.feedflow.core.utils.AppEnvironment
import com.prof18.feedflow.desktop.versionchecker.NewVersionChecker
import com.prof18.feedflow.shared.di.getWith
import com.prof18.feedflow.shared.di.initKoinDesktop
import com.prof18.feedflow.shared.ui.utils.coilImageLoader
import org.koin.core.Koin
import org.koin.dsl.module

Expand All @@ -21,6 +23,12 @@ object DI {
logger = getWith("NewVersionChecker"),
)
}
single {
coilImageLoader(
context = PlatformContext.INSTANCE,
debug = appEnvironment.isDebug()
)
}
},
),
).koin
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
package com.prof18.feedflow.desktop.home.components

import androidx.compose.foundation.Image
import androidx.compose.foundation.background
import androidx.compose.foundation.layout.Box
import androidx.compose.foundation.layout.size
Expand All @@ -12,8 +11,10 @@ import androidx.compose.ui.graphics.Color
import androidx.compose.ui.layout.ContentScale
import androidx.compose.ui.platform.LocalInspectionMode
import androidx.compose.ui.unit.Dp
import coil3.compose.AsyncImage
import coil3.compose.LocalPlatformContext
import coil3.request.ImageRequest
import com.prof18.feedflow.shared.ui.style.Spacing
import com.seiko.imageloader.rememberImagePainter

@Composable
fun FeedItemImage(
Expand All @@ -28,13 +29,15 @@ fun FeedItemImage(
.background(Color.Green),
)
} else {
Image(
painter = rememberImagePainter(url),
AsyncImage(
model = ImageRequest.Builder(LocalPlatformContext.current)
.data(url)
.build(),
contentDescription = null,
contentScale = ContentScale.Crop,
modifier = modifier
.size(width)
.clip(RoundedCornerShape(Spacing.small)),
contentDescription = null,
)
}
}

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
package com.prof18.feedflow.desktop.ui.components

import androidx.compose.foundation.Image
import androidx.compose.foundation.background
import androidx.compose.foundation.layout.Box
import androidx.compose.foundation.layout.size
Expand All @@ -15,8 +14,10 @@ import androidx.compose.ui.graphics.vector.rememberVectorPainter
import androidx.compose.ui.layout.ContentScale
import androidx.compose.ui.platform.LocalInspectionMode
import androidx.compose.ui.unit.Dp
import coil3.compose.AsyncImage
import coil3.compose.LocalPlatformContext
import coil3.request.ImageRequest
import com.prof18.feedflow.shared.ui.style.Spacing
import com.seiko.imageloader.rememberImagePainter

@Composable
fun FeedSourceLogoImage(
Expand All @@ -31,16 +32,13 @@ fun FeedSourceLogoImage(
.background(Color.Green),
)
} else {
Image(
painter = rememberImagePainter(
url = imageUrl,
errorPainter = {
rememberVectorPainter(Icons.Default.Category)
},
placeholderPainter = {
rememberVectorPainter(Icons.Default.Category)
},
),
AsyncImage(
model = ImageRequest.Builder(LocalPlatformContext.current)
.data(imageUrl)
.build(),
placeholder = rememberVectorPainter(Icons.Default.Category),
fallback = rememberVectorPainter(Icons.Default.Category),
error = rememberVectorPainter(Icons.Default.Category),
contentDescription = null,
contentScale = ContentScale.Crop,
modifier = modifier
Expand Down
9 changes: 4 additions & 5 deletions gradle/libs.versions.toml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ activity-compose = "1.8.2"
androidx-core-ktx = "1.5.0"
coroutines = "1.8.0"
detekt = "1.23.6"
io-coil = "2.6.0"
io-coil = "3.0.0-alpha06"
junit = "4.13.2"
kermit = "2.0.3"
koin-bom = "3.5.3"
Expand Down Expand Up @@ -39,7 +39,6 @@ decompose = "2.2.2"
jsystem-theme-detector = "3.6"
native-coroutines = "1.0.0-ALPHA-27"
ksp = "1.9.23-1.0.19"
compose-image-loader = "1.7.8"
multiplatform-settings = "1.1.1"
crashlytics = "18.6.3"
crashlytics-plugin = "2.9.9"
Expand All @@ -62,7 +61,8 @@ androidx-lifecycle-runtime-compose = { module = "androidx.lifecycle:lifecycle-ru
androidx-navigation-navigation-compose = { module = "androidx.navigation:navigation-compose", version.ref = "nav-compose" }
androidx-test-core-ktx = { module = "androidx.test:core-ktx", version.ref = "androidx-core-ktx" }
cashapp-turbine = { module = "app.cash.turbine:turbine", version.ref = "turbine" }
io-coil-compose = { module = "io.coil-kt:coil-compose", version.ref = "io-coil" }
io-coil-compose = { module = "io.coil-kt.coil3:coil-compose", version.ref = "io-coil" }
io-coil-network = { module = "io.coil-kt.coil3:coil-network-okhttp", version.ref = "io-coil" }
io-gitlab-arturbosch-detekt-formatting = { module = "io.gitlab.arturbosch.detekt:detekt-formatting", version.ref = "detekt" }
junit = { module = "junit:junit", version.ref = "junit" }
koin-android = { module = "io.insert-koin:koin-android" }
Expand Down Expand Up @@ -93,7 +93,6 @@ jsoup = { module = "org.jsoup:jsoup", version.ref = "jsoup" }
decompose = { module = "com.arkivanov.decompose:decompose", version.ref = "decompose" }
decompose-compose-jetbrains = { module = "com.arkivanov.decompose:extensions-compose-jetbrains", version.ref = "decompose" }
jsystem-theme-detector = { module = "com.github.Dansoftowner:jSystemThemeDetector", version.ref = "jsystem-theme-detector" }
compose-image-loader = { module = "io.github.qdsfdhvh:image-loader", version.ref = "compose-image-loader" }
multiplatform-settings = { module = "com.russhwolf:multiplatform-settings", version.ref = "multiplatform-settings" }
firebase-crashlytics-ktx = { module = "com.google.firebase:firebase-crashlytics-ktx", version.ref = "crashlytics" }
crashk-ios = { module = "co.touchlab.crashkios:crashlytics", version.ref = "crashk-ios" }
Expand All @@ -110,7 +109,7 @@ lyricist-processorXml = { module = "com.github.prof18:lyricist", version = "e305

[bundles]
compose = [
"androidx-activity-compose", "io-coil-compose", "androidx-lifecycle-viewModel-compose",
"androidx-activity-compose", "androidx-lifecycle-viewModel-compose",
"accompanist-systemuicontroller", "androidx-lifecycle-runtime-compose",
"androidx-navigation-navigation-compose",
]
Expand Down
9 changes: 9 additions & 0 deletions sharedUI/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,20 @@ kotlin {
languageSettings.optIn("androidx.compose.material3.ExperimentalMaterial3Api")
}

androidMain {
dependencies {
api(libs.io.coil.network)
}
}

commonMain {
dependencies {
api(project(":i18n"))
implementation(project(":core"))

api(libs.lyricist)
api(libs.io.coil.compose)

implementation(compose.runtime)
implementation(compose.foundation)
implementation(compose.material3)
Expand All @@ -36,6 +44,7 @@ kotlin {
jvmMain {
dependencies {
implementation(libs.jsystem.theme.detector)
api(libs.io.coil.network)
}
}
}
Expand Down
Loading

0 comments on commit 1f5b283

Please sign in to comment.