-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(coil): enable very early support for animated emotes on iOS (#453)
- Loading branch information
Showing
9 changed files
with
330 additions
and
61 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
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
40 changes: 40 additions & 0 deletions
40
...d/src/androidMain/kotlin/fr/outadoc/justchatting/utils/coil/ImageLoaderFactory.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,40 @@ | ||
package fr.outadoc.justchatting.utils.coil | ||
|
||
import android.os.Build | ||
import coil3.ImageLoader | ||
import coil3.PlatformContext | ||
import coil3.SingletonImageLoader | ||
import coil3.disk.DiskCache | ||
import coil3.gif.AnimatedImageDecoder | ||
import coil3.gif.GifDecoder | ||
import coil3.memory.MemoryCache | ||
import coil3.request.crossfade | ||
import okio.Path.Companion.toOkioPath | ||
|
||
internal actual object ImageLoaderFactory : SingletonImageLoader.Factory { | ||
|
||
override fun newImageLoader(context: PlatformContext): ImageLoader { | ||
return ImageLoader.Builder(context) | ||
.crossfade(true) | ||
.memoryCache { | ||
MemoryCache.Builder() | ||
.maxSizePercent(context, percent = 0.25) | ||
.build() | ||
} | ||
.diskCache { | ||
DiskCache.Builder() | ||
.directory(context.cacheDir.toOkioPath().resolve("image_cache")) | ||
.maxSizePercent(0.02) | ||
.build() | ||
} | ||
.components { | ||
if (Build.VERSION.SDK_INT >= 28) { | ||
add(AnimatedImageDecoder.Factory()) | ||
} else { | ||
add(GifDecoder.Factory()) | ||
} | ||
} | ||
.logger(CoilCustomLogger()) | ||
.build() | ||
} | ||
} |
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
37 changes: 37 additions & 0 deletions
37
shared/src/commonMain/kotlin/fr/outadoc/justchatting/utils/coil/CoilCustomLogger.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,37 @@ | ||
package fr.outadoc.justchatting.utils.coil | ||
|
||
import fr.outadoc.justchatting.utils.logging.Logger | ||
|
||
internal class CoilCustomLogger( | ||
override var minLevel: coil3.util.Logger.Level = coil3.util.Logger.Level.Debug, | ||
) : coil3.util.Logger { | ||
|
||
override fun log( | ||
tag: String, | ||
level: coil3.util.Logger.Level, | ||
message: String?, | ||
throwable: Throwable?, | ||
) { | ||
Logger.println( | ||
level = when (level) { | ||
coil3.util.Logger.Level.Error -> Logger.Level.Error | ||
coil3.util.Logger.Level.Warn -> Logger.Level.Warning | ||
coil3.util.Logger.Level.Info -> Logger.Level.Info | ||
coil3.util.Logger.Level.Debug -> Logger.Level.Debug | ||
coil3.util.Logger.Level.Verbose -> Logger.Level.Verbose | ||
}, | ||
tag = tag, | ||
content = { | ||
buildString { | ||
if (message != null) { | ||
appendLine(message) | ||
} | ||
|
||
if (throwable != null) { | ||
appendLine(throwable.stackTraceToString()) | ||
} | ||
} | ||
}, | ||
) | ||
} | ||
} |
5 changes: 5 additions & 0 deletions
5
shared/src/commonMain/kotlin/fr/outadoc/justchatting/utils/coil/ImageLoaderFactory.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,5 @@ | ||
package fr.outadoc.justchatting.utils.coil | ||
|
||
import coil3.SingletonImageLoader | ||
|
||
internal expect object ImageLoaderFactory : SingletonImageLoader.Factory |
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
Oops, something went wrong.