-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
21 changed files
with
252 additions
and
152 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
28 changes: 28 additions & 0 deletions
28
composeApp/src/androidMain/kotlin/imageLoader/ImageLoader.android.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
package imageLoader | ||
|
||
import applicationContext | ||
import com.seiko.imageloader.ImageLoader | ||
import com.seiko.imageloader.component.setupDefaultComponents | ||
import com.seiko.imageloader.intercept.painterMemoryCacheConfig | ||
import com.seiko.imageloader.option.androidContext | ||
import okio.Path.Companion.toOkioPath | ||
|
||
actual fun generateImageLoader(): ImageLoader { | ||
return ImageLoader { | ||
options { | ||
androidContext(applicationContext) | ||
} | ||
components { | ||
setupDefaultComponents() | ||
} | ||
interceptor { | ||
painterMemoryCacheConfig { | ||
maxSize(50) | ||
} | ||
diskCacheConfig { | ||
directory(applicationContext.cacheDir.resolve("image_cache").toOkioPath()) | ||
maxSizeBytes(512L * 1024 * 1024) // 512MB | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
package imageLoader | ||
|
||
import com.seiko.imageloader.ImageLoader | ||
|
||
expect fun generateImageLoader(): ImageLoader |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
53 changes: 53 additions & 0 deletions
53
composeApp/src/desktopMain/kotlin/imageLoader/ImageLoader.desktop.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
package imageLoader | ||
|
||
import com.seiko.imageloader.ImageLoader | ||
import com.seiko.imageloader.component.setupDefaultComponents | ||
import com.seiko.imageloader.intercept.painterMemoryCacheConfig | ||
import okio.Path.Companion.toOkioPath | ||
import java.io.File | ||
|
||
actual fun generateImageLoader(): ImageLoader { | ||
return ImageLoader { | ||
components { | ||
setupDefaultComponents() | ||
} | ||
interceptor { | ||
painterMemoryCacheConfig { | ||
maxSize(50) | ||
} | ||
diskCacheConfig { | ||
directory(getCacheDir().toOkioPath().resolve("image_cache")) | ||
maxSizeBytes(512L * 1024 * 1024) // 512MB | ||
} | ||
} | ||
} | ||
} | ||
|
||
enum class OperatingSystem { | ||
Windows, Linux, MacOS, Unknown | ||
} | ||
|
||
private val currentOperatingSystem: OperatingSystem | ||
get() { | ||
val operSys = System.getProperty("os.name").lowercase() | ||
return if (operSys.contains("win")) { | ||
OperatingSystem.Windows | ||
} else if (operSys.contains("nix") || operSys.contains("nux") || | ||
operSys.contains("aix") | ||
) { | ||
OperatingSystem.Linux | ||
} else if (operSys.contains("mac")) { | ||
OperatingSystem.MacOS | ||
} else { | ||
OperatingSystem.Unknown | ||
} | ||
} | ||
|
||
private fun getCacheDir() = when (currentOperatingSystem) { | ||
OperatingSystem.Windows -> File(System.getenv("AppData"), "$ApplicationName/cache") | ||
OperatingSystem.Linux -> File(System.getProperty("user.home"), ".cache/$ApplicationName") | ||
OperatingSystem.MacOS -> File(System.getProperty("user.home"), "Library/Caches/$ApplicationName") | ||
else -> throw IllegalStateException("Unsupported operating system") | ||
} | ||
|
||
private const val ApplicationName = "Compose ImageLoader" |
Oops, something went wrong.