-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* wip * wip * add url param name * refactor * fix duplicate jvm class name, hide io dispatcher * cleanup * cleanup * ktor3 by default --------- Co-authored-by: Zhirkevich Alexander Y <[email protected]>
- Loading branch information
1 parent
d239c08
commit 68e357e
Showing
38 changed files
with
516 additions
and
715 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
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
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,16 @@ | ||
plugins { | ||
id("kotlinx-atomicfu") | ||
} | ||
|
||
kotlin { | ||
sourceSets { | ||
commonMain.dependencies { | ||
api(project(":compottie")) | ||
implementation(project(":compottie-dot")) | ||
implementation(compose.ui) | ||
implementation(libs.serialization) | ||
api(libs.okio) | ||
implementation(libs.coroutines.core) | ||
} | ||
} | ||
} |
File renamed without changes.
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
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
File renamed without changes.
File renamed without changes.
File renamed without changes.
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
60 changes: 60 additions & 0 deletions
60
...ork-core/src/commonMain/kotlin/io/github/alexzhirkevich/compottie/NetworkAssetsManager.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,60 @@ | ||
@file:JvmName("CoreNetworkAssetsManager") | ||
|
||
|
||
package io.github.alexzhirkevich.compottie | ||
|
||
import androidx.compose.runtime.Stable | ||
import io.github.alexzhirkevich.compottie.assets.ImageRepresentable | ||
import io.github.alexzhirkevich.compottie.assets.LottieAssetsManager | ||
import io.github.alexzhirkevich.compottie.assets.LottieImageSpec | ||
import kotlin.jvm.JvmName | ||
|
||
/** | ||
* Asset manager that load images from web using [request] . | ||
* | ||
* @param request network request used for loading assets | ||
* @param cacheStrategy caching strategy. Caching to system temp dir by default | ||
* */ | ||
@OptIn(InternalCompottieApi::class) | ||
@Stable | ||
public fun NetworkAssetsManager( | ||
request : suspend (url: String) -> ByteArray, | ||
cacheStrategy: LottieCacheStrategy = DiskCacheStrategy.Instance, | ||
) : LottieAssetsManager = NetworkAssetsManagerImpl( | ||
request = request, | ||
cacheStrategy = cacheStrategy, | ||
) | ||
|
||
|
||
@Stable | ||
private class NetworkAssetsManagerImpl( | ||
private val request : suspend (url: String) -> ByteArray, | ||
private val cacheStrategy: LottieCacheStrategy, | ||
) : LottieAssetsManager { | ||
|
||
override suspend fun image(image: LottieImageSpec): ImageRepresentable? { | ||
return networkLoad( | ||
request = request, | ||
cacheStrategy = cacheStrategy, | ||
url = image.path + image.name | ||
).second?.let(ImageRepresentable::Bytes) | ||
} | ||
|
||
override fun equals(other: Any?): Boolean { | ||
if (this === other) return true | ||
if (other == null || this::class != other::class) return false | ||
|
||
other as NetworkAssetsManagerImpl | ||
|
||
if (request != other.request) return false | ||
if (cacheStrategy != other.cacheStrategy) return false | ||
|
||
return true | ||
} | ||
|
||
override fun hashCode(): Int { | ||
var result = request.hashCode() | ||
result = 31 * result + cacheStrategy.hashCode() | ||
return result | ||
} | ||
} |
79 changes: 79 additions & 0 deletions
79
...twork-core/src/commonMain/kotlin/io/github/alexzhirkevich/compottie/NetworkFontManager.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,79 @@ | ||
@file:JvmName("CoreNetworkFontManager") | ||
|
||
|
||
package io.github.alexzhirkevich.compottie | ||
|
||
import androidx.compose.runtime.Stable | ||
import androidx.compose.ui.text.font.Font | ||
import io.github.alexzhirkevich.compottie.assets.LottieFontManager | ||
import io.github.alexzhirkevich.compottie.assets.LottieFontSpec | ||
import okio.Path | ||
import kotlin.jvm.JvmName | ||
|
||
/** | ||
* Font manager that loads fonts from the web using [request]. | ||
* | ||
* Guaranteed to work only with [LottieFontSpec.FontOrigin.FontUrl] .ttf fonts | ||
* (support may be higher on non-Android platforms). | ||
* | ||
* Note: [LottieCacheStrategy.path] should return valid file system paths to make [NetworkFontManager] work. | ||
* Default [DiskCacheStrategy] supports it. | ||
* | ||
* @param request network request used for loading fonts | ||
* @param cacheStrategy caching strategy. Caching to system temp dir by default | ||
* */ | ||
@OptIn(InternalCompottieApi::class) | ||
@Stable | ||
public fun NetworkFontManager( | ||
request : suspend (url: String) -> ByteArray, | ||
cacheStrategy: LottieCacheStrategy = DiskCacheStrategy.Instance, | ||
) : LottieFontManager = NetworkFontManagerImpl( | ||
request = request, | ||
cacheStrategy = cacheStrategy, | ||
) | ||
|
||
@Stable | ||
private class NetworkFontManagerImpl( | ||
private val request : suspend (url: String) -> ByteArray, | ||
private val cacheStrategy: LottieCacheStrategy, | ||
) : LottieFontManager { | ||
|
||
override suspend fun font(font: LottieFontSpec): Font? { | ||
|
||
if (font.origin != LottieFontSpec.FontOrigin.FontUrl){ | ||
return null | ||
} | ||
|
||
val (path, bytes) = networkLoad( | ||
request = request, | ||
cacheStrategy = cacheStrategy, | ||
url = font.path ?: return null | ||
) | ||
|
||
if (path == null || bytes == null){ | ||
return null | ||
} | ||
|
||
return makeFont(font, path, bytes) | ||
} | ||
|
||
override fun equals(other: Any?): Boolean { | ||
if (this === other) return true | ||
if (other == null || this::class != other::class) return false | ||
|
||
other as NetworkFontManagerImpl | ||
|
||
if (request != other.request) return false | ||
if (cacheStrategy != other.cacheStrategy) return false | ||
|
||
return true | ||
} | ||
|
||
override fun hashCode(): Int { | ||
var result = request.hashCode() | ||
result = 31 * result + cacheStrategy.hashCode() | ||
return result | ||
} | ||
} | ||
|
||
internal expect suspend fun makeFont(spec: LottieFontSpec, path: Path, bytes: ByteArray) : Font |
File renamed without changes.
Oops, something went wrong.